PR: MNG-404

add ability to have a minimum Maven version for a project build

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@219473 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-07-18 11:57:29 +00:00
parent e53ecf1af2
commit 4c45989dcb
3 changed files with 139 additions and 53 deletions

View File

@ -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 <a href="mailto:jason@maven.org">Jason van Zyl </a>
@ -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()

View File

@ -211,6 +211,16 @@
]]></description>
<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>
@ -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>
@ -2619,6 +2637,21 @@
</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>

View File

@ -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;