You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
24
+
A good practice is to create a common prefix to use for your programmatic session. The prefix should be unique to the session. There are convenience methods in the library to append identifiers unique to the model store.
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.
From here on, things get easier. We can get and set properties to the sbom we just created.
59
59
60
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:
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.
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.
Copy file name to clipboardExpand all lines: README-SPI-MODEL-STORE.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,18 +9,19 @@ NOTE: This README is currently under development.
9
9
## Storing and Retrieving Values
10
10
11
11
### Converting Object Types
12
+
12
13
The class org.spdx.library.ModelStorageClassConverter contains static methods to convert object types supported by the SPI.
13
14
14
15
storedObjectToModelObject will convert a stored object to a Model object.
15
16
16
17
modelObjectToStoredObject will convert a model object to a stored object.
17
18
18
-
These methods should be used to avoid common errors when converting between supported object types.
19
+
These methods should be used to avoid common errors when converting between supported object types.
19
20
20
21
## Using the Serialization interfaces
21
22
22
23
Note: You can extend the default org.spdx.storage.simple.InMemSpdxStore with a couple of serialization / de-serialization methods to implement a storage interface to a serializeable format (such as a JSON or YAML file).
Copy file name to clipboardExpand all lines: README-V3-UPGRADE.md
+7-4Lines changed: 7 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,7 @@ The packages in `org.spdx.licenseTemplates` are now in the `java-spdx-core` repo
22
22
A new class `LicenseTextHelper` was added and the method `isLicenseTextEquivalent(String, String)` along with many supporting methods were moved to `LicenseTextHelper` from `org.spdx.utility.compare.LicenseCompareHelper`.
23
23
24
24
## Changes to SPDX version 2 package, class, and method names
25
+
25
26
To support accessing SPDX 2.X model object while updating the library for SPDX 3.0 support, the package names for the SPDX 2.X model objects are now named `org.spdx.library.model.v2.[package]`.
26
27
27
28
Many of the class and property names have been changed to append `CompatV2` to clearly designate a compatible object is being referenced.
@@ -37,14 +38,16 @@ will check for the old DocumentRef format and attempt a conversion.
37
38
Note that this incompatibility was introduced due to using a common mode store API which in some cases will not have the documentUri as a required parameter
38
39
39
40
## Changes to deserialize interface
41
+
40
42
Since SPDX documents are not generally required in SPDX spec version 3.0, the SPDX namespace was removed from the return value for deserialized and also removed as a parameter for the serialize method. Serialize will now serialize all objects - which may be multiple SPDX documents.
41
43
42
44
To find all the SPDX documents in a serialization, you can execute:
after deserialization to get a list of all SPDX documents.
49
52
50
53
For the RDF store, to keep compatible with the SPDX 2.X requirements, it now only supports a single document namespace.
@@ -54,9 +57,9 @@ For the RDF store, to keep compatible with the SPDX 2.X requirements, it now onl
54
57
### Change propertyName to propertyDescriptor
55
58
56
59
One significant change to the model store which impacts most of the API's.
57
-
All `String``propertyName` properties are replaced by a `propertyDescriptor` of type `ProperyDescriptor`.
60
+
All `String``propertyName` properties are replaced by a `propertyDescriptor` of type `PropertyDescriptor`.
58
61
The `PropertyDescriptor` has a `name` property and a `nameSpace` property.
59
-
The property constants defined in `org.spdx.library.SpdxConstants` have all been changed to use constant `PropertyDescriptor`s.
62
+
The property constants defined in `org.spdx.library.SpdxConstants` have all been changed to use constant `PropertyDescriptor`s.
60
63
If you're using the constants, you may not need to change much beyond the method signatures for anything that was passing along the `propertyName`.
61
64
62
65
### Make DocumentNamespace Optional
@@ -75,4 +78,4 @@ There is a convenience helper method `CompatibleModelStoreWrapper.typedValueFrom
75
78
76
79
To help with the migration, the `CompatibleModelStoreWrapper` class was introduced supporting the `IModelStore` interface taking a base store as a parameter in the constructor. This class "wraps" the base store and supports the SPDX 2 methods which take the document namespace parameters.
77
80
78
-
There is also a convenience static method to convert a namespace and ID to an Object URI.
81
+
There is also a convenience static method to convert a namespace and ID to an Object URI.
@@ -17,17 +18,21 @@ The library does support the spec versions 2.X and 3.X.
17
18
See the [README-V3-UPGRADE.md](README-V3-UPGRADE.md) file for information on how to upgrade from earlier versions of the library.
18
19
19
20
## Storage Interface
21
+
20
22
The Spdx-Java-Library allows for different implementations of SPDX object storage. The storage facility implements the org.spdx.storage.IModelStore interface. This is a low level Service Provider Interface (SPI). The ISerializableModelStore extends the IModelStore and supports serializing and de-serializing the store to an I/O Stream. This interface is currently used to implement JSON, XML, YAML, and RDF/XML formats. The default storage interface is an in-memory Map which should be sufficient for light weight usage of the library.
21
23
22
-
Most common use of the library would de-serialize an existing SPDX document using one of the supported formats and model stores. To create SPDX objects from scratch, simply create the Java objects found in the org.spdx.library.model package. The model follows the [SPDX Object Model](https://github.com/spdx/spdx-spec/blob/2a7aff7afa089a774916bd5c64fc2cb83637ea07/model/SPDX-UML-Class-Diagram.jpg). The model objects themselves are stateless and do not store information. All information is retrieved from the model store when properties are access. Storage to the classes will store the updates through the use of the storage interface.
24
+
Most common use of the library would de-serialize an existing SPDX document using one of the supported formats and model stores. To create SPDX objects from scratch, simply create the Java objects found in the org.spdx.library.model package. The model follows the [SPDX Object Model](https://github.com/spdx/spdx-spec/blob/2a7aff7afa089a774916bd5c64fc2cb83637ea07/model/SPDX-UML-Class-Diagram.jpg). The model objects themselves are stateless and do not store information. All information is retrieved from the model store when properties are access. Storage to the classes will store the updates through the use of the storage interface.
23
25
24
26
## Multi-Threaded Considerations
27
+
25
28
The methods enterCriticalSection and leaveCritialSection are available to support multi-threaded applications. These methods serialize access to the model store for the specific SPDX document used for the SPDX model object.
26
29
27
30
## Getting Started
31
+
28
32
The library is available in [Maven Central org.spdx:java-spdx-library](https://search.maven.org/artifact/org.spdx/java-spdx-library).
29
33
30
34
If you are using Maven, you can add the following dependency in your POM file:
35
+
31
36
```xml
32
37
<dependency>
33
38
<groupId>org.spdx</groupId>
@@ -43,12 +48,12 @@ There are a couple of static classes that help common usage scenarios:
43
48
- org.spdx.library.SpdxModelFactory supports the creation of specific model objects
44
49
- org.spdx.library.model.license.LicenseInfoFactory supports the parsing of SPDX license expressions, creation, and comparison of SPDX licenses
45
50
46
-
47
51
## Configuration options
48
52
49
53
`Spdx-Java-Library` can be configured using either Java system properties or a Java properties file located in the runtime CLASSPATH at `/resources/spdx-java-library.properties`.
50
54
51
55
The library has these configuration options:
56
+
52
57
1.`org.spdx.useJARLicenseInfoOnly` - a boolean that controls whether the (potentially out of date) listed license information bundled inside the JAR is used (true), vs the library downloading the latest files from the SPDX website (false). Default is false (always download the latest files from the SPDX website).
53
58
2.`org.spdx.downloadCacheEnabled` - a boolean that enables or disables the download cache. Defaults to `false` (the cache is disabled). The cache location is determined as per the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) (i.e. `${XDG_CACHE_HOME}/Spdx-Java-Library` or `${HOME}/.cache/Spdx-Java-Library`).
54
59
3.`org.spdx.downloadCacheCheckIntervalSecs` - a long that controls how often each cache entry is rechecked for staleness, in units of seconds. Defaults to 86,400 seconds (24 hours). Set to 0 (zero) to have each cache entry checked every time (note: this will result in a lot more network I/O and negatively impact performance, albeit there is still a substantial performance saving vs not using the cache at all).
@@ -57,13 +62,15 @@ Note that these configuration options can only be modified prior to first use of
57
62
58
63
The first thing that needs to be done in your implementation is call `SpdxModelFactory.init()` - this will load all the supported versions.
59
64
60
-
If you are programatically creating SPDX data, you will start by creating a model store. The simplest model store is an in-memory model store which can be created with `store = new InMemSpdxStore()`. A copy manager will be needed if you are working with more than one store (e.g. a serialized format of SPDX data and in memory). If you're not sure, you should just create one. This can be done with `copyManager = new ModelCopyManager()`.
65
+
If you are programmatically creating SPDX data, you will start by creating a model store. The simplest model store is an in-memory model store which can be created with `store = new InMemSpdxStore()`. A copy manager will be needed if you are working with more than one store (e.g. a serialized format of SPDX data and in memory). If you're not sure, you should just create one. This can be done with `copyManager = new ModelCopyManager()`.
61
66
62
67
The first object you create will depend on the major version:
68
+
63
69
- For SPDX 2.X, you would start by creating an SpdxDocument. The factory method `SpdxDocument document = SpdxModelFactory.createSpdxDocumentV2(IModelStore modelStore, String documentUri, IModelCopyManager copyManager)` will create a new SPDX document. Once created, you can use the setters to set the specific fields. You can then use the convenience create methods on the document to create additional SPDX objects (e.g. `document.createSpdxFile(...)`);
64
-
- For SPDX 3.X, you will start with a CreationInfo class. The factory method `CreationInfo creationInfo = SpdxModelClassFactory.createCreationInfo(IModelStore modelStore, String createdByUri,String createdByName, @Nullable IModelCopyManager copyManager)` will create and initialize a CreationInfo with today's date and the Agent information. To create any additional objects, you can use the builder convenience methods from the creationInfo (or any Elements created by the creationInfo) (e.g. `creationInfo.createSoftwareSpdxFile(String spdxFileObjectUri)`. The created objects will copy the creationInfo.
70
+
- For SPDX 3.X, you will start with a CreationInfo class. The factory method `CreationInfo creationInfo = SpdxModelClassFactory.createCreationInfo(IModelStore modelStore, String createdByUri,String createdByName, @Nullable IModelCopyManager copyManager)` will create and initialize a CreationInfo with today's date and the Agent information. To create any additional objects, you can use the builder convenience methods from the creationInfo (or any Elements created by the creationInfo) e.g. `creationInfo.createSoftwareSpdxFile(String spdxFileObjectUri)`. The created objects will copy the creationInfo.
65
71
66
72
## Update for new versions of the spec
73
+
67
74
To update Spdx-Java-Library, the following is a very brief checklist:
68
75
69
76
1. Create a Java .jar file for the new version which contains an implementation of `ISpdxModelInfo` - typically named SpdxModelInfoVXXX - where XXX is the version of the spec.
@@ -72,4 +79,5 @@ To update Spdx-Java-Library, the following is a very brief checklist:
72
79
4. Update SpdxModelFactory unit test for the highest version check
73
80
74
81
## Development Status
82
+
75
83
Note: This library is currently unstable, and under development. Reviews, suggestions are welcome. Please enter an issue with any suggestions.
0 commit comments