From a941e0772e93c9f77326564b941e5897bef5bf89 Mon Sep 17 00:00:00 2001 From: zhaolida98 Date: Fri, 8 Apr 2022 11:07:56 +0800 Subject: [PATCH] Add examples for relationship creation --- .../org/spdx/examples/SimpleSpdxDocument.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/examples/org/spdx/examples/SimpleSpdxDocument.java b/examples/org/spdx/examples/SimpleSpdxDocument.java index 14b18bc..c97c77a 100644 --- a/examples/org/spdx/examples/SimpleSpdxDocument.java +++ b/examples/org/spdx/examples/SimpleSpdxDocument.java @@ -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 warnings = document.verify(); if (warnings.size() > 0) {