From 7f7a1049e616b1406f1089b1cdd89d2f146bb016 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Wed, 4 May 2005 16:23:42 +0000 Subject: [PATCH] improve the artifact ID parsing - any maven or plugin is removed to get the default prefix. If you want something different, use the configuration for plugin:descriptor git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@168141 13f79535-47bb-0310-9956-ffa450edef68 --- .../lifecycle/DefaultLifecycleExecutor.java | 4 +++- .../plugin/descriptor/PluginDescriptor.java | 17 ++++++----------- .../tools/plugin/util/PluginUtilsTest.java | 13 +++++-------- 3 files changed, 14 insertions(+), 20 deletions(-) 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 580b59b145..ec118365f3 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 @@ -351,7 +351,9 @@ public class DefaultLifecycleExecutor { String groupId = PluginDescriptor.getDefaultPluginGroupId(); - String artifactId = PluginDescriptor.getPluginArtifactIdFromGoal( task ); + String pluginId = PluginDescriptor.getPrefixFromGoal( task ); + + String artifactId = PluginDescriptor.getDefaultPluginArtifactId( pluginId ); injectHandlerPluginConfiguration( session.getProject(), groupId, artifactId ); diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java index b8cad537b0..efa1399609 100644 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java @@ -103,16 +103,15 @@ public class PluginDescriptor /** * @todo remove - harcoding. */ - public static String getPluginArtifactIdFromGoal( String goalName ) + public static String getPrefixFromGoal( String goalName ) { - String pluginId = goalName; + String prefix = goalName; - if ( pluginId.indexOf( ":" ) > 0 ) + if ( prefix.indexOf( ":" ) > 0 ) { - pluginId = pluginId.substring( 0, pluginId.indexOf( ":" ) ); + prefix = prefix.substring( 0, prefix.indexOf( ":" ) ); } - - return getDefaultPluginArtifactId( pluginId ); + return prefix; } /** @@ -138,11 +137,7 @@ public class PluginDescriptor */ public static String getGoalPrefixFromArtifactId( String artifactId ) { - int firstHyphen = artifactId.indexOf( "-" ); - - int lastHyphen = artifactId.lastIndexOf( "-" ); - - return artifactId.substring( firstHyphen + 1, lastHyphen ); + return artifactId.replaceAll( "-?maven-?", "" ).replaceAll( "-?plugin-?", "" ); } /** diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java index 21812e967d..187408ce51 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java @@ -19,14 +19,11 @@ public class PluginUtilsTest public void testShouldTrimArtifactIdToFindPluginId() { - Model model = new Model(); - model.setArtifactId( "maven-artifactId-plugin" ); - - MavenProject project = new MavenProject( model ); - - String pluginId = PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() ); - - assertEquals( "artifactId", pluginId ); + assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "maven-artifactId-plugin" ) ); + assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "maven-plugin-artifactId" ) ); + assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "artifactId-maven-plugin" ) ); + assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "artifactId" ) ); + assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "artifactId-plugin" ) ); } public void testShouldWriteDependencies()