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

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

Introduction

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

Prototype

public File getFile() 

Source Link

Usage

From source file:org.codehaus.cargo.documentation.ConfluenceProjectStructureDocumentationGenerator.java

License:Apache License

/**
 * Creates the wiki markup for any Modules found for the given MavenProject instance.
 * @param aProject the current MavenProject we are analyzing for modules.
 * @param treeIndex the current project level in the source tree.
 * @return wiki markup for the given MavenProject's modules.
 *//*from w ww .  jav a2s.c  o m*/
private String getModuleTree(MavenProject aProject, int treeIndex) {
    StringBuilder markup = new StringBuilder();
    List<String> modules = aProject.getModules();
    int newTreeIndex = modules.size() > 0 ? treeIndex + 1 : treeIndex;
    for (String moduleArtifactId : modules) {
        File moduleDirectory = new File(aProject.getFile().getParent(), moduleArtifactId);
        MavenProject moduleProject = createProjectFromPom(new File(moduleDirectory, POM));
        for (int i = 0; i < treeIndex; i++) {
            markup.append(ASTERISK);
        }
        markup.append(getProjectInfo(moduleProject, newTreeIndex));
    }
    return markup.toString();
}

From source file:org.codehaus.mojo.cassandra.Utils.java

License:Apache License

/**
 * Returns {@code true} if the resource is not a file, does not exist or is older than the project file.
 *
 * @param project  the project that the resource is dependent on.
 * @param resource the resource to query.
 * @return {@code true} if the resource is not a file, does not exist or is older than the project file.
 *///from   w w w  .j  av  a 2 s .  c o  m
static boolean shouldGenerateResource(MavenProject project, File resource) {
    if (!resource.isFile()) {
        return true;
    }
    long resourceLM = resource.lastModified();
    long projectLM = project.getFile().lastModified();
    if (Long.signum(resourceLM) == Long.signum(projectLM)) {
        // the two dates are in the same epoch or else the universe is lasting a really long time.
        return resourceLM < projectLM;
    }
    // the universe has been around long enough that we should rewrite the resource.
    return true;
}

From source file:org.codehaus.mojo.config.ConfigLifecycleParticipant.java

License:Open Source License

/**
 * Processes plugin of given container./*  ww w.  j a  v  a 2s .  c  o  m*/
 */
private void processPlugins(final MavenProject project, final Map<String, Xpp3Dom> projectConfigurations,
        final PluginContainer pluginContainer) {
    for (Plugin plugin : pluginContainer.getPlugins()) {
        if (!(groupId.equals(plugin.getGroupId()) && artifactId.equals(plugin.getArtifactId()))) {
            Xpp3Dom pluginConfiguration = (Xpp3Dom) plugin.getConfiguration();
            if (pluginConfiguration != null) {
                Xpp3Dom templateReference = pluginConfiguration.getChild(TEMPLATE_TAG);
                if (templateReference != null) {
                    String name = templateReference.getAttribute(NAME_ATTRIBUTE);
                    checkArgument(name != null,
                            "Found configurationTemplate without %s attribute, plugin %s:%s\nPOM file: %s",
                            NAME_ATTRIBUTE, plugin.getGroupId(), plugin.getArtifactId(),
                            project.getFile().getAbsolutePath());
                    logger.debug("plugin: {} {} needs template {}", plugin.getGroupId(), plugin.getArtifactId(),
                            name);
                    Xpp3Dom projectConfiguration = projectConfigurations.get(name);
                    checkArgument(projectConfiguration != null,
                            "No template defined with name '%s', required by plugin %s:%s configurationTemplate\nPOM file: %s",
                            name, plugin.getGroupId(), plugin.getArtifactId(),
                            project.getFile().getAbsoluteFile());

                    addUnique(projectConfiguration, pluginConfiguration);
                    addUnique(templateReference, pluginConfiguration);
                    removeChildByName(TEMPLATE_TAG, pluginConfiguration);
                }
            }
        }
    }
}

From source file:org.codehaus.mojo.cruisecontrol.CruiseControlMojo.java

License:Apache License

private void addSchedule(XMLWriter writer, MavenProject reactorProject) throws MojoExecutionException {
    writer.startElement("schedule");
    {/*w  w  w.  j a  v  a 2s  .c  om*/
        writer.startElement("maven2");
        {
            writer.addAttribute("mvnhome", mavenHome);
            writer.addAttribute("goal", "-N -B scm:update|-N -B clean install");
            writer.addAttribute("pomfile",
                    "checkout/" + toRelativeAndFixSeparator(basedir, reactorProject.getFile()));
        }
        writer.endElement();
    }
    writer.endElement();

}

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());/*ww  w .  j  a  va  2  s. co  m*/
    models.put(coordinates, project.getFile());
}

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 w w . ja v  a  2s  . co  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.versions.api.PomHelper.java

License:Apache License

/**
 * Gets the raw model before any interpolation what-so-ever.
 *
 * @param project The project to get the raw model for.
 * @return The raw model.// w  w  w .  j av  a  2  s  .c  om
 * @throws IOException if the file is not found or if the file does not parse.
 */
public static Model getRawModel(MavenProject project) throws IOException {
    return getRawModel(project.getFile());
}

From source file:org.codehaus.mojo.versions.branch.BranchMojo.java

License:Apache License

private static Map<String, ModelFileTuple> loadModels(MavenProject project, Log logger) throws IOException {
    Map<String, ModelFileTuple> result = new LinkedHashMap<>();
    Model model = getRawModel(project);//  ww  w  .j  a v  a2  s . c om
    result.put(moduleId(model), new ModelFileTuple(model, project.getFile()));
    result.putAll(loadModels("", model, project, logger));
    return result;
}

From source file:org.codehaus.mojo.versions.DisplayPluginUpdatesMojo.java

License:Apache License

/**
 * @throws MojoExecutionException when things go wrong
 * @throws MojoFailureException   when things go wrong in a very bad way
 * @see AbstractVersionsUpdaterMojo#execute()
 * @since 1.0-alpha-1/* w ww  .  j av a2s.c  o m*/
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    logInit();
    Set<String> pluginsWithVersionsSpecified;
    try {
        pluginsWithVersionsSpecified = findPluginsWithVersionsSpecified(getProject());
    } catch (XMLStreamException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }

    Map<String, String> superPomPluginManagement = getSuperPomPluginManagement();
    getLog().debug("superPom plugins = " + superPomPluginManagement);

    Map<String, String> parentPluginManagement = new HashMap<String, String>();
    Map<String, String> parentBuildPlugins = new HashMap<String, String>();
    Map<String, String> parentReportPlugins = new HashMap<String, String>();

    List<MavenProject> parents = getParentProjects(getProject());

    for (MavenProject parentProject : parents) {
        getLog().debug("Processing parent: " + parentProject.getGroupId() + ":" + parentProject.getArtifactId()
                + ":" + parentProject.getVersion() + " -> " + parentProject.getFile());

        StringWriter writer = new StringWriter();
        boolean havePom = false;
        Model interpolatedModel;
        try {
            Model originalModel = parentProject.getOriginalModel();
            if (originalModel == null) {
                getLog().warn("project.getOriginalModel()==null for  " + parentProject.getGroupId() + ":"
                        + parentProject.getArtifactId() + ":" + parentProject.getVersion()
                        + " is null, substituting project.getModel()");
                originalModel = parentProject.getModel();
            }
            try {
                new MavenXpp3Writer().write(writer, originalModel);
                writer.close();
                havePom = true;
            } catch (IOException e) {
                // ignore
            }
            interpolatedModel = modelInterpolator.interpolate(originalModel, null,
                    new DefaultProjectBuilderConfiguration()
                            .setExecutionProperties(getProject().getProperties()),
                    false);
        } catch (ModelInterpolationException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
        if (havePom) {
            try {
                Set<String> withVersionSpecified = findPluginsWithVersionsSpecified(
                        new StringBuilder(writer.toString()));
                Map<String, String> map = getPluginManagement(interpolatedModel);
                map.keySet().retainAll(withVersionSpecified);
                parentPluginManagement.putAll(map);

                map = getBuildPlugins(interpolatedModel, true);
                map.keySet().retainAll(withVersionSpecified);
                parentPluginManagement.putAll(map);

                map = getReportPlugins(interpolatedModel, true);
                map.keySet().retainAll(withVersionSpecified);
                parentPluginManagement.putAll(map);
            } catch (IOException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            } catch (XMLStreamException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
        } else {
            parentPluginManagement.putAll(getPluginManagement(interpolatedModel));
            parentPluginManagement.putAll(getBuildPlugins(interpolatedModel, true));
            parentPluginManagement.putAll(getReportPlugins(interpolatedModel, true));
        }
    }

    Set<Plugin> plugins = getProjectPlugins(superPomPluginManagement, parentPluginManagement,
            parentBuildPlugins, parentReportPlugins, pluginsWithVersionsSpecified);
    List<String> updates = new ArrayList<String>();
    List<String> lockdowns = new ArrayList<String>();
    Map<ArtifactVersion, Map<String, String>> upgrades = new TreeMap<ArtifactVersion, Map<String, String>>(
            new MavenVersionComparator());
    ArtifactVersion curMavenVersion = runtimeInformation.getApplicationVersion();
    ArtifactVersion specMavenVersion = new DefaultArtifactVersion(getRequiredMavenVersion(getProject(), "2.0"));
    ArtifactVersion minMavenVersion = null;
    boolean superPomDrivingMinVersion = false;
    Iterator<Plugin> i = plugins.iterator();
    while (i.hasNext()) {
        Object plugin = i.next();
        String groupId = getPluginGroupId(plugin);
        String artifactId = getPluginArtifactId(plugin);
        String version = getPluginVersion(plugin);
        String coords = ArtifactUtils.versionlessKey(groupId, artifactId);

        if (version == null) {
            version = parentPluginManagement.get(coords);
        }
        getLog().debug(new StringBuilder().append("Checking ").append(coords).append(" for updates newer than ")
                .append(version).toString());
        String effectiveVersion = version;

        VersionRange versionRange;
        boolean unspecified = version == null;
        try {
            versionRange = unspecified ? VersionRange.createFromVersionSpec("[0,)")
                    : VersionRange.createFromVersionSpec(version);
        } catch (InvalidVersionSpecificationException e) {
            throw new MojoExecutionException("Invalid version range specification: " + version, e);
        }

        Artifact artifact = artifactFactory.createPluginArtifact(groupId, artifactId, versionRange);

        ArtifactVersion artifactVersion = null;
        try {
            // now we want to find the newest version that is compatible with the invoking version of Maven
            ArtifactVersions artifactVersions = getHelper().lookupArtifactVersions(artifact, true);
            ArtifactVersion[] newerVersions = artifactVersions
                    .getVersions(Boolean.TRUE.equals(this.allowSnapshots));
            ArtifactVersion minRequires = null;
            for (int j = newerVersions.length - 1; j >= 0; j--) {
                Artifact probe = artifactFactory.createDependencyArtifact(groupId, artifactId,
                        VersionRange.createFromVersion(newerVersions[j].toString()), "pom", null, "runtime");
                try {
                    getHelper().resolveArtifact(probe, true);
                    MavenProject mavenProject = projectBuilder.buildFromRepository(probe,
                            remotePluginRepositories, localRepository);
                    ArtifactVersion requires = new DefaultArtifactVersion(
                            getRequiredMavenVersion(mavenProject, "2.0"));
                    if (specMavenVersion.compareTo(requires) >= 0 && artifactVersion == null) {
                        artifactVersion = newerVersions[j];
                    }
                    if (effectiveVersion == null && curMavenVersion.compareTo(requires) >= 0) {
                        // version was unspecified, current version of maven thinks it should use this
                        effectiveVersion = newerVersions[j].toString();
                    }
                    if (artifactVersion != null && effectiveVersion != null) {
                        // no need to look at any older versions.
                        break;
                    }
                    if (minRequires == null || minRequires.compareTo(requires) > 0) {
                        Map<String, String> upgradePlugins = upgrades.get(requires);
                        if (upgradePlugins == null) {
                            upgrades.put(requires, upgradePlugins = new LinkedHashMap<String, String>());
                        }
                        String upgradePluginKey = compactKey(groupId, artifactId);
                        if (!upgradePlugins.containsKey(upgradePluginKey)) {
                            upgradePlugins.put(upgradePluginKey, newerVersions[j].toString());
                        }
                        minRequires = requires;
                    }
                } catch (ArtifactResolutionException e) {
                    // ignore bad version
                } catch (ArtifactNotFoundException e) {
                    // ignore bad version
                } catch (ProjectBuildingException e) {
                    // ignore bad version
                }
            }
            if (effectiveVersion != null) {
                VersionRange currentVersionRange = VersionRange.createFromVersion(effectiveVersion);
                Artifact probe = artifactFactory.createDependencyArtifact(groupId, artifactId,
                        currentVersionRange, "pom", null, "runtime");
                try {
                    getHelper().resolveArtifact(probe, true);
                    MavenProject mavenProject = projectBuilder.buildFromRepository(probe,
                            remotePluginRepositories, localRepository);
                    ArtifactVersion requires = new DefaultArtifactVersion(
                            getRequiredMavenVersion(mavenProject, "2.0"));
                    if (minMavenVersion == null || minMavenVersion.compareTo(requires) < 0) {
                        minMavenVersion = requires;
                    }
                } catch (ArtifactResolutionException e) {
                    // ignore bad version
                } catch (ArtifactNotFoundException e) {
                    // ignore bad version
                } catch (ProjectBuildingException e) {
                    // ignore bad version
                }
            }
        } catch (ArtifactMetadataRetrievalException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }

        String newVersion;

        if (version == null && pluginsWithVersionsSpecified.contains(coords)) {
            // Hack ALERT!
            //
            // All this should be re-written in a less "pom is xml" way... but it'll
            // work for now :-(
            //
            // we have removed the version information, as it was the same as from
            // the super-pom... but it actually was specified.
            version = artifactVersion != null ? artifactVersion.toString() : null;
        }

        getLog().debug("[" + coords + "].version=" + version);
        getLog().debug("[" + coords + "].artifactVersion=" + artifactVersion);
        getLog().debug("[" + coords + "].effectiveVersion=" + effectiveVersion);
        getLog().debug("[" + coords + "].specified=" + pluginsWithVersionsSpecified.contains(coords));
        if (version == null || !pluginsWithVersionsSpecified.contains(coords)) {
            version = (String) superPomPluginManagement.get(ArtifactUtils.versionlessKey(artifact));
            getLog().debug("[" + coords + "].superPom.version=" + version);

            newVersion = artifactVersion != null ? artifactVersion.toString()
                    : (version != null ? version : (effectiveVersion != null ? effectiveVersion : "(unknown)"));
            StringBuilder buf = new StringBuilder(compactKey(groupId, artifactId));
            buf.append(' ');
            int padding = WARN_PAD_SIZE - newVersion.length() - (version != null ? FROM_SUPER_POM.length() : 0);
            while (buf.length() < padding) {
                buf.append('.');
            }
            buf.append(' ');
            if (version != null) {
                buf.append(FROM_SUPER_POM);
                superPomDrivingMinVersion = true;
            }
            buf.append(newVersion);
            lockdowns.add(buf.toString());
        } else if (artifactVersion != null) {
            newVersion = artifactVersion.toString();
        } else {
            newVersion = null;
        }
        if (version != null && artifactVersion != null && newVersion != null && effectiveVersion != null
                && new DefaultArtifactVersion(effectiveVersion)
                        .compareTo(new DefaultArtifactVersion(newVersion)) < 0) {
            StringBuilder buf = new StringBuilder(compactKey(groupId, artifactId));
            buf.append(' ');
            int padding = INFO_PAD_SIZE - version.length() - newVersion.length() - 4;
            while (buf.length() < padding) {
                buf.append('.');
            }
            buf.append(' ');
            buf.append(effectiveVersion);
            buf.append(" -> ");
            buf.append(newVersion);
            updates.add(buf.toString());
        }
    }
    logLine(false, "");
    if (updates.isEmpty()) {
        logLine(false, "All plugins with a version specified are using the latest versions.");
    } else {
        logLine(false, "The following plugin updates are available:");
        for (String update : updates) {
            logLine(false, "  " + update);
        }
    }
    logLine(false, "");
    if (lockdowns.isEmpty()) {
        logLine(false, "All plugins have a version specified.");
    } else {
        getLog().warn("The following plugins do not have their version specified:");
        for (String lockdown : lockdowns) {
            getLog().warn("  " + lockdown);
        }
    }
    logLine(false, "");
    boolean noMavenMinVersion = getRequiredMavenVersion(getProject(), null) == null;
    boolean noExplicitMavenMinVersion = getProject().getPrerequisites() == null
            || getProject().getPrerequisites().getMaven() == null;
    if (noMavenMinVersion) {
        getLog().warn("Project does not define minimum Maven version, default is: 2.0");
    } else if (noExplicitMavenMinVersion) {
        logLine(false, "Project inherits minimum Maven version as: " + specMavenVersion);
    } else {
        ArtifactVersion explicitMavenVersion = new DefaultArtifactVersion(
                getProject().getPrerequisites().getMaven());
        if (explicitMavenVersion.compareTo(specMavenVersion) < 0) {
            logLine(true, "Project's effective minimum Maven (from parent) is: " + specMavenVersion);
            logLine(true, "Project defines minimum Maven version as: " + explicitMavenVersion);
        } else {
            logLine(false, "Project defines minimum Maven version as: " + specMavenVersion);
        }
    }
    logLine(false, "Plugins require minimum Maven version of: " + minMavenVersion);
    if (superPomDrivingMinVersion) {
        logLine(false, "Note: the super-pom from Maven " + curMavenVersion + " defines some of the plugin");
        logLine(false, "      versions and may be influencing the plugins required minimum Maven");
        logLine(false, "      version.");
    }
    logLine(false, "");
    if ("maven-plugin".equals(getProject().getPackaging())) {
        if (noMavenMinVersion) {
            getLog().warn(
                    "Project (which is a Maven Plugin) does not define required minimum version of Maven.");
            getLog().warn("Update the pom.xml to contain");
            getLog().warn("    <prerequisites>");
            getLog().warn("      <maven><!-- minimum version of Maven that the plugin works with --></maven>");
            getLog().warn("    </prerequisites>");
            getLog().warn("To build this plugin you need at least Maven " + minMavenVersion);
            getLog().warn(
                    "A Maven Enforcer rule can be used to enforce this if you have not already set one up");
        } else if (minMavenVersion != null && specMavenVersion.compareTo(minMavenVersion) < 0) {
            getLog().warn("Project (which is a Maven Plugin) targets Maven " + specMavenVersion + " or newer");
            getLog().warn("but requires Maven " + minMavenVersion + " or newer to build.");
            getLog().warn("This may or may not be a problem. A Maven Enforcer rule can help ");
            getLog().warn("enforce that the correct version of Maven is used to build this plugin.");
        } else {
            logLine(false, "No plugins require a newer version of Maven than specified by the pom.");
        }
    } else {
        if (noMavenMinVersion) {
            logLine(true, "Project does not define required minimum version of Maven.");
            logLine(true, "Update the pom.xml to contain");
            logLine(true, "    <prerequisites>");
            logLine(true, "      <maven>" + minMavenVersion + "</maven>");
            logLine(true, "    </prerequisites>");
        } else if (minMavenVersion != null && specMavenVersion.compareTo(minMavenVersion) < 0) {
            logLine(true, "Project requires an incorrect minimum version of Maven.");
            logLine(true, "Either change plugin versions to those compatible with " + specMavenVersion);
            logLine(true, "or update the pom.xml to contain");
            logLine(true, "    <prerequisites>");
            logLine(true, "      <maven>" + minMavenVersion + "</maven>");
            logLine(true, "    </prerequisites>");
        } else {
            logLine(false, "No plugins require a newer version of Maven than specified by the pom.");
        }
    }
    for (Map.Entry<ArtifactVersion, Map<String, String>> mavenUpgrade : upgrades.entrySet()) {
        ArtifactVersion mavenUpgradeVersion = (ArtifactVersion) mavenUpgrade.getKey();
        Map<String, String> upgradePlugins = mavenUpgrade.getValue();
        if (upgradePlugins.isEmpty() || specMavenVersion.compareTo(mavenUpgradeVersion) >= 0) {
            continue;
        }
        logLine(false, "");
        logLine(false, "Require Maven " + mavenUpgradeVersion + " to use the following plugin updates:");
        for (Map.Entry<String, String> entry : upgradePlugins.entrySet()) {
            StringBuilder buf = new StringBuilder("  ");
            buf.append(entry.getKey());
            buf.append(' ');
            String s = entry.getValue();
            int padding = INFO_PAD_SIZE - s.length() + 2;
            while (buf.length() < padding) {
                buf.append('.');
            }
            buf.append(' ');
            buf.append(s);
            logLine(false, buf.toString());
        }
    }
    logLine(false, "");
}

From source file:org.codehaus.mojo.versions.DisplayPluginUpdatesMojo.java

License:Apache License

/**
 * Returns a set of Strings which correspond to the plugin coordinates where there is a version
 * specified./*w  w  w . j  a  v  a2  s.com*/
 *
 * @param project The project to get the plugins with versions specified.
 * @return a set of Strings which correspond to the plugin coordinates where there is a version
 *         specified.
 */
private Set<String> findPluginsWithVersionsSpecified(MavenProject project)
        throws IOException, XMLStreamException {
    return findPluginsWithVersionsSpecified(PomHelper.readXmlFile(project.getFile()));
}