o integrate changes made in maven-artifact for non fail-fast and request/result usage in the embedder for

use in IDE integration to provide as much feedback as possible.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@571862 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-09-01 19:23:17 +00:00
parent 7097dc041a
commit 884f70085e
16 changed files with 393 additions and 341 deletions

View File

@ -15,9 +15,9 @@
# specific language governing permissions and limitations
# under the License.
classworlds.version=1.2-alpha-9
classworlds.version=1.2-alpha-10
plexus-active-collections.version=1.0-beta-1
plexus.version=1.0-alpha-30
plexus.version=1.0-alpha-32
plexus-utils.version=1.4.5
maven-artifact.version=3.0-SNAPSHOT
commons-cli.version=1.0

View File

@ -109,6 +109,10 @@ public class DefaultMaven
// Project execution
// ----------------------------------------------------------------------
// project build
// artifact resolution
// lifecycle execution
public MavenExecutionResult execute( MavenExecutionRequest request )
{
request.setStartTime( new Date() );
@ -121,9 +125,88 @@ public class DefaultMaven
dispatcher.dispatchStart( event, request.getBaseDirectory() );
MavenExecutionResult result;
MavenExecutionResult result = new DefaultMavenExecutionResult();
result = doExecute( request, dispatcher );
// old doExecute
ProfileManager globalProfileManager = new DefaultProfileManager( container, request.getProperties() );
globalProfileManager.loadSettingsProfiles( request.getSettings() );
globalProfileManager.explicitlyActivate( request.getActiveProfiles() );
globalProfileManager.explicitlyDeactivate( request.getInactiveProfiles() );
getLogger().info( "Scanning for projects..." );
boolean foundProjects = true;
List projects;
try
{
projects = getProjects( request, globalProfileManager );
if ( projects.isEmpty() )
{
projects.add( getSuperProject( request ) );
foundProjects = false;
}
}
catch ( Exception e )
{
result.addException( e );
return result;
}
ReactorManager reactorManager;
try
{
reactorManager = new ReactorManager( projects, request.getReactorFailureBehavior() );
}
catch ( CycleDetectedException e )
{
result.addException( new BuildFailureException(
"The projects in the reactor contain a cyclic reference: " + e.getMessage(), e ) );
return result;
}
catch ( DuplicateProjectException e )
{
result.addException( new BuildFailureException( e.getMessage(), e ) );
return result;
}
if ( reactorManager.hasMultipleProjects() )
{
getLogger().info( "Reactor build order: " );
for ( Iterator i = reactorManager.getSortedProjects().iterator(); i.hasNext(); )
{
MavenProject project = (MavenProject) i.next();
getLogger().info( " " + project.getName() );
}
}
MavenSession session = createSession( request, reactorManager, dispatcher );
session.setUsingPOMsFromFilesystem( foundProjects );
try
{
lifecycleExecutor.execute( session, reactorManager, dispatcher );
}
catch ( Exception e )
{
result.addException( new BuildFailureException( e.getMessage(), e ) );
}
// old doExecute
if ( result.hasExceptions() )
{
@ -143,8 +226,6 @@ public class DefaultMaven
// Either the build was successful, or it was a fail_at_end/fail_never reactor build
ReactorManager reactorManager = result.getReactorManager();
// TODO: should all the logging be left to the CLI?
logReactorSummary( reactorManager );
@ -164,8 +245,9 @@ public class DefaultMaven
line();
return new DefaultMavenExecutionResult(
Collections.singletonList( new MavenExecutionException( "Some builds failed" ) ) );
result.addException( new MavenExecutionException( "Some builds failed" ) );
return result;
}
else
{
@ -181,7 +263,11 @@ public class DefaultMaven
dispatcher.dispatchEnd( event, request.getBaseDirectory() );
return new DefaultMavenExecutionResult( result.getReactorManager() );
result.setTopologicallySortedProjects( reactorManager.getSortedProjects() );
result.setProject( reactorManager.getTopLevelProject() );
return result;
}
/**
@ -228,90 +314,6 @@ public class DefaultMaven
}
}
private MavenExecutionResult doExecute( MavenExecutionRequest request, EventDispatcher dispatcher )
{
List executionExceptions = new ArrayList();
ProfileManager globalProfileManager = new DefaultProfileManager( container, request.getProperties() );
globalProfileManager.loadSettingsProfiles( request.getSettings() );
globalProfileManager.explicitlyActivate( request.getActiveProfiles() );
globalProfileManager.explicitlyDeactivate( request.getInactiveProfiles() );
getLogger().info( "Scanning for projects..." );
boolean foundProjects = true;
List projects;
try
{
projects = getProjects( request, globalProfileManager );
if ( projects.isEmpty() )
{
projects.add( getSuperProject( request ) );
foundProjects = false;
}
}
catch ( Exception e )
{
executionExceptions.add( e );
return new DefaultMavenExecutionResult( executionExceptions );
}
ReactorManager rm;
try
{
rm = new ReactorManager( projects, request.getReactorFailureBehavior() );
}
catch ( CycleDetectedException e )
{
executionExceptions.add( new BuildFailureException(
"The projects in the reactor contain a cyclic reference: " + e.getMessage(), e ) );
return new DefaultMavenExecutionResult( executionExceptions );
}
catch ( DuplicateProjectException e )
{
executionExceptions.add( new BuildFailureException( e.getMessage(), e ) );
return new DefaultMavenExecutionResult( executionExceptions );
}
if ( rm.hasMultipleProjects() )
{
getLogger().info( "Reactor build order: " );
for ( Iterator i = rm.getSortedProjects().iterator(); i.hasNext(); )
{
MavenProject project = (MavenProject) i.next();
getLogger().info( " " + project.getName() );
}
}
MavenSession session = createSession( request, rm, dispatcher );
session.setUsingPOMsFromFilesystem( foundProjects );
try
{
lifecycleExecutor.execute( session, rm, dispatcher );
}
catch ( Exception e )
{
executionExceptions.add( new BuildFailureException( e.getMessage(), e ) );
}
return new DefaultMavenExecutionResult( executionExceptions, rm );
}
private MavenProject getSuperProject( MavenExecutionRequest request )
throws MavenExecutionException
{

View File

@ -67,6 +67,8 @@ public class DefaultMavenExecutionRequest
private boolean useReactor = false;
private boolean recursive = true;
private String pomFile;
private String reactorFailureBehavior = REACTOR_FAIL_FAST;
@ -89,8 +91,6 @@ public class DefaultMavenExecutionRequest
private String globalChecksumPolicy = CHECKSUM_POLICY_WARN;
private boolean recursive = true;
private boolean updateSnapshots = false;
/**

View File

@ -19,6 +19,7 @@ package org.apache.maven.execution;
* under the License.
*/
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.project.MavenProject;
import java.util.ArrayList;
@ -28,49 +29,48 @@ import java.util.List;
public class DefaultMavenExecutionResult
implements MavenExecutionResult
{
private MavenProject project;
private List topologicallySortedProjects;
private ArtifactResolutionResult artifactResolutionResult;
private List exceptions;
private MavenProject mavenProject;
private ReactorManager reactorManager;
public DefaultMavenExecutionResult( List exceptions )
public MavenExecutionResult setProject( MavenProject project )
{
this.exceptions = exceptions;
this.project = project;
return this;
}
public DefaultMavenExecutionResult( ReactorManager reactorManager )
public MavenProject getProject()
{
this.reactorManager = reactorManager;
return project;
}
public DefaultMavenExecutionResult( List exceptions,
ReactorManager reactorManager )
public MavenExecutionResult setTopologicallySortedProjects( List topologicallySortedProjects )
{
this.reactorManager = reactorManager;
this.exceptions = exceptions;
this.topologicallySortedProjects = topologicallySortedProjects;
return this;
}
public DefaultMavenExecutionResult( MavenProject project,
List exceptions )
public List getTopologicallySortedProjects()
{
this.mavenProject = project;
this.exceptions = exceptions;
return topologicallySortedProjects;
}
public MavenProject getMavenProject()
public ArtifactResolutionResult getArtifactResolutionResult()
{
if ( reactorManager != null )
{
return reactorManager.getTopLevelProject();
}
return mavenProject;
return artifactResolutionResult;
}
public ReactorManager getReactorManager()
public MavenExecutionResult setArtifactResolutionResult( ArtifactResolutionResult artifactResolutionResult )
{
return reactorManager;
this.artifactResolutionResult = artifactResolutionResult;
return this;
}
public List getExceptions()

View File

@ -19,6 +19,7 @@ package org.apache.maven.execution;
* under the License.
*/
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.project.MavenProject;
import java.util.List;
@ -28,9 +29,17 @@ import java.util.List;
*/
public interface MavenExecutionResult
{
MavenProject getMavenProject();
MavenExecutionResult setProject( MavenProject project );
ReactorManager getReactorManager();
MavenProject getProject();
MavenExecutionResult setTopologicallySortedProjects( List projects );
List getTopologicallySortedProjects();
MavenExecutionResult setArtifactResolutionResult( ArtifactResolutionResult result );
ArtifactResolutionResult getArtifactResolutionResult();
// for each exception
// - knowing what artifacts are missing

View File

@ -29,76 +29,6 @@ under the License.
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-embedder</artifactId>
<name>Maven Embedder</name>
<properties>
<bundleVersion>2.1.0.v20070728-1835</bundleVersion>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>shade-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.0-alpha-10</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>false</createDependencyReducedPom>
<!-- this will work with shade plugin 1.0-alpha-11-SNAP -->
<keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
<transformers>
<transformer implementation="org.codehaus.mojo.shade.resource.ComponentsXmlResourceTransformer"/>
</transformers>
<artifactSet>
<excludes>
<exclude>org.codehaus.plexus:plexus-component-api</exclude>
<exclude>classworlds:classworlds</exclude>
<exclude>junit:junit</exclude>
<exclude>jmock:jmock</exclude>
<exclude>xml-apis:xml-apis</exclude>
</excludes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.codehaus.plexus.util</pattern>
<excludes>
<exclude>org.codehaus.plexus.util.xml.Xpp3Dom</exclude>
<exclude>org.codehaus.plexus.util.xml.pull.*</exclude>
</excludes>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-1</version>
<executions>
<execution>
<id>create-distro</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptor>src/main/assembly/bin.xml</descriptor>
<finalName>maven-${version}</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
@ -144,7 +74,7 @@ under the License.
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
</dependency>
</dependency>
</dependencies>
<distributionManagement>
<site>
@ -167,7 +97,7 @@ under the License.
<plugin>
<artifactId>shade-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.0-alpha-10</version>
<version>1.0-alpha-12-SNAPSHOT</version>
<executions>
<execution>
<phase>package</phase>
@ -175,12 +105,78 @@ under the License.
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<!-- The IDEA folks don't want to put SNAPSHOT libs in their projects even though they are -->
<finalName>maven-embedder-idea-2.1</finalName>
<createDependencyReducedPom>false</createDependencyReducedPom>
<!-- this will work with shade plugin 1.0-alpha-11-SNAP -->
<keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
<transformers>
<transformer implementation="org.codehaus.mojo.shade.resource.ComponentsXmlResourceTransformer"/>
<transformer implementation="org.codehaus.mojo.shade.resource.ComponentsXmlResourceTransformer"/>
</transformers>
<artifactSet>
<excludes>
<exclude>org.codehaus.plexus:plexus-component-api</exclude>
<exclude>classworlds:classworlds</exclude>
<exclude>junit:junit</exclude>
<exclude>jmock:jmock</exclude>
<exclude>xml-apis:xml-apis</exclude>
<!-- So this is required for the IDEA embedder which already has its own copy of JDOM -->
<exclude>jdom:jdom</exclude>
<exclude>jtidy:jtidy</exclude>
</excludes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.codehaus.plexus.util</pattern>
<excludes>
<exclude>org.codehaus.plexus.util.xml.Xpp3Dom</exclude>
<exclude>org.codehaus.plexus.util.xml.pull.*</exclude>
</excludes>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!--
|
| This profile is specifically for creating an embedder that can be used for Eclipse integration. We need to
| need a single embedder JAR that looks like an OSGi bundle.
|
-->
<id>tycho</id>
<properties>
<bundleVersion>2.1.0.v20070728-1835</bundleVersion>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>shade-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.0-alpha-11-SNAPSHOT</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactId>maven-embedder-idea</shadedArtifactId>
<createDependencyReducedPom>false</createDependencyReducedPom>
<!-- this will work with shade plugin 1.0-alpha-11-SNAP -->
<keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
<transformers>
<transformer implementation="org.codehaus.mojo.shade.resource.ComponentsXmlResourceTransformer"/>
</transformers>
<artifactSet>
<excludes>
@ -233,7 +229,7 @@ under the License.
<!-- this will work with shade plugin 1.0-alpha-11-SNAP -->
<keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
<transformers>
<transformer implementation="org.codehaus.mojo.shade.resource.ComponentsXmlResourceTransformer"/>
<transformer implementation="org.codehaus.mojo.shade.resource.ComponentsXmlResourceTransformer"/>
</transformers>
<artifactSet>
<excludes>
@ -257,6 +253,23 @@ under the License.
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-1</version>
<executions>
<execution>
<id>create-distro</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptor>src/main/assembly/bin.xml</descriptor>
<finalName>maven-${version}</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

View File

@ -57,6 +57,7 @@ import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.MavenProjectBuildingResult;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.settings.MavenSettingsBuilder;
import org.apache.maven.settings.Settings;
@ -419,6 +420,8 @@ public class MavenEmbedder
*/
public MavenExecutionResult readProjectWithDependencies( MavenExecutionRequest request )
{
MavenExecutionResult result = new DefaultMavenExecutionResult();
MavenProject project = null;
try
@ -433,16 +436,37 @@ public class MavenEmbedder
//is this necessary in this context, I doubt it..mkleint
artifactHandlerManager.addHandlers( handlers );
project = mavenProjectBuilder.buildWithDependencies( new File( request.getPomFile() ),
request.getLocalRepository(), profileManager,
request.getTransferListener() );
}
catch ( Exception e )
{
return new DefaultMavenExecutionResult( project, Collections.singletonList( e ) );
// At this point real project building, and artifact resolution have not occured.
result.addException( e );
return result;
}
return new DefaultMavenExecutionResult( project, Collections.EMPTY_LIST );
MavenProjectBuildingResult r = null;
try
{
r = mavenProjectBuilder.buildWithDependencies(
new File( request.getPomFile() ),
request.getLocalRepository(),
profileManager,
request.getTransferListener() );
}
catch ( ProjectBuildingException e )
{
}
result.setProject( r.getProject() );
result.setArtifactResolutionResult( r.getArtifactResolutionResult() );
return result;
}
// ----------------------------------------------------------------------
@ -629,7 +653,7 @@ public class MavenEmbedder
try
{
settings = settingsBuilder.buildSettings( configuration.getUserSettingsFile(),
configuration.getGlobalSettingsFile() );
configuration.getGlobalSettingsFile() );
}
catch ( Exception e )
{
@ -873,7 +897,7 @@ public class MavenEmbedder
new ArtifactRepositoryPolicy( true, updatePolicyFlag, checksumPolicyFlag );
return artifactRepositoryFactory.createArtifactRepository( repositoryId, url, defaultArtifactRepositoryLayout,
snapshotsPolicy, releasesPolicy );
snapshotsPolicy, releasesPolicy );
}
// ----------------------------------------------------------------------------
@ -905,7 +929,11 @@ public class MavenEmbedder
}
catch ( MavenEmbedderException e )
{
return new DefaultMavenExecutionResult( Collections.singletonList( e ) );
MavenExecutionResult result = new DefaultMavenExecutionResult();
result.addException( e );
return result;
}
return maven.execute( request );

View File

@ -40,7 +40,7 @@ public class MavenEmbedderBehaviorTest
ConfigurationValidationResult result = MavenEmbedder.validateConfiguration( configuration );
assertTrue( result.isValid() );
assertTrue( result.isValid() );
MavenEmbedder maven = new MavenEmbedder( configuration );

View File

@ -58,9 +58,9 @@ public class MavenEmbedderCrappySettingsConfigurationTest
MavenExecutionResult result = embedder.execute( request );
assertNotNull( result.getMavenProject() );
assertNotNull( result.getProject() );
MavenProject project = result.getMavenProject();
MavenProject project = result.getProject();
String environment = project.getProperties().getProperty( "environment" );

View File

@ -66,7 +66,7 @@ public class MavenEmbedderExampleTest
// You may want to inspect the project after the execution.
// ----------------------------------------------------------------------------
MavenProject project = result.getMavenProject();
MavenProject project = result.getProject();
// Do something with the project

View File

@ -126,7 +126,7 @@ public class MavenEmbedderTest
assertNoExceptions( result );
MavenProject project = result.getMavenProject();
MavenProject project = result.getProject();
assertEquals( "embedder-test-project", project.getArtifactId() );
@ -153,7 +153,7 @@ public class MavenEmbedderTest
assertNoExceptions( result );
MavenProject project = result.getMavenProject();
MavenProject project = result.getProject();
assertEquals( "embedder-test-project", project.getArtifactId() );
@ -181,7 +181,7 @@ public class MavenEmbedderTest
assertNoExceptions( r0 );
MavenProject p0 = r0.getMavenProject();
MavenProject p0 = r0.getProject();
assertNull( p0.getProperties().getProperty( "embedderProfile" ) );
@ -199,7 +199,7 @@ public class MavenEmbedderTest
MavenExecutionResult r1 = maven.execute( request );
MavenProject p1 = r1.getMavenProject();
MavenProject p1 = r1.getProject();
assertEquals( "true", p1.getProperties().getProperty( "embedderProfile" ) );
@ -245,7 +245,7 @@ public class MavenEmbedderTest
assertNoExceptions( result );
MavenProject project = result.getMavenProject();
MavenProject project = result.getProject();
Artifact p = (Artifact) project.getPluginArtifactMap().get( plugin.getKey() );
assertEquals( "2.2", p.getVersion() );
@ -263,7 +263,7 @@ public class MavenEmbedderTest
assertNoExceptions( result );
project = result.getMavenProject();
project = result.getProject();
p = (Artifact) project.getPluginArtifactMap().get( plugin.getKey() );
assertEquals( "2.3", p.getVersion() );
@ -321,9 +321,9 @@ public class MavenEmbedderTest
assertNoExceptions( result );
assertEquals( "org.apache.maven", result.getMavenProject().getGroupId() );
assertEquals( "org.apache.maven", result.getProject().getGroupId() );
Set artifacts = result.getMavenProject().getArtifacts();
Set artifacts = result.getProject().getArtifacts();
assertEquals( 1, artifacts.size() );
@ -343,7 +343,7 @@ public class MavenEmbedderTest
assertNoExceptions( result );
// sources, test sources, and the junit jar..
assertEquals( 3, result.getMavenProject().getTestClasspathElements().size() );
assertEquals( 3, result.getProject().getTestClasspathElements().size() );
}
public void testProjectReadingWithDistributionStatus()
@ -361,9 +361,9 @@ public class MavenEmbedderTest
assertNoExceptions( result );
assertEquals( "org.apache.maven", result.getMavenProject().getGroupId() );
assertEquals( "org.apache.maven", result.getProject().getGroupId() );
assertEquals( "deployed", result.getMavenProject().getDistributionManagement().getStatus() );
assertEquals( "deployed", result.getProject().getDistributionManagement().getStatus() );
}
// ----------------------------------------------------------------------------

View File

@ -24,13 +24,14 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactStatus;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
@ -195,7 +196,9 @@ public class DefaultMavenProjectBuilder
// MavenProjectBuilder Implementation
// ----------------------------------------------------------------------
public MavenProject build( File projectDescriptor, ArtifactRepository localRepository, ProfileManager profileManager )
public MavenProject build( File projectDescriptor,
ArtifactRepository localRepository,
ProfileManager profileManager )
throws ProjectBuildingException
{
return buildFromSourceFileInternal( projectDescriptor, localRepository, profileManager, true );
@ -253,7 +256,8 @@ public class DefaultMavenProjectBuilder
return buildStandaloneSuperProject( localRepository, profileManager );
}
public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository, ProfileManager profileManager )
public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository,
ProfileManager profileManager )
throws ProjectBuildingException
{
Model superModel = getSuperModel();
@ -273,7 +277,7 @@ public class DefaultMavenProjectBuilder
String projectId = safeVersionlessKey( STANDALONE_SUPERPOM_GROUPID, STANDALONE_SUPERPOM_ARTIFACTID );
project.setManagedVersionMap(createManagedVersionMap(projectId, superModel.getDependencyManagement(), null));
project.setManagedVersionMap( createManagedVersionMap( projectId, superModel.getDependencyManagement(), null ) );
List activeProfiles = profileAdvisor.applyActivatedProfiles( superModel, null, profileManager.getExplicitlyActivatedIds(), profileManager.getExplicitlyDeactivatedIds() );
List activeExternalProfiles = profileAdvisor.applyActivatedExternalProfiles( superModel, null, profileManager );
@ -313,24 +317,22 @@ public class DefaultMavenProjectBuilder
}
public MavenProject buildWithDependencies( File projectDescriptor,
ArtifactRepository localRepository,
ProfileManager profileManager )
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException
public MavenProjectBuildingResult buildWithDependencies( File projectDescriptor,
ArtifactRepository localRepository,
ProfileManager profileManager )
throws ProjectBuildingException
{
return buildWithDependencies( projectDescriptor, localRepository, profileManager, null );
}
// note:jvz This was added for the embedder.
/**
* @todo move to metadatasource itself?
*/
public MavenProject buildWithDependencies( File projectDescriptor,
ArtifactRepository localRepository,
ProfileManager profileManager,
TransferListener transferListener )
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException
/** @todo move to metadatasource itself? */
public MavenProjectBuildingResult buildWithDependencies( File projectDescriptor,
ArtifactRepository localRepository,
ProfileManager profileManager,
TransferListener transferListener )
throws ProjectBuildingException
{
MavenProject project = build( projectDescriptor, localRepository, profileManager, false );
@ -362,8 +364,8 @@ public class DefaultMavenProjectBuilder
catch ( InvalidDependencyVersionException e )
{
throw new ProjectBuildingException( projectId,
"Unable to build project due to an invalid dependency version: " +
e.getMessage(), e );
"Unable to build project due to an invalid dependency version: " +
e.getMessage(), e );
}
if ( transferListener != null )
@ -371,15 +373,19 @@ public class DefaultMavenProjectBuilder
wagonManager.setDownloadMonitor( transferListener );
}
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(),
projectArtifact, managedVersions,
localRepository,
project.getRemoteArtifactRepositories(),
artifactMetadataSource );
ArtifactResolutionRequest request = new ArtifactResolutionRequest()
.setArtifact( projectArtifact )
.setArtifactDependencies( project.getDependencyArtifacts() )
.setLocalRepository( localRepository )
.setRemoteRepostories( project.getRemoteArtifactRepositories() )
.setManagedVersionMap( managedVersions )
.setMetadataSource( artifactMetadataSource );
ArtifactResolutionResult result = artifactResolver.resolve( request );
project.setArtifacts( result.getArtifacts() );
return project;
return new MavenProjectBuildingResult( project, result );
}
// ----------------------------------------------------------------------
@ -398,17 +404,19 @@ public class DefaultMavenProjectBuilder
catch ( ComponentLookupException e )
{
throw new ProjectBuildingException( "all", "Cannot lookup metadata source for building the project.",
e );
e );
}
}
}
private Map createManagedVersionMap( String projectId, DependencyManagement dependencyManagement, MavenProject parent )
private Map createManagedVersionMap( String projectId,
DependencyManagement dependencyManagement,
MavenProject parent )
throws ProjectBuildingException
{
Map map = null;
List deps;
if ( ( dependencyManagement != null ) && ( (deps = dependencyManagement.getDependencies()) != null ) && ( deps.size() > 0 ))
if ( ( dependencyManagement != null ) && ( ( deps = dependencyManagement.getDependencies() ) != null ) && ( deps.size() > 0 ) )
{
map = new ManagedVersionMap( map );
@ -425,9 +433,9 @@ public class DefaultMavenProjectBuilder
{
VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
versionRange, d.getType(),
d.getClassifier(), d.getScope(),
d.isOptional() );
versionRange, d.getType(),
d.getClassifier(), d.getScope(),
d.isOptional() );
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( " " + artifact );
@ -477,18 +485,18 @@ public class DefaultMavenProjectBuilder
// TODO: Remove this once we have build-context stuff working...
if ( !container.getContext().contains( "SystemProperties" ) )
{
container.addContextValue("SystemProperties", System.getProperties());
container.addContextValue( "SystemProperties", System.getProperties() );
}
Model model = readModel( "unknown", projectDescriptor, STRICT_MODEL_PARSING );
MavenProject project = buildInternal( projectDescriptor.getAbsolutePath(),
model,
localRepository,
buildArtifactRepositories( getSuperModel() ),
projectDescriptor,
profileManager,
STRICT_MODEL_PARSING );
model,
localRepository,
buildArtifactRepositories( getSuperModel() ),
projectDescriptor,
profileManager,
STRICT_MODEL_PARSING );
if ( checkDistributionManagementStatus )
{
@ -497,7 +505,7 @@ public class DefaultMavenProjectBuilder
String projectId = safeVersionlessKey( project.getGroupId(), project.getArtifactId() );
throw new ProjectBuildingException( projectId,
"Invalid project file: distribution status must not be specified for a project outside of the repository" );
"Invalid project file: distribution status must not be specified for a project outside of the repository" );
}
}
@ -520,13 +528,13 @@ public class DefaultMavenProjectBuilder
else
{
getLogger().warn( "Attempting to build MavenProject instance for Artifact (" + artifact.getGroupId() + ":"
+ artifact.getArtifactId() + ":" + artifact.getVersion() + ") of type: "
+ artifact.getType() + "; constructing POM artifact instead." );
+ artifact.getArtifactId() + ":" + artifact.getVersion() + ") of type: "
+ artifact.getType() + "; constructing POM artifact instead." );
projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(),
artifact.getArtifactId(),
artifact.getVersion(),
artifact.getScope() );
artifact.getArtifactId(),
artifact.getVersion(),
artifact.getScope() );
}
Model model;
@ -589,7 +597,8 @@ public class DefaultMavenProjectBuilder
}
private void checkStatusAndUpdate( Artifact projectArtifact,
ArtifactStatus status, File file,
ArtifactStatus status,
File file,
List remoteArtifactRepositories,
ArtifactRepository localRepository )
throws ArtifactNotFoundException
@ -709,9 +718,9 @@ public class DefaultMavenProjectBuilder
LinkedList lineage = new LinkedList();
LinkedHashSet aggregatedRemoteWagonRepositories = collectInitialRepositories( model, superModel,
parentSearchRepositories,
projectDir, explicitlyActive,
explicitlyInactive );
parentSearchRepositories,
projectDir, explicitlyActive,
explicitlyInactive );
Model originalModel = ModelUtils.cloneModel( model );
@ -719,13 +728,13 @@ public class DefaultMavenProjectBuilder
try
{
project = assembleLineage( model,
lineage,
localRepository,
projectDir,
parentSearchRepositories,
aggregatedRemoteWagonRepositories,
externalProfileManager,
strict );
lineage,
localRepository,
projectDir,
parentSearchRepositories,
aggregatedRemoteWagonRepositories,
externalProfileManager,
strict );
}
catch ( InvalidRepositoryException e )
{
@ -827,7 +836,7 @@ public class DefaultMavenProjectBuilder
}
project.setManagedVersionMap( createManagedVersionMap( projectId, project.getDependencyManagement(),
project.getParent() ) );
project.getParent() ) );
return project;
}
@ -841,8 +850,12 @@ public class DefaultMavenProjectBuilder
* 4. superModel repositories
* 5. parentSearchRepositories
*/
private LinkedHashSet collectInitialRepositories( Model model, Model superModel, List parentSearchRepositories,
File projectDir, List explicitlyActive, List explicitlyInactive )
private LinkedHashSet collectInitialRepositories( Model model,
Model superModel,
List parentSearchRepositories,
File projectDir,
List explicitlyActive,
List explicitlyInactive )
throws ProjectBuildingException
{
LinkedHashSet collected = new LinkedHashSet();
@ -859,13 +872,16 @@ public class DefaultMavenProjectBuilder
return collected;
}
private void collectInitialRepositoriesFromModel( LinkedHashSet collected, Model model, File projectDir,
List explicitlyActive, List explicitlyInactive )
private void collectInitialRepositoriesFromModel( LinkedHashSet collected,
Model model,
File projectDir,
List explicitlyActive,
List explicitlyInactive )
throws ProjectBuildingException
{
Set reposFromProfiles = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model, projectDir,
explicitlyActive,
explicitlyInactive );
explicitlyActive,
explicitlyInactive );
if ( ( reposFromProfiles != null ) && !reposFromProfiles.isEmpty() )
{
@ -882,13 +898,14 @@ public class DefaultMavenProjectBuilder
catch ( InvalidRepositoryException e )
{
throw new ProjectBuildingException( safeVersionlessKey( model.getGroupId(), model.getArtifactId() ),
"Failed to construct ArtifactRepository instances for repositories declared in: "
+ model.getId(), e );
"Failed to construct ArtifactRepository instances for repositories declared in: "
+ model.getId(), e );
}
}
}
private String safeVersionlessKey( String groupId, String artifactId )
private String safeVersionlessKey( String groupId,
String artifactId )
{
String gid = groupId;
@ -981,7 +998,7 @@ public class DefaultMavenProjectBuilder
// TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't
Artifact projectArtifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(),
project.getVersion(), project.getPackaging() );
project.getVersion(), project.getPackaging() );
project.setArtifact( projectArtifact );
project.setPluginArtifactRepositories( mavenTools.buildArtifactRepositories( model.getPluginRepositories() ) );
@ -1018,7 +1035,7 @@ public class DefaultMavenProjectBuilder
if ( validationResult.getMessageCount() > 0 )
{
throw new InvalidProjectModelException( projectId, pomLocation, "Failed to validate POM",
validationResult );
validationResult );
}
project.setRemoteArtifactRepositories(
@ -1088,7 +1105,7 @@ public class DefaultMavenProjectBuilder
projectContext.store( buildContextManager );
project.setActiveProfiles( profileAdvisor.applyActivatedProfiles( currentModel, projectDir, explicitlyActive,
explicitlyInactive ) );
explicitlyInactive ) );
if ( lastProject != null )
{
@ -1121,7 +1138,9 @@ public class DefaultMavenProjectBuilder
return result;
}
private Model readModel( String projectId, File file, boolean strict )
private Model readModel( String projectId,
File file,
boolean strict )
throws ProjectBuildingException
{
Reader reader = null;
@ -1133,7 +1152,7 @@ public class DefaultMavenProjectBuilder
catch ( FileNotFoundException e )
{
throw new ProjectBuildingException( projectId,
"Could not find the model file '" + file.getAbsolutePath() + "'.", e );
"Could not find the model file '" + file.getAbsolutePath() + "'.", e );
}
catch ( IOException e )
{
@ -1146,7 +1165,10 @@ public class DefaultMavenProjectBuilder
}
}
private Model readModel( String projectId, String pomLocation, Reader reader, boolean strict )
private Model readModel( String projectId,
String pomLocation,
Reader reader,
boolean strict )
throws IOException, InvalidProjectModelException
{
StringWriter sw = new StringWriter();
@ -1169,11 +1191,13 @@ public class DefaultMavenProjectBuilder
catch ( XmlPullParserException e )
{
throw new InvalidProjectModelException( projectId, pomLocation,
"Parse error reading POM. Reason: " + e.getMessage(), e );
"Parse error reading POM. Reason: " + e.getMessage(), e );
}
}
private Model readModel( String projectId, URL url, boolean strict )
private Model readModel( String projectId,
URL url,
boolean strict )
throws ProjectBuildingException
{
InputStreamReader reader = null;
@ -1193,12 +1217,15 @@ public class DefaultMavenProjectBuilder
}
}
private static String createCacheKey( String groupId, String artifactId, String version )
private static String createCacheKey( String groupId,
String artifactId,
String version )
{
return groupId + ":" + artifactId + ":" + version;
}
protected Set createPluginArtifacts( String projectId, List plugins )
protected Set createPluginArtifacts( String projectId,
List plugins )
throws ProjectBuildingException
{
Set pluginArtifacts = new HashSet();
@ -1221,7 +1248,7 @@ public class DefaultMavenProjectBuilder
try
{
artifact = artifactFactory.createPluginArtifact( p.getGroupId(), p.getArtifactId(),
VersionRange.createFromVersionSpec( version ) );
VersionRange.createFromVersionSpec( version ) );
}
catch ( InvalidVersionSpecificationException e )
{
@ -1240,7 +1267,8 @@ public class DefaultMavenProjectBuilder
}
// TODO: share with createPluginArtifacts?
protected Set createReportArtifacts( String projectId, List reports )
protected Set createReportArtifacts( String projectId,
List reports )
throws ProjectBuildingException
{
Set pluginArtifacts = new HashSet();
@ -1265,7 +1293,7 @@ public class DefaultMavenProjectBuilder
try
{
artifact = artifactFactory.createPluginArtifact( p.getGroupId(), p.getArtifactId(),
VersionRange.createFromVersionSpec( version ) );
VersionRange.createFromVersionSpec( version ) );
}
catch ( InvalidVersionSpecificationException e )
{
@ -1285,7 +1313,8 @@ public class DefaultMavenProjectBuilder
}
// TODO: share with createPluginArtifacts?
protected Set createExtensionArtifacts( String projectId, List extensions )
protected Set createExtensionArtifacts( String projectId,
List extensions )
throws ProjectBuildingException
{
Set extensionArtifacts = new HashSet();

View File

@ -71,13 +71,13 @@ public interface MavenProjectBuilder
// These methods are used by the MavenEmbedder
// ----------------------------------------------------------------------
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository,
MavenProjectBuildingResult buildWithDependencies( File project, ArtifactRepository localRepository,
ProfileManager globalProfileManager, TransferListener transferListener )
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException;
throws ProjectBuildingException;
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository,
MavenProjectBuildingResult buildWithDependencies( File project, ArtifactRepository localRepository,
ProfileManager globalProfileManager )
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException;
throws ProjectBuildingException;
// ----------------------------------------------------------------------
//

View File

@ -19,63 +19,34 @@ package org.apache.maven.project;
* under the License.
*/
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.project.validation.ModelValidationResult;
/**
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @author Jason van Zyl
* @version $Id$
*/
public class MavenProjectBuildingResult
{
/** */
private MavenProject project;
/** */
private ModelValidationResult modelValidationResult;
private ArtifactResolutionResult artifactResolutionResult;
/** */
private boolean successful;
/**
* @param project
*/
public MavenProjectBuildingResult( MavenProject project )
public MavenProjectBuildingResult( MavenProject project,
ArtifactResolutionResult artifactResolutionResult )
{
this.project = project;
successful = true;
this.artifactResolutionResult = artifactResolutionResult;
}
public MavenProjectBuildingResult( ModelValidationResult modelValidationResult )
{
this.modelValidationResult = modelValidationResult;
successful = modelValidationResult.getMessageCount() == 0;
}
/**
* @return Returns the modelValidationResult.
*/
public ModelValidationResult getModelValidationResult()
{
return modelValidationResult;
}
/**
* @return Returns the project.
*/
public MavenProject getProject()
{
return project;
}
/**
* Returns true if the project is valid.
*
* @return Returns true if the project is valid.
*/
public boolean isSuccessful()
public ArtifactResolutionResult getArtifactResolutionResult()
{
return successful;
return artifactResolutionResult;
}
}

View File

@ -103,7 +103,7 @@ public abstract class AbstractMavenProjectTestCase
protected MavenProject getProjectWithDependencies( File pom )
throws Exception
{
return projectBuilder.buildWithDependencies( pom, getLocalRepository(), null );
return projectBuilder.buildWithDependencies( pom, getLocalRepository(), null ).getProject();
}
protected MavenProject getProject( File pom )

View File

@ -148,7 +148,7 @@ under the License.
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-classworlds</artifactId>
<version>[1.2-alpha-9]</version>
<version>1.2-alpha-10</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>