From e6d8aeb6c07dce155ff5b8043c431dc2c17cdeb3 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Sat, 12 Mar 2005 21:54:21 +0000 Subject: [PATCH] o allowing the selective execution of a set of mojos inside a plugins by specifying a section inside a configuration. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163539 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/maven/DefaultMaven.java | 16 ++- .../lifecycle/DefaultLifecycleExecutor.java | 121 +++++++++++++----- .../maven/plugin/DefaultPluginManager.java | 3 +- .../project/DefaultMavenProjectBuilder.java | 2 +- 4 files changed, 106 insertions(+), 36 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index 8269a140a9..4568e9d09c 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -152,18 +152,24 @@ public class DefaultMaven if ( project.getModules() != null && !project.getModules().isEmpty() ) { - String includes = StringUtils.join( project.getModules().iterator(), "/pom.xml," ) + - "/pom.xml"; + String includes = StringUtils.join( project.getModules().iterator(), "/pom.xml," ) + "/pom.xml"; + File baseDir = project.getFile().getParentFile(); + MavenExecutionRequest reactorRequest = new DefaultMavenExecutionRequest( - request.getLocalRepository(), request.getUserModel(), request.getEventDispatcher(), - request.getGoals(), FileUtils.getFiles( baseDir, includes, null ), baseDir.getPath() ); + request.getLocalRepository(), + request.getUserModel(), + request.getEventDispatcher(), + request.getGoals(), + FileUtils.getFiles( baseDir, includes, null ), + baseDir.getPath() ); + MavenExecutionResponse response = execute( reactorRequest ); + if ( response != null && response.isExecutionFailure() ) { return response; } - } if ( !isPom ) 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 2da6a0558c..e3d04ca67a 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 @@ -23,6 +23,7 @@ import org.apache.maven.execution.MavenExecutionResponse; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginManagement; +import org.apache.maven.model.Goal; import org.apache.maven.monitor.event.EventDispatcher; import org.apache.maven.monitor.event.MavenEvents; import org.apache.maven.plugin.PluginExecutionResponse; @@ -84,27 +85,35 @@ public class DefaultLifecycleExecutor { MavenProject project = session.getProject(); - // TODO: should enrich this with the type handler, but for now just + // TODO: should enrich this with the type artifactHandler, but for now just // use "type" as is - ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( project.getPackaging() ); + ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( project.getPackaging() ); - if ( handler != null ) + if ( artifactHandler != null ) { // TODO: perhaps each type should define their own lifecycle // completely, using the base as a default? - // If so, remove both of these goals from type handler - if ( handler.packageGoal() != null ) + // If so, remove both of these goals from type artifactHandler + if ( artifactHandler.packageGoal() != null ) { - verifyMojoPhase( handler.packageGoal(), session ); + verifyMojoPhase( artifactHandler.packageGoal(), session ); } - if ( handler.additionalPlugin() != null ) + + if ( artifactHandler.additionalPlugin() != null ) { String additionalPluginGroupId = "maven"; - String additionalPluginArtifactId = "maven-" + handler.additionalPlugin() + "-plugin"; + + String additionalPluginArtifactId = "maven-" + artifactHandler.additionalPlugin() + "-plugin"; injectHandlerPluginConfiguration( project, additionalPluginGroupId, additionalPluginArtifactId ); - processPluginPhases( "maven", "maven-" + handler.additionalPlugin() + "-plugin", session ); + Plugin plugin = new Plugin(); + + plugin.setGroupId( additionalPluginGroupId ); + + plugin.setArtifactId( additionalPluginArtifactId ); + + processPluginPhases( plugin, session ); } } @@ -149,18 +158,22 @@ public class DefaultLifecycleExecutor private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId ) { - PluginManagement mgmt = project.getPluginManagement(); - if( mgmt != null ) + PluginManagement pluginManagement = project.getPluginManagement(); + + if ( pluginManagement != null ) { - List pluginList = mgmt.getPlugins(); + List pluginList = pluginManagement.getPlugins(); Plugin handlerPlugin = null; + for ( Iterator it = pluginList.iterator(); it.hasNext(); ) { Plugin plugin = (Plugin) it.next(); + if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) ) { handlerPlugin = plugin; + break; } } @@ -180,33 +193,78 @@ public class DefaultLifecycleExecutor { Plugin plugin = (Plugin) i.next(); - // TODO: should this flag be used in verifyPlugin, completely disabling the plugin? - if ( Boolean.TRUE != plugin.isDisabled() ) + processPluginPhases( plugin, mavenSession ); + } + } + + /** + * Take each mojo contained with a plugin, look to see whether it contributes to a + * phase in the lifecycle and if it does place it at the end of the list of goals + * to execute for that given phase. + * + * @param mavenSession + * @throws Exception + */ + // TODO: don't throw Exception + private void processPluginPhases( Plugin plugin, MavenSession mavenSession ) + throws Exception + { + String groupId = plugin.getGroupId(); + + String artifactId = plugin.getArtifactId(); + + pluginManager.verifyPlugin( groupId, artifactId, mavenSession ); + + PluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptor( groupId, artifactId ); + + // ---------------------------------------------------------------------- + // Look to see if the plugin configuration specifies particular mojos + // within the plugin. If this is the case then simply configure the + // mojos the user has specified and ignore the rest. + // ---------------------------------------------------------------------- + + + if ( plugin.getGoals().size() > 0 ) + { + String pluginId = pluginDescriptor.getArtifactId(); + + pluginId = pluginId.substring( 6 ).substring( 0, 7 ); + + for ( Iterator i = plugin.getGoals().iterator(); i.hasNext(); ) { - processPluginPhases( plugin.getGroupId(), plugin.getArtifactId(), mavenSession ); + Goal goal = (Goal) i.next(); + + configureMojo( pluginManager.getMojoDescriptor( pluginId + ":" + goal.getId() ) ); + } + } + else + { + for ( Iterator j = pluginDescriptor.getMojos().iterator(); j.hasNext(); ) + { + MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next(); + + configureMojo( mojoDescriptor ); } } } - // TODO: don't throw Exception - private void processPluginPhases( String groupId, String artifactId, MavenSession mavenSession ) + /** + * Take a look at a mojo contained within a plugin, look to see whether it contributes to a + * phase in the lifecycle and if it does place it at the end of the list of goals + * to execute for the stated phase. + * + * @param mojoDescriptor + * @throws Exception + */ + private void configureMojo( MojoDescriptor mojoDescriptor ) throws Exception { - pluginManager.verifyPlugin( groupId, artifactId, mavenSession ); - PluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptor( groupId, artifactId ); - for ( Iterator j = pluginDescriptor.getMojos().iterator(); j.hasNext(); ) + if ( mojoDescriptor.getPhase() != null ) { - MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next(); + Phase phase = (Phase) phaseMap.get( mojoDescriptor.getPhase() ); - // TODO: check if the goal exists in the configuration and is - // disabled - if ( mojoDescriptor.getPhase() != null ) - { - Phase phase = (Phase) phaseMap.get( mojoDescriptor.getPhase() ); - phase.getGoals().add( mojoDescriptor.getId() ); - } + phase.getGoals().add( mojoDescriptor.getId() ); } - } private void processGoalChain( String task, MavenSession session ) @@ -242,10 +300,13 @@ public class DefaultLifecycleExecutor throws Exception { MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( task ); + if ( mojoDescriptor == null ) { pluginManager.verifyPluginForGoal( task, session ); + mojoDescriptor = pluginManager.getMojoDescriptor( task ); + if ( mojoDescriptor == null ) { throw new LifecycleExecutionException( "Required goal not found: " + task ); @@ -254,6 +315,7 @@ public class DefaultLifecycleExecutor if ( mojoDescriptor.getPhase() != null ) { Phase phase = (Phase) phaseMap.get( mojoDescriptor.getPhase() ); + phase.getGoals().add( task ); } } @@ -289,6 +351,7 @@ public class DefaultLifecycleExecutor if ( pluginResponse.isExecutionFailure() ) { response.setExecutionFailure( goal, pluginResponse.getFailureResponse() ); + return; } } 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 559fb4ab79..7217dffc6d 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 @@ -444,7 +444,8 @@ public class DefaultPluginManager // Mojo Parameter Handling // ---------------------------------------------------------------------- - public static Map createParameters( MojoDescriptor goal, MavenSession session ) throws PluginConfigurationException + public static Map createParameters( MojoDescriptor goal, MavenSession session ) + throws PluginConfigurationException { Map map = null; diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 1f3af19d84..fbdfedfea2 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -2,7 +2,7 @@ package org.apache.maven.project; /* * Copyright 2001-2005 The Apache Software Foundation. - * + * * Licensed 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