public static String findLicenseByMavenProjectContent(MavenProject mp) { // try to match the project's license URL and the mavenLicenseURL attribute of license template FileObject licensesFO = FileUtil.getConfigFile("Templates/Licenses"); //NOI18N if (licensesFO == null) { return null; } FileObject[] licenseFiles = licensesFO.getChildren(); for (License license : mp.getLicenses()) { String url = license.getUrl(); if (url != null) { for (FileObject fo : licenseFiles) { String str = (String)fo.getAttribute("mavenLicenseURL"); //NOI18N if (str != null && Arrays.asList(str.split(" ")).contains(url)) { if (fo.getName().startsWith("license-")) { // NOI18N return fo.getName().substring("license-".length()); //NOI18N } else { Logger.getLogger(TemplateAttrProvider.class.getName()).log(Level.WARNING, "Bad license file name {0} (expected to start with ''license-'' prefix)", fo.getName()); } break; } } } } return null; }
private void writeLicense(License license, String tagName, XmlSerializer serializer) throws java.io.IOException { serializer.startTag(NAMESPACE, tagName); flush(serializer); StringBuffer b = b(serializer); int start = b.length(); if (license.getName() != null) { writeValue(serializer, "name", license.getName(), license); } if (license.getUrl() != null) { writeValue(serializer, "url", license.getUrl(), license); } if (license.getDistribution() != null) { writeValue(serializer, "distribution", license.getDistribution(), license); } if (license.getComments() != null) { writeValue(serializer, "comments", license.getComments(), license); } serializer.endTag(NAMESPACE, tagName).flush(); logLocation(license, "", start, b.length()); }
private void checkDependency(final DependencyNode dependency) throws ProjectResolutionException, DependencyException { log.debug("Checking dependency: " + dependency.getArtifact().getId()); if (!excludedArtifacts.contains(convertArtifactToExclusion(dependency.getArtifact()))) { final List<License> licenses = getArtifactLicenses(dependency.getArtifact()); if (licenses.isEmpty()) { throw new LicenseMissingException(dependency); } else { for (final License license : licenses) { log.debug("Inspecting license - " + license.getName()); if (!whitelistedLicenses.contains(license.getName())) { throw new LicenseNotAllowedException(dependency, license); } else if (log.isDebugEnabled()) { log.debug("\"" + dependency.getArtifact().getId() + "\" with license \"" + license.getName() + "\" is good!"); } } } } else if (log.isDebugEnabled()) { log.debug(dependency.getArtifact().getId() + " is in artifact exclusions"); } }
public List<License> getLicense(MavenProject p) { if (p==null) return null; List<License> result = null; result = parseAsLicenses(getOverridesForProject(p).get("license")); if (result!=null) return result; // anything on project trumps something unversioned result = p.getLicenses(); // semantics of MavenProject is never to return null if (result!=null && !result.isEmpty()) return result; // next look up unversioned (as a default if nothing specified) result = getLicense(Coords.of(p).unversioned()); if (result!=null) return result; return Collections.emptyList(); }
protected void addCompleteLicenseInfoEntries(List<License> lics) throws MojoExecutionException { String code = licensesCode(lics); addProjectEntry("License Code", licensesCode(lics)); addProjectEntry("License", licensesString(lics, true)); // if code found or single license, extract simple info, preferring canonical (code) info License license = LicenseCodes.lookupCode(code); if (license!=null) { addProjectEntry("License Name", license.getName()); addProjectEntry("License URL", license.getUrl()); } else if (lics!=null && lics.size()==1) { license = lics.iterator().next(); addProjectEntry("License Name", license.getName()); addProjectEntry("License URL", license.getUrl()); // comments and distribution removed; // comments included in "License" string above, for all licenses, // and distribution not really useful (repo or manual) } }
@Override public void startProject(String id, MavenProject p) throws MojoExecutionException { super.startProject(id, p); if (p==null) p = projectByIdCache.get(id); Set<Object> errs = projectErrors.get(id); // if we wanted to show where it was dragged in from // Set<String> parentDN = projectToDependencyGraphParent.get(id); // Set<DependencyNode> referencingDNs = depNodesByIdCache.get(id); List<License> lics = getLicenses(p, id); String licenseLine = (suppressLicenseInfo ? "" : ": "+((lics!=null && !lics.isEmpty()) || p!=null ? oneLine(licensesSummaryString(lics), "; ") : "<not loaded>")); output(id+ (errs==null || errs.isEmpty() ? "" : " (ERROR)")+ licenseLine); }
@Override protected String extraInfoForProjectLineInfo(String id, MavenProject p, Set<DependencyDetail> details, String exclusionInfo) { if (p==null) p = projectByIdCache.get(id); List<License> lics = getLicenses(p, id); if (p==null) { getLog().debug("No project loaded: "+id); } String licenseLine = (suppressLicenseInfo ? "" : ": "+(p!=null ? oneLine(licensesSummaryString(lics), "; ") : "<not loaded>")); if (isRoot(id)) { // root project, no need to show deps info return (isNonEmpty(exclusionInfo) ? "("+exclusionInfo+")" : "")+ licenseLine; } return " ("+ (projectErrors.get(id)!=null ? "ERROR; " : "") + allScopesFromDetails(details) + (isOptionalFromDetails(details) ? ", optional" : "")+ (isNonEmpty(exclusionInfo) ? ", "+exclusionInfo : "")+")"+ licenseLine; }
/** * Map a list of Maven licenses to an SPDX license. If no licenses * are supplied, SpdxNoAssertion license is returned. if a single * license is supplied, the mapped SPDX license is returned. If * multiple licenses are supplied, a conjunctive license is returned * containing all mapped SPDX licenses. * @return * @throws LicenseManagerException */ public AnyLicenseInfo mavenLicenseListToSpdxLicense( List<License> licenseList ) throws LicenseManagerException { if ( licenseList == null ) { return new SpdxNoAssertionLicense(); } List<AnyLicenseInfo> spdxLicenses = new ArrayList<AnyLicenseInfo>(); Iterator<License> iter = licenseList.iterator(); while( iter.hasNext() ) { License license = iter.next(); spdxLicenses.add( mavenLicenseToSpdxLicense( license ) ); } if ( spdxLicenses.size() < 1) { return new SpdxNoAssertionLicense(); } else if ( spdxLicenses.size() == 1 ) { return spdxLicenses.get( 0 ); } else { AnyLicenseInfo[] licensesInSet = spdxLicenses.toArray( new AnyLicenseInfo[spdxLicenses.size()] ); AnyLicenseInfo conjunctiveLicense = new ConjunctiveLicenseSet( licensesInSet ); return conjunctiveLicense; } }
/** * Map a Maven license to an SPDX license based on the URL * @param mavenLicense license to map to a listed SPDX license * @return SPDX license * @throws LicenseManagerException thrown if no SPDX listed or extracted license exists with the same URL */ public AnyLicenseInfo mavenLicenseToSpdxLicense( License mavenLicense ) throws LicenseManagerException { if ( mavenLicense.getUrl() == null ) { throw( new LicenseManagerException( "Can not map maven license " + mavenLicense.getName() + " No URL exists to provide a mapping" ) ); } String licenseId = this.urlStringToSpdxLicenseId.get( mavenLicense.getUrl() ); if ( licenseId == null ) { throw( new LicenseManagerException( "Can not map maven license " + mavenLicense.getName() + " No listed or extracted license matches the URL " + mavenLicense.getUrl() ) ); } AnyLicenseInfo retval = extractedLicenses.get( licenseId ); if (retval == null) { try { retval = LicenseInfoFactory.parseSPDXLicenseString( licenseId ); } catch ( InvalidLicenseStringException e ) { throw( new LicenseManagerException( "Can not map maven license " + mavenLicense.getName() + " Invalid listed or extracted license id matching the URL " + mavenLicense.getUrl() ) ); } } return retval; }
private License spdxStdLicenseToMavenLicense( SpdxListedLicense spdxLicense ) { License retval = new License(); // name if ( spdxLicense.getName() != null && !spdxLicense.getName().isEmpty() ) { retval.setName( spdxLicense.getName() ); } else { retval.setName( spdxLicense.getLicenseId() ); } // comment if ( spdxLicense.getComment() != null && !spdxLicense.getComment().isEmpty() ) { retval.setComments( spdxLicense.getComment() ); } // url if ( spdxLicense.getSeeAlso() != null && spdxLicense.getSeeAlso().length > 0 ) { retval.setUrl( spdxLicense.getSeeAlso()[0] ); if ( spdxLicense.getSeeAlso().length > 1 ) { if ( getLog() != null ) { getLog().warn( "SPDX license "+spdxLicense.getLicenseId() + " contains multiple URLs. Only the first URL will be preserved in the Maven license created." ); } } } return retval; }
private License spdxNonStdLicenseToMavenLicense( ExtractedLicenseInfo spdxLicense ) { License retval = new License(); // name if ( spdxLicense.getName() != null && !spdxLicense.getName().isEmpty() ) { retval.setName( spdxLicense.getName() ); } else { retval.setName( spdxLicense.getLicenseId() ); } // comment if ( spdxLicense.getComment() != null && !spdxLicense.getComment().isEmpty() ) { retval.setComments( spdxLicense.getComment() ); } // url if ( spdxLicense.getSeeAlso() != null && spdxLicense.getSeeAlso().length > 0 ) { retval.setUrl( spdxLicense.getSeeAlso()[0] ); if ( spdxLicense.getSeeAlso().length > 1 ) { getLog().warn( "SPDX license "+spdxLicense.getLicenseId() + " contains multiple URLs. Only the first URL will be preserved in the Maven license created." ); } } return retval; }
/** * Map a list of Maven licenses to an SPDX 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. * @return * @throws LicenseManagerException */ public AnyLicenseInfo mavenLicenseListToSpdxLicense( List<License> licenseList ) { if ( licenseList == null ) { return new SpdxNoAssertionLicense(); } List<AnyLicenseInfo> spdxLicenses = new ArrayList<AnyLicenseInfo>(); Iterator<License> iter = licenseList.iterator(); while( iter.hasNext() ) { License license = iter.next(); SpdxListedLicense listedLicense = mavenLicenseToSpdxListedLicense( license ); if (listedLicense != null) { spdxLicenses.add( listedLicense ); } } if ( spdxLicenses.size() < 1) { return new SpdxNoAssertionLicense(); } else if ( spdxLicenses.size() == 1 ) { return spdxLicenses.get( 0 ); } else { AnyLicenseInfo[] licensesInSet = spdxLicenses.toArray( new AnyLicenseInfo[spdxLicenses.size()] ); AnyLicenseInfo conjunctiveLicense = new ConjunctiveLicenseSet( licensesInSet ); return conjunctiveLicense; } }
private SpdxListedLicense mavenLicenseToSpdxListedLicense( License license ) { if ( license == null ) { return null; } if ( license.getUrl() == null || license.getUrl().isEmpty() ) { return null; } String spdxId = this.urlStringToSpdxLicenseId.get( license.getUrl() ); if (spdxId == null) { return null; } try { return LicenseInfoFactory.getListedLicenseById( spdxId ); } catch ( InvalidSPDXAnalysisException e ) { return null; } }
private String createDefaultLicenseText() { String toRet = "License terms:\n"; List licenses = project.getLicenses(); if (licenses != null && licenses.size() > 0) { Iterator lic = licenses.iterator(); while (lic.hasNext()) { License ll = ( License )lic.next(); if (ll.getName() != null) { toRet = toRet + ll.getName() + " - "; } if (ll.getUrl() != null) { toRet = toRet + ll.getUrl(); } if (lic.hasNext()) { toRet = toRet + ",\n"; } } } else { toRet = toRet + "Unknown"; } return toRet; }
/** Constructor. * @param artifact the artifact. * @param name name of the artifact. * @param website website. * @param organization organization. * @param scmRevision url of the SCM. * @param scm SCM. * @param developers developers. * @param contributors constributors. * @param licenses licenses. */ public ExtendedArtifact( Artifact artifact, String name, String website, Organization organization, String scmRevision, Scm scm, List<? extends Developer> developers, List<? extends Contributor> contributors, List<? extends License> licenses) { this.original = artifact; this.artifactName = name; this.developers = developers; this.contributors = contributors; this.website = website; this.organization = organization; this.scm = scm; this.scmRevision = scmRevision; this.licenses = licenses; }
private static StringBuilder printLicenses(List licenses) { if (licenses == null || licenses.isEmpty()) { return null; } StringBuilder sb = new StringBuilder(); String del = ""; for (Object license : licenses) { License l = (License) license; String url = l.getUrl(); if (url == null) { continue; } sb.append(del); sb.append(url); del = ", "; } if (sb.length() == 0) { return null; } return sb; }
/** * This method returns the normalized name of the license. * * @param artifactInformation * * @param license * is the {@link License} object which is to be looked up. * @return A {@link KnownLicense} is returned containing the known license. * @throws MojoFailureException * is thrown if the normalized name cannot be looked up due to * missing configuration. */ private KnownLicense findKnownLicense( ArtifactInformation artifactInformation, License license) throws MojoFailureException { for (KnownLicense knownLicense : knownLicenses) { if (knownLicense.getName().equals(license.getName())) { return knownLicense; } for (String alias : knownLicense.getAliases()) { if ((alias == null) || (alias.isEmpty())) { throw new MojoFailureException( "An alias was found without identifier."); } if (alias.equals(license.getName())) { return knownLicense; } } } return null; }
@Test public void shouldNotFindBestPracticesViolation() { License license = new License(); license.setName("license-name"); license.setUrl("license-url"); Developer developer = new Developer(); developer.setId("dev-id"); developer.setName("dev-name"); Scm scm = new Scm(); scm.setUrl("scm-url"); scm.setConnection("scm-connection"); PomBuilder pomBuilder = pom(); pomBuilder.model().setName("foo-name"); pomBuilder.model().setDescription(""); // empty description is allowed, see WOLF-69 pomBuilder.model().setUrl("foo-url"); pomBuilder.model().addLicense(license); pomBuilder.model().addDeveloper(developer); pomBuilder.model().setScm(scm); pomBuilder.create(repoFooDir); validationExecutor.execute(ctx); assertSuccess(); }
/** * Returns a string with the license(s) of a MavenProject. * * @param project * @return * @throws MojoExecutionException */ @SuppressWarnings("unchecked") public static String getConsolidatedLicenseString(MavenProject project) throws MojoExecutionException { StringBuilder license = new StringBuilder(); Iterator<License> ite = null; try { ite = (Iterator<License>) project.getLicenses().iterator(); license.append(((License) ite.next()).getName()); } catch (Exception ex) { throw new MojoExecutionException( "Please provide at least one license in your POM.", ex); } while (ite.hasNext()) { license.append(", "); license.append(((License) ite.next()).getName()); } return license.toString(); }
@Test @SuppressWarnings("unchecked") public void getLicenseForProject() throws Exception { Packaging p = (Packaging) mockEnvironment(RPMPOM, "pkg"); List<License> licenses = createLicenseList("License 1", "License 2"); p.project.setLicenses(licenses); String result = Utils.getConsolidatedLicenseString(p.project); Assert.assertEquals("License 1, License 2", result); List<License> l = p.project.getLicenses(); l.remove(0); p.project.setLicenses(l); result = Utils.getConsolidatedLicenseString(p.project); Assert.assertEquals("License 2", result); }
/** * Method updateLicense * * @param value * @param element * @param counter * @param xmlTag */ protected void updateLicense( License value, String xmlTag, Counter counter, Element element ) { Element root = element; Counter innerCount = new Counter( counter.getDepth() + 1 ); findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null ); findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null ); findAndReplaceSimpleElement( innerCount, root, "distribution", value.getDistribution(), null ); findAndReplaceSimpleElement( innerCount, root, "comments", value.getComments(), null ); }
private List<License> getArtifactLicenses(final Artifact artifact) throws ProjectResolutionException { try { MavenProject projectArtifact = generateMavenProject(artifact); List<License> licenses = projectArtifact.getLicenses(); if (licenses == null || licenses.isEmpty()) { Artifact parentArtifact = projectArtifact.getParentArtifact(); return (parentArtifact == null) ? Collections.emptyList() : getArtifactLicenses(parentArtifact); } else { return licenses; } } catch (Exception e) { throw new ProjectResolutionException(artifact, e); } }
private List<org.apache.archiva.metadata.model.License> convertLicenses( List<License> licenses ) { List<org.apache.archiva.metadata.model.License> l = new ArrayList<>(); for ( License license : licenses ) { org.apache.archiva.metadata.model.License newLicense = new org.apache.archiva.metadata.model.License(); newLicense.setName( license.getName() ); newLicense.setUrl( license.getUrl() ); l.add( newLicense ); } return l; }
public static List<License> getLicenses(File filePath, String userSettings, String globalSettings) { try { Model model = new MavenXpp3Reader().read(new FileInputStream(filePath)); if (!model.getLicenses().isEmpty()) { return model.getLicenses(); } else { if (model.getParent() != null) { Parent parent = model.getParent(); Dependency dependency = new Dependency(parent.getGroupId() + ":" + parent.getArtifactId(), parent.getVersion(), null); return getLicenses(DirectoryFinder.getPomPath(dependency, DirectoryFinder.getMavenRepsitoryDir(userSettings, globalSettings)), userSettings, globalSettings); } else { return Collections.emptyList(); } } } catch (Exception e) { LOGGER.warn("Could not parse Maven POM " + filePath, e); return Collections.emptyList(); } }
protected Set<String> getLicenses(String groupId, Set<Object> projects) { List<License> overrideLic = overrides.getLicense(groupId); if (overrideLic!=null && !overrideLic.isEmpty()) { // replace projects with the singleton set of the override projects = new LinkedHashSet<Object>(); projects.add(overrides.getOverridesForProject(groupId)); } Set<String> result = new LinkedHashSet<String>(); for (Object p: projects) { List<License> lics; if (p instanceof MavenProject) lics = overrides.getLicense((MavenProject)p); else { lics = ProjectsOverrides.parseAsLicenses( ((Map<?,?>)p).get("license") ); // if licenses left out of maps, don't generate error yet if (lics==null) continue; } String singleCode = licensesCode(lics); String url; if (singleCode!=null) { // look for a url declared in a license url = lics.iterator().next().getUrl(); if (url==null) { url = LicenseCodes.lookupCode(singleCode).getUrl(); } else { if (!url.matches(URL_REGEX)) { // not a valid URL; assume in project url = "in-project reference: "+url; } } result.add(LicenseCodes.lookupCode(singleCode).getName()+" ("+url+")"); } else { result.addAll(Arrays.asList(licensesString(lics, false).split("\n"))); } } if (result.isEmpty() && !projects.isEmpty()) result.addAll(Arrays.asList(licensesString(null, false).split("\n"))); return result; }
private static String licensesStringInternal(Iterable<? extends License> licenses, boolean preferSummaryCodeOverName, boolean includeUrl, boolean includeComments) { // NB: subtly different messages if things are empty if (licenses==null) return "<no license info>"; Set<String> result = new LinkedHashSet<String>(); for (License l: licenses) { StringBuilder ri = new StringBuilder(); if (isNonEmpty(l.getName())) { if (preferSummaryCodeOverName) { String code = LicenseCodes.getLicenseCode(l.getName()); ri.append(isNonEmpty(code) ? code : l.getName()); } else { ri.append(l.getName()); } } if (isNonEmpty(l.getUrl())) { if (ri.length()>0) { if (!includeUrl) { /* nothing */ } else { ri.append(" ("+l.getUrl()+")"); } } else { ri.append(l.getUrl()); } } if (isNonEmpty(l.getComments())) { if (ri.length()>0) { if (!includeComments) { /* nothing */ } else { ri.append("; "+l.getComments()); } } else { ri.append("Comment: "+l.getComments()); } } if (ri.toString().trim().length()>0) { result.add(ri.toString().trim()); } else { result.add("<no info on license>"); } } if (result.size()>0) return join(result, "\n"); return "<no licenses>"; }
protected static String licensesSummaryString(Iterable<? extends License> licenses) { String summary = licensesStringInternal(licenses, true, false, false); String code = LicenseCodes.getLicenseCode(summary); if (code==null) return summary; if (code.length()==0) return "<unknown>"; return code; }
public static List<License> parseAsLicenses(Object ll) { if (ll==null) return null; if (ll instanceof Iterable) { List<License> result = new ArrayList<License>(); for (Object l: ((Iterable<?>)ll)) { result.add(parseSingleLicense(l)); } return result; } else { return Collections.singletonList(parseSingleLicense(ll)); } }
public static License parseSingleLicense(Object l) { if (l instanceof String) { final License lookup = LicenseCodes.lookupCode((String) l); if (null != lookup) return lookup; throw new IllegalArgumentException("Invalid license; it should be a map or a known code (string), not "+l); } if (l instanceof Map) { Map<?, ?> lmap = ((Map<?,?>)l); return LicenseCodes.newLicense(getRequired(lmap, String.class, "name"), (String)lmap.get("url"), (String)lmap.get("comments")); } throw new IllegalArgumentException("Invalid license; it should be a map or a known code (string), not "+l); }
public static License newLicense(String name, String url, String comments) { License result = new License(); result.setName(name); result.setUrl(url); result.setComments(comments); return result; }
public void testGetCodesFromRegexLookupKnownNames() { for (String code: LicenseCodes.KNOWN_LICENSE_CODES_WITH_REGEX.keySet()) { License l = LicenseCodes.KNOWN_LICENSE_CODES_WITH_LICENSE.get(code); if (l!=null) { String name = l.getName(); assertEquals("lookup of "+name, code, LicenseCodes.getLicenseCode(name)); } } }
public void testGetCodesFromRegexLookupKnownCodes() { for (String code: LicenseCodes.KNOWN_LICENSE_CODES_WITH_REGEX.keySet()) { License l = LicenseCodes.KNOWN_LICENSE_CODES_WITH_LICENSE.get(code); if (l!=null) { assertEquals("lookup of "+code, code, code); } } }
/** * Create a Maven license from the SPDX license * @param spdxLicense * @return * @throws LicenseManagerException */ public License spdxLicenseToMavenLicense( AnyLicenseInfo spdxLicense ) throws LicenseManagerException { if ( spdxLicense instanceof ExtractedLicenseInfo ) { return spdxNonStdLicenseToMavenLicense( (ExtractedLicenseInfo)spdxLicense ); } else if ( spdxLicense instanceof SpdxListedLicense ) { return spdxStdLicenseToMavenLicense( (SpdxListedLicense)spdxLicense ); } else { throw( new LicenseManagerException( "Can not create a Maven license from this SPDX license type. " + "Must be an ExtractedLicenseInfo or an SpdxListedLicense ")); } }
/** * Convert a list of Maven licenses to an SPDX License * @param mavenLicenses List of maven licenses to map * @return * @throws LicenseMapperException * @throws LicenseManagerException */ private AnyLicenseInfo mavenLicensesToSpdxLicense( List<License> mavenLicenses ) throws LicenseMapperException { try { // The call below will map non standard licenses as well as standard licenses // but will throw an exception if no mapping is found - we'll try this first // and if there is an error, try just the standard license mapper which will // return an UNSPECIFIED license type if there is no mapping return this.licenseManager.mavenLicenseListToSpdxLicense( mavenLicenses ); } catch (LicenseManagerException ex) { return MavenToSpdxLicenseMapper.getInstance( log ).mavenLicenseListToSpdxLicense( mavenLicenses ); } }
@Test public void testMavenLicenseListToSpdxLicenseNone() throws LicenseMapperException { List<License> licenseList = new ArrayList<License>(); AnyLicenseInfo result = MavenToSpdxLicenseMapper.getInstance( null ).mavenLicenseListToSpdxLicense( licenseList ); assertEquals( new SpdxNoAssertionLicense(), result ); }
@Test public void testMavenLicenseListToSpdxLicenseUnknown() throws LicenseMapperException { List<License> licenseList = new ArrayList<License>(); License license = new License(); license.setUrl( "http://not.a.known.url" ); licenseList.add( license ); AnyLicenseInfo result = MavenToSpdxLicenseMapper.getInstance( null ).mavenLicenseListToSpdxLicense( licenseList ); assertEquals( new SpdxNoAssertionLicense(), result ); }
@Test public void testMavenLicenseListToSpdxLicenseSingle() throws LicenseMapperException, InvalidLicenseStringException { List<License> licenseList = new ArrayList<License>(); License license = new License(); license.setUrl( APACHE2_URL ); licenseList.add( license ); AnyLicenseInfo result = MavenToSpdxLicenseMapper.getInstance( null ).mavenLicenseListToSpdxLicense( licenseList ); AnyLicenseInfo expected = LicenseInfoFactory.parseSPDXLicenseString( APACHE_SPDX_ID ); assertEquals( expected, result ); }
@Test public void testMavenLicenseListToSpdxLicenseConjunctive() throws LicenseMapperException, InvalidLicenseStringException { List<License> licenseList = new ArrayList<License>(); License license = new License(); license.setUrl( APACHE2_URL ); licenseList.add( license ); License licenseM = new License(); licenseM.setUrl( MIT_URL ); licenseList.add( licenseM ); AnyLicenseInfo result = MavenToSpdxLicenseMapper.getInstance( null ).mavenLicenseListToSpdxLicense( licenseList ); AnyLicenseInfo expected = LicenseInfoFactory.parseSPDXLicenseString( APACHE_SPDX_ID + " AND " + MIT_SPDX_ID ); assertEquals( expected, result ); }
@Test public void testMavenLicenseListToSpdxLicenseConunctiveUnknown() throws LicenseMapperException, InvalidLicenseStringException { List<License> licenseList = new ArrayList<License>(); License license = new License(); license.setUrl( APACHE2_URL ); licenseList.add( license ); License licenseM = new License(); licenseM.setUrl( "http://unknown.url" ); licenseList.add( licenseM ); AnyLicenseInfo result = MavenToSpdxLicenseMapper.getInstance( null ).mavenLicenseListToSpdxLicense( licenseList ); AnyLicenseInfo expected = LicenseInfoFactory.parseSPDXLicenseString( APACHE_SPDX_ID ); assertEquals( expected, result ); }