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

Add OSI JSON API checking for OSI Approved #118

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* SpdxLicenseIdentifier: Apache-2.0
*
* Copyright (c) 2021 Source Auditor Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.spdx.licenselistpublisher.licensegenerator;

import static org.junit.Assert.*;

import java.util.Optional;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.spdx.licenselistpublisher.LicenseGeneratorException;

/**
* @author gary
*
*/
public class OsiLicenseDataParserTest {

/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
OsiLicenseDataParser.reset();
}

/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
OsiLicenseDataParser.reset();
}

/**
* Test method for {@link org.spdx.licenselistpublisher.licensegenerator.OsiLicenseDataParser#getOsiLicenseDataParser()}.
* @throws LicenseGeneratorException
*/
@Test
public void testGetOsiLicenseDataParser() throws LicenseGeneratorException {
OsiLicenseDataParser.getOsiLicenseDataParser();
// just test to see if we get an exception
}

/**
* Test method for {@link org.spdx.licenselistpublisher.licensegenerator.OsiLicenseDataParser#isSpdxLicenseOsiApproved(java.lang.String)}.
* @throws LicenseGeneratorException
*/
@Test
public void testIsSpdxLicenseOsiApproved() throws LicenseGeneratorException {
OsiLicenseDataParser osildp = OsiLicenseDataParser.getOsiLicenseDataParser();
Optional<Boolean> result = osildp.isSpdxLicenseOsiApproved("Apache-2.0");
assertTrue(result.isPresent());
assertTrue(result.get());
result = osildp.isSpdxLicenseOsiApproved("apache-2.0");
assertTrue(result.isPresent());
assertTrue(result.get());
result = osildp.isSpdxLicenseOsiApproved("invalidid");
assertFalse(result.isPresent());
// All of the current OSI licenses have an OSI approved keyword - no test for the negative
}

}
1 change: 1 addition & 0 deletions resources/osi-licenses

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions src/org/spdx/licenselistpublisher/LicenseRDFAGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Map.Entry;
import java.util.Set;

Expand All @@ -53,6 +54,7 @@
import org.spdx.licenselistpublisher.licensegenerator.LicenseRdfaFormatWriter;
import org.spdx.licenselistpublisher.licensegenerator.LicenseTemplateFormatWriter;
import org.spdx.licenselistpublisher.licensegenerator.LicenseTextFormatWriter;
import org.spdx.licenselistpublisher.licensegenerator.OsiLicenseDataParser;
import org.spdx.licenselistpublisher.licensegenerator.SimpleLicenseTester;
import org.spdx.licenselistpublisher.licensegenerator.SpdxWebsiteFormatWriter;

Expand Down Expand Up @@ -486,7 +488,7 @@ private static Set<String> writeLicenseList(String version, String releaseDate,
if (licenseProvider instanceof XmlLicenseProviderSingleFile) {
license.getCrossRef().addAll(CrossRefHelper.buildUrlDetails(license));
}
addExternalMetaData(license);
addExternalMetaData(license, warnings);
if (license.getLicenseId() != null && !license.getLicenseId().isEmpty()) {
// Check for duplicate licenses
if (!license.isDeprecated()) {
Expand Down Expand Up @@ -552,11 +554,25 @@ private static Set<String> writeLicenseList(String version, String releaseDate,
/**
* Update license fields based on information from external metadata
* @param license
* @param warnings this list is updated if there are any warnings
* @throws LicenseGeneratorException
* @throws InvalidSPDXAnalysisException
*/
private static void addExternalMetaData(SpdxListedLicense license) throws LicenseGeneratorException, InvalidSPDXAnalysisException {
private static void addExternalMetaData(SpdxListedLicense license, List<String> warnings) throws LicenseGeneratorException, InvalidSPDXAnalysisException {
license.setFsfLibre(FsfLicenseDataParser.getFsfLicenseDataParser().isSpdxLicenseFsfLibre(license.getLicenseId()));
Optional<Boolean> osiApproved = OsiLicenseDataParser.getOsiLicenseDataParser().isSpdxLicenseOsiApproved(license.getLicenseId());
if (osiApproved.isPresent()) {
if (osiApproved.get()) {
if (!license.isOsiApproved()) {
warnings.add("License " + license.getLicenseId() + " osiApproved is set to true by OSI, but is not marked as OSI approved in the License XML");
}
//TODO: Consider setting OSI approved based on the OSI API
} else if (license.isOsiApproved()) {
warnings.add("License " + license.getLicenseId() + " osiApproved is set to false by OSI, but is marked as OSI approved in the License XML");
}
} else if (license.isOsiApproved()) {
warnings.add("License " + license.getLicenseId() + " is not included in the OSI metadata, but is marked as OSI approved in the License XML");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* SpdxLicenseIdentifier: Apache-2.0
*
* Copyright (c) 2021 Source Auditor Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.spdx.licenselistpublisher.licensegenerator;

/**
* OSI Identifier used in the OSI license API schema (see https://github.com/OpenSourceOrg/api/blob/master/doc/endpoints.md)
* @author Gary O'Neall
*
*/
public class OsiIdentifier {

String identifier;
String scheme;
/**
* @return the identifier
*/
public String getIdentifier() {
return identifier;
}
/**
* @param identifier the identifier to set
*/
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
/**
* @return the scheme
*/
public String getScheme() {
return scheme;
}
/**
* @param scheme the scheme to set
*/
public void setScheme(String scheme) {
this.scheme = scheme;
}



}
138 changes: 138 additions & 0 deletions src/org/spdx/licenselistpublisher/licensegenerator/OsiLicense.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**
* SpdxLicenseIdentifier: Apache-2.0
*
* Copyright (c) 2021 Source Auditor Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.spdx.licenselistpublisher.licensegenerator;

import java.util.List;

/**
* OSI Licenses based on the OSI licenses schema: https://github.com/OpenSourceOrg/api/blob/master/doc/endpoints.md
*
* @author Gary O'Neall
*
*/
public class OsiLicense {

String id;
String name;
String superseded_by;
List<OsiIdentifier> identifiers;
List<String> keywords;
List<Object> links;
List<Object> other_names;
List<Object> text;

/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}

/**
* @return the identifiers
*/
public List<OsiIdentifier> getIdentifiers() {
return identifiers;
}
/**
* @param identifiers the identifiers to set
*/
public void setIdentifiers(List<OsiIdentifier> identifiers) {
this.identifiers = identifiers;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the superseded_by
*/
public String getSuperseded_by() {
return superseded_by;
}
/**
* @param superseded_by the superseded_by to set
*/
public void setSuperseded_by(String superseded_by) {
this.superseded_by = superseded_by;
}
/**
* @return the keywords
*/
public List<String> getKeywords() {
return keywords;
}
/**
* @param keywords the keywords to set
*/
public void setKeywords(List<String> keywords) {
this.keywords = keywords;
}
/**
* @return the links
*/
public List<Object> getLinks() {
return links;
}
/**
* @param links the links to set
*/
public void setLinks(List<Object> links) {
this.links = links;
}
/**
* @return the other_names
*/
public List<Object> getOther_names() {
return other_names;
}
/**
* @param other_names the other_names to set
*/
public void setOther_names(List<Object> other_names) {
this.other_names = other_names;
}
/**
* @return the text
*/
public List<Object> getText() {
return text;
}
/**
* @param text the text to set
*/
public void setText(List<Object> text) {
this.text = text;
}

}
Loading