Skip to content

Commit 631b60a

Browse files
authored
Merge pull request #64 from spdx/rc1
Update to SPDX Spec 3.0.1
2 parents 744549b + 622b5c2 commit 631b60a

File tree

10 files changed

+288
-346
lines changed

10 files changed

+288
-346
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
<dependency>
119119
<groupId>org.spdx</groupId>
120120
<artifactId>java-spdx-library</artifactId>
121-
<version>2.0.0-Alpha</version>
121+
<version>2.0.0-RC1</version>
122122
</dependency>
123123
<dependency>
124124
<groupId>org.apache.jena</groupId>

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

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/**
22
* Copyright (c) 2020 Source Auditor Inc.
3-
*
3+
* <p>
44
* SPDX-License-Identifier: Apache-2.0
5-
*
5+
* <p>
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
9-
*
9+
* <p>
1010
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
11+
* <p>
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,8 +18,6 @@
1818
package org.spdx.spdxRdfStore;
1919

2020
import java.util.ArrayList;
21-
import java.util.Collections;
22-
import java.util.HashMap;
2321
import java.util.HashSet;
2422
import java.util.List;
2523
import java.util.Map;
@@ -58,20 +56,17 @@ public class CompatibilityUpgrader {
5856
static final Logger logger = LoggerFactory.getLogger(CompatibilityUpgrader.class);
5957

6058
static {
61-
Map<String, Map<String, String>> mutableTypePropertyMap = new HashMap<>();
62-
Map<String, String> documentMap = new HashMap<>();
63-
//TODO: In 3.0, uncomment those below to change the spec versions
64-
// documentMap.put(SpdxConstantsCompatV2.SPDX_NAMESPACE + SpdxConstantsCompatV2.PROP_SPDX_VERSION.getName(),
65-
// SpdxConstantsCompatV2.SPDX_NAMESPACE + SpdxConstantsCompatV2.PROP_SPDX_SPEC_VERSION.getName());
66-
mutableTypePropertyMap.put(SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT, Collections.unmodifiableMap(documentMap));
67-
68-
TYPE_PROPERTY_MAP = Collections.unmodifiableMap(mutableTypePropertyMap);
59+
TYPE_PROPERTY_MAP = Map.of(SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT, Map.of(
60+
// TODO: In 3.0, uncomment those below to change the spec versions
61+
SpdxConstantsCompatV2.SPDX_NAMESPACE + SpdxConstantsCompatV2.PROP_SPDX_VERSION.getName(),
62+
SpdxConstantsCompatV2.SPDX_NAMESPACE + SpdxConstantsCompatV2.PROP_SPDX_SPEC_VERSION.getName())
63+
);
6964
}
7065

7166
/**
7267
* Upgrade the properties in the model to the current version of the spec
73-
* @param model
74-
* @param documentNamespace
68+
* @param model RDF model
69+
* @param documentNamespace Namespace or URI for the SPDX document
7570
*/
7671
public static void upgrade(Model model, String documentNamespace) throws InvalidSPDXAnalysisException {
7772
model.enterCriticalSection(false);
@@ -94,7 +89,8 @@ public static void upgrade(Model model, String documentNamespace) throws Invalid
9489
RDFNode object = iter.next();
9590
subject.addProperty(compatibleProperty, object);
9691
}
97-
subject.removeAll(incompatibleProperty);
92+
// We'll leave the old property for compatibility
93+
// subject.removeAll(incompatibleProperty);
9894
}
9995
}
10096
}
@@ -103,18 +99,17 @@ public static void upgrade(Model model, String documentNamespace) throws Invalid
10399
upgradeArtifactOf(model, documentNamespace);
104100
upgradeReviewers(model, documentNamespace);
105101
upgradeExternalDocumentRefs(model, documentNamespace);
106-
upgradeHasFiles(model, documentNamespace);
102+
upgradeHasFiles(model);
107103
} finally {
108104
model.leaveCriticalSection();
109105
}
110106
}
111107

112108
/**
113109
* Changes all hasFile properties to CONTAINS relationships
114-
* @param model
115-
* @param documentNamespace
110+
* @param model RDF model
116111
*/
117-
private static void upgradeHasFiles(Model model, String documentNamespace) {
112+
private static void upgradeHasFiles(Model model) {
118113
List<Statement> statementsToRemove = new ArrayList<>();
119114
Property hasFileProperty = model.createProperty("http://spdx.org/rdf/terms#hasFile");
120115
Property relationshipProperty = model.createProperty(SpdxConstantsCompatV2.SPDX_NAMESPACE + SpdxConstantsCompatV2.PROP_RELATIONSHIP.getName());
@@ -138,7 +133,7 @@ private static void upgradeHasFiles(Model model, String documentNamespace) {
138133
foundContainsRelationships.add(stmt);
139134
}
140135
});
141-
if (foundContainsRelationships.size() == 0) {
136+
if (foundContainsRelationships.isEmpty()) {
142137
Resource relationship = createRelationship(model, file, RelationshipType.CONTAINS);
143138
pkg.addProperty(relationshipProperty, relationship);
144139
}
@@ -149,9 +144,9 @@ private static void upgradeHasFiles(Model model, String documentNamespace) {
149144

150145
/**
151146
* Make sure all external document Ref's have a URI with proper ID rather than using the externalDocumentId property
152-
* @param model
153-
* @param documentNamespace
154-
* @throws InvalidSPDXAnalysisException
147+
* @param model RDF model
148+
* @param documentNamespace Namespace or URI for the SPDX document
149+
* @throws InvalidSPDXAnalysisException on SPDX parsing errors
155150
*/
156151
private static void upgradeExternalDocumentRefs(Model model, String documentNamespace) throws InvalidSPDXAnalysisException {
157152
String query = "SELECT ?s ?o WHERE { ?s <http://spdx.org/rdf/terms#externalDocumentId> ?o }";
@@ -197,9 +192,9 @@ private static void upgradeExternalDocumentRefs(Model model, String documentName
197192

198193
/**
199194
* Upgrade the reviewers field to Annotations with a type reviewer
200-
* @param model
201-
* @param documentNamespace
202-
* @throws InvalidSPDXAnalysisException
195+
* @param model RDF model
196+
* @param documentNamespace Namespace or URI for the SPDX document
197+
* @throws InvalidSPDXAnalysisException on SPDX parsing errors
203198
*/
204199
private static void upgradeReviewers(Model model, String documentNamespace) throws InvalidSPDXAnalysisException {
205200
Resource document = model.createResource(documentNamespace + "#" + SpdxConstantsCompatV2.SPDX_DOCUMENT_ID);
@@ -267,13 +262,13 @@ private static void upgradeReviewers(Model model, String documentNamespace) thro
267262

268263
/**
269264
* Convert all artifactOf properties to relationships and remove the old properties and DOAP classes
270-
* @param model
265+
* @param model RDF model
271266
* @param documentNamespace the document Namespace
272-
* @throws InvalidSPDXAnalysisException
267+
* @throws InvalidSPDXAnalysisException on SPDX parsing errors
273268
*/
274269
private static void upgradeArtifactOf(Model model, String documentNamespace) throws InvalidSPDXAnalysisException {
275270
String docNamespace = documentNamespace + "#";
276-
Set<String> addedDoapProjects = new HashSet<String>(); // prevent duplicates
271+
Set<String> addedDoapProjects = new HashSet<>(); // prevent duplicates
277272
List<Statement> statementsToRemove = new ArrayList<>();
278273
Property artifactOfProperty = model.createProperty("http://spdx.org/rdf/terms#artifactOf");
279274
Property relationshipProperty = model.createProperty(SpdxConstantsCompatV2.SPDX_NAMESPACE + SpdxConstantsCompatV2.PROP_RELATIONSHIP.getName());
@@ -291,7 +286,7 @@ private static void upgradeArtifactOf(Model model, String documentNamespace) thr
291286
while (iter.hasNext()) {
292287
statementsToRemove.add(iter.next());
293288
}
294-
Resource pkg = convertDoapProjectToSpdxPackage(model, doapProject, docNamespace + idPrefix + Integer.toString(nextSpdxIdNum));
289+
Resource pkg = convertDoapProjectToSpdxPackage(model, doapProject, docNamespace + idPrefix + nextSpdxIdNum);
295290
if (pkg.isURIResource() && !addedDoapProjects.contains(pkg.getURI())) {
296291
addedDoapProjects.add(pkg.getURI());
297292
nextSpdxIdNum = getNexId(model, docNamespace, idPrefix, nextSpdxIdNum);
@@ -305,10 +300,10 @@ private static void upgradeArtifactOf(Model model, String documentNamespace) thr
305300

306301
/**
307302
* Creates an anonymous relationship resource
308-
* @param model
309-
* @param pkg
310-
* @param relationshipType
311-
* @return
303+
* @param model RDF model
304+
* @param relatedElement related element
305+
* @param relationshipType SPDX relationship type
306+
* @return resource for the relationship
312307
*/
313308
private static Resource createRelationship(Model model, Resource relatedElement, RelationshipType relationshipType) {
314309
Resource retval = model.createResource();
@@ -321,28 +316,28 @@ private static Resource createRelationship(Model model, Resource relatedElement,
321316
}
322317

323318
/**
324-
* @param model
325-
* @param docNamespace
326-
* @param idPrefix
319+
* @param model RDF model
320+
* @param docNamespace Namespace or URI for the SPDX document
321+
* @param idPrefix prefix for the ID to be used
327322
* @param startingNum Starting number to search for the next available ID
328323
* @return the next ID number available
329324
*/
330325
private static int getNexId(Model model, String docNamespace, String idPrefix, int startingNum) {
331326
int retval = startingNum;
332-
Resource idResource = model.getResource(docNamespace + idPrefix + Integer.toString(retval));
327+
Resource idResource = model.getResource(docNamespace + idPrefix + retval);
333328
while (model.containsResource(idResource)) {
334329
retval++;
335-
idResource = model.getResource(docNamespace + idPrefix + Integer.toString(retval));
330+
idResource = model.getResource(docNamespace + idPrefix + retval);
336331
}
337332
return retval;
338333
}
339334

340335
/**
341336
* Convert a DOAP project resource into a package resource
342-
* @param model
343-
* @param doapProject
344-
* @return
345-
* @throws InvalidSPDXAnalysisException
337+
* @param model RDF model
338+
* @param doapProject DOAP project to convert
339+
* @return a related package representing the DOAP project
340+
* @throws InvalidSPDXAnalysisException on SPDX parsing errors
346341
*/
347342
private static Resource convertDoapProjectToSpdxPackage(Model model, Resource doapProject, String packageUri) throws InvalidSPDXAnalysisException {
348343
String packageName;
@@ -354,7 +349,7 @@ private static Resource convertDoapProjectToSpdxPackage(Model model, Resource do
354349
if (Objects.isNull(packageName)) {
355350
throw new InvalidSPDXAnalysisException("Missing required DOAP project name");
356351
}
357-
String homePage = null;
352+
String homePage;
358353
Property homePageProperty = model.createProperty(SpdxConstantsCompatV2.DOAP_NAMESPACE + SpdxConstantsCompatV2.PROP_PROJECT_HOMEPAGE.getName());
359354
try {
360355
homePage = doapProject.getProperty(homePageProperty).getString();

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/**
22
* Copyright (c) 2020 Source Auditor Inc.
33
*
4+
* <p>
45
* SPDX-License-Identifier: Apache-2.0
5-
*
6+
* <p>
67
* Licensed under the Apache License, Version 2.0 (the "License");
78
* you may not use this file except in compliance with the License.
89
* You may obtain a copy of the License at
9-
*
10+
* <p>
1011
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
12+
* <p>
1213
* Unless required by applicable law or agreed to in writing, software
1314
* distributed under the License is distributed on an "AS IS" BASIS,
1415
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -31,15 +32,15 @@ public class MissingDataTypeAndClassRestriction extends SpdxRdfException {
3132
private static final long serialVersionUID = 1L;
3233

3334
/**
34-
* @param msg
35+
* @param msg error message
3536
*/
3637
public MissingDataTypeAndClassRestriction(String msg) {
3738
super(msg);
3839
}
3940

4041
/**
41-
* @param msg
42-
* @param inner
42+
* @param msg error message
43+
* @param inner exception
4344
*/
4445
public MissingDataTypeAndClassRestriction(String msg, Throwable inner) {
4546
super(msg, inner);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/**
22
* Copyright (c) 2020 Source Auditor Inc.
3-
*
3+
* <p>
44
* SPDX-License-Identifier: Apache-2.0
5-
*
5+
* <p>
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
9-
*
9+
* <p>
1010
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
11+
* <p>
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -31,10 +31,10 @@ public enum OutputFormat {
3131
TURTLE("TURTLE"),
3232
JSON_LD("JSON-LD");
3333

34-
private String type;
35-
private OutputFormat(String type) {
34+
private final String type;
35+
OutputFormat(String type) {
3636
this.type = type;
3737
}
38-
String getType() { return type; };
38+
String getType() { return type; }
3939
}
4040

0 commit comments

Comments
 (0)