|
2 | 2 |
|
3 | 3 | import edu.kit.datamanager.ro_crate.Crate;
|
4 | 4 | import edu.kit.datamanager.ro_crate.entities.contextual.ContextualEntity;
|
| 5 | + |
| 6 | +import java.io.IOException; |
| 7 | +import java.io.InputStream; |
| 8 | +import java.net.URL; |
5 | 9 | import java.time.Instant;
|
6 |
| -import java.util.Collection; |
7 |
| -import java.util.Map; |
| 10 | +import java.util.Properties; |
8 | 11 | import java.util.UUID;
|
9 | 12 |
|
10 | 13 | import static edu.kit.datamanager.ro_crate.entities.contextual.ContextualEntity.ContextualEntityBuilder;
|
@@ -49,21 +52,42 @@ private ContextualEntity buildRoCrateJavaEntity(
|
49 | 52 | ContextualEntity self = crate.getAllContextualEntities().stream()
|
50 | 53 | .filter(contextualEntity -> RO_CRATE_JAVA_ID.equals(contextualEntity.getId()))
|
51 | 54 | .findFirst()
|
52 |
| - .orElseGet(() -> |
53 |
| - new ContextualEntityBuilder() |
54 |
| - .setId(RO_CRATE_JAVA_ID) |
55 |
| - .addType("SoftwareApplication") |
56 |
| - .addProperty("name", "ro-crate-java") |
57 |
| - .addProperty("url", "https://github.com/kit-data-manager/ro-crate-java") |
58 |
| - // TODO read software version and version from gradle (write into resources properties file when building and read it from there) |
59 |
| - .addProperty("version", "1.0.0") |
60 |
| - .addProperty("softwareVersion", "1.0.0") |
61 |
| - .addProperty("license", "Apache-2.0") |
62 |
| - .addProperty("description", "A Java library for creating and manipulating RO-Crates") |
63 |
| - .addIdProperty("Action", newActionId) |
64 |
| - .build() |
| 55 | + .orElseGet(() -> { |
| 56 | + String version = loadVersionFromProperties(); |
| 57 | + return new ContextualEntityBuilder() |
| 58 | + .setId(RO_CRATE_JAVA_ID) |
| 59 | + .addType("SoftwareApplication") |
| 60 | + .addProperty("name", "ro-crate-java") |
| 61 | + .addProperty("url", "https://github.com/kit-data-manager/ro-crate-java") |
| 62 | + // TODO read software version and version from gradle (write into resources properties file when building and read it from there) |
| 63 | + .addProperty("version", version) |
| 64 | + .addProperty("softwareVersion", version) |
| 65 | + .addProperty("license", "Apache-2.0") |
| 66 | + .addProperty("description", "A Java library for creating and manipulating RO-Crates") |
| 67 | + .addIdProperty("Action", newActionId) |
| 68 | + .build(); |
| 69 | + } |
65 | 70 | );
|
66 | 71 | self.addIdProperty("Action", newActionId);
|
67 | 72 | return self;
|
68 | 73 | }
|
| 74 | + |
| 75 | + private String loadVersionFromProperties() { |
| 76 | + try { |
| 77 | + URL resource = this.getClass().getResource("/version.properties"); |
| 78 | + if (resource != null) { |
| 79 | + try (InputStream input = resource.openStream()) { |
| 80 | + Properties properties = new Properties(); |
| 81 | + properties.load(input); |
| 82 | + return properties.getProperty("version"); |
| 83 | + } |
| 84 | + } else { |
| 85 | + System.err.println("Properties file not found!"); |
| 86 | + return "unknown"; |
| 87 | + } |
| 88 | + } catch (IOException e) { |
| 89 | + System.err.println("Properties file not found!"); |
| 90 | + return "unknown"; |
| 91 | + } |
| 92 | + } |
69 | 93 | }
|
0 commit comments