o Created non-abstract base class for DefaultArtifactFactory to extend, called ArtifactConstructionSupport, which provides centralized means for constructing artifacts consistently without all the maven-core specific methods. These maven-core specifics not delegate to the generic methods provided in this new class.

o Adjusted the maven-archetype stuff to work with the new artifact creation/resolution/etc. methods in maven-artifact and maven-core.
o Removed all direct construction of DefaultArtifact and replaced with ArtifactConstructionSupport where it would have involved putting the DefaultArtifactFactory in the plexus.xml, and where the code doesn't need dependency-oriented methods.
o Archetype works now, using the example provided in plexus/plexus-site/src/site/apt/building-plexus-applications.apt


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163615 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-03-18 22:02:09 +00:00
parent fcb311e99c
commit 10b55add40
15 changed files with 140 additions and 71 deletions

View File

@ -16,8 +16,8 @@
* limitations under the License.
*/
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.maven.artifact.repository.ArtifactRepository;
@ -36,6 +36,6 @@ public interface Archetype
String ARCHETYPE_POM = "pom.xml";
void createArchetype( String archetypeGroupId, String archetypeArtifactId, String archetypeVersion,
ArtifactRepository localRepository, Set remoteRepositories, Map parameters )
ArtifactRepository localRepository, List remoteRepositories, Map parameters )
throws ArchetypeNotFoundException, ArchetypeDescriptorException, ArchetypeTemplateProcessingException;
}

View File

@ -26,12 +26,11 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.maven.archetype.descriptor.ArchetypeDescriptor;
import org.apache.maven.archetype.descriptor.ArchetypeDescriptorBuilder;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.construction.ArtifactConstructionSupport;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
@ -54,33 +53,33 @@ public class DefaultArchetype
// ----------------------------------------------------------------------
private VelocityComponent velocity;
private WagonManager wagonManager;
private ArtifactResolver artifactResolver;
// ----------------------------------------------------------------------
// Implementation
// ----------------------------------------------------------------------
private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport();
// groupId = maven
// artifactId = maven-foo-archetype
// version = latest
public void createArchetype( String archetypeGroupId, String archetypeArtifactId, String archetypeVersion,
ArtifactRepository localRepository, Set remoteRepositories, Map parameters )
ArtifactRepository localRepository, List remoteRepositories, Map parameters )
throws ArchetypeNotFoundException, ArchetypeDescriptorException, ArchetypeTemplateProcessingException
{
// ----------------------------------------------------------------------
// Download the archetype
// ----------------------------------------------------------------------
Artifact archetypeJar =
wagonManager.createArtifact( archetypeGroupId, archetypeArtifactId, archetypeVersion, "jar" );
Artifact archetypeArtifact =
artifactConstructionSupport.createArtifact( archetypeGroupId, archetypeArtifactId, archetypeVersion, Artifact.SCOPE_RUNTIME, "jar" );
try
{
artifactResolver.resolve( archetypeJar, remoteRepositories, localRepository );
artifactResolver.resolve( archetypeArtifact, remoteRepositories, localRepository );
}
catch ( ArtifactResolutionException e )
{
@ -107,7 +106,7 @@ public void createArchetype( String archetypeGroupId, String archetypeArtifactId
{
URL[] urls = new URL[1];
urls[0] = archetypeJar.getFile().toURL();
urls[0] = archetypeArtifact.getFile().toURL();
archetypeJarLoader = new URLClassLoader( urls );

View File

@ -7,9 +7,6 @@
<requirement>
<role>org.codehaus.plexus.velocity.VelocityComponent</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
</requirement>

View File

@ -16,16 +16,16 @@
* limitations under the License.
*/
import org.codehaus.plexus.PlexusTestCase;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.PlexusTestCase;
import java.util.Map;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.Properties;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -65,7 +65,7 @@ public void testArchetype()
ArtifactRepository localRepository = new ArtifactRepository( "local", "file://" + mavenProperties.getProperty( "maven.repo.local" ) );
Set remoteRepositories = new HashSet();
List remoteRepositories = new ArrayList();
ArtifactRepository remoteRepository = new ArtifactRepository( "remote", "http://repo1.maven.org" );

View File

@ -7,7 +7,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>maven</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<packaging>plugin</packaging>
<packaging>maven-plugin</packaging>
<name>Maven Archetype Plugin</name>
<version>1.0-SNAPSHOT</version>
<dependencies>

View File

@ -22,8 +22,8 @@
import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse;
import java.util.HashSet;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;
/**
* @goal create
@ -131,7 +131,7 @@ public void execute( PluginExecutionRequest request, PluginExecutionResponse res
ArtifactRepository localRepository = (ArtifactRepository) request.getParameter( "localRepository" );
Set remoteRepositories = new HashSet();
List remoteRepositories = new ArrayList();
ArtifactRepository remoteRepository = new ArtifactRepository( "remote", "http://repo1.maven.org" );

View File

@ -25,6 +25,7 @@
public class DefaultArtifact
implements Artifact
{
// ----------------------------------------------------------------------
// These are the only things i need to specify
// ----------------------------------------------------------------------
@ -48,6 +49,11 @@ public class DefaultArtifact
*/
public DefaultArtifact( String groupId, String artifactId, String version, String scope, String type, String extension )
{
if(type == null)
{
throw new NullPointerException("Artifact type cannot be null.");
}
this.groupId = groupId;
this.artifactId = artifactId;

View File

@ -0,0 +1,71 @@
package org.apache.maven.artifact.construction;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
/* ====================================================================
* 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.
* ====================================================================
*/
/**
* @author jdcasey
*/
public class ArtifactConstructionSupport
{
public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type )
{
return createArtifact( groupId, artifactId, version, scope, type, type, null );
}
public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type, String extension )
{
return createArtifact( groupId, artifactId, version, scope, type, extension, null );
}
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;
}
// vvv added to retain compile scope. Remove if you want compile inherited as runtime
else if ( Artifact.SCOPE_COMPILE.equals( scope ) && Artifact.SCOPE_COMPILE.equals( inheritedScope ) )
{
desiredScope = Artifact.SCOPE_COMPILE;
}
// ^^^ added to retain compile scope. Remove if you want compile inherited as runtime
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

@ -2,7 +2,7 @@
import org.apache.maven.artifact.AbstractArtifactComponent;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.construction.ArtifactConstructionSupport;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
@ -45,6 +45,8 @@ public class DefaultArtifactResolver
// ----------------------------------------------------------------------
// Implementation
// ----------------------------------------------------------------------
private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport();
public Artifact resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException
@ -228,10 +230,12 @@ private ArtifactResolutionResult collect( Set artifacts, ArtifactRepository loca
if ( updateScope )
{
// TODO: Artifact factory?
Artifact artifact = new DefaultArtifact( knownArtifact.getGroupId(),
knownArtifact.getArtifactId(), knownVersion,
newArtifact.getScope(), knownArtifact.getType(),
knownArtifact.getExtension() );
// TODO: [jc] Is this a better way to centralize artifact construction here?
Artifact artifact = artifactConstructionSupport.createArtifact( knownArtifact.getGroupId(),
knownArtifact.getArtifactId(),
knownVersion, newArtifact.getScope(),
knownArtifact.getType(),
knownArtifact.getExtension() );
resolvedArtifacts.put( artifact.getConflictId(), artifact );
}
}

View File

@ -101,7 +101,7 @@ public MavenExecutionResponse execute( MavenExecutionRequest request )
if ( projects.isEmpty() )
{
projects.add( projectBuilder.buildSuperProject( request.getLocalRepository() ) );
projects.add( projectBuilder.buildStandaloneSuperProject( request.getLocalRepository() ) );
}
}
catch ( IOException e )

View File

@ -17,7 +17,7 @@
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.construction.ArtifactConstructionSupport;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Dependency;
@ -29,6 +29,7 @@
// TODO: packaging is very confusing - this isn't in artifact after all
public class DefaultArtifactFactory
extends ArtifactConstructionSupport
implements ArtifactFactory
{
public Set createArtifacts( List dependencies, ArtifactRepository localRepository, String inheritedScope )
@ -55,35 +56,4 @@ public Artifact createArtifact( Dependency dependency, ArtifactRepository localR
dependency.getScope(), dependency.getType(), dependency.getType(), inheritedScope );
}
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;
}
// vvv added to retain compile scope. Remove if you want compile inherited as runtime
else if ( Artifact.SCOPE_COMPILE.equals( scope ) && Artifact.SCOPE_COMPILE.equals( inheritedScope ) )
{
desiredScope = Artifact.SCOPE_COMPILE;
}
// ^^^ added to retain compile scope. Remove if you want compile inherited as runtime
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

@ -377,10 +377,18 @@ private static String createCacheKey( String groupId, String artifactId, String
return groupId + ":" + artifactId + ":" + version;
}
public MavenProject buildSuperProject( ArtifactRepository localRepository )
public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository )
throws ProjectBuildingException
{
MavenProject project = new MavenProject( getSuperModel() );
Model superModel = getSuperModel();
superModel.setGroupId( STANDALONE_SUPERPOM_GROUPID );
superModel.setArtifactId( STANDALONE_SUPERPOM_ARTIFACTID );
superModel.setVersion( STANDALONE_SUPERPOM_VERSION );
MavenProject project = new MavenProject( superModel );
try
{

View File

@ -18,7 +18,7 @@
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.construction.ArtifactConstructionSupport;
import org.apache.maven.model.Build;
import org.apache.maven.model.CiManagement;
import org.apache.maven.model.Contributor;
@ -74,6 +74,8 @@ public class MavenProject
private Set artifacts;
private List collectedProjects = Collections.EMPTY_LIST;
private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport();
public MavenProject( Model model )
{
@ -682,9 +684,14 @@ public void addArtifacts( Collection newArtifacts )
if ( updateScope )
{
// TODO: Artifact factory?
Artifact artifact = new DefaultArtifact( existing.getGroupId(), existing.getArtifactId(),
existing.getVersion(), a.getScope(), existing.getType(),
existing.getExtension() );
// TODO: [jc] Is this a better way to centralize artifact construction here?
Artifact artifact = artifactConstructionSupport.createArtifact( existing.getGroupId(),
existing.getArtifactId(),
existing.getVersion(),
a.getScope(),
existing.getType(),
existing.getExtension() );
artifacts.put( id, artifact );
}
}

View File

@ -26,6 +26,12 @@
public interface MavenProjectBuilder
{
String ROLE = MavenProjectBuilder.class.getName();
static final String STANDALONE_SUPERPOM_GROUPID = "maven";
static final String STANDALONE_SUPERPOM_ARTIFACTID = "super-pom";
static final String STANDALONE_SUPERPOM_VERSION = "2.0";
MavenProject build( File project, ArtifactRepository localRepository )
throws ProjectBuildingException;
@ -36,7 +42,7 @@ MavenProject buildWithDependencies( File project, ArtifactRepository localReposi
MavenProject buildFromRepository( Artifact artifact, ArtifactRepository localRepository )
throws ProjectBuildingException;
MavenProject buildSuperProject( ArtifactRepository localRepository )
MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository )
throws ProjectBuildingException;
Model getCachedModel( String groupId, String artifactId, String version );

View File

@ -54,6 +54,7 @@ public class MBoot
String[] pluginGeneratorDeps = new String[]{"plexus/jars/plexus-container-default-1.0-alpha-2-SNAPSHOT.jar",
"maven/jars/maven-core-2.0-SNAPSHOT.jar",
"maven/jars/maven-artifact-2.0-SNAPSHOT.jar",
"maven/jars/maven-model-2.0-SNAPSHOT.jar",
"maven/jars/maven-plugin-2.0-SNAPSHOT.jar",
"maven/jars/maven-plugin-tools-api-2.0-SNAPSHOT.jar",