Skip to content

Commit acd8641

Browse files
authored
Merge pull request #31 from spdx/v23
Update to SPDX spec version 2.3
2 parents 51308e8 + 4c251f7 commit acd8641

14 files changed

Lines changed: 10040 additions & 1821 deletions

TestFiles/SPDXRdfExample-old.rdf

Lines changed: 1365 additions & 0 deletions
Large diffs are not rendered by default.

TestFiles/SPDXRdfExample.rdf

Lines changed: 3873 additions & 896 deletions
Large diffs are not rendered by default.

TestFiles/SPDXRdfExampleHttps.rdf

Lines changed: 845 additions & 821 deletions
Large diffs are not rendered by default.

TestFiles/withHasFile.rdf

Lines changed: 1365 additions & 0 deletions
Large diffs are not rendered by default.

TestFiles/withHasFileAndContains.rdf

Lines changed: 1983 additions & 0 deletions
Large diffs are not rendered by default.

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.spdx</groupId>
66
<artifactId>spdx-rdf-store</artifactId>
7-
<version>1.0.5-SNAPSHOT</version>
7+
<version>1.1.0</version>
88
<packaging>jar</packaging>
99

1010
<name>spdx-rdf-store</name>
@@ -91,7 +91,7 @@
9191
<dependency>
9292
<groupId>org.spdx</groupId>
9393
<artifactId>java-spdx-library</artifactId>
94-
<version>1.0.10</version>
94+
<version>1.1.0</version>
9595
</dependency>
9696
<dependency>
9797
<groupId>org.apache.jena</groupId>

resources/spdx-2-2-revision-14-onotology.owl.xml renamed to resources/spdx-2-3-revision-2-ontology.owl.xml

Lines changed: 378 additions & 93 deletions
Large diffs are not rendered by default.

src/main/java/org/spdx/spdxRdfStore/CompatibilityUpgrader.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,49 @@ public static void upgrade(Model model, String documentNamespace) throws Invalid
103103
upgradeArtifactOf(model, documentNamespace);
104104
upgradeReviewers(model, documentNamespace);
105105
upgradeExternalDocumentRefs(model, documentNamespace);
106+
upgradeHasFiles(model, documentNamespace);
106107
} finally {
107108
model.leaveCriticalSection();
108109
}
109110
}
110111

112+
/**
113+
* Changes all hasFile properties to CONTAINS relationships
114+
* @param model
115+
* @param documentNamespace
116+
*/
117+
private static void upgradeHasFiles(Model model, String documentNamespace) {
118+
List<Statement> statementsToRemove = new ArrayList<>();
119+
Property hasFileProperty = model.createProperty("http://spdx.org/rdf/terms#hasFile");
120+
Property relationshipProperty = model.createProperty(SpdxConstants.SPDX_NAMESPACE + SpdxConstants.PROP_RELATIONSHIP);
121+
String query = "SELECT ?s ?o WHERE { ?s <http://spdx.org/rdf/terms#hasFile> ?o }";
122+
try (QueryExecution qe = QueryExecutionFactory.create(query, model)) {
123+
ResultSet result = qe.execSelect();
124+
while (result.hasNext()) {
125+
QuerySolution qs = result.next();
126+
Resource pkg = qs.get("s").asResource();
127+
Resource file = qs.get("o").asResource();
128+
statementsToRemove.add(model.createStatement(pkg, hasFileProperty, file));
129+
// check for existing contains relationships - avoids duplication
130+
List<Statement> foundContainsRelationships = new ArrayList<>();
131+
pkg.listProperties(relationshipProperty).forEach((stmt) -> {
132+
Resource existingRelationship = stmt.getObject().asResource();
133+
Resource relatedElement = existingRelationship.getPropertyResourceValue(model.createProperty(SpdxConstants.SPDX_NAMESPACE + SpdxConstants.PROP_RELATED_SPDX_ELEMENT));
134+
Resource relationshipType = existingRelationship.getPropertyResourceValue(model.createProperty(SpdxConstants.SPDX_NAMESPACE + SpdxConstants.PROP_RELATIONSHIP_TYPE));
135+
if (relatedElement.getURI().equals(file.getURI()) &&
136+
relationshipType.getURI().equals(RelationshipType.CONTAINS.getIndividualURI())) {
137+
foundContainsRelationships.add(stmt);
138+
}
139+
});
140+
if (foundContainsRelationships.size() == 0) {
141+
Resource relationship = createRelationship(model, file, RelationshipType.CONTAINS);
142+
pkg.addProperty(relationshipProperty, relationship);
143+
}
144+
}
145+
model.remove(statementsToRemove);
146+
}
147+
}
148+
111149
/**
112150
* Make sure all external document Ref's have a URI with proper ID rather than using the externalDocumentId property
113151
* @param model

src/main/java/org/spdx/spdxRdfStore/RdfSpdxDocumentModelManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public void removedStatement(Statement s) {
180180
private NextIdListener nextIdListener = new NextIdListener();
181181

182182
private String documentUri;
183-
private Model model;
183+
protected Model model;
184184
/**
185185
* Map of a lower case ID to the case sensitive ID
186186
*/

src/main/java/org/spdx/spdxRdfStore/SpdxOwlOntology.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class SpdxOwlOntology {
5454

5555
static SpdxOwlOntology myself = null;
5656

57-
static final String ONTOLOGY_PATH = "/resources/spdx-2-2-revision-14-onotology.owl.xml";
57+
static final String ONTOLOGY_PATH = "/resources/spdx-2-3-revision-2-ontology.owl.xml";
5858

5959
private OntModel model;
6060

0 commit comments

Comments
 (0)