org.apache.maven.model.License Java Examples
The following examples show how to use
org.apache.maven.model.License.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TemplateAttrProvider.java From netbeans with Apache License 2.0 | 6 votes |
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; }
Example #2
Source File: LocationAwareMavenXpp3Writer.java From netbeans with Apache License 2.0 | 6 votes |
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()); }
Example #3
Source File: MavenDependencyScanner.java From sonarqube-licensecheck with Apache License 2.0 | 6 votes |
private static Dependency loadLicense(Map<Pattern, String> licenseMap, MavenSettings settings, Dependency dependency) { String pomPath = dependency.getPomPath(); if (pomPath != null) { List<License> licenses = LicenseFinder.getLicenses(new File(pomPath), settings.userSettings, settings.globalSettings); if (licenses.isEmpty()) { LOGGER.info("No licenses found in dependency {}", dependency.getName()); return dependency; } for (License license : licenses) { licenseMatcher(licenseMap, dependency, license); } } return dependency; }
Example #4
Source File: MavenDependencyScanner.java From sonarqube-licensecheck with Apache License 2.0 | 6 votes |
private static void licenseMatcher(Map<Pattern, String> licenseMap, Dependency dependency, License license) { String licenseName = license.getName(); if (StringUtils.isBlank(licenseName)) { LOGGER.info("Dependency '{}' has no license set.", dependency.getName()); return; } for (Entry<Pattern, String> entry : licenseMap.entrySet()) { if (entry.getKey().matcher(licenseName).matches()) { dependency.setLicense(entry.getValue()); return; } } LOGGER.info("No licenses found for '{}'", licenseName); }
Example #5
Source File: MavenUtils.java From wisdom with Apache License 2.0 | 6 votes |
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; }
Example #6
Source File: LicenseFinder.java From sonarqube-licensecheck with Apache License 2.0 | 5 votes |
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(); } }
Example #7
Source File: Maven2RepositoryStorage.java From archiva with Apache License 2.0 | 5 votes |
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; }
Example #8
Source File: Packager.java From JavaPackager with GNU General Public License v3.0 | 4 votes |
protected String getLicenseName() { List<License> licenses = env.getMavenProject().getLicenses(); return licenses != null && !licenses.isEmpty() && licenses.get(0) != null ? licenses.get(0).getName() : ""; }
Example #9
Source File: RpmMojo.java From rpm-builder with Eclipse Public License 2.0 | 4 votes |
private String makeLicense () { return this.project.getLicenses ().stream ().map ( License::getName ).collect ( Collectors.joining ( ", " ) ); }
Example #10
Source File: PomProperty.java From flatten-maven-plugin with Apache License 2.0 | 4 votes |
@Override public List<License> get( Model model ) { return model.getLicenses(); }
Example #11
Source File: PomProperty.java From flatten-maven-plugin with Apache License 2.0 | 4 votes |
@Override public void set( Model model, List<License> value ) { model.setLicenses( value ); }