spdx / tools-java

SPDX Command Line Tools using the Spdx-Java-Library
Apache License 2.0
59 stars 34 forks source link

how to get SPDXpackages form spdxDocument #137

Closed lunbin closed 1 year ago

lunbin commented 1 year ago

i have got spdxDocument by deserializeDocument function, like this:

  spdxDocument = SpdxToolsHelper.deserializeDocument(new File(file), SpdxToolsHelper.SerFileType.JSON);

the file like this

but spdxDocument do not have getPackages() ,like this function , how can i get the package list use tools-java?

please help me. thank you!

lunbin commented 1 year ago

@kemitchell @sschuberth @vargenau

goneall commented 1 year ago

@lunbin - There are a couple of approaches depending on what you are trying to accomplish with the packages.

If you just want to get all the packages described in the document independent of how that package is referenced or used, you can use the SpdxModelFactory.getelements() method. You can find an example of this in the tag/value parser: https://github.com/spdx/spdx-java-tagvalue-store/blob/23dcbe43993f90cd0569b47d799a02d390e98bf8/src/main/java/org/spdx/tag/CommonCode.java#L235

If you want to find the packages that are described directly or indirectly by the SPDX Document, you can traverse the graph of relationships starting with the documentDescribes collection which is the root of the relationships graph for the document.