Skip to content

Commit 0ca5d73

Browse files
authored
Merge pull request #264 from kit-data-manager/development
Next Version (2.1.0 | 2.1.0-rc3)
2 parents 7254152 + 88fc710 commit 0ca5d73

27 files changed

+1156
-27
lines changed

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ authors:
1010
given-names: "Sabrine"
1111
orcid: "https://orcid.org/0000-0002-4480-6116"
1212
title: "ro-crate-java"
13-
version: 1.0.3
13+
version: 2.1.0-rc3
1414
date-released: 2022-07-19
1515
url: "https://github.com/kit-data-manager/ro-crate-java"

build.gradle

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ ext {
4343

4444
dependencies {
4545
// JUnit setup for testing
46-
testImplementation(platform("org.junit:junit-bom:5.12.2"))
46+
testImplementation(platform("org.junit:junit-bom:5.13.0"))
4747
testImplementation('org.junit.jupiter:junit-jupiter')
4848
testRuntimeOnly('org.junit.platform:junit-platform-launcher')
4949
// JSON object mapping / (de-)serialization
@@ -64,7 +64,7 @@ dependencies {
6464
// JSON-LD, Zenodo mapping
6565
implementation group: 'com.apicatalog', name: 'titanium-json-ld', version: '1.6.0'
6666
// metadata validation, profiles based on JSON schema
67-
implementation group: "com.networknt", name: "json-schema-validator", version: "1.5.6"
67+
implementation group: "com.networknt", name: "json-schema-validator", version: "1.5.7"
6868
implementation 'org.glassfish:jakarta.json:2.0.1'
6969
//JTE for template processing
7070
implementation('gg.jte:jte:3.2.1')
@@ -111,6 +111,22 @@ configurations {
111111
performanceTestImplementation.extendsFrom implementation
112112
}
113113

114+
// Task for creating a resource file with the version info
115+
tasks.register("generateVersionProps", WriteProperties) { t ->
116+
def generatedResourcesDir = project.layout.buildDirectory.dir(["resources", "main"].join(File.separator))
117+
def outputFile = generatedResourcesDir.map { it.file("version.properties") }
118+
119+
t.destinationFile = outputFile.get().asFile
120+
t.property("version", version)
121+
}
122+
123+
tasks.register("generateVersionPropsTest", WriteProperties) { t ->
124+
def generatedResourcesDir = project.layout.buildDirectory.dir(["resources", "test"].join(File.separator))
125+
def outputFile = generatedResourcesDir.map { it.file("version.properties") }
126+
127+
t.destinationFile = outputFile.get().asFile
128+
t.property("version", version)
129+
}
114130

115131
tasks.register('performanceContextEntitiesBenchmark', JavaExec) {
116132
description = "Run the context entities benchmarks."
@@ -154,8 +170,13 @@ tasks.register('performanceReadWriteMultipleCratesBenchmark', JavaExec) {
154170
mainClass = 'edu.kit.datamanager.ro_crate.multiplecrates.MultipleCratesWriteAndRead'
155171
}
156172

173+
compileJava {
174+
dependsOn generateVersionProps
175+
}
176+
157177
test {
158178
useJUnitPlatform()
179+
dependsOn generateVersionPropsTest
159180
finalizedBy jacocoTestReport
160181
}
161182

@@ -178,3 +199,5 @@ if (System.getProperty('profile') == "release") {
178199
println 'Using release profile for building ' + project.getName()
179200
apply from: 'gradle/profile-release.gradle'
180201
}
202+
203+
apply from: 'gradle/updateCff.gradle'

gradle/profile-release.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
apply plugin: 'net.researchgate.release'
1818
apply plugin: 'maven-publish'
1919
apply plugin: 'signing'
20-
20+
2121
//for plugin net.researchgate.release
2222
//see https://github.com/researchgate/gradle-release
2323
release {

gradle/updateCff.gradle

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import java.time.LocalDate
2+
import java.time.format.DateTimeFormatter
3+
4+
/**
5+
* This file defines the updateCff task.
6+
*
7+
* This task hooks into the workflow of the release task,
8+
* which, according to the source code of the release plugin,
9+
* seems to be defined like this:
10+
*
11+
* tasks = [
12+
* "${p}createScmAdapter" as String,
13+
* "${p}initScmAdapter" as String,
14+
* "${p}checkCommitNeeded" as String,
15+
* "${p}checkUpdateNeeded" as String,
16+
* "${p}checkoutMergeToReleaseBranch" as String,
17+
* "${p}unSnapshotVersion" as String,
18+
* "${p}confirmReleaseVersion" as String,
19+
* -> we insert our task here <-
20+
* "${p}checkSnapshotDependencies" as String,
21+
* "${p}runBuildTasks" as String,
22+
* "${p}preTagCommit" as String,
23+
* "${p}createReleaseTag" as String,
24+
* "${p}checkoutMergeFromReleaseBranch" as String,
25+
* "${p}updateVersion" as String,
26+
* "${p}commitNewVersion" as String
27+
* ]
28+
*/
29+
30+
tasks.register('updateCff') {
31+
group = 'release'
32+
description = 'Updates the version in CITATION.cff file'
33+
34+
outputs.file("CITATION.cff")
35+
36+
doLast {
37+
def version = project.version.toString()
38+
def today = LocalDate.now().format(DateTimeFormatter.ISO_DATE)
39+
40+
def cffFile = file('CITATION.cff')
41+
def content = cffFile.text
42+
43+
// Update or insert version
44+
if (content.contains('version:')) {
45+
content = content.replaceAll(/(?m)^version:\s*.+$/, "version: ${version}")
46+
} else {
47+
content = content + "\nversion: ${version}"
48+
}
49+
50+
// Update or insert date-released
51+
if (content.contains('date-released:')) {
52+
content = content.replaceAll(/(?m)^date-released:\s*.+$/, "date-released: ${today}")
53+
} else {
54+
content = content + "\ndate-released: ${today}"
55+
}
56+
57+
cffFile.text = content
58+
println "Updated CITATION.cff to version ${version} and date-released ${today}"
59+
}
60+
}
61+
62+
// Make sure your custom task runs after a specific task in the release sequence
63+
tasks.named('updateCff') {
64+
mustRunAfter(tasks.named('confirmReleaseVersion'))
65+
}
66+
67+
// Ensure subsequent tasks in the release sequence run after your custom task
68+
tasks.named('checkSnapshotDependencies') {
69+
dependsOn('updateCff')
70+
}

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

src/main/java/edu/kit/datamanager/ro_crate/Crate.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,28 @@
2222
*/
2323
public interface Crate {
2424

25+
/**
26+
* Mark the crate as imported, i.e. it has been read from a file
27+
* or is for other reasons not considered a new crate.
28+
* <p>
29+
* This is useful mostly for readers to indicate this in case
30+
* the crate may not have any provenance information yet and
31+
* should still be recognized as an imported crate.
32+
*
33+
* @return this crate, for convenience.
34+
*/
35+
Crate markAsImported();
36+
37+
/**
38+
* Check if the crate is marked as imported.
39+
* <p>
40+
* If true, it indicates that the crate has been read from a file
41+
* or is for other reasons not considered a new crate.
42+
*
43+
* @return true if the crate is marked as imported, false otherwise.
44+
*/
45+
boolean isImported();
46+
2547
/**
2648
* Read version from the crate descriptor and return it as a class
2749
* representation.

src/main/java/edu/kit/datamanager/ro_crate/RoCrate.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ public class RoCrate implements Crate {
5050

5151
protected Collection<File> untrackedFiles;
5252

53+
/**
54+
* Indicates whether this crate has been imported from an external source.
55+
* This is used to determine if ro-crate-java should add a CreateAction
56+
* or an UpdateAction in the provenance on export.
57+
*/
58+
protected boolean isImported = false;
59+
60+
@Override
61+
public RoCrate markAsImported() {
62+
this.isImported = true;
63+
return this;
64+
}
65+
66+
@Override
67+
public boolean isImported() {
68+
return this.isImported;
69+
}
70+
5371
@Override
5472
public CratePreview getPreview() {
5573
return this.roCratePreview;
@@ -375,12 +393,14 @@ public RoCrateBuilder addDescription(String description) {
375393
* @return returns the builder for further usage.
376394
*/
377395
public RoCrateBuilder addDataEntity(DataEntity dataEntity) {
396+
this.metadataContext.checkEntity(dataEntity);
378397
this.payload.addDataEntity(dataEntity);
379398
this.rootDataEntity.addToHasPart(dataEntity.getId());
380399
return this;
381400
}
382401

383402
public RoCrateBuilder addContextualEntity(ContextualEntity contextualEntity) {
403+
this.metadataContext.checkEntity(contextualEntity);
384404
this.payload.addContextualEntity(contextualEntity);
385405
return this;
386406
}

0 commit comments

Comments
 (0)