[MNG-1980] Removing the duplicate ID, the reactor will catch duplicate IDs in a single build so it doesn't not need

to be checked for in the project builder. I have removed the model caching for now while I'm refactoring
           the project builder. The plan is to break the 1000+ lines down into its constituent components and use
           a pipeline to build up the project.



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@371079 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2006-01-21 16:36:06 +00:00
parent ea7da68e38
commit 95189e189e
3 changed files with 310 additions and 280 deletions

View File

@ -240,7 +240,7 @@ it0086: Verify that a plugin dependency class can be loaded from both the plugin
it0087: Verify that a project-level plugin dependency class can be loaded from both the plugin classloader it0087: Verify that a project-level plugin dependency class can be loaded from both the plugin classloader
and the context classloader available to the plugin. and the context classloader available to the plugin.
it0088: Test path translation it0088: Test path translation.
it0089: Test that Checkstyle PackageNamesLoader.loadModuleFactory(..) method will complete as-is with it0089: Test that Checkstyle PackageNamesLoader.loadModuleFactory(..) method will complete as-is with
the context classloader available to the plugin. the context classloader available to the plugin.

View File

@ -120,6 +120,7 @@ public class DefaultLifecycleExecutor
if ( goals.isEmpty() && rootProject != null ) if ( goals.isEmpty() && rootProject != null )
{ {
String goal = rootProject.getDefaultGoal(); String goal = rootProject.getDefaultGoal();
if ( goal != null ) if ( goal != null )
{ {
goals = Collections.singletonList( goal ); goals = Collections.singletonList( goal );
@ -170,6 +171,7 @@ public class DefaultLifecycleExecutor
try try
{ {
Map handlers = findArtifactTypeHandlers( project, session.getSettings(), session.getLocalRepository() ); Map handlers = findArtifactTypeHandlers( project, session.getSettings(), session.getLocalRepository() );
artifactHandlerManager.addHandlers( handlers ); artifactHandlerManager.addHandlers( handlers );
} }
catch ( PluginNotFoundException e ) catch ( PluginNotFoundException e )
@ -179,8 +181,11 @@ public class DefaultLifecycleExecutor
} }
} }
private void executeTaskSegments( List taskSegments, ReactorManager rm, MavenSession session, private void executeTaskSegments( List taskSegments,
MavenProject rootProject, EventDispatcher dispatcher ) ReactorManager rm,
MavenSession session,
MavenProject rootProject,
EventDispatcher dispatcher )
throws LifecycleExecutionException, BuildFailureException throws LifecycleExecutionException, BuildFailureException
{ {
for ( Iterator it = taskSegments.iterator(); it.hasNext(); ) for ( Iterator it = taskSegments.iterator(); it.hasNext(); )
@ -206,6 +211,7 @@ public class DefaultLifecycleExecutor
long buildStartTime = System.currentTimeMillis(); long buildStartTime = System.currentTimeMillis();
String target = rootProject.getId() + " ( " + segment + " )"; String target = rootProject.getId() + " ( " + segment + " )";
dispatcher.dispatchStart( event, target ); dispatcher.dispatchStart( event, target );
// only call once, with the top-level project (assumed to be provided as a parameter)... // only call once, with the top-level project (assumed to be provided as a parameter)...
@ -213,8 +219,7 @@ public class DefaultLifecycleExecutor
{ {
String task = (String) goalIterator.next(); String task = (String) goalIterator.next();
executeGoalAndHandleFailures( task, session, rootProject, dispatcher, event, rm, buildStartTime, executeGoalAndHandleFailures( task, session, rootProject, dispatcher, event, rm, buildStartTime,target );
target );
} }
rm.registerBuildSuccess( rootProject, System.currentTimeMillis() - buildStartTime ); rm.registerBuildSuccess( rootProject, System.currentTimeMillis() - buildStartTime );
@ -229,8 +234,7 @@ public class DefaultLifecycleExecutor
getLogger().info( " " + segment ); getLogger().info( " " + segment );
getLogger().info( getLogger().info("This project has been banned from further executions due to previous failures." );
"This project has been banned from further executions due to previous failures." );
line(); line();
} }
@ -283,8 +287,7 @@ public class DefaultLifecycleExecutor
getLogger().info( " " + segment ); getLogger().info( " " + segment );
getLogger().info( getLogger().info( "This project has been banned from further executions due to previous failures." );
"This project has been banned from further executions due to previous failures." );
line(); line();
} }
@ -293,9 +296,14 @@ public class DefaultLifecycleExecutor
} }
} }
private void executeGoalAndHandleFailures( String task, MavenSession session, MavenProject project, private void executeGoalAndHandleFailures( String task,
EventDispatcher dispatcher, String event, ReactorManager rm, MavenSession session,
long buildStartTime, String target ) MavenProject project,
EventDispatcher dispatcher,
String event,
ReactorManager rm,
long buildStartTime,
String target )
throws BuildFailureException, LifecycleExecutionException throws BuildFailureException, LifecycleExecutionException
{ {
try try

View File

@ -93,6 +93,40 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
/*:apt
-----
POM lifecycle
-----
POM Lifecycle
Order of operations when building a POM
* inheritance
* path translation
* interpolation
* defaults injection
Current processing is:
* inheritance
* interpolation
* defaults injection
* path translation
I'm not sure how this is working at all ... i think i have a case where this is failing but i need to
encapsulate as a test so i can fix it. Also need to think of the in working build directory versus looking
things up from the repository i.e buildFromSource vs buildFromRepository.
Notes
* when the model is read it may not have a groupId, as it must be inherited
* the inheritance assembler must use models that are unadulterated!
*/
/** /**
* @version $Id: DefaultMavenProjectBuilder.java,v 1.37 2005/03/08 01:55:22 * @version $Id: DefaultMavenProjectBuilder.java,v 1.37 2005/03/08 01:55:22
* trygvis Exp $ * trygvis Exp $
@ -118,6 +152,8 @@ public class DefaultMavenProjectBuilder
private ModelValidator validator; private ModelValidator validator;
private Map projectCache = new HashMap();
// TODO: make it a component // TODO: make it a component
private MavenXpp3Reader modelReader; private MavenXpp3Reader modelReader;
@ -137,12 +173,8 @@ public class DefaultMavenProjectBuilder
private WagonManager wagonManager; private WagonManager wagonManager;
private final Map modelCache = new HashMap();
public static final String MAVEN_MODEL_VERSION = "4.0.0"; public static final String MAVEN_MODEL_VERSION = "4.0.0";
private Map projectCache = new HashMap();
public void initialize() public void initialize()
{ {
modelReader = new MavenXpp3Reader(); modelReader = new MavenXpp3Reader();
@ -152,18 +184,118 @@ public class DefaultMavenProjectBuilder
// MavenProjectBuilder Implementation // MavenProjectBuilder Implementation
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository, public MavenProject build( File projectDescriptor, ArtifactRepository localRepository, ProfileManager profileManager )
throws ProjectBuildingException
{
return buildFromSourceFileInternal( projectDescriptor, localRepository, profileManager, true );
}
public MavenProject build( File projectDescriptor,
ArtifactRepository localRepository,
ProfileManager profileManager,
boolean checkDistributionManagementStatus )
throws ProjectBuildingException
{
return buildFromSourceFileInternal( projectDescriptor, localRepository, profileManager, checkDistributionManagementStatus );
}
// jvz:note
// When asked for something from the repository are we getting it from the reactor? Yes, when using this call
// we are assuming that the reactor has been run and we have collected the projects required to satisfy it0042
// which means the projects in the reactor are required for finding classes in <project>/target/classes. Not
// sure this is ideal. I remove all caching from the builder and all reactor related ITs which assume
// access to simbling project resources failed.
public MavenProject buildFromRepository( Artifact artifact,
List remoteArtifactRepositories,
ArtifactRepository localRepository,
boolean allowStubModel )
throws ProjectBuildingException
{
String cacheKey = createCacheKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );
MavenProject project = (MavenProject) projectCache.get( cacheKey );
if ( project != null )
{
return project;
}
Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository, allowStubModel );
return buildInternal( "Artifact [" + artifact + "]", model, localRepository, remoteArtifactRepositories, null, null, false );
}
public MavenProject buildFromRepository( Artifact artifact,
List remoteArtifactRepositories,
ArtifactRepository localRepository )
throws ProjectBuildingException
{
return buildFromRepository( artifact, remoteArtifactRepositories, localRepository, true );
}
// what is using this externally? jvz.
public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository )
throws ProjectBuildingException
{
Model superModel = getSuperModel();
superModel.setGroupId( STANDALONE_SUPERPOM_GROUPID );
superModel.setArtifactId( STANDALONE_SUPERPOM_ARTIFACTID );
superModel.setVersion( STANDALONE_SUPERPOM_VERSION );
ProfileManager profileManager = new DefaultProfileManager( container );
List activeProfiles;
profileManager.addProfiles( superModel.getProfiles() );
String projectId = safeVersionlessKey( STANDALONE_SUPERPOM_GROUPID, STANDALONE_SUPERPOM_ARTIFACTID );
activeProfiles = injectActiveProfiles( profileManager, superModel );
MavenProject project = new MavenProject( superModel );
project.setActiveProfiles( activeProfiles );
project.setOriginalModel( superModel );
try
{
project = processProjectLogic( "<Super-POM>", project, null, null, true );
project.setExecutionRoot( true );
return project;
}
catch ( ModelInterpolationException e )
{
throw new ProjectBuildingException( projectId, e.getMessage(), e );
}
catch ( InvalidRepositoryException e )
{
throw new ProjectBuildingException( projectId, e.getMessage(), e );
}
}
public MavenProject buildWithDependencies( File projectDescriptor,
ArtifactRepository localRepository,
ProfileManager profileManager ) ProfileManager profileManager )
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException
{ {
return buildWithDependencies( projectDescriptor, localRepository, profileManager, null ); return buildWithDependencies( projectDescriptor, localRepository, profileManager, null );
} }
// note:jvz This was added for the embedder.
/** /**
* @todo move to metadatasource itself? * @todo move to metadatasource itself?
*/ */
public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository, public MavenProject buildWithDependencies( File projectDescriptor,
ProfileManager profileManager, TransferListener transferListener ) ArtifactRepository localRepository,
ProfileManager profileManager,
TransferListener transferListener )
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException
{ {
MavenProject project = build( projectDescriptor, localRepository, profileManager ); MavenProject project = build( projectDescriptor, localRepository, profileManager );
@ -216,6 +348,10 @@ public class DefaultMavenProjectBuilder
return project; return project;
} }
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
private void ensureMetadataSourceIsInitialized() private void ensureMetadataSourceIsInitialized()
throws ProjectBuildingException throws ProjectBuildingException
{ {
@ -267,47 +403,25 @@ public class DefaultMavenProjectBuilder
return map; return map;
} }
public MavenProject build( File projectDescriptor, ArtifactRepository localRepository, private MavenProject buildFromSourceFileInternal( File projectDescriptor,
ProfileManager profileManager ) ArtifactRepository localRepository,
throws ProjectBuildingException ProfileManager profileManager,
{ boolean checkDistributionManagementStatus )
return buildFromSourceFile( projectDescriptor, localRepository, profileManager, true );
}
public MavenProject build( File projectDescriptor, ArtifactRepository localRepository,
ProfileManager profileManager, boolean checkDistributionManagementStatus )
throws ProjectBuildingException
{
return buildFromSourceFile( projectDescriptor, localRepository, profileManager,
checkDistributionManagementStatus );
}
private MavenProject buildFromSourceFile( File projectDescriptor, ArtifactRepository localRepository,
ProfileManager profileManager, boolean checkDistributionManagementStatus )
throws ProjectBuildingException throws ProjectBuildingException
{ {
Model model = readModel( "unknown", projectDescriptor, true ); Model model = readModel( "unknown", projectDescriptor, true );
// Always cache files in the source tree over those in the repository MavenProject project = buildInternal( projectDescriptor.getAbsolutePath(),
CachedModel cachedModel = new CachedModel( projectDescriptor, model ); model,
localRepository,
String modelKey = createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() );
if ( modelCache.containsKey( modelKey ) )
{
throw new ProjectBuildingException( model.getGroupId() + ":" + model.getArtifactId(),
"Duplicate project ID found in " +
projectDescriptor.getAbsolutePath() );
}
modelCache.put( modelKey, cachedModel );
MavenProject project = build( projectDescriptor.getAbsolutePath(), model, localRepository,
buildArtifactRepositories( getSuperModel() ), buildArtifactRepositories( getSuperModel() ),
projectDescriptor.getAbsoluteFile().getParentFile(), profileManager, true ); projectDescriptor,
profileManager,
true );
if ( checkDistributionManagementStatus ) if ( checkDistributionManagementStatus )
{ {
if ( project.getDistributionManagement() != null && if ( project.getDistributionManagement() != null && project.getDistributionManagement().getStatus() != null )
project.getDistributionManagement().getStatus() != null )
{ {
String projectId = safeVersionlessKey( project.getGroupId(), project.getArtifactId() ); String projectId = safeVersionlessKey( project.getGroupId(), project.getArtifactId() );
@ -316,46 +430,13 @@ public class DefaultMavenProjectBuilder
} }
} }
// Only translate the base directory for files in the source tree
pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor.getParentFile() );
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; return project;
} }
public MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories, private Model findModelFromRepository( Artifact artifact,
ArtifactRepository localRepository ) List remoteArtifactRepositories,
throws ProjectBuildingException ArtifactRepository localRepository,
{ boolean allowStubModel )
return buildFromRepository( artifact, remoteArtifactRepositories, localRepository, true );
}
public MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories,
ArtifactRepository localRepository, boolean allowStubModel )
throws ProjectBuildingException
{
String cacheKey = createCacheKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );
MavenProject project = (MavenProject) projectCache.get( cacheKey );
if ( project != null )
{
return project;
}
Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository, allowStubModel );
return build( "Artifact [" + artifact + "]", model, localRepository, remoteArtifactRepositories, null, null,
false );
}
private Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories,
ArtifactRepository localRepository, boolean allowStubModel )
throws ProjectBuildingException throws ProjectBuildingException
{ {
Artifact projectArtifact; Artifact projectArtifact;
@ -367,18 +448,16 @@ public class DefaultMavenProjectBuilder
} }
else else
{ {
getLogger().warn( "Attempting to build MavenProject instance for Artifact of type: " + artifact.getType() + getLogger().warn( "Attempting to build MavenProject instance for Artifact of type: " + artifact.getType() + "; constructing POM artifact instead." );
"; constructing POM artifact instead." );
projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(),
artifact.getVersion(), artifact.getScope() ); artifact.getArtifactId(),
artifact.getVersion(),
artifact.getScope() );
} }
CachedModel cachedModel = getCachedProject( projectArtifact.getGroupId(), projectArtifact.getArtifactId(),
projectArtifact.getVersion() );
Model model; Model model;
if ( cachedModel == null )
{
String projectId = ArtifactUtils.versionlessKey( projectArtifact ); String projectId = ArtifactUtils.versionlessKey( projectArtifact );
try try
@ -386,12 +465,15 @@ public class DefaultMavenProjectBuilder
artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository ); artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository );
File file = projectArtifact.getFile(); File file = projectArtifact.getFile();
model = readModel( projectId, file, false ); model = readModel( projectId, file, false );
String downloadUrl = null; String downloadUrl = null;
ArtifactStatus status = ArtifactStatus.NONE; ArtifactStatus status = ArtifactStatus.NONE;
DistributionManagement distributionManagement = model.getDistributionManagement(); DistributionManagement distributionManagement = model.getDistributionManagement();
if ( distributionManagement != null ) if ( distributionManagement != null )
{ {
downloadUrl = distributionManagement.getDownloadUrl(); downloadUrl = distributionManagement.getDownloadUrl();
@ -414,33 +496,29 @@ public class DefaultMavenProjectBuilder
} }
catch ( ArtifactResolutionException e ) catch ( ArtifactResolutionException e )
{ {
throw new ProjectBuildingException( projectId, "Error getting POM for '" + projectId + throw new ProjectBuildingException( projectId, "Error getting POM for '" + projectId + "' from the repository: " + e.getMessage(), e );
"' from the repository: " + e.getMessage(), e );
} }
catch ( ArtifactNotFoundException e ) catch ( ArtifactNotFoundException e )
{ {
if ( allowStubModel ) if ( allowStubModel )
{ {
getLogger().debug( "Artifact not found - using stub model: " + e.getMessage() ); getLogger().debug( "Artifact not found - using stub model: " + e.getMessage() );
model = createStubModel( projectArtifact ); model = createStubModel( projectArtifact );
} }
else else
{ {
throw new ProjectBuildingException( projectId, "POM '" + projectId + "' not found in repository: " + throw new ProjectBuildingException( projectId, "POM '" + projectId + "' not found in repository: " + e.getMessage(), e );
e.getMessage(), e );
} }
} }
}
else
{
model = cachedModel.getModel();
}
return model; return model;
} }
private void checkStatusAndUpdate( Artifact projectArtifact, ArtifactStatus status, File file, private void checkStatusAndUpdate( Artifact projectArtifact,
List remoteArtifactRepositories, ArtifactRepository localRepository ) ArtifactStatus status, File file,
List remoteArtifactRepositories,
ArtifactRepository localRepository )
throws ArtifactNotFoundException throws ArtifactNotFoundException
{ {
// TODO: configurable actions dependant on status // TODO: configurable actions dependant on status
@ -476,50 +554,52 @@ public class DefaultMavenProjectBuilder
} }
} }
// jvz:note
// This is used when requested artifacts do not have an associated POM. This is for the case where we are
// using an m1 repo where the only thing required to be present are the JAR files.
private Model createStubModel( Artifact projectArtifact ) private Model createStubModel( Artifact projectArtifact )
{ {
getLogger().debug( "Using defaults for missing POM " + projectArtifact ); getLogger().debug( "Using defaults for missing POM " + projectArtifact );
Model model = new Model(); Model model = new Model();
model.setModelVersion( "4.0.0" ); model.setModelVersion( "4.0.0" );
model.setArtifactId( projectArtifact.getArtifactId() ); model.setArtifactId( projectArtifact.getArtifactId() );
model.setGroupId( projectArtifact.getGroupId() ); model.setGroupId( projectArtifact.getGroupId() );
model.setVersion( projectArtifact.getVersion() ); model.setVersion( projectArtifact.getVersion() );
// TODO: not correct in some instances // TODO: not correct in some instances
model.setPackaging( projectArtifact.getType() ); model.setPackaging( projectArtifact.getType() );
model.setDistributionManagement( new DistributionManagement() ); model.setDistributionManagement( new DistributionManagement() );
model.getDistributionManagement().setStatus( ArtifactStatus.GENERATED.toString() ); model.getDistributionManagement().setStatus( ArtifactStatus.GENERATED.toString() );
/* TODO: we should only do this if we can verify the existence of the JAR itself
File file = artifact.getFile();
file.getParentFile().mkdirs();
FileWriter writer = null;
try
{
writer = new FileWriter( file );
MavenXpp3Writer w = new MavenXpp3Writer();
w.write( writer, model );
}
catch ( IOException ioe )
{
getLogger().warn( "Attempted to write out a temporary generated POM, but failed", ioe );
}
finally
{
IOUtil.close( writer );
}
*/
return model; return model;
} }
private MavenProject build( String pomLocation, Model model, ArtifactRepository localRepository, // jvz:note
List parentSearchRepositories, File projectDir, ProfileManager externalProfileManager, // We've got a mixture of things going in the USD and from the repository, sometimes the descriptor
// is a real file and sometimes null which makes things confusing.
private MavenProject buildInternal( String pomLocation,
Model model,
ArtifactRepository localRepository,
List parentSearchRepositories,
File projectDescriptor,
ProfileManager externalProfileManager,
boolean strict ) boolean strict )
throws ProjectBuildingException throws ProjectBuildingException
{ {
File projectDir = null;
if ( projectDescriptor != null )
{
projectDir = projectDescriptor.getAbsoluteFile().getParentFile();
}
Model superModel = getSuperModel(); Model superModel = getSuperModel();
ProfileManager superProjectProfileManager = new DefaultProfileManager( container ); ProfileManager superProjectProfileManager = new DefaultProfileManager( container );
@ -573,8 +653,7 @@ public class DefaultMavenProjectBuilder
ArtifactRepository artifactRepo = null; ArtifactRepository artifactRepo = null;
try try
{ {
artifactRepo = artifactRepo = ProjectUtils.buildArtifactRepository( mavenRepo, artifactRepositoryFactory, container );
ProjectUtils.buildArtifactRepository( mavenRepo, artifactRepositoryFactory, container );
} }
catch ( InvalidRepositoryException e ) catch ( InvalidRepositoryException e )
{ {
@ -590,8 +669,14 @@ public class DefaultMavenProjectBuilder
MavenProject project = null; MavenProject project = null;
try try
{ {
project = assembleLineage( model, lineage, localRepository, projectDir, parentSearchRepositories, project = assembleLineage( model,
aggregatedRemoteWagonRepositories, externalProfileManager, strict ); lineage,
localRepository,
projectDir,
parentSearchRepositories,
aggregatedRemoteWagonRepositories,
externalProfileManager,
strict );
} }
catch ( InvalidRepositoryException e ) catch ( InvalidRepositoryException e )
{ {
@ -616,10 +701,13 @@ public class DefaultMavenProjectBuilder
// only add the super repository if it wasn't overridden by a profile or project // only add the super repository if it wasn't overridden by a profile or project
List repositories = new ArrayList( aggregatedRemoteWagonRepositories ); List repositories = new ArrayList( aggregatedRemoteWagonRepositories );
List superRepositories = buildArtifactRepositories( superModel ); List superRepositories = buildArtifactRepositories( superModel );
for ( Iterator i = superRepositories.iterator(); i.hasNext(); ) for ( Iterator i = superRepositories.iterator(); i.hasNext(); )
{ {
ArtifactRepository repository = (ArtifactRepository) i.next(); ArtifactRepository repository = (ArtifactRepository) i.next();
if ( !repositories.contains( repository ) ) if ( !repositories.contains( repository ) )
{ {
repositories.add( repository ); repositories.add( repository );
@ -628,8 +716,7 @@ public class DefaultMavenProjectBuilder
try try
{ {
project = project = processProjectLogic( pomLocation, project, externalProfileManager, projectDir, strict );
processProjectLogic( pomLocation, project, repositories, externalProfileManager, projectDir, strict );
} }
catch ( ModelInterpolationException e ) catch ( ModelInterpolationException e )
{ {
@ -639,8 +726,28 @@ public class DefaultMavenProjectBuilder
{ {
throw new InvalidProjectModelException( projectId, pomLocation, e.getMessage(), e ); throw new InvalidProjectModelException( projectId, pomLocation, e.getMessage(), e );
} }
projectCache.put( createCacheKey( project.getGroupId(), project.getArtifactId(), project.getVersion() ),
project ); projectCache.put( createCacheKey( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project );
// jvz:note
// this only happens if we are building from a source file
if ( projectDescriptor != null )
{
// Only translate the base directory for files in the source tree
pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor.getParentFile() );
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; return project;
} }
@ -668,8 +775,7 @@ public class DefaultMavenProjectBuilder
{ {
try try
{ {
return ProjectUtils.buildArtifactRepositories( model.getRepositories(), artifactRepositoryFactory, return ProjectUtils.buildArtifactRepositories( model.getRepositories(), artifactRepositoryFactory, container );
container );
} }
catch ( InvalidRepositoryException e ) catch ( InvalidRepositoryException e )
{ {
@ -686,18 +792,14 @@ public class DefaultMavenProjectBuilder
* the resolved source roots, etc for the parent - that occurs for the parent when it is constructed independently * 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 * and projects are not cached or reused
*/ */
private MavenProject processProjectLogic( String pomLocation, MavenProject project, List remoteRepositories, private MavenProject processProjectLogic( String pomLocation,
ProfileManager profileMgr, File projectDir, boolean strict ) MavenProject project,
ProfileManager profileMgr,
File projectDir,
boolean strict )
throws ProjectBuildingException, ModelInterpolationException, InvalidRepositoryException throws ProjectBuildingException, ModelInterpolationException, InvalidRepositoryException
{ {
Model model = project.getModel(); Model model = project.getModel();
String key = createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() );
if ( !modelCache.containsKey( key ) )
{
// clone the model because the profile injection below will modify this instance
CachedModel cachedModel = new CachedModel( project.getFile(), ModelUtils.cloneModel( model ) );
modelCache.put( key, cachedModel );
}
List activeProfiles = project.getActiveProfiles(); List activeProfiles = project.getActiveProfiles();
@ -787,7 +889,9 @@ public class DefaultMavenProjectBuilder
// TODO: these aren't taking active project artifacts into consideration in the reactor // TODO: these aren't taking active project artifacts into consideration in the reactor
project.setPluginArtifacts( createPluginArtifacts( projectId, project.getBuildPlugins() ) ); project.setPluginArtifacts( createPluginArtifacts( projectId, project.getBuildPlugins() ) );
project.setReportArtifacts( createReportArtifacts( projectId, project.getReportPlugins() ) ); project.setReportArtifacts( createReportArtifacts( projectId, project.getReportPlugins() ) );
project.setExtensionArtifacts( createExtensionArtifacts( projectId, project.getBuildExtensions() ) ); project.setExtensionArtifacts( createExtensionArtifacts( projectId, project.getBuildExtensions() ) );
return project; return project;
@ -796,9 +900,13 @@ public class DefaultMavenProjectBuilder
/** /**
* @noinspection CollectionDeclaredAsConcreteClass * @noinspection CollectionDeclaredAsConcreteClass
*/ */
private MavenProject assembleLineage( Model model, LinkedList lineage, ArtifactRepository localRepository, private MavenProject assembleLineage( Model model,
File projectDir, List parentSearchRepositories, LinkedList lineage,
Set aggregatedRemoteWagonRepositories, ProfileManager externalProfileManager, ArtifactRepository localRepository,
File projectDir,
List parentSearchRepositories,
Set aggregatedRemoteWagonRepositories,
ProfileManager externalProfileManager,
boolean strict ) boolean strict )
throws ProjectBuildingException, InvalidRepositoryException throws ProjectBuildingException, InvalidRepositoryException
{ {
@ -822,6 +930,7 @@ public class DefaultMavenProjectBuilder
if ( externalProfileManager != null ) if ( externalProfileManager != null )
{ {
profileManager.explicitlyActivate( externalProfileManager.getExplicitlyActivatedIds() ); profileManager.explicitlyActivate( externalProfileManager.getExplicitlyActivatedIds() );
profileManager.explicitlyDeactivate( externalProfileManager.getExplicitlyDeactivatedIds() ); profileManager.explicitlyDeactivate( externalProfileManager.getExplicitlyDeactivatedIds() );
} }
@ -839,8 +948,7 @@ public class DefaultMavenProjectBuilder
{ {
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
throw new ProjectBuildingException( projectId, "Failed to activate local (project-level) build profiles: " + throw new ProjectBuildingException( projectId, "Failed to activate local (project-level) build profiles: " + e.getMessage(), e );
e.getMessage(), e );
} }
MavenProject project = new MavenProject( model ); MavenProject project = new MavenProject( model );
@ -866,8 +974,7 @@ public class DefaultMavenProjectBuilder
else if ( parentModel.getGroupId().equals( model.getGroupId() ) && else if ( parentModel.getGroupId().equals( model.getGroupId() ) &&
parentModel.getArtifactId().equals( model.getArtifactId() ) ) parentModel.getArtifactId().equals( model.getArtifactId() ) )
{ {
throw new ProjectBuildingException( projectId, throw new ProjectBuildingException( projectId, "Parent element is a duplicate of " + "the current project " );
"Parent element is a duplicate of " + "the current project " );
} }
else if ( StringUtils.isEmpty( parentModel.getVersion() ) ) else if ( StringUtils.isEmpty( parentModel.getVersion() ) )
{ {
@ -877,17 +984,7 @@ public class DefaultMavenProjectBuilder
// the only way this will have a value is if we find the parent on disk... // the only way this will have a value is if we find the parent on disk...
File parentDescriptor = null; File parentDescriptor = null;
CachedModel cachedModel =
getCachedProject( parentModel.getGroupId(), parentModel.getArtifactId(), parentModel.getVersion() );
if ( cachedModel != null )
{
model = cachedModel.getModel();
parentDescriptor = cachedModel.getDescriptor();
}
else
{
model = null; model = null;
}
String parentRelativePath = parentModel.getRelativePath(); String parentRelativePath = parentModel.getRelativePath();
@ -1156,11 +1253,6 @@ public class DefaultMavenProjectBuilder
} }
} }
private CachedModel getCachedProject( String groupId, String artifactId, String version )
{
return (CachedModel) modelCache.get( createCacheKey( groupId, artifactId, version ) );
}
private static String createCacheKey( String groupId, String artifactId, String version ) private static String createCacheKey( String groupId, String artifactId, String version )
{ {
return groupId + ":" + artifactId + ":" + version; return groupId + ":" + artifactId + ":" + version;
@ -1298,53 +1390,6 @@ public class DefaultMavenProjectBuilder
return extensionArtifacts; return extensionArtifacts;
} }
public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository )
throws ProjectBuildingException
{
Model superModel = getSuperModel();
superModel.setGroupId( STANDALONE_SUPERPOM_GROUPID );
superModel.setArtifactId( STANDALONE_SUPERPOM_ARTIFACTID );
superModel.setVersion( STANDALONE_SUPERPOM_VERSION );
ProfileManager profileManager = new DefaultProfileManager( container );
List activeProfiles;
profileManager.addProfiles( superModel.getProfiles() );
String projectId = safeVersionlessKey( STANDALONE_SUPERPOM_GROUPID, STANDALONE_SUPERPOM_ARTIFACTID );
activeProfiles = injectActiveProfiles( profileManager, superModel );
MavenProject project = new MavenProject( superModel );
project.setActiveProfiles( activeProfiles );
project.setOriginalModel( superModel );
try
{
List remoteRepositories = buildArtifactRepositories( superModel );
project = processProjectLogic( "<Super-POM>", project, remoteRepositories, null, null, true );
project.setExecutionRoot( true );
return project;
}
catch ( ModelInterpolationException e )
{
throw new ProjectBuildingException( projectId, e.getMessage(), e );
}
catch ( InvalidRepositoryException e )
{
throw new ProjectBuildingException( projectId, e.getMessage(), e );
}
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// //
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -1364,27 +1409,4 @@ public class DefaultMavenProjectBuilder
{ {
this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
} }
private static class CachedModel
{
private File descriptor;
private Model model;
public CachedModel( File descriptor, Model model )
{
this.descriptor = descriptor;
this.model = model;
}
public File getDescriptor()
{
return descriptor;
}
public Model getModel()
{
return model;
}
}
} }