From a73c5abc9c58470b14a6e63fa0af859afdfb587e Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Fri, 8 May 2009 03:24:55 +0000 Subject: [PATCH] o in the middle of a ReactorArtifactRepository but ben and igor need access so checking in git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@772832 13f79535-47bb-0310-9956-ffa450edef68 --- apache-maven/pom.xml | 11 - .../maven/artifact/DefaultArtifact.java | 4 +- .../factory/DefaultArtifactFactory.java | 3 +- .../metadata/ArtifactMetadataSource.java | 23 +- .../repository/ArtifactRepository.java | 12 +- .../repository/DefaultArtifactRepository.java | 14 +- .../resolver/DefaultArtifactCollector.java | 7 - .../resolver/DefaultArtifactResolver.java | 1 - .../transform/SnapshotTransformation.java | 6 +- .../lifecycle/DefaultLifecycleExecutor.java | 39 +- .../maven/plugin/DefaultPluginManager.java | 34 +- .../project/DefaultMavenProjectBuilder.java | 660 ++++++++---------- .../project/TestMavenRepositorySystem.java | 64 -- .../artifact/MavenMetadataSourceTest.java | 15 +- maven-embedder/pom.xml | 8 - .../apache/maven/embedder/MavenEmbedder.java | 13 - ...DefaultMavenExecutionRequestPopulator.java | 23 - .../org/apache/maven/model/DomainModel.java | 2 +- .../repository/LegacyRepositorySystem.java | 123 +--- .../maven/repository/RepositorySystem.java | 20 +- pom.xml | 13 +- 21 files changed, 382 insertions(+), 713 deletions(-) diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml index cad1bdc025..69a2ffe9de 100644 --- a/apache-maven/pom.xml +++ b/apache-maven/pom.xml @@ -23,11 +23,8 @@ maven 3.0-SNAPSHOT - apache-maven - Maven Distribution - org.apache.maven @@ -58,14 +55,6 @@ org.apache.maven.wagon wagon-http-lightweight - - org.apache.maven.wagon - wagon-ssh - - - org.apache.maven.wagon - wagon-ssh-external - org.apache.maven.wagon wagon-file diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/DefaultArtifact.java b/maven-compat/src/main/java/org/apache/maven/artifact/DefaultArtifact.java index 40a0987fb0..de02d65e02 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/DefaultArtifact.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/DefaultArtifact.java @@ -38,9 +38,7 @@ import org.apache.maven.artifact.versioning.VersionRange; import org.codehaus.plexus.util.StringUtils; /** - * @author Jason van Zyl - * @version $Id$ - * @todo this should possibly be replaced by type handler + * @author Jason van Zyl */ public class DefaultArtifact implements Artifact diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java b/maven-compat/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java index fbc50e708e..2ab45f1dca 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java @@ -180,9 +180,8 @@ public class DefaultArtifactFactory String inheritedScope, boolean optional ) { - // TODO: can refactor - inherited artifactScope calculation belongs in the collector, use artifactScope handler - String desiredScope = Artifact.SCOPE_RUNTIME; + if ( inheritedScope == null ) { desiredScope = scope; diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java b/maven-compat/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java index dee58181f4..2792d9325d 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java @@ -34,19 +34,7 @@ import org.apache.maven.artifact.versioning.ArtifactVersion; */ public interface ArtifactMetadataSource { - String ROLE = ArtifactMetadataSource.class.getName(); - - ResolutionGroup retrieve( Artifact artifact, - ArtifactRepository localRepository, - List remoteRepositories ) - throws ArtifactMetadataRetrievalException; - - /** - * Resolve all relocations in the POM for this artifact, and return the new artifact coordinate. - */ - Artifact retrieveRelocatedArtifact( Artifact artifact, - ArtifactRepository localRepository, - List remoteRepositories ) + ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactMetadataRetrievalException; /** @@ -61,9 +49,7 @@ public interface ArtifactMetadataSource * @throws ArtifactMetadataRetrievalException * in case of error while retrieving repository metadata from the repository. */ - List retrieveAvailableVersions( Artifact artifact, - ArtifactRepository localRepository, - List remoteRepositories ) + List retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactMetadataRetrievalException; /** @@ -79,7 +65,6 @@ public interface ArtifactMetadataSource * @throws ArtifactMetadataRetrievalException * in case of error while retrieving repository metadata from the repository. */ - List retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact, - ArtifactRepository localRepository, - ArtifactRepository remoteRepository ) throws ArtifactMetadataRetrievalException; + List retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact, ArtifactRepository localRepository, ArtifactRepository remoteRepository ) + throws ArtifactMetadataRetrievalException; } \ No newline at end of file diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java index 8ad2d02737..96b9499ccc 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java @@ -19,12 +19,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -/** - * Specifies the repository used for artifact handling. - * - * @author Brett Porter - * @version $Id$ - */ public interface ArtifactRepository { String pathOf( Artifact artifact ); @@ -59,9 +53,11 @@ public interface ArtifactRepository String getKey(); - boolean isUniqueVersion(); - void setBlacklisted( boolean blackListed ); boolean isBlacklisted(); + + // New interface methods for the repository system. + + Artifact find( Artifact artifact ); } diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java index 38068cfa9b..e5a679c3ad 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java @@ -31,6 +31,7 @@ import org.apache.maven.wagon.repository.Repository; * @author Michal Maczka * @version $Id$ */ +//TODO: this needs to be decoupled from Wagon public class DefaultArtifactRepository extends Repository implements ArtifactRepository @@ -41,8 +42,6 @@ public class DefaultArtifactRepository private ArtifactRepositoryPolicy releases; - private boolean uniqueVersion = true; - private boolean blacklisted; /** @@ -69,7 +68,6 @@ public class DefaultArtifactRepository { super( id, url ); this.layout = layout; - this.uniqueVersion = uniqueVersion; } /** @@ -155,11 +153,6 @@ public class DefaultArtifactRepository return getId(); } - public boolean isUniqueVersion() - { - return uniqueVersion; - } - public boolean isBlacklisted() { return blacklisted; @@ -184,4 +177,9 @@ public class DefaultArtifactRepository return sb.toString(); } + + public Artifact find( Artifact artifact ) + { + return null; + } } diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java index 7b52ea74f8..dce28a78a7 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java @@ -512,13 +512,6 @@ public class DefaultArtifactCollector artifact.selectVersion( version.toString() ); fireEvent( ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, child ); } - - Artifact relocated = source.retrieveRelocatedArtifact( artifact, localRepository, childRemoteRepositories ); - if ( !artifact.equals( relocated ) ) - { - artifact = relocated; - child.setArtifact( artifact ); - } } while( !childKey.equals( child.getKey() ) ); diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index cef2b1373d..283e5dfd7d 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -455,7 +455,6 @@ public class DefaultArtifactResolver } catch ( ArtifactMetadataRetrievalException e ) { - e.printStackTrace(); // need to add metadata resolution exception return result; } diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java b/maven-compat/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java index e6e73e9adf..2e8ce026f8 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java @@ -95,10 +95,8 @@ public class SnapshotTransformation if ( artifact.isSnapshot() ) { Snapshot snapshot = new Snapshot(); - if ( remoteRepository.isUniqueVersion() ) - { - snapshot.setTimestamp( getDeploymentTimestamp() ); - } + + snapshot.setTimestamp( getDeploymentTimestamp() ); // we update the build number anyway so that it doesn't get lost. It requires the timestamp to take effect try diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index d17ae87f2d..8390b297cd 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -508,6 +508,36 @@ public class DefaultLifecycleExecutor return mojoDescriptor; } + + private static int count = 0; + + // org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process + MojoDescriptor getMojoDescriptor( String groupId, String artifactId, String version, String goal, MavenProject project, ArtifactRepository localRepository ) + throws LifecycleExecutionException + { + Plugin plugin = new Plugin(); + plugin.setGroupId( groupId ); + plugin.setArtifactId( artifactId ); + plugin.setVersion( version ); + + MojoDescriptor mojoDescriptor; + + //need to do the active project thing as the site plugin is referencing itself + + if ( artifactId.equals( "maven-site-plugin" ) ){ count++; System.out.println( count ); }; + + System.out.println( ">>> " + artifactId ); + try + { + mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, project, localRepository ); + } + catch ( PluginLoaderException e ) + { + throw new LifecycleExecutionException( "Error loading MojoDescriptor.", e ); + } + + return mojoDescriptor; + } public void initialize() throws InitializationException @@ -620,13 +650,13 @@ public class DefaultLifecycleExecutor public Set populateDefaultConfigurationForPlugins( Set plugins, MavenProject project, ArtifactRepository localRepository ) throws LifecycleExecutionException { - for( Plugin p: plugins ) + for( Plugin p : plugins ) { for( PluginExecution e : p.getExecutions() ) { - for( String g : e.getGoals() ) + for( String goal : e.getGoals() ) { - Xpp3Dom dom = getDefaultPluginConfiguration( p.getGroupId(), p.getArtifactId(), p.getVersion(), g, project, localRepository ); + Xpp3Dom dom = getDefaultPluginConfiguration( p.getGroupId(), p.getArtifactId(), p.getVersion(), goal, project, localRepository ); e.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) e.getConfiguration(), dom, Boolean.TRUE ) ); } } @@ -638,8 +668,7 @@ public class DefaultLifecycleExecutor public Xpp3Dom getDefaultPluginConfiguration( String groupId, String artifactId, String version, String goal, MavenProject project, ArtifactRepository localRepository ) throws LifecycleExecutionException { - //return new Xpp3Dom( "configuration" ); - return convert( getMojoDescriptor( groupId+":"+artifactId+":"+version+":"+goal, project, localRepository ) ); + return convert( getMojoDescriptor( groupId, artifactId, version, goal, project, localRepository ) ); } public Xpp3Dom getMojoConfiguration( MojoDescriptor mojoDescriptor ) diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index 5acd64f108..0807356195 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -54,7 +54,6 @@ import org.apache.maven.project.DuplicateArtifactAttachmentException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.apache.maven.repository.RepositorySystem; -import org.apache.maven.repository.VersionNotFoundException; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.annotations.Component; @@ -149,10 +148,6 @@ public class DefaultPluginManager { throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e ); } -// catch ( InvalidPluginException e ) -// { -// throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e ); -// } catch ( PluginVersionResolutionException e ) { throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e ); @@ -588,31 +583,16 @@ public class DefaultPluginManager { MavenProject project = session.getCurrentProject(); - // TODO: such a call in MavenMetadataSource too - packaging not really the intention of type Artifact artifact = repositorySystem.createArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), null, project.getPackaging() ); - - // TODO: we don't need to resolve over and over again, as long as we are sure that the parameters are the same - // check this with yourkit as a hot spot. - // Don't recreate if already created - for effeciency, and because clover plugin adds to it - if ( project.getDependencyArtifacts() == null ) - { - // NOTE: Don't worry about covering this case with the error-reporter bindings...it's already handled by the project error reporter. - try - { - project.setDependencyArtifacts( repositorySystem.createArtifacts( project.getDependencies(), null, null, project ) ); - } - catch ( VersionNotFoundException e ) - { - throw new InvalidDependencyVersionException( e.getProjectId(), e.getDependency(), e.getPomFile(), e.getCauseException() ); - } - } - + ArtifactFilter filter = new ScopeArtifactFilter( scope ); ArtifactResolutionRequest request = new ArtifactResolutionRequest() .setArtifact( artifact ) + // Here the root is not resolved because we are presumably working with a project locally. .setResolveRoot( false ) - .setArtifactDependencies( project.getDependencyArtifacts() ) + .setResolveTransitively( true ) + //.setArtifactDependencies( project.getDependencyArtifacts() ) .setLocalRepository( session.getLocalRepository() ) .setRemoteRepostories( project.getRemoteArtifactRepositories() ) .setManagedVersionMap( project.getManagedVersionMap() ) @@ -622,6 +602,7 @@ public class DefaultPluginManager resolutionErrorHandler.throwErrors( request, result ); + //TODO: this is wrong project.setArtifacts( result.getArtifacts() ); ArtifactRepository localRepository = session.getLocalRepository(); @@ -698,11 +679,6 @@ public class DefaultPluginManager public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, MavenProject project, ArtifactRepository localRepository ) throws PluginLoaderException { - if ( plugin.getVersion() == null ) - { - throw new IllegalArgumentException( "plugin.version: null" ); - } - PluginDescriptor pluginDescriptor = loadPlugin( plugin, project, localRepository ); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal ); diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index d3a30376ca..eb56c9b82f 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.io.Reader; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Properties; @@ -71,26 +70,26 @@ public class DefaultMavenProjectBuilder { @Requirement private Logger logger; - + @Requirement private ModelValidator validator; - + @Requirement - private LifecycleExecutor lifecycle; + private LifecycleExecutor lifecycle; @Requirement private RepositorySystem repositorySystem; @Requirement List listeners; - - @Requirement - private Interpolator interpolator; - - @Requirement - private ResolutionErrorHandler resolutionErrorHandler; - private static HashMap hm = new HashMap(); + @Requirement + private Interpolator interpolator; + + @Requirement + private ResolutionErrorHandler resolutionErrorHandler; + + //private static HashMap hm = new HashMap(); private MavenProject superProject; @@ -98,100 +97,85 @@ public class DefaultMavenProjectBuilder // MavenProjectBuilder Implementation // ---------------------------------------------------------------------- - // This is used by the SITE plugin. - public MavenProject build( File project, ArtifactRepository localRepository, ProfileManager profileManager ) - throws ProjectBuildingException - { - ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration() - .setLocalRepository( localRepository ) - .setGlobalProfileManager( profileManager ); - - return build( project, configuration ); - } - public MavenProject build( File pomFile, ProjectBuilderConfiguration configuration ) throws ProjectBuildingException { - //Do inheritance DomainModel domainModel; - try - { - domainModel = build( "unknown", pomFile, configuration ); - - } - catch (IOException e) - { - throw new ProjectBuildingException("", "", e); - } - - //Profiles - - List projectProfiles; - Properties props = new Properties(); - props.putAll(configuration.getExecutionProperties()); try { - projectProfiles = DefaultProfileManager.getActiveProfilesFrom(configuration.getGlobalProfileManager(), props, domainModel.getModel() ); - } - catch ( ProfileActivationException e ) - { - throw new ProjectBuildingException( "", "Failed to activate pom profiles."); - } - - try - { - List externalProfiles = new ArrayList(); - for(Profile p : projectProfiles) - { - if(!"pom".equals(p.getSource())) - { - logger.debug("Merging profile into model (build): Model = " + domainModel.getId() + ", Profile = " + p.getId() ); - externalProfiles.add(p); - } - } - - domainModel = ProcessorContext.mergeProfilesIntoModel( externalProfiles, domainModel ); + domainModel = build( "unknown", pomFile, configuration ); } catch ( IOException e ) { - throw new ProjectBuildingException("", ""); + throw new ProjectBuildingException( "", "", e ); } - + + //Profiles + + List projectProfiles; + Properties props = new Properties(); + props.putAll( configuration.getExecutionProperties() ); + + try + { + projectProfiles = DefaultProfileManager.getActiveProfilesFrom( configuration.getGlobalProfileManager(), props, domainModel.getModel() ); + } + catch ( ProfileActivationException e ) + { + throw new ProjectBuildingException( "", "Failed to activate pom profiles." ); + } + + try + { + List externalProfiles = new ArrayList(); + for ( Profile p : projectProfiles ) + { + if ( !"pom".equals( p.getSource() ) ) + { + logger.debug( "Merging profile into model (build): Model = " + domainModel.getId() + ", Profile = " + p.getId() ); + externalProfiles.add( p ); + } + } + + domainModel = ProcessorContext.mergeProfilesIntoModel( externalProfiles, domainModel ); + } + catch ( IOException e ) + { + throw new ProjectBuildingException( "", "" ); + } + //Interpolation & Management MavenProject project; - try - { - Model model = interpolateDomainModel( domainModel, configuration, pomFile ); - - List plns = new ArrayList(); - - Set plugins = lifecycle.getPluginsBoundByDefaultToAllLifecycles(model.getPackaging()); + try + { + Model model = interpolateDomainModel( domainModel, configuration, pomFile ); + + Set plugins = lifecycle.getPluginsBoundByDefaultToAllLifecycles( model.getPackaging() ); + + addPluginsToModel( model, plugins ); + + ProcessorContext.processManagementNodes( model ); + + project = this.fromDomainModelToMavenProject( model, domainModel.getParentFile(), configuration, pomFile ); + + Set pluginsFromProject = new HashSet(); + for ( Plugin p : project.getModel().getBuild().getPlugins() ) + { + Plugin copy = new Plugin(); + PluginProcessor.copy2( p, copy, true ); + pluginsFromProject.add( copy ); + } - addPluginsToModel(model, plugins); - - ProcessorContext.processManagementNodes(model); - - project = this.fromDomainModelToMavenProject(model, domainModel.getParentFile(), configuration, pomFile); - - ArrayList pln = new ArrayList(); - for(Plugin p : project.getModel().getBuild().getPlugins()) - { - Plugin copy = new Plugin(); - PluginProcessor.copy2(p, copy, true); - pln.add(copy); - } - // Merge the various sources for mojo configuration: // 1. default values from mojo descriptor // 2. POM values from per-plugin configuration // 3. POM values from per-execution configuration // These configuration sources are given in increasing order of dominance. - Set pl = lifecycle.populateDefaultConfigurationForPlugins(new HashSet(pln), - project, configuration.getLocalRepository()); - - for ( Plugin buildPlugin : pl ) + Set processedPlugins = lifecycle.populateDefaultConfigurationForPlugins( pluginsFromProject, project, configuration.getLocalRepository() ); + + for ( Plugin buildPlugin : processedPlugins ) { Xpp3Dom dom = (Xpp3Dom) buildPlugin.getConfiguration(); Plugin x = containsPlugin( buildPlugin, project.getModel().getBuild().getPlugins() ); @@ -210,30 +194,27 @@ public class DefaultMavenProjectBuilder PluginExecution pe = contains( g, x.getExecutions() ); if ( pe != null ) { - Xpp3Dom dom2 = - Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) pe.getConfiguration(), - (Xpp3Dom) e.getConfiguration() ); + Xpp3Dom dom2 = Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) pe.getConfiguration(), (Xpp3Dom) e.getConfiguration() ); e.setConfiguration( dom2 ); } } } } - } - - project.getModel().getBuild().setPlugins(new ArrayList(pl)); - } - catch (IOException e) - { - throw new ProjectBuildingException("", ""); - } - catch (LifecycleExecutionException e) - { - e.printStackTrace(); - throw new ProjectBuildingException("",e.getMessage()); - } - project.setActiveProfiles( projectProfiles ); - + + project.getModel().getBuild().setPlugins( new ArrayList( processedPlugins ) ); + } + catch ( IOException e ) + { + throw new ProjectBuildingException( "", "" ); + } + catch ( LifecycleExecutionException e ) + { + throw new ProjectBuildingException( "", e.getMessage() ); + } + + //project.setActiveProfiles( projectProfiles ); + Build build = project.getBuild(); // NOTE: setting this script-source root before path translation, because // the plugin tools compose basedir and scriptSourceRoot into a single file. @@ -241,95 +222,15 @@ public class DefaultMavenProjectBuilder project.addCompileSourceRoot( build.getSourceDirectory() ); project.addTestCompileSourceRoot( build.getTestSourceDirectory() ); project.setFile( pomFile ); - + setBuildOutputDirectoryOnParent( project ); - hm.put( ArtifactUtils.artifactId( project.getGroupId(), project.getArtifactId(), "pom", project.getVersion() ), project ); - return project; } - - private static PluginExecution contains(String goal, List plugins) - { - for(PluginExecution pe : plugins) - { - if(pe.getGoals().contains(goal)) - { - return pe; - } - } - return null; - } - - public static void addPluginsToModel( Model target, Set plugins ) - { - List mngPlugins = (target.getBuild().getPluginManagement() != null) - ? target.getBuild().getPluginManagement().getPlugins() : new ArrayList(); - - List pomPlugins = new ArrayList(target.getBuild().getPlugins()); - - List lifecyclePlugins = new ArrayList(); - - for( Plugin p : plugins ) - { - //Go ahead and add version if exists in pluginManagement - don't use default version - Plugin mngPlugin = containsPlugin(p, mngPlugins); - if(mngPlugin != null && mngPlugin.getVersion() != null) - { - //System.out.println("Set version:" + p.getVersion() + ": To = " + mngPlugin.getVersion()); - p.setVersion(mngPlugin.getVersion()); - } - - Plugin pomPlugin = containsPlugin( p, pomPlugins); - if ( pomPlugin == null ) - { - lifecyclePlugins.add( p ); - } - else - { - PluginProcessor.copy2( p, pomPlugin, true ); - if ( p.getConfiguration() != null ) - { - System.out.println( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) p.getConfiguration(), - (Xpp3Dom) pomPlugin.getConfiguration() ) ); - } - } - } - pomPlugins.addAll(lifecyclePlugins); - target.getBuild().setPlugins(pomPlugins); - } - - private static Plugin containsPlugin(Plugin plugin, List plugins) - { - for(Plugin p : plugins) - { - if( p.getGroupId().equals(plugin.getGroupId()) && p.getArtifactId().equals(plugin.getArtifactId())) - { - return p; - } - } - - return null; - } - - - public MavenProject buildFromRepository( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) - throws ProjectBuildingException - { - return buildFromRepository( artifact, new DefaultProjectBuilderConfiguration( localRepository, remoteRepositories ) ); - } - public MavenProject buildFromRepository( Artifact artifact, ProjectBuilderConfiguration configuration ) throws ProjectBuildingException { - MavenProject project = hm.get( artifact.getId() ); - - if ( project != null ) - { - return project; - } - if ( !artifact.getType().equals( "pom" ) ) { artifact = repositorySystem.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ); @@ -346,62 +247,24 @@ public class DefaultMavenProjectBuilder { throw new ProjectBuildingException( artifact.getId(), "Error resolving project artifact.", e ); } - DomainModel domainModel; - try - { - domainModel = build( "unknown", artifact.getFile(), configuration ); - } - catch ( IOException e ) - { - throw new ProjectBuildingException( artifact.getId(), "Error reading project artifact.", e ); - } - List projectProfiles; - Properties props = new Properties(); - props.putAll( configuration.getExecutionProperties() ); - // props.putAll(configuration.getUserProperties()); + return build( artifact.getFile(), configuration ); + } - try - { - projectProfiles = DefaultProfileManager.getActiveProfilesFrom( configuration.getGlobalProfileManager(), props, domainModel.getModel() ); - } - catch ( ProfileActivationException e ) - { - throw new ProjectBuildingException( "", "Failed to activate pom profiles." ); - } + // This is used by the SITE plugin. + public MavenProject build( File project, ArtifactRepository localRepository, ProfileManager profileManager ) + throws ProjectBuildingException + { + ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ).setGlobalProfileManager( profileManager ); - try - { - for ( Profile p : projectProfiles ) - { - logger.debug( "Merging profile into model (buildFromRepository): Model = " + domainModel.getId() + ", Profile = " + p.getId() ); - } + return build( project, configuration ); + } - domainModel = ProcessorContext.mergeProfilesIntoModel( projectProfiles, domainModel ); - } - catch ( IOException e ) - { - throw new ProjectBuildingException( "", "" ); - } - - try - { - Model model = ProcessorContext.processManagementNodes( interpolateDomainModel( domainModel, configuration, artifact.getFile() ) ); - project = this.fromDomainModelToMavenProject( model, domainModel.getParentFile(), configuration, artifact.getFile() ); - } - catch ( IOException e ) - { - throw new ProjectBuildingException( "", "" ); - } - - project.setActiveProfiles( projectProfiles ); - artifact.setFile( artifact.getFile() ); - project.setVersion( artifact.getVersion() ); - - hm.put( artifact.getId(), project ); - - return project; - } + public MavenProject buildFromRepository( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) + throws ProjectBuildingException + { + return buildFromRepository( artifact, new DefaultProjectBuilderConfiguration( localRepository, remoteRepositories ) ); + } /** * This is used for pom-less execution like running archetype:generate. @@ -440,27 +303,86 @@ public class DefaultMavenProjectBuilder Artifact pomArtifact = repositorySystem.createProjectArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion() ); pomArtifact.setFile( pomFile ); - ArtifactResolutionRequest request = new ArtifactResolutionRequest() - .setArtifact( pomArtifact ) - .setArtifactDependencies( project.getDependencyArtifacts() ) - .setLocalRepository( configuration.getLocalRepository() ) - .setRemoteRepostories( project.getRemoteArtifactRepositories() ) - .setManagedVersionMap( project.getManagedVersionMap() ); - + ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact( pomArtifact ).setArtifactDependencies( project.getDependencyArtifacts() ) + .setLocalRepository( configuration.getLocalRepository() ).setRemoteRepostories( project.getRemoteArtifactRepositories() ).setManagedVersionMap( project.getManagedVersionMap() ); + ArtifactResolutionResult result = repositorySystem.resolve( request ); if ( result.hasExceptions() ) { Exception e = result.getExceptions().get( 0 ); - throw new ProjectBuildingException( safeVersionlessKey( project.getGroupId(), project.getArtifactId() ), "Unable to build project due to an invalid dependency version: " + e.getMessage(), pomFile, e ); + throw new ProjectBuildingException( safeVersionlessKey( project.getGroupId(), project.getArtifactId() ), "Unable to build project due to an invalid dependency version: " + e.getMessage(), + pomFile, e ); } project.setArtifacts( result.getArtifacts() ); return new MavenProjectBuildingResult( project, result ); } - + + private static PluginExecution contains( String goal, List plugins ) + { + for ( PluginExecution pe : plugins ) + { + if ( pe.getGoals().contains( goal ) ) + { + return pe; + } + } + return null; + } + + public static void addPluginsToModel( Model target, Set plugins ) + { + List mngPlugins = ( target.getBuild().getPluginManagement() != null ) ? target.getBuild().getPluginManagement().getPlugins() : new ArrayList(); + + List pomPlugins = new ArrayList( target.getBuild().getPlugins() ); + + List lifecyclePlugins = new ArrayList(); + + for ( Plugin p : plugins ) + { + //Go ahead and add version if exists in pluginManagement - don't use default version + Plugin mngPlugin = containsPlugin( p, mngPlugins ); + if ( mngPlugin != null && mngPlugin.getVersion() != null ) + { + //System.out.println("Set version:" + p.getVersion() + ": To = " + mngPlugin.getVersion()); + p.setVersion( mngPlugin.getVersion() ); + } + + Plugin pomPlugin = containsPlugin( p, pomPlugins ); + if ( pomPlugin == null ) + { + lifecyclePlugins.add( p ); + } + else + { + PluginProcessor.copy2( p, pomPlugin, true ); + if ( p.getConfiguration() != null ) + { + System.out.println( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) p.getConfiguration(), (Xpp3Dom) pomPlugin.getConfiguration() ) ); + } + } + } + pomPlugins.addAll( lifecyclePlugins ); + target.getBuild().setPlugins( pomPlugins ); + + } + + private static Plugin containsPlugin( Plugin plugin, List plugins ) + { + for ( Plugin p : plugins ) + { + if ( p.getGroupId().equals( plugin.getGroupId() ) && p.getArtifactId().equals( plugin.getArtifactId() ) ) + { + return p; + } + } + + return null; + } + private Model interpolateDomainModel( DomainModel domainModel, ProjectBuilderConfiguration config, File projectDescriptor ) throws ProjectBuildingException { @@ -474,15 +396,14 @@ public class DefaultMavenProjectBuilder } catch ( IOException e ) { - throw new ProjectBuildingException( projectId, "", projectDescriptor, e ); } return model; } - - private MavenProject fromDomainModelToMavenProject(Model model, File parentFile, ProjectBuilderConfiguration config, File projectDescriptor) - throws InvalidProjectModelException, IOException + + private MavenProject fromDomainModelToMavenProject( Model model, File parentFile, ProjectBuilderConfiguration config, File projectDescriptor ) + throws InvalidProjectModelException, IOException { MavenProject project; String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); @@ -503,9 +424,9 @@ public class DefaultMavenProjectBuilder throw new InvalidProjectModelException( projectId, e.getMessage(), projectDescriptor, e ); } - return project; + return project; } - + private DomainModel build( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration ) throws ProjectBuildingException, IOException { @@ -515,97 +436,97 @@ public class DefaultMavenProjectBuilder List inactiveProfileIds = ( projectBuilderConfiguration != null && projectBuilderConfiguration.getGlobalProfileManager() != null && projectBuilderConfiguration .getGlobalProfileManager().getProfileActivationContext() != null ) ? projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext().getExplicitlyInactiveProfileIds() : new ArrayList(); - - ProfileManagerInfo profileInfo = new ProfileManagerInfo(projectBuilderConfiguration.getExecutionProperties(), activeProfileIds, inactiveProfileIds); - DomainModel domainModel = new DomainModel( pomFile ); - domainModel.setProjectDirectory( pomFile.getParentFile() ); - domainModel.setMostSpecialized( true ); - List domainModels = new ArrayList(); + ProfileManagerInfo profileInfo = new ProfileManagerInfo( projectBuilderConfiguration.getExecutionProperties(), activeProfileIds, inactiveProfileIds ); + DomainModel domainModel = new DomainModel( pomFile ); + domainModel.setProjectDirectory( pomFile.getParentFile() ); + domainModel.setMostSpecialized( true ); - domainModels.add( domainModel ); - ArtifactRepository localRepository = projectBuilderConfiguration.getLocalRepository(); - List remoteRepositories = projectBuilderConfiguration.getRemoteRepositories(); + List domainModels = new ArrayList(); - File parentFile = null; - int lineageCount = 0; - if ( domainModel.getParentId() != null ) + domainModels.add( domainModel ); + ArtifactRepository localRepository = projectBuilderConfiguration.getLocalRepository(); + List remoteRepositories = projectBuilderConfiguration.getRemoteRepositories(); + + File parentFile = null; + int lineageCount = 0; + if ( domainModel.getParentId() != null ) + { + List mavenParents; + MavenProject topProject = projectBuilderConfiguration.getTopLevelProjectFromReactor(); + if ( useTopLevelProjectForParent( domainModel, topProject ) ) { - List mavenParents; - MavenProject topProject = projectBuilderConfiguration.getTopLevelProjectFromReactor(); - if(useTopLevelProjectForParent(domainModel, topProject) ) - { - mavenParents = getDomainModelParentsFromLocalPath( domainModel, localRepository, remoteRepositories, topProject.getFile(), projectBuilderConfiguration ); - } - else if ( isParentLocal( domainModel.getRelativePathOfParent(), pomFile.getParentFile() ) ) - { - mavenParents = getDomainModelParentsFromLocalPath( domainModel, localRepository, remoteRepositories, pomFile.getParentFile(), projectBuilderConfiguration ); - } - else - { - mavenParents = getDomainModelParentsFromRepository( domainModel, localRepository, remoteRepositories ); - } - - if ( mavenParents.size() > 0 ) - { - DomainModel dm = (DomainModel) mavenParents.get( 0 ); - parentFile = dm.getFile(); - domainModel.setParentFile( parentFile ); - lineageCount = mavenParents.size(); - } - - domainModels.addAll( mavenParents ); + mavenParents = getDomainModelParentsFromLocalPath( domainModel, localRepository, remoteRepositories, topProject.getFile(), projectBuilderConfiguration ); + } + else if ( isParentLocal( domainModel.getRelativePathOfParent(), pomFile.getParentFile() ) ) + { + mavenParents = getDomainModelParentsFromLocalPath( domainModel, localRepository, remoteRepositories, pomFile.getParentFile(), projectBuilderConfiguration ); + } + else + { + mavenParents = getDomainModelParentsFromRepository( domainModel, localRepository, remoteRepositories ); } - domainModels.add( new DomainModel( getSuperModel(), false ) ); - List profileModels = new ArrayList(); - //Process Profiles - for(DomainModel domain : domainModels) + if ( mavenParents.size() > 0 ) { - DomainModel dm = (DomainModel) domain; - - if(!dm.getModel().getProfiles().isEmpty()) - { - Collection profiles = DefaultProfileManager.getActiveProfiles(dm.getModel().getProfiles(), profileInfo); - if(!profiles.isEmpty()) - { - for(Profile p : profiles) - { - logger.debug("Merging profile into model: Model = " + dm.getId() + ", Profile = " + p.getId() ); - } - profileModels.add(ProcessorContext.mergeProfilesIntoModel( profiles, dm )); - } - else - { - profileModels.add( dm ); - } - } - else - { - profileModels.add( dm ); - } + DomainModel dm = (DomainModel) mavenParents.get( 0 ); + parentFile = dm.getFile(); + domainModel.setParentFile( parentFile ); + lineageCount = mavenParents.size(); } - DomainModel transformedDomainModel = ProcessorContext.build(profileModels, listeners); + domainModels.addAll( mavenParents ); + } - // Lineage count is inclusive to add the POM read in itself. - transformedDomainModel.setLineageCount( lineageCount + 1 ); - transformedDomainModel.setParentFile( parentFile ); + domainModels.add( new DomainModel( getSuperModel(), false ) ); + List profileModels = new ArrayList(); + //Process Profiles + for ( DomainModel domain : domainModels ) + { + DomainModel dm = (DomainModel) domain; - return transformedDomainModel; + if ( !dm.getModel().getProfiles().isEmpty() ) + { + Collection profiles = DefaultProfileManager.getActiveProfiles( dm.getModel().getProfiles(), profileInfo ); + if ( !profiles.isEmpty() ) + { + for ( Profile p : profiles ) + { + logger.debug( "Merging profile into model: Model = " + dm.getId() + ", Profile = " + p.getId() ); + } + profileModels.add( ProcessorContext.mergeProfilesIntoModel( profiles, dm ) ); + } + else + { + profileModels.add( dm ); + } + } + else + { + profileModels.add( dm ); + } + } + + DomainModel transformedDomainModel = ProcessorContext.build( profileModels, listeners ); + + // Lineage count is inclusive to add the POM read in itself. + transformedDomainModel.setLineageCount( lineageCount + 1 ); + transformedDomainModel.setParentFile( parentFile ); + + return transformedDomainModel; } - - private static boolean useTopLevelProjectForParent(DomainModel currentModel, MavenProject topProject) throws IOException - { - if(topProject == null || currentModel.getModel().getParent() == null) - { - return false; - } - return topProject.getGroupId().equals(currentModel.getParentGroupId()) - && topProject.getArtifactId().equals(currentModel.getParentArtifactId()) - && topProject.getVersion().equals(currentModel.getParentVersion()); - + private static boolean useTopLevelProjectForParent( DomainModel currentModel, MavenProject topProject ) + throws IOException + { + if ( topProject == null || currentModel.getModel().getParent() == null ) + { + return false; + } + + return topProject.getGroupId().equals( currentModel.getParentGroupId() ) && topProject.getArtifactId().equals( currentModel.getParentArtifactId() ) + && topProject.getVersion().equals( currentModel.getParentVersion() ); + } private void validateModel( Model model, File pomFile ) @@ -683,14 +604,14 @@ public class DefaultMavenProjectBuilder } } - private List getDomainModelParentsFromRepository( DomainModel domainModel, ArtifactRepository localRepository, List remoteRepositories ) + private List getDomainModelParentsFromRepository( DomainModel domainModel, ArtifactRepository localRepository, List remoteRepositories ) throws IOException { List domainModels = new ArrayList(); String parentId = domainModel.getParentId(); - if ( parentId == null || localRepository == null) + if ( parentId == null || localRepository == null ) { return domainModels; } @@ -699,24 +620,22 @@ public class DefaultMavenProjectBuilder ArtifactResolutionRequest request = new ArtifactResolutionRequest( artifactParent, localRepository, remoteRepositories ); ArtifactResolutionResult result; - try - { - result = repositorySystem.resolve( request ); - } - catch (Exception e) - { - throw (IOException) new IOException( "The parent POM " + artifactParent - + " could not be retrieved from any repository" ).initCause( e ); - } - + try + { + result = repositorySystem.resolve( request ); + } + catch ( Exception e ) + { + throw (IOException) new IOException( "The parent POM " + artifactParent + " could not be retrieved from any repository" ).initCause( e ); + } + try { resolutionErrorHandler.throwErrors( request, result ); } catch ( ArtifactResolutionException e ) { - throw (IOException) new IOException( "The parent POM " + artifactParent - + " could not be retrieved from any repository" ).initCause( e ); + throw (IOException) new IOException( "The parent POM " + artifactParent + " could not be retrieved from any repository" ).initCause( e ); } DomainModel parentDomainModel = new DomainModel( artifactParent.getFile() ); @@ -726,7 +645,7 @@ public class DefaultMavenProjectBuilder //shane: what does this mean exactly and why does it occur logger.debug( "Parent pom ids do not match: Parent File = " + artifactParent.getFile().getAbsolutePath() + ": Child ID = " + domainModel.getId() ); - // return domainModels; + // return domainModels; } domainModels.add( parentDomainModel ); @@ -744,8 +663,8 @@ public class DefaultMavenProjectBuilder * @return * @throws IOException */ - private List getDomainModelParentsFromLocalPath( DomainModel domainModel, ArtifactRepository localRepository, List remoteRepositories, - File projectDirectory, ProjectBuilderConfiguration projectBuilderConfiguration ) + private List getDomainModelParentsFromLocalPath( DomainModel domainModel, ArtifactRepository localRepository, List remoteRepositories, File projectDirectory, + ProjectBuilderConfiguration projectBuilderConfiguration ) throws IOException { List domainModels = new ArrayList(); @@ -756,27 +675,27 @@ public class DefaultMavenProjectBuilder { return domainModels; } - + File parentFile = new File( projectDirectory, domainModel.getRelativePathOfParent() ).getCanonicalFile(); if ( parentFile.isDirectory() ) { parentFile = new File( parentFile.getAbsolutePath(), "pom.xml" ); } - MavenProject topProject = projectBuilderConfiguration.getTopLevelProjectFromReactor(); - boolean isTop = useTopLevelProjectForParent(domainModel, topProject); - DomainModel parentDomainModel = null; - if ( !isTop ) + MavenProject topProject = projectBuilderConfiguration.getTopLevelProjectFromReactor(); + boolean isTop = useTopLevelProjectForParent( domainModel, topProject ); + DomainModel parentDomainModel = null; + if ( !isTop ) { - if(!parentFile.isFile()) - { - throw new IOException( "File does not exist: File = " + parentFile.getAbsolutePath() ); - } - parentDomainModel = new DomainModel( parentFile ); - parentDomainModel.setProjectDirectory( parentFile.getParentFile() ); + if ( !parentFile.isFile() ) + { + throw new IOException( "File does not exist: File = " + parentFile.getAbsolutePath() ); + } + parentDomainModel = new DomainModel( parentFile ); + parentDomainModel.setProjectDirectory( parentFile.getParentFile() ); } else { - parentDomainModel = new DomainModel(projectBuilderConfiguration.getTopLevelProjectFromReactor().getFile()); + parentDomainModel = new DomainModel( projectBuilderConfiguration.getTopLevelProjectFromReactor().getFile() ); } if ( !parentDomainModel.matchesParentOf( domainModel ) ) @@ -798,18 +717,19 @@ public class DefaultMavenProjectBuilder domainModels.add( parentDomainModel ); if ( domainModel.getParentId() != null ) { - if(isTop) - { - if ( isParentLocal( parentDomainModel.getRelativePathOfParent(), parentFile.getParentFile() ) ) - { - domainModels.addAll( getDomainModelParentsFromLocalPath( parentDomainModel, localRepository, remoteRepositories, topProject.getFile().getParentFile(), projectBuilderConfiguration ) ); - } - else - { - domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, localRepository, remoteRepositories ) ); - } - } - else if ( isParentLocal( parentDomainModel.getRelativePathOfParent(), parentFile.getParentFile() ) ) + if ( isTop ) + { + if ( isParentLocal( parentDomainModel.getRelativePathOfParent(), parentFile.getParentFile() ) ) + { + domainModels + .addAll( getDomainModelParentsFromLocalPath( parentDomainModel, localRepository, remoteRepositories, topProject.getFile().getParentFile(), projectBuilderConfiguration ) ); + } + else + { + domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, localRepository, remoteRepositories ) ); + } + } + else if ( isParentLocal( parentDomainModel.getRelativePathOfParent(), parentFile.getParentFile() ) ) { domainModels.addAll( getDomainModelParentsFromLocalPath( parentDomainModel, localRepository, remoteRepositories, parentFile.getParentFile(), projectBuilderConfiguration ) ); } diff --git a/maven-core/src/test/java/org/apache/maven/project/TestMavenRepositorySystem.java b/maven-core/src/test/java/org/apache/maven/project/TestMavenRepositorySystem.java index 3387f24bed..f7b1d16d96 100644 --- a/maven-core/src/test/java/org/apache/maven/project/TestMavenRepositorySystem.java +++ b/maven-core/src/test/java/org/apache/maven/project/TestMavenRepositorySystem.java @@ -1,75 +1,11 @@ package org.apache.maven.project; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.List; -import java.util.Set; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ResolutionGroup; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Model; -import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.apache.maven.repository.LegacyRepositorySystem; import org.apache.maven.repository.RepositorySystem; -import org.apache.maven.repository.VersionNotFoundException; import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @Component(role = RepositorySystem.class, hint = "test") public class TestMavenRepositorySystem extends LegacyRepositorySystem { - public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) - throws ArtifactMetadataRetrievalException - { - Model model = null; - InputStreamReader r = null; - try - { - String scope = artifact.getArtifactId().substring( "scope-".length() ); - if ( "maven-test".equals( artifact.getGroupId() ) ) - { - String name = "/projects/scope/transitive-" + scope + "-dep.xml"; - r = new InputStreamReader( getClass().getResourceAsStream( name ) ); - MavenXpp3Reader reader = new MavenXpp3Reader(); - model = reader.read( r ); - } - else - { - model = new Model(); - } - model.setGroupId( artifact.getGroupId() ); - model.setArtifactId( artifact.getArtifactId() ); - } - catch ( IOException e ) - { - throw new ArtifactMetadataRetrievalException( e ); - } - catch ( XmlPullParserException e ) - { - throw new ArtifactMetadataRetrievalException( e ); - } - finally - { - IOUtil.close( r ); - } - - Set artifacts; - try - { - artifacts = createArtifacts( model.getDependencies(), artifact.getScope(), null, null ); - } - catch ( VersionNotFoundException e ) - { - InvalidDependencyVersionException ee = new InvalidDependencyVersionException(e.getProjectId(), e.getDependency(),e.getPomFile(), e.getCauseException() ); - - throw new ArtifactMetadataRetrievalException( ee ); - } - - return new ResolutionGroup( artifact, artifacts, remoteRepositories ); - } } diff --git a/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java b/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java index 4fe5700e07..923139d5cd 100644 --- a/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java @@ -81,7 +81,7 @@ public class MavenMetadataSourceTest MavenProject project = new MavenProject( new Model() ); - Set result = repositorySystem.createArtifacts( deps, null, dependencyFilter, project ); + Set result = project.createArtifacts( dependencyFilter ); for ( Iterator it = result.iterator(); it.hasNext(); ) { @@ -96,6 +96,8 @@ public class MavenMetadataSourceTest } } + //TODO: restore these if it makes sense + /* public void testShouldUseCompileScopeIfDependencyScopeEmpty() throws Exception { @@ -112,9 +114,9 @@ public class MavenMetadataSourceTest model.addDependency( dep ); - MavenProject project = new MavenProject( model ); + MavenProject project = new MavenProject( model, repositorySystem ); - project.setArtifacts( repositorySystem.createArtifacts( project.getDependencies(), null, null, project ) ); + project.setArtifacts( project.createArtifacts( null ) ); String key = ArtifactUtils.versionlessKey( groupId, artifactId ); @@ -159,13 +161,13 @@ public class MavenMetadataSourceTest model.setDependencyManagement( depMgmt ); - MavenProject project = new MavenProject( model ); + MavenProject project = new MavenProject( model, repositorySystem ); TestModelDefaultsInjector injector = new TestModelDefaultsInjector(); injector.injectDefaults( model ); - - project.setArtifacts( repositorySystem.createArtifacts( project.getDependencies(), null, null, project ) ); + + project.setArtifacts( project.createArtifacts( null ) ); String key = ArtifactUtils.versionlessKey( groupId, artifactId ); @@ -182,5 +184,6 @@ public class MavenMetadataSourceTest //check for back-propagation of default scope. assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_TEST, dep.getScope() ); } + */ } diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index 1cb163fd07..69557b30dc 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -49,14 +49,6 @@ org.apache.maven.wagon wagon-http-lightweight - - org.apache.maven.wagon - wagon-ssh - - - org.apache.maven.wagon - wagon-ssh-external - org.apache.maven.wagon wagon-file 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 899b49c7b6..def6a3f43f 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 @@ -38,7 +38,6 @@ import org.apache.maven.lifecycle.LifecycleExecutor; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; -import org.apache.maven.plugin.PluginLoaderException; import org.apache.maven.plugin.PluginManager; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; @@ -269,18 +268,6 @@ public class MavenEmbedder } } - /** - * mkleint: protected so that IDE integrations can selectively allow downloading artifacts - * from remote repositories (if they prohibit by default on project loading) - * @throws PluginLoaderException - protected void verifyPlugin( Plugin plugin, MavenProject project ) - throws ComponentLookupException, PluginLoaderException - { - MavenSession session = new MavenSession( request ); - pluginManager.loadPlugin( plugin, project, session ); - } - */ - // ---------------------------------------------------------------------- // Project // ---------------------------------------------------------------------- diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java index 1dbf92c40b..ba95f1f9c9 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java @@ -90,8 +90,6 @@ public class DefaultMavenExecutionRequestPopulator toolchains( request, configuration ); - artifactTransferMechanism( request, configuration ); - profileManager( request, configuration ); processSettings( request, configuration ); @@ -342,27 +340,6 @@ public class DefaultMavenExecutionRequestPopulator // Artifact Transfer Mechanism // ------------------------------------------------------------------------ - private void artifactTransferMechanism( MavenExecutionRequest request, Configuration configuration ) - throws MavenEmbedderException - { - // ------------------------------------------------------------------------ - // Artifact Transfer Mechanism - // ------------------------------------------------------------------------ - - if ( request.isOffline() ) - { - repositorySystem.setOnline( false ); - } - else if ( ( request.getSettings() != null ) && request.getSettings().isOffline() ) - { - repositorySystem.setOnline( false ); - } - else - { - repositorySystem.setOnline( true ); - } - } - public ArtifactRepository createLocalRepository( MavenExecutionRequest request, Settings settings, Configuration configuration ) throws MavenEmbedderException { diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/DomainModel.java b/maven-model-builder/src/main/java/org/apache/maven/model/DomainModel.java index ecdf683fbe..870fd65c6c 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/DomainModel.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/DomainModel.java @@ -39,7 +39,7 @@ public class DomainModel protected Model model; - public Model getModel() throws IOException + public Model getModel() { return model; } diff --git a/maven-repository/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java b/maven-repository/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java index 51e1cf3931..a1cee1d467 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java @@ -34,6 +34,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.resolver.ArtifactCollector; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolver; @@ -76,6 +77,9 @@ public class LegacyRepositorySystem @Requirement private ArtifactRepositoryLayout defaultArtifactRepositoryLayout; + @Requirement + private ArtifactCollector artifactCollector; + @Requirement private MirrorBuilder mirrorBuilder; @@ -157,118 +161,15 @@ public class LegacyRepositorySystem return artifactFactory.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), versionRange ); } - /** - * @return {@link Set} < {@link Artifact} > - * @todo desperately needs refactoring. It's just here because it's implementation is - * maven-project specific - */ - public Set createArtifacts( List dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenRepositoryWrapper reactor ) - throws VersionNotFoundException - { - return createArtifacts( artifactFactory, dependencies, inheritedScope, dependencyFilter, reactor ); - } - - @Deprecated - public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenRepositoryWrapper reactor ) - throws VersionNotFoundException - { - Set projectArtifacts = new LinkedHashSet( dependencies.size() ); - - for ( Iterator i = dependencies.iterator(); i.hasNext(); ) - { - Dependency d = i.next(); - - String scope = d.getScope(); - - if ( StringUtils.isEmpty( scope ) ) - { - scope = Artifact.SCOPE_COMPILE; - - d.setScope( scope ); - } - - VersionRange versionRange; - - //TODO: how does a poorly specified range turn into a VersionNotFoundException? - try - { - versionRange = VersionRange.createFromVersionSpec( d.getVersion() ); - } - catch ( InvalidVersionSpecificationException e ) - { - throw new VersionNotFoundException( reactor.getId(), d, reactor.getFile(), e ); - } - - Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), d.getClassifier(), scope, inheritedScope, d.isOptional() ); - - if ( Artifact.SCOPE_SYSTEM.equals( scope ) ) - { - artifact.setFile( new File( d.getSystemPath() ) ); - } - - ArtifactFilter artifactFilter = dependencyFilter; - - if ( ( artifact != null ) && ( ( artifactFilter == null ) || artifactFilter.include( artifact ) ) ) - { - if ( ( d.getExclusions() != null ) && !d.getExclusions().isEmpty() ) - { - List exclusions = new ArrayList(); - for ( Iterator j = d.getExclusions().iterator(); j.hasNext(); ) - { - Exclusion e = j.next(); - exclusions.add( e.getGroupId() + ":" + e.getArtifactId() ); - } - - ArtifactFilter newFilter = new ExcludesArtifactFilter( exclusions ); - - if ( artifactFilter != null ) - { - AndArtifactFilter filter = new AndArtifactFilter(); - filter.add( artifactFilter ); - filter.add( newFilter ); - artifactFilter = filter; - } - else - { - artifactFilter = newFilter; - } - } - - artifact.setDependencyFilter( artifactFilter ); - - if ( reactor != null ) - { - artifact = reactor.find( artifact ); - } - - projectArtifacts.add( artifact ); - } - } - - return projectArtifacts; - } - public ArtifactRepository buildArtifactRepository( Repository repo ) throws InvalidRepositoryException { if ( repo != null ) { String id = repo.getId(); + String url = repo.getUrl(); - /* - MNG-4050: Temporarily disabled this check since it is breaking the bootstrap unit tests on commons-parent pom - */ - /* - if ( id == null || id.trim().length() < 1 ) - { - throw new InvalidRepositoryException( "Repository ID must not be empty (URL is: " + url + ").", url ); - } - - if ( url == null || url.trim().length() < 1 ) - { - throw new InvalidRepositoryException( "Repository URL must not be empty (ID is: " + id + ").", id ); - } - */ + ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repo.getSnapshots() ); ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repo.getReleases() ); @@ -471,6 +372,18 @@ public class LegacyRepositorySystem public MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request ) { + +// ArtifactResolutionResult collect( Set artifacts, +// Artifact originatingArtifact, +// Map managedVersions, +// ArtifactRepository localRepository, +// List remoteRepositories, +// ArtifactMetadataSource source, +// ArtifactFilter filter, +// List listeners, +// List conflictResolvers ) + +// ArtifactResolutionResult result = artifactCollector. return null; } } diff --git a/maven-repository/src/main/java/org/apache/maven/repository/RepositorySystem.java b/maven-repository/src/main/java/org/apache/maven/repository/RepositorySystem.java index ab8afe3852..2c00f534a1 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/RepositorySystem.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/RepositorySystem.java @@ -25,7 +25,6 @@ import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; import org.apache.maven.model.Repository; @@ -57,14 +56,9 @@ public interface RepositorySystem Artifact createDependencyArtifact( Dependency dependency ); - //REMOVE - // This will disappear when we actually deal with resolving a root dependency and its dependencies. This is used everywhere because of that - // deficiency - Set createArtifacts( List dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenRepositoryWrapper reactor ) - throws VersionNotFoundException; - - // Repository creation - + //TODO: this needs a project to do anything useful + //Set createArtifacts(); + // maven model ArtifactRepository buildArtifactRepository( Repository repository ) throws InvalidRepositoryException; @@ -97,13 +91,7 @@ public interface RepositorySystem * @return */ MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request ); - - //REMOVE - // Network enablement: this needs to go as we will know at a higher level from the embedder if the system is offline or not, we should not have to - // deal with this here. - void setOnline( boolean online ); - boolean isOnline(); - + //REMOVE // These should be associated with repositories and the repositories should be examine as part of metadatda and // artifact resolution. So these methods should also not be here. diff --git a/pom.xml b/pom.xml index 4cfd4151b1..7972d29188 100644 --- a/pom.xml +++ b/pom.xml @@ -22,13 +22,16 @@ under the License. 4.0.0 + + org.apache.maven maven 3.0-SNAPSHOT pom @@ -294,16 +297,6 @@ under the License. wagon-http-lightweight ${wagonVersion} - - org.apache.maven.wagon - wagon-ssh - ${wagonVersion} - - - org.apache.maven.wagon - wagon-ssh-external - ${wagonVersion} - org.apache.maven.doxia