diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java b/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
index 60b87a19b4..489ec83a85 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
@@ -43,7 +43,10 @@ public class DefaultArtifact
private String path;
- public DefaultArtifact( String groupId, String artifactId, String version, String scope, String type,
+ /**
+ * @todo this should be replaced by type handler
+ */
+ public DefaultArtifact( String groupId, String artifactId, String version, String scope, String type,
String extension )
{
this.groupId = groupId;
@@ -54,15 +57,9 @@ public DefaultArtifact( String groupId, String artifactId, String version, Strin
this.extension = extension;
}
- /** @todo this should be replaced by type handler */
- public DefaultArtifact( String groupId, String artifactId, String version, String type, String extension )
- {
- this( groupId, artifactId, version, SCOPE_COMPILE, type, extension );
- }
-
public DefaultArtifact( String groupId, String artifactId, String version, String type )
{
- this( groupId, artifactId, version, type, type );
+ this( groupId, artifactId, version, null, type, type );
}
public String getScope()
@@ -135,17 +132,12 @@ public File getChecksumFile()
public String getId()
{
- return getGroupId() + ":" +
- getArtifactId() + ":" +
- getType() + ":" +
- getVersion();
+ return getGroupId() + ":" + getArtifactId() + ":" + getType() + ":" + getVersion();
}
public String getConflictId()
{
- return getGroupId() + ":" +
- getArtifactId() + ":" +
- getType();
+ return getGroupId() + ":" + getArtifactId() + ":" + getType();
}
// ----------------------------------------------------------------------
@@ -166,9 +158,7 @@ public boolean equals( Object o )
{
Artifact other = (Artifact) o;
- return this.groupId.equals( other.getGroupId() ) &&
- this.artifactId.equals( other.getArtifactId() ) &&
- this.version.equals( other.getVersion() ) &&
- this.type.equals( other.getType() );
+ return this.groupId.equals( other.getGroupId() ) && this.artifactId.equals( other.getArtifactId() ) && this.version.equals(
+ other.getVersion() ) && this.type.equals( other.getType() );
}
}
diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/ArtifactComponentTestCase.java b/maven-artifact/src/test/java/org/apache/maven/artifact/ArtifactComponentTestCase.java
index ea18f9cc05..bcd3d62ce0 100644
--- a/maven-artifact/src/test/java/org/apache/maven/artifact/ArtifactComponentTestCase.java
+++ b/maven-artifact/src/test/java/org/apache/maven/artifact/ArtifactComponentTestCase.java
@@ -16,17 +16,17 @@
package org.apache.maven.artifact;
-import org.codehaus.plexus.PlexusTestCase;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.codehaus.plexus.PlexusTestCase;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
-import java.util.Set;
import java.util.HashSet;
+import java.util.Set;
/**
* @author Jason van Zyl
@@ -47,8 +47,11 @@ protected void setUp()
protected abstract String component();
- /** Return an existing file, not a directory - causes creation to fail. */
- protected ArtifactRepository badLocalRepository() throws IOException
+ /**
+ * Return an existing file, not a directory - causes creation to fail.
+ */
+ protected ArtifactRepository badLocalRepository()
+ throws IOException
{
ArtifactRepository localRepository = new ArtifactRepository();
@@ -225,7 +228,12 @@ protected Artifact createArtifact( String artifactId, String version )
protected Artifact createArtifact( String artifactId, String version, String type )
{
- return new DefaultArtifact( "maven", artifactId, version, type );
+ return createArtifact( "maven", artifactId, version, type );
+ }
+
+ protected Artifact createArtifact( String groupId, String artifactId, String version, String type )
+ {
+ return new DefaultArtifact( groupId, artifactId, version, Artifact.SCOPE_COMPILE, type, type );
}
protected void deleteLocalArtifact( Artifact artifact )
diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java
index 6c806f84c0..2956c9115c 100644
--- a/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java
+++ b/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java
@@ -18,24 +18,22 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactComponentTestCase;
-import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.HashSet;
import java.util.Set;
-/**
- * @author Jason van Zyl
- * @version $Id$
- */
-
// It would be cool if there was a hook that i could use to setup a test environment.
// I want to setup a local/remote repositories for testing but i don't want to have
// to change them when i change the layout of the repositories. So i want to generate
// the structure i want to test by using the artifact handler manager which dictates
// the layout used for a particular artifact type.
+/**
+ * @author Jason van Zyl
+ * @version $Id$
+ */
public class ArtifactResolverTest
extends ArtifactComponentTestCase
{
@@ -127,6 +125,11 @@ public void testResolutionOfASetOfArtifactsWhereTheArtifactsAreNotPresentInTheLo
assertTrue( resolvedArtifacts.contains( f ) );
}
+ protected Artifact createArtifact( String groupId, String artifactId, String version, String type )
+ {
+ // for the anonymous classes
+ return super.createArtifact( groupId, artifactId, version, type );
+ }
public void testTransitiveResolutionWhereAllArtifactsArePresentInTheLocalRepository()
throws Exception
@@ -143,17 +146,15 @@ public Set retrieve( Artifact artifact, ArtifactRepository localRepository, Set
if ( artifact.getArtifactId().equals( "g" ) )
{
- dependencies.add( new DefaultArtifact( "maven", "h", "1.0", "jar" ) );
+ dependencies.add( createArtifact( "maven", "h", "1.0", "jar" ) );
}
return dependencies;
}
};
- ArtifactResolutionResult result = artifactResolver.resolveTransitively( g,
- remoteRepositories(),
- localRepository(),
- mds );
+ ArtifactResolutionResult result = artifactResolver.resolveTransitively( g, remoteRepositories(),
+ localRepository(), mds );
assertEquals( 2, result.getArtifacts().size() );
@@ -183,17 +184,15 @@ public Set retrieve( Artifact artifact, ArtifactRepository localRepository, Set
if ( artifact.getArtifactId().equals( "i" ) )
{
- dependencies.add( new DefaultArtifact( "maven", "j", "1.0", "jar" ) );
+ dependencies.add( createArtifact( "maven", "j", "1.0", "jar" ) );
}
return dependencies;
}
};
- ArtifactResolutionResult result = artifactResolver.resolveTransitively( i,
- remoteRepositories(),
- localRepository(),
- mds );
+ ArtifactResolutionResult result = artifactResolver.resolveTransitively( i, remoteRepositories(),
+ localRepository(), mds );
assertEquals( 2, result.getArtifacts().size() );
diff --git a/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java
index 5fb5470f8d..5a290fdbc0 100644
--- a/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java
+++ b/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java
@@ -16,21 +16,19 @@
* limitations under the License.
*/
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.factory.DefaultArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
-import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import java.io.FileReader;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
import java.util.Set;
/**
@@ -43,6 +41,9 @@ public class MavenMetadataSource
private MavenProjectBuilder mavenProjectBuilder;
private ArtifactResolver artifactResolver;
+ // TODO: configure?
+ protected ArtifactFactory artifactFactory = new DefaultArtifactFactory();
+
/**
* @todo remove.
*/
@@ -66,8 +67,9 @@ public Set retrieve( Artifact artifact, ArtifactRepository localRepository, Set
throws ArtifactMetadataRetrievalException
{
Set artifacts;
- Artifact metadataArtifact = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(),
- artifact.getVersion(), "pom" );
+ Artifact metadataArtifact = artifactFactory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(),
+ artifact.getVersion(), artifact.getScope(), "pom",
+ "pom", null );
try
{
artifactResolver.resolve( metadataArtifact, remoteRepositories, localRepository );
@@ -78,12 +80,14 @@ public Set retrieve( Artifact artifact, ArtifactRepository localRepository, Set
if ( mavenProjectBuilder != null )
{
MavenProject project = mavenProjectBuilder.build( metadataArtifact.getFile(), localRepository );
- artifacts = createArtifacts( project.getDependencies(), artifact.getScope(), localRepository );
+ artifacts =
+ artifactFactory.createArtifacts( project.getDependencies(), localRepository, artifact.getScope() );
}
else
{
Model model = reader.read( new FileReader( metadataArtifact.getFile() ) );
- artifacts = createArtifacts( model.getDependencies(), artifact.getScope(), localRepository );
+ artifacts =
+ artifactFactory.createArtifacts( model.getDependencies(), localRepository, artifact.getScope() );
}
}
catch ( ArtifactResolutionException e )
@@ -97,39 +101,4 @@ public Set retrieve( Artifact artifact, ArtifactRepository localRepository, Set
}
return artifacts;
}
-
- protected Set createArtifacts( List dependencies, String scope, ArtifactRepository localRepository )
- {
- Set projectArtifacts = new HashSet();
- for ( Iterator i = dependencies.iterator(); i.hasNext(); )
- {
- Dependency d = (Dependency) i.next();
- Artifact artifact = createArtifact( d, scope, localRepository );
- if ( artifact != null )
- {
- projectArtifacts.add( artifact );
- }
- }
- return projectArtifacts;
- }
-
- protected Artifact createArtifact( Dependency dependency, String scope, ArtifactRepository localRepository )
- {
- // TODO: can refactor
- String requestedScope = dependency.getScope();
- if ( Artifact.SCOPE_TEST.equals( scope ) && Artifact.SCOPE_TEST.equals( requestedScope ) )
- {
- return null;
- }
-
- // TODO: duplicated with the ArtifactFactory, localRepository not used (should be used here to resolve path?
- // TODO: scope handler
- String desiredScope = Artifact.SCOPE_RUNTIME;
- if ( Artifact.SCOPE_TEST.equals( requestedScope ) || Artifact.SCOPE_TEST.equals( scope ) )
- {
- desiredScope = Artifact.SCOPE_TEST;
- }
- return new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(),
- desiredScope, dependency.getType(), dependency.getType() );
- }
}
diff --git a/maven-core/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java b/maven-core/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java
index c6b3cfd4f3..d5a2a135db 100644
--- a/maven-core/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java
+++ b/maven-core/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java
@@ -1,20 +1,19 @@
package org.apache.maven.artifact.factory;
-/* ====================================================================
- * Copyright 2001-2004 The Apache Software Foundation.
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ====================================================================
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
import org.apache.maven.artifact.Artifact;
@@ -28,7 +27,10 @@ public interface ArtifactFactory
{
static String ROLE = ArtifactFactory.class.getName();
- Set createArtifacts( List dependencies, ArtifactRepository localRepository );
+ Set createArtifacts( List dependencies, ArtifactRepository localRepository, String inheritedScope );
- Artifact createArtifact( Dependency dependency, ArtifactRepository localRepository );
+ Artifact createArtifact( Dependency dependency, ArtifactRepository localRepository, String inheritedScope );
+
+ Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type,
+ String extension, String inheritedScope );
}
diff --git a/maven-core/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java b/maven-core/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java
index 3ceedbb862..c0d1cf9243 100644
--- a/maven-core/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java
+++ b/maven-core/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java
@@ -1,20 +1,19 @@
package org.apache.maven.artifact.factory;
-/* ====================================================================
- * Copyright 2001-2004 The Apache Software Foundation.
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ====================================================================
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
import org.apache.maven.artifact.Artifact;
@@ -30,7 +29,7 @@
public class DefaultArtifactFactory
implements ArtifactFactory
{
- public Set createArtifacts( List dependencies, ArtifactRepository localRepository )
+ public Set createArtifacts( List dependencies, ArtifactRepository localRepository, String inheritedScope )
{
Set projectArtifacts = new HashSet();
@@ -38,23 +37,44 @@ public Set createArtifacts( List dependencies, ArtifactRepository localRepositor
{
Dependency d = (Dependency) i.next();
- Artifact artifact = createArtifact( d, localRepository );
-
- projectArtifacts.add( artifact );
+ Artifact artifact = createArtifact( d, localRepository, inheritedScope );
+ if ( artifact != null )
+ {
+ projectArtifacts.add( artifact );
+ }
}
return projectArtifacts;
}
- public Artifact createArtifact( Dependency dependency, ArtifactRepository localRepository )
+ public Artifact createArtifact( Dependency dependency, ArtifactRepository localRepository, String inheritedScope )
{
- Artifact artifact = new DefaultArtifact( dependency.getGroupId(),
- dependency.getArtifactId(),
- dependency.getVersion(),
- dependency.getScope(),
- dependency.getType(),
- dependency.getType() );
+ return createArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(),
+ dependency.getScope(), dependency.getType(), dependency.getType(), inheritedScope );
+ }
- return artifact;
+ public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type,
+ String extension, String inheritedScope )
+ {
+ // TODO: can refactor, use scope handler
+
+ // if this artifact is test, and the dependency is test, don't transitively create
+ if ( Artifact.SCOPE_TEST.equals( inheritedScope ) && Artifact.SCOPE_TEST.equals( scope ) )
+ {
+ return null;
+ }
+
+ // TODO: localRepository not used (should be used here to resolve path?
+ String desiredScope = Artifact.SCOPE_RUNTIME;
+ if ( Artifact.SCOPE_COMPILE.equals( scope ) && inheritedScope == null )
+ {
+ desiredScope = Artifact.SCOPE_COMPILE;
+ }
+
+ if ( Artifact.SCOPE_TEST.equals( scope ) || Artifact.SCOPE_TEST.equals( inheritedScope ) )
+ {
+ desiredScope = Artifact.SCOPE_TEST;
+ }
+ return new DefaultArtifact( groupId, artifactId, version, desiredScope, type, extension );
}
}
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
index 3aedb6f434..6d19c17d52 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
@@ -1,22 +1,24 @@
package org.apache.maven.plugin;
/*
- * ====================================================================
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache
- * License, Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
- * ====================================================================
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.MavenMetadataSource;
-import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
@@ -65,9 +67,7 @@ public class DefaultPluginManager
protected Map pluginDescriptors;
- protected ArtifactResolver artifactResolver;
-
- protected ArtifactHandlerManager artifactHandlerManager;
+// protected ArtifactHandlerManager artifactHandlerManager;
protected PlexusContainer container;
@@ -77,8 +77,6 @@ public class DefaultPluginManager
protected ArtifactFilter artifactFilter;
- protected MavenProjectBuilder mavenProjectBuilder;
-
public DefaultPluginManager()
{
mojoDescriptors = new HashMap();
@@ -101,7 +99,7 @@ public Map getMojoDescriptors()
* Mojo descriptors are looked up using their id which is of the form
* : . So this might be archetype:create for example which
* is the create mojo that resides in the archetype plugin.
- *
+ *
* @param name
* @return
*/
@@ -121,7 +119,8 @@ public PluginDescriptor getPluginDescriptor( String pluginId )
private Set pluginsInProcess = new HashSet();
- public void processPluginDescriptor( MavenPluginDescriptor mavenPluginDescriptor ) throws CycleDetectedException
+ public void processPluginDescriptor( MavenPluginDescriptor mavenPluginDescriptor )
+ throws CycleDetectedException
{
if ( pluginsInProcess.contains( mavenPluginDescriptor.getPluginId() ) )
{
@@ -152,7 +151,7 @@ public void componentDiscovered( ComponentDiscoveryEvent event )
{
ComponentSetDescriptor componentSetDescriptor = event.getComponentSetDescriptor();
- if ( !(componentSetDescriptor instanceof MavenPluginDescriptor) )
+ if ( !( componentSetDescriptor instanceof MavenPluginDescriptor ) )
{
return;
}
@@ -189,7 +188,8 @@ private String getPluginId( String goalName )
}
// TODO: don't throw Exception
- public void verifyPluginForGoal( String goalName, MavenSession session ) throws Exception
+ public void verifyPluginForGoal( String goalName, MavenSession session )
+ throws Exception
{
String pluginId = getPluginId( goalName );
@@ -197,7 +197,8 @@ public void verifyPluginForGoal( String goalName, MavenSession session ) throws
}
// TODO: don't throw Exception
- public void verifyPlugin( String pluginId, MavenSession session ) throws Exception
+ public void verifyPlugin( String pluginId, MavenSession session )
+ throws Exception
{
if ( !isPluginInstalled( pluginId ) )
{
@@ -209,37 +210,65 @@ public void verifyPlugin( String pluginId, MavenSession session ) throws Excepti
String version = "1.0-SNAPSHOT";
- Artifact pluginArtifact = new DefaultArtifact( "maven", artifactId, version, DefaultArtifact.SCOPE_RUNTIME,
- "plugin", "jar" );
+ ArtifactFactory artifactFactory = null;
+ try
+ {
+ artifactFactory = (ArtifactFactory) container.lookup( ArtifactFactory.ROLE );
- addPlugin( pluginArtifact, session );
+ Artifact pluginArtifact = artifactFactory.createArtifact( "maven", artifactId, version, null, "plugin",
+ "jar", null );
+
+ addPlugin( pluginArtifact, session );
+ }
+ finally
+ {
+ if ( artifactFactory != null )
+ {
+ container.release( artifactFactory );
+ }
+ }
}
}
// TODO: don't throw Exception
- protected void addPlugin( Artifact pluginArtifact, MavenSession session ) throws Exception
+ protected void addPlugin( Artifact pluginArtifact, MavenSession session )
+ throws Exception
{
- // TODO: these should be configured, not instantiated here
+ ArtifactResolver artifactResolver = null;
+ MavenProjectBuilder mavenProjectBuilder = null;
- artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE );
+ try
+ {
+ artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE );
+ mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE );
- mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE );
+ MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, mavenProjectBuilder );
- MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, mavenProjectBuilder );
-
- ((ArtifactEnabledContainer) container).addComponent( pluginArtifact,
- artifactResolver,
- remotePluginRepositories,
- session.getLocalRepository(),
- metadataSource,
- artifactFilter );
+ ( (ArtifactEnabledContainer) container ).addComponent( pluginArtifact, artifactResolver,
+ remotePluginRepositories,
+ session.getLocalRepository(), metadataSource,
+ artifactFilter );
+ }
+ finally
+ {
+ // TODO: watch out for the exceptions being thrown
+ if ( artifactResolver != null )
+ {
+ container.release( artifactResolver );
+ }
+ if ( mavenProjectBuilder != null )
+ {
+ container.release( mavenProjectBuilder );
+ }
+ }
}
// ----------------------------------------------------------------------
// Plugin execution
// ----------------------------------------------------------------------
- public PluginExecutionResponse executeMojo( MavenSession session, String goalName ) throws GoalExecutionException
+ public PluginExecutionResponse executeMojo( MavenSession session, String goalName )
+ throws GoalExecutionException
{
try
{
@@ -264,12 +293,34 @@ public PluginExecutionResponse executeMojo( MavenSession session, String goalNam
{
if ( mojoDescriptor.requiresDependencyResolution() )
{
- resolveTransitiveDependencies( session );
- downloadDependencies( session );
+ ArtifactResolver artifactResolver = null;
+ MavenProjectBuilder mavenProjectBuilder = null;
+
+ // TODO: should these be released
+ try
+ {
+ artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE );
+ mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE );
+
+ resolveTransitiveDependencies( session, artifactResolver, mavenProjectBuilder );
+ downloadDependencies( session, artifactResolver );
+ }
+ finally
+ {
+ // TODO: watch out for the exceptions being thrown
+ if ( artifactResolver != null )
+ {
+ container.release( artifactResolver );
+ }
+ if ( mavenProjectBuilder != null )
+ {
+ container.release( mavenProjectBuilder );
+ }
+ }
}
}
- catch ( ArtifactResolutionException e )
+ catch ( Exception e )
{
throw new GoalExecutionException( "Unable to resolve required dependencies for goal", e );
}
@@ -331,7 +382,8 @@ public PluginExecutionResponse executeMojo( MavenSession session, String goalNam
}
// TODO: don't throw Exception
- private void releaseComponents( MojoDescriptor goal, PluginExecutionRequest request ) throws Exception
+ private void releaseComponents( MojoDescriptor goal, PluginExecutionRequest request )
+ throws Exception
{
if ( request != null && request.getParameters() != null )
{
@@ -357,7 +409,8 @@ private void releaseComponents( MojoDescriptor goal, PluginExecutionRequest requ
// Mojo Parameter Handling
// ----------------------------------------------------------------------
- public static Map createParameters( MojoDescriptor goal, MavenSession session ) throws PluginConfigurationException
+ public static Map createParameters( MojoDescriptor goal, MavenSession session )
+ throws PluginConfigurationException
{
Map map = null;
@@ -450,10 +503,8 @@ public static String createPluginParameterRequiredMessage( MojoDescriptor mojo,
{
StringBuffer message = new StringBuffer();
- message.append( "The '" + parameter.getName() )
- .append( "' parameter is required for the execution of the " )
- .append( mojo.getId() )
- .append( " mojo and cannot be null." );
+ message.append( "The '" + parameter.getName() ).append( "' parameter is required for the execution of the " ).append(
+ mojo.getId() ).append( " mojo and cannot be null." );
return message.toString();
}
@@ -462,7 +513,8 @@ public static String createPluginParameterRequiredMessage( MojoDescriptor mojo,
// Lifecycle
// ----------------------------------------------------------------------
- public void contextualize( Context context ) throws ContextException
+ public void contextualize( Context context )
+ throws ContextException
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
@@ -470,17 +522,10 @@ public void contextualize( Context context ) throws ContextException
public void initialize()
{
// TODO: configure this from bootstrap or scan lib
- artifactFilter = new ExclusionSetFilter( new String[] {
- "maven-core",
- "maven-artifact",
- "maven-model",
- "maven-monitor",
- "maven-plugin",
- "plexus-container-api",
- "plexus-container-default",
- "plexus-artifact-container",
- "wagon-provider-api",
- "classworlds" } );
+ artifactFilter = new ExclusionSetFilter( new String[]{"maven-core", "maven-artifact", "maven-model",
+ "maven-monitor", "maven-plugin", "plexus-container-api",
+ "plexus-container-default", "plexus-artifact-container",
+ "wagon-provider-api", "classworlds"} );
// TODO: move this to be configurable from the Maven component
remotePluginRepositories = new HashSet();
@@ -493,7 +538,9 @@ public void initialize()
// Artifact resolution
// ----------------------------------------------------------------------
- private void resolveTransitiveDependencies( MavenSession context ) throws ArtifactResolutionException
+ private void resolveTransitiveDependencies( MavenSession context, ArtifactResolver artifactResolver,
+ MavenProjectBuilder mavenProjectBuilder )
+ throws ArtifactResolutionException
{
MavenProject project = context.getProject();
@@ -511,7 +558,8 @@ private void resolveTransitiveDependencies( MavenSession context ) throws Artifa
// Artifact downloading
// ----------------------------------------------------------------------
- private void downloadDependencies( MavenSession context ) throws GoalExecutionException
+ private void downloadDependencies( MavenSession context, ArtifactResolver artifactResolver )
+ throws GoalExecutionException
{
try
{
diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
index dd3f069698..8223322452 100644
--- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
+++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
@@ -16,23 +16,8 @@
* limitations under the License.
*/
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.apache.maven.MavenConstants;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.MavenMetadataSource;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -50,7 +35,6 @@
import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator;
import org.apache.maven.repository.RepositoryUtils;
-
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.util.StringUtils;
@@ -58,6 +42,20 @@
import org.codehaus.plexus.util.dag.DAG;
import org.codehaus.plexus.util.dag.TopologicalSorter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* @version $Id$
*/
@@ -130,7 +128,7 @@ public MavenProject build( File projectDescriptor, ArtifactRepository localRepos
project = new MavenProject( model );
project.setFile( projectDescriptor );
project.setParent( parentProject );
- project.setArtifacts( artifactFactory.createArtifacts( project.getDependencies(), localRepository ) );
+ project.setArtifacts( artifactFactory.createArtifacts( project.getDependencies(), localRepository, null ) );
// ----------------------------------------------------------------------
// Typically when the project builder is being used from maven proper
@@ -242,7 +240,8 @@ private Model readModel( File file )
}
catch ( Exception e )
{
- throw new ProjectBuildingException( "Error while reading model from file '" + file.getAbsolutePath() + "'.", e );
+ throw new ProjectBuildingException(
+ "Error while reading model from file '" + file.getAbsolutePath() + "'.", e );
}
}
@@ -266,8 +265,8 @@ private Model readModel( URL url )
private File findParentModel( Parent parent, Set remoteArtifactRepositories, ArtifactRepository localRepository )
throws ProjectBuildingException
{
- Artifact artifact = new DefaultArtifact( parent.getGroupId(), parent.getArtifactId(), parent.getVersion(),
- "pom" );
+ Artifact artifact = artifactFactory.createArtifact( parent.getGroupId(), parent.getArtifactId(),
+ parent.getVersion(), null, "pom", "pom", null );
try
{
diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathArtifactResolver.java b/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathArtifactResolver.java
index ef2911e470..66c634faca 100644
--- a/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathArtifactResolver.java
+++ b/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathArtifactResolver.java
@@ -33,9 +33,11 @@
import java.io.InputStreamReader;
import java.util.Set;
-public class ProjectClasspathArtifactResolver extends DefaultArtifactResolver
+public class ProjectClasspathArtifactResolver
+ extends DefaultArtifactResolver
{
- private static class Source extends MavenMetadataSource
+ private static class Source
+ extends MavenMetadataSource
{
public Source( ArtifactResolver artifactResolver )
{
@@ -57,7 +59,7 @@ public Set retrieve( Artifact artifact, ArtifactRepository localRepository, Set
{
throw new ArtifactMetadataRetrievalException( e );
}
- return createArtifacts( model.getDependencies(), artifact.getScope(), localRepository );
+ return artifactFactory.createArtifacts( model.getDependencies(), localRepository, artifact.getScope() );
}
}
diff --git a/maven-plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugin/pom/PomInstallMojo.java b/maven-plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugin/pom/PomInstallMojo.java
index dbf5639003..96e5489118 100644
--- a/maven-plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugin/pom/PomInstallMojo.java
+++ b/maven-plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugin/pom/PomInstallMojo.java
@@ -29,30 +29,25 @@
/**
* @goal install
- *
* @description installs project's main artifact in local repository
- *
* @parameter name="project"
* type="org.apache.maven.project.MavenProject"
* required="true"
* validator=""
* expression="#project"
* description=""
- *
* @parameter name="installer"
* type="org.apache.maven.artifact.installer.ArtifactInstaller"
* required="true"
* validator=""
* expression="#component.org.apache.maven.artifact.installer.ArtifactInstaller"
* description=""
- *
* @parameter name="localRepository"
* type="org.apache.maven.artifact.repository.ArtifactRepository"
* required="true"
* validator=""
* expression="#localRepository"
* description=""
- *
*/
public class PomInstallMojo
extends AbstractPlugin
@@ -66,9 +61,7 @@ public void execute( PluginExecutionRequest request, PluginExecutionResponse res
ArtifactRepository localRepository = (ArtifactRepository) request.getParameter( "localRepository" );
- Artifact artifact = new DefaultArtifact( project.getGroupId(),
- project.getArtifactId(),
- project.getVersion(),
+ Artifact artifact = new DefaultArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(),
"pom" );
File pom = new File( project.getFile().getParentFile(), "pom.xml" );