From 9a2c66dde1a7da7d11572cce84235265bb6e4e22 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Sun, 8 Mar 2009 18:22:23 +0000 Subject: [PATCH] o remove duplicate signature from the plugin manager git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@751492 13f79535-47bb-0310-9956-ffa450edef68 --- .../lifecycle/DefaultLifecycleExecutor.java | 2 +- .../org/apache/maven/lifecycle/Lifecycle.java | 101 +++++++++++++ .../maven/lifecycle/LifecycleExecutor.java | 5 +- .../maven/plugin/DefaultPluginManager.java | 136 +----------------- .../apache/maven/plugin/PluginManager.java | 36 +++-- 5 files changed, 128 insertions(+), 152 deletions(-) create mode 100644 maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java 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 7000ded209..9771c31fa4 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 @@ -1266,7 +1266,7 @@ public class DefaultLifecycleExecutor String prefix = tok.nextToken(); goal = tok.nextToken(); - plugin = pluginManager.getPluginDefinitionForPrefix( prefix, session, project ); + plugin = pluginManager.findPluginForPrefix( prefix, project, session ); if ( plugin == null ) { diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java b/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java new file mode 100644 index 0000000000..2101ec0f10 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java @@ -0,0 +1,101 @@ +package org.apache.maven.lifecycle; + +/* + * 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.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Class Lifecycle. + */ +public class Lifecycle +{ + /** + * Field id + */ + private String id; + + /** + * Field phases + */ + private List phases; + + /** + * default phases. + */ + private Map defaultPhases; + + /** + * Method addPhase + * + * @param phase + */ + public void addPhase( String phase ) + { + getPhases().add( phase ); + } //-- void addPhase(Phase) + + /** + * Method getId + */ + public String getId() + { + return this.id; + } //-- String getId() + + /** + * Method getPhases + */ + public List getPhases() + { + if ( this.phases == null ) + { + this.phases = new ArrayList(); + } + + return this.phases; + } //-- java.util.List getPhases() + + /** + * Method setId + * + * @param id + */ + public void setId( String id ) + { + this.id = id; + } //-- void setId(String) + + /** + * Method setPhases + * + * @param phases + */ + public void setPhases( List phases ) + { + this.phases = phases; + } //-- void setPhases(java.util.List) + + public Map getDefaultPhases() + { + return defaultPhases; + } +} 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 87e9ec67ed..b0282f9a64 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 @@ -26,11 +26,10 @@ import org.apache.maven.monitor.event.EventDispatcher; import org.apache.maven.project.MavenProject; /** - * @author Jason van Zyl - * @version $Id$ + * @author Jason van Zyl */ public interface LifecycleExecutor -{ +{ TaskValidationResult isTaskValid( String task, MavenSession session, MavenProject rootProject ); void execute( MavenSession session, ReactorManager rm, EventDispatcher dispatcher ) diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index 5a371d4612..dc2712ab8c 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -29,7 +29,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.commons.jxpath.JXPathContext; import org.apache.maven.ArtifactFilterManager; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; @@ -151,7 +150,7 @@ public class DefaultPluginManager // // ---------------------------------------------------------------------- - public Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project ) + public Plugin findPluginForPrefix( String prefix, MavenProject project, MavenSession session ) { // TODO: since this is only used in the lifecycle executor, maybe it should be moved there? There is no other // use for the mapping manager in here @@ -184,8 +183,6 @@ public class DefaultPluginManager { logger.debug( "In verifyVersionedPlugin for: " + plugin.getKey() ); - ArtifactRepository localRepository = session.getLocalRepository(); - // TODO: this might result in an artifact "RELEASE" being resolved continuously // FIXME: need to find out how a plugin gets marked as 'installed' // and no ChildContainer exists. The check for that below fixes @@ -1523,137 +1520,6 @@ public class DefaultPluginManager return ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri ); } - // Plugin Prefix Loader - - /** - * Determine the appropriate {@link PluginDescriptor} instance for use with the specified plugin - * prefix, using the following strategies (in order):
- *
    - *
  1. Search for a plugin that has already been loaded with the specified prefix
  2. - *
  3. Search for a plugin configured in the POM that has a matching prefix
  4. - *
  5. Search the pluginGroups specified in the settings.xml for a matching plugin
  6. - *
  7. Use groupId == org.apache.maven.plugins, and artifactId == maven-<prefix>-plugin, - * and try to resolve based on that.
  8. - *
- */ - public Plugin findPluginForPrefix( String prefix, MavenProject project, MavenSession session ) - throws PluginLoaderException - { - Set descriptors = pluginCollector.getPluginDescriptorsForPrefix( prefix ); - Map projectPluginMap = project.getBuild().getPluginsAsMap(); - - Plugin plugin = null; - - if ( descriptors != null ) - { - PluginDescriptor pluginDescriptor = null; - - for ( Iterator it = descriptors.iterator(); it.hasNext(); ) - { - PluginDescriptor pd = (PluginDescriptor) it.next(); - - Plugin projectPlugin = (Plugin) projectPluginMap.get( pd.getPluginLookupKey() ); - if ( ( projectPlugin != null ) && ( projectPlugin.getVersion() != null ) && projectPlugin.getVersion().equals( pd.getVersion() ) ) - { - pluginDescriptor = pd; - break; - } - } - - plugin = toPlugin( pluginDescriptor ); - } - - if ( plugin == null ) - { - PluginDescriptor pluginDescriptor = loadFromProjectForPrefixQuery( prefix, project, session ); - - plugin = toPlugin( pluginDescriptor ); - } - - if ( plugin == null ) - { - plugin = loadFromPrefixMapper( prefix, project, session ); - } - - if ( plugin == null ) - { - plugin = new Plugin(); - plugin.setArtifactId( PluginDescriptor.getDefaultPluginArtifactId( prefix ) ); - - PluginDescriptor pluginDescriptor = loadIsolatedPluginDescriptor( plugin, project, session ); - plugin = toPlugin( pluginDescriptor ); - } - - if ( plugin == null ) - { - throw new PluginLoaderException( "Cannot find plugin with prefix: " + prefix ); - } - - return plugin; - } - - private Plugin toPlugin( PluginDescriptor pluginDescriptor ) - { - if ( pluginDescriptor == null ) - { - return null; - } - - Plugin plugin = new Plugin(); - - plugin.setGroupId( pluginDescriptor.getGroupId() ); - plugin.setArtifactId( pluginDescriptor.getArtifactId() ); - plugin.setVersion( pluginDescriptor.getVersion() ); - - return plugin; - } - - /** - * Look for a plugin configured in the current project that has a prefix matching the one - * specified. Return the {@link PluginDescriptor} if a match is found. - */ - private PluginDescriptor loadFromProjectForPrefixQuery( String prefix, MavenProject project, MavenSession session ) - throws PluginLoaderException - { - PluginDescriptor result = null; - - for ( Iterator it = project.getBuildPlugins().iterator(); it.hasNext(); ) - { - Plugin plugin = (Plugin) it.next(); - - PluginDescriptor pluginDescriptor = loadIsolatedPluginDescriptor( plugin, project, session ); - - if ( ( pluginDescriptor != null ) && prefix.equals( pluginDescriptor.getGoalPrefix() ) ) - { - result = pluginDescriptor; - break; - } - } - - return result; - } - - /** - * Look for a plugin in the pluginGroups specified in the settings.xml that has a prefix - * matching the one specified. Return the {@link PluginDescriptor} if a match is found. - */ - private Plugin loadFromPrefixMapper( String prefix, MavenProject project, MavenSession session ) - throws PluginLoaderException - { - Plugin plugin = getByPrefix( prefix, session.getPluginGroups(), project.getRemoteArtifactRepositories(), session.getLocalRepository() ); - - if ( plugin != null ) - { - Plugin projectPlugin = (Plugin) project.getBuild().getPluginsAsMap().get( plugin.getKey() ); - if ( ( projectPlugin != null ) && ( projectPlugin.getVersion() != null ) ) - { - plugin.setVersion( projectPlugin.getVersion() ); - } - } - - return plugin; - } - public String resolvePluginVersion( String groupId, String artifactId, MavenProject project, MavenSession session ) throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException { 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 d9172eec34..35f7462a71 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 @@ -27,24 +27,34 @@ import org.apache.maven.reporting.MavenReport; /** * @author Jason van Zyl - * @version $Id$ */ public interface PluginManager { - void executeMojo( MavenProject project, MojoExecution execution, MavenSession session ) - throws ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException, InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException; - - MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session ) - throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException, ArtifactResolutionException; - - Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project ); - - Plugin findPluginForPrefix( String prefix, MavenProject project, MavenSession session ) - throws PluginLoaderException; - + // - find the plugin [extension point: any client may wish to do whatever they choose] + // - load the plugin [extension point: we want to take them from a repository, some may take from disk or whatever] + // - configure the plugin + // - execute the plugin + + Plugin findPluginForPrefix( String prefix, MavenProject project, MavenSession session ); + PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, MavenSession session ) throws PluginLoaderException; - + + //!!jvz + // Clean up the exceptions returned. We should not be coupled to the repository layer. We need to generalize to allow a general plugin mechanism. + void executeMojo( MavenProject project, MojoExecution execution, MavenSession session ) + throws ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException, InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException; + + //!!jvz + // Reporting + // As a function inside Maven is wrong. This needs to be entirely delegated to an external system. We need to provide an extension + // point for any tools that want to hook into the lifecycle but burning reporting into the core is extremely bad coupling. We need + // an aliasing mechanism for the POM as not to break backward compat. During 3.0 we can support this and at 3.1 with changes to the + // model we turf it. + + MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session ) + throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException, ArtifactResolutionException; + PluginDescriptor loadReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session ) throws PluginLoaderException; } \ No newline at end of file