Author: brett
Date: Mon Jul 18 04:57:29 2005
New Revision: 219473
URL: http://svn.apache.org/viewcvs?rev=219473&view=rev
Log:
PR: MNG-404
add ability to have a minimum Maven version for a project build
Modified:
maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
maven/components/trunk/maven-model/maven.mdo
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
Modified:
maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java?rev=219473&r1=219472&r2=219473&view=diff
==============================================================================
---
maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
(original)
+++
maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
Mon Jul 18 04:57:29 2005
@@ -19,6 +19,8 @@
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.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 <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl </a>
@@ -82,9 +87,11 @@
protected PlexusContainer container;
protected Map errorDiagnosers;
-
+
protected MavenProfilesBuilder profilesBuilder;
-
+
+ private ArtifactVersion mavenVersion;
+
// ----------------------------------------------------------------------
// Project execution
// ----------------------------------------------------------------------
@@ -92,6 +99,15 @@
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 @@
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 @@
}
}
+ 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 @@
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 @@
{
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 @@
throw new ProjectBuildingException( "Cannot parse profiles.xml
resource for pom: " + pom, e );
}
}
-
+
return externalProfiles;
}
@@ -459,7 +506,7 @@
getLogger().error( "BUILD ERROR" );
line();
-
+
Throwable error = r.getException();
String message = null;
@@ -482,9 +529,9 @@
}
getLogger().info( "Diagnosis: " + message );
-
+
line();
-
+
getLogger().error( "Cause: ", r.getException() );
line();
@@ -572,8 +619,8 @@
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()
Modified: maven/components/trunk/maven-model/maven.mdo
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-model/maven.mdo?rev=219473&r1=219472&r2=219473&view=diff
==============================================================================
--- maven/components/trunk/maven-model/maven.mdo (original)
+++ maven/components/trunk/maven-model/maven.mdo Mon Jul 18 04:57:29 2005
@@ -212,6 +212,16 @@
<type>String</type>
</field>
<field>
+ <name>prerequesites</name>
+ <version>4.0.0</version>
+ <description>
+ Describes the prerequesites in the build environment for this
project.
+ </description>
+ <association>
+ <type>Prerequesites</type>
+ </association>
+ </field>
+ <field>
<name>issueTrackingUrl</name>
<version>3.0.0</version>
<description><![CDATA[
@@ -427,7 +437,8 @@
<association>
<type>Repository</type>
</association>
- <comment>This element needs to be renamed as it conflicts with the
existing notion of repositories in Maven.</comment>
+ <comment>This element needs to be renamed as it conflicts with the
existing notion of repositories in
+ Maven.</comment>
</field>
<field>
<name>organization</name>
@@ -561,7 +572,8 @@
<type>Repository</type>
<multiplicity>*</multiplicity>
</association>
- <comment>This may be removed or relocated in the near future. It is
undecided whether plugins really need a remote repository set of their
own.</comment>
+ <comment>This may be removed or relocated in the near future. It is
undecided whether plugins really need a
+ remote repository set of their own.</comment>
</field>
<field>
<name>dependencies</name>
@@ -622,7 +634,8 @@
<type>Dependency</type>
<multiplicity>*</multiplicity>
</association>
- <comment>These should ultimately only be compile time dependencies
when transitive dependencies come into play.</comment>
+ <comment>These should ultimately only be compile time dependencies
when transitive dependencies come into
+ play.</comment>
</field>
<field>
<name>reports</name>
@@ -1040,7 +1053,7 @@
<name>Contributor</name>
<description>
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.
</description>
<version>3.0.0+</version>
@@ -1995,14 +2008,16 @@
<field>
<name>layout</name>
<version>4.0.0</version>
- <description>The type of layout this repository uses for locating
and storing artifacts - can be "legacy" or "default".</description>
+ <description>The type of layout this repository uses for locating
and storing artifacts - can be "legacy" or
+ "default".</description>
<type>String</type>
<defaultValue>default</defaultValue>
</field>
<field>
<name>checksumPolicy</name>
<version>4.0.0</version>
- <description>What to do when verification of an artifact checksum
fails - warn, fail, etc. Valid values are "fail" or "warn"</description>
+ <description>What to do when verification of an artifact checksum
fails - warn, fail, etc. Valid values are
+ "fail" or "warn"</description>
<type>String</type>
<defaultValue>warn</defaultValue>
</field>
@@ -2071,7 +2086,8 @@
<field>
<name>inherited</name>
<version>4.0.0</version>
- <description><![CDATA[Whether this container's configuration should
be propagated to child POMs.]]></description>
+ <description>
+ <![CDATA[Whether this container's configuration should be
propagated to child POMs.]]></description>
<type>String</type>
</field>
<field>
@@ -2125,7 +2141,8 @@
<field>
<name>executions</name>
<version>4.0.0</version>
- <description>Multiple specifications of a set of goals, each having
(possibly) different configuration</description>
+ <description>Multiple specifications of a set of goals, each having
(possibly) different
+ configuration</description>
<association>
<type>PluginExecution</type>
<multiplicity>*</multiplicity>
@@ -2356,7 +2373,7 @@
<required>true</required>
<version>4.0.0</version>
<type>String</type>
- <description>The ID of this build profile, for activation
+ <description>The ID of this build profile, for activation
purposes.</description>
</field>
<field>
@@ -2504,7 +2521,8 @@
<field>
<name>reportSets</name>
<version>4.0.0</version>
- <description>Multiple specifications of a set of reports, each
having (possibly) different configuration</description>
+ <description>Multiple specifications of a set of reports, each
having (possibly) different
+ configuration</description>
<association>
<type>ReportSet</type>
<multiplicity>*</multiplicity>
@@ -2618,6 +2636,21 @@
]]></code>
</codeSegment>
</codeSegments>
+ </class>
+ <class>
+ <name>Prerequesites</name>
+ <version>4.0.0</version>
+ <description>Describes the prerequesites a project can have</description>
+ <fields>
+ <field>
+ <name>maven</name>
+ <version>4.0.0</version>
+ <type>String</type>
+ <defaultValue>2.0-beta-1-SNAPSHOT</defaultValue>
+ <description>The minimum version of Maven required</description>
+ <required>false</required>
+ </field>
+ </fields>
</class>
</classes>
</model>
Modified:
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java?rev=219473&r1=219472&r2=219473&view=diff
==============================================================================
---
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
(original)
+++
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
Mon Jul 18 04:57:29 2005
@@ -36,6 +36,7 @@
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 @@
private List activeProfiles = new ArrayList();
private Set dependencyArtifacts;
-
+
private Artifact artifact;
// calculated.
@@ -150,12 +151,12 @@
// ----------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------
-
+
public Artifact getArtifact()
{
return artifact;
}
-
+
public void setArtifact( Artifact artifact )
{
this.artifact = artifact;
@@ -385,8 +386,8 @@
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 @@
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 @@
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 @@
return model.getUrl();
}
+ public Prerequesites getPrerequesites()
+ {
+ return model.getPrerequesites();
+ }
+
public void setIssueManagement( IssueManagement issueManagement )
{
model.setIssueManagement( issueManagement );
@@ -787,7 +793,7 @@
public void setArtifacts( Set artifacts )
{
this.artifacts = artifacts;
-
+
// flush the calculated artifactMap
artifactMap = null;
}
@@ -803,7 +809,7 @@
{
artifactMap = ArtifactUtils.artifactMap( getArtifacts() );
}
-
+
return artifactMap;
}
@@ -960,7 +966,7 @@
}
public Xpp3Dom getGoalConfiguration( String pluginGroupId, String
pluginArtifactId, String executionId,
- String goalId )
+ String goalId )
{
Xpp3Dom dom = null;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]