Skip to content

Commit

Permalink
Merge pull request #55 from zhaolida98/Add-relation-creation-example
Browse files Browse the repository at this point in the history
Add examples for relationship creation
  • Loading branch information
goneall authored Apr 8, 2022
2 parents 8622229 + a941e07 commit 09c4684
Showing 1 changed file with 17 additions and 1 deletion.
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

0 comments on commit 09c4684

Please sign in to comment.