mirror of https://github.com/apache/maven.git
o more reduction of the repository interface
o cleaning up the project builder git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@750677 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8fd147fff0
commit
74384e7c63
|
@ -43,6 +43,7 @@ import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
|||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Profile;
|
||||
|
@ -90,6 +91,9 @@ import org.codehaus.plexus.util.xml.pull.XmlSerializer;
|
|||
public class DefaultMavenProjectBuilder
|
||||
implements MavenProjectBuilder
|
||||
{
|
||||
@Requirement
|
||||
private Logger logger;
|
||||
|
||||
@Requirement
|
||||
private ModelValidator validator;
|
||||
|
||||
|
@ -101,9 +105,9 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
@Requirement
|
||||
List<ModelEventListener> listeners;
|
||||
|
||||
|
||||
@Requirement
|
||||
private Logger logger;
|
||||
private ResolutionErrorHandler resolutionErrorHandler;
|
||||
|
||||
//DO NOT USE, it is here only for backward compatibility reasons. The existing
|
||||
// maven-assembly-plugin (2.2-beta-1) is accessing it via reflection.
|
||||
|
@ -172,32 +176,25 @@ public class DefaultMavenProjectBuilder
|
|||
return project;
|
||||
}
|
||||
|
||||
File f = ( artifact.getFile() != null ) ? artifact.getFile() : new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
|
||||
|
||||
ArtifactResolutionRequest request = new ArtifactResolutionRequest( artifact, localRepository, remoteRepositories );
|
||||
ArtifactResolutionResult result = repositorySystem.resolve( request );
|
||||
|
||||
try
|
||||
{
|
||||
repositorySystem.findModelFromRepository( artifact, remoteRepositories, localRepository );
|
||||
resolutionErrorHandler.throwErrors( request, result );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new ProjectBuildingException( artifact.getId(), "Error resolving project artifact.", e );
|
||||
}
|
||||
catch ( ArtifactNotFoundException e )
|
||||
{
|
||||
throw new ProjectBuildingException( artifact.getId(), "Error finding project artifact.", e );
|
||||
}
|
||||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
throw new ProjectBuildingException( artifact.getId(), "Error with repository specified in project.", e );
|
||||
}
|
||||
|
||||
|
||||
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration()
|
||||
.setLocalRepository( localRepository )
|
||||
.setRemoteRepositories( remoteRepositories );
|
||||
|
||||
project = readModelFromLocalPath( "unknown", artifact.getFile(), config.getLocalRepository(), remoteRepositories, config );
|
||||
project = buildWithProfiles( project.getModel(), config, artifact.getFile(), project.getParentFile() );
|
||||
artifact.setFile( f );
|
||||
artifact.setFile( artifact.getFile() );
|
||||
project.setVersion( artifact.getVersion() );
|
||||
|
||||
hm.put( artifact.getId(), project );
|
||||
|
@ -424,15 +421,9 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
}
|
||||
|
||||
private MavenProject readModelFromLocalPath( String projectId, File projectDescriptor, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
|
||||
ProjectBuilderConfiguration config )
|
||||
private MavenProject readModelFromLocalPath( String projectId, File pomFile, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories, ProjectBuilderConfiguration config )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
if ( projectDescriptor == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "projectDescriptor: null, Project Id =" + projectId );
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties(), PomInterpolatorTag.EXECUTION_PROPERTIES.name() ) );
|
||||
|
@ -449,11 +440,11 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
try
|
||||
{
|
||||
mavenProject = buildFromLocalPath( projectDescriptor, interpolatorProperties, localRepository, remoteRepositories, config, this );
|
||||
mavenProject = buildFromLocalPath( pomFile, interpolatorProperties, localRepository, remoteRepositories, config, this );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new ProjectBuildingException( projectId, "File = " + projectDescriptor.getAbsolutePath(), e );
|
||||
throw new ProjectBuildingException( projectId, "File = " + pomFile.getAbsolutePath(), e );
|
||||
}
|
||||
|
||||
return mavenProject;
|
||||
|
@ -649,7 +640,6 @@ public class DefaultMavenProjectBuilder
|
|||
private static Model convertFromInputStreamToModel( InputStream inputStream )
|
||||
throws IOException
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
return new MavenXpp3Reader().read( ReaderFactory.newXmlReader( inputStream ) );
|
||||
|
|
|
@ -70,8 +70,7 @@ public class TestArtifactResolver
|
|||
this.container = container;
|
||||
}
|
||||
|
||||
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository,
|
||||
List<ArtifactRepository> remoteRepositories )
|
||||
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
Model model = null;
|
||||
|
@ -116,17 +115,7 @@ public class TestArtifactResolver
|
|||
throw new ArtifactMetadataRetrievalException( e );
|
||||
}
|
||||
|
||||
List artifactRepositories;
|
||||
try
|
||||
{
|
||||
artifactRepositories = repositorySystem.buildArtifactRepositories( model.getRepositories() );
|
||||
}
|
||||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
throw new ArtifactMetadataRetrievalException( e );
|
||||
}
|
||||
|
||||
return new ResolutionGroup( artifact, artifacts, artifactRepositories );
|
||||
return new ResolutionGroup( artifact, artifacts, remoteRepositories );
|
||||
}
|
||||
|
||||
public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository,
|
||||
|
@ -163,13 +152,7 @@ public class TestArtifactResolver
|
|||
d.setScope( scope );
|
||||
}
|
||||
|
||||
Artifact artifact = repositorySystem.createDependencyArtifact( d.getGroupId(),
|
||||
d.getArtifactId(),
|
||||
d.getVersion(),
|
||||
d.getType(),
|
||||
d.getClassifier(),
|
||||
scope,
|
||||
inheritedScope );
|
||||
Artifact artifact = repositorySystem.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(), d.getType(), d.getClassifier(), scope, inheritedScope );
|
||||
if ( artifact != null )
|
||||
{
|
||||
projectArtifacts.add( artifact );
|
||||
|
|
|
@ -71,16 +71,6 @@ public class TestMavenRepositorySystem
|
|||
throw new ArtifactMetadataRetrievalException( ee );
|
||||
}
|
||||
|
||||
List artifactRepositories;
|
||||
try
|
||||
{
|
||||
artifactRepositories = buildArtifactRepositories( model.getRepositories() );
|
||||
}
|
||||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
throw new ArtifactMetadataRetrievalException( e );
|
||||
}
|
||||
|
||||
return new ResolutionGroup( artifact, artifacts, artifactRepositories );
|
||||
return new ResolutionGroup( artifact, artifacts, remoteRepositories );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.ArtifactUtils;
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.manager.WagonManager;
|
||||
|
@ -37,8 +36,6 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
|
|||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||
|
@ -97,8 +94,6 @@ public class LegacyMavenRepositorySystem
|
|||
@Requirement
|
||||
private Logger logger;
|
||||
|
||||
private boolean interactive = true;
|
||||
|
||||
private TransferListener downloadMonitor;
|
||||
|
||||
private Map<String, ProxyInfo> proxies = new HashMap<String, ProxyInfo>();
|
||||
|
@ -107,8 +102,6 @@ public class LegacyMavenRepositorySystem
|
|||
|
||||
private Map<String, RepositoryPermissions> serverPermissionsMap = new HashMap<String, RepositoryPermissions>();
|
||||
|
||||
private static HashMap<String, Artifact> cache = new HashMap<String, Artifact>();
|
||||
|
||||
// Artifact Creation
|
||||
|
||||
public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type )
|
||||
|
@ -298,29 +291,6 @@ public class LegacyMavenRepositorySystem
|
|||
return artifactMetadataSource.retrieve( artifact, localRepository, remoteRepositories );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Code snagged from ProjectUtils: this will have to be moved somewhere else
|
||||
// but just trying to collect it all in one place right now.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
public List<ArtifactRepository> buildArtifactRepositories( List<Repository> repositories )
|
||||
throws InvalidRepositoryException
|
||||
{
|
||||
List<ArtifactRepository> repos = new ArrayList<ArtifactRepository>();
|
||||
|
||||
for ( Repository mavenRepo : repositories )
|
||||
{
|
||||
ArtifactRepository artifactRepo = buildArtifactRepository( mavenRepo );
|
||||
|
||||
if ( !repos.contains( artifactRepo ) )
|
||||
{
|
||||
repos.add( artifactRepo );
|
||||
}
|
||||
}
|
||||
|
||||
return repos;
|
||||
}
|
||||
|
||||
public ArtifactRepository buildArtifactRepository( Repository repo )
|
||||
throws InvalidRepositoryException
|
||||
{
|
||||
|
@ -444,57 +414,6 @@ public class LegacyMavenRepositorySystem
|
|||
artifactRepositoryFactory.setGlobalChecksumPolicy( policy );
|
||||
}
|
||||
|
||||
// Taken from RepositoryHelper
|
||||
|
||||
public void findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository )
|
||||
throws InvalidRepositoryException, ArtifactResolutionException, ArtifactNotFoundException
|
||||
{
|
||||
if ( cache.containsKey( artifact.getId() ) )
|
||||
{
|
||||
artifact.setFile( cache.get( artifact.getId() ).getFile() );
|
||||
}
|
||||
|
||||
// if the artifact is not a POM, we need to construct a POM artifact based on the artifact parameter given.
|
||||
/*
|
||||
if ( "pom".equals( artifact.getType() ) )
|
||||
{
|
||||
projectArtifact = artifact;
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug( "Attempting to build MavenProject instance for Artifact (" + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + ") of type: "
|
||||
+ artifact.getType() + "; constructing POM artifact instead." );
|
||||
|
||||
projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope() );
|
||||
}
|
||||
*/
|
||||
|
||||
ArtifactResolutionRequest request = new ArtifactResolutionRequest( artifact, localRepository, remoteArtifactRepositories );
|
||||
ArtifactResolutionResult result = resolve( request );
|
||||
resolutionErrorHandler.throwErrors( request, result );
|
||||
|
||||
cache.put( artifact.getId(), artifact );
|
||||
}
|
||||
|
||||
private String safeVersionlessKey( String groupId, String artifactId )
|
||||
{
|
||||
String gid = groupId;
|
||||
|
||||
if ( StringUtils.isEmpty( gid ) )
|
||||
{
|
||||
gid = "unknown";
|
||||
}
|
||||
|
||||
String aid = artifactId;
|
||||
|
||||
if ( StringUtils.isEmpty( aid ) )
|
||||
{
|
||||
aid = "unknown";
|
||||
}
|
||||
|
||||
return ArtifactUtils.versionlessKey( gid, aid );
|
||||
}
|
||||
|
||||
public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
|
||||
{
|
||||
return artifactResolver.resolve( request );
|
||||
|
@ -510,11 +429,6 @@ public class LegacyMavenRepositorySystem
|
|||
return artifactResolver.isOnline();
|
||||
}
|
||||
|
||||
public void setInteractive( boolean interactive )
|
||||
{
|
||||
this.interactive = interactive;
|
||||
}
|
||||
|
||||
public void setDownloadMonitor( TransferListener downloadMonitor )
|
||||
{
|
||||
this.downloadMonitor = downloadMonitor;
|
||||
|
@ -593,11 +507,6 @@ public class LegacyMavenRepositorySystem
|
|||
mirrorBuilder.addMirror( id, mirrorOf, url );
|
||||
}
|
||||
|
||||
public ArtifactRepository getMirror( ArtifactRepository repository )
|
||||
{
|
||||
return mirrorBuilder.getMirror( repository );
|
||||
}
|
||||
|
||||
public List<ArtifactRepository> getMirrors( List<ArtifactRepository> repositories )
|
||||
{
|
||||
return mirrorBuilder.getMirrors( repositories );
|
||||
|
|
|
@ -66,10 +66,6 @@ public interface MavenRepositorySystem
|
|||
|
||||
// Repository creation
|
||||
|
||||
// maven model
|
||||
List<ArtifactRepository> buildArtifactRepositories( List<Repository> repositories )
|
||||
throws InvalidRepositoryException;
|
||||
|
||||
// maven model
|
||||
ArtifactRepository buildArtifactRepository( Repository repository )
|
||||
throws InvalidRepositoryException;
|
||||
|
@ -91,9 +87,6 @@ public interface MavenRepositorySystem
|
|||
|
||||
// Metadata
|
||||
|
||||
void findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository )
|
||||
throws InvalidRepositoryException, ArtifactResolutionException, ArtifactNotFoundException;
|
||||
|
||||
ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
||||
throws ArtifactMetadataRetrievalException;
|
||||
|
||||
|
@ -113,9 +106,6 @@ public interface MavenRepositorySystem
|
|||
|
||||
boolean isOnline();
|
||||
|
||||
// This doesn't belong here
|
||||
void setInteractive( boolean interactive );
|
||||
|
||||
void setDownloadMonitor( TransferListener downloadMonitor );
|
||||
|
||||
void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts );
|
||||
|
@ -127,9 +117,6 @@ public interface MavenRepositorySystem
|
|||
// Mirrors
|
||||
|
||||
void addMirror( String id, String mirrorOf, String url );
|
||||
|
||||
ArtifactRepository getMirror( ArtifactRepository repository );
|
||||
|
||||
List<ArtifactRepository> getMirrors( List<ArtifactRepository> repositories );
|
||||
|
||||
|
||||
List<ArtifactRepository> getMirrors( List<ArtifactRepository> repositories );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue