diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index 0654477638..d620ad2285 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -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,13 +96,16 @@ public class DefaultLifecycleExecutor private Logger logger; @Requirement - private PluginManager pluginManager; + private BuildPluginManager pluginManager; @Requirement protected RepositorySystem repositorySystem; @Requirement private ProjectDependenciesResolver projectDependenciesResolver; + + @Requirement + private PluginVersionResolver pluginVersionResolver; // @Configuration(source="org/apache/maven/lifecycle/lifecycles.xml") private List 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 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 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 ); } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java index 592e2e232d..1dd1f2993b 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java @@ -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 @@ -73,9 +74,6 @@ public interface LifecycleExecutor // void populateDefaultConfigurationForPlugins( Collection plugins, RepositoryRequest repositoryRequest ) throws LifecycleExecutionException; - - void resolvePluginVersion( Plugin plugin, RepositoryRequest repositoryRequest ) - throws PluginNotFoundException; void execute( MavenSession session ); } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/BuildPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/BuildPluginManager.java new file mode 100644 index 0000000000..5f1b833df7 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/plugin/BuildPluginManager.java @@ -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; +} \ No newline at end of file diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java similarity index 98% rename from maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java rename to maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java index 31c09d93eb..b461d1e018 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java @@ -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 diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginLoaderException.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginLoaderException.java index 2eeaf768b1..161e1c4e7c 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginLoaderException.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginLoaderException.java @@ -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 diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java index 407bfbd930..e3ba4b0fe9 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java @@ -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 - * - * 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. + * 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.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 Jason van Zyl + * @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 ); - ClassRealm getPluginRealm( MavenSession session, PluginDescriptor pluginDescriptor ) - throws PluginManagerException; -} \ No newline at end of file + 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; + +} diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java new file mode 100644 index 0000000000..ca78102c76 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java @@ -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; + } + +} diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionRequest.java b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionRequest.java new file mode 100644 index 0000000000..bd470cbd21 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionRequest.java @@ -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 getRemoteRepositories() + { + return repositoryRequest.getRemoteRepositories(); + } + + public DefaultPluginVersionRequest setRemoteRepositories( List remoteRepositories ) + { + repositoryRequest.setRemoteRepositories( remoteRepositories ); + + return this; + } + + public boolean isOffline() + { + return repositoryRequest.isOffline(); + } + + public DefaultPluginVersionRequest setOffline( boolean offline ) + { + repositoryRequest.setOffline( offline ); + + return this; + } + +} diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginVersionNotFoundException.java b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionNotFoundException.java similarity index 97% rename from maven-core/src/main/java/org/apache/maven/plugin/PluginVersionNotFoundException.java rename to maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionNotFoundException.java index 03fa077128..b5539be0c5 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginVersionNotFoundException.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionNotFoundException.java @@ -1,4 +1,4 @@ -package org.apache.maven.plugin; +package org.apache.maven.plugin.version; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionRequest.java b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionRequest.java new file mode 100644 index 0000000000..215f3a9580 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionRequest.java @@ -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 getRemoteRepositories(); + + /** + * Sets the remote repositories to use. + * + * @param remoteRepositories The remote repositories to use. + * @return This request, never {@code null}. + */ + PluginVersionRequest setRemoteRepositories( List 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 ); + +} diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginVersionResolutionException.java b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResolutionException.java similarity index 86% rename from maven-core/src/main/java/org/apache/maven/plugin/PluginVersionResolutionException.java rename to maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResolutionException.java index a9a3cc61c9..dda533eaef 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginVersionResolutionException.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResolutionException.java @@ -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 ); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResolver.java new file mode 100644 index 0000000000..fe67028061 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResolver.java @@ -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; + +} diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResult.java b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResult.java new file mode 100644 index 0000000000..0454ecdfcf --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResult.java @@ -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(); + +} diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java new file mode 100644 index 0000000000..57b6b44881 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java @@ -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; + } + +} diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResult.java b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResult.java new file mode 100644 index 0000000000..24116a1cb9 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResult.java @@ -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; + } + +} diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java b/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java index 7a46c7ff97..60fda4b309 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java @@ -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 ); } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java index f5154ed52f..f629af02be 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java @@ -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 createArtifactRepositories( List pomRepositories, List 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 ); diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingHelper.java b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingHelper.java index 3a6828c083..f879d279ba 100644 --- a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingHelper.java +++ b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingHelper.java @@ -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; } diff --git a/maven-core/src/main/resources/META-INF/plexus/components.xml b/maven-core/src/main/resources/META-INF/plexus/components.xml index 043618c948..037120ff60 100644 --- a/maven-core/src/main/resources/META-INF/plexus/components.xml +++ b/maven-core/src/main/resources/META-INF/plexus/components.xml @@ -12,7 +12,7 @@ @@ -33,7 +33,7 @@ logger - org.apache.maven.plugin.PluginManager + org.apache.maven.plugin.BuildPluginManager org.apache.maven.ProjectDependenciesResolver @@ -45,6 +45,9 @@ org.apache.maven.lifecycle.mapping.LifecycleMapping lifecycleMappings + + org.apache.maven.plugin.version.PluginVersionResolver + diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java index bfb7f6e614..4f3453dc8c 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java @@ -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