o Renamed new plugin manager to make room for the legacy impl that will provide backward-compat with existing plugins

o Extracted plugin version resolution into a dedicated component

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@805962 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-08-19 20:24:35 +00:00
parent 68ca923fb5
commit ff4d83c2d5
20 changed files with 914 additions and 147 deletions

View File

@ -54,7 +54,7 @@ import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.MojoNotFoundException;
import org.apache.maven.plugin.PluginConfigurationException;
import org.apache.maven.plugin.PluginDescriptorParsingException;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.PluginManagerException;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.PluginResolutionException;
@ -63,6 +63,10 @@ import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.lifecycle.Execution;
import org.apache.maven.plugin.lifecycle.Phase;
import org.apache.maven.plugin.version.DefaultPluginVersionRequest;
import org.apache.maven.plugin.version.PluginVersionRequest;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.plugin.version.PluginVersionResolver;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.wagon.ResourceDoesNotExistException;
@ -92,7 +96,7 @@ public class DefaultLifecycleExecutor
private Logger logger;
@Requirement
private PluginManager pluginManager;
private BuildPluginManager pluginManager;
@Requirement
protected RepositorySystem repositorySystem;
@ -100,6 +104,9 @@ public class DefaultLifecycleExecutor
@Requirement
private ProjectDependenciesResolver projectDependenciesResolver;
@Requirement
private PluginVersionResolver pluginVersionResolver;
// @Configuration(source="org/apache/maven/lifecycle/lifecycles.xml")
private List<Lifecycle> lifecycles;
@ -379,7 +386,7 @@ public class DefaultLifecycleExecutor
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException,
InvalidPluginDescriptorException, PluginManagerException, LifecyclePhaseNotFoundException,
LifecycleNotFoundException
LifecycleNotFoundException, PluginVersionResolutionException
{
MavenProject project = session.getCurrentProject();
@ -464,7 +471,7 @@ public class DefaultLifecycleExecutor
}
private void calculateExecutionForIndividualGoal( MavenSession session, List<MojoExecution> lifecyclePlan, String goal )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, PluginVersionResolutionException
{
// If this is a goal like "mvn modello:java" and the POM looks like the following:
//
@ -623,7 +630,7 @@ public class DefaultLifecycleExecutor
Collection<MojoDescriptor> alreadyForkedExecutions )
throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
PluginDescriptorParsingException, CycleDetectedInPluginGraphException, NoPluginFoundForPrefixException,
InvalidPluginDescriptorException, LifecyclePhaseNotFoundException, LifecycleNotFoundException
InvalidPluginDescriptorException, LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
@ -889,7 +896,7 @@ public class DefaultLifecycleExecutor
// org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process
MojoDescriptor getMojoDescriptor( String task, MavenSession session )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, PluginVersionResolutionException
{
MavenProject project = session.getCurrentProject();
@ -971,98 +978,11 @@ public class DefaultLifecycleExecutor
return pluginManager.getMojoDescriptor( plugin, goal, repositoryRequest );
}
public void resolvePluginVersion( Plugin plugin, RepositoryRequest repositoryRequest )
throws PluginNotFoundException
private void resolvePluginVersion( Plugin plugin, RepositoryRequest repositoryRequest )
throws PluginVersionResolutionException
{
ArtifactRepository localRepository = repositoryRequest.getLocalRepository();
File artifactMetadataFile = null;
String localPath;
// Search in remote repositories for a (released) version.
//
// maven-metadata-{central|nexus|...}.xml
//
//TODO: we should cycle through the repositories but take the repository which actually
// satisfied the prefix.
for ( ArtifactRepository repository : repositoryRequest.getRemoteRepositories() )
{
localPath = plugin.getGroupId().replace( '.', '/' ) + "/" + plugin.getArtifactId() + "/maven-metadata-" + repository.getId() + ".xml";
artifactMetadataFile = new File( localRepository.getBasedir(), localPath );
if ( !artifactMetadataFile.exists() /* || user requests snapshot updates */)
{
try
{
String remotePath = plugin.getGroupId().replace( '.', '/' ) + "/" + plugin.getArtifactId() + "/maven-metadata.xml";
repositorySystem.retrieve( repository, artifactMetadataFile, remotePath, null );
}
catch ( TransferFailedException e )
{
continue;
}
catch ( ResourceDoesNotExistException e )
{
continue;
}
}
break;
}
// Search in the local repositiory for a (development) version
//
// maven-metadata-local.xml
//
if ( artifactMetadataFile == null || !artifactMetadataFile.exists() )
{
localPath =
plugin.getGroupId().replace( '.', '/' ) + "/" + plugin.getArtifactId() + "/maven-metadata-"
+ localRepository.getId() + ".xml";
artifactMetadataFile = new File( localRepository.getBasedir(), localPath );
}
if ( artifactMetadataFile.exists() )
{
logger.debug( "Extracting version for plugin " + plugin.getKey() + " from " + artifactMetadataFile );
try
{
Metadata pluginMetadata = readMetadata( artifactMetadataFile );
if ( pluginMetadata.getVersioning() != null )
{
String release = pluginMetadata.getVersioning().getRelease();
if ( StringUtils.isNotEmpty( release ) )
{
plugin.setVersion( release );
}
else
{
String latest = pluginMetadata.getVersioning().getLatest();
if ( StringUtils.isNotEmpty( latest ) )
{
plugin.setVersion( latest );
}
}
}
}
catch ( RepositoryMetadataReadException e )
{
logger.warn( "Error reading plugin metadata: ", e );
}
}
if ( StringUtils.isEmpty( plugin.getVersion() ) )
{
throw new PluginNotFoundException( plugin, repositoryRequest.getRemoteRepositories() );
}
PluginVersionRequest versionRequest = new DefaultPluginVersionRequest( plugin, repositoryRequest );
plugin.setVersion( pluginVersionResolver.resolve( versionRequest ).getVersion() );
}
private void injectPluginDeclarationFromProject( Plugin plugin, MavenProject project )
@ -1221,7 +1141,7 @@ public class DefaultLifecycleExecutor
{
resolvePluginVersion( plugin, repositoryRequest );
}
catch ( PluginNotFoundException e )
catch ( PluginVersionResolutionException e )
{
throw new LifecycleExecutionException( "Error resolving version for plugin " + plugin.getKey(), e );
}

View File

@ -32,6 +32,7 @@ import org.apache.maven.plugin.PluginDescriptorParsingException;
import org.apache.maven.plugin.PluginManagerException;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.PluginResolutionException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
/**
* @author Jason van Zyl
@ -51,7 +52,7 @@ public interface LifecycleExecutor
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException,
InvalidPluginDescriptorException, PluginManagerException, LifecyclePhaseNotFoundException,
LifecycleNotFoundException;
LifecycleNotFoundException, PluginVersionResolutionException;
// For a given project packaging find all the plugins that are bound to any registered
// lifecycles. The project builder needs to now what default plugin information needs to be
@ -74,8 +75,5 @@ public interface LifecycleExecutor
void populateDefaultConfigurationForPlugins( Collection<Plugin> plugins, RepositoryRequest repositoryRequest )
throws LifecycleExecutionException;
void resolvePluginVersion( Plugin plugin, RepositoryRequest repositoryRequest )
throws PluginNotFoundException;
void execute( MavenSession session );
}

View File

@ -0,0 +1,43 @@
package org.apache.maven.plugin;
/*
* 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.repository.RepositoryRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
/**
* @author Jason van Zyl
*/
public interface BuildPluginManager
{
// igorf: Way too many declared exceptions!
PluginDescriptor loadPlugin( Plugin plugin, RepositoryRequest repositoryRequest )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, InvalidPluginDescriptorException;
// igorf: Way too many declared exceptions!
MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, RepositoryRequest repositoryRequest )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, InvalidPluginDescriptorException;
void executeMojo( MavenSession session, MojoExecution execution )
throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException;
ClassRealm getPluginRealm( MavenSession session, PluginDescriptor pluginDescriptor )
throws PluginManagerException;
}

View File

@ -38,9 +38,9 @@ import org.codehaus.plexus.configuration.PlexusConfigurationException;
// TODO: the antrun plugin has its own configurator, the only plugin that does. might need to think about how that works
// TODO: remove the coreArtifactFilterManager
@Component(role = PluginManager.class)
public class DefaultPluginManager
implements PluginManager
@Component(role = BuildPluginManager.class)
public class DefaultBuildPluginManager
implements BuildPluginManager
{
@Requirement

View File

@ -24,6 +24,8 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
/**
* Signifies a failure to load a plugin. This is used to abstract the specific errors which may be

View File

@ -1,43 +1,83 @@
package org.apache.maven.plugin;
/*
* 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
* 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.
* 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.repository.RepositoryRequest;
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.versioning.InvalidVersionSpecificationException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.util.Map;
/**
* @author Jason van Zyl
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$
*/
@Deprecated
public interface PluginManager
{
// igorf: Way too many declared exceptions!
PluginDescriptor loadPlugin( Plugin plugin, RepositoryRequest repositoryRequest )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, InvalidPluginDescriptorException;
String ROLE = PluginManager.class.getName();
// igorf: Way too many declared exceptions!
MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, RepositoryRequest repositoryRequest )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, InvalidPluginDescriptorException;
void executeMojo( MavenProject project, MojoExecution execution, MavenSession session )
throws MojoExecutionException, ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException,
InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException;
void executeMojo( MavenSession session, MojoExecution execution )
throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException;
PluginDescriptor getPluginDescriptorForPrefix( String prefix );
Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project );
PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException;
Object getPluginComponent( Plugin plugin, String role, String roleHint )
throws PluginManagerException, ComponentLookupException;
Map getPluginComponents( Plugin plugin, String role )
throws ComponentLookupException, PluginManagerException;
/**
* @since 2.2.1
*/
PluginDescriptor loadPluginDescriptor( Plugin plugin, MavenProject project, MavenSession session )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException;
/**
* @since 2.2.1
*/
PluginDescriptor loadPluginFully( Plugin plugin, MavenProject project, MavenSession session )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException;
ClassRealm getPluginRealm( MavenSession session, PluginDescriptor pluginDescriptor )
throws PluginManagerException;
}

View File

@ -0,0 +1,121 @@
package org.apache.maven.plugin.internal;
/*
* 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 java.util.Map;
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.versioning.InvalidVersionSpecificationException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.InvalidPluginException;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.PluginConfigurationException;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.PluginManagerException;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
/**
* @author Benjamin Bentmann
*/
@Component( role = PluginManager.class )
public class DefaultPluginManager
implements PluginManager
{
@Requirement
private BuildPluginManager pluginManager;
public void executeMojo( MavenProject project, MojoExecution execution, MavenSession session )
throws MojoExecutionException, ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException,
InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException
{
throw new UnsupportedOperationException();
}
public Object getPluginComponent( Plugin plugin, String role, String roleHint )
throws PluginManagerException, ComponentLookupException
{
// TODO Auto-generated method stub
return null;
}
public Map getPluginComponents( Plugin plugin, String role )
throws ComponentLookupException, PluginManagerException
{
// TODO Auto-generated method stub
return null;
}
public Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project )
{
// TODO Auto-generated method stub
return null;
}
public PluginDescriptor getPluginDescriptorForPrefix( String prefix )
{
// TODO Auto-generated method stub
return null;
}
public PluginDescriptor loadPluginDescriptor( Plugin plugin, MavenProject project, MavenSession session )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException
{
// TODO Auto-generated method stub
return null;
}
public PluginDescriptor loadPluginFully( Plugin plugin, MavenProject project, MavenSession session )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException
{
// TODO Auto-generated method stub
return null;
}
public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException
{
// TODO Auto-generated method stub
return null;
}
}

View File

@ -0,0 +1,134 @@
package org.apache.maven.plugin.version;
/*
* 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 java.util.List;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
import org.apache.maven.artifact.repository.RepositoryCache;
import org.apache.maven.artifact.repository.RepositoryRequest;
import org.apache.maven.model.Plugin;
/**
* Collects settings required to resolve the version for a plugin.
*
* @author Benjamin Bentmann
*/
public class DefaultPluginVersionRequest
implements PluginVersionRequest
{
private String groupId;
private String artifactId;
private RepositoryRequest repositoryRequest;
public DefaultPluginVersionRequest()
{
repositoryRequest = new DefaultRepositoryRequest();
}
public DefaultPluginVersionRequest( RepositoryRequest repositoryRequest )
{
this.repositoryRequest = new DefaultRepositoryRequest( repositoryRequest );
}
public DefaultPluginVersionRequest( Plugin plugin, RepositoryRequest repositoryRequest )
{
this.groupId = plugin.getGroupId();
this.artifactId = plugin.getArtifactId();
this.repositoryRequest = new DefaultRepositoryRequest( repositoryRequest );
}
public String getGroupId()
{
return groupId;
}
public DefaultPluginVersionRequest setGroupId( String groupId )
{
this.groupId = groupId;
return this;
}
public String getArtifactId()
{
return artifactId;
}
public DefaultPluginVersionRequest setArtifactId( String artifactId )
{
this.artifactId = artifactId;
return this;
}
public RepositoryCache getCache()
{
return repositoryRequest.getCache();
}
public DefaultPluginVersionRequest setCache( RepositoryCache cache )
{
repositoryRequest.setCache( cache );
return this;
}
public ArtifactRepository getLocalRepository()
{
return repositoryRequest.getLocalRepository();
}
public DefaultPluginVersionRequest setLocalRepository( ArtifactRepository localRepository )
{
repositoryRequest.setLocalRepository( localRepository );
return this;
}
public List<ArtifactRepository> getRemoteRepositories()
{
return repositoryRequest.getRemoteRepositories();
}
public DefaultPluginVersionRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories )
{
repositoryRequest.setRemoteRepositories( remoteRepositories );
return this;
}
public boolean isOffline()
{
return repositoryRequest.isOffline();
}
public DefaultPluginVersionRequest setOffline( boolean offline )
{
repositoryRequest.setOffline( offline );
return this;
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.plugin;
package org.apache.maven.plugin.version;
/*
* Licensed to the Apache Software Foundation (ASF) under one

View File

@ -0,0 +1,127 @@
package org.apache.maven.plugin.version;
/*
* 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 java.util.List;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.RepositoryCache;
import org.apache.maven.artifact.repository.RepositoryRequest;
/**
* Collects settings required to resolve the version for a plugin.
*
* @author Benjamin Bentmann
*/
public interface PluginVersionRequest
extends RepositoryRequest
{
/**
* Gets the group id of the plugin.
*
* @return The group id of the plugin.
*/
String getGroupId();
/**
* Sets the group id of the plugin.
*
* @param groupId The group id of the plugin.
* @return This request, never {@code null}.
*/
PluginVersionRequest setGroupId( String groupId );
/**
* Gets the artifact id of the plugin.
*
* @return The artifact id of the plugin.
*/
String getArtifactId();
/**
* Sets the artifact id of the plugin.
*
* @param artifactId The artifact id of the plugin.
* @return This request, never {@code null}.
*/
PluginVersionRequest setArtifactId( String artifactId );
/**
* Indicates whether network access to remote repositories has been disabled.
*
* @return {@code true} if remote access has been disabled, {@code false} otherwise.
*/
boolean isOffline();
/**
* Enables/disables network access to remote repositories.
*
* @param offline {@code true} to disable remote access, {@code false} to allow network access.
* @return This request, never {@code null}.
*/
PluginVersionRequest setOffline( boolean offline );
/**
* Gets the local repository to use.
*
* @return The local repository to use or {@code null} if not set.
*/
ArtifactRepository getLocalRepository();
/**
* Sets the local repository to use.
*
* @param localRepository The local repository to use.
* @return This request, never {@code null}.
*/
PluginVersionRequest setLocalRepository( ArtifactRepository localRepository );
/**
* Gets the remote repositories to use.
*
* @return The remote repositories to use, never {@code null}.
*/
List<ArtifactRepository> getRemoteRepositories();
/**
* Sets the remote repositories to use.
*
* @param remoteRepositories The remote repositories to use.
* @return This request, never {@code null}.
*/
PluginVersionRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories );
/**
* Gets the repository cache to use.
*
* @return The repository cache to use or {@code null} if none.
*/
RepositoryCache getCache();
/**
* Sets the repository cache to use.
*
* @param cache The repository cache to use, may be {@code null}.
* @return This request, never {@code null}.
*/
PluginVersionRequest setCache( RepositoryCache cache );
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.plugin;
package org.apache.maven.plugin.version;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -31,6 +31,15 @@ public class PluginVersionResolutionException
private final String baseMessage;
public PluginVersionResolutionException( String groupId, String artifactId, String baseMessage, Throwable cause )
{
super( "Error resolving version for \'" + groupId + ":" + artifactId + "\': " + baseMessage, cause );
this.groupId = groupId;
this.artifactId = artifactId;
this.baseMessage = baseMessage;
}
public PluginVersionResolutionException( String groupId, String artifactId, String baseMessage, ArtifactMetadataRetrievalException cause )
{
super( "Error resolving version for \'" + groupId + ":" + artifactId + "\': " + baseMessage, cause );

View File

@ -0,0 +1,41 @@
package org.apache.maven.plugin.version;
/*
* 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.
*/
/**
* Resolves a version for a plugin.
*
* @author Benjamin Bentmann
*/
public interface PluginVersionResolver
{
/**
* Resolves the version for the specified request.
*
* @param request The request that holds the details about the plugin and the repositories to consult, must not be
* {@code null}.
* @return The result of the version resolutioh, never {@code null}.
* @throws PluginVersionResolutionException If the plugin version could not be resolved.
*/
PluginVersionResult resolve( PluginVersionRequest request )
throws PluginVersionResolutionException;
}

View File

@ -0,0 +1,46 @@
package org.apache.maven.plugin.version;
/*
* 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.repository.ArtifactRepository;
/**
* Describes the result of a plugin version resolution request.
*
* @author Benjamin Bentmann
*/
public interface PluginVersionResult
{
/**
* The resolved plugin version.
*
* @return The resolved plugin version, never {@code null}.
*/
String getVersion();
/**
* The repository from which the plugin version was resolved.
*
* @return The repository from which the plugin version was resolved, never {@code null}.
*/
ArtifactRepository getRepository();
}

View File

@ -0,0 +1,217 @@
package org.apache.maven.plugin.version.internal;
/*
* 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 java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Reader;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataReadException;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
import org.apache.maven.plugin.version.PluginVersionRequest;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.plugin.version.PluginVersionResolver;
import org.apache.maven.plugin.version.PluginVersionResult;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
* Resolves a version for a plugin.
*
* @author Benjamin Bentmann
*/
@Component( role = PluginVersionResolver.class )
public class DefaultPluginVersionResolver
implements PluginVersionResolver
{
@Requirement
private Logger logger;
@Requirement
private RepositorySystem repositorySystem;
public PluginVersionResult resolve( PluginVersionRequest request )
throws PluginVersionResolutionException
{
DefaultPluginVersionResult result = new DefaultPluginVersionResult();
Throwable error = null;
ArtifactRepository localRepository = request.getLocalRepository();
File artifactMetadataFile = null;
String localPath;
// Search in remote repositories for a (released) version.
//
// maven-metadata-{central|nexus|...}.xml
//
// TODO: we should cycle through the repositories but take the repository which actually
// satisfied the prefix.
for ( ArtifactRepository repository : request.getRemoteRepositories() )
{
localPath =
request.getGroupId().replace( '.', '/' ) + "/" + request.getArtifactId() + "/maven-metadata-"
+ repository.getId() + ".xml";
artifactMetadataFile = new File( localRepository.getBasedir(), localPath );
if ( !artifactMetadataFile.exists() /* || user requests snapshot updates */)
{
String remotePath =
request.getGroupId().replace( '.', '/' ) + "/" + request.getArtifactId() + "/maven-metadata.xml";
try
{
repositorySystem.retrieve( repository, artifactMetadataFile, remotePath, null );
}
catch ( TransferFailedException e )
{
error = e;
logger.debug( "Failed to retrieve " + remotePath, e );
continue;
}
catch ( ResourceDoesNotExistException e )
{
continue;
}
}
result.setRepository( repository );
break;
}
// Search in the local repositiory for a (development) version
//
// maven-metadata-local.xml
//
if ( artifactMetadataFile == null || !artifactMetadataFile.exists() )
{
localPath =
request.getGroupId().replace( '.', '/' ) + "/" + request.getArtifactId() + "/maven-metadata-"
+ localRepository.getId() + ".xml";
artifactMetadataFile = new File( localRepository.getBasedir(), localPath );
result.setRepository( localRepository );
}
if ( artifactMetadataFile.exists() )
{
logger.debug( "Extracting version for plugin " + request.getGroupId() + ':' + request.getArtifactId()
+ " from " + artifactMetadataFile );
try
{
Metadata pluginMetadata = readMetadata( artifactMetadataFile );
if ( pluginMetadata.getVersioning() != null )
{
String release = pluginMetadata.getVersioning().getRelease();
if ( StringUtils.isNotEmpty( release ) )
{
result.setVersion( release );
}
else
{
String latest = pluginMetadata.getVersioning().getLatest();
if ( StringUtils.isNotEmpty( latest ) )
{
result.setVersion( latest );
}
}
}
}
catch ( RepositoryMetadataReadException e )
{
throw new PluginVersionResolutionException( request.getGroupId(), request.getArtifactId(),
e.getMessage(), e );
}
}
else if ( error != null )
{
throw new PluginVersionResolutionException( request.getGroupId(), request.getArtifactId(),
error.getMessage(), error );
}
if ( StringUtils.isEmpty( result.getVersion() ) )
{
throw new PluginVersionResolutionException( request.getGroupId(), request.getArtifactId(),
"Plugin not found in any repository" );
}
return result;
}
private Metadata readMetadata( File mappingFile )
throws RepositoryMetadataReadException
{
Metadata result;
Reader reader = null;
try
{
reader = ReaderFactory.newXmlReader( mappingFile );
MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
result = mappingReader.read( reader, false );
}
catch ( FileNotFoundException e )
{
throw new RepositoryMetadataReadException( "Cannot read metadata from '" + mappingFile + "'", e );
}
catch ( IOException e )
{
throw new RepositoryMetadataReadException( "Cannot read metadata from '" + mappingFile + "': "
+ e.getMessage(), e );
}
catch ( XmlPullParserException e )
{
throw new RepositoryMetadataReadException( "Cannot read metadata from '" + mappingFile + "': "
+ e.getMessage(), e );
}
finally
{
IOUtil.close( reader );
}
return result;
}
}

View File

@ -0,0 +1,58 @@
package org.apache.maven.plugin.version.internal;
/*
* 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.repository.ArtifactRepository;
import org.apache.maven.plugin.version.PluginVersionResult;
/**
* Describes the result of a plugin version resolution request.
*
* @author Benjamin Bentmann
*/
class DefaultPluginVersionResult
implements PluginVersionResult
{
private String version;
private ArtifactRepository repository;
public String getVersion()
{
return version;
}
public void setVersion( String version )
{
this.version = version;
}
public ArtifactRepository getRepository()
{
return repository;
}
public void setRepository( ArtifactRepository repository )
{
this.repository = repository;
}
}

View File

@ -24,10 +24,11 @@ import java.util.List;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
import org.apache.maven.artifact.repository.RepositoryRequest;
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.model.Model;
import org.apache.maven.model.building.AbstractModelBuildingListener;
import org.apache.maven.model.building.ModelBuildingEvent;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
/**
@ -142,7 +143,11 @@ class DefaultModelBuildingListener
projectRealm = projectBuildingHelper.createProjectRealm( model, repositoryRequest );
}
catch ( AbstractArtifactResolutionException e )
catch ( ArtifactResolutionException e )
{
event.getProblems().addError( "Unresolveable build extensions: " + e.getMessage(), e );
}
catch ( PluginVersionResolutionException e )
{
event.getProblems().addError( "Unresolveable build extensions: " + e.getMessage(), e );
}

View File

@ -36,14 +36,16 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.classrealm.ClassRealmManager;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.Repository;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.version.DefaultPluginVersionRequest;
import org.apache.maven.plugin.version.PluginVersionRequest;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.plugin.version.PluginVersionResolver;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
@ -82,7 +84,7 @@ public class DefaultProjectBuildingHelper
private ArtifactFilterManager artifactFilterManager;
@Requirement
private LifecycleExecutor lifecycleExecutor;
private PluginVersionResolver pluginVersionResolver;
public List<ArtifactRepository> createArtifactRepositories( List<Repository> pomRepositories,
List<ArtifactRepository> externalRepositories )
@ -108,7 +110,7 @@ public class DefaultProjectBuildingHelper
}
public ClassRealm createProjectRealm( Model model, RepositoryRequest repositoryRequest )
throws ArtifactResolutionException, PluginNotFoundException
throws ArtifactResolutionException, PluginVersionResolutionException
{
ClassRealm projectRealm = null;
@ -149,7 +151,8 @@ public class DefaultProjectBuildingHelper
{
if ( plugin.getVersion() == null )
{
lifecycleExecutor.resolvePluginVersion( plugin, repositoryRequest );
PluginVersionRequest versionRequest = new DefaultPluginVersionRequest( plugin, repositoryRequest );
plugin.setVersion( pluginVersionResolver.resolve( versionRequest ).getVersion() );
}
Artifact artifact = repositorySystem.createPluginArtifact( plugin );

View File

@ -27,7 +27,7 @@ import org.apache.maven.artifact.repository.RepositoryRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.model.Model;
import org.apache.maven.model.Repository;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
/**
@ -62,6 +62,6 @@ public interface ProjectBuildingHelper
* @throws ArtifactResolutionException If any build extension could not be resolved.
*/
ClassRealm createProjectRealm( Model model, RepositoryRequest repositoryRequest )
throws ArtifactResolutionException, PluginNotFoundException;
throws ArtifactResolutionException, PluginVersionResolutionException;
}

View File

@ -12,7 +12,7 @@
<!--
There is currently only one component descriptor that cannot be generated from annotations because of the
accompanying configurationl. Our options are to embed this information programatically or use a configuration source
accompanying configuration. Our options are to embed this information programatically or use a configuration source
to pull in the lifecycle information.
-->
<component-set>
@ -33,7 +33,7 @@
<field-name>logger</field-name>
</requirement>
<requirement>
<role>org.apache.maven.plugin.PluginManager</role>
<role>org.apache.maven.plugin.BuildPluginManager</role>
</requirement>
<requirement>
<role>org.apache.maven.ProjectDependenciesResolver</role>
@ -45,6 +45,9 @@
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<field-name>lifecycleMappings</field-name>
</requirement>
<requirement>
<role>org.apache.maven.plugin.version.PluginVersionResolver</role>
</requirement>
</requirements>
<configuration>
<lifecycles>

View File

@ -17,7 +17,7 @@ public class PluginManagerTest
extends AbstractCoreMavenComponentTestCase
{
@Requirement
private DefaultPluginManager pluginManager;
private DefaultBuildPluginManager pluginManager;
private String plexusVersion = "1.0-beta-3.0.7";
@ -25,7 +25,7 @@ public class PluginManagerTest
throws Exception
{
super.setUp();
pluginManager = (DefaultPluginManager) lookup( PluginManager.class );
pluginManager = (DefaultBuildPluginManager) lookup( BuildPluginManager.class );
}
@Override