o fixed mirror code

o more plugin manager wrangling


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@750568 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-03-05 19:59:06 +00:00
parent e1602d1a96
commit b9f9244f5f
10 changed files with 40 additions and 112 deletions

View File

@ -38,12 +38,14 @@ public interface ArtifactRepository
String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository ); String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository );
String getUrl(); String getUrl();
void setUrl( String url );
String getBasedir(); String getBasedir();
String getProtocol(); String getProtocol();
String getId(); String getId();
void setId( String id );
ArtifactRepositoryPolicy getSnapshots(); ArtifactRepositoryPolicy getSnapshots();
void setSnapshotUpdatePolicy( ArtifactRepositoryPolicy policy ); void setSnapshotUpdatePolicy( ArtifactRepositoryPolicy policy );

View File

@ -194,11 +194,7 @@ private void findForkModifiers( final MojoBinding mojoBinding,
final boolean allowUnbindableMojos ) final boolean allowUnbindableMojos )
throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException
{ {
PluginDescriptor pluginDescriptor = loadPluginDescriptor( mojoBinding, PluginDescriptor pluginDescriptor = loadPluginDescriptor( mojoBinding, plan, project, session, allowUnbindableMojos );
plan,
project,
session,
allowUnbindableMojos );
if ( pluginDescriptor == null ) if ( pluginDescriptor == null )
{ {
@ -314,14 +310,11 @@ private void addReportingLifecycleModifiers( final BuildPlan plan,
} }
} }
private PluginDescriptor loadPluginDescriptor( final MojoBinding mojoBinding, private PluginDescriptor loadPluginDescriptor( final MojoBinding mojoBinding, final BuildPlan plan, final MavenProject project, final MavenSession session, final boolean allowUnbindableMojos )
final BuildPlan plan,
final MavenProject project,
final MavenSession session,
final boolean allowUnbindableMojos )
throws LifecyclePlannerException throws LifecyclePlannerException
{ {
PluginDescriptor pluginDescriptor = null; PluginDescriptor pluginDescriptor = null;
try try
{ {
pluginDescriptor = pluginLoader.loadPlugin( mojoBinding, project, session ); pluginDescriptor = pluginLoader.loadPlugin( mojoBinding, project, session );
@ -330,9 +323,7 @@ private PluginDescriptor loadPluginDescriptor( final MojoBinding mojoBinding,
{ {
if ( allowUnbindableMojos ) if ( allowUnbindableMojos )
{ {
String message = "Failed to load plugin: " String message = "Failed to load plugin: " + MojoBindingUtils.createPluginKey( mojoBinding ) + ". Adding to late-bound plugins list.\nReason: " + e.getMessage();
+ MojoBindingUtils.createPluginKey( mojoBinding )
+ ". Adding to late-bound plugins list.\nReason: " + e.getMessage();
if ( logger.isDebugEnabled() ) if ( logger.isDebugEnabled() )
{ {

View File

@ -64,7 +64,7 @@ public PluginDescriptor loadPlugin( MojoBinding mojoBinding, MavenProject projec
*/ */
public PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, MavenSession session ) public PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, MavenSession session )
throws PluginLoaderException throws PluginLoaderException
{ {
if ( plugin.getGroupId() == null ) if ( plugin.getGroupId() == null )
{ {
plugin.setGroupId( PluginDescriptor.getDefaultPluginGroupId() ); plugin.setGroupId( PluginDescriptor.getDefaultPluginGroupId() );

View File

@ -83,12 +83,12 @@ public Artifact resolvePluginArtifact( Plugin plugin, MavenProject project, Mave
MavenProject pluginProject = buildPluginProject( plugin, localRepository, project.getRemoteArtifactRepositories() ); MavenProject pluginProject = buildPluginProject( plugin, localRepository, project.getRemoteArtifactRepositories() );
Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() );
checkRequiredMavenVersion( plugin, pluginProject, localRepository, project.getRemoteArtifactRepositories() ); checkRequiredMavenVersion( plugin, pluginProject, localRepository, project.getRemoteArtifactRepositories() );
checkPluginDependencySpec( plugin, pluginProject ); checkPluginDependencySpec( plugin, pluginProject );
Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() );
pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact ); pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact );
ArtifactResolutionRequest request = new ArtifactResolutionRequest( pluginArtifact, localRepository, project.getRemoteArtifactRepositories() ); ArtifactResolutionRequest request = new ArtifactResolutionRequest( pluginArtifact, localRepository, project.getRemoteArtifactRepositories() );
@ -100,13 +100,15 @@ public Artifact resolvePluginArtifact( Plugin plugin, MavenProject project, Mave
return pluginArtifact; return pluginArtifact;
} }
public MavenProject buildPluginProject( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories ) public MavenProject buildPluginProject( Plugin plugin, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws InvalidPluginException throws InvalidPluginException
{ {
Artifact artifact = repositorySystem.createProjectArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ); Artifact artifact = repositorySystem.createProjectArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() );
try try
{ {
return mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository ); MavenProject p = mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository );
return p;
} }
catch ( ProjectBuildingException e ) catch ( ProjectBuildingException e )
{ {

View File

@ -17,7 +17,7 @@ public interface PluginManagerSupport
Artifact resolvePluginArtifact( Plugin plugin, MavenProject project, MavenSession session ) Artifact resolvePluginArtifact( Plugin plugin, MavenProject project, MavenSession session )
throws PluginManagerException, InvalidPluginException, PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException; throws PluginManagerException, InvalidPluginException, PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException;
MavenProject buildPluginProject( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories ) MavenProject buildPluginProject( Plugin plugin, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws InvalidPluginException; throws InvalidPluginException;
/** /**

View File

@ -274,19 +274,20 @@ private void processRepositoriesInSettings( MavenExecutionRequest request, Confi
for ( Server server : settings.getServers() ) for ( Server server : settings.getServers() )
{ {
String pass; String password;
String phrase; String passPhrase;
try try
{ {
pass = securityDispatcher.decrypt( server.getPassword() ); password = securityDispatcher.decrypt( server.getPassword() );
phrase = securityDispatcher.decrypt( server.getPassphrase() ); passPhrase = securityDispatcher.decrypt( server.getPassphrase() );
} }
catch ( SecDispatcherException e ) catch ( SecDispatcherException e )
{ {
throw new MavenEmbedderException( "Error decrypting server password/passphrase.", e ); throw new MavenEmbedderException( "Error decrypting server password/passphrase.", e );
} }
repositorySystem.addAuthenticationInfo( server.getId(), server.getUsername(), pass, server.getPrivateKey(), phrase ); repositorySystem.addAuthenticationInfo( server.getId(), server.getUsername(), password, server.getPrivateKey(), passPhrase );
repositorySystem.addPermissionInfo( server.getId(), server.getFilePermissions(), server.getDirectoryPermissions() ); repositorySystem.addPermissionInfo( server.getId(), server.getFilePermissions(), server.getDirectoryPermissions() );
} }

View File

@ -217,21 +217,12 @@ public MavenProject buildFromRepository( Artifact artifact, List remoteRepositor
{ {
return project; return project;
} }
List<ArtifactRepository> artifactRepositories = new ArrayList<ArtifactRepository>( remoteRepositories );
try
{
artifactRepositories.addAll( repositorySystem.buildArtifactRepositories( getSuperModel().getRepositories() ) );
}
catch ( InvalidRepositoryException e )
{
throw new ProjectBuildingException( "Cannot create repositories from super model.", e.getMessage() );
}
File f = (artifact.getFile() != null) ? artifact.getFile() : new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) ); File f = (artifact.getFile() != null) ? artifact.getFile() : new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
try
{ try
repositorySystem.findModelFromRepository( artifact, artifactRepositories, localRepository ); {
repositorySystem.findModelFromRepository( artifact, remoteRepositories, localRepository );
} }
catch ( ArtifactResolutionException e ) catch ( ArtifactResolutionException e )
{ {
@ -250,7 +241,8 @@ public MavenProject buildFromRepository( Artifact artifact, List remoteRepositor
.setLocalRepository( localRepository ) .setLocalRepository( localRepository )
.setRemoteRepositories( remoteRepositories ); .setRemoteRepositories( remoteRepositories );
project = readModelFromLocalPath( "unknown", artifact.getFile(), config.getLocalRepository(), artifactRepositories, config ); project = readModelFromLocalPath( "unknown", artifact.getFile(), config.getLocalRepository(), remoteRepositories
, config );
project = buildWithProfiles( project.getModel(), config, artifact.getFile(), project.getParentFile() ); project = buildWithProfiles( project.getModel(), config, artifact.getFile(), project.getParentFile() );
artifact.setFile( f ); artifact.setFile( f );
project.setVersion( artifact.getVersion() ); project.setVersion( artifact.getVersion() );

View File

@ -91,36 +91,23 @@ public void clearMirrors()
public List<ArtifactRepository> getMirrors( List<ArtifactRepository> remoteRepositories ) public List<ArtifactRepository> getMirrors( List<ArtifactRepository> remoteRepositories )
{ {
Set<ArtifactRepository> remoteRepositoriesWithMirrors = new LinkedHashSet<ArtifactRepository>();
if ( remoteRepositories != null ) if ( remoteRepositories != null )
{ {
for ( ArtifactRepository repository : remoteRepositories) for ( ArtifactRepository repository : remoteRepositories)
{ {
// Check to see if we have a valid mirror for this repository // Check to see if we have a valid mirror for this repository
ArtifactRepository mirror = getMirror( repository ); ArtifactRepository mirror = getMirror( repository );
if ( mirror != null )
{
// Make sure that we take the the properties of the repository we are mirroring we want to direct
// all requests for this mirror at the mirror, but the mirror specification does not allow for
// any of the regular settings.
mirror.setLayout( repository.getLayout() );
mirror.setSnapshotUpdatePolicy( repository.getSnapshots() );
mirror.setReleaseUpdatePolicy( repository.getReleases() );
// If there is a valid mirror for this repository then we'll enter the mirror as a replacement for this repository. if ( mirror != null )
remoteRepositoriesWithMirrors.add( mirror ); {
} // We basically just want to take the URL
else repository.setUrl( mirror.getUrl() );
{ repository.setId( repository.getId() + "-" + mirror.getId() );
// If we have no valid mirrors for this repository we will keep this repository in the list.
remoteRepositoriesWithMirrors.add( repository );
} }
} }
} }
return new ArrayList<ArtifactRepository>( remoteRepositoriesWithMirrors ); return remoteRepositories;
} }
// Make these available to tests // Make these available to tests

View File

@ -448,19 +448,14 @@ public void setGlobalChecksumPolicy( String policy )
public void findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository ) public void findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository )
throws InvalidRepositoryException, ArtifactResolutionException, ArtifactNotFoundException throws InvalidRepositoryException, ArtifactResolutionException, ArtifactNotFoundException
{ {
if ( cache.containsKey( artifact.getId() ) ) if ( cache.containsKey( artifact.getId() ) )
{ {
artifact.setFile( cache.get( artifact.getId() ).getFile() ); artifact.setFile( cache.get( artifact.getId() ).getFile() );
} }
String projectId = safeVersionlessKey( artifact.getGroupId(), artifact.getArtifactId() );
remoteArtifactRepositories = normalizeToArtifactRepositories( remoteArtifactRepositories, projectId );
Artifact projectArtifact;
// if the artifact is not a POM, we need to construct a POM artifact based on the artifact parameter given. // 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() ) ) if ( "pom".equals( artifact.getType() ) )
{ {
projectArtifact = artifact; projectArtifact = artifact;
@ -472,55 +467,15 @@ public void findModelFromRepository( Artifact artifact, List remoteArtifactRepos
projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope() ); projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope() );
} }
*/
ArtifactResolutionRequest request =
new ArtifactResolutionRequest( projectArtifact, localRepository, remoteArtifactRepositories ); ArtifactResolutionRequest request = new ArtifactResolutionRequest( artifact, localRepository, remoteArtifactRepositories );
ArtifactResolutionResult result = resolve( request ); ArtifactResolutionResult result = resolve( request );
resolutionErrorHandler.throwErrors( request, result ); resolutionErrorHandler.throwErrors( request, result );
File file = projectArtifact.getFile();
artifact.setFile( file );
cache.put( artifact.getId(), artifact ); cache.put( artifact.getId(), artifact );
} }
private List normalizeToArtifactRepositories( List remoteArtifactRepositories, String projectId )
throws InvalidRepositoryException
{
List normalized = new ArrayList( remoteArtifactRepositories.size() );
boolean normalizationNeeded = false;
for ( Iterator it = remoteArtifactRepositories.iterator(); it.hasNext(); )
{
Object item = it.next();
if ( item instanceof ArtifactRepository )
{
normalized.add( item );
}
else if ( item instanceof Repository )
{
Repository repo = (Repository) item;
item = buildArtifactRepository( repo );
normalized.add( item );
normalizationNeeded = true;
}
else
{
throw new InvalidRepositoryException( projectId, "Error building artifact repository from non-repository information item: " + item );
}
}
if ( normalizationNeeded )
{
return normalized;
}
else
{
return remoteArtifactRepositories;
}
}
private String safeVersionlessKey( String groupId, String artifactId ) private String safeVersionlessKey( String groupId, String artifactId )
{ {
String gid = groupId; String gid = groupId;

View File

@ -1,8 +1,6 @@
package org.apache.maven.repository; package org.apache.maven.repository;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;