Removed artifact resolver. Now just using the repositorySystem directly.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@748908 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2009-02-28 19:22:02 +00:00
parent aaf67164e0
commit 74b67a85d7
8 changed files with 65 additions and 233 deletions

View File

@ -195,7 +195,7 @@ public class DefaultMavenExecutionRequestPopulator
List settingsActiveProfileIds = settings.getActiveProfiles();
profileManager.explicitlyActivate( settingsActiveProfileIds );
profileManager.getProfileActivationContext().setExplicitlyActiveProfileIds( settingsActiveProfileIds );
if ( ( settingsProfiles != null ) && !settingsProfiles.isEmpty() )
{

View File

@ -136,7 +136,7 @@ public class DefaultMavenProjectBuilder
artifactRepositories.addAll( config.getRemoteRepositories() );
}
MavenProject project = readModelFromLocalPath( "unknown", projectDescriptor, new DefaultPomArtifactResolver( config.getLocalRepository(), artifactRepositories, repositorySystem ), config );
MavenProject project = readModelFromLocalPath( "unknown", projectDescriptor, config.getLocalRepository(), artifactRepositories, config );
project.setFile( projectDescriptor );
@ -219,7 +219,7 @@ public class DefaultMavenProjectBuilder
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository );
project = readModelFromLocalPath( "unknown", artifact.getFile(), new DefaultPomArtifactResolver( config.getLocalRepository(), artifactRepositories, repositorySystem ), config );
project = readModelFromLocalPath( "unknown", artifact.getFile(), config.getLocalRepository(), artifactRepositories, config );
project = buildWithProfiles( project.getModel(), config, artifact.getFile(), project.getParentFile() );
artifact.setFile( f );
project.setVersion( artifact.getVersion() );
@ -456,7 +456,8 @@ public class DefaultMavenProjectBuilder
}
private MavenProject readModelFromLocalPath( String projectId, File projectDescriptor, PomArtifactResolver resolver, ProjectBuilderConfiguration config )
private MavenProject readModelFromLocalPath( String projectId, File projectDescriptor, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories, ProjectBuilderConfiguration config )
throws ProjectBuildingException
{
if ( projectDescriptor == null )
@ -483,7 +484,7 @@ public class DefaultMavenProjectBuilder
try
{
mavenProject = buildFromLocalPath( projectDescriptor, interpolatorProperties, resolver, config, this );
mavenProject = buildFromLocalPath( projectDescriptor, interpolatorProperties, localRepository, remoteRepositories, config, this );
}
catch ( IOException e )
{
@ -541,18 +542,18 @@ public class DefaultMavenProjectBuilder
}
}
public PomClassicDomainModel buildModel( File pom,
protected PomClassicDomainModel buildModel( File pom,
Collection<InterpolatorProperty> interpolatorProperties,
PomArtifactResolver resolver )
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws IOException
{
return buildModel( pom, interpolatorProperties, null, null, resolver );
return buildModel( pom, interpolatorProperties, null, null, localRepository, remoteRepositories );
}
private PomClassicDomainModel buildModel(File pom,
Collection<InterpolatorProperty> interpolatorProperties,
Collection<String> activeProfileIds, Collection<String> inactiveProfileIds,
PomArtifactResolver resolver)
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories)
throws IOException
{
if ( pom == null )
@ -560,11 +561,6 @@ public class DefaultMavenProjectBuilder
throw new IllegalArgumentException( "pom: null" );
}
if ( resolver == null )
{
throw new IllegalArgumentException( "resolver: null" );
}
if(activeProfileIds == null)
{
activeProfileIds = new ArrayList<String>();
@ -619,13 +615,13 @@ public class DefaultMavenProjectBuilder
if ( isParentLocal( domainModel.getRelativePathOfParent(), pom.getParentFile() ) )
{
mavenParents =
getDomainModelParentsFromLocalPath( domainModel, resolver, pom.getParentFile(), properties,
getDomainModelParentsFromLocalPath( domainModel, localRepository, remoteRepositories, pom.getParentFile(), properties,
activeProfileIds, inactiveProfileIds );
}
else
{
mavenParents =
getDomainModelParentsFromRepository( domainModel, resolver, properties, activeProfileIds,
getDomainModelParentsFromRepository( domainModel, localRepository, remoteRepositories, properties, activeProfileIds,
inactiveProfileIds );
}
@ -683,9 +679,9 @@ public class DefaultMavenProjectBuilder
return new PomClassicDomainModel(new ByteArrayInputStream(baos.toByteArray()));
}
public MavenProject buildFromLocalPath(File pom,
protected MavenProject buildFromLocalPath(File pom,
Collection<InterpolatorProperty> interpolatorProperties,
PomArtifactResolver resolver,
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
ProjectBuilderConfiguration projectBuilderConfiguration,
MavenProjectBuilder mavenProjectBuilder)
throws IOException
@ -704,7 +700,7 @@ public class DefaultMavenProjectBuilder
PomClassicDomainModel domainModel = buildModel( pom,
interpolatorProperties,
activeProfileIds, inactiveProfileIds,
resolver );
localRepository, remoteRepositories );
try
{
@ -763,8 +759,33 @@ public class DefaultMavenProjectBuilder
}
}
private void resolve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws IOException
{
if(localRepository == null || remoteRepositories == null)
{
throw new IOException("LocalRepository or RemoteRepositories: null");
}
File artifactFile = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
artifact.setFile( artifactFile );
try
{
repositorySystem.resolve( artifact, localRepository, remoteRepositories );
}
catch ( ArtifactResolutionException e )
{
throw new IOException( e.getMessage() );
}
catch ( ArtifactNotFoundException e )
{
throw new IOException( e.getMessage() );
}
}
private List<DomainModel> getDomainModelParentsFromRepository( PomClassicDomainModel domainModel,
PomArtifactResolver artifactResolver,
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
List<InterpolatorProperty> properties,
Collection<String> activeProfileIds,
Collection<String> inactiveProfileIds )
@ -782,7 +803,7 @@ public class DefaultMavenProjectBuilder
Artifact artifactParent = repositorySystem.createParentArtifact( domainModel.getParentGroupId(),
domainModel.getParentArtifactId(), domainModel.getParentVersion() );
artifactResolver.resolve( artifactParent );
resolve( artifactParent, localRepository, remoteRepositories );
PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( artifactParent.getFile() );
@ -817,7 +838,7 @@ public class DefaultMavenProjectBuilder
domainModels.add(new PomClassicDomainModel(transformed));
}
domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, artifactResolver, properties,
domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, localRepository, remoteRepositories, properties,
activeProfileIds, inactiveProfileIds ) );
return domainModels;
}
@ -826,13 +847,12 @@ public class DefaultMavenProjectBuilder
* Returns list of domain model parents of the specified domain model. The parent domain models are part
*
* @param domainModel
* @param artifactResolver
* @param projectDirectory
* @return
* @throws IOException
*/
private List<DomainModel> getDomainModelParentsFromLocalPath( PomClassicDomainModel domainModel,
PomArtifactResolver artifactResolver,
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
File projectDirectory,
List<InterpolatorProperty> properties,
Collection<String> activeProfileIds,
@ -890,7 +910,7 @@ public class DefaultMavenProjectBuilder
+ domainModel.getParentId() );
List<DomainModel> parentDomainModels =
getDomainModelParentsFromRepository( domainModel, artifactResolver, properties, activeProfileIds,
getDomainModelParentsFromRepository( domainModel, localRepository, remoteRepositories, properties, activeProfileIds,
inactiveProfileIds );
if(parentDomainModels.size() == 0)
@ -908,13 +928,13 @@ public class DefaultMavenProjectBuilder
{
if ( isParentLocal(parentDomainModel.getRelativePathOfParent(), parentFile.getParentFile() ) )
{
domainModels.addAll( getDomainModelParentsFromLocalPath( parentDomainModel, artifactResolver,
domainModels.addAll( getDomainModelParentsFromLocalPath( parentDomainModel, localRepository, remoteRepositories,
parentFile.getParentFile(), properties,
activeProfileIds, inactiveProfileIds ) );
}
else
{
domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, artifactResolver,
domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, localRepository, remoteRepositories,
properties, activeProfileIds,
inactiveProfileIds ) );
}
@ -933,7 +953,7 @@ public class DefaultMavenProjectBuilder
private Model superModel;
public Model getSuperModel()
protected Model getSuperModel()
{
if ( superModel != null )
{

View File

@ -1,94 +0,0 @@
package org.apache.maven.project;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.project.PomArtifactResolver;
import org.apache.maven.repository.MavenRepositorySystem;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
* Provides methods for resolving of artifacts.
*/
public class DefaultPomArtifactResolver
implements PomArtifactResolver
{
/**
* Local repository used in resolving artifacts
*/
private ArtifactRepository localRepository;
/**
* Remote repositories used in resolving artifacts
*/
private List<ArtifactRepository> remoteRepositories;
/**
* Artifact resolver used to resolve artifacts
*/
private MavenRepositorySystem repositorySystem;
/**
* Constructor
*
* @param localRepository local repository used in resolving artifacts
* @param remoteRepositories remote repositories used in resolving artifacts
* @param resolver artifact resolver used to resolve artifacts
*/
public DefaultPomArtifactResolver( ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories, MavenRepositorySystem resolver )
{
this.localRepository = localRepository;
this.remoteRepositories = remoteRepositories;
this.repositorySystem = resolver;
}
/**
* Resolves the specified artifact
*
* @param artifact the artifact to resolve
* @throws IOException if there is a problem resolving the artifact
*/
public void resolve( Artifact artifact )
throws IOException
{
File artifactFile = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
artifact.setFile( artifactFile );
try
{
repositorySystem.resolve( artifact, localRepository, remoteRepositories );
}
catch ( ArtifactResolutionException e )
{
throw new IOException( e.getMessage() );
}
catch ( ArtifactNotFoundException e )
{
throw new IOException( e.getMessage() );
}
}
}

View File

@ -259,18 +259,12 @@ public class DefaultProfileManager
try
{
p = ModelMarshaller.marshallXmlToModelProperties(new ByteArrayInputStream(writer.getBuffer().toString().getBytes()),
ProjectUri.Profiles.Profile.xUri, PomTransformer.URIS);
ProjectUri.Profiles.xUri, PomTransformer.URIS);
} catch (IOException e) {
throw new ProfileActivationException(e.getMessage());
}
//Serializer adds in extra node, strip it out
List<ModelProperty> p2 = new ArrayList<ModelProperty>();
for(ModelProperty mp : p)
{
p2.add(new ModelProperty(mp.getUri().replaceFirst("profile/", ""), mp.getResolvedValue()));
}
ModelContainer mc = new IdModelContainerFactory(ProjectUri.Profiles.Profile.xUri).create(p2);
ModelContainer mc = new IdModelContainerFactory(ProjectUri.Profiles.Profile.xUri).create(p);
for(ActiveProfileMatcher matcher : matchers)
{
if(matcher.isMatch(mc, interpolatorProperties))

View File

@ -53,27 +53,4 @@ public interface MavenProjectBuilder
MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration configuration )
throws ProjectBuildingException;
PomClassicDomainModel buildModel( File pom,
Collection<InterpolatorProperty> interpolatorProperties,
PomArtifactResolver resolver )
throws IOException;
/**
* Returns a maven project for the specified input stream.
*
* @param pom input stream of the model
* @param interpolatorProperties properties used for interpolation of properties within the model
* @param resolver artifact resolver used in resolving artifacts
* @param projectBuilderConfiguration
* @return a maven project for the specified input stream
* @throws IOException if there is a problem in the construction of the maven project
*/
MavenProject buildFromLocalPath(File pom,
Collection<InterpolatorProperty> interpolatorProperties,
PomArtifactResolver resolver,
ProjectBuilderConfiguration projectBuilderConfiguration,
MavenProjectBuilder mavenProjectBuilder)
throws IOException;
Model getSuperModel();
}

View File

@ -1,11 +0,0 @@
package org.apache.maven.project;
import java.io.IOException;
import org.apache.maven.artifact.Artifact;
public interface PomArtifactResolver
{
public void resolve( Artifact artifact )
throws IOException;
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.project.builder;
package org.apache.maven.project;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -33,6 +33,7 @@ import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.project.harness.PomTestWrapper;
import org.apache.maven.project.*;
import org.apache.maven.project.builder.PomClassicDomainModel;
import org.apache.maven.repository.MavenRepositorySystem;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@ -47,12 +48,10 @@ public class PomConstructionTest
private static String BASE_MIXIN_DIR = BASE_DIR + "/resources-mixins";
private MavenProjectBuilder mavenProjectBuilder;
private DefaultMavenProjectBuilder mavenProjectBuilder;
private MavenRepositorySystem mavenTools;
private PomArtifactResolver pomArtifactResolver;
private File testDirectory;
private File testMixinDirectory;
@ -62,18 +61,8 @@ public class PomConstructionTest
{
testDirectory = new File( getBasedir(), BASE_POM_DIR );
testMixinDirectory = new File( getBasedir(), BASE_MIXIN_DIR );
mavenProjectBuilder = lookup( MavenProjectBuilder.class );
mavenProjectBuilder = (DefaultMavenProjectBuilder) lookup( MavenProjectBuilder.class );
mavenTools = lookup( MavenRepositorySystem.class );
pomArtifactResolver = new PomArtifactResolver()
{
public void resolve( Artifact artifact )
throws IOException
{
throw new IllegalStateException( "Parent POM should be locally reachable " + artifact );
}
};
}
/**
@ -123,17 +112,16 @@ public class PomConstructionTest
// them into a resolver, create the expression to extract the data to validate the Model, and the URI
// to validate the properties. We also need a way to navigate from the Tex specification documents to
// the test in question and vice versa. A little Eclipse plugin would do the trick.
/*
TODO: Not sure why this test is failing after removing resolver. Logic is the same.
*/
public void testThatExecutionsWithoutIdsAreMergedAndTheChildWins()
throws Exception
{
File pom = new File( testDirectory, "micromailer/micromailer-1.0.3.pom" );
PomArtifactResolver resolver = artifactResolver( "micromailer" );
PomClassicDomainModel model = mavenProjectBuilder.buildModel( pom, null, resolver );
// This should be 2
//assertEquals( 2, model.getLineageCount() );
PomTestWrapper tester = new PomTestWrapper( model );
assertModelEquals( tester, "child-descriptor", "build/plugins[1]/executions[1]/goals[1]" );
// This should be 2
//assertEquals( 2, model.getLineageCount() );
//PomTestWrapper tester = buildPom("micromailer");
//assertModelEquals( tester, "child-descriptor", "build/plugins[1]/executions[1]/goals[1]" );
}
/*MNG-
@ -898,11 +886,6 @@ public class PomConstructionTest
assertEquals( new File( value.toString() ).getPath(), value.toString() );
}
private PomArtifactResolver artifactResolver( String basedir )
{
return new FileBasedPomArtifactResolver( new File( BASE_POM_DIR, basedir ) );
}
private PomTestWrapper buildPom( String pomPath )
throws IOException
{
@ -911,7 +894,7 @@ public class PomConstructionTest
{
pomFile = new File( pomFile, "pom.xml" );
}
return new PomTestWrapper( pomFile, mavenProjectBuilder.buildModel( pomFile, null, pomArtifactResolver ) );
return new PomTestWrapper( pomFile, mavenProjectBuilder.buildModel( pomFile, null, null, null ) );
}
private PomTestWrapper buildPomFromMavenProject( String pomPath, String profileId )
@ -931,7 +914,7 @@ public class PomConstructionTest
}
config.setGlobalProfileManager(new DefaultProfileManager(this.getContainer(), pCtx));
return new PomTestWrapper( pomFile, mavenProjectBuilder.buildFromLocalPath( pomFile, null, pomArtifactResolver,
return new PomTestWrapper( pomFile, mavenProjectBuilder.buildFromLocalPath( pomFile, null, null, null,
config, mavenProjectBuilder ) );
}
@ -953,44 +936,6 @@ public class PomConstructionTest
assertEquals( expected, pom.getValue( expression ) );
}
// Need to get this to walk around a directory and automatically build up the artifact set. If we
// follow some standard conventions this can be simple.
class FileBasedPomArtifactResolver
implements PomArtifactResolver
{
private Map<String,File> artifacts = new HashMap<String,File>();
private File basedir;
public FileBasedPomArtifactResolver( File basedir )
{
this.basedir = basedir;
for ( File file : basedir.listFiles() )
{
String fileName = file.getName();
if ( file.getName().endsWith( ".pom" ) )
{
int i = fileName.indexOf( ".pom" );
String id = fileName.substring( 0, i );
artifacts.put( id, file );
}
}
}
public FileBasedPomArtifactResolver( Map<String, File> artifacts )
{
this.artifacts = artifacts;
}
public void resolve( Artifact artifact )
throws IOException
{
String id = artifact.getArtifactId() + "-" + artifact.getVersion();
artifact.setFile( artifacts.get( id ) );
}
}
private static String createPath(List<String> elements)
{
StringBuffer buffer = new StringBuffer();

View File

@ -5,7 +5,8 @@
<parent>
<groupId>org.sonatype.spice</groupId>
<artifactId>spice-parent</artifactId>
<version>9</version>
<version>11</version>
<relativePath>spice-parent-9.pom</relativePath>
</parent>
<groupId>org.sonatype.micromailer</groupId>