Example usage for org.apache.maven.project MavenProject getName

List of usage examples for org.apache.maven.project MavenProject getName

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getName.

Prototype

public String getName() 

Source Link

Usage

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.//from   w  w w  . j  av  a  2 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  w  w . ja va2  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()));
        }/*ww w  .  java 2s.c  o  m*/
        licenseDependencies.add(new LicenseDependency(depProject.getName(), dependency, licenses));
    }

    return licenseDependencies;
}

From source file:com.xebia.mojo.dashboard.DashboardMojo.java

License:Apache License

private void createProjectNameCell(MavenProject subProject, Element tableRow) {
    Element projectElement = createTableCell(tableRow, null);
    createLink(projectElement, DashboardUtil.determineCompletePath(subProject) + "index.html",
            subProject.getName());
}

From source file:de.eacg.ecs.plugin.ScanAndTransferMojo.java

private Dependency mapDependency(DependencyNode node,
        Map<ComponentId, Map.Entry<MavenProject, String[]>> projectLookup) {
    Dependency.Builder builder = new Dependency.Builder();
    Artifact artifact = node.getArtifact();
    ComponentId artifactId = ComponentId.create(artifact);
    Map.Entry<MavenProject, String[]> projectLicensesPair = projectLookup.get(artifactId);

    // try fallback to artifact baseVersion, (for example because a snapshot is locked )
    if (projectLicensesPair == null) {
        projectLicensesPair = projectLookup.get(ComponentId.createFallback(artifact));
    }//from   w w w.j a v a  2 s . co  m

    if (projectLicensesPair == null) {
        getLog().error("Something weird happened: no Project found for artifact: " + artifactId);
        return null;
    }

    MavenProject project = projectLicensesPair.getKey();
    String[] licensesArr = projectLicensesPair.getValue();

    builder.setName(project.getName()).setDescription(project.getDescription())
            .setKey("mvn:" + project.getGroupId() + ':' + project.getArtifactId())
            .addVersion(project.getVersion()).setHomepageUrl(project.getUrl());
    if (isPrivateComponent(project)) {
        builder.setPrivate(true);
    }

    try {
        File file = artifact.getFile();
        if (file != null) {
            builder.setChecksum("sha-1:" + ChecksumCreator.createChecksum(file));
        } else {
            Artifact af = findProjectArtifact(artifact);
            if (af != null && af.getFile() != null) {
                builder.setChecksum("sha-1:" + ChecksumCreator.createChecksum(af.getFile()));
            } else {
                getLog().warn(
                        "Could not generate checksum - no file specified: " + ComponentId.create(artifact));
            }
        }
    } catch (NoSuchAlgorithmException | IOException e) {
        getLog().warn("Could not generate checksum: " + e.getMessage());
    }

    if (licensesArr != null
            && (licensesArr.length != 1 || !LicenseMap.UNKNOWN_LICENSE_MESSAGE.equals(licensesArr[0]))) {
        for (String license : licensesArr) {
            builder.addLicense(license);
        }
    }

    for (DependencyNode childNode : node.getChildren()) {
        Dependency dep = mapDependency(childNode, projectLookup);
        if (dep != null) {
            builder.addDependency(dep);
        }
    }

    return builder.buildDependency();
}

From source file:de.eacg.ecs.plugin.ScanAndTransferMojo.java

private void printStats(Set<Map.Entry<String, SortedSet<MavenProject>>> licenseAndProjectSet,
        Set<Map.Entry<MavenProject, String[]>> projectsAndLicenseSet) {

    Log log = getLog();/*ww  w  .  j  a va  2s .  c om*/
    if (log.isInfoEnabled() && this.verbose) {
        log.info("Dependencies found:");
        for (Map.Entry<MavenProject, String[]> entry : projectsAndLicenseSet) {
            MavenProject project = entry.getKey();
            String[] licenses = entry.getValue();
            log.info(String.format("%s %s, %s", project.getId(), project.getName(), Arrays.toString(licenses)));
        }
    }
    if (log.isInfoEnabled()) {
        log.info("Licenses found:");
        for (Map.Entry<String, SortedSet<MavenProject>> entry : licenseAndProjectSet) {
            log.info(String.format("%-75s %d", entry.getKey(), entry.getValue().size()));
        }
    }
}

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 .  jav  a  2  s .c  o  m*/
    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.smartics.maven.enforcer.rule.AbstractNoCyclicPackageDependencyRule.java

License:Apache License

/**
 * {@inheritDoc}/*w  ww .  j  a  va2  s . c o  m*/
 */
// CHECKSTYLE:OFF
@SuppressWarnings("unchecked")
public void execute(final EnforcerRuleHelper helper) throws EnforcerRuleException {
    final Log log = helper.getLog();

    try {
        final MavenProject project = (MavenProject) helper.evaluate("${project}");
        final String projectName = project.getName();

        final File classesDir = new File((String) helper.evaluate("${project.build.outputDirectory}"));

        if (classesDir.canRead()) {
            final JDepend jdepend = new JDepend();
            jdepend.addDirectory(classesDir.getAbsolutePath());
            addTestClassesIfRequested(helper, classesDir, jdepend);

            final Collection<JavaPackage> packages = jdepend.analyze();
            if (jdepend.containsCycles()) {
                final String buffer = collectCycles(packages);
                throw new EnforcerRuleException(
                        "Dependency cycle check found package cycles in '" + projectName + "': " + buffer);
            } else {
                log.info("No package cycles found in '" + projectName + "'.");
            }
        } else {
            log.warn("Skipping package cycle analysis since '" + classesDir + "' does not exist.");
        }
    } catch (final ExpressionEvaluationException e) {
        throw new EnforcerRuleException(
                "Dependency cycle check is unable to evaluate expression '" + e.getLocalizedMessage() + "'.",
                e);
    } catch (final IOException e) {
        throw new EnforcerRuleException("Dependency cycle check is unable to access a classes directory '"
                + e.getLocalizedMessage() + "'.", e);
    }
}

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);
            }/*  w w w .  jav a 2  s .c om*/
        }
    }

    // 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:hudson.gridmaven.PomInfo.java

License:Open Source License

public PomInfo(MavenProject project, PomInfo parent, String relPath) {
    this.name = new ModuleName(project);
    this.version = project.getVersion();
    this.displayName = project.getName();
    this.defaultGoal = project.getDefaultGoal();
    this.relativePath = relPath;
    this.parent = parent;
    if (parent != null)
        parent.children.add(name);// ww w.  j a  v a 2s.com

    for (Dependency dep : (List<Dependency>) project.getDependencies())
        dependencies.add(new ModuleDependency(dep));

    MavenProject parentProject = project.getParent();
    if (parentProject != null)
        dependencies.add(new ModuleDependency(parentProject));
    if (parent != null)
        dependencies.add(parent.asDependency());

    addPluginsAsDependencies(project.getBuildPlugins(), dependencies);
    addReportPluginsAsDependencies(project.getReportPlugins(), dependencies);

    List<Extension> extensions = project.getBuildExtensions();
    if (extensions != null)
        for (Extension ext : extensions)
            dependencies.add(new ModuleDependency(ext));

    // when the parent POM uses a plugin and builds a plugin at the same time,
    // the plugin module ends up depending on itself
    dependencies.remove(asDependency());

    CiManagement ciMgmt = project.getCiManagement();
    if ((ciMgmt != null) && (ciMgmt.getSystem() == null || ciMgmt.getSystem().equals("hudson"))) {
        Notifier mailNotifier = null;
        for (Notifier n : (List<Notifier>) ciMgmt.getNotifiers()) {
            if (n.getType().equals("mail")) {
                mailNotifier = n;
                break;
            }
        }
        this.mailNotifier = mailNotifier;
    } else
        this.mailNotifier = null;

    this.groupId = project.getGroupId();
    this.artifactId = project.getArtifactId();
    this.packaging = project.getPackaging();
}