List of usage examples for org.apache.maven.project MavenProject getLicenses
public List<License> getLicenses()
From source file:licenseUtil.LicensingObject.java
License:Apache License
LicensingObject(MavenProject project, String includingProject, String version, Map<String, String> licenseUrlFileMappings) { super();/*from ww w .java 2 s . co m*/ put(ColumnHeader.ARTIFACT_ID.value(), project.getArtifactId()); put(ColumnHeader.GROUP_ID.value(), project.getGroupId()); put(ColumnHeader.VERSION.value(), project.getVersion()); if (project.getLicenses() != null && !project.getLicenses().isEmpty()) { String licenseNames = ""; String licenseUrls = ""; String licenseComments = ""; String licenseFN = null; int i = 0; for (License license : project.getLicenses()) { if (license.getUrl() != null && licenseFN == null) // remove protocol and lookup license url licenseFN = Utils.getValue(licenseUrlFileMappings, license.getUrl().replaceFirst("^[^:]+://", "")); if (i++ > 0) { licenseNames += multiEntriesSeparator; licenseUrls += multiEntriesSeparator; licenseComments += multiEntriesSeparator; } licenseNames += license.getName(); if (!Strings.isNullOrEmpty(license.getUrl())) licenseUrls += license.getUrl(); if (!Strings.isNullOrEmpty(license.getComments())) licenseComments += license.getComments(); } if (!Strings.isNullOrEmpty(licenseFN)) put(ColumnHeader.LICENSE_TEMPLATE.value(), licenseFN); if (!Strings.isNullOrEmpty(licenseNames)) put(ColumnHeader.LICENSE_NAMES.value(), licenseNames); if (!Strings.isNullOrEmpty(licenseUrls)) put(ColumnHeader.LICENSE_URLS.value(), licenseUrls); if (!Strings.isNullOrEmpty(licenseComments)) put(ColumnHeader.LICENSE_COMMENTS.value(), licenseComments); } put(includingProject, version); //clean(); }
From source file:net.kozelka.contentcheck.mojo.LicenseShowMojo.java
License:Open Source License
/** * Artifact resolving and the rest of Maven repo magic taken from <a href="http://maven.apache.org/plugins/maven-project-info-reports-plugin/index.html">Maven Project Info Reports Plugin</a>. *//*from w ww . j a v a 2 s. co m*/ public void execute() throws MojoExecutionException, MojoFailureException { final File src = sourceFile.exists() ? sourceFile : defaultBundleForPOMPacking; if (!src.exists()) { getLog().warn("Skipping project since there is no archive to check."); return; } final List<MavenProject> mavenProjectForDependencies = getMavenProjectForDependencies(); try { final ContentIntrospector introspector = VendorFilter.createIntrospector( new MyIntrospectionListener(getLog()), ignoreVendorArchives, vendorId, manifestVendorEntry, checkFilesPattern); final Set<ActualEntry> archiveEntries = new LinkedHashSet<ActualEntry>(); introspector.setSourceFile(src); //TODO: instead of collecting, put the dependency comparison right inside final ContentCollector collector = new ContentCollector(archiveEntries); introspector.getEvents().addListener(collector); introspector.walk(); introspector.getEvents().removeListener(collector); final Map<String, List<License>> entries = new LinkedHashMap<String, List<License>>(); final Map<String, List<License>> additionalLicenseInformation = new LinkedHashMap<String, List<License>>(); if (licenseMappingFile != null && licenseMappingFile.exists()) { //read additional license information getLog().info( String.format("Reading license mapping file %s", licenseMappingFile.getAbsolutePath())); try { additionalLicenseInformation.putAll(LicenseShow.parseLicenseMappingFile(licenseMappingFile)); } catch (JsonParseException e) { throw new MojoFailureException(String.format( "Cannot parse JSON from file %s the content of the file is not well formed JSON.", licenseMappingFile), e); } catch (JsonMappingException e) { throw new MojoFailureException( String.format("Cannot deserialize JSON from file %s", licenseMappingFile), e); } catch (IOException e) { throw new MojoFailureException(e.getMessage(), e); } } getLog().info("Comparing the archive content with Maven project artifacts"); for (ActualEntry archiveEntry : archiveEntries) { List<License> licenses = null; //these licenses will be associated with the given archive entry for (MavenProject mavenProject : mavenProjectForDependencies) { mavenProject.getGroupId(); final String artifactId = mavenProject.getArtifactId(); final String version = mavenProject.getVersion(); final String jarName = artifactId + "-" + version + ".jar"; //guess jar name if (archiveEntry.getUri().endsWith(jarName)) { @SuppressWarnings("unchecked") final List<License> _licenses = mavenProject.getLicenses(); licenses = _licenses == null || _licenses.size() == 0 ? null : _licenses; break; } } final List<License> licensesMappingFile = additionalLicenseInformation .get(FileUtils.filename(archiveEntry.getUri())); if (licenses == null && licensesMappingFile == null) {//misising license information getLog().debug(String.format( "Cannot resolve license information for archive entry %s neither from the POM file nor the file for license mapping", archiveEntry)); //archive entry must be present even if there is no a matching Maven Project entries.put(archiveEntry.getUri(), Collections.<License>emptyList()); } else if (licenses != null && licensesMappingFile != null) {//licenses specified in both - POM and license mapping file getLog().warn(String.format( "The license information for file %s are defined in the POM file and also in the file for license mapping. Using license information from the the file for license mapping.", archiveEntry)); entries.put(archiveEntry.getUri(), licensesMappingFile); //mapping manually specified licenses precedes licenses from POM } else if (licenses != null) {//license information in POM entries.put(archiveEntry.getUri(), licenses);//license } else { //license information in mapping file //put additional license information to the object that holds this information entries.put(archiveEntry.getUri(), licensesMappingFile); } } final LicenseShow.LicenseOutput logOutput = new MavenLogOutput(getLog()); logOutput.output(entries); if (csvOutput) { final LicenseShow.CsvOutput csvOutput = new LicenseShow.CsvOutput(csvOutputFile); getLog().info(String.format("Creating license output to CSV file %s", csvOutputFile.getPath())); csvOutput.output(entries); } } catch (IOException e) { throw new MojoFailureException(e.getMessage(), e); } }
From source file:net.sf.buildbox.maven.contentcheck.LicenseShowMojo.java
License:Open Source License
/** * @see net.sf.buildbox.maven.contentcheck.AbstractArchiveContentMojo#doExecute() *//*ww w . j ava 2 s.c o m*/ @Override protected void doExecute() throws IOException, MojoExecutionException, MojoFailureException { List<MavenProject> mavenProjectForDependencies = getMavenProjectForDependencies(); DefaultIntrospector introspector = new DefaultIntrospector(getLog(), isIgnoreVendorArchives(), getVendorId(), getManifestVendorEntry(), getCheckFilesPattern()); introspector.readArchive(getArchive()); Set<String> archiveEntries = new LinkedHashSet<String>(introspector.getArchiveEntries()); Map<String, List<License>> entries = new LinkedHashMap<String, List<License>>(); Map<String, List<License>> additionalLicenseInformation = new LinkedHashMap<String, List<License>>(); if (licenseMappingFile != null && licenseMappingFile.exists()) { //read additional license information LicenseMappingParser licenseMappingParser = new LicenseMappingParser(getLog(), licenseMappingFile); additionalLicenseInformation.putAll(licenseMappingParser.parseLicenseMappingFile()); } getLog().info("Comparing the archive content with Maven project artifacts"); for (String archiveEntry : archiveEntries) { List<License> licenses = null; //these licenses will be associated with the given archive entry for (MavenProject mavenProject : mavenProjectForDependencies) { mavenProject.getGroupId(); String artifactId = mavenProject.getArtifactId(); String version = mavenProject.getVersion(); String jarName = artifactId + "-" + version + ".jar"; //guess jar name if (archiveEntry.endsWith(jarName)) { @SuppressWarnings("unchecked") List<License> _licenses = mavenProject.getLicenses(); licenses = _licenses == null || _licenses.size() == 0 ? null : _licenses; break; } } List<License> licensesMappingFile = additionalLicenseInformation .get(stripJARNameFromPath(archiveEntry)); if (licenses == null && licensesMappingFile == null) {//misising license information getLog().debug(String.format( "Cannot resolve license information for archive entry %s neither from the POM file nor the file for license mapping", archiveEntry)); //archive entry must be present even if there is no a matching Maven Project entries.put(archiveEntry, Collections.<License>emptyList()); } else if (licenses != null && licensesMappingFile != null) {//licenses specified in both - POM and license mapping file getLog().warn(String.format( "The license information for file %s are defined in the POM file and also in the file for license mapping. Using license information from the the file for license mapping.", archiveEntry)); entries.put(archiveEntry, licensesMappingFile); //mapping manually specified licenses precedes licenses from POM } else if (licenses != null) {//license information in POM entries.put(archiveEntry, licenses);//license } else { //license information in mapping file //put additional license information to the object that holds this information entries.put(archiveEntry, licensesMappingFile); } } LicenseOutput logOutput = new LogOutput(getLog()); logOutput.output(entries); if (csvOutput) { CsvOutput csvOutput = new CsvOutput(getLog(), csvOutputFile); csvOutput.output(entries); } }
From source file:org.apache.felix.bundleplugin.BundlePlugin.java
License:Apache License
protected Properties getDefaultProperties(MavenProject currentProject) { Properties properties = new Properties(); String bsn;//from w ww . j a va 2 s .c o m try { bsn = getMaven2OsgiConverter().getBundleSymbolicName(currentProject.getArtifact()); } catch (Exception e) { bsn = currentProject.getGroupId() + "." + currentProject.getArtifactId(); } // Setup defaults properties.put(MAVEN_SYMBOLICNAME, bsn); properties.put(Analyzer.BUNDLE_SYMBOLICNAME, bsn); properties.put(Analyzer.IMPORT_PACKAGE, "*"); properties.put(Analyzer.BUNDLE_VERSION, getMaven2OsgiConverter().getVersion(currentProject.getVersion())); // remove the extraneous Include-Resource and Private-Package entries from generated manifest properties.put(Analyzer.REMOVE_HEADERS, Analyzer.INCLUDE_RESOURCE + ',' + Analyzer.PRIVATE_PACKAGE); header(properties, Analyzer.BUNDLE_DESCRIPTION, currentProject.getDescription()); StringBuffer licenseText = printLicenses(currentProject.getLicenses()); if (licenseText != null) { header(properties, Analyzer.BUNDLE_LICENSE, licenseText); } header(properties, Analyzer.BUNDLE_NAME, currentProject.getName()); if (currentProject.getOrganization() != null) { String organizationName = currentProject.getOrganization().getName(); header(properties, Analyzer.BUNDLE_VENDOR, organizationName); properties.put("project.organization.name", organizationName); properties.put("pom.organization.name", organizationName); if (currentProject.getOrganization().getUrl() != null) { String organizationUrl = currentProject.getOrganization().getUrl(); header(properties, Analyzer.BUNDLE_DOCURL, organizationUrl); properties.put("project.organization.url", organizationUrl); properties.put("pom.organization.url", organizationUrl); } } properties.putAll(currentProject.getProperties()); properties.putAll(currentProject.getModel().getProperties()); properties.putAll(getProperties(currentProject.getModel(), "project.build.")); properties.putAll(getProperties(currentProject.getModel(), "pom.")); properties.putAll(getProperties(currentProject.getModel(), "project.")); properties.put("project.baseDir", baseDir); properties.put("project.build.directory", getBuildDirectory()); properties.put("project.build.outputdirectory", getOutputDirectory()); properties.put("classifier", classifier == null ? "" : classifier); // Add default plugins header(properties, Analyzer.PLUGIN, BlueprintPlugin.class.getName() + "," + SpringXMLType.class.getName()); return properties; }
From source file:org.apache.felix.obr.plugin.ResourcesBundle.java
License:Apache License
/** * this method gets information form pom.xml to complete missing data from those given by user. * @param project project information given by maven * @param ebi bundle information extracted from bindex * @return true//from ww w.j av a2s . c o m */ public boolean construct(MavenProject project, ExtractBindexInfo ebi) { if (ebi.getPresentationName() != null) { setPresentationName(ebi.getPresentationName()); if (project.getName() != null) { m_logger.debug("pom property override:<presentationname> " + project.getName()); } } else { setPresentationName(project.getName()); } if (ebi.getSymbolicName() != null) { setSymbolicName(ebi.getSymbolicName()); if (project.getArtifactId() != null) { m_logger.debug("pom property override:<symbolicname> " + project.getArtifactId()); } } else { setSymbolicName(project.getArtifactId()); } if (ebi.getVersion() != null) { setVersion(ebi.getVersion()); if (project.getVersion() != null) { m_logger.debug("pom property override:<version> " + project.getVersion()); } } else { setVersion(project.getVersion()); } if (ebi.getId() != null) { setId(ebi.getId()); } if (ebi.getDescription() != null) { setDescription(ebi.getDescription()); if (project.getDescription() != null) { m_logger.debug("pom property override:<description> " + project.getDescription()); } } else { setDescription(project.getDescription()); } if (ebi.getDocumentation() != null) { setDocumentation(ebi.getDocumentation()); if (project.getUrl() != null) { m_logger.debug("pom property override:<documentation> " + project.getUrl()); } } else { setDocumentation(project.getUrl()); } if (ebi.getSource() != null) { setSource(ebi.getSource()); if (project.getScm() != null) { m_logger.debug("pom property override:<source> " + project.getScm()); } } else { String src = null; if (project.getScm() != null) { src = project.getScm().getUrl(); } setSource(src); } if (ebi.getLicense() != null) { setLicense(ebi.getLicense()); String lic = null; List l = project.getLicenses(); Iterator it = l.iterator(); while (it.hasNext()) { if (it.next() != null) { m_logger.debug("pom property override:<license> " + lic); break; } } } else { String lic = null; List l = project.getLicenses(); Iterator it = l.iterator(); while (it.hasNext()) { lic = it.next() + ";"; } setLicense(lic); } // create the first capability (ie : bundle) Capability capability = new Capability(); capability.setName("bundle"); PElement p = new PElement(); p.setN("manifestversion"); p.setV("2"); capability.addP(p); p = new PElement(); p.setN("presentationname"); p.setV(getPresentationName()); capability.addP(p); p = new PElement(); p.setN("symbolicname"); p.setV(getSymbolicName()); capability.addP(p); p = new PElement(); p.setN("version"); p.setT("version"); p.setV(getVersion()); capability.addP(p); addCapability(capability); List capabilities = ebi.getCapabilities(); for (int i = 0; i < capabilities.size(); i++) { addCapability((Capability) capabilities.get(i)); } List requirement = ebi.getRequirement(); for (int i = 0; i < requirement.size(); i++) { addRequire((Require) requirement.get(i)); } // we also add the goupId Category category = new Category(); category.setId(project.getGroupId()); addCategory(category); return true; }
From source file:org.apache.felix.obrplugin.ResourcesBundle.java
License:Apache License
/** * this method gets information form pom.xml to complete missing data from those given by user. * @param project project information given by maven * @param ebi bundle information extracted from bindex * @param sourcePath path to local sources * @param javadocPath path to local javadocs * @return true/*from w w w .ja v a 2 s .c om*/ */ public boolean construct(MavenProject project, ExtractBindexInfo ebi, String sourcePath, String javadocPath) { if (ebi.getPresentationName() != null) { setPresentationName(ebi.getPresentationName()); if (project.getName() != null) { m_logger.debug("pom property override:<presentationname> " + project.getName()); } } else { setPresentationName(project.getName()); } if (ebi.getSymbolicName() != null) { setSymbolicName(ebi.getSymbolicName()); if (project.getArtifactId() != null) { m_logger.debug("pom property override:<symbolicname> " + project.getArtifactId()); } } else { setSymbolicName(project.getArtifactId()); } if (ebi.getVersion() != null) { setVersion(ebi.getVersion()); if (project.getVersion() != null) { m_logger.debug("pom property override:<version> " + project.getVersion()); } } else { setVersion(project.getVersion()); } if (ebi.getId() != null) { setId(ebi.getId()); } if (ebi.getDescription() != null) { setDescription(ebi.getDescription()); if (project.getDescription() != null) { m_logger.debug("pom property override:<description> " + project.getDescription()); } } else { setDescription(project.getDescription()); } // fallback to javadoc if no project URL String documentation = project.getUrl(); if (null == documentation) { documentation = javadocPath; } if (ebi.getDocumentation() != null) { setDocumentation(ebi.getDocumentation()); if (documentation != null) { m_logger.debug("pom property override:<documentation> " + documentation); } } else { setDocumentation(documentation); } if (ebi.getSource() != null) { setSource(ebi.getSource()); if (sourcePath != null) { m_logger.debug("pom property override:<source> " + sourcePath); } } else { setSource(sourcePath); } setJavadoc(javadocPath); if (ebi.getLicense() != null) { setLicense(ebi.getLicense()); String lic = null; List l = project.getLicenses(); Iterator it = l.iterator(); while (it.hasNext()) { if (it.next() != null) { m_logger.debug("pom property override:<license> " + lic); break; } } } else { String lic = null; List l = project.getLicenses(); Iterator it = l.iterator(); while (it.hasNext()) { lic = it.next() + ";"; } setLicense(lic); } // create the first capability (ie : bundle) Capability capability = new Capability(); capability.setName("bundle"); PElement p = new PElement(); p.setN("manifestversion"); p.setV("2"); capability.addP(p); p = new PElement(); p.setN("presentationname"); p.setV(getPresentationName()); capability.addP(p); p = new PElement(); p.setN("symbolicname"); p.setV(getSymbolicName()); capability.addP(p); p = new PElement(); p.setN("version"); p.setT("version"); p.setV(getVersion()); capability.addP(p); addCapability(capability); List capabilities = ebi.getCapabilities(); for (int i = 0; i < capabilities.size(); i++) { addCapability((Capability) capabilities.get(i)); } List requirement = ebi.getRequirement(); for (int i = 0; i < requirement.size(); i++) { addRequire((Require) requirement.get(i)); } List categories = ebi.getCategories(); for (int i = 0; i < categories.size(); i++) { addCategory((Category) categories.get(i)); } // we also add the goupId Category category = new Category(); category.setId(project.getGroupId()); addCategory(category); return true; }
From source file:org.apache.hyracks.maven.license.LicenseMojo.java
License:Apache License
private void gatherProjectDependencies(MavenProject project, Map<MavenProject, List<Pair<String, String>>> dependencyLicenseMap, Map<String, MavenProject> dependencyGavMap) throws ProjectBuildingException { final Set dependencyArtifacts = project.getArtifacts(); if (dependencyArtifacts != null) { for (Object depArtifactObj : dependencyArtifacts) { final Artifact depArtifact = (Artifact) depArtifactObj; if (!excludedScopes.contains(depArtifact.getScope())) { MavenProject dep = resolveDependency(depArtifact); dep.setArtifact(depArtifact); dependencyGavMap.put(toGav(dep), dep); List<Pair<String, String>> licenseUrls = new ArrayList<>(); for (Object license : dep.getLicenses()) { final License license1 = (License) license; String url = license1.getUrl() != null ? license1.getUrl() : (license1.getName() != null ? license1.getName() : "LICENSE_EMPTY_NAME_URL"); licenseUrls.add(new ImmutablePair<>(url, license1.getName())); }//www . ja v a 2 s. c o m dependencyLicenseMap.put(dep, licenseUrls); } } } }
From source file:org.axway.grapes.maven.resolver.LicenseResolver.java
License:Open Source License
public List<License> resolve(final MavenProject project) throws MojoExecutionException { final List<License> licenses = new ArrayList<License>(); licenses.addAll(project.getLicenses()); if (licenses.isEmpty() && project.getParent() != null) { final MavenProject parent = project.getParent(); licenses.addAll(resolve(project, parent.getGroupId(), parent.getArtifactId(), parent.getVersion())); }/*from w ww . j a v a2 s . c o m*/ return licenses; }
From source file:org.codehaus.mojo.license.AbstractDownloadLicensesMojo.java
License:Open Source License
/** * Create a simple DependencyProject object containing the GAV and license info from the Maven Artifact * * @param depMavenProject the dependency maven project * @return DependencyProject with artifact and license info */// w w w.ja va 2 s .co m private ProjectLicenseInfo createDependencyProject(MavenProject depMavenProject) { ProjectLicenseInfo dependencyProject = new ProjectLicenseInfo(depMavenProject.getGroupId(), depMavenProject.getArtifactId(), depMavenProject.getVersion()); List<?> licenses = depMavenProject.getLicenses(); for (Object license : licenses) { dependencyProject.addLicense((License) license); } return dependencyProject; }
From source file:org.codehaus.mojo.license.api.DefaultThirdPartyHelper.java
License:Open Source License
/** * {@inheritDoc}/*ww w .jav a2 s . c o m*/ */ public LicenseMap createLicenseMap(SortedMap<String, MavenProject> dependencies) { LicenseMap licenseMap = new LicenseMap(); for (MavenProject project : dependencies.values()) { thirdPartyTool.addLicense(licenseMap, project, project.getLicenses()); } return licenseMap; }