You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2006/02/17 17:27:16 UTC
svn commit: r378561 - in /maven/components/branches/maven-2.0.x:
maven-core-it/ maven-core/src/main/java/org/apache/maven/lifecycle/
maven-embedder/ maven-embedder/src/main/java/org/apache/maven/embedder/
maven-project/src/main/java/org/apache/maven/pr...
Author: jvanzyl
Date: Fri Feb 17 08:27:14 2006
New Revision: 378561
URL: http://svn.apache.org/viewcvs?rev=378561&view=rev
Log:
o merging revisions 371079 and 370406. the duplicate id problem and aligning the embedder with an installed version of maven.
Modified:
maven/components/branches/maven-2.0.x/maven-core-it/README.txt
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
maven/components/branches/maven-2.0.x/maven-embedder/pom.xml
maven/components/branches/maven-2.0.x/maven-embedder/run.sh
maven/components/branches/maven-2.0.x/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
Modified: maven/components/branches/maven-2.0.x/maven-core-it/README.txt
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-2.0.x/maven-core-it/README.txt?rev=378561&r1=378560&r2=378561&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-core-it/README.txt (original)
+++ maven/components/branches/maven-2.0.x/maven-core-it/README.txt Fri Feb 17 08:27:14 2006
@@ -240,7 +240,7 @@
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.
-it0088: Test path translation
+it0088: Test path translation.
it0089: Test that Checkstyle PackageNamesLoader.loadModuleFactory(..) method will complete as-is with
the context classloader available to the plugin.
Modified: maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=378561&r1=378560&r2=378561&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java (original)
+++ maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java Fri Feb 17 08:27:14 2006
@@ -120,6 +120,7 @@
if ( goals.isEmpty() && rootProject != null )
{
String goal = rootProject.getDefaultGoal();
+
if ( goal != null )
{
goals = Collections.singletonList( goal );
@@ -170,6 +171,7 @@
try
{
Map handlers = findArtifactTypeHandlers( project, session.getSettings(), session.getLocalRepository() );
+
artifactHandlerManager.addHandlers( handlers );
}
catch ( PluginNotFoundException e )
@@ -179,8 +181,11 @@
}
}
- private void executeTaskSegments( List taskSegments, ReactorManager rm, MavenSession session,
- MavenProject rootProject, EventDispatcher dispatcher )
+ private void executeTaskSegments( List taskSegments,
+ ReactorManager rm,
+ MavenSession session,
+ MavenProject rootProject,
+ EventDispatcher dispatcher )
throws LifecycleExecutionException, BuildFailureException
{
for ( Iterator it = taskSegments.iterator(); it.hasNext(); )
@@ -206,6 +211,7 @@
long buildStartTime = System.currentTimeMillis();
String target = rootProject.getId() + " ( " + segment + " )";
+
dispatcher.dispatchStart( event, target );
// only call once, with the top-level project (assumed to be provided as a parameter)...
@@ -213,8 +219,7 @@
{
String task = (String) goalIterator.next();
- executeGoalAndHandleFailures( task, session, rootProject, dispatcher, event, rm, buildStartTime,
- target );
+ executeGoalAndHandleFailures( task, session, rootProject, dispatcher, event, rm, buildStartTime,target );
}
rm.registerBuildSuccess( rootProject, System.currentTimeMillis() - buildStartTime );
@@ -229,8 +234,7 @@
getLogger().info( " " + segment );
- getLogger().info(
- "This project has been banned from further executions due to previous failures." );
+ getLogger().info("This project has been banned from further executions due to previous failures." );
line();
}
@@ -283,8 +287,7 @@
getLogger().info( " " + segment );
- getLogger().info(
- "This project has been banned from further executions due to previous failures." );
+ getLogger().info( "This project has been banned from further executions due to previous failures." );
line();
}
@@ -293,9 +296,14 @@
}
}
- private void executeGoalAndHandleFailures( String task, MavenSession session, MavenProject project,
- EventDispatcher dispatcher, String event, ReactorManager rm,
- long buildStartTime, String target )
+ private void executeGoalAndHandleFailures( String task,
+ MavenSession session,
+ MavenProject project,
+ EventDispatcher dispatcher,
+ String event,
+ ReactorManager rm,
+ long buildStartTime,
+ String target )
throws BuildFailureException, LifecycleExecutionException
{
try
Modified: maven/components/branches/maven-2.0.x/maven-embedder/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-2.0.x/maven-embedder/pom.xml?rev=378561&r1=378560&r2=378561&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-embedder/pom.xml (original)
+++ maven/components/branches/maven-2.0.x/maven-embedder/pom.xml Fri Feb 17 08:27:14 2006
@@ -13,6 +13,7 @@
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
+ <version>2.1-SNAPSHOT</version>
<configuration>
<descriptor>src/main/assembly/dep.xml</descriptor>
</configuration>
Modified: maven/components/branches/maven-2.0.x/maven-embedder/run.sh
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-2.0.x/maven-embedder/run.sh?rev=378561&r1=378560&r2=378561&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-embedder/run.sh (original)
+++ maven/components/branches/maven-2.0.x/maven-embedder/run.sh Fri Feb 17 08:27:14 2006
@@ -2,7 +2,7 @@
mvn clean:clean assembly:assembly
-CLASSPATH=target/maven-embedder-2.0-dep.jar
+CLASSPATH=target/maven-embedder-2.1-SNAPSHOT-dep.jar
javac -classpath $CLASSPATH Plugin.java
Modified: maven/components/branches/maven-2.0.x/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-2.0.x/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java?rev=378561&r1=378560&r2=378561&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java (original)
+++ maven/components/branches/maven-2.0.x/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java Fri Feb 17 08:27:14 2006
@@ -137,44 +137,23 @@
// User options
// ----------------------------------------------------------------------
- private boolean pluginUpdateOverride;
-
- private boolean checkLatestPluginVersion;
-
+ // release plugin uses this but in IDE there will probably always be some form of interaction.
private boolean interactiveMode;
- private boolean usePluginRegistry;
-
private boolean offline;
- private boolean updateSnapshots;
-
private String globalChecksumPolicy;
+ /**
+ * This option determines whether the embedder is to be aligned to the user
+ * installation.
+ */
+ private boolean alignWithUserInstallation;
+
// ----------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------
- public void setPluginUpdateOverride( boolean pluginUpdateOverride )
- {
- this.pluginUpdateOverride = pluginUpdateOverride;
- }
-
- public boolean isPluginUpdateOverride()
- {
- return pluginUpdateOverride;
- }
-
- public void setCheckLatestPluginVersion( boolean checkLatestPluginVersion )
- {
- this.checkLatestPluginVersion = checkLatestPluginVersion;
- }
-
- public boolean isCheckLatestPluginVersion()
- {
- return checkLatestPluginVersion;
- }
-
public void setInteractiveMode( boolean interactiveMode )
{
this.interactiveMode = interactiveMode;
@@ -185,16 +164,6 @@
return interactiveMode;
}
- public void setUsePluginRegistry( boolean usePluginRegistry )
- {
- this.usePluginRegistry = usePluginRegistry;
- }
-
- public boolean isUsePluginRegistry()
- {
- return usePluginRegistry;
- }
-
public void setOffline( boolean offline )
{
this.offline = offline;
@@ -205,24 +174,24 @@
return offline;
}
- public void setUpdateSnapshots( boolean updateSnapshots )
+ public void setGlobalChecksumPolicy( String globalChecksumPolicy )
{
- this.updateSnapshots = updateSnapshots;
+ this.globalChecksumPolicy = globalChecksumPolicy;
}
- public boolean isUpdateSnapshots()
+ public String getGlobalChecksumPolicy()
{
- return updateSnapshots;
+ return globalChecksumPolicy;
}
- public void setGlobalChecksumPolicy( String globalChecksumPolicy )
+ public boolean isAlignWithUserInstallation()
{
- this.globalChecksumPolicy = globalChecksumPolicy;
+ return alignWithUserInstallation;
}
- public String getGlobalChecksumPolicy()
+ public void setAlignWithUserInstallation( boolean alignWithUserInstallation )
{
- return globalChecksumPolicy;
+ this.alignWithUserInstallation = alignWithUserInstallation;
}
/**
@@ -398,7 +367,6 @@
// ----------------------------------------------------------------------
// TODO: should we allow the passing in of a settings object so that everything can be taken from the client env
-
// TODO: transfer listener
// TODO: logger
@@ -543,14 +511,7 @@
{
RuntimeInfo runtimeInfo = new RuntimeInfo( settings );
- if ( pluginUpdateOverride )
- {
- runtimeInfo.setPluginUpdateOverride( Boolean.TRUE );
- }
- else
- {
- runtimeInfo.setPluginUpdateOverride( Boolean.FALSE );
- }
+ runtimeInfo.setPluginUpdateOverride( Boolean.FALSE );
return runtimeInfo;
}
@@ -584,6 +545,8 @@
public void start()
throws MavenEmbedderException
{
+ detectUserInstallation();
+
// ----------------------------------------------------------------------
// Set the maven.home system property which is need by components like
// the plugin registry builder.
@@ -624,52 +587,21 @@
mavenProjectBuilder = (MavenProjectBuilder) embedder.lookup( MavenProjectBuilder.ROLE );
- artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder.lookup( ArtifactRepositoryFactory.ROLE );
-
- lifecycleExecutor = (LifecycleExecutor) embedder.lookup( LifecycleExecutor.ROLE );
-
- wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE );
-
- artifactFactory = (ArtifactFactory) embedder.lookup( ArtifactFactory.ROLE );
-
- artifactResolver = (ArtifactResolver) embedder.lookup( ArtifactResolver.ROLE );
-
// ----------------------------------------------------------------------
- // If an explicit local repository has not been set then we will use the
- // setting builder to use the maven defaults to help us find one.
+ // Artifact related components
// ----------------------------------------------------------------------
- if ( localRepositoryDirectory == null )
- {
- settingsBuilder = (MavenSettingsBuilder) embedder.lookup( MavenSettingsBuilder.ROLE );
-
- try
- {
- settings = settingsBuilder.buildSettings();
- }
- catch ( IOException e )
- {
- throw new MavenEmbedderException( "Error creating settings.", e );
- }
- catch ( XmlPullParserException e )
- {
- throw new MavenEmbedderException( "Error creating settings.", e );
- }
- }
- else
- {
- settings = new Settings();
+ artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder.lookup( ArtifactRepositoryFactory.ROLE );
- settings.setLocalRepository( localRepositoryDirectory.getAbsolutePath() );
- }
+ artifactFactory = (ArtifactFactory) embedder.lookup( ArtifactFactory.ROLE );
- settings.setRuntimeInfo( createRuntimeInfo( settings ) );
+ artifactResolver = (ArtifactResolver) embedder.lookup( ArtifactResolver.ROLE );
- settings.setOffline( offline );
+ lifecycleExecutor = (LifecycleExecutor) embedder.lookup( LifecycleExecutor.ROLE );
- settings.setUsePluginRegistry( usePluginRegistry );
+ wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE );
- settings.setInteractiveMode( interactiveMode );
+ createMavenSettings();
localRepository = createLocalRepository( settings );
}
@@ -686,6 +618,76 @@
throw new MavenEmbedderException( "Cannot lookup required component.", e );
}
}
+
+ // ----------------------------------------------------------------------
+ //
+ // ----------------------------------------------------------------------
+
+ private void detectUserInstallation()
+ {
+ if ( new File( userHome, ".m2" ).exists() )
+ {
+ alignWithUserInstallation = true;
+ }
+ }
+
+ /**
+ * Create the Settings that will be used with the embedder. If we are aligning with the user
+ * installation then we lookup the standard settings builder and use that to create our
+ * settings. Otherwise we constructs a settings object and populate the information
+ * ourselves.
+ *
+ * @throws MavenEmbedderException
+ * @throws ComponentLookupException
+ */
+ private void createMavenSettings()
+ throws MavenEmbedderException, ComponentLookupException
+ {
+ if ( alignWithUserInstallation )
+ {
+ // ----------------------------------------------------------------------
+ // We will use the standard method for creating the settings. This
+ // method reproduces the method of building the settings from the CLI
+ // mode of operation.
+ // ----------------------------------------------------------------------
+
+ settingsBuilder = (MavenSettingsBuilder) embedder.lookup( MavenSettingsBuilder.ROLE );
+
+ try
+ {
+ settings = settingsBuilder.buildSettings();
+ }
+ catch ( IOException e )
+ {
+ throw new MavenEmbedderException( "Error creating settings.", e );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new MavenEmbedderException( "Error creating settings.", e );
+ }
+ }
+ else
+ {
+ if ( localRepository == null )
+ {
+ throw new IllegalArgumentException( "When not aligning with a user install you must specify a local repository location using the setLocalRepositoryDirectory( File ) method." );
+ }
+
+ settings = new Settings();
+
+ settings.setLocalRepository( localRepositoryDirectory.getAbsolutePath() );
+
+ settings.setRuntimeInfo( createRuntimeInfo( settings ) );
+
+ settings.setOffline( offline );
+
+ settings.setInteractiveMode( interactiveMode );
+ }
+ }
+
+ // ----------------------------------------------------------------------
+ // Lifecycle
+ // ----------------------------------------------------------------------
public void stop()
throws MavenEmbedderException
Modified: maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?rev=378561&r1=378560&r2=378561&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java (original)
+++ maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java Fri Feb 17 08:27:14 2006
@@ -93,6 +93,40 @@
import java.util.Map;
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
* trygvis Exp $
@@ -118,6 +152,8 @@
private ModelValidator validator;
+ private Map projectCache = new HashMap();
+
// TODO: make it a component
private MavenXpp3Reader modelReader;
@@ -137,12 +173,8 @@
private WagonManager wagonManager;
- private final Map modelCache = new HashMap();
-
public static final String MAVEN_MODEL_VERSION = "4.0.0";
- private Map projectCache = new HashMap();
-
public void initialize()
{
modelReader = new MavenXpp3Reader();
@@ -152,18 +184,118 @@
// 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 )
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException
{
return buildWithDependencies( projectDescriptor, localRepository, profileManager, null );
}
+ // note:jvz This was added for the embedder.
+
/**
* @todo move to metadatasource itself?
*/
- public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository,
- ProfileManager profileManager, TransferListener transferListener )
+ public MavenProject buildWithDependencies( File projectDescriptor,
+ ArtifactRepository localRepository,
+ ProfileManager profileManager,
+ TransferListener transferListener )
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException
{
MavenProject project = build( projectDescriptor, localRepository, profileManager );
@@ -216,6 +348,10 @@
return project;
}
+ // ----------------------------------------------------------------------
+ //
+ // ----------------------------------------------------------------------
+
private void ensureMetadataSourceIsInitialized()
throws ProjectBuildingException
{
@@ -267,47 +403,25 @@
return map;
}
- public MavenProject build( File projectDescriptor, ArtifactRepository localRepository,
- ProfileManager profileManager )
- throws ProjectBuildingException
- {
- 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 )
+ private MavenProject buildFromSourceFileInternal( File projectDescriptor,
+ ArtifactRepository localRepository,
+ ProfileManager profileManager,
+ boolean checkDistributionManagementStatus )
throws ProjectBuildingException
{
Model model = readModel( "unknown", projectDescriptor, true );
- // Always cache files in the source tree over those in the repository
- CachedModel cachedModel = new CachedModel( projectDescriptor, model );
-
- 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() ),
- projectDescriptor.getAbsoluteFile().getParentFile(), profileManager, true );
+ MavenProject project = buildInternal( projectDescriptor.getAbsolutePath(),
+ model,
+ localRepository,
+ buildArtifactRepositories( getSuperModel() ),
+ projectDescriptor,
+ profileManager,
+ true );
if ( checkDistributionManagementStatus )
{
- if ( project.getDistributionManagement() != null &&
- project.getDistributionManagement().getStatus() != null )
+ if ( project.getDistributionManagement() != null && project.getDistributionManagement().getStatus() != null )
{
String projectId = safeVersionlessKey( project.getGroupId(), project.getArtifactId() );
@@ -316,46 +430,13 @@
}
}
- // 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;
}
- public MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories,
- ArtifactRepository localRepository )
- throws ProjectBuildingException
- {
- 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 )
+ private Model findModelFromRepository( Artifact artifact,
+ List remoteArtifactRepositories,
+ ArtifactRepository localRepository,
+ boolean allowStubModel )
throws ProjectBuildingException
{
Artifact projectArtifact;
@@ -367,80 +448,77 @@
}
else
{
- getLogger().warn( "Attempting to build MavenProject instance for Artifact of type: " + artifact.getType() +
- "; constructing POM artifact instead." );
+ getLogger().warn( "Attempting to build MavenProject instance for Artifact of type: " + artifact.getType() + "; constructing POM artifact instead." );
- projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
- artifact.getVersion(), artifact.getScope() );
+ projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(),
+ artifact.getArtifactId(),
+ artifact.getVersion(),
+ artifact.getScope() );
}
- CachedModel cachedModel = getCachedProject( projectArtifact.getGroupId(), projectArtifact.getArtifactId(),
- projectArtifact.getVersion() );
Model model;
- if ( cachedModel == null )
+
+ String projectId = ArtifactUtils.versionlessKey( projectArtifact );
+
+ try
{
- String projectId = ArtifactUtils.versionlessKey( projectArtifact );
+ artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository );
- try
- {
- 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;
- ArtifactStatus status = ArtifactStatus.NONE;
+ String downloadUrl = null;
- DistributionManagement distributionManagement = model.getDistributionManagement();
- if ( distributionManagement != null )
- {
- downloadUrl = distributionManagement.getDownloadUrl();
+ ArtifactStatus status = ArtifactStatus.NONE;
- status = ArtifactStatus.valueOf( distributionManagement.getStatus() );
- }
+ DistributionManagement distributionManagement = model.getDistributionManagement();
- checkStatusAndUpdate( projectArtifact, status, file, remoteArtifactRepositories, localRepository );
+ if ( distributionManagement != null )
+ {
+ downloadUrl = distributionManagement.getDownloadUrl();
- // TODO: this is gross. Would like to give it the whole model, but maven-artifact shouldn't depend on that
- // Can a maven-core implementation of the Artifact interface store it, and be used in the exceptions?
- if ( downloadUrl != null )
- {
- projectArtifact.setDownloadUrl( downloadUrl );
- }
- else
- {
- projectArtifact.setDownloadUrl( model.getUrl() );
- }
+ status = ArtifactStatus.valueOf( distributionManagement.getStatus() );
}
- catch ( ArtifactResolutionException e )
+
+ checkStatusAndUpdate( projectArtifact, status, file, remoteArtifactRepositories, localRepository );
+
+ // TODO: this is gross. Would like to give it the whole model, but maven-artifact shouldn't depend on that
+ // Can a maven-core implementation of the Artifact interface store it, and be used in the exceptions?
+ if ( downloadUrl != null )
{
- throw new ProjectBuildingException( projectId, "Error getting POM for '" + projectId +
- "' from the repository: " + e.getMessage(), e );
+ projectArtifact.setDownloadUrl( downloadUrl );
}
- catch ( ArtifactNotFoundException e )
+ else
{
- if ( allowStubModel )
- {
- getLogger().debug( "Artifact not found - using stub model: " + e.getMessage() );
- model = createStubModel( projectArtifact );
- }
- else
- {
- throw new ProjectBuildingException( projectId, "POM '" + projectId + "' not found in repository: " +
- e.getMessage(), e );
- }
+ projectArtifact.setDownloadUrl( model.getUrl() );
}
}
- else
+ catch ( ArtifactResolutionException e )
{
- model = cachedModel.getModel();
+ throw new ProjectBuildingException( projectId, "Error getting POM for '" + projectId + "' from the repository: " + e.getMessage(), e );
+ }
+ catch ( ArtifactNotFoundException e )
+ {
+ if ( allowStubModel )
+ {
+ getLogger().debug( "Artifact not found - using stub model: " + e.getMessage() );
+
+ model = createStubModel( projectArtifact );
+ }
+ else
+ {
+ throw new ProjectBuildingException( projectId, "POM '" + projectId + "' not found in repository: " + e.getMessage(), e );
+ }
}
return model;
}
- private void checkStatusAndUpdate( Artifact projectArtifact, ArtifactStatus status, File file,
- List remoteArtifactRepositories, ArtifactRepository localRepository )
+ private void checkStatusAndUpdate( Artifact projectArtifact,
+ ArtifactStatus status, File file,
+ List remoteArtifactRepositories,
+ ArtifactRepository localRepository )
throws ArtifactNotFoundException
{
// TODO: configurable actions dependant on status
@@ -476,50 +554,52 @@
}
}
+ // 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 )
{
getLogger().debug( "Using defaults for missing POM " + projectArtifact );
Model model = new Model();
+
model.setModelVersion( "4.0.0" );
+
model.setArtifactId( projectArtifact.getArtifactId() );
+
model.setGroupId( projectArtifact.getGroupId() );
+
model.setVersion( projectArtifact.getVersion() );
+
// TODO: not correct in some instances
model.setPackaging( projectArtifact.getType() );
model.setDistributionManagement( new DistributionManagement() );
- 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 );
+ model.getDistributionManagement().setStatus( ArtifactStatus.GENERATED.toString() );
- 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;
}
- private MavenProject build( String pomLocation, Model model, ArtifactRepository localRepository,
- List parentSearchRepositories, File projectDir, ProfileManager externalProfileManager,
- boolean strict )
+ // jvz:note
+ // 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 )
throws ProjectBuildingException
{
+ File projectDir = null;
+
+ if ( projectDescriptor != null )
+ {
+ projectDir = projectDescriptor.getAbsoluteFile().getParentFile();
+ }
+
Model superModel = getSuperModel();
ProfileManager superProjectProfileManager = new DefaultProfileManager( container );
@@ -573,8 +653,7 @@
ArtifactRepository artifactRepo = null;
try
{
- artifactRepo =
- ProjectUtils.buildArtifactRepository( mavenRepo, artifactRepositoryFactory, container );
+ artifactRepo = ProjectUtils.buildArtifactRepository( mavenRepo, artifactRepositoryFactory, container );
}
catch ( InvalidRepositoryException e )
{
@@ -590,8 +669,14 @@
MavenProject project = null;
try
{
- project = assembleLineage( model, lineage, localRepository, projectDir, parentSearchRepositories,
- aggregatedRemoteWagonRepositories, externalProfileManager, strict );
+ project = assembleLineage( model,
+ lineage,
+ localRepository,
+ projectDir,
+ parentSearchRepositories,
+ aggregatedRemoteWagonRepositories,
+ externalProfileManager,
+ strict );
}
catch ( InvalidRepositoryException e )
{
@@ -616,10 +701,13 @@
// only add the super repository if it wasn't overridden by a profile or project
List repositories = new ArrayList( aggregatedRemoteWagonRepositories );
+
List superRepositories = buildArtifactRepositories( superModel );
+
for ( Iterator i = superRepositories.iterator(); i.hasNext(); )
{
ArtifactRepository repository = (ArtifactRepository) i.next();
+
if ( !repositories.contains( repository ) )
{
repositories.add( repository );
@@ -628,8 +716,7 @@
try
{
- project =
- processProjectLogic( pomLocation, project, repositories, externalProfileManager, projectDir, strict );
+ project = processProjectLogic( pomLocation, project, externalProfileManager, projectDir, strict );
}
catch ( ModelInterpolationException e )
{
@@ -639,8 +726,28 @@
{
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;
}
@@ -668,8 +775,7 @@
{
try
{
- return ProjectUtils.buildArtifactRepositories( model.getRepositories(), artifactRepositoryFactory,
- container );
+ return ProjectUtils.buildArtifactRepositories( model.getRepositories(), artifactRepositoryFactory, container );
}
catch ( InvalidRepositoryException e )
{
@@ -686,18 +792,14 @@
* 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( String pomLocation, MavenProject project, List remoteRepositories,
- ProfileManager profileMgr, File projectDir, boolean strict )
+ private MavenProject processProjectLogic( String pomLocation,
+ MavenProject project,
+ ProfileManager profileMgr,
+ File projectDir,
+ boolean strict )
throws ProjectBuildingException, ModelInterpolationException, InvalidRepositoryException
{
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();
@@ -787,7 +889,9 @@
// TODO: these aren't taking active project artifacts into consideration in the reactor
project.setPluginArtifacts( createPluginArtifacts( projectId, project.getBuildPlugins() ) );
+
project.setReportArtifacts( createReportArtifacts( projectId, project.getReportPlugins() ) );
+
project.setExtensionArtifacts( createExtensionArtifacts( projectId, project.getBuildExtensions() ) );
return project;
@@ -796,9 +900,13 @@
/**
* @noinspection CollectionDeclaredAsConcreteClass
*/
- private MavenProject assembleLineage( Model model, LinkedList lineage, ArtifactRepository localRepository,
- File projectDir, List parentSearchRepositories,
- Set aggregatedRemoteWagonRepositories, ProfileManager externalProfileManager,
+ private MavenProject assembleLineage( Model model,
+ LinkedList lineage,
+ ArtifactRepository localRepository,
+ File projectDir,
+ List parentSearchRepositories,
+ Set aggregatedRemoteWagonRepositories,
+ ProfileManager externalProfileManager,
boolean strict )
throws ProjectBuildingException, InvalidRepositoryException
{
@@ -822,6 +930,7 @@
if ( externalProfileManager != null )
{
profileManager.explicitlyActivate( externalProfileManager.getExplicitlyActivatedIds() );
+
profileManager.explicitlyDeactivate( externalProfileManager.getExplicitlyDeactivatedIds() );
}
@@ -839,8 +948,7 @@
{
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
- throw new ProjectBuildingException( projectId, "Failed to activate local (project-level) build profiles: " +
- e.getMessage(), e );
+ throw new ProjectBuildingException( projectId, "Failed to activate local (project-level) build profiles: " + e.getMessage(), e );
}
MavenProject project = new MavenProject( model );
@@ -866,8 +974,7 @@
else if ( parentModel.getGroupId().equals( model.getGroupId() ) &&
parentModel.getArtifactId().equals( model.getArtifactId() ) )
{
- throw new ProjectBuildingException( projectId,
- "Parent element is a duplicate of " + "the current project " );
+ throw new ProjectBuildingException( projectId, "Parent element is a duplicate of " + "the current project " );
}
else if ( StringUtils.isEmpty( parentModel.getVersion() ) )
{
@@ -877,17 +984,7 @@
// the only way this will have a value is if we find the parent on disk...
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();
@@ -1156,11 +1253,6 @@
}
}
- 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 )
{
return groupId + ":" + artifactId + ":" + version;
@@ -1298,53 +1390,6 @@
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 );
- }
- }
-
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
@@ -1363,28 +1408,5 @@
throws ContextException
{
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;
- }
}
}