merge from branch

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163855 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-04-08 04:48:04 +00:00
parent eceb6dbc12
commit f8ba3a48d1
11 changed files with 184 additions and 200 deletions

View File

@ -54,7 +54,8 @@ it0016: Test a WAR generation
it0017: Test an EJB generation
it0018: Ensure that managed dependencies for dependency POMs are calculated
correctly when resolved.
correctly when resolved. Removes commons-logging-1.0.3 and checks it is
redownloaded.
-------------------------------------------------------------------------------
- generated sources

View File

@ -14,4 +14,4 @@ it0013
it0015
it0016
it0017
it0018
it0018

View File

@ -9,22 +9,16 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin</artifactId>
<version>2.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-script-marmalade</artifactId>
<version>2.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>marmalade</groupId>
<artifactId>marmalade-core</artifactId>
<version>1.0-alpha2-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
<version>1.0-alpha-2</version>
</dependency>
</dependencies>
<build>

View File

@ -1 +1,2 @@
target/classes/org/apache/maven/it0018/Person.class
# TODO: I would like to build some small core-it artifacts for this purpose instead
${artifact:commons-logging:commons-logging:1.0.3:jar}

View File

@ -0,0 +1 @@
rm ${artifact:commons-logging:commons-logging:1.0.3:jar}

View File

@ -83,6 +83,11 @@ public class DefaultMaven
public MavenExecutionResponse execute( MavenExecutionRequest request ) throws ReactorException
{
if ( request.getGoals().isEmpty() )
{
throw new ReactorException( "You must specify at least one goal. Try 'install'." );
}
EventDispatcher dispatcher = request.getEventDispatcher();
String event = MavenEvents.REACTOR_EXECUTION;
@ -405,4 +410,4 @@ public class DefaultMaven
return secs + " seconds";
}
}
}
}

View File

@ -55,9 +55,6 @@ public class MavenMetadataSource
public MavenMetadataSource( ArtifactResolver artifactResolver )
{
// there is code in plexus that uses this (though it shouldn't) so we
// need to be able to not have a project builder
// TODO: remove, then remove those null checks
this.artifactResolver = artifactResolver;
this.mavenProjectBuilder = null;
}
@ -71,38 +68,32 @@ public class MavenMetadataSource
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException
{
Artifact metadataArtifact = artifactFactory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getBaseVersion(), artifact.getScope(),
"pom", null );
List dependencies = null;
// [jc] Commenting this out, because the place where the model is
// cached in the project builder has not accounted for interpolation or
// defaults injection. This wouldn't be a problem, except that the
// interpolation step actually returns a different instance of the
// model than was input, thus rendering the old version of the model
// stale. To test this, you have to create an artifact whose pom uses
// managed dependencies, then depend on that artifact from another
// project. The first plugin to refer to this dependency will work fine,
// but subsequent plugins referring to the dep will retrieved a cached
// copy of the model that has no versions, etc. defined because that
// model instance has not had defaults injected or interpolations
// resolved. See note in DefaultMavenProjectBuilder, line 170 for
// further discussion.
// Use the ProjectBuilder, to enable post-processing and inheritance calculation before retrieving the
// associated artifacts.
if ( mavenProjectBuilder != null )
{
Model model = mavenProjectBuilder.getCachedModel( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion() );
if ( model != null )
try
{
dependencies = model.getDependencies();
MavenProject p = mavenProjectBuilder.buildFromRepository( metadataArtifact, remoteRepositories,
localRepository );
dependencies = p.getDependencies();
}
catch ( ProjectBuildingException e )
{
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
}
}
if ( dependencies == null )
else
{
Artifact metadataArtifact = artifactFactory.createArtifact( artifact.getGroupId(),
artifact.getArtifactId(),
artifact.getBaseVersion(), artifact.getScope(),
"pom", null );
// there is code in plexus that uses this (though it shouldn't) so we
// need to be able to not have a project builder
// TODO: remove - which then makes this a very thin wrapper around a project builder - is it needed?
try
{
@ -113,38 +104,20 @@ public class MavenMetadataSource
throw new ArtifactMetadataRetrievalException( "Error while resolving metadata artifact", e );
}
// [jdcasey/03-Feb-2005]: Replacing with ProjectBuilder, to enable
// post-processing and inheritance calculation before retrieving the
// associated artifacts. This should improve consistency.
if ( mavenProjectBuilder != null )
FileReader reader = null;
try
{
try
{
MavenProject p = mavenProjectBuilder.buildFromRepository( metadataArtifact, localRepository );
dependencies = p.getDependencies();
}
catch ( ProjectBuildingException e )
{
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
}
reader = new FileReader( metadataArtifact.getFile() );
Model model = this.reader.read( reader );
dependencies = model.getDependencies();
}
else
catch ( Exception e )
{
FileReader reader = null;
try
{
reader = new FileReader( metadataArtifact.getFile() );
Model model = this.reader.read( reader );
dependencies = model.getDependencies();
}
catch ( Exception e )
{
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
}
finally
{
IoUtils.close( reader );
}
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
}
finally
{
IoUtils.close( reader );
}
}
return artifactFactory.createArtifacts( dependencies, localRepository, artifact.getScope() );

View File

@ -26,6 +26,7 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.model.Build;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
@ -104,81 +105,126 @@ public class DefaultMavenProjectBuilder
// MavenProjectBuilder Implementation
// ----------------------------------------------------------------------
public MavenProject buildWithDependencies( File project, ArtifactRepository localRepository )
public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository )
throws ProjectBuildingException
{
return build( project, localRepository, true, true );
return buildFromSourceFile( projectDescriptor, localRepository, true );
}
public MavenProject build( File project, ArtifactRepository localRepository )
public MavenProject build( File projectDescriptor, ArtifactRepository localRepository )
throws ProjectBuildingException
{
return build( project, localRepository, false, true );
return buildFromSourceFile( projectDescriptor, localRepository, false );
}
public MavenProject buildFromRepository( Artifact artifact, ArtifactRepository localRepository )
private MavenProject buildFromSourceFile( File projectDescriptor, ArtifactRepository localRepository,
boolean resolveDependencies )
throws ProjectBuildingException
{
return build( artifact.getFile(), localRepository, false, false );
Model model = readModel( projectDescriptor );
// Always cache files in the source tree over those in the repository
modelCache.put( createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() ), model );
MavenProject project = build( model, localRepository, resolveDependencies );
// Only translate the base directory for files in the source tree
pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor );
Build build = project.getBuild();
project.addCompileSourceRoot( build.getSourceDirectory() );
project.addScriptSourceRoot( build.getScriptSourceDirectory() );
project.addTestCompileSourceRoot( build.getTestSourceDirectory() );
// Only track the file of a POM in the source tree
project.setFile( projectDescriptor );
return project;
}
private MavenProject build( File projectDescriptor, ArtifactRepository localRepository,
boolean resolveDependencies, boolean sourceProject )
public MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories,
ArtifactRepository localRepository )
throws ProjectBuildingException
{
Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository );
return build( model, localRepository, false );
}
private Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories,
ArtifactRepository localRepository )
throws ProjectBuildingException
{
Model model = getCachedModel( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );
if ( model == null )
{
try
{
artifactResolver.resolve( artifact, remoteArtifactRepositories, localRepository );
}
catch ( ArtifactResolutionException e )
{
throw new ProjectBuildingException( "Unable to find artifact: " + artifact.toString() );
}
model = readModel( artifact.getFile() );
}
return model;
}
private MavenProject build( Model model, ArtifactRepository localRepository, boolean resolveDependencies )
throws ProjectBuildingException
{
Model superModel = getSuperModel();
LinkedList lineage = new LinkedList();
List aggregatedRemoteWagonRepositories = buildArtifactRepositories( superModel.getRepositories() );
MavenProject project = assembleLineage( model, lineage, aggregatedRemoteWagonRepositories, localRepository );
Model previous = superModel;
for ( Iterator i = lineage.iterator(); i.hasNext(); )
{
Model current = ( (MavenProject) i.next() ).getModel();
modelInheritanceAssembler.assembleModelInheritance( current, previous );
previous = current;
}
try
{
Model superModel = getSuperModel();
LinkedList lineage = new LinkedList();
List aggregatedRemoteWagonRepositories = buildArtifactRepositories( superModel.getRepositories() );
MavenProject project = assembleLineage( projectDescriptor, localRepository, lineage,
aggregatedRemoteWagonRepositories );
Model previous = superModel;
for ( Iterator i = lineage.iterator(); i.hasNext(); )
{
Model current = ( (MavenProject) i.next() ).getModel();
modelInheritanceAssembler.assembleModelInheritance( current, previous );
previous = current;
}
project = processProjectLogic( project, localRepository, aggregatedRemoteWagonRepositories,
resolveDependencies, sourceProject );
return project;
resolveDependencies );
}
catch ( Exception e )
catch ( ModelInterpolationException e )
{
throw new ProjectBuildingException( "Error building project from " + projectDescriptor, e );
throw new ProjectBuildingException( "Error building project: " + model.getId(), e );
}
catch ( ArtifactResolutionException e )
{
throw new ProjectBuildingException( "Error building project: " + model.getId(), e );
}
return project;
}
/**
* @todo can this take in a model instead of a project and still be successful?
* @todo In fact, does project REALLY need a MavenProject as a parent? Couldn't it have just a wrapper around a
* model that supported parents which were also the wrapper so that inheritence was assembled. We don't really need
* the resolved source roots, etc for the parent - that occurs for the parent when it is constructed independently
* and projects are not cached or reused
*/
private MavenProject processProjectLogic( MavenProject project, ArtifactRepository localRepository,
List remoteRepositories, boolean resolveDependencies,
boolean sourceProject )
List remoteRepositories, boolean resolveDependencies )
throws ProjectBuildingException, ModelInterpolationException, ArtifactResolutionException
{
Model model = project.getModel();
String cacheKey = createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() );
// [jc] This needs to be moved below the interpolation and defaults
// injection steps, especially since the interpolator returns a different
// instance of the Model. HOWEVER, I cannot move this caching step to
// the appropriate place, since it results in inconsistent artifact
// naming between the jar:jar and install:install steps for some reason.
//
// So, instead I'm commenting out the part of the MavenMetadataSource
// that looks up the cached model, and leaving this caching step right
// here...at least until I have more time to look at why this cannot be
// moved down.
Model cachedModel = (Model) modelCache.get( cacheKey );
if ( cachedModel == null || sourceProject )
String key = createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() );
Model cachedModel = (Model) modelCache.get( key );
if ( cachedModel == null )
{
modelCache.put( cacheKey, model );
}
@ -190,12 +236,6 @@ public class DefaultMavenProjectBuilder
MavenProject parentProject = project.getParent();
File projectDescriptor = project.getFile();
if ( sourceProject )
{
pathTranslator.alignToBaseDirectory( model, projectDescriptor );
}
project = new MavenProject( model );
try
@ -221,7 +261,6 @@ public class DefaultMavenProjectBuilder
}
}
project.setFile( projectDescriptor );
project.setParent( parentProject );
project.setRemoteArtifactRepositories( remoteRepositories );
project.setArtifacts( artifactFactory.createArtifacts( project.getDependencies(), localRepository, null ) );
@ -256,27 +295,11 @@ public class DefaultMavenProjectBuilder
throw new ProjectBuildingException( "Exception while building project: " + validationResult.toString() );
}
project.addCompileSourceRoot( project.getBuild().getSourceDirectory() );
project.addScriptSourceRoot( project.getBuild().getScriptSourceDirectory() );
project.addTestCompileSourceRoot( project.getBuild().getTestSourceDirectory() );
return project;
}
private MavenProject assembleLineage( File projectDescriptor, ArtifactRepository localRepository,
LinkedList lineage, List aggregatedRemoteWagonRepositories )
throws ProjectBuildingException
{
Model model = readModel( projectDescriptor );
MavenProject project = assembleLineage( model, localRepository, lineage, aggregatedRemoteWagonRepositories );
project.setFile( projectDescriptor );
return project;
}
private MavenProject assembleLineage( Model model, ArtifactRepository localRepository, LinkedList lineage,
List aggregatedRemoteWagonRepositories )
private MavenProject assembleLineage( Model model, LinkedList lineage, List aggregatedRemoteWagonRepositories,
ArtifactRepository localRepository )
throws ProjectBuildingException
{
aggregatedRemoteWagonRepositories.addAll( buildArtifactRepositories( model.getRepositories() ) );
@ -311,19 +334,13 @@ public class DefaultMavenProjectBuilder
// as we go in order to do this.
// ----------------------------------------------------------------------
MavenProject parent;
Model cachedModel = getCachedModel( parentModel.getGroupId(), parentModel.getArtifactId(),
parentModel.getVersion() );
if ( cachedModel == null )
{
File parentPom = findParentModel( parentModel, aggregatedRemoteWagonRepositories, localRepository );
Artifact artifact = artifactFactory.createArtifact( parentModel.getGroupId(), parentModel.getArtifactId(),
parentModel.getVersion(), null, "pom", null );
model = findModelFromRepository( artifact, aggregatedRemoteWagonRepositories, localRepository );
MavenProject parent = assembleLineage( model, lineage, aggregatedRemoteWagonRepositories, localRepository );
parent = assembleLineage( parentPom, localRepository, lineage, aggregatedRemoteWagonRepositories );
}
else
{
parent = assembleLineage( cachedModel, localRepository, lineage, aggregatedRemoteWagonRepositories );
}
project.setParent( parent );
}
@ -355,15 +372,16 @@ public class DefaultMavenProjectBuilder
ArtifactRepositoryLayout remoteRepoLayout = null;
try
{
remoteRepoLayout = (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE,
layout );
remoteRepoLayout =
(ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE, layout );
}
catch ( ComponentLookupException e )
{
throw new ProjectBuildingException( "Cannot find layout implementation corresponding to: \'" + layout + "\' for remote repository with id: \'" + mavenRepo.getId() + "\'.",
throw new ProjectBuildingException( "Cannot find layout implementation corresponding to: \'" + layout +
"\' for remote repository with id: \'" + mavenRepo.getId() + "\'.",
e );
}
ArtifactRepository artifactRepo = artifactRepositoryFactory.createArtifactRepository( mavenRepo, settings,
remoteRepoLayout );
@ -379,45 +397,47 @@ public class DefaultMavenProjectBuilder
throws Exception
{
List remotePluginRepositories = new ArrayList();
MavenSettings settings = mavenSettingsBuilder.buildSettings();
for ( Iterator it = pluginRepositories.iterator(); it.hasNext(); )
{
Repository mavenRepo = (Repository) it.next();
String layout = mavenRepo.getLayout();
ArtifactRepositoryLayout repositoryLayout = null;
try
{
repositoryLayout = (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE,
layout );
repositoryLayout =
(ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE, layout );
}
catch ( ComponentLookupException e )
{
throw new ProjectBuildingException( "Cannot find layout implementation corresponding to: \'" + layout + "\' for remote repository with id: \'" + mavenRepo.getId() + "\'.",
throw new ProjectBuildingException( "Cannot find layout implementation corresponding to: \'" + layout +
"\' for remote repository with id: \'" + mavenRepo.getId() + "\'.",
e );
}
ArtifactRepository pluginRepository = artifactRepositoryFactory.createArtifactRepository( mavenRepo, settings,
ArtifactRepository pluginRepository = artifactRepositoryFactory.createArtifactRepository( mavenRepo,
settings,
repositoryLayout );
remotePluginRepositories.add( pluginRepository );
}
return remotePluginRepositories;
}
private ArtifactRepository buildDistributionManagementRepository( Repository dmRepo )
throws Exception
{
if(dmRepo == null)
if ( dmRepo == null )
{
return null;
}
MavenSettings settings = mavenSettingsBuilder.buildSettings();
String repoLayoutId = dmRepo.getLayout();
@ -438,7 +458,8 @@ public class DefaultMavenProjectBuilder
try
{
reader = new FileReader( file );
return modelReader.read( reader );
Model model = modelReader.read( reader );
return model;
}
catch ( FileNotFoundException e )
{
@ -472,27 +493,7 @@ public class DefaultMavenProjectBuilder
}
}
private File findParentModel( Parent parent, List remoteArtifactRepositories, ArtifactRepository localRepository )
throws ProjectBuildingException
{
Artifact artifact = artifactFactory.createArtifact( parent.getGroupId(), parent.getArtifactId(),
parent.getVersion(), null, "pom", null );
try
{
artifactResolver.resolve( artifact, remoteArtifactRepositories, localRepository );
}
catch ( ArtifactResolutionException e )
{
// @todo use parent.toString() if modello could generate it, or specify in a code segment
throw new ProjectBuildingException( "Missing parent POM: " + parent.getGroupId() + ":" +
parent.getArtifactId() + "-" + parent.getVersion(), e );
}
return artifact.getFile();
}
public Model getCachedModel( String groupId, String artifactId, String version )
private Model getCachedModel( String groupId, String artifactId, String version )
{
return (Model) modelCache.get( createCacheKey( groupId, artifactId, version ) );
}
@ -521,7 +522,7 @@ public class DefaultMavenProjectBuilder
List remoteRepositories = buildArtifactRepositories( superModel.getRepositories() );
project = processProjectLogic( project, localRepository, remoteRepositories, false, false );
project = processProjectLogic( project, localRepository, remoteRepositories, false );
return project;
}
@ -552,4 +553,4 @@ public class DefaultMavenProjectBuilder
{
this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
}
}

View File

@ -19,18 +19,18 @@ package org.apache.maven.project;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Model;
import java.io.File;
import java.util.List;
public interface MavenProjectBuilder
{
String ROLE = MavenProjectBuilder.class.getName();
static final String STANDALONE_SUPERPOM_GROUPID = "org.apache.maven";
static final String STANDALONE_SUPERPOM_ARTIFACTID = "super-pom";
static final String STANDALONE_SUPERPOM_VERSION = "2.0";
MavenProject build( File project, ArtifactRepository localRepository )
@ -39,11 +39,19 @@ public interface MavenProjectBuilder
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository )
throws ProjectBuildingException;
MavenProject buildFromRepository( Artifact artifact, ArtifactRepository localRepository )
/**
* Build the artifact from the local repository, resolving it if necessary.
*
* @param artifact the artifact description
* @param localRepository the local repository
* @param remoteArtifactRepositories the remote repository list
* @return the built project
* @throws ProjectBuildingException
*/
MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories,
ArtifactRepository localRepository )
throws ProjectBuildingException;
MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository )
throws ProjectBuildingException;
Model getCachedModel( String groupId, String artifactId, String version );
}

View File

@ -1,6 +1,6 @@
<project>
<modelVersion>4.0.0</modelVersion>
<name>Maven Super Model</name>
<name>Maven Default Project</name>
<repositories>
<repository>

View File

@ -1,3 +1,3 @@
target
maven-site.iml
velocity.log
velocity.log*