Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is there no ListedLicense::getId in SPDXv3? #282

Closed
dwalluck opened this issue Jan 24, 2025 · 8 comments
Closed

Why is there no ListedLicense::getId in SPDXv3? #282

dwalluck opened this issue Jan 24, 2025 · 8 comments
Labels
question Further information is requested

Comments

@dwalluck
Copy link
Contributor

dwalluck commented Jan 24, 2025

SPDXv2 has SpdxListedLicense::getId (or SpdxListedLicense::getLicenseId), but there is no equivalent for ListedLicense in SPDXv3. Actually, ListedLicense::toString returns exactly the id, I think, but it's not good to rely on toString for something like that.

@bact bact added the question Further information is requested label Jan 24, 2025
@goneall
Copy link
Member

goneall commented Jan 24, 2025

In Spec version 3, we now only refer to licenses in the serialized file with the full URI (e.g. http://spdx.org/licenses/0BSD).

Since we're generating the SPDXv3 code from the model file, it would be a bit hacky to add a getId call to the model class since it technically isn't part of the model.

You can use the static helper function SpdxListedLicenseModelStore.objectUriToLicenseOrExceptionId(String objectUri) to reliably convert.

@dwalluck
Copy link
Contributor Author

By full URI, you mean I should use getObjectUri()? So, in V3 you aren't to use the short license IDs, but the full URI? Or does no URI imply the STANDARD_LICENSE_URI_PREFIX?

@dwalluck
Copy link
Contributor Author

Isn't ListedLicense::idPrefix always STANDARD_LICENSE_URI_PREFIX? If not, I don't understand why it's hardcoded in SpdxListedLicenseModelStore::objectUriToLicenseOrExceptionId.

I still feel ListedLicense itself should provide some utility methods that actually make use of idPrefix to go back and forth from id <-> objectUri or maybe I am still missing something.

@goneall
Copy link
Member

goneall commented Jan 25, 2025

Isn't ListedLicense::idPrefix always STANDARD_LICENSE_URI_PREFIX? If not, I don't understand why it's hardcoded in SpdxListedLicenseModelStore::objectUriToLicenseOrExceptionId.

I still feel ListedLicense itself should provide some utility methods that actually make use of idPrefix to go back and forth from id <-> objectUri or maybe I am still missing something.

Good point on the ListedLicense::idPrefix. This gives me an idea - we could create a method getId() in the core CoreModelObject which is a superclass of all SPDX objects including ListedLicense. The implementation would be to remove the idPRefix from the objectUri if the prefix exists, otherwise just return the objectUri.

This would restore the getId function to the model version 3 objects without having to implement something that, at least to me, feels like a hack to the code generator for the SPDX spec version 3 model.

@dwalluck
Copy link
Contributor Author

Does SPDXv3 now require the full URI format for identifiers? Or is listing the short identifier like

/*
 * SPDX-License-Identifier: Apache-2.0
 */

still valid in v3?

If it's still used, and we need to work with ids directly, then it seems like the plain id should be there in the code.

@goneall goneall mentioned this issue Jan 29, 2025
11 tasks
@goneall
Copy link
Member

goneall commented Jan 29, 2025

@dwalluck I just created spdx/spdx-java-core#25 which should add a getId() method to the listed license objects (as well as all other SPDX core model objects).

I tested to make sure it worked with both spec version 2 listed licenses and spec version 3 listed licenses. The tests were not exhaustive - they only tested one path for created the listed license using the create license by ID - but I think this should resolve this issue.

Let me know if you agree.

@dwalluck
Copy link
Contributor Author

I think this is fine.

@goneall
Copy link
Member

goneall commented Jan 30, 2025

Fixed with spdx/spdx-java-core#25

@goneall goneall closed this as completed Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants