Skip to content

Commit 4a04e0a

Browse files
committed
Update documentation for init
1 parent 3b3afd1 commit 4a04e0a

File tree

2 files changed

+59
-34
lines changed

2 files changed

+59
-34
lines changed

GETTING-STARTED.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
# Getting Started
22

3+
## Installation
4+
5+
The library is available in Maven Central as
6+
[`org.spdx:java-spdx-library`](https://search.maven.org/artifact/org.spdx/java-spdx-library)
7+
(note the order of the word "java-spdx").
8+
9+
If you are using Maven, you can add the following dependency in your POM file:
10+
11+
```xml
12+
<dependency>
13+
<groupId>org.spdx</groupId>
14+
<artifactId>java-spdx-library</artifactId>
15+
<version>(,2.0]</version>
16+
</dependency>
17+
```
18+
19+
## Using the library for license analysis
20+
21+
The static class `org.spdx.library.model.license.LicenseInfoFactory` supports the parsing of
22+
SPDX license expressions, creation, and comparison of SPDX licenses.
23+
24+
The `LicenseInfoFactory` will initialize the library and work with both the SPDX spe version 3
25+
and the SPDX spec version 2 license models. SPDX spec version to methods end in `CompatV2`.
26+
327
## Initialization
428

529
Before executing any of the model class methods, the model versions need to be initialized. This is done by calling:
@@ -140,4 +164,7 @@ We now need to add the required fields to make this a valid SPDX document:
140164
myDoc.createChecksum(ChecksumAlgorithm.SHA1, "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"))
141165
.build(); // The more complex model objects follows a builder pattern
142166
myDoc.getDocumentDescribes().add(file);
143-
```
167+
```
168+
169+
Similar to SPDX spec version 3, the create methods in the SPDX spec version 2 objects will copy the
170+
model store, copy manager, and document uri to the newly created objects.

README.md

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,13 @@ document used for the SPDX model object.
6060

6161
## Getting Started
6262

63-
The library is available in Maven Central as
64-
[`org.spdx:java-spdx-library`](https://search.maven.org/artifact/org.spdx/java-spdx-library)
65-
(note the order of the word "java-spdx").
66-
67-
If you are using Maven, you can add the following dependency in your POM file:
68-
69-
```xml
70-
<dependency>
71-
<groupId>org.spdx</groupId>
72-
<artifactId>java-spdx-library</artifactId>
73-
<version>(,2.0]</version>
74-
</dependency>
75-
```
63+
See the [GETTING-STARTED.md](GETTING-STARTED.md) file for how to get started in different scenarios.
64+
65+
## API Documentation
7666

7767
The API documentation is available at:
7868
<https://spdx.github.io/Spdx-Java-Library/>
7969

80-
There are a couple of static classes that help common usage scenarios:
81-
82-
- `org.spdx.library.SpdxModelFactory` supports the creation of specific
83-
model objects
84-
- `org.spdx.library.model.license.LicenseInfoFactory` supports the parsing of
85-
SPDX license expressions, creation, and comparison of SPDX licenses
86-
8770
## Configuration options
8871

8972
`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`.
@@ -100,23 +83,38 @@ of Spdx-Java-Library.
10083

10184
## Initialization
10285

103-
The first thing that needs to be done in your implementation is call `SpdxModelFactory.init()` - this will load all the supported versions.
86+
Before executing any of the model class methods, the model versions need to be initialized. This is done by calling:
87+
88+
```java
89+
SpdxModelFactory.init();
90+
```
91+
92+
SPDX data is stored in a "model store" and copying between model stores requires a copy manager.
10493

105-
If you are programmatically creating SPDX data, you will start by creating a model store.
106-
The simplest model store is an in-memory model store which can be created with `store = new InMemSpdxStore()`.
94+
A simple store is provided in the java library. To create the simple in-memory model store and a copy manager, execute the following:
10795

108-
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()`.
96+
```java
97+
InMemSpdxStore modelStore = new InMemSpdxStore();
98+
IModelCopyManager copyManager = new ModelCopyManager();
99+
```
100+
101+
Many factory and helper methods in the library make use of a DefaultModelStore
102+
if no model store or copy manager is specified.
103+
104+
The `SpdxModelFactory.init()` will create defaults for this purpose.
105+
106+
If you would like to use a different default model store and/or copy manager, you can call:
107+
108+
```java
109+
DefaultModelStore.initialize(IModelStore newModelStore, String newDefaultDocumentUri,
110+
IModelCopyManager newDefaultCopyManager);
111+
```
109112

110-
The first object you create will depend on the major version:
113+
The `newDefaultDocumentUri` is a default document URI used for SPDX Spec version 2 model objects.
111114

112-
- For SPDX 2.X, you would start by creating an `SpdxDocument`.
113-
- The factory method `SpdxDocument document = SpdxModelFactory.createSpdxDocumentV2(IModelStore modelStore, String documentUri, IModelCopyManager copyManager)` will create a new SPDX document.
114-
- Once created, you can use the setters to set the specific fields.
115-
- You can then use the convenience create methods on the document to create additional SPDX objects (e.g. `document.createSpdxFile(...)`);
116-
- For SPDX 3.X, you will start with a `CreationInfo` class.
117-
- 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.
118-
- 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)`.
119-
- The created objects will copy the creationInfo.
115+
IMPORTANT NOTE: The call to `DefaultModelStore.initialize` must be made prior to or immediately after the call
116+
to `SpdxModelFactory.init()`. Otherwise, any data stored in the previous default model object will be lost.
117+
The `SpdxModelFactory.init()` will not overwrite an already initialized default model store.
120118

121119
## Update for new versions of the spec
122120

0 commit comments

Comments
 (0)