Git Product home page Git Product logo

Comments (5)

maxhbr avatar maxhbr commented on May 24, 2024

but get LicenseRef-gnrtd0 everywhere else in the output document when using licenseRef1.

Can you add an example document and a minimal full code example?

from spdx-java-library.

armintaenzertng avatar armintaenzertng commented on May 24, 2024
public static void buildDocument() throws InvalidSPDXAnalysisException, IOException {
        var modelStore = new MultiFormatStore(new InMemSpdxStore(), MultiFormatStore.Format.XML, MultiFormatStore.Verbose.COMPACT);
        var documentUri = "https://some.namespace";
        var copyManager = new ModelCopyManager();

        var document = SpdxModelFactory.createSpdxDocument(modelStore, documentUri, copyManager);

        document.setName("document name");

        var extractedLicenseInfo1 = new ExtractedLicenseInfo(modelStore, documentUri, "LicenseRef-1", copyManager, true);
        var licenseRef1 = LicenseInfoFactory.parseSPDXLicenseString("LicenseRef-1");


        var sha1Checksum = Checksum.create(modelStore, documentUri, ChecksumAlgorithm.SHA1, "d6a770ba38583ed4bb4525bd96e50461655d2758");
        var file = document.createSpdxFile("SPDXRef-somefile", "./foo.txt", licenseRef1, List.of(), null, sha1Checksum).build();

        document.addExtractedLicenseInfos(extractedLicenseInfo1);
        document.getDocumentDescribes().add(file);

        modelStore.serialize(documentUri, new FileOutputStream("temp.xml"));
}

yields

<?xml version='1.0' encoding='UTF-8'?>
<Document>
  <SPDXID>SPDXRef-DOCUMENT</SPDXID>
  <spdxVersion>SPDX-2.3</spdxVersion>
  <creationInfo>
    <created>2022-10-13T11:08:12Z</created>
    <creators>Tool: SPDX Tools</creators>
    <licenseListVersion>3.18</licenseListVersion>
  </creationInfo>
  <name>document name</name>
  <dataLicense>CC0-1.0</dataLicense>
  <hasExtractedLicensingInfos>
    <licenseId>LicenseRef-1</licenseId>
  </hasExtractedLicensingInfos>
  <documentDescribes>SPDXRef-somefile</documentDescribes>
  <documentNamespace>https://some.namespace</documentNamespace>
  <files>
    <SPDXID>SPDXRef-somefile</SPDXID>
    <checksums>
      <algorithm>SHA1</algorithm>
      <checksumValue>d6a770ba38583ed4bb4525bd96e50461655d2758</checksumValue>
    </checksums>
    <fileName>./foo.txt</fileName>
    <licenseConcluded>LicenseRef-gnrtd0</licenseConcluded>
  </files>
</Document>

from spdx-java-library.

goneall avatar goneall commented on May 24, 2024

This is not the intended behavior. I'll take a look and see what's going on in the code.

from spdx-java-library.

goneall avatar goneall commented on May 24, 2024

In looking a bit closer - the library is working correctly.

The issue is you are using the default model store for the license parser.

In your above example, change:

var licenseRef1 = LicenseInfoFactory.parseSPDXLicenseString("LicenseRef-1");

to:

var licenseRef1 = LicenseInfoFactory.parseSPDXLicenseString("LicenseRef-1", modelStore, documentUri, copyManager);

A bit more background and context. Anytime you create a ModelObject it is stored in a ModelStore. This includes ExtractedLicenseInfo. When you created your ExtractedLicenseInfo, you specified a specific model store. When you called the parseSPDXLicenseString, you did not specify a model store so it used the default. Since the default model store didn't have the LicenseRef-1, it created a new and different ExtractedLicenseInfo. When you added as a concluded license, the library recognized it wasn't present in the model store for the File and copied what it had from the default model store to the specified modelStore. Since there already existed a "LicenseRef-1", it generated a new ID so that it would not conflict.

from spdx-java-library.

armintaenzertng avatar armintaenzertng commented on May 24, 2024

Oh yeah, that makes sense!
Thanks for the comprehensive advice, Gary! :)

from spdx-java-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.