List of usage examples for org.apache.maven.project MavenProject getLicenses
public List<License> getLicenses()
From source file:com.teamtter.simplelicenses.GenerateDependenciesLicenseInfoMojo.java
private void generateDependenciesLicenseInfo() throws ProjectBuildingException { Artifacts2LicensesRepository repo = new Artifacts2LicensesRepository(); ProjectBuildingRequest request = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest()); // Build the project and get the result List<Artifact> runtimeArtifacts = mavenProject.getRuntimeArtifacts(); for (Artifact artifact : runtimeArtifacts) { MavenProject project = projectBuilder.build(artifact, request).getProject(); List<String> licenses = project.getLicenses(); log.info("licenses = {}", licenses); repo.add(artifact, project.getLicenses()); }/* w w w. j av a 2 s.co m*/ }
From source file:com.torchmind.maven.plugins.attribution.AttributionMojo.java
License:Apache License
/** * Creates an attribution object using a root artifact and its listed dependencies. * @param artifact the maven project.//w w w. jav a2 s. c om * @param dependencies the dependencies. * @return the attribution. */ @Nonnull public static AttributionDocument createAttribution(@Nonnull MavenProject artifact, @Nonnull List<Artifact> dependencies, @Nonnull List<Artifact> plugins) { return new AttributionDocument(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getName(), artifact.getDescription(), artifact.getUrl(), artifact.getLicenses().stream().map(AttributionMojo::createLicense).collect(Collectors.toList()), artifact.getDevelopers().stream().map(AttributionMojo::createDeveloper) .collect(Collectors.toList()), artifact.getContributors().stream().map(AttributionMojo::createDeveloper) .collect(Collectors.toList()), dependencies, plugins); }
From source file:com.torchmind.maven.plugins.attribution.AttributionMojo.java
License:Apache License
/** * Creates an artifact using a maven project. * @param artifact the maven project./*w ww . j a v a2 s . c o m*/ * @return the artifact. */ @Nonnull public static Artifact createArtifact(@Nonnull MavenProject artifact) { return new Artifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getName(), artifact.getDescription(), artifact.getUrl(), artifact.getLicenses().stream().map(AttributionMojo::createLicense).collect(Collectors.toList()), artifact.getDevelopers().stream().map(AttributionMojo::createDeveloper) .collect(Collectors.toList()), artifact.getContributors().stream().map(AttributionMojo::createDeveloper) .collect(Collectors.toList())); }
From source file:com.willowtreeapps.saguaro.maven.MavenLicenseResolver.java
License:Apache License
@Override public Set<LicenseDependency> resolveLicenseDependencies() throws PluginException { Set<Artifact> deps = projectHelper.getArtifacts(); Set<LicenseDependency> licenseDependencies = new LinkedHashSet<LicenseDependency>(); for (Artifact artifact : deps) { MavenProject depProject = projectHelper.buildFromRepository(artifact); Dependency dependency = new Dependency(depProject.getGroupId(), depProject.getArtifactId()); List<org.apache.maven.model.License> licenseList = depProject.getLicenses(); Set<LicenseInfo> licenses = new LinkedHashSet<LicenseInfo>(); for (org.apache.maven.model.License license : licenseList) { licenses.add(LicenseInfo.withUrl(license.getName(), license.getUrl())); }// w w w. ja v a 2s . c o m licenseDependencies.add(new LicenseDependency(depProject.getName(), dependency, licenses)); } return licenseDependencies; }
From source file:de.saumya.mojo.gem.GemspecWriter.java
@SuppressWarnings("unchecked") GemspecWriter(final File gemspec, final MavenProject project, final GemArtifact artifact) throws IOException { this.latestModified = project.getFile() == null ? 0 : project.getFile().lastModified(); this.gemspec = gemspec; this.gemspec.getParentFile().mkdirs(); this.writer = new FileWriter(gemspec); this.project = project; append("Gem::Specification.new do |s|"); append("name", artifact.getGemName()); append("version", gemVersion(project.getVersion())); append();/*from w w w .ja va 2s . c om*/ append("summary", project.getName()); append("description", project.getDescription()); append("homepage", project.getUrl()); append(); for (final Developer developer : (List<Developer>) project.getDevelopers()) { appendAuthor(developer.getName(), developer.getEmail()); } for (final Contributor contributor : (List<Contributor>) project.getContributors()) { appendAuthor(contributor.getName(), contributor.getEmail()); } append(); for (final License license : (List<License>) project.getLicenses()) { appendLicense(license.getUrl(), license.getName()); } }
From source file:de.tarent.maven.plugins.pkg.Utils.java
License:Open Source License
/** * Returns a string with the license(s) of a MavenProject. * //w ww .j av a2 s .c o m * @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(); }
From source file:fr.in2p3.maven.plugin.DependencyXmlMojo.java
private void dump(DependencyNode current, PrintStream out) throws MojoExecutionException, MojoFailureException { String artifactId = current.getArtifact().getArtifactId(); boolean hasClassifier = (current.getArtifact().getClassifier() != null); if ((artifactId.startsWith("jsaga-") || artifactId.startsWith("saga-")) && !hasClassifier) { MavenProject module = this.getMavenProject(current.getArtifact()); if (module != null) { // Filter does NOT work // AndArtifactFilter scopeFilter = new AndArtifactFilter(); // scopeFilter.add(new ScopeArtifactFilter(Artifact.SCOPE_COMPILE)); // scopeFilter.add(new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME)); try { current = dependencyTreeBuilder.buildDependencyTree(module, localRepository, factory, artifactMetadataSource, null, collector); } catch (DependencyTreeBuilderException e) { throw new MojoExecutionException("Unable to build dependency tree", e); }/*from w ww. ja v a2 s .c o m*/ } } // dump (part 1) indent(current, out); out.print("<artifact"); Artifact artifact = current.getArtifact(); addAttribute(out, "id", artifact.getArtifactId()); addAttribute(out, "group", artifact.getGroupId()); // Get version from HashMap String v = includedArtifacts.get(artifact.getArtifactId()); if (v != null) { artifact.setVersion(v); } addAttribute(out, "version", artifact.getVersion()); addAttribute(out, "type", artifact.getType()); addAttribute(out, "scope", artifact.getScope()); addAttribute(out, "classifier", artifact.getClassifier()); try { addAttribute(out, "file", this.getJarFile(artifact).toString()); } catch (Exception e) { getLog().debug(artifact.getArtifactId() + "Could not find JAR"); } MavenProject proj = this.getMavenProject(artifact); if (proj != null) { if (!proj.getName().startsWith("Unnamed - ")) { addAttribute(out, "name", proj.getName()); } addAttribute(out, "description", proj.getDescription()); addAttribute(out, "url", proj.getUrl()); if (proj.getOrganization() != null) { addAttribute(out, "organization", proj.getOrganization().getName()); addAttribute(out, "organizationUrl", proj.getOrganization().getUrl()); } if (proj.getLicenses().size() > 0) { License license = (License) proj.getLicenses().get(0); addAttribute(out, "license", license.getName()); addAttribute(out, "licenseUrl", license.getUrl()); } } out.println(">"); // recurse for (Iterator it = current.getChildren().iterator(); it.hasNext();) { DependencyNode child = (DependencyNode) it.next(); // filter dependencies with scope "test", except those with classifier "tests" (i.e. adaptor integration tests) if ("test".equals(child.getArtifact().getScope()) && !"tests".equals(child.getArtifact().getClassifier())) { Artifact c = child.getArtifact(); getLog().debug(artifact.getArtifactId() + ": ignoring dependency " + c.getGroupId() + ":" + c.getArtifactId()); } else { this.dump(child, out); } } // dump (part 2) indent(current, out); out.println("</artifact>"); }
From source file:io.github.patrickpilch.dependencylicensechecker.DependencyChecker.java
License:Open Source License
private List<License> getArtifactLicenses(final Artifact artifact) throws ProjectResolutionException { try {/*from w ww . j a va 2 s . co m*/ 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); } }
From source file:io.sundr.maven.GenerateBomMojo.java
License:Apache License
/** * Returns the model of the {@link org.apache.maven.project.MavenProject} to generate. * This is a trimmed down version and contains just the stuff that need to go into the bom. * * @param project The source {@link org.apache.maven.project.MavenProject}. * @param config The {@link io.sundr.maven.BomConfig}. * @return The build {@link org.apache.maven.project.MavenProject}. *///from w w w . j a v a2 s .c o m private static MavenProject toGenerate(MavenProject project, BomConfig config, Collection<Dependency> dependencies, Set<Artifact> plugins) { MavenProject toGenerate = project.clone(); toGenerate.setGroupId(project.getGroupId()); toGenerate.setArtifactId(config.getArtifactId()); toGenerate.setVersion(project.getVersion()); toGenerate.setPackaging("pom"); toGenerate.setName(config.getName()); toGenerate.setDescription(config.getDescription()); toGenerate.setUrl(project.getUrl()); toGenerate.setLicenses(project.getLicenses()); toGenerate.setScm(project.getScm()); toGenerate.setDevelopers(project.getDevelopers()); toGenerate.getModel().setDependencyManagement(new DependencyManagement()); for (Dependency dependency : dependencies) { toGenerate.getDependencyManagement().addDependency(dependency); } toGenerate.getModel().setBuild(new Build()); if (!plugins.isEmpty()) { toGenerate.getModel().setBuild(new Build()); toGenerate.getModel().getBuild().setPluginManagement(new PluginManagement()); for (Artifact artifact : plugins) { toGenerate.getPluginManagement().addPlugin(toPlugin(artifact)); } } return toGenerate; }
From source file:io.sundr.maven.GenerateBomMojo.java
License:Apache License
/** * Returns the generated {@link org.apache.maven.project.MavenProject} to build. * This version of the project contains all the stuff needed for building (parents, profiles, properties etc). * * @param project The source {@link org.apache.maven.project.MavenProject}. * @param config The {@link io.sundr.maven.BomConfig}. * @return The build {@link org.apache.maven.project.MavenProject}. *///from w w w.j a v a 2 s . c o m private static MavenProject toBuild(MavenProject project, BomConfig config) { File outputDir = new File(project.getBuild().getOutputDirectory()); File bomDir = new File(outputDir, config.getArtifactId()); File generatedBom = new File(bomDir, BOM_NAME); MavenProject toBuild = project.clone(); //we want to avoid recursive "generate-bom". toBuild.setExecutionRoot(false); toBuild.setFile(generatedBom); toBuild.getModel().setPomFile(generatedBom); toBuild.setModelVersion(project.getModelVersion()); toBuild.setArtifact(new DefaultArtifact(project.getGroupId(), config.getArtifactId(), project.getVersion(), project.getArtifact().getScope(), project.getArtifact().getType(), project.getArtifact().getClassifier(), project.getArtifact().getArtifactHandler())); toBuild.setParent(project.getParent()); toBuild.getModel().setParent(project.getModel().getParent()); toBuild.setGroupId(project.getGroupId()); toBuild.setArtifactId(config.getArtifactId()); toBuild.setVersion(project.getVersion()); toBuild.setPackaging("pom"); toBuild.setName(config.getName()); toBuild.setDescription(config.getDescription()); toBuild.setUrl(project.getUrl()); toBuild.setLicenses(project.getLicenses()); toBuild.setScm(project.getScm()); toBuild.setDevelopers(project.getDevelopers()); toBuild.setDistributionManagement(project.getDistributionManagement()); toBuild.getModel().setProfiles(project.getModel().getProfiles()); //We want to avoid having the generated stuff wiped. toBuild.getProperties().put("clean.skip", "true"); toBuild.getModel().getBuild().setDirectory(bomDir.getAbsolutePath()); toBuild.getModel().getBuild().setOutputDirectory(new File(bomDir, "target").getAbsolutePath()); for (String key : config.getProperties().stringPropertyNames()) { toBuild.getProperties().put(key, config.getProperties().getProperty(key)); } return toBuild; }