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
This commit is contained in:
Jason van Zyl 2009-05-08 03:24:55 +00:00
parent 51c1cb584c
commit a73c5abc9c
21 changed files with 382 additions and 713 deletions

View File

@ -23,11 +23,8 @@
<artifactId>maven</artifactId> <artifactId>maven</artifactId>
<version>3.0-SNAPSHOT</version> <version>3.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>apache-maven</artifactId> <artifactId>apache-maven</artifactId>
<name>Maven Distribution</name> <name>Maven Distribution</name>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.apache.maven</groupId> <groupId>org.apache.maven</groupId>
@ -58,14 +55,6 @@
<groupId>org.apache.maven.wagon</groupId> <groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId> <artifactId>wagon-http-lightweight</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh-external</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.apache.maven.wagon</groupId> <groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId> <artifactId>wagon-file</artifactId>

View File

@ -38,9 +38,7 @@ import org.apache.maven.artifact.versioning.VersionRange;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a> * @author Jason van Zyl
* @version $Id$
* @todo this should possibly be replaced by type handler
*/ */
public class DefaultArtifact public class DefaultArtifact
implements Artifact implements Artifact

View File

@ -180,9 +180,8 @@ public class DefaultArtifactFactory
String inheritedScope, String inheritedScope,
boolean optional ) boolean optional )
{ {
// TODO: can refactor - inherited artifactScope calculation belongs in the collector, use artifactScope handler
String desiredScope = Artifact.SCOPE_RUNTIME; String desiredScope = Artifact.SCOPE_RUNTIME;
if ( inheritedScope == null ) if ( inheritedScope == null )
{ {
desiredScope = scope; desiredScope = scope;

View File

@ -34,19 +34,7 @@ import org.apache.maven.artifact.versioning.ArtifactVersion;
*/ */
public interface ArtifactMetadataSource public interface ArtifactMetadataSource
{ {
String ROLE = ArtifactMetadataSource.class.getName(); ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
ResolutionGroup retrieve( Artifact artifact,
ArtifactRepository localRepository,
List<ArtifactRepository> 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<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException; throws ArtifactMetadataRetrievalException;
/** /**
@ -61,9 +49,7 @@ public interface ArtifactMetadataSource
* @throws ArtifactMetadataRetrievalException * @throws ArtifactMetadataRetrievalException
* in case of error while retrieving repository metadata from the repository. * in case of error while retrieving repository metadata from the repository.
*/ */
List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException; throws ArtifactMetadataRetrievalException;
/** /**
@ -79,7 +65,6 @@ public interface ArtifactMetadataSource
* @throws ArtifactMetadataRetrievalException * @throws ArtifactMetadataRetrievalException
* in case of error while retrieving repository metadata from the repository. * in case of error while retrieving repository metadata from the repository.
*/ */
List<ArtifactVersion> retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact, List<ArtifactVersion> retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact, ArtifactRepository localRepository, ArtifactRepository remoteRepository )
ArtifactRepository localRepository, throws ArtifactMetadataRetrievalException;
ArtifactRepository remoteRepository ) throws ArtifactMetadataRetrievalException;
} }

View File

@ -19,12 +19,6 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
/**
* Specifies the repository used for artifact handling.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public interface ArtifactRepository public interface ArtifactRepository
{ {
String pathOf( Artifact artifact ); String pathOf( Artifact artifact );
@ -59,9 +53,11 @@ public interface ArtifactRepository
String getKey(); String getKey();
boolean isUniqueVersion();
void setBlacklisted( boolean blackListed ); void setBlacklisted( boolean blackListed );
boolean isBlacklisted(); boolean isBlacklisted();
// New interface methods for the repository system.
Artifact find( Artifact artifact );
} }

View File

@ -31,6 +31,7 @@ import org.apache.maven.wagon.repository.Repository;
* @author <a href="michal.maczka@dimatics.com">Michal Maczka </a> * @author <a href="michal.maczka@dimatics.com">Michal Maczka </a>
* @version $Id$ * @version $Id$
*/ */
//TODO: this needs to be decoupled from Wagon
public class DefaultArtifactRepository public class DefaultArtifactRepository
extends Repository extends Repository
implements ArtifactRepository implements ArtifactRepository
@ -41,8 +42,6 @@ public class DefaultArtifactRepository
private ArtifactRepositoryPolicy releases; private ArtifactRepositoryPolicy releases;
private boolean uniqueVersion = true;
private boolean blacklisted; private boolean blacklisted;
/** /**
@ -69,7 +68,6 @@ public class DefaultArtifactRepository
{ {
super( id, url ); super( id, url );
this.layout = layout; this.layout = layout;
this.uniqueVersion = uniqueVersion;
} }
/** /**
@ -155,11 +153,6 @@ public class DefaultArtifactRepository
return getId(); return getId();
} }
public boolean isUniqueVersion()
{
return uniqueVersion;
}
public boolean isBlacklisted() public boolean isBlacklisted()
{ {
return blacklisted; return blacklisted;
@ -184,4 +177,9 @@ public class DefaultArtifactRepository
return sb.toString(); return sb.toString();
} }
public Artifact find( Artifact artifact )
{
return null;
}
} }

View File

@ -512,13 +512,6 @@ public class DefaultArtifactCollector
artifact.selectVersion( version.toString() ); artifact.selectVersion( version.toString() );
fireEvent( ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, child ); 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() ) ); while( !childKey.equals( child.getKey() ) );

View File

@ -455,7 +455,6 @@ public class DefaultArtifactResolver
} }
catch ( ArtifactMetadataRetrievalException e ) catch ( ArtifactMetadataRetrievalException e )
{ {
e.printStackTrace();
// need to add metadata resolution exception // need to add metadata resolution exception
return result; return result;
} }

View File

@ -95,10 +95,8 @@ public class SnapshotTransformation
if ( artifact.isSnapshot() ) if ( artifact.isSnapshot() )
{ {
Snapshot snapshot = new Snapshot(); 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 // we update the build number anyway so that it doesn't get lost. It requires the timestamp to take effect
try try

View File

@ -508,6 +508,36 @@ public class DefaultLifecycleExecutor
return mojoDescriptor; 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() public void initialize()
throws InitializationException throws InitializationException
@ -620,13 +650,13 @@ public class DefaultLifecycleExecutor
public Set<Plugin> populateDefaultConfigurationForPlugins( Set<Plugin> plugins, MavenProject project, ArtifactRepository localRepository ) public Set<Plugin> populateDefaultConfigurationForPlugins( Set<Plugin> plugins, MavenProject project, ArtifactRepository localRepository )
throws LifecycleExecutionException throws LifecycleExecutionException
{ {
for( Plugin p: plugins ) for( Plugin p : plugins )
{ {
for( PluginExecution e : p.getExecutions() ) 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 ) ); 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 ) public Xpp3Dom getDefaultPluginConfiguration( String groupId, String artifactId, String version, String goal, MavenProject project, ArtifactRepository localRepository )
throws LifecycleExecutionException 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 ) public Xpp3Dom getMojoConfiguration( MojoDescriptor mojoDescriptor )

View File

@ -54,7 +54,6 @@ import org.apache.maven.project.DuplicateArtifactAttachmentException;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.VersionNotFoundException;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.annotations.Component; 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 ); 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 ) catch ( PluginVersionResolutionException e )
{ {
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e ); throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
@ -588,31 +583,16 @@ public class DefaultPluginManager
{ {
MavenProject project = session.getCurrentProject(); 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() ); 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 ); ArtifactFilter filter = new ScopeArtifactFilter( scope );
ArtifactResolutionRequest request = new ArtifactResolutionRequest() ArtifactResolutionRequest request = new ArtifactResolutionRequest()
.setArtifact( artifact ) .setArtifact( artifact )
// Here the root is not resolved because we are presumably working with a project locally.
.setResolveRoot( false ) .setResolveRoot( false )
.setArtifactDependencies( project.getDependencyArtifacts() ) .setResolveTransitively( true )
//.setArtifactDependencies( project.getDependencyArtifacts() )
.setLocalRepository( session.getLocalRepository() ) .setLocalRepository( session.getLocalRepository() )
.setRemoteRepostories( project.getRemoteArtifactRepositories() ) .setRemoteRepostories( project.getRemoteArtifactRepositories() )
.setManagedVersionMap( project.getManagedVersionMap() ) .setManagedVersionMap( project.getManagedVersionMap() )
@ -622,6 +602,7 @@ public class DefaultPluginManager
resolutionErrorHandler.throwErrors( request, result ); resolutionErrorHandler.throwErrors( request, result );
//TODO: this is wrong
project.setArtifacts( result.getArtifacts() ); project.setArtifacts( result.getArtifacts() );
ArtifactRepository localRepository = session.getLocalRepository(); ArtifactRepository localRepository = session.getLocalRepository();
@ -698,11 +679,6 @@ public class DefaultPluginManager
public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, MavenProject project, ArtifactRepository localRepository ) public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, MavenProject project, ArtifactRepository localRepository )
throws PluginLoaderException throws PluginLoaderException
{ {
if ( plugin.getVersion() == null )
{
throw new IllegalArgumentException( "plugin.version: null" );
}
PluginDescriptor pluginDescriptor = loadPlugin( plugin, project, localRepository ); PluginDescriptor pluginDescriptor = loadPlugin( plugin, project, localRepository );
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal ); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );

View File

@ -20,7 +20,6 @@ import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -71,26 +70,26 @@ public class DefaultMavenProjectBuilder
{ {
@Requirement @Requirement
private Logger logger; private Logger logger;
@Requirement @Requirement
private ModelValidator validator; private ModelValidator validator;
@Requirement @Requirement
private LifecycleExecutor lifecycle; private LifecycleExecutor lifecycle;
@Requirement @Requirement
private RepositorySystem repositorySystem; private RepositorySystem repositorySystem;
@Requirement @Requirement
List<ModelEventListener> listeners; List<ModelEventListener> listeners;
@Requirement
private Interpolator interpolator;
@Requirement
private ResolutionErrorHandler resolutionErrorHandler;
private static HashMap<String, MavenProject> hm = new HashMap<String, MavenProject>(); @Requirement
private Interpolator interpolator;
@Requirement
private ResolutionErrorHandler resolutionErrorHandler;
//private static HashMap<String, MavenProject> hm = new HashMap<String, MavenProject>();
private MavenProject superProject; private MavenProject superProject;
@ -98,100 +97,85 @@ public class DefaultMavenProjectBuilder
// MavenProjectBuilder Implementation // 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 ) public MavenProject build( File pomFile, ProjectBuilderConfiguration configuration )
throws ProjectBuildingException throws ProjectBuildingException
{ {
//Do inheritance
DomainModel domainModel; DomainModel domainModel;
try
{
domainModel = build( "unknown", pomFile, configuration );
}
catch (IOException e)
{
throw new ProjectBuildingException("", "", e);
}
//Profiles
List<Profile> projectProfiles;
Properties props = new Properties();
props.putAll(configuration.getExecutionProperties());
try try
{ {
projectProfiles = DefaultProfileManager.getActiveProfilesFrom(configuration.getGlobalProfileManager(), props, domainModel.getModel() ); domainModel = build( "unknown", pomFile, configuration );
}
catch ( ProfileActivationException e )
{
throw new ProjectBuildingException( "", "Failed to activate pom profiles.");
}
try
{
List<Profile> externalProfiles = new ArrayList<Profile>();
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 ) catch ( IOException e )
{ {
throw new ProjectBuildingException("", ""); throw new ProjectBuildingException( "", "", e );
} }
//Profiles
List<Profile> 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<Profile> externalProfiles = new ArrayList<Profile>();
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 //Interpolation & Management
MavenProject project; MavenProject project;
try try
{ {
Model model = interpolateDomainModel( domainModel, configuration, pomFile ); Model model = interpolateDomainModel( domainModel, configuration, pomFile );
List<Plugin> plns = new ArrayList<Plugin>(); Set<Plugin> plugins = lifecycle.getPluginsBoundByDefaultToAllLifecycles( model.getPackaging() );
Set<Plugin> plugins = lifecycle.getPluginsBoundByDefaultToAllLifecycles(model.getPackaging()); addPluginsToModel( model, plugins );
ProcessorContext.processManagementNodes( model );
project = this.fromDomainModelToMavenProject( model, domainModel.getParentFile(), configuration, pomFile );
Set<Plugin> pluginsFromProject = new HashSet<Plugin>();
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<Plugin> pln = new ArrayList<Plugin>();
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: // Merge the various sources for mojo configuration:
// 1. default values from mojo descriptor // 1. default values from mojo descriptor
// 2. POM values from per-plugin configuration // 2. POM values from per-plugin configuration
// 3. POM values from per-execution configuration // 3. POM values from per-execution configuration
// These configuration sources are given in increasing order of dominance. // These configuration sources are given in increasing order of dominance.
Set<Plugin> pl = lifecycle.populateDefaultConfigurationForPlugins(new HashSet<Plugin>(pln), Set<Plugin> processedPlugins = lifecycle.populateDefaultConfigurationForPlugins( pluginsFromProject, project, configuration.getLocalRepository() );
project, configuration.getLocalRepository());
for ( Plugin buildPlugin : processedPlugins )
for ( Plugin buildPlugin : pl )
{ {
Xpp3Dom dom = (Xpp3Dom) buildPlugin.getConfiguration(); Xpp3Dom dom = (Xpp3Dom) buildPlugin.getConfiguration();
Plugin x = containsPlugin( buildPlugin, project.getModel().getBuild().getPlugins() ); Plugin x = containsPlugin( buildPlugin, project.getModel().getBuild().getPlugins() );
@ -210,30 +194,27 @@ public class DefaultMavenProjectBuilder
PluginExecution pe = contains( g, x.getExecutions() ); PluginExecution pe = contains( g, x.getExecutions() );
if ( pe != null ) if ( pe != null )
{ {
Xpp3Dom dom2 = Xpp3Dom dom2 = Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) pe.getConfiguration(), (Xpp3Dom) e.getConfiguration() );
Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) pe.getConfiguration(),
(Xpp3Dom) e.getConfiguration() );
e.setConfiguration( dom2 ); e.setConfiguration( dom2 );
} }
} }
} }
} }
} }
project.getModel().getBuild().setPlugins(new ArrayList<Plugin>(pl)); project.getModel().getBuild().setPlugins( new ArrayList<Plugin>( processedPlugins ) );
} }
catch (IOException e) catch ( IOException e )
{ {
throw new ProjectBuildingException("", ""); throw new ProjectBuildingException( "", "" );
} }
catch (LifecycleExecutionException e) catch ( LifecycleExecutionException e )
{ {
e.printStackTrace(); throw new ProjectBuildingException( "", e.getMessage() );
throw new ProjectBuildingException("",e.getMessage()); }
}
project.setActiveProfiles( projectProfiles ); //project.setActiveProfiles( projectProfiles );
Build build = project.getBuild(); Build build = project.getBuild();
// NOTE: setting this script-source root before path translation, because // NOTE: setting this script-source root before path translation, because
// the plugin tools compose basedir and scriptSourceRoot into a single file. // the plugin tools compose basedir and scriptSourceRoot into a single file.
@ -241,95 +222,15 @@ public class DefaultMavenProjectBuilder
project.addCompileSourceRoot( build.getSourceDirectory() ); project.addCompileSourceRoot( build.getSourceDirectory() );
project.addTestCompileSourceRoot( build.getTestSourceDirectory() ); project.addTestCompileSourceRoot( build.getTestSourceDirectory() );
project.setFile( pomFile ); project.setFile( pomFile );
setBuildOutputDirectoryOnParent( project ); setBuildOutputDirectoryOnParent( project );
hm.put( ArtifactUtils.artifactId( project.getGroupId(), project.getArtifactId(), "pom", project.getVersion() ), project );
return project; return project;
} }
private static PluginExecution contains(String goal, List<PluginExecution> plugins)
{
for(PluginExecution pe : plugins)
{
if(pe.getGoals().contains(goal))
{
return pe;
}
}
return null;
}
public static void addPluginsToModel( Model target, Set<Plugin> plugins )
{
List<Plugin> mngPlugins = (target.getBuild().getPluginManagement() != null)
? target.getBuild().getPluginManagement().getPlugins() : new ArrayList<Plugin>();
List<Plugin> pomPlugins = new ArrayList<Plugin>(target.getBuild().getPlugins());
List<Plugin> lifecyclePlugins = new ArrayList<Plugin>();
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<Plugin> 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<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository )
throws ProjectBuildingException
{
return buildFromRepository( artifact, new DefaultProjectBuilderConfiguration( localRepository, remoteRepositories ) );
}
public MavenProject buildFromRepository( Artifact artifact, ProjectBuilderConfiguration configuration ) public MavenProject buildFromRepository( Artifact artifact, ProjectBuilderConfiguration configuration )
throws ProjectBuildingException throws ProjectBuildingException
{ {
MavenProject project = hm.get( artifact.getId() );
if ( project != null )
{
return project;
}
if ( !artifact.getType().equals( "pom" ) ) if ( !artifact.getType().equals( "pom" ) )
{ {
artifact = repositorySystem.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ); 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 ); 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<Profile> projectProfiles; return build( artifact.getFile(), configuration );
Properties props = new Properties(); }
props.putAll( configuration.getExecutionProperties() );
// props.putAll(configuration.getUserProperties());
try // This is used by the SITE plugin.
{ public MavenProject build( File project, ArtifactRepository localRepository, ProfileManager profileManager )
projectProfiles = DefaultProfileManager.getActiveProfilesFrom( configuration.getGlobalProfileManager(), props, domainModel.getModel() ); throws ProjectBuildingException
} {
catch ( ProfileActivationException e ) ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ).setGlobalProfileManager( profileManager );
{
throw new ProjectBuildingException( "", "Failed to activate pom profiles." );
}
try return build( project, configuration );
{ }
for ( Profile p : projectProfiles )
{
logger.debug( "Merging profile into model (buildFromRepository): Model = " + domainModel.getId() + ", Profile = " + p.getId() );
}
domainModel = ProcessorContext.mergeProfilesIntoModel( projectProfiles, domainModel ); public MavenProject buildFromRepository( Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository )
} throws ProjectBuildingException
catch ( IOException e ) {
{ return buildFromRepository( artifact, new DefaultProjectBuilderConfiguration( localRepository, remoteRepositories ) );
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;
}
/** /**
* This is used for pom-less execution like running archetype:generate. * 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() ); Artifact pomArtifact = repositorySystem.createProjectArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion() );
pomArtifact.setFile( pomFile ); pomArtifact.setFile( pomFile );
ArtifactResolutionRequest request = new ArtifactResolutionRequest() ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact( pomArtifact ).setArtifactDependencies( project.getDependencyArtifacts() )
.setArtifact( pomArtifact ) .setLocalRepository( configuration.getLocalRepository() ).setRemoteRepostories( project.getRemoteArtifactRepositories() ).setManagedVersionMap( project.getManagedVersionMap() );
.setArtifactDependencies( project.getDependencyArtifacts() )
.setLocalRepository( configuration.getLocalRepository() )
.setRemoteRepostories( project.getRemoteArtifactRepositories() )
.setManagedVersionMap( project.getManagedVersionMap() );
ArtifactResolutionResult result = repositorySystem.resolve( request ); ArtifactResolutionResult result = repositorySystem.resolve( request );
if ( result.hasExceptions() ) if ( result.hasExceptions() )
{ {
Exception e = result.getExceptions().get( 0 ); 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() ); project.setArtifacts( result.getArtifacts() );
return new MavenProjectBuildingResult( project, result ); return new MavenProjectBuildingResult( project, result );
} }
private static PluginExecution contains( String goal, List<PluginExecution> plugins )
{
for ( PluginExecution pe : plugins )
{
if ( pe.getGoals().contains( goal ) )
{
return pe;
}
}
return null;
}
public static void addPluginsToModel( Model target, Set<Plugin> plugins )
{
List<Plugin> mngPlugins = ( target.getBuild().getPluginManagement() != null ) ? target.getBuild().getPluginManagement().getPlugins() : new ArrayList<Plugin>();
List<Plugin> pomPlugins = new ArrayList<Plugin>( target.getBuild().getPlugins() );
List<Plugin> lifecyclePlugins = new ArrayList<Plugin>();
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<Plugin> 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 ) private Model interpolateDomainModel( DomainModel domainModel, ProjectBuilderConfiguration config, File projectDescriptor )
throws ProjectBuildingException throws ProjectBuildingException
{ {
@ -474,15 +396,14 @@ public class DefaultMavenProjectBuilder
} }
catch ( IOException e ) catch ( IOException e )
{ {
throw new ProjectBuildingException( projectId, "", projectDescriptor, e ); throw new ProjectBuildingException( projectId, "", projectDescriptor, e );
} }
return model; return model;
} }
private MavenProject fromDomainModelToMavenProject(Model model, File parentFile, ProjectBuilderConfiguration config, File projectDescriptor) private MavenProject fromDomainModelToMavenProject( Model model, File parentFile, ProjectBuilderConfiguration config, File projectDescriptor )
throws InvalidProjectModelException, IOException throws InvalidProjectModelException, IOException
{ {
MavenProject project; MavenProject project;
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
@ -503,9 +424,9 @@ public class DefaultMavenProjectBuilder
throw new InvalidProjectModelException( projectId, e.getMessage(), projectDescriptor, e ); throw new InvalidProjectModelException( projectId, e.getMessage(), projectDescriptor, e );
} }
return project; return project;
} }
private DomainModel build( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration ) private DomainModel build( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration )
throws ProjectBuildingException, IOException throws ProjectBuildingException, IOException
{ {
@ -515,97 +436,97 @@ public class DefaultMavenProjectBuilder
List<String> inactiveProfileIds = ( projectBuilderConfiguration != null && projectBuilderConfiguration.getGlobalProfileManager() != null && projectBuilderConfiguration List<String> inactiveProfileIds = ( projectBuilderConfiguration != null && projectBuilderConfiguration.getGlobalProfileManager() != null && projectBuilderConfiguration
.getGlobalProfileManager().getProfileActivationContext() != null ) ? projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext().getExplicitlyInactiveProfileIds() .getGlobalProfileManager().getProfileActivationContext() != null ) ? projectBuilderConfiguration.getGlobalProfileManager().getProfileActivationContext().getExplicitlyInactiveProfileIds()
: new ArrayList<String>(); : new ArrayList<String>();
ProfileManagerInfo profileInfo = new ProfileManagerInfo(projectBuilderConfiguration.getExecutionProperties(), activeProfileIds, inactiveProfileIds);
DomainModel domainModel = new DomainModel( pomFile );
domainModel.setProjectDirectory( pomFile.getParentFile() );
domainModel.setMostSpecialized( true );
List<DomainModel> domainModels = new ArrayList<DomainModel>(); ProfileManagerInfo profileInfo = new ProfileManagerInfo( projectBuilderConfiguration.getExecutionProperties(), activeProfileIds, inactiveProfileIds );
DomainModel domainModel = new DomainModel( pomFile );
domainModel.setProjectDirectory( pomFile.getParentFile() );
domainModel.setMostSpecialized( true );
domainModels.add( domainModel ); List<DomainModel> domainModels = new ArrayList<DomainModel>();
ArtifactRepository localRepository = projectBuilderConfiguration.getLocalRepository();
List<ArtifactRepository> remoteRepositories = projectBuilderConfiguration.getRemoteRepositories();
File parentFile = null; domainModels.add( domainModel );
int lineageCount = 0; ArtifactRepository localRepository = projectBuilderConfiguration.getLocalRepository();
if ( domainModel.getParentId() != null ) List<ArtifactRepository> remoteRepositories = projectBuilderConfiguration.getRemoteRepositories();
File parentFile = null;
int lineageCount = 0;
if ( domainModel.getParentId() != null )
{
List<DomainModel> mavenParents;
MavenProject topProject = projectBuilderConfiguration.getTopLevelProjectFromReactor();
if ( useTopLevelProjectForParent( domainModel, topProject ) )
{ {
List<DomainModel> mavenParents; mavenParents = getDomainModelParentsFromLocalPath( domainModel, localRepository, remoteRepositories, topProject.getFile(), projectBuilderConfiguration );
MavenProject topProject = projectBuilderConfiguration.getTopLevelProjectFromReactor(); }
if(useTopLevelProjectForParent(domainModel, topProject) ) else if ( isParentLocal( domainModel.getRelativePathOfParent(), pomFile.getParentFile() ) )
{ {
mavenParents = getDomainModelParentsFromLocalPath( domainModel, localRepository, remoteRepositories, topProject.getFile(), projectBuilderConfiguration ); mavenParents = getDomainModelParentsFromLocalPath( domainModel, localRepository, remoteRepositories, pomFile.getParentFile(), projectBuilderConfiguration );
} }
else if ( isParentLocal( domainModel.getRelativePathOfParent(), pomFile.getParentFile() ) ) else
{ {
mavenParents = getDomainModelParentsFromLocalPath( domainModel, localRepository, remoteRepositories, pomFile.getParentFile(), projectBuilderConfiguration ); mavenParents = getDomainModelParentsFromRepository( domainModel, localRepository, remoteRepositories );
}
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 );
} }
domainModels.add( new DomainModel( getSuperModel(), false ) ); if ( mavenParents.size() > 0 )
List<DomainModel> profileModels = new ArrayList<DomainModel>();
//Process Profiles
for(DomainModel domain : domainModels)
{ {
DomainModel dm = (DomainModel) domain; DomainModel dm = (DomainModel) mavenParents.get( 0 );
parentFile = dm.getFile();
if(!dm.getModel().getProfiles().isEmpty()) domainModel.setParentFile( parentFile );
{ lineageCount = mavenParents.size();
Collection<Profile> 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); domainModels.addAll( mavenParents );
}
// Lineage count is inclusive to add the POM read in itself. domainModels.add( new DomainModel( getSuperModel(), false ) );
transformedDomainModel.setLineageCount( lineageCount + 1 ); List<DomainModel> profileModels = new ArrayList<DomainModel>();
transformedDomainModel.setParentFile( parentFile ); //Process Profiles
for ( DomainModel domain : domainModels )
{
DomainModel dm = (DomainModel) domain;
return transformedDomainModel; if ( !dm.getModel().getProfiles().isEmpty() )
{
Collection<Profile> 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()) private static boolean useTopLevelProjectForParent( DomainModel currentModel, MavenProject topProject )
&& topProject.getArtifactId().equals(currentModel.getParentArtifactId()) throws IOException
&& topProject.getVersion().equals(currentModel.getParentVersion()); {
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 ) private void validateModel( Model model, File pomFile )
@ -683,14 +604,14 @@ public class DefaultMavenProjectBuilder
} }
} }
private List<DomainModel> getDomainModelParentsFromRepository( DomainModel domainModel, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories ) private List<DomainModel> getDomainModelParentsFromRepository( DomainModel domainModel, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws IOException throws IOException
{ {
List<DomainModel> domainModels = new ArrayList<DomainModel>(); List<DomainModel> domainModels = new ArrayList<DomainModel>();
String parentId = domainModel.getParentId(); String parentId = domainModel.getParentId();
if ( parentId == null || localRepository == null) if ( parentId == null || localRepository == null )
{ {
return domainModels; return domainModels;
} }
@ -699,24 +620,22 @@ public class DefaultMavenProjectBuilder
ArtifactResolutionRequest request = new ArtifactResolutionRequest( artifactParent, localRepository, remoteRepositories ); ArtifactResolutionRequest request = new ArtifactResolutionRequest( artifactParent, localRepository, remoteRepositories );
ArtifactResolutionResult result; ArtifactResolutionResult result;
try try
{ {
result = repositorySystem.resolve( request ); result = repositorySystem.resolve( request );
} }
catch (Exception e) catch ( Exception e )
{ {
throw (IOException) new IOException( "The parent POM " + artifactParent throw (IOException) new IOException( "The parent POM " + artifactParent + " could not be retrieved from any repository" ).initCause( e );
+ " could not be retrieved from any repository" ).initCause( e ); }
}
try try
{ {
resolutionErrorHandler.throwErrors( request, result ); resolutionErrorHandler.throwErrors( request, result );
} }
catch ( ArtifactResolutionException e ) catch ( ArtifactResolutionException e )
{ {
throw (IOException) new IOException( "The parent POM " + artifactParent throw (IOException) new IOException( "The parent POM " + artifactParent + " could not be retrieved from any repository" ).initCause( e );
+ " could not be retrieved from any repository" ).initCause( e );
} }
DomainModel parentDomainModel = new DomainModel( artifactParent.getFile() ); DomainModel parentDomainModel = new DomainModel( artifactParent.getFile() );
@ -726,7 +645,7 @@ public class DefaultMavenProjectBuilder
//shane: what does this mean exactly and why does it occur //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() ); logger.debug( "Parent pom ids do not match: Parent File = " + artifactParent.getFile().getAbsolutePath() + ": Child ID = " + domainModel.getId() );
// return domainModels; // return domainModels;
} }
domainModels.add( parentDomainModel ); domainModels.add( parentDomainModel );
@ -744,8 +663,8 @@ public class DefaultMavenProjectBuilder
* @return * @return
* @throws IOException * @throws IOException
*/ */
private List<DomainModel> getDomainModelParentsFromLocalPath( DomainModel domainModel, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories, private List<DomainModel> getDomainModelParentsFromLocalPath( DomainModel domainModel, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories, File projectDirectory,
File projectDirectory, ProjectBuilderConfiguration projectBuilderConfiguration ) ProjectBuilderConfiguration projectBuilderConfiguration )
throws IOException throws IOException
{ {
List<DomainModel> domainModels = new ArrayList<DomainModel>(); List<DomainModel> domainModels = new ArrayList<DomainModel>();
@ -756,27 +675,27 @@ public class DefaultMavenProjectBuilder
{ {
return domainModels; return domainModels;
} }
File parentFile = new File( projectDirectory, domainModel.getRelativePathOfParent() ).getCanonicalFile(); File parentFile = new File( projectDirectory, domainModel.getRelativePathOfParent() ).getCanonicalFile();
if ( parentFile.isDirectory() ) if ( parentFile.isDirectory() )
{ {
parentFile = new File( parentFile.getAbsolutePath(), "pom.xml" ); parentFile = new File( parentFile.getAbsolutePath(), "pom.xml" );
} }
MavenProject topProject = projectBuilderConfiguration.getTopLevelProjectFromReactor(); MavenProject topProject = projectBuilderConfiguration.getTopLevelProjectFromReactor();
boolean isTop = useTopLevelProjectForParent(domainModel, topProject); boolean isTop = useTopLevelProjectForParent( domainModel, topProject );
DomainModel parentDomainModel = null; DomainModel parentDomainModel = null;
if ( !isTop ) if ( !isTop )
{ {
if(!parentFile.isFile()) if ( !parentFile.isFile() )
{ {
throw new IOException( "File does not exist: File = " + parentFile.getAbsolutePath() ); throw new IOException( "File does not exist: File = " + parentFile.getAbsolutePath() );
} }
parentDomainModel = new DomainModel( parentFile ); parentDomainModel = new DomainModel( parentFile );
parentDomainModel.setProjectDirectory( parentFile.getParentFile() ); parentDomainModel.setProjectDirectory( parentFile.getParentFile() );
} }
else else
{ {
parentDomainModel = new DomainModel(projectBuilderConfiguration.getTopLevelProjectFromReactor().getFile()); parentDomainModel = new DomainModel( projectBuilderConfiguration.getTopLevelProjectFromReactor().getFile() );
} }
if ( !parentDomainModel.matchesParentOf( domainModel ) ) if ( !parentDomainModel.matchesParentOf( domainModel ) )
@ -798,18 +717,19 @@ public class DefaultMavenProjectBuilder
domainModels.add( parentDomainModel ); domainModels.add( parentDomainModel );
if ( domainModel.getParentId() != null ) if ( domainModel.getParentId() != null )
{ {
if(isTop) if ( isTop )
{ {
if ( isParentLocal( parentDomainModel.getRelativePathOfParent(), parentFile.getParentFile() ) ) if ( isParentLocal( parentDomainModel.getRelativePathOfParent(), parentFile.getParentFile() ) )
{ {
domainModels.addAll( getDomainModelParentsFromLocalPath( parentDomainModel, localRepository, remoteRepositories, topProject.getFile().getParentFile(), projectBuilderConfiguration ) ); domainModels
} .addAll( getDomainModelParentsFromLocalPath( parentDomainModel, localRepository, remoteRepositories, topProject.getFile().getParentFile(), projectBuilderConfiguration ) );
else }
{ else
domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, localRepository, remoteRepositories ) ); {
} domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, localRepository, remoteRepositories ) );
} }
else if ( isParentLocal( parentDomainModel.getRelativePathOfParent(), parentFile.getParentFile() ) ) }
else if ( isParentLocal( parentDomainModel.getRelativePathOfParent(), parentFile.getParentFile() ) )
{ {
domainModels.addAll( getDomainModelParentsFromLocalPath( parentDomainModel, localRepository, remoteRepositories, parentFile.getParentFile(), projectBuilderConfiguration ) ); domainModels.addAll( getDomainModelParentsFromLocalPath( parentDomainModel, localRepository, remoteRepositories, parentFile.getParentFile(), projectBuilderConfiguration ) );
} }

View File

@ -1,75 +1,11 @@
package org.apache.maven.project; 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.LegacyRepositorySystem;
import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.VersionNotFoundException;
import org.codehaus.plexus.component.annotations.Component; 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") @Component(role = RepositorySystem.class, hint = "test")
public class TestMavenRepositorySystem public class TestMavenRepositorySystem
extends LegacyRepositorySystem extends LegacyRepositorySystem
{ {
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> 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 );
}
} }

View File

@ -81,7 +81,7 @@ public class MavenMetadataSourceTest
MavenProject project = new MavenProject( new Model() ); 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(); ) for ( Iterator it = result.iterator(); it.hasNext(); )
{ {
@ -96,6 +96,8 @@ public class MavenMetadataSourceTest
} }
} }
//TODO: restore these if it makes sense
/*
public void testShouldUseCompileScopeIfDependencyScopeEmpty() public void testShouldUseCompileScopeIfDependencyScopeEmpty()
throws Exception throws Exception
{ {
@ -112,9 +114,9 @@ public class MavenMetadataSourceTest
model.addDependency( dep ); 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 ); String key = ArtifactUtils.versionlessKey( groupId, artifactId );
@ -159,13 +161,13 @@ public class MavenMetadataSourceTest
model.setDependencyManagement( depMgmt ); model.setDependencyManagement( depMgmt );
MavenProject project = new MavenProject( model ); MavenProject project = new MavenProject( model, repositorySystem );
TestModelDefaultsInjector injector = new TestModelDefaultsInjector(); TestModelDefaultsInjector injector = new TestModelDefaultsInjector();
injector.injectDefaults( model ); injector.injectDefaults( model );
project.setArtifacts( repositorySystem.createArtifacts( project.getDependencies(), null, null, project ) ); project.setArtifacts( project.createArtifacts( null ) );
String key = ArtifactUtils.versionlessKey( groupId, artifactId ); String key = ArtifactUtils.versionlessKey( groupId, artifactId );
@ -182,5 +184,6 @@ public class MavenMetadataSourceTest
//check for back-propagation of default scope. //check for back-propagation of default scope.
assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_TEST, dep.getScope() ); assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_TEST, dep.getScope() );
} }
*/
} }

View File

@ -49,14 +49,6 @@
<groupId>org.apache.maven.wagon</groupId> <groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId> <artifactId>wagon-http-lightweight</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh-external</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.apache.maven.wagon</groupId> <groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId> <artifactId>wagon-file</artifactId>

View File

@ -38,7 +38,6 @@ import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.plugin.PluginLoaderException;
import org.apache.maven.plugin.PluginManager; import org.apache.maven.plugin.PluginManager;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder; 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 // Project
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------

View File

@ -90,8 +90,6 @@ public class DefaultMavenExecutionRequestPopulator
toolchains( request, configuration ); toolchains( request, configuration );
artifactTransferMechanism( request, configuration );
profileManager( request, configuration ); profileManager( request, configuration );
processSettings( request, configuration ); processSettings( request, configuration );
@ -342,27 +340,6 @@ public class DefaultMavenExecutionRequestPopulator
// Artifact Transfer Mechanism // 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 ) public ArtifactRepository createLocalRepository( MavenExecutionRequest request, Settings settings, Configuration configuration )
throws MavenEmbedderException throws MavenEmbedderException
{ {

View File

@ -39,7 +39,7 @@ public class DomainModel
protected Model model; protected Model model;
public Model getModel() throws IOException public Model getModel()
{ {
return model; return model;
} }

View File

@ -34,6 +34,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; 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.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.resolver.ArtifactResolver;
@ -76,6 +77,9 @@ public class LegacyRepositorySystem
@Requirement @Requirement
private ArtifactRepositoryLayout defaultArtifactRepositoryLayout; private ArtifactRepositoryLayout defaultArtifactRepositoryLayout;
@Requirement
private ArtifactCollector artifactCollector;
@Requirement @Requirement
private MirrorBuilder mirrorBuilder; private MirrorBuilder mirrorBuilder;
@ -157,118 +161,15 @@ public class LegacyRepositorySystem
return artifactFactory.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), versionRange ); return artifactFactory.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), versionRange );
} }
/**
* @return {@link Set} &lt; {@link Artifact} >
* @todo desperately needs refactoring. It's just here because it's implementation is
* maven-project specific
*/
public Set<Artifact> createArtifacts( List<Dependency> dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenRepositoryWrapper reactor )
throws VersionNotFoundException
{
return createArtifacts( artifactFactory, dependencies, inheritedScope, dependencyFilter, reactor );
}
@Deprecated
public static Set<Artifact> createArtifacts( ArtifactFactory artifactFactory, List<Dependency> dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenRepositoryWrapper reactor )
throws VersionNotFoundException
{
Set<Artifact> projectArtifacts = new LinkedHashSet<Artifact>( dependencies.size() );
for ( Iterator<Dependency> 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<String> exclusions = new ArrayList<String>();
for ( Iterator<Exclusion> 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 ) public ArtifactRepository buildArtifactRepository( Repository repo )
throws InvalidRepositoryException throws InvalidRepositoryException
{ {
if ( repo != null ) if ( repo != null )
{ {
String id = repo.getId(); String id = repo.getId();
String url = repo.getUrl(); 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 snapshots = buildArtifactRepositoryPolicy( repo.getSnapshots() );
ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repo.getReleases() ); ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repo.getReleases() );
@ -471,6 +372,18 @@ public class LegacyRepositorySystem
public MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request ) public MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request )
{ {
// ArtifactResolutionResult collect( Set<Artifact> artifacts,
// Artifact originatingArtifact,
// Map managedVersions,
// ArtifactRepository localRepository,
// List<ArtifactRepository> remoteRepositories,
// ArtifactMetadataSource source,
// ArtifactFilter filter,
// List<ResolutionListener> listeners,
// List<ConflictResolver> conflictResolvers )
// ArtifactResolutionResult result = artifactCollector.
return null; return null;
} }
} }

View File

@ -25,7 +25,6 @@ import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult; 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.Dependency;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.model.Repository; import org.apache.maven.model.Repository;
@ -57,14 +56,9 @@ public interface RepositorySystem
Artifact createDependencyArtifact( Dependency dependency ); Artifact createDependencyArtifact( Dependency dependency );
//REMOVE //TODO: this needs a project to do anything useful
// This will disappear when we actually deal with resolving a root dependency and its dependencies. This is used everywhere because of that //Set<Artifact> createArtifacts();
// deficiency
Set<Artifact> createArtifacts( List<Dependency> dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenRepositoryWrapper reactor )
throws VersionNotFoundException;
// Repository creation
// maven model // maven model
ArtifactRepository buildArtifactRepository( Repository repository ) ArtifactRepository buildArtifactRepository( Repository repository )
throws InvalidRepositoryException; throws InvalidRepositoryException;
@ -97,13 +91,7 @@ public interface RepositorySystem
* @return * @return
*/ */
MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request ); 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 //REMOVE
// These should be associated with repositories and the repositories should be examine as part of metadatda and // 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. // artifact resolution. So these methods should also not be here.

13
pom.xml
View File

@ -22,13 +22,16 @@ under the License.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<!--
<parent> <parent>
<groupId>org.apache.maven</groupId> <groupId>org.apache.maven</groupId>
<artifactId>maven-parent</artifactId> <artifactId>maven-parent</artifactId>
<version>11</version> <version>11</version>
<relativePath>../pom/maven/pom.xml</relativePath> <relativePath>../pom/maven/pom.xml</relativePath>
</parent> </parent>
-->
<groupId>org.apache.maven</groupId>
<artifactId>maven</artifactId> <artifactId>maven</artifactId>
<version>3.0-SNAPSHOT</version> <version>3.0-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
@ -294,16 +297,6 @@ under the License.
<artifactId>wagon-http-lightweight</artifactId> <artifactId>wagon-http-lightweight</artifactId>
<version>${wagonVersion}</version> <version>${wagonVersion}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>${wagonVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh-external</artifactId>
<version>${wagonVersion}</version>
</dependency>
<!-- Doxia --> <!-- Doxia -->
<dependency> <dependency>
<groupId>org.apache.maven.doxia</groupId> <groupId>org.apache.maven.doxia</groupId>