From 884f70085e6e8c1127d2aa351ddc88e25eae2523 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Sat, 1 Sep 2007 19:23:17 +0000 Subject: [PATCH] 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 --- build.properties | 4 +- .../java/org/apache/maven/DefaultMaven.java | 184 ++++++++--------- .../DefaultMavenExecutionRequest.java | 4 +- .../DefaultMavenExecutionResult.java | 50 ++--- .../maven/execution/MavenExecutionResult.java | 13 +- maven-embedder/pom.xml | 163 ++++++++------- .../apache/maven/embedder/MavenEmbedder.java | 44 ++++- .../embedder/MavenEmbedderBehaviorTest.java | 2 +- ...bedderCrappySettingsConfigurationTest.java | 4 +- .../embedder/MavenEmbedderExampleTest.java | 2 +- .../maven/embedder/MavenEmbedderTest.java | 22 +-- .../project/DefaultMavenProjectBuilder.java | 185 ++++++++++-------- .../maven/project/MavenProjectBuilder.java | 8 +- .../project/MavenProjectBuildingResult.java | 45 +---- .../project/AbstractMavenProjectTestCase.java | 2 +- pom.xml | 2 +- 16 files changed, 393 insertions(+), 341 deletions(-) diff --git a/build.properties b/build.properties index 5e5b37fceb..dd48e85489 100644 --- a/build.properties +++ b/build.properties @@ -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 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 7d504c5c9a..fd1cc85293 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -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 { diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java index 295586448b..528fd544df 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java @@ -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; /** diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java index 51e360de91..8edee3709b 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java @@ -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() diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java index 5267e16772..06232f4b33 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java @@ -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 diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index b87910b2ef..ff3e23af2c 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -29,76 +29,6 @@ under the License. 4.0.0 maven-embedder Maven Embedder - - 2.1.0.v20070728-1835 - - - - - src/main/resources - true - - - - - shade-maven-plugin - org.codehaus.mojo - 1.0-alpha-10 - - - package - - shade - - - true - false - - true - - - - - - org.codehaus.plexus:plexus-component-api - classworlds:classworlds - junit:junit - jmock:jmock - xml-apis:xml-apis - - - - - org.codehaus.plexus.util - - org.codehaus.plexus.util.xml.Xpp3Dom - org.codehaus.plexus.util.xml.pull.* - - - - - - - - - maven-assembly-plugin - 2.2-beta-1 - - - create-distro - package - - single - - - src/main/assembly/bin.xml - maven-${version} - - - - - - org.apache.maven @@ -144,7 +74,7 @@ under the License. org.apache.maven.wagon wagon-file - + @@ -167,7 +97,7 @@ under the License. shade-maven-plugin org.codehaus.mojo - 1.0-alpha-10 + 1.0-alpha-12-SNAPSHOT package @@ -175,12 +105,78 @@ under the License. shade - true + + maven-embedder-idea-2.1 false true - + + + + + org.codehaus.plexus:plexus-component-api + classworlds:classworlds + junit:junit + jmock:jmock + xml-apis:xml-apis + + jdom:jdom + jtidy:jtidy + + + + + org.codehaus.plexus.util + + org.codehaus.plexus.util.xml.Xpp3Dom + org.codehaus.plexus.util.xml.pull.* + + + + + + + + + + + + + tycho + + 2.1.0.v20070728-1835 + + + + + src/main/resources + true + + + + + shade-maven-plugin + org.codehaus.mojo + 1.0-alpha-11-SNAPSHOT + + + package + + shade + + + maven-embedder-idea + false + + true + + @@ -233,7 +229,7 @@ under the License. true - + @@ -257,6 +253,23 @@ under the License. + + maven-assembly-plugin + 2.2-beta-1 + + + create-distro + package + + single + + + src/main/assembly/bin.xml + maven-${version} + + + + diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java index f000eb1aef..391f5cc60f 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java @@ -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 ); diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderBehaviorTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderBehaviorTest.java index 1d3c79771b..43c32ad145 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderBehaviorTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderBehaviorTest.java @@ -40,7 +40,7 @@ public class MavenEmbedderBehaviorTest ConfigurationValidationResult result = MavenEmbedder.validateConfiguration( configuration ); - assertTrue( result.isValid() ); + assertTrue( result.isValid() ); MavenEmbedder maven = new MavenEmbedder( configuration ); diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderCrappySettingsConfigurationTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderCrappySettingsConfigurationTest.java index 13c0efcaee..f0904f5a1b 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderCrappySettingsConfigurationTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderCrappySettingsConfigurationTest.java @@ -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" ); diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderExampleTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderExampleTest.java index 51a3e8d91e..578717f5f1 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderExampleTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderExampleTest.java @@ -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 diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java index 522c5d60e4..69da8e75f1 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java @@ -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() ); } // ---------------------------------------------------------------------------- diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index bd00e06ee1..67ea4d0ad5 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -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(); diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java index db61e07539..1fca73a8ea 100644 --- a/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java @@ -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; // ---------------------------------------------------------------------- // diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuildingResult.java b/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuildingResult.java index c3136bab88..d2fe3a8910 100644 --- a/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuildingResult.java +++ b/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuildingResult.java @@ -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 Trygve Laugstøl + * @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; } } diff --git a/maven-project/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/maven-project/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java index 06e0918650..d21454a481 100644 --- a/maven-project/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java +++ b/maven-project/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java @@ -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 ) diff --git a/pom.xml b/pom.xml index 62b6a70d6a..72c79c0637 100644 --- a/pom.xml +++ b/pom.xml @@ -148,7 +148,7 @@ under the License. org.codehaus.plexus plexus-classworlds - [1.2-alpha-9] + 1.2-alpha-10 org.codehaus.plexus