move all artifact creation to artifact factory - further refactoring planned

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163499 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-03-09 02:39:10 +00:00
parent fecb4632b0
commit 1fe8c76a3d
10 changed files with 243 additions and 213 deletions

View File

@ -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 class DefaultArtifact
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 class DefaultArtifact
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 class DefaultArtifact
{
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() );
}
}

View File

@ -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 <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -47,8 +47,11 @@ public abstract class ArtifactComponentTestCase
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 @@ public abstract class ArtifactComponentTestCase
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 )

View File

@ -18,24 +18,22 @@ package org.apache.maven.artifact.resolver;
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 <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @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 <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class ArtifactResolverTest
extends ArtifactComponentTestCase
{
@ -127,6 +125,11 @@ public class ArtifactResolverTest
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 class ArtifactResolverTest
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 class ArtifactResolverTest
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() );

View File

@ -16,21 +16,19 @@ package org.apache.maven.artifact;
* 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 class MavenMetadataSource
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 class MavenMetadataSource
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 class MavenMetadataSource
}
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() );
}
}

View File

@ -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 );
}

View File

@ -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 @@ import java.util.Set;
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 class DefaultArtifactFactory
{
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 );
}
}

View File

@ -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 class DefaultPluginManager
* Mojo descriptors are looked up using their id which is of the form
* <pluginId>: <mojoId>. 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 class DefaultPluginManager
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 class DefaultPluginManager
{
ComponentSetDescriptor componentSetDescriptor = event.getComponentSetDescriptor();
if ( !(componentSetDescriptor instanceof MavenPluginDescriptor) )
if ( !( componentSetDescriptor instanceof MavenPluginDescriptor ) )
{
return;
}
@ -189,7 +188,8 @@ public class DefaultPluginManager
}
// 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 class DefaultPluginManager
}
// 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 class DefaultPluginManager
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 class DefaultPluginManager
{
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 class DefaultPluginManager
}
// 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 @@ public class DefaultPluginManager
// 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 class DefaultPluginManager
{
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 class DefaultPluginManager
// 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 class DefaultPluginManager
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 class DefaultPluginManager
// 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 @@ public class DefaultPluginManager
// Artifact downloading
// ----------------------------------------------------------------------
private void downloadDependencies( MavenSession context ) throws GoalExecutionException
private void downloadDependencies( MavenSession context, ArtifactResolver artifactResolver )
throws GoalExecutionException
{
try
{

View File

@ -16,23 +16,8 @@ package org.apache.maven.project;
* 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.path.PathTranslator;
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.CycleDetectedException;
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 class DefaultMavenProjectBuilder
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 @@ public class DefaultMavenProjectBuilder
}
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 @@ public class DefaultMavenProjectBuilder
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
{

View File

@ -33,9 +33,11 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
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 class ProjectClasspathArtifactResolver extends DefaultArtifactResolver
{
throw new ArtifactMetadataRetrievalException( e );
}
return createArtifacts( model.getDependencies(), artifact.getScope(), localRepository );
return artifactFactory.createArtifacts( model.getDependencies(), localRepository, artifact.getScope() );
}
}

View File

@ -29,30 +29,25 @@ import java.io.File;
/**
* @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 class PomInstallMojo
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" );