public static License parseLicenseByUrl ( String licenseUrl ) throws InvalidLicenseStringException { final String protocolExcludedUrl = licenseUrl . replace ( "http://" , "" ) . replace ( "https://" , "" ) ; final ListedLicenses ll = ListedLicenses . getListedLicenses ( ) ; // Check cache. If hit, return, otherwise go through the native SPDX model which is terribly slow License license = resolvedByUrl . get ( licenseUrl ) ; if ( license != null ) { return license ; } for ( final String licenseId : ll . getSpdxListedLicenseIds ( ) ) { final AnyLicenseInfo licenseInfo = LicenseInfoFactory . parseSPDXLicenseString ( licenseId ) ; if ( licenseInfo instanceof SpdxListedLicense ) { final SpdxListedLicense spdxListedLicense = ( SpdxListedLicense ) licenseInfo ; for ( final String seeAlso : spdxListedLicense . getSeeAlso ( ) ) { final String protocolExcludedSeeAlsoUrl = seeAlso . replace ( "http://" , "" ) . replace ( "https://" , "" ) ; // Attempt to account for .txt, .html, and other extensions in the URLs being compared if ( protocolExcludedUrl . toLowerCase ( ) . contains ( protocolExcludedSeeAlsoUrl . toLowerCase ( ) ) || protocolExcludedSeeAlsoUrl . toLowerCase ( ) . contains ( protocolExcludedUrl . toLowerCase ( ) ) ) { license = createLicenseObject ( spdxListedLicense ) ; // Lazily cache the mapping for future performance improvements resolvedByUrl . put ( licenseUrl , license ) ; return license ; } } } } return null ; }
Given a URL this method will attempt to resolve the SPDX license . This method will not retrieve the URL rather it will interrogate it s internal list of SPDX licenses and the URLs defined for each . This method may impact performance for URLs that are not associated with an SPDX license or otherwise have not been queried on previously . This method will cache resolved licenses and their URLs for faster access on subsequent calls .