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

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

Introduction

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

Prototype

public String getVersion() 

Source Link

Usage

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

License:Apache License

public DashBoardMavenProject getDashBoardMavenProject(MavenProject project, String dashboardDataFile,
        Date generatedDate) {/*from ww w.j  a v  a2  s  .co m*/

    String projectName = project.getName();
    // Fixes MOJO-801. NPE in a particular three level multimodule build
    this.fillProjectMap(project);

    DashBoardMavenProject mavenProject;
    if (project.getModules().size() > 0) {
        // String artefactId = project.getGroupId() + "." + project.getArtifactId();
        mavenProject = new DashBoardMavenProject(project.getArtifactId(), project.getGroupId(), projectName,
                project.getVersion());
        for (int i = 0; i < project.getModules().size(); i++) {
            String modulename = (String) project.getModules().get(i);

            MavenProject proj = this.getModuleMavenProject(project, modulename);
            String key = proj.getGroupId() + "." + proj.getArtifactId();
            if (this.projectMap.containsKey(key)) {
                MavenProject realproj = (MavenProject) this.projectMap.get(key);
                DashBoardMavenProject subMavenProject = dashBoardUtils.getDashBoardMavenProject(realproj,
                        dashboardDataFile, generatedDate);
                mavenProject.addModule(subMavenProject);
            }

        }

    } else {
        mavenProject = new DashBoardMavenProject(project.getArtifactId(), project.getGroupId(), projectName,
                project.getVersion());
        for (Iterator reports = project.getReportPlugins().iterator(); reports.hasNext();) {
            ReportPlugin report = (ReportPlugin) reports.next();
            String artifactId = report.getArtifactId();
            AbstractReportBean dashBoardReport = null;
            if ("maven-checkstyle-plugin".equals(artifactId) || "checkstyle-maven-plugin".equals(artifactId)) {
                dashBoardReport = this.getCheckstyleReport(project, generatedDate);
            } else if ("maven-clover-plugin".equals(artifactId)) {
                dashBoardReport = this.getCloverReport(project, generatedDate);
            } else if ("maven-surefire-report-plugin".equals(artifactId)
                    || "surefire-report-maven-plugin".equals(artifactId)) {
                dashBoardReport = this.getSurefireReport(project, generatedDate);
            } else if ("cobertura-maven-plugin".equals(artifactId)
                    || "maven-cobertura-plugin".equals(artifactId)) {
                dashBoardReport = this.getCoberturaReport(project, generatedDate);
            } else if ("maven-pmd-plugin".equals(artifactId) || "pmd-maven-plugin".equals(artifactId)) {
                dashBoardReport = this.getCpdReport(project, generatedDate);
                if (dashBoardReport != null) {
                    mavenProject.addReport(dashBoardReport);
                }
                dashBoardReport = this.getPmdReport(project, generatedDate);
            } else if ("maven-findbugs-plugin".equals(artifactId)
                    || "findbugs-maven-plugin".equals(artifactId)) {
                dashBoardReport = this.getFindBugsReport(project, generatedDate);
            } else if ("maven-jdepend-plugin".equals(artifactId) || "jdepend-maven-plugin".equals(artifactId)) {
                if (!this.dbPersist) {
                    dashBoardReport = this.getJDependReport(project, generatedDate);
                }
            } else if ("maven-taglist-plugin".equals(artifactId) || "taglist-maven-plugin".equals(artifactId)) {
                dashBoardReport = this.getTaglistReport(project, generatedDate);
            }
            if (dashBoardReport != null) {
                mavenProject.addReport(dashBoardReport);
            }
        }
    }
    return mavenProject;
}

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());
    models.put(coordinates, project.getFile());
}

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 .  j  a v  a2  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

/**
 * {@inheritDoc}//  ww  w.  j ava 2 s  .co  m
 */
public SortedProperties loadUnsafeMapping(LicenseMap licenseMap, SortedMap<String, MavenProject> artifactCache,
        String encoding, File missingFile) throws IOException {
    Map<String, MavenProject> snapshots = new HashMap<String, MavenProject>();

    //find snapshot dependencies
    for (Map.Entry<String, MavenProject> entry : artifactCache.entrySet()) {
        MavenProject mavenProject = entry.getValue();
        if (mavenProject.getVersion().endsWith(Artifact.SNAPSHOT_VERSION)) {
            snapshots.put(entry.getKey(), mavenProject);
        }
    }

    for (Map.Entry<String, MavenProject> snapshot : snapshots.entrySet()) {
        // remove invalid entries, which contain timestamps in key
        artifactCache.remove(snapshot.getKey());
        // put corrected keys/entries into artifact cache
        MavenProject mavenProject = snapshot.getValue();

        String id = MojoHelper.getArtifactId(mavenProject.getArtifact());
        artifactCache.put(id, mavenProject);

    }
    SortedSet<MavenProject> unsafeDependencies = getProjectsWithNoLicense(licenseMap, false);

    SortedProperties unsafeMappings = new SortedProperties(encoding);

    if (missingFile.exists()) {
        // there is some unsafe dependencies

        getLogger().info("Load missing file " + missingFile);

        // load the missing file
        unsafeMappings.load(missingFile);
    }

    // get from the missing file, all unknown dependencies
    List<String> unknownDependenciesId = new ArrayList<String>();

    // coming from maven-license-plugin, we used the full g/a/v/c/t. Now we remove classifier and type
    // since GAV is good enough to qualify a license of any artifact of it...
    Map<String, String> migrateKeys = migrateMissingFileKeys(unsafeMappings.keySet());

    for (Object o : migrateKeys.keySet()) {
        String id = (String) o;
        String migratedId = migrateKeys.get(id);

        MavenProject project = artifactCache.get(migratedId);
        if (project == null) {
            // now we are sure this is a unknown dependency
            unknownDependenciesId.add(id);
        } else {
            if (!id.equals(migratedId)) {

                // migrates id to migratedId
                getLogger().info("Migrates [" + id + "] to [" + migratedId + "] in the missing file.");
                Object value = unsafeMappings.get(id);
                unsafeMappings.remove(id);
                unsafeMappings.put(migratedId, value);
            }
        }
    }

    if (!unknownDependenciesId.isEmpty()) {

        // there is some unknown dependencies in the missing file, remove them
        for (String id : unknownDependenciesId) {
            getLogger().warn(
                    "dependency [" + id + "] does not exist in project, remove it from the missing file.");
            unsafeMappings.remove(id);
        }

        unknownDependenciesId.clear();
    }

    // push back loaded dependencies
    for (Object o : unsafeMappings.keySet()) {
        String id = (String) o;

        MavenProject project = artifactCache.get(id);
        if (project == null) {
            getLogger().warn("dependency [" + id + "] does not exist in project.");
            continue;
        }

        String license = (String) unsafeMappings.get(id);

        String[] licenses = StringUtils.split(license, '|');

        if (ArrayUtils.isEmpty(licenses)) {

            // empty license means not fill, skip it
            continue;
        }

        // add license in map
        addLicense(licenseMap, project, licenses);

        // remove unknown license
        unsafeDependencies.remove(project);
    }

    if (unsafeDependencies.isEmpty()) {

        // no more unknown license in map
        licenseMap.remove(LicenseMap.UNKNOWN_LICENSE_MESSAGE);
    } else {

        // add a "with no value license" for missing dependencies
        for (MavenProject project : unsafeDependencies) {
            String id = MojoHelper.getArtifactId(project.getArtifact());
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("dependency [" + id + "] has no license, add it in the missing file.");
            }
            unsafeMappings.setProperty(id, "");
        }
    }
    return unsafeMappings;
}

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

License:Open Source License

/**
 * @param project         not null//from  ww w  . j a v  a  2  s .  c o m
 * @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  w w .ja v a  2 s . com
        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;/*w  w  w . j ava2  s.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 ww  . j a va2  s  .c  om*/
 *            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.nbm.CreateUpdateSiteMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {
    Project antProject = registerNbmAntTasks();
    File nbmBuildDirFile = new File(outputDirectory, "netbeans_site");
    if (!nbmBuildDirFile.exists()) {
        nbmBuildDirFile.mkdirs();//w ww .ja  va 2  s  .  c  o m
    }

    boolean isRepository = false;
    if ("auto".equals(distBase)) {
        distBase = null;
    }
    ArtifactRepository distRepository = getDeploymentRepository(distBase, container, getLog());
    String oldDistBase = null;
    if (distRepository != null) {
        isRepository = true;
    } else {
        if (distBase != null && !distBase.contains("::")) {
            oldDistBase = distBase;
        }
    }

    if ("nbm-application".equals(project.getPackaging())) {
        @SuppressWarnings("unchecked")
        Set<Artifact> artifacts = project.getArtifacts();
        for (Artifact art : artifacts) {
            if (!matchesIncludes(art)) {
                continue;
            }
            ArtifactResult res = turnJarToNbmFile(art, artifactFactory, artifactResolver, project,
                    localRepository);
            if (res.hasConvertedArtifact()) {
                art = res.getConvertedArtifact();
            }

            if (art.getType().equals("nbm-file")) {
                Copy copyTask = (Copy) antProject.createTask("copy");
                copyTask.setOverwrite(true);
                copyTask.setFile(art.getFile());
                if (!isRepository) {
                    copyTask.setFlatten(true);
                    copyTask.setTodir(nbmBuildDirFile);
                } else {
                    String path = distRepository.pathOf(art);
                    File f = new File(nbmBuildDirFile, path.replace('/', File.separatorChar));
                    copyTask.setTofile(f);
                }
                try {
                    copyTask.execute();
                } catch (BuildException ex) {
                    throw new MojoExecutionException("Cannot merge nbm files into autoupdate site", ex);
                }

            }
            if (res.isOSGiBundle()) {
                // TODO check for bundles
            }
        }
        getLog().info("Created NetBeans module cluster(s) at " + nbmBuildDirFile.getAbsoluteFile());

    } else if (reactorProjects != null && reactorProjects.size() > 0) {

        Iterator it = reactorProjects.iterator();
        while (it.hasNext()) {
            MavenProject proj = (MavenProject) it.next();
            //TODO how to figure where the the buildDir/nbm directory is
            File moduleDir = proj.getFile().getParentFile();
            if (moduleDir != null && moduleDir.exists()) {
                Copy copyTask = (Copy) antProject.createTask("copy");
                if (!isRepository) {
                    FileSet fs = new FileSet();
                    File projOutputDirectory = new File(proj.getBuild().getDirectory());
                    fs.setDir(projOutputDirectory);
                    fs.createInclude().setName("*.nbm");
                    copyTask.addFileset(fs);
                    copyTask.setOverwrite(true);
                    copyTask.setFlatten(true);
                    copyTask.setTodir(nbmBuildDirFile);
                } else {
                    File target = new File(proj.getBuild().getDirectory());
                    boolean has = false;
                    File[] fls = target.listFiles();
                    if (fls != null) {
                        for (File fl : fls) {
                            if (fl.getName().endsWith(".nbm")) {
                                copyTask.setFile(fl);
                                has = true;
                                break;
                            }
                        }
                    }
                    if (!has) {
                        continue;
                    }
                    Artifact art = artifactFactory.createArtifact(proj.getGroupId(), proj.getArtifactId(),
                            proj.getVersion(), null, "nbm-file");
                    String path = distRepository.pathOf(art);
                    File f = new File(nbmBuildDirFile, path.replace('/', File.separatorChar));
                    copyTask.setTofile(f);
                }
                try {
                    copyTask.execute();
                } catch (BuildException ex) {
                    throw new MojoExecutionException("Cannot merge nbm files into autoupdate site", ex);
                }
            }
        }
    } else {
        throw new MojoExecutionException(
                "This goal only makes sense on reactor projects or project with 'nbm-application' packaging.");

    }
    MakeUpdateDesc descTask = (MakeUpdateDesc) antProject.createTask("updatedist");
    File xmlFile = new File(nbmBuildDirFile, fileName);
    descTask.setDesc(xmlFile);
    if (oldDistBase != null) {
        descTask.setDistBase(oldDistBase);
    }
    if (distRepository != null) {
        descTask.setDistBase(distRepository.getUrl());
    }
    FileSet fs = new FileSet();
    fs.setDir(nbmBuildDirFile);
    fs.createInclude().setName("**/*.nbm");
    descTask.addFileset(fs);
    try {
        descTask.execute();
    } catch (BuildException ex) {
        throw new MojoExecutionException("Cannot create autoupdate site xml file", ex);
    }
    getLog().info("Generated autoupdate site content at " + nbmBuildDirFile.getAbsolutePath());

    try {
        GZipArchiver gz = new GZipArchiver();
        gz.addFile(xmlFile, fileName);
        File gzipped = new File(nbmBuildDirFile, fileName + ".gz");
        gz.setDestFile(gzipped);
        gz.createArchive();
        if ("nbm-application".equals(project.getPackaging())) {
            projectHelper.attachArtifact(project, "xml.gz", "updatesite", gzipped);
        }
    } catch (Exception ex) {
        throw new MojoExecutionException("Cannot create gzipped version of the update site xml file.", ex);
    }

}

From source file:org.codehaus.mojo.pom.DependencyInfo.java

License:Apache License

/**
 * The constructor from a {@link MavenProject}.
 *///  w w w.  j a  va  2s . co m
public DependencyInfo(MavenProject project) {

    this(project.getGroupId(), project.getArtifactId(), project.getVersion(), project.getPackaging(), null,
            null);
}