Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples for relationship creation #55

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion examples/org/spdx/examples/SimpleSpdxDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,23 @@ public static void main(String[] args) {
* example above
*/

document.getDocumentDescribes().add(pkg); // Let's add the package as the described element for the document
/* Let's add the package relationships to the document
* This step
*/
// This step will add a relationship between document and pkg as "DESCRIBES".
document.getDocumentDescribes().add(pkg);
// Let's create another package
pkgId = modelStore.getNextId(IdType.SpdxId, documentUri);
SpdxPackage childPkg = document.createPackage(pkgId, "Child Example Package Name", pkgConcludedLicense,
"Copyright example.org", pkgDeclaredLicense)
.setFilesAnalyzed(false) // Default is true and we don't want to add all the required fields
.setComment("This package is used as an example in creating an SPDX document from scratch")
.setDownloadLocation("NOASSERTION")
.build();
// Then create a DEPEND_ON relation by relationship factory
Relationship relationship = pkg.createRelationship(childPkg, RelationshipType.DEPENDS_ON, "");
pkg.addRelationship(relationship);

// That's for creating the simple document. Let's verify to make sure nothing is out of spec
List<String> warnings = document.verify();
if (warnings.size() > 0) {
Expand Down