From 0fa8f7dc93ea6d4befcbf451a512750590dbbd50 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Thu, 20 Aug 2009 20:06:58 +0000 Subject: [PATCH] [MNG-4313] Plugin descriptor builder ignores deprecation message for mojo git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@806335 13f79535-47bb-0310-9956-ffa450edef68 --- .../plugin/DefaultBuildPluginManager.java | 2 +- .../descriptor/PluginDescriptorBuilder.java | 7 + .../PluginDescriptorBuilderTest.java | 121 ++++++++++++++++++ .../src/test/resources/plugin.xml | 63 +++++++++ 4 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 maven-plugin-api/src/test/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilderTest.java create mode 100644 maven-plugin-api/src/test/resources/plugin.xml diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java index f9cd3266fc..4772804afb 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java @@ -93,7 +93,7 @@ public class DefaultBuildPluginManager MavenSession oldSession = legacySupport.getSession(); try - { + { mojo = mavenPluginManager.getConfiguredMojo( Mojo.class, session, mojoExecution ); Thread.currentThread().setContextClassLoader( pluginRealm ); diff --git a/maven-plugin-api/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java b/maven-plugin-api/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java index 5423ec6830..b82262ef4c 100644 --- a/maven-plugin-api/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java +++ b/maven-plugin-api/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java @@ -156,6 +156,13 @@ public class PluginDescriptorBuilder mojo.setSince( since ); } + PlexusConfiguration deprecated = c.getChild( "deprecated", false ); + + if ( deprecated != null ) + { + mojo.setDeprecated( deprecated.getValue() ); + } + String phase = c.getChild( "phase" ).getValue(); if ( phase != null ) diff --git a/maven-plugin-api/src/test/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilderTest.java b/maven-plugin-api/src/test/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilderTest.java new file mode 100644 index 0000000000..d50b2ddace --- /dev/null +++ b/maven-plugin-api/src/test/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilderTest.java @@ -0,0 +1,121 @@ +package org.apache.maven.plugin.descriptor; + +/* + * 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.IOException; +import java.io.Reader; + +import org.codehaus.plexus.component.repository.ComponentDependency; +import org.codehaus.plexus.component.repository.ComponentRequirement; +import org.codehaus.plexus.configuration.PlexusConfiguration; +import org.codehaus.plexus.configuration.PlexusConfigurationException; +import org.codehaus.plexus.util.ReaderFactory; + +import junit.framework.TestCase; + +/** + * Tests {@link PluginDescriptorBuilder}. + * + * @author Benjamin Bentmann + */ +public class PluginDescriptorBuilderTest + extends TestCase +{ + + private PluginDescriptor build( String resource ) + throws IOException, PlexusConfigurationException + { + Reader reader = ReaderFactory.newXmlReader( getClass().getResourceAsStream( resource ) ); + + return new PluginDescriptorBuilder().build( reader ); + } + + public void testBuildReader() + throws Exception + { + PluginDescriptor pd = build( "/plugin.xml" ); + + assertEquals( "org.apache.maven.plugins", pd.getGroupId() ); + assertEquals( "maven-jar-plugin", pd.getArtifactId() ); + assertEquals( "2.3-SNAPSHOT", pd.getVersion() ); + assertEquals( "jar", pd.getGoalPrefix() ); + assertEquals( "plugin-description", pd.getDescription() ); + assertEquals( false, pd.isIsolatedRealm() ); + assertEquals( true, pd.isInheritedByDefault() ); + assertEquals( 1, pd.getMojos().size() ); + assertEquals( 1, pd.getDependencies().size() ); + + MojoDescriptor md = (MojoDescriptor) pd.getMojos().get( 0 ); + + assertEquals( "jar", md.getGoal() ); + assertEquals( "mojo-description", md.getDescription() ); + assertEquals( "runtime", md.isDependencyResolutionRequired() ); + assertEquals( false, md.isAggregator() ); + assertEquals( false, md.isDirectInvocationOnly() ); + assertEquals( true, md.isInheritedByDefault() ); + assertEquals( false, md.isOnlineRequired() ); + assertEquals( true, md.isProjectRequired() ); + assertEquals( "package", md.getPhase() ); + assertEquals( "org.apache.maven.plugin.jar.JarMojo", md.getImplementation() ); + assertEquals( "antrun", md.getComponentConfigurator() ); + assertEquals( "java", md.getLanguage() ); + assertEquals( "per-lookup", md.getInstantiationStrategy() ); + assertEquals( "some-goal", md.getExecuteGoal() ); + assertEquals( "generate-sources", md.getExecutePhase() ); + assertEquals( "cobertura", md.getExecuteLifecycle() ); + assertEquals( "2.2", md.getSince() ); + assertEquals( "deprecated-mojo", md.getDeprecated() ); + assertEquals( 1, md.getRequirements().size() ); + assertEquals( 1, md.getParameters().size() ); + + assertNotNull( md.getMojoConfiguration() ); + assertEquals( 1, md.getMojoConfiguration().getChildCount() ); + + PlexusConfiguration pc = md.getMojoConfiguration().getChild( 0 ); + + assertEquals( "${jar.finalName}", pc.getValue() ); + assertEquals( "${project.build.finalName}", pc.getAttribute( "default-value" ) ); + assertEquals( "java.lang.String", pc.getAttribute( "implementation" ) ); + + Parameter mp = md.getParameters().get( 0 ); + + assertEquals( "finalName", mp.getName() ); + assertEquals( "jarName", mp.getAlias() ); + assertEquals( "java.lang.String", mp.getType() ); + assertEquals( true, mp.isEditable() ); + assertEquals( false, mp.isRequired() ); + assertEquals( "parameter-description", mp.getDescription() ); + assertEquals( "deprecated-parameter", mp.getDeprecated() ); + + ComponentRequirement cr = (ComponentRequirement) md.getRequirements().get( 0 ); + + assertEquals( "org.codehaus.plexus.archiver.Archiver", cr.getRole() ); + assertEquals( "jar", cr.getRoleHint() ); + assertEquals( "jarArchiver", cr.getFieldName() ); + + ComponentDependency cd = pd.getDependencies().get( 0 ); + + assertEquals( "org.apache.maven", cd.getGroupId() ); + assertEquals( "maven-plugin-api", cd.getArtifactId() ); + assertEquals( "2.0.6", cd.getVersion() ); + assertEquals( "jar", cd.getType() ); + } + +} diff --git a/maven-plugin-api/src/test/resources/plugin.xml b/maven-plugin-api/src/test/resources/plugin.xml new file mode 100644 index 0000000000..3c91fe729a --- /dev/null +++ b/maven-plugin-api/src/test/resources/plugin.xml @@ -0,0 +1,63 @@ + + + plugin-description + org.apache.maven.plugins + maven-jar-plugin + 2.3-SNAPSHOT + jar + false + true + + + jar + mojo-description + runtime + false + true + false + false + false + true + package + org.apache.maven.plugin.jar.JarMojo + java + per-lookup + once-per-session + deprecated-mojo + 2.2 + generate-sources + some-goal + cobertura + antrun + + + finalName + jarName + java.lang.String + false + true + parameter-description + deprecated-parameter + + + + ${jar.finalName} + + + + org.codehaus.plexus.archiver.Archiver + jar + jarArchiver + + + + + + + org.apache.maven + maven-plugin-api + jar + 2.0.6 + + +