List of usage examples for org.apache.maven.project MavenProject getModel
public Model getModel()
From source file:org.apache.hyracks.maven.license.LicenseMojo.java
License:Apache License
protected MavenProject resolveDependency(Artifact depObj) throws ProjectBuildingException { String key = depObj.getGroupId() + ":" + depObj.getArtifactId() + ":" + depObj.getVersion(); MavenProject depProj = projectCache.get(key); if (depProj == null) { try {//from w w w.j av a 2 s. c o m depProj = projectBuilder.buildFromRepository(depObj, remoteRepositories, localRepository, false); } catch (ProjectBuildingException e) { throw new ProjectBuildingException(key, "Error creating dependent artifacts", e); } Model supplement = supplementModels.get( SupplementalModelHelper.generateSupplementMapKey(depObj.getGroupId(), depObj.getArtifactId())); if (supplement != null) { Model merged = SupplementalModelHelper.mergeModels(assembler, depProj.getModel(), supplement); Set<String> origLicenses = depProj.getModel().getLicenses().stream().map(License::getUrl) .collect(Collectors.toSet()); Set<String> newLicenses = merged.getLicenses().stream().map(License::getUrl) .collect(Collectors.toSet()); if (!origLicenses.equals(newLicenses)) { getLog().warn("license list for " + toGav(depProj) + " changed with supplemental model; was: " + origLicenses + ", now: " + newLicenses); } depProj = new MavenProject(merged); depProj.setArtifact(depObj); depProj.setVersion(depObj.getVersion()); } depProj.getArtifact().setScope(depObj.getScope()); projectCache.put(key, depProj); } return depProj; }
From source file:org.axway.grapes.maven.report.ModuleBuilder.java
/** * Turn a maven project (Maven data model) into a module (Grapes data model) * * @param project MavenProject/*from w ww .j av a2 s . c om*/ * @return Module */ public Module getModule(final MavenProject project, final LicenseResolver licenseResolver, final ArtifactResolver artifactResolver) throws MojoExecutionException { final Module module = GrapesTranslator.getGrapesModule(project); final List<License> licenses = licenseResolver.resolve(project); /* Manage Artifacts */ final Artifact mainArtifact = GrapesTranslator.getGrapesArtifact(project.getArtifact()); addLicenses(mainArtifact, licenses); module.addArtifact(mainArtifact); // Get pom file if main artifact is not already a pom file if (!mainArtifact.getType().equals("pom")) { final Artifact pomArtifact = GrapesTranslator.getGrapesArtifact(project.getModel()); addLicenses(pomArtifact, licenses); module.addArtifact(pomArtifact); } for (int i = 0; i < project.getAttachedArtifacts().size(); i++) { artifactResolver.resolveArtifact(project, project.getAttachedArtifacts().get(i)); final Artifact attachedArtifact = GrapesTranslator .getGrapesArtifact(project.getAttachedArtifacts().get(i)); // handle licenses addLicenses(attachedArtifact, licenses); module.addArtifact(attachedArtifact); } /* Manage Dependencies */ for (int i = 0; i < project.getDependencies().size(); i++) { final Dependency dependency = GrapesTranslator.getGrapesDependency( artifactResolver.resolveArtifact(project, project.getDependencies().get(i)), project.getDependencies().get(i).getScope()); // handle licenses for (License license : licenseResolver.resolve(project, dependency.getTarget().getGroupId(), dependency.getTarget().getArtifactId(), dependency.getTarget().getVersion())) { dependency.getTarget().addLicense(license.getName()); } module.addDependency(dependency); } return module; }
From source file:org.codehaus.cargo.maven2.DependencyCalculator.java
License:Apache License
/** * Fixup the project artifact./*from w ww . j a va 2 s .co m*/ * @throws Exception If anything goes wrong. */ protected void fixupProjectArtifact() throws Exception { MavenProject mp2 = new MavenProject(mavenProject); // For each of our dependencies.. for (Object artifact : mp2.createArtifacts(artifactFactory, null, null)) { Artifact art = (Artifact) artifact; if (art.getType().equals("war")) { // Sigh... Artifact art2 = artifactFactory.createArtifactWithClassifier(art.getGroupId(), art.getArtifactId(), art.getVersion(), "pom", null); fixupRepositoryArtifact(art2); } } // If we mess with this model, it's the 'REAL' model. So lets copy it Model pomFile = mp2.getModel(); File outFile = File.createTempFile("pom", ".xml"); MavenXpp3Writer pomWriter = new MavenXpp3Writer(); pomWriter.write(new FileWriter(outFile), pomFile); MavenXpp3Reader pomReader = new MavenXpp3Reader(); pomFile = pomReader.read(new FileReader(outFile)); Artifact art = mp2.getArtifact(); fixModelAndSaveInRepository(art, pomFile); outFile.delete(); }
From source file:org.codehaus.griffon.maven.plugin.tools.DefaultGriffonServices.java
License:Apache License
public MavenProject createPOM(String groupId, GriffonProject griffonProjectDescriptor, String mtgGroupId, String griffonPluginArtifactId, String mtgVersion, boolean addEclipseSettings) { MavenProject pom = new MavenProject(); if (pom.getBuild().getPluginManagement() == null) { pom.getBuild().setPluginManagement(new PluginManagement()); }//from ww w. j a v a 2s.c o m PluginManagement pluginMgt = pom.getPluginManagement(); // Those four properties are needed. pom.setModelVersion("4.0.0"); pom.setPackaging("griffon-app"); // Specific for GRAILS pom.getModel().getProperties().setProperty("griffonHome", "${env.GRIFFON_HOME}"); pom.getModel().getProperties().setProperty("griffonVersion", griffonProjectDescriptor.getAppGriffonVersion()); // Add our own plugin Plugin griffonPlugin = new Plugin(); griffonPlugin.setGroupId(mtgGroupId); griffonPlugin.setArtifactId(griffonPluginArtifactId); griffonPlugin.setVersion(mtgVersion); griffonPlugin.setExtensions(true); pom.addPlugin(griffonPlugin); // Add compiler plugin settings Plugin compilerPlugin = new Plugin(); compilerPlugin.setGroupId("org.apache.maven.plugins"); compilerPlugin.setArtifactId("maven-compiler-plugin"); Xpp3Dom compilerConfig = new Xpp3Dom("configuration"); Xpp3Dom source = new Xpp3Dom("source"); source.setValue("1.5"); compilerConfig.addChild(source); Xpp3Dom target = new Xpp3Dom("target"); target.setValue("1.5"); compilerConfig.addChild(target); compilerPlugin.setConfiguration(compilerConfig); pom.addPlugin(compilerPlugin); // Add eclipse plugin settings if (addEclipseSettings) { Plugin eclipsePlugin = new Plugin(); eclipsePlugin.setGroupId("org.apache.maven.plugins"); eclipsePlugin.setArtifactId("maven-eclipse-plugin"); Xpp3Dom configuration = new Xpp3Dom("configuration"); Xpp3Dom projectnatures = new Xpp3Dom("additionalProjectnatures"); Xpp3Dom projectnature = new Xpp3Dom("projectnature"); projectnature.setValue("org.codehaus.groovy.eclipse.groovyNature"); projectnatures.addChild(projectnature); configuration.addChild(projectnatures); Xpp3Dom additionalBuildcommands = new Xpp3Dom("additionalBuildcommands"); Xpp3Dom buildcommand = new Xpp3Dom("buildcommand"); buildcommand.setValue("org.codehaus.groovy.eclipse.groovyBuilder"); additionalBuildcommands.addChild(buildcommand); configuration.addChild(additionalBuildcommands); Xpp3Dom packaging = new Xpp3Dom("packaging"); packaging.setValue("zip"); configuration.addChild(packaging); eclipsePlugin.setConfiguration(configuration); pluginMgt.addPlugin(eclipsePlugin); } // Change the default output directory to generate classes pom.getModel().getBuild().setOutputDirectory("web-app/WEB-INF/classes"); pom.setArtifactId(griffonProjectDescriptor.getAppName()); pom.setName(griffonProjectDescriptor.getAppName()); pom.setGroupId(groupId); pom.setVersion(griffonProjectDescriptor.getAppVersion()); if (!griffonProjectDescriptor.getAppVersion().endsWith("SNAPSHOT")) { getLogger().warn("====================================================================="); getLogger().warn("If your project is currently in development, in accordance with maven "); getLogger().warn("standards, its version must be " + griffonProjectDescriptor.getAppVersion() + "-SNAPSHOT and not " + griffonProjectDescriptor.getAppVersion() + "."); getLogger().warn("Please, change your version in the application.properties descriptor"); getLogger().warn("and regenerate your pom."); getLogger().warn("====================================================================="); } return pom; }
From source file:org.codehaus.mojo.config.ConfigLifecycleParticipant.java
License:Open Source License
@Override public void afterProjectsRead(final MavenSession session) throws MavenExecutionException { try {//from w w w. j a v a 2s . c o m final int totalModules = session.getProjects().size(); logger.info("Introspecting model with total of " + totalModules + " modules..."); for (MavenProject project : session.getProjects()) { Build build = project.getModel().getBuild(); final Map<String, Xpp3Dom> projectConfigurations = getProjectConfigurations(project); if (!projectConfigurations.isEmpty()) { logger.debug("{}", projectConfigurations); processPlugins(project, projectConfigurations, build.getPluginManagement()); processPlugins(project, projectConfigurations, build); } } } catch (IllegalArgumentException e) { throw new MavenExecutionException(groupId + ":" + artifactId + " error:\n " + e.getMessage(), e); } }
From source file:org.codehaus.mojo.config.ConfigLifecycleParticipant.java
License:Open Source License
/** * Returns the available configuration templates for given project. *//* ww w . j a va 2s . com*/ private Map<String, Xpp3Dom> getProjectConfigurations(final MavenProject mavenProject) { final Map<String, Xpp3Dom> result = new HashMap<>(); final Plugin configurationMavenPlugin = mavenProject.getModel().getBuild() != null ? getConfigurationMavenPluginFromContainer(mavenProject.getModel().getBuild()) : null; if (configurationMavenPlugin != null) { Xpp3Dom configuration = (Xpp3Dom) configurationMavenPlugin.getConfiguration(); for (Xpp3Dom child : configuration.getChildren()) { if (TEMPLATE_TAG.equals(child.getName())) { String name = child.getAttribute(NAME_ATTRIBUTE); if (!Strings.isNullOrEmpty(name)) { result.put(name, child); } } } } return result; }
From source file:org.codehaus.mojo.dashboard.report.plugin.DashBoardUtils.java
License:Apache License
/** * Return the optionName value defined in a project for a given artifactId plugin. * //from w w w . j a v a 2 s. c om * @param project * not null * @param pluginArtifact * not null * @param optionName * an Xpath expression from the plugin <code><configuration/></code> * @param defaultValue * @return the value for the option name (comma separated value in the case of list) or null if not found * @throws IOException * if any */ private static String getMavenPluginConfiguration(MavenProject project, String pluginArtifact, String pluginGroupId, String optionName, String defaultValue) throws IOException { for (Iterator it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext();) { Plugin plugin = (Plugin) it.next(); if ((plugin.getGroupId().equals(pluginGroupId)) && (plugin.getArtifactId().equals(pluginArtifact))) { Xpp3Dom pluginConf = (Xpp3Dom) plugin.getConfiguration(); if (pluginConf != null) { StringBuffer sb = new StringBuffer(); try { Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new StringInputStream(pluginConf.toString())); XObject obj = XPathAPI.eval(doc, "//configuration//" + optionName); if (StringUtils.isNotEmpty(obj.toString())) { StringTokenizer token = new StringTokenizer(obj.toString(), "\n "); while (token.hasMoreTokens()) { sb.append(token.nextToken().trim()); if (token.hasMoreElements()) { sb.append(","); } } return sb.toString(); } } catch (Exception e) { throw new IOException("Exception occured" + e.getMessage()); } } } } return defaultValue; }
From source file:org.codehaus.mojo.dashboard.report.plugin.utils.MavenUtils.java
License:Apache License
/** * Return the optionName value defined in a project for a given artifactId plugin. * //from w ww . j a v a2 s .c o m * @param project * not null * @param pluginArtifact * not null * @param optionName * an Xpath expression from the plugin <code><configuration/></code> * @param defaultValue * @return the value for the option name (comma separated value in the case of list) or null if not found * @throws IOException * if any */ private String getMavenPluginConfiguration(MavenProject project, String pluginArtifact, String pluginGroupId, String optionName, String defaultValue) throws IOException { for (Iterator it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext();) { Plugin plugin = (Plugin) it.next(); if ((plugin.getGroupId().equals(pluginGroupId)) && (plugin.getArtifactId().equals(pluginArtifact))) { Xpp3Dom pluginConf = (Xpp3Dom) plugin.getConfiguration(); if (pluginConf != null) { StringBuffer sb = new StringBuffer(); try { Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new StringInputStream(pluginConf.toString())); XObject obj = XPathAPI.eval(doc, "//configuration//" + optionName); if (StringUtils.isNotEmpty(obj.toString())) { StringTokenizer token = new StringTokenizer(obj.toString(), "\n "); while (token.hasMoreTokens()) { sb.append(token.nextToken().trim()); if (token.hasMoreElements()) { sb.append(","); } } return sb.toString(); } } catch (Exception e) { throw new IOException("Exception occured" + e.getMessage()); } } } } return defaultValue; }
From source file:org.codehaus.mojo.sysdeo.ide.IdeUtils.java
License:Apache License
/** * @todo there should be a better way to do this *///w ww .ja v a 2s .c o m public static String getPluginSetting(MavenProject project, String artifactId, String optionName, String defaultValue) { for (Iterator it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext();) { Plugin plugin = (Plugin) it.next(); if (plugin.getArtifactId().equals(artifactId)) { Xpp3Dom o = (Xpp3Dom) plugin.getConfiguration(); if (o != null && o.getChild(optionName) != null) { return o.getChild(optionName).getValue(); } } } return defaultValue; }
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/*from w w w .ja va 2 s .c om*/ */ 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, ""); }