Skip to content

Commit

Permalink
Allow x.y.z format in license list version
Browse files Browse the repository at this point in the history
Closes #247

Signed-off-by: Gary O'Neall <[email protected]>
  • Loading branch information
goneall committed Aug 19, 2024
1 parent 6388208 commit 579be72
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/spdx/library/SpdxConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public class SpdxConstants {

// License list version Format

public static final Pattern LICENSE_LIST_VERSION_PATTERN = Pattern.compile("^[a-zA-Z0-9]+\\.[a-zA-Z0-9]+");
public static final Pattern LICENSE_LIST_VERSION_PATTERN = Pattern.compile("^[a-zA-Z0-9]+\\.[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+)?");
// Standard value strings
public static String NONE_VALUE = "NONE";
public static String NOASSERTION_VALUE = "NOASSERTION";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ protected List<String> _verify(Set<String> verifiedIds, String specVersion) {
if (SpdxConstants.LICENSE_LIST_VERSION_PATTERN.matcher(version).matches()) {
return null;
} else {
return "License list version does not match the pattern M.N";
return "License list version does not match the pattern M.N or M.N.P";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ public void testGetSetCreators() throws InvalidSPDXAnalysisException {
assertEquals(0, ci.verify().size());
}

public void testSemVerLicenseListVersion() throws InvalidSPDXAnalysisException {
List<String> creators = new ArrayList<>(Arrays.asList(new String[] {"Person: me"}));
DateFormat format = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT);
String date = format.format(new Date());
SpdxCreatorInformation ci = gmo.createCreationInfo(creators, date);
String licenseVersion = "1.1";
ci.setLicenseListVersion(licenseVersion);
assertEquals(0, ci.verify().size());
licenseVersion = "1.1.2";
ci.setLicenseListVersion(licenseVersion);
assertEquals(0, ci.verify().size());
}

public void testGetSetLicenseListVersion() throws InvalidSPDXAnalysisException {
List<String> creators = new ArrayList<>(Arrays.asList(new String[] {"Person: me"}));
DateFormat format = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.spdx.library.model.license;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import org.spdx.library.InvalidSPDXAnalysisException;
import org.spdx.library.SpdxConstants;

Expand Down Expand Up @@ -54,14 +52,6 @@ protected void setUp() throws Exception {
protected void tearDown() throws Exception {
super.tearDown();
}

public void testLicenseListVersionFormat() {
String licenseListversion = ListedLicenses.getListedLicenses().getLicenseListVersion();

assertEquals("Expected one point in license list version. ", 1, StringUtils.countMatches(licenseListversion, "."));
assertTrue("Number expected before the point in license list version (" + licenseListversion + ")", StringUtils.isNumeric(StringUtils.substringBefore(licenseListversion, ".")));
assertTrue("Number expected after the point in license list version (" + licenseListversion + ")", StringUtils.isNumeric(StringUtils.substringAfter(licenseListversion, ".")));
}

/**
* Test method for {@link org.spdx.library.model.license.ListedLicenses#isSpdxListedLicenseId(java.lang.String)}.
Expand Down

0 comments on commit 579be72

Please sign in to comment.