Class MavenToSpdxLicenseMapper

java.lang.Object
org.spdx.maven.utils.MavenToSpdxLicenseMapper

public class MavenToSpdxLicenseMapper extends Object
Singleton class which maps Maven license objects to SPDX licenses.

The license mapping uses the JSON file from the spdx.org/licenses/licenses.json file

If the site spdx.org/licenses is not accessible, then static version of the file will be used

The seeAlso property of the SPDX file is matched to the Maven license URL.

Author:
Gary O'Neall
  • Method Details

    • getInstance

      public static MavenToSpdxLicenseMapper getInstance() throws LicenseMapperException
      Throws:
      LicenseMapperException
    • urlToSpdxId

      public String urlToSpdxId(String url)
      Parameters:
      url - URL string for a license
      Returns:
      SPDX ID associated with the URL
    • mavenLicenseListToSpdxV2License

      public org.spdx.library.model.v2.license.AnyLicenseInfo mavenLicenseListToSpdxV2License(List<org.apache.maven.model.License> licenseList, org.spdx.library.model.v2.SpdxDocument spdxDoc) throws org.spdx.core.InvalidSPDXAnalysisException
      Map a list of Maven licenses to an SPDX Spec version 2 license. If no licenses are supplied, SpdxNoAssertion license is returned. if a single license is supplied, and a URL can be found matching a listed license, the listed license is returned. if a single license is supplied, and a URL can not be found matching a listed license, SpdxNoAssertion is returned. If multiple licenses are supplied, a conjunctive license is returned containing all mapped SPDX licenses.
      Parameters:
      licenseList - list of licenses
      spdxDoc - SPDX document which will hold the licenses
      Returns:
      SPDX license which matches the list of maven licenses
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - on SPDX parsing errors
    • mavenLicenseListToSpdxV3License

      public org.spdx.library.model.v3_0_1.simplelicensing.AnyLicenseInfo mavenLicenseListToSpdxV3License(List<org.apache.maven.model.License> licenseList, org.spdx.library.model.v3_0_1.core.Element spdxDoc) throws org.spdx.core.InvalidSPDXAnalysisException
      Map a list of Maven licenses to an SPDX Spec version 2 license. If no licenses are supplied, SpdxNoAssertion license is returned. if a single license is supplied, and a URL can be found matching a listed license, the listed license is returned. if a single license is supplied, and a URL can not be found matching a listed license, SpdxNoAssertion is returned. If multiple licenses are supplied, a conjunctive license is returned containing all mapped SPDX licenses.
      Parameters:
      licenseList - list of Maven licenses
      spdxDoc - SPDX document which will hold the licenses
      Returns:
      SPDX version 3 license equivalent to the list of Maven licenses
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - On SPDX parsing errors
    • getMap

      public Map<String,String> getMap()
      Returns:
      Map of URL's to listed license ID's