Skip to content

Commit c52f52f

Browse files
committed
Redesigned spec conversion
Implementation is not complete - this is an intermediate checkin Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
1 parent 0a76886 commit c52f52f

9 files changed

Lines changed: 1148 additions & 231 deletions

File tree

GETTING-STARTED.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Getting Started
2+
3+
## SPDX Version 3
4+
5+
### Programmatically Creating SPDX Data
6+
7+
Before executing any of the model class methods, the model versions need to be intialized. This is done by calling:
8+
9+
```
10+
SpdxModelFactory.init();
11+
```
12+
13+
SPDX data is stored in a "model store" and copying between model stores requires a copy manager.
14+
15+
A simple store is provided in the java library. To create the simple in-memory model store and a copy manager, execute the following:
16+
17+
```
18+
InMemSpdxStore modelStore = new InMemSpdxStore();
19+
IModelCopyManager copyManager = new ModelCopyManager();
20+
```
21+
22+
All SPDX elements are required to have a unique SPDX ID which is an Object URI. In the SPDX Java libraries, this is commonly referred to as the `objectUri` to avoid confusion with the SPDX 2.X version short SPDX IDs.
23+
24+
A good practice is to create a common prefix to use for your programatic session. The prefix should be unique to the session. There are convenience methods in the library to append identifiers uniques to the model store.
25+
26+
In these examples, we'll use:
27+
28+
```
29+
String prefix = "https://org.spdx.spdxdata/899b1918-f72a-4755-9215-6262b3c346df/";
30+
```
31+
32+
Since SPDX 3.0 requires creation info on every element, the easiest way to start is to use the SPDX 3 model convenience method `SpdxModelClassFactory.createCreationInfo(...)` which will create the `Agent` and `CreationInfo` classes which can be added to all of the subsequent elements.
33+
34+
For example:
35+
36+
```
37+
CreationInfo creationInfo = SpdxModelClassFactory.createCreationInfo(
38+
modelStore, prefix + "Agent/Gary01123", "Gary O'Neall",
39+
copyManager);
40+
```
41+
42+
We're now ready to create our first SPDX element. You can start anywhere, but let's start with an SBOM element.
43+
44+
There is a factory method you can use to get started:
45+
46+
```
47+
Sbom sbom = SpdxModelClassFactory.getModelObject(modelStore,
48+
prefix + "sbom/mysbom", SpdxConstantsV3.SOFTWARE_SBOM,
49+
copyManager, true, prefix);
50+
```
51+
52+
Let's not forget to add the creation info:
53+
54+
```
55+
sbom.setCreationInfo(creationInfo);
56+
```
57+
58+
From here on, things get easier. We can get and set properties to the sbom we just created.
59+
60+
If we want to create another SPDX object or element, we can use the builder convenience methods available to all SPDX objects. For example, if we want to create a package to add to the SBOM we can call:
61+
62+
```
63+
sbom.getElements().add(
64+
sbom.createSpdxPackage(prefix + "package/mypackage")
65+
.setName("Package Name")
66+
.build()
67+
);
68+
```
69+
70+
The model store, creation info, copy manager, and prefix information will all be copied from the sbom allowing you to focus just on the properties you need to add.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"typeUriMap" : {
3+
"http://spdx.org/rdf/terms#SpdxDocument" : "https://spdx.org/rdf/3.0.0/terms/Core/SpdxDocument",
4+
"http://spdx.org/rdf/terms#Package" : "https://spdx.org/rdf/3.0.0/terms/Software/Package",
5+
"http://spdx.org/rdf/terms#CreationInfo" : "",
6+
"http://spdx.org/rdf/terms#Checksum" : "",
7+
"http://spdx.org/rdf/terms#AnyLicenseInfo" : "",
8+
"http://spdx.org/rdf/terms#SimpleLicensingInfo" : "",
9+
"http://spdx.org/rdf/terms#ConjunctiveLicenseSet" : "",
10+
"http://spdx.org/rdf/terms#DisjunctiveLicenseSet" : "",
11+
"http://spdx.org/rdf/terms#ExtractedLicensingInfo" : "",
12+
"http://spdx.org/rdf/terms#License" : "",
13+
"http://spdx.org/rdf/terms#ListedLicense" : "",
14+
"http://spdx.org/rdf/terms#LicenseException" : "",
15+
"http://spdx.org/rdf/terms#ListedLicenseException" : "",
16+
"http://spdx.org/rdf/terms#OrLaterOperator" : "",
17+
"http://spdx.org/rdf/terms#WithExceptionOperator" : "",
18+
"http://spdx.org/rdf/terms#File" : "",
19+
"http://spdx.org/rdf/terms#Review" : "",
20+
"http://spdx.org/rdf/terms#PackageVerificationCode" : "",
21+
"http://spdx.org/rdf/terms#Annotation" : "",
22+
"http://spdx.org/rdf/terms#Relationship" : "",
23+
"http://spdx.org/rdf/terms#SpdxItem" : "",
24+
"http://spdx.org/rdf/terms#SpdxElement" : "",
25+
"http://spdx.org/rdf/terms#SpdxNoneElement" : "",
26+
"http://spdx.org/rdf/terms#SpdxNoAssertionElement" : "",
27+
"http://spdx.org/rdf/terms#ExternalDocumentRef" : "",
28+
"http://spdx.org/rdf/terms#ExternalRef" : "",
29+
"http://spdx.org/rdf/terms#ReferenceType" : "",
30+
"http://spdx.org/rdf/terms#Snippet" : "",
31+
"http://spdx.org/rdf/terms#SpdxNoneLicense" : "",
32+
"http://spdx.org/rdf/terms#SpdxNoAssertionLicense" : "",
33+
"http://spdx.org/rdf/terms#ExternalSpdxElement" : "",
34+
"http://spdx.org/rdf/terms#ExternalExtractedLicenseInfo" : "",
35+
"http://spdx.org/rdf/terms#CrossRef" : "",
36+
"http://usefulinc.com/ns/doap#Project" : "",
37+
"http://www.w3.org/2000/01/rdf-schema#StartEndPointer" : "",
38+
"http://www.w3.org/2000/01/rdf-schema#ByteOffsetPointer" : "",
39+
"http://www.w3.org/2000/01/rdf-schema#CompoundPointer" : "",
40+
"http://www.w3.org/2000/01/rdf-schema#LineCharPointer" : "",
41+
"http://www.w3.org/2000/01/rdf-schema#SinglePointer" : ""
42+
},
43+
"fromTypeStructuralChange" : {
44+
45+
},
46+
"propertyUriMap" : {
47+
48+
},
49+
"individualUriMap" : {
50+
"http://spdx.org/rdf/terms#noassertion" : {
51+
"https://spdx.org/rdf/3.0.0/terms/ExpandedLicensing/NoAssertionLicense" : {
52+
"subclassOf" : [
53+
"https://spdx.org/rdf/3.0.0/terms/SimpleLicensing/AnyLicenseInfo"
54+
],
55+
"excludeSubclassOf" : []
56+
},
57+
"https://spdx.org/rdf/3.0.0/terms/Core/NoAssertionElement" : {
58+
"subclassOf" : [
59+
"https://spdx.org/rdf/3.0.0/terms/Core/Element"
60+
],
61+
"excludeSubclassOf" : [
62+
"https://spdx.org/rdf/3.0.0/terms/SimpleLicensing/AnyLicenseInfo"
63+
]
64+
}
65+
},
66+
"http://spdx.org/rdf/terms#none" : {
67+
"https://spdx.org/rdf/3.0.0/terms/ExpandedLicensing/NoneLicense" : {
68+
"subclassOf" : [
69+
"https://spdx.org/rdf/3.0.0/terms/SimpleLicensing/AnyLicenseInfo"
70+
],
71+
"excludeSubclassOf" : []
72+
},
73+
"https://spdx.org/rdf/3.0.0/terms/Core/NoneElement" : {
74+
"subclassOf" : [
75+
"https://spdx.org/rdf/3.0.0/terms/Core/Element"
76+
],
77+
"excludeSubclassOf" : [
78+
"https://spdx.org/rdf/3.0.0/terms/SimpleLicensing/AnyLicenseInfo"
79+
]
80+
}
81+
}
82+
}
83+
}

src/main/java/org/spdx/library/ModelSpecConverter.java renamed to src/main/java/org/spdx/conversion/ISpdxConverter.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package org.spdx.library;
18+
package org.spdx.conversion;
1919

2020
/**
2121
* @author Gary O'Neall
2222
*
23-
* Manages the conversion of classes and properties between 2 versions of an SPDX specification
23+
* Interface for classes that can convert from one SPDX spec version to another
24+
*
2425
*/
25-
public class ModelSpecConverter {
26-
27-
String convertType(String fromType) {
28-
//TODO Implement
29-
return null;
30-
}
26+
public interface ISpdxConverter {
3127

3228
}

0 commit comments

Comments
 (0)