diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
index 0351215dec..4a9cbdd2ce 100644
--- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
+++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
@@ -19,6 +19,8 @@ package org.apache.maven;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenSession;
@@ -45,22 +47,25 @@ import org.apache.maven.settings.SettingsUtils;
import org.apache.maven.usability.ErrorDiagnoser;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.dag.CycleDetectedException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
/**
* @author Jason van Zyl
@@ -82,9 +87,11 @@ public class DefaultMaven
protected PlexusContainer container;
protected Map errorDiagnosers;
-
+
protected MavenProfilesBuilder profilesBuilder;
-
+
+ private ArtifactVersion mavenVersion;
+
// ----------------------------------------------------------------------
// Project execution
// ----------------------------------------------------------------------
@@ -92,6 +99,15 @@ public class DefaultMaven
public MavenExecutionResponse execute( MavenExecutionRequest request )
throws ReactorException
{
+ try
+ {
+ mavenVersion = getMavenVersion();
+ }
+ catch ( IOException e )
+ {
+ throw new ReactorException( "Unable to determine the executing version of Maven", e );
+ }
+
if ( request.getSettings().isOffline() )
{
getLogger().info( "Maven is running in offline mode." );
@@ -119,15 +135,17 @@ public class DefaultMaven
try
{
- projects = collectProjects( request.getFiles(), request.getLocalRepository(), request.isRecursive(), request.getSettings() );
+ projects = collectProjects( request.getFiles(), request.getLocalRepository(), request.isRecursive(),
+ request.getSettings() );
projects = ProjectSorter.getSortedProjects( projects );
if ( projects.isEmpty() )
{
List externalProfiles = getActiveExternalProfiles( null, request.getSettings() );
-
- projects.add( projectBuilder.buildStandaloneSuperProject( request.getLocalRepository(), externalProfiles ) );
+
+ projects.add(
+ projectBuilder.buildStandaloneSuperProject( request.getLocalRepository(), externalProfiles ) );
}
}
catch ( IOException e )
@@ -204,6 +222,25 @@ public class DefaultMaven
}
}
+ private DefaultArtifactVersion getMavenVersion()
+ throws IOException
+ {
+ InputStream resourceAsStream = null;
+ try
+ {
+ Properties properties = new Properties();
+ resourceAsStream = getClass().getClassLoader().getResourceAsStream(
+ "META-INF/maven/org.apache.maven/maven-core/pom.properties" );
+ properties.load( resourceAsStream );
+
+ return new DefaultArtifactVersion( properties.getProperty( "version" ) );
+ }
+ finally
+ {
+ IOUtil.close( resourceAsStream );
+ }
+ }
+
private List collectProjects( List files, ArtifactRepository localRepository, boolean recursive, Settings settings )
throws ProjectBuildingException, ReactorException, IOException, ArtifactResolutionException
{
@@ -215,6 +252,16 @@ public class DefaultMaven
MavenProject project = getProject( file, localRepository, settings );
+ if ( project.getPrerequesites() != null && project.getPrerequesites().getMaven() != null )
+ {
+ DefaultArtifactVersion version = new DefaultArtifactVersion( project.getPrerequesites().getMaven() );
+ if ( mavenVersion.compareTo( version ) < 0 )
+ {
+ throw new ProjectBuildingException( "Unable to build project '" + project.getFile() +
+ "; it requires Maven version " + version.toString() );
+ }
+ }
+
if ( project.getModules() != null && !project.getModules().isEmpty() && recursive )
{
// TODO: Really should fail if it was not? What if it is aggregating - eg "ear"?
@@ -315,55 +362,55 @@ public class DefaultMaven
{
if ( pom.length() == 0 )
{
- throw new ProjectBuildingException( "The file " + pom.getAbsolutePath() + " you specified has zero length." );
+ throw new ProjectBuildingException(
+ "The file " + pom.getAbsolutePath() + " you specified has zero length." );
}
}
List externalProfiles = getActiveExternalProfiles( pom, settings );
-
- MavenProject project = projectBuilder.build( pom, localRepository, externalProfiles );
-
- return project;
+
+ return projectBuilder.build( pom, localRepository, externalProfiles );
}
- private List getActiveExternalProfiles( File pom, Settings settings ) throws ProjectBuildingException
+ private List getActiveExternalProfiles( File pom, Settings settings )
+ throws ProjectBuildingException
{
// TODO: apply profiles.xml and settings.xml Profiles here.
List externalProfiles = new ArrayList();
-
+
List settingsProfiles = settings.getProfiles();
-
- if(settingsProfiles != null && !settingsProfiles.isEmpty())
+
+ if ( settingsProfiles != null && !settingsProfiles.isEmpty() )
{
List settingsActiveProfileIds = settings.getActiveProfiles();
-
+
for ( Iterator it = settings.getProfiles().iterator(); it.hasNext(); )
{
org.apache.maven.settings.Profile rawProfile = (org.apache.maven.settings.Profile) it.next();
-
+
Profile profile = SettingsUtils.convertFromSettingsProfile( rawProfile );
-
- if( settingsActiveProfileIds.contains( rawProfile.getId() ) )
+
+ if ( settingsActiveProfileIds.contains( rawProfile.getId() ) )
{
profile.setActivation( new AlwaysOnActivation() );
}
-
+
externalProfiles.add( profile );
}
}
-
- if( pom != null )
+
+ if ( pom != null )
{
try
{
ProfilesRoot root = profilesBuilder.buildProfiles( pom.getParentFile() );
-
- if( root != null )
+
+ if ( root != null )
{
for ( Iterator it = root.getProfiles().iterator(); it.hasNext(); )
{
org.apache.maven.profiles.Profile rawProfile = (org.apache.maven.profiles.Profile) it.next();
-
+
externalProfiles.add( ProfilesConversionUtils.convertFromProfileXmlProfile( rawProfile ) );
}
}
@@ -377,7 +424,7 @@ public class DefaultMaven
throw new ProjectBuildingException( "Cannot parse profiles.xml resource for pom: " + pom, e );
}
}
-
+
return externalProfiles;
}
@@ -459,7 +506,7 @@ public class DefaultMaven
getLogger().error( "BUILD ERROR" );
line();
-
+
Throwable error = r.getException();
String message = null;
@@ -482,9 +529,9 @@ public class DefaultMaven
}
getLogger().info( "Diagnosis: " + message );
-
+
line();
-
+
getLogger().error( "Cause: ", r.getException() );
line();
@@ -572,8 +619,8 @@ public class DefaultMaven
Runtime r = Runtime.getRuntime();
- getLogger().info( "Final Memory: " + ( ( r.totalMemory() - r.freeMemory() ) / mb ) + "M/" +
- ( r.totalMemory() / mb ) + "M" );
+ getLogger().info(
+ "Final Memory: " + ( ( r.totalMemory() - r.freeMemory() ) / mb ) + "M/" + ( r.totalMemory() / mb ) + "M" );
}
protected void line()
diff --git a/maven-model/maven.mdo b/maven-model/maven.mdo
index 618dd40f27..2a4604e6f0 100644
--- a/maven-model/maven.mdo
+++ b/maven-model/maven.mdo
@@ -211,6 +211,16 @@
]]>
String
+
+ prerequesites
+ 4.0.0
+
+ Describes the prerequesites in the build environment for this project.
+
+
+ Prerequesites
+
+
issueTrackingUrl
3.0.0
@@ -427,7 +437,8 @@
Repository
- This element needs to be renamed as it conflicts with the existing notion of repositories in Maven.
+ This element needs to be renamed as it conflicts with the existing notion of repositories in
+ Maven.
organization
@@ -561,7 +572,8 @@
Repository
*
- This may be removed or relocated in the near future. It is undecided whether plugins really need a remote repository set of their own.
+ This may be removed or relocated in the near future. It is undecided whether plugins really need a
+ remote repository set of their own.
dependencies
@@ -622,7 +634,8 @@
Dependency
*
- These should ultimately only be compile time dependencies when transitive dependencies come into play.
+ These should ultimately only be compile time dependencies when transitive dependencies come into
+ play.
reports
@@ -1040,7 +1053,7 @@
Contributor
Description of a person who has contributed to the project, but who does
- not have commit privileges. Usually, these contributions come in the
+ not have commit privileges. Usually, these contributions come in the
form of patches submitted.
3.0.0+
@@ -1995,14 +2008,16 @@
layout
4.0.0
- The type of layout this repository uses for locating and storing artifacts - can be "legacy" or "default".
+ The type of layout this repository uses for locating and storing artifacts - can be "legacy" or
+ "default".
String
default
checksumPolicy
4.0.0
- What to do when verification of an artifact checksum fails - warn, fail, etc. Valid values are "fail" or "warn"
+ What to do when verification of an artifact checksum fails - warn, fail, etc. Valid values are
+ "fail" or "warn"
String
warn
@@ -2071,7 +2086,8 @@
inherited
4.0.0
-
+
+
String
@@ -2125,7 +2141,8 @@
executions
4.0.0
- Multiple specifications of a set of goals, each having (possibly) different configuration
+ Multiple specifications of a set of goals, each having (possibly) different
+ configuration
PluginExecution
*
@@ -2356,7 +2373,7 @@
true
4.0.0
String
- The ID of this build profile, for activation
+ The ID of this build profile, for activation
purposes.
@@ -2504,7 +2521,8 @@
reportSets
4.0.0
- Multiple specifications of a set of reports, each having (possibly) different configuration
+ Multiple specifications of a set of reports, each having (possibly) different
+ configuration
ReportSet
*
@@ -2619,6 +2637,21 @@
+
+ Prerequesites
+ 4.0.0
+ Describes the prerequesites a project can have
+
+
+ maven
+ 4.0.0
+ String
+ 2.0-beta-1-SNAPSHOT
+ The minimum version of Maven required
+ false
+
+
+
diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
index 849e7ce587..0512d64ef2 100644
--- a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
+++ b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
@@ -36,6 +36,7 @@ import org.apache.maven.model.Organization;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.PluginManagement;
+import org.apache.maven.model.Prerequesites;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.ReportSet;
import org.apache.maven.model.Reporting;
@@ -104,7 +105,7 @@ public class MavenProject
private List activeProfiles = new ArrayList();
private Set dependencyArtifacts;
-
+
private Artifact artifact;
// calculated.
@@ -150,12 +151,12 @@ public class MavenProject
// ----------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------
-
+
public Artifact getArtifact()
{
return artifact;
}
-
+
public void setArtifact( Artifact artifact )
{
this.artifact = artifact;
@@ -385,8 +386,8 @@ public class MavenProject
if ( isAddedToClasspath( a ) )
{
// TODO: let the scope handler deal with this
- if ( Artifact.SCOPE_TEST.equals( a.getScope() ) || Artifact.SCOPE_COMPILE.equals( a.getScope() )
- || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
+ if ( Artifact.SCOPE_TEST.equals( a.getScope() ) || Artifact.SCOPE_COMPILE.equals( a.getScope() ) ||
+ Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
{
File file = a.getFile();
if ( file == null )
@@ -411,8 +412,8 @@ public class MavenProject
if ( isAddedToClasspath( a ) )
{
// TODO: let the scope handler deal with this
- if ( Artifact.SCOPE_TEST.equals( a.getScope() ) || Artifact.SCOPE_COMPILE.equals( a.getScope() )
- || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
+ if ( Artifact.SCOPE_TEST.equals( a.getScope() ) || Artifact.SCOPE_COMPILE.equals( a.getScope() ) ||
+ Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
{
list.add( a );
}
@@ -437,8 +438,8 @@ public class MavenProject
Artifact a = (Artifact) i.next();
// TODO: let the scope handler deal with this
- if ( Artifact.SCOPE_TEST.equals( a.getScope() ) || Artifact.SCOPE_COMPILE.equals( a.getScope() )
- || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
+ if ( Artifact.SCOPE_TEST.equals( a.getScope() ) || Artifact.SCOPE_COMPILE.equals( a.getScope() ) ||
+ Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
{
Dependency dependency = new Dependency();
@@ -644,6 +645,11 @@ public class MavenProject
return model.getUrl();
}
+ public Prerequesites getPrerequesites()
+ {
+ return model.getPrerequesites();
+ }
+
public void setIssueManagement( IssueManagement issueManagement )
{
model.setIssueManagement( issueManagement );
@@ -787,7 +793,7 @@ public class MavenProject
public void setArtifacts( Set artifacts )
{
this.artifacts = artifacts;
-
+
// flush the calculated artifactMap
artifactMap = null;
}
@@ -803,7 +809,7 @@ public class MavenProject
{
artifactMap = ArtifactUtils.artifactMap( getArtifacts() );
}
-
+
return artifactMap;
}
@@ -960,7 +966,7 @@ public class MavenProject
}
public Xpp3Dom getGoalConfiguration( String pluginGroupId, String pluginArtifactId, String executionId,
- String goalId )
+ String goalId )
{
Xpp3Dom dom = null;