2
2
3
3
import edu .kit .datamanager .ro_crate .Crate ;
4
4
import edu .kit .datamanager .ro_crate .entities .contextual .ContextualEntity ;
5
+ import edu .kit .datamanager .ro_crate .util .ClasspathPropertiesVersionProvider ;
6
+ import edu .kit .datamanager .ro_crate .util .VersionProvider ;
5
7
6
- import java .io .IOException ;
7
- import java .io .InputStream ;
8
- import java .net .URL ;
9
8
import java .time .Instant ;
10
- import java .util .Properties ;
11
9
import java .util .UUID ;
12
10
13
11
import static edu .kit .datamanager .ro_crate .entities .contextual .ContextualEntity .ContextualEntityBuilder ;
19
17
class ProvenanceManager {
20
18
private static final String RO_CRATE_JAVA_ID = "#ro-crate-java" ;
21
19
20
+ protected VersionProvider versionProvider ;
21
+
22
+ /**
23
+ * Constructs a ProvenanceManager with the default ClasspathPropertiesVersionProvider.
24
+ */
25
+ public ProvenanceManager () {
26
+ this (new ClasspathPropertiesVersionProvider ());
27
+ }
28
+
29
+ /**
30
+ * Constructs a ProvenanceManager with a specified VersionProvider.
31
+ *
32
+ * @param versionProvider The VersionProvider to use for retrieving the version of ro-crate-java.
33
+ */
34
+ public ProvenanceManager (VersionProvider versionProvider ) {
35
+ this .versionProvider = versionProvider ;
36
+ }
37
+
22
38
void addProvenanceInformation (Crate crate ) {
23
39
// Determine if this is the first write
24
40
boolean isFirstWrite = !crate .getJsonMetadata ().contains (RO_CRATE_JAVA_ID ) && !crate .isImported ();
@@ -53,7 +69,7 @@ private ContextualEntity buildRoCrateJavaEntity(
53
69
.filter (contextualEntity -> RO_CRATE_JAVA_ID .equals (contextualEntity .getId ()))
54
70
.findFirst ()
55
71
.orElseGet (() -> {
56
- String version = loadVersionFromProperties ();
72
+ String version = this . versionProvider . getVersion ();
57
73
return new ContextualEntityBuilder ()
58
74
.setId (RO_CRATE_JAVA_ID )
59
75
.addType ("SoftwareApplication" )
@@ -71,23 +87,4 @@ private ContextualEntity buildRoCrateJavaEntity(
71
87
self .addIdProperty ("Action" , newActionId );
72
88
return self ;
73
89
}
74
-
75
- private String loadVersionFromProperties () {
76
- URL resource = this .getClass ().getResource ("/version.properties" );
77
- if (resource == null ) {
78
- throw new IllegalStateException ("version.properties not found in classpath. This indicates a build configuration issue." );
79
- }
80
-
81
- try (InputStream input = resource .openStream ()) {
82
- Properties properties = new Properties ();
83
- properties .load (input );
84
- String version = properties .getProperty ("version" );
85
- if (version == null || version .trim ().isEmpty ()) {
86
- throw new IllegalStateException ("No version property found in version.properties" );
87
- }
88
- return version .trim ();
89
- } catch (IOException e ) {
90
- throw new IllegalStateException ("Failed to read version from properties file" , e );
91
- }
92
- }
93
90
}
0 commit comments