spdx/tools-java

how to get SPDXpackages form spdxDocument

lunbin opened this issue · 2 comments

lunbin commented

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 - 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.