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

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

Introduction

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

Prototype

public String getArtifactId() 

Source Link

Usage

From source file:org.codehaus.mojo.dashboard.report.plugin.DashBoardUtils.java

License:Apache License

/**
 * Fixes MOJO-801. NPE in a particular three level multimodule build
 * //  ww  w. j a  va2  s  .c  o m
 * @param project
 */
private void fillProjectMap(MavenProject project) {
    if (project.getModules().size() > 0) {
        Iterator iter = project.getCollectedProjects().iterator();

        while (iter.hasNext()) {
            MavenProject proj = (MavenProject) iter.next();
            String key = proj.getGroupId() + "." + proj.getArtifactId();
            if (!this.projectMap.containsKey(key)) {
                this.projectMap.put(key, proj);
            }
        }
    } else {
        String key = project.getGroupId() + "." + project.getArtifactId();
        if (!this.projectMap.containsKey(key)) {
            this.projectMap.put(key, project);
        }
    }
}

From source file:org.codehaus.mojo.flatten.model.resolution.ReactorModelPool.java

License:Apache License

public void addProject(MavenProject project) {
    Coordinates coordinates = new Coordinates(project.getGroupId(), project.getArtifactId(),
            project.getVersion());//from ww  w .j  ava  2  s  . c  om
    models.put(coordinates, project.getFile());
}

From source file:org.codehaus.mojo.gwt.eclipse.EclipseUtil.java

License:Apache License

/**
 * Read the Eclipse project name for .project file. Fall back to artifactId on error
 *
 * @return project name in eclipse workspace
 *//*from w w w  .  j a  v a2  s.c  o  m*/
public String getProjectName(MavenProject project) {
    File dotProject = new File(project.getBasedir(), ".project");
    try {
        Xpp3Dom dom = Xpp3DomBuilder.build(ReaderFactory.newXmlReader(dotProject));
        return dom.getChild("name").getValue();
    } catch (Exception e) {
        getLogger().warn("Failed to read the .project file");
        return project.getArtifactId();
    }
}

From source file:org.codehaus.mojo.jsimport.LocalRepositoryCollector.java

License:Apache License

/**
 * Constructor./*ww  w.jav  a 2 s.c  o m*/
 * 
 * @param project The Maven project to be processed.
 * @param localRepository The local repository being used by Maven.
 * @param additionalFolderBases an array containing the locations of additional base folders to be considered.
 */
public LocalRepositoryCollector(MavenProject project, //
        ArtifactRepository localRepository, File[] additionalFolderBases) {
    // The local repo will always be in this list and it is optimal to assume that it will be hit tested the most
    // outside of here.
    localRepositoryPaths.add(localRepository.getBasedir());

    // Determine the root project

    String projectArtifactId = project.getArtifactId();

    MavenProject parentProject = project.getParent();
    while (parentProject != null) {
        List<?> modules = parentProject.getModules();
        if (modules.contains(projectArtifactId)) {
            projectArtifactId = parentProject.getArtifactId();
            String parentProjectPath = parentProject.getBasedir().getAbsolutePath();
            localRepositoryPaths.add(parentProjectPath);
        } else {
            break;
        }

        parentProject = parentProject.getParent();
    }

    // Consider additional folders and their immediate sub folders.

    for (File additionalFolderBase : additionalFolderBases) {
        File[] additionalFolders = additionalFolderBase.listFiles();
        if (additionalFolders != null) {
            for (File additionalFolder : additionalFolders) {
                if (additionalFolder.isDirectory()) {
                    localRepositoryPaths.add(additionalFolder.getAbsolutePath());
                }
            }
        }
    }
}

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
 *///ww  w.j a  va 2 s.c  om
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.DefaultThirdPartyTool.java

License:Open Source License

/**
 * @param project         not null//w ww .  ja  v  a2 s  .com
 * @param localRepository not null
 * @param repositories    not null
 * @return the resolved site descriptor
 * @throws IOException                 if any
 * @throws ArtifactResolutionException if any
 * @throws ArtifactNotFoundException   if any
 */
private File resolveThirdPartyDescriptor(MavenProject project, ArtifactRepository localRepository,
        List<ArtifactRepository> repositories)
        throws IOException, ArtifactResolutionException, ArtifactNotFoundException {
    File result;
    try {
        result = resolveArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(),
                DESCRIPTOR_TYPE, DESCRIPTOR_CLASSIFIER, localRepository, repositories);

        // we use zero length files to avoid re-resolution (see below)
        if (result.length() == 0) {
            getLogger().debug("Skipped third party descriptor");
        }
    } catch (ArtifactNotFoundException e) {
        getLogger().debug("Unable to locate third party files descriptor : " + e);

        // we can afford to write an empty descriptor here as we don't expect it to turn up later in the remote
        // repository, because the parent was already released (and snapshots are updated automatically if changed)
        result = new File(localRepository.getBasedir(), localRepository.pathOf(e.getArtifact()));

        FileUtil.createNewFile(result);
    }

    return result;
}

From source file:org.codehaus.mojo.license.ArtifactHelper.java

License:Open Source License

public static String getArtifactName(MavenProject project) {
    StringBuilder sb = new StringBuilder();
    if (project.getName().startsWith("Unnamed -")) {

        // as in Maven 3, let's use the artifact id
        sb.append(project.getArtifactId());
    } else {/*from w  ww.j  a va2 s . c om*/
        sb.append(project.getName());
    }
    sb.append(" (");
    sb.append(project.getGroupId());
    sb.append(":");
    sb.append(project.getArtifactId());
    sb.append(":");
    sb.append(project.getVersion());
    sb.append(" - ");
    String url = project.getUrl();
    sb.append(url == null ? "no url defined" : url);
    sb.append(")");

    return sb.toString();
}

From source file:org.codehaus.mojo.license.DefaultThirdPartyTool.java

License:Educational Community License

protected String getLicense(MavenProject d, Properties mappings) {
    String groupId = d.getGroupId();
    String artifactId = d.getArtifactId();
    String version = d.getVersion();

    // Exact match
    String id1 = groupId + "--" + artifactId + "--" + version;
    // Match on groupId + artifactId
    String id2 = groupId + "--" + artifactId;
    // Match on groupId
    String id3 = groupId;/*from w w  w  .j  ava  2s .c om*/

    String value1 = mappings.getProperty(id1);
    String value2 = mappings.getProperty(id2);
    String value3 = mappings.getProperty(id3);

    // Return the license, starting with the most specific, progressing to the least specific
    if (!StringUtils.isBlank(value1)) {
        return value1;
    } else if (!StringUtils.isBlank(value2)) {
        return value2;
    } else if (!StringUtils.isBlank(value3)) {
        return value3;
    } else {
        return null;
    }
}

From source file:org.codehaus.mojo.license.DefaultThirdPartyTool.java

License:Educational Community License

/**
 * @param project// w w w  .j a  v a2 s  . co m
 *            not null
 * @param localRepository
 *            not null
 * @param repositories
 *            not null
 * @return the resolved site descriptor
 * @throws IOException
 *             if any
 * @throws ArtifactResolutionException
 *             if any
 * @throws ArtifactNotFoundException
 *             if any
 */
private File resolveThirdPartyDescriptor(MavenProject project, ArtifactRepository localRepository,
        List<ArtifactRepository> repositories)
        throws IOException, ArtifactResolutionException, ArtifactNotFoundException {
    File result;

    // TODO: this is a bit crude - proper type, or proper handling as metadata rather than an artifact in 2.1?
    Artifact artifact = artifactFactory.createArtifactWithClassifier(project.getGroupId(),
            project.getArtifactId(), project.getVersion(), DESCRIPTOR_TYPE, DESCRIPTOR_CLASSIFIER);
    try {
        artifactResolver.resolve(artifact, repositories, localRepository);

        result = artifact.getFile();

        // we use zero length files to avoid re-resolution (see below)
        if (result.length() == 0) {
            getLogger().debug("Skipped third party descriptor");
        }
    } catch (ArtifactNotFoundException e) {
        getLogger().debug("Unable to locate third party files descriptor : " + e);

        // we can afford to write an empty descriptor here as we don't expect it to turn up later in the remote
        // repository, because the parent was already released (and snapshots are updated automatically if changed)
        result = new File(localRepository.getBasedir(), localRepository.pathOf(artifact));

        FileUtil.createNewFile(result);
    }

    return result;
}

From source file:org.codehaus.mojo.license.utils.MojoHelper.java

License:Open Source License

public static String getProjectName(MavenProject project) {
    String sb;/* w  ww.  j a v a  2  s.  com*/
    if (project.getName().startsWith("Unnamed")) {

        // as in Maven 3, let's use the artifact id
        sb = project.getArtifactId();
    } else {
        sb = project.getName();
    }

    return sb;
}