From 76c4ceda28a98ca54da4e08088f54f6fb71430ef Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Fri, 6 May 2005 17:41:03 +0000 Subject: [PATCH] o Added duplicate check for mojo descriptor Parameters o changed the exception(s) throws during mojo descriptor extraction to be derivatives of InvalidPluginDescriptorException o changed PluginConfigurationException in plugin.descriptor to InvalidPluginDescriptorException o changed all "true".equals(something) to Boolean.valueOf(something).booleanValue() o added validation of 'modelVersion' back to [Default]ModelValidator o Fixed/added tests for new 'modelVersion' validation o changed all requiresXXX in MojoDescriptor to XXXRequired, and getRequiresXXX():boolean to isXXXRequired():boolean to help maintain bean-ness for future use git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@168630 13f79535-47bb-0310-9956-ffa450edef68 --- .../lifecycle/DefaultLifecycleExecutor.java | 2 +- .../maven/plugin/DefaultPluginManager.java | 4 +- .../DuplicateMojoDescriptorException.java | 2 +- .../DuplicateParameterException.java | 28 +++++++++ .../InvalidParameterException.java | 6 +- ... => InvalidPluginDescriptorException.java} | 6 +- .../plugin/descriptor/MojoDescriptor.java | 60 +++++++++++++------ .../descriptor/PluginDescriptorBuilder.java | 10 ++-- ...stractScriptedMojoDescriptorExtractor.java | 10 ++-- .../ExtractionException.java} | 20 +++---- .../extractor/MojoDescriptorExtractor.java | 4 +- .../generator/PluginDescriptorGenerator.java | 8 +-- .../plugin/scanner/DefaultMojoScanner.java | 16 ++--- .../tools/plugin/scanner/MojoScanner.java | 5 +- .../generator/AbstractGeneratorTestCase.java | 2 +- .../PluginDescriptorGeneratorTest.java | 2 +- .../java/JavaMojoDescriptorExtractor.java | 29 ++++----- .../MarmaladeMojoDescriptorExtractor.java | 20 +++++-- .../maven/plugin/AbstractCompilerMojo.java | 2 +- .../plugin/plugin/AbstractGeneratorMojo.java | 11 +++- .../project/DefaultMavenProjectBuilder.java | 16 ++--- .../validation/DefaultModelValidator.java | 2 + .../validation/ModelValidationResult.java | 6 ++ .../validation/DefaultModelValidatorTest.java | 23 +++++-- .../project-with-scoped-dependencies.xml | 1 + 25 files changed, 182 insertions(+), 113 deletions(-) create mode 100644 maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/DuplicateParameterException.java rename {maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor => maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor}/InvalidParameterException.java (88%) rename maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/{PluginConfigurationException.java => InvalidPluginDescriptorException.java} (82%) rename maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/{PluginToolsException.java => extractor/ExtractionException.java} (63%) 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 46128ee0e8..ae833ba7fa 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 @@ -268,7 +268,7 @@ public class DefaultLifecycleExecutor private void configureMojoPhaseBinding( MojoDescriptor mojoDescriptor, Map phaseMap, Settings settings ) throws LifecycleExecutionException { - if ( settings.getActiveProfile().isOffline() && mojoDescriptor.requiresOnline() ) + if ( settings.getActiveProfile().isOffline() && mojoDescriptor.isOnlineRequired() ) { String goal = mojoDescriptor.getGoal(); getLogger().warn( goal + " requires online mode, but maven is currently offline. Disabling " + goal + "." ); 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 5a6c569fd7..5358060dbd 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 @@ -307,7 +307,7 @@ public class DefaultPluginManager public void executeMojo( MavenSession session, MojoDescriptor mojoDescriptor ) throws ArtifactResolutionException, PluginManagerException, MojoExecutionException { - if ( mojoDescriptor.getRequiresDependencyResolution() != null ) + if ( mojoDescriptor.isDependencyResolutionRequired() != null ) { ArtifactResolver artifactResolver = null; @@ -319,7 +319,7 @@ public class DefaultPluginManager mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE ); resolveTransitiveDependencies( session, artifactResolver, mavenProjectBuilder, - mojoDescriptor.getRequiresDependencyResolution() ); + mojoDescriptor.isDependencyResolutionRequired() ); downloadDependencies( session, artifactResolver ); } catch ( ComponentLookupException e ) diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/DuplicateMojoDescriptorException.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/DuplicateMojoDescriptorException.java index fe58579fe9..e936e0c1ab 100644 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/DuplicateMojoDescriptorException.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/DuplicateMojoDescriptorException.java @@ -17,7 +17,7 @@ package org.apache.maven.plugin.descriptor; */ public class DuplicateMojoDescriptorException - extends PluginConfigurationException + extends InvalidPluginDescriptorException { public DuplicateMojoDescriptorException( String goalPrefix, String goal, String existingImplementation, String newImplementation ) diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/DuplicateParameterException.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/DuplicateParameterException.java new file mode 100644 index 0000000000..10bc1ffd28 --- /dev/null +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/DuplicateParameterException.java @@ -0,0 +1,28 @@ +package org.apache.maven.plugin.descriptor; + +/* + * 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 + * + * 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. + */ + +public class DuplicateParameterException + extends InvalidPluginDescriptorException +{ + + public DuplicateParameterException( String message ) + { + super( message ); + } + +} diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/InvalidParameterException.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/InvalidParameterException.java similarity index 88% rename from maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/InvalidParameterException.java rename to maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/InvalidParameterException.java index fedd01ef12..619230dab4 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/InvalidParameterException.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/InvalidParameterException.java @@ -1,6 +1,4 @@ -package org.apache.maven.tools.plugin.extractor; - -import org.apache.maven.tools.plugin.PluginToolsException; +package org.apache.maven.plugin.descriptor; /* * Copyright 2001-2004 The Apache Software Foundation. @@ -24,7 +22,7 @@ import org.apache.maven.tools.plugin.PluginToolsException; * jdcasey Exp $ */ public class InvalidParameterException - extends PluginToolsException + extends InvalidPluginDescriptorException { public InvalidParameterException( String element, int i ) { diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginConfigurationException.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/InvalidPluginDescriptorException.java similarity index 82% rename from maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginConfigurationException.java rename to maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/InvalidPluginDescriptorException.java index 27f6f5ac19..ef763b4cb5 100644 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginConfigurationException.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/InvalidPluginDescriptorException.java @@ -18,16 +18,16 @@ import org.codehaus.plexus.configuration.PlexusConfigurationException; * limitations under the License. */ -public class PluginConfigurationException +public class InvalidPluginDescriptorException extends PlexusConfigurationException { - public PluginConfigurationException( String message, Throwable cause ) + public InvalidPluginDescriptorException( String message, Throwable cause ) { super( message, cause ); } - public PluginConfigurationException( String message ) + public InvalidPluginDescriptorException( String message ) { super( message ); } diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java index 515437cbb9..f05a5ebc4c 100755 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java @@ -23,6 +23,7 @@ import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -64,11 +65,11 @@ public class MojoDescriptor // // ---------------------------------------------------------------------- - private String requiresDependencyResolution = null; + private String dependencyResolutionRequired = null; - private boolean requiresProject = true; + private boolean projectRequired = true; - private boolean requiresOnline = false; + private boolean onlineRequired = false; private PlexusConfiguration mojoConfiguration; @@ -110,8 +111,33 @@ public class MojoDescriptor } public void setParameters( List parameters ) + throws DuplicateParameterException { - this.parameters = parameters; + for ( Iterator it = parameters.iterator(); it.hasNext(); ) + { + Parameter parameter = (Parameter) it.next(); + addParameter( parameter ); + } + } + + public void addParameter( Parameter parameter ) + throws DuplicateParameterException + { + if ( parameters != null && parameters.contains( parameter ) ) + { + throw new DuplicateParameterException( parameter.getName() + + " has been declared multiple times in mojo with goal: " + getGoal() + " (implementation: " + + getImplementation() + ")" ); + } + else + { + if ( parameters == null ) + { + parameters = new LinkedList(); + } + + parameters.add( parameter ); + } } public Map getParameterMap() @@ -135,50 +161,50 @@ public class MojoDescriptor // Dependency requirement // ---------------------------------------------------------------------- - public void setRequiresDependencyResolution( String requiresDependencyResolution ) + public void setDependencyResolutionRequired( String requiresDependencyResolution ) { - this.requiresDependencyResolution = requiresDependencyResolution; + this.dependencyResolutionRequired = requiresDependencyResolution; } - public String getRequiresDependencyResolution() + public String isDependencyResolutionRequired() { - return requiresDependencyResolution; + return dependencyResolutionRequired; } // ---------------------------------------------------------------------- // Project requirement // ---------------------------------------------------------------------- - public void setRequiresProject( boolean requiresProject ) + public void setProjectRequired( boolean requiresProject ) { - this.requiresProject = requiresProject; + this.projectRequired = requiresProject; } - public boolean getRequiresProject() + public boolean isProjectRequired() { - return requiresProject; + return projectRequired; } // ---------------------------------------------------------------------- // Online vs. Offline requirement // ---------------------------------------------------------------------- - public void setRequiresOnline( boolean requiresOnline ) + public void setOnlineRequired( boolean requiresOnline ) { - this.requiresOnline = requiresOnline; + this.onlineRequired = requiresOnline; } // blech! this isn't even intelligible as a method name. provided for // consistency... - public boolean isRequiresOnline() + public boolean isOnlineRequired() { - return requiresOnline; + return onlineRequired; } // more english-friendly method...keep the code clean! :) public boolean requiresOnline() { - return requiresOnline; + return onlineRequired; } public String getPhase() diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java index c0a1cd0a4b..5fa40b0c73 100755 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java @@ -129,21 +129,21 @@ public class PluginDescriptorBuilder if ( dependencyResolution != null ) { - mojo.setRequiresDependencyResolution( dependencyResolution ); + mojo.setDependencyResolutionRequired( dependencyResolution ); } String requiresProject = c.getChild( "requiresProject" ).getValue(); if ( requiresProject != null ) { - mojo.setRequiresProject( "true".equals( requiresProject ) ); + mojo.setProjectRequired( Boolean.valueOf( requiresProject ).booleanValue() ); } String requiresOnline = c.getChild( "requiresOnline" ).getValue(); if ( requiresOnline != null ) { - mojo.setRequiresOnline( "true".equals( requiresOnline ) ); + mojo.setOnlineRequired( Boolean.valueOf( requiresOnline ).booleanValue() ); } // ---------------------------------------------------------------------- @@ -168,7 +168,7 @@ public class PluginDescriptorBuilder String required = d.getChild( "required" ).getValue(); - parameter.setRequired( "true".equals( required ) ); + parameter.setRequired( Boolean.valueOf( required ).booleanValue() ); PlexusConfiguration editableConfig = d.getChild( "editable" ); @@ -177,7 +177,7 @@ public class PluginDescriptorBuilder { String editable = d.getChild( "editable" ).getValue(); - parameter.setEditable( editable == null || "true".equals( editable ) ); + parameter.setEditable( editable == null || Boolean.valueOf( editable ).booleanValue() ); } parameter.setValidator( d.getChild( "validator" ).getValue() ); diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/AbstractScriptedMojoDescriptorExtractor.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/AbstractScriptedMojoDescriptorExtractor.java index 386d8d1f1e..0322823337 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/AbstractScriptedMojoDescriptorExtractor.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/AbstractScriptedMojoDescriptorExtractor.java @@ -1,8 +1,8 @@ package org.apache.maven.tools.plugin.extractor; -import org.apache.maven.project.MavenProject; +import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.tools.plugin.PluginToolsException; +import org.apache.maven.project.MavenProject; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.DirectoryScanner; @@ -22,7 +22,7 @@ public abstract class AbstractScriptedMojoDescriptorExtractor implements MojoDescriptorExtractor { public List execute( MavenProject project, PluginDescriptor pluginDescriptor ) - throws PluginToolsException + throws ExtractionException, InvalidPluginDescriptorException { Map scriptFilesKeyedByBasedir = gatherScriptSourcesByBasedir( project.getScriptSourceRoots(), getScriptFileExtension() ); @@ -33,7 +33,7 @@ public abstract class AbstractScriptedMojoDescriptorExtractor } protected abstract List extractMojoDescriptors( Map scriptFilesKeyedByBasedir, PluginDescriptor pluginDescriptor ) - throws PluginToolsException; + throws ExtractionException, InvalidPluginDescriptorException; protected abstract String getScriptFileExtension(); @@ -47,7 +47,7 @@ public abstract class AbstractScriptedMojoDescriptorExtractor String resourceDir = (String) it.next(); File dir = new File( resourceDir ).getAbsoluteFile(); - + resourceDir = dir.getPath(); if ( dir.exists() ) diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsException.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/ExtractionException.java similarity index 63% rename from maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsException.java rename to maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/ExtractionException.java index c39fc55ced..5b1d0ee6f0 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsException.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/ExtractionException.java @@ -1,4 +1,4 @@ -package org.apache.maven.tools.plugin; +package org.apache.maven.tools.plugin.extractor; /* * Copyright 2001-2005 The Apache Software Foundation. @@ -16,22 +16,18 @@ package org.apache.maven.tools.plugin; * limitations under the License. */ -/** - * Error during the plugin tools. - * - * @author Brett Porter - * @version $Id$ - */ -public class PluginToolsException +public class ExtractionException extends Exception { - public PluginToolsException( String message, Throwable throwable ) + + public ExtractionException( String message, Throwable cause ) { - super( message, throwable ); + super( message, cause ); } - public PluginToolsException( String message ) + public ExtractionException( String message ) { - super( message ); + super( message ); } + } diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/MojoDescriptorExtractor.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/MojoDescriptorExtractor.java index 61074a27e5..c18e2ed7f0 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/MojoDescriptorExtractor.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/MojoDescriptorExtractor.java @@ -16,9 +16,9 @@ package org.apache.maven.tools.plugin.extractor; * limitations under the License. */ +import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; -import org.apache.maven.tools.plugin.PluginToolsException; import java.util.List; @@ -30,5 +30,5 @@ public interface MojoDescriptorExtractor String ROLE = MojoDescriptorExtractor.class.getName(); List execute( MavenProject project, PluginDescriptor pluginDescriptor ) - throws PluginToolsException; + throws ExtractionException, InvalidPluginDescriptorException; } \ No newline at end of file diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java index 70cdbd0fa2..5e2724c1c8 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java @@ -110,22 +110,22 @@ public class PluginDescriptorGenerator // // ---------------------------------------------------------------------- - if ( mojoDescriptor.getRequiresDependencyResolution() != null ) + if ( mojoDescriptor.isDependencyResolutionRequired() != null ) { - element( w, "requiresDependencyResolution", mojoDescriptor.getRequiresDependencyResolution() ); + element( w, "requiresDependencyResolution", mojoDescriptor.isDependencyResolutionRequired() ); } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- - element( w, "requiresProject", "" + mojoDescriptor.getRequiresProject() ); + element( w, "requiresProject", "" + mojoDescriptor.isProjectRequired() ); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- - element( w, "requiresOnline", "" + mojoDescriptor.requiresOnline() ); + element( w, "requiresOnline", "" + mojoDescriptor.isOnlineRequired() ); // ---------------------------------------------------------------------- // diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java index 364c534d09..8d112bf7d0 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java @@ -16,11 +16,11 @@ package org.apache.maven.tools.plugin.scanner; * limitations under the License. */ -import org.apache.maven.plugin.descriptor.DuplicateMojoDescriptorException; +import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; -import org.apache.maven.tools.plugin.PluginToolsException; +import org.apache.maven.tools.plugin.extractor.ExtractionException; import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.Logger; @@ -52,7 +52,7 @@ public class DefaultMojoScanner } public void populatePluginDescriptor( MavenProject project, PluginDescriptor pluginDescriptor ) - throws PluginToolsException + throws ExtractionException, InvalidPluginDescriptorException { Logger logger = getLogger(); @@ -79,15 +79,7 @@ public class DefaultMojoScanner descriptor.setPluginDescriptor( pluginDescriptor ); - try - { - pluginDescriptor.addMojo( descriptor ); - } - catch ( DuplicateMojoDescriptorException e ) - { - throw new PluginToolsException( "Duplicate goal specification detected.\nError was: " - + e.getLocalizedMessage(), e ); - } + pluginDescriptor.addMojo( descriptor ); } } } diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/MojoScanner.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/MojoScanner.java index f22ebe7b6d..a04ef0e4e4 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/MojoScanner.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/MojoScanner.java @@ -16,9 +16,10 @@ package org.apache.maven.tools.plugin.scanner; * limitations under the License. */ +import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; -import org.apache.maven.tools.plugin.PluginToolsException; +import org.apache.maven.tools.plugin.extractor.ExtractionException; /** * @author jdcasey @@ -28,6 +29,6 @@ public interface MojoScanner String ROLE = MojoScanner.class.getName(); void populatePluginDescriptor( MavenProject project, PluginDescriptor pluginDescriptor ) - throws PluginToolsException; + throws ExtractionException, InvalidPluginDescriptorException; } \ No newline at end of file diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java index 94a9d73136..9ee3dfd48d 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java @@ -53,7 +53,7 @@ public abstract class AbstractGeneratorTestCase MojoDescriptor mojoDescriptor = new MojoDescriptor(); mojoDescriptor.setGoal( "testGoal" ); mojoDescriptor.setImplementation( "org.apache.maven.tools.plugin.generator.TestMojo" ); - mojoDescriptor.setRequiresDependencyResolution( "compile" ); + mojoDescriptor.setDependencyResolutionRequired( "compile" ); List params = new ArrayList(); diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGeneratorTest.java b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGeneratorTest.java index 0c2939a42b..82d27b3bb2 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGeneratorTest.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGeneratorTest.java @@ -100,7 +100,7 @@ public class PluginDescriptorGeneratorTest // The following should be defaults assertEquals( "per-lookup", mojoDescriptor.getInstantiationStrategy() ); - assertNotNull( mojoDescriptor.getRequiresDependencyResolution() ); + assertNotNull( mojoDescriptor.isDependencyResolutionRequired() ); // check the parameter. checkParameter( (Parameter) mojoDescriptor.getParameters().get( 0 ) ); diff --git a/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java b/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java index e941ec0c32..17423af3fe 100644 --- a/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java +++ b/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java @@ -16,11 +16,12 @@ package org.apache.maven.tools.plugin.extractor.java; * limitations under the License. */ +import org.apache.maven.plugin.descriptor.InvalidParameterException; +import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; -import org.apache.maven.tools.plugin.extractor.InvalidParameterException; import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor; import org.codehaus.modello.StringUtils; import org.codehaus.plexus.logging.AbstractLogEnabled; @@ -33,14 +34,13 @@ import com.thoughtworks.qdox.model.JavaSource; import java.io.File; import java.util.ArrayList; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.TreeMap; import java.util.Map.Entry; + /** * @todo add example usage tag that can be shown in the doco * @todo need to add validation directives so that systems embedding maven2 can @@ -110,7 +110,7 @@ public class JavaMojoDescriptorExtractor // Mojo descriptor creation from @tags // ---------------------------------------------------------------------- - private MojoDescriptor createMojoDescriptor( JavaSource javaSource, PluginDescriptor pluginDescriptor ) + private MojoDescriptor createMojoDescriptor( JavaSource javaSource, PluginDescriptor pluginDescriptor ) throws InvalidPluginDescriptorException { MojoDescriptor mojoDescriptor = new MojoDescriptor(); mojoDescriptor.setPluginDescriptor( pluginDescriptor ); @@ -187,7 +187,7 @@ public class JavaMojoDescriptorExtractor { value = "runtime"; } - mojoDescriptor.setRequiresDependencyResolution( value ); + mojoDescriptor.setDependencyResolutionRequired( value ); } // ---------------------------------------------------------------------- @@ -198,7 +198,7 @@ public class JavaMojoDescriptorExtractor if ( requiresProject != null ) { - mojoDescriptor.setRequiresProject( true ); + mojoDescriptor.setProjectRequired( true ); } // ---------------------------------------------------------------------- @@ -209,7 +209,7 @@ public class JavaMojoDescriptorExtractor if ( requiresOnline != null ) { - mojoDescriptor.setRequiresOnline( true ); + mojoDescriptor.setOnlineRequired( true ); } extractParameters( mojoDescriptor, javaClass ); @@ -234,7 +234,7 @@ public class JavaMojoDescriptorExtractor return tag; } - private void extractParameters( MojoDescriptor mojoDescriptor, JavaClass javaClass ) + private void extractParameters( MojoDescriptor mojoDescriptor, JavaClass javaClass ) throws InvalidPluginDescriptorException { // --------------------------------------------------------------------------------- // We're resolving class-level, ancestor-class-field, local-class-field order here. @@ -244,8 +244,6 @@ public class JavaMojoDescriptorExtractor extractFieldParameterTags( javaClass, rawParams ); - Set parameters = new HashSet(); - for ( Iterator it = rawParams.entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Entry) it.next(); @@ -282,14 +280,7 @@ public class JavaMojoDescriptorExtractor pd.setExpression( parameter.getNamedParameter( PARAMETER_EXPRESSION ) ); - parameters.add( pd ); - } - - if ( !parameters.isEmpty() ) - { - List paramList = new ArrayList( parameters ); - - mojoDescriptor.setParameters( paramList ); + mojoDescriptor.addParameter( pd ); } } @@ -329,7 +320,7 @@ public class JavaMojoDescriptorExtractor } public List execute( MavenProject project, PluginDescriptor pluginDescriptor ) - throws InvalidParameterException + throws InvalidPluginDescriptorException { JavaDocBuilder builder = new JavaDocBuilder(); diff --git a/maven-plugin-tools/maven-plugin-tools-marmalade/src/main/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractor.java b/maven-plugin-tools/maven-plugin-tools-marmalade/src/main/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractor.java index f5c2e8ff93..3282588f8a 100644 --- a/maven-plugin-tools/maven-plugin-tools-marmalade/src/main/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractor.java +++ b/maven-plugin-tools/maven-plugin-tools-marmalade/src/main/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractor.java @@ -16,12 +16,13 @@ package org.apache.maven.tools.plugin.extractor.marmalade; * limitations under the License. */ +import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.script.marmalade.MarmaladeMojoExecutionDirectives; import org.apache.maven.script.marmalade.tags.MojoTag; -import org.apache.maven.tools.plugin.PluginToolsException; import org.apache.maven.tools.plugin.extractor.AbstractScriptedMojoDescriptorExtractor; +import org.apache.maven.tools.plugin.extractor.ExtractionException; import org.codehaus.marmalade.launch.MarmaladeLaunchException; import org.codehaus.marmalade.launch.MarmaladeLauncher; import org.codehaus.marmalade.model.MarmaladeScript; @@ -49,8 +50,8 @@ public class MarmaladeMojoDescriptorExtractor return ".mmld"; } - protected List extractMojoDescriptors( Map sourceFilesKeyedByBasedir, PluginDescriptor pluginDescriptor ) - throws PluginToolsException + protected List extractMojoDescriptors( Map sourceFilesKeyedByBasedir, PluginDescriptor pluginDescriptor ) + throws ExtractionException, InvalidPluginDescriptorException { ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); try @@ -112,11 +113,20 @@ public class MarmaladeMojoDescriptorExtractor } catch ( IOException e ) { - throw new PluginToolsException( "Error reading descriptor Marmalade mojo in: " + scriptFile, e ); + throw new ExtractionException( "Error extracting mojo descriptor from Marmalade script: " + scriptFile, e ); } catch ( MarmaladeLaunchException e ) { - throw new PluginToolsException( "Error extracting descriptor Marmalade mojo from: " + scriptFile, e ); + Throwable cause = e.getCause(); + + if ( cause instanceof InvalidPluginDescriptorException ) + { + throw (InvalidPluginDescriptorException) cause; + } + else + { + throw new ExtractionException( "Error extracting mojo descriptor from Marmalade script: " + scriptFile, e ); + } } } } diff --git a/maven-plugins/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java b/maven-plugins/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java index 246bd9e0b8..ec9da9da05 100644 --- a/maven-plugins/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java +++ b/maven-plugins/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java @@ -121,7 +121,7 @@ public abstract class AbstractCompilerMojo compilerConfiguration.addCompilerOption( "-target", target ); } - if ( debug != null && "true".equals( debug ) ) + if ( debug != null && Boolean.valueOf( debug ).booleanValue() ) { compilerConfiguration.setDebug( true ); } diff --git a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java index 07e3eb1d7c..192eac4c01 100644 --- a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java +++ b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java @@ -18,9 +18,10 @@ package org.apache.maven.plugin.plugin; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; -import org.apache.maven.tools.plugin.PluginToolsException; +import org.apache.maven.tools.plugin.extractor.ExtractionException; import org.apache.maven.tools.plugin.generator.Generator; import org.apache.maven.tools.plugin.scanner.MojoScanner; import org.apache.maven.tools.plugin.util.PluginUtils; @@ -91,9 +92,13 @@ public abstract class AbstractGeneratorMojo { throw new MojoExecutionException( "Error writing plugin descriptor", e ); } - catch ( PluginToolsException e ) + catch ( InvalidPluginDescriptorException e ) { - throw new MojoExecutionException( "Error creatin plugin descriptor", e ); + throw new MojoExecutionException( "Error extracting plugin descriptor: \'" + e.getLocalizedMessage() + "\'", e ); + } + catch ( ExtractionException e ) + { + throw new MojoExecutionException( "Error extracting plugin descriptor: \'" + e.getLocalizedMessage() + "\'", e ); } } } diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 332b136cb3..9345cd8662 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -150,7 +150,7 @@ public class DefaultMavenProjectBuilder // Always cache files in the source tree over those in the repository modelCache.put( createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() ), model ); - MavenProject project = build( model, localRepository ); + MavenProject project = build( projectDescriptor.getAbsolutePath(), model, localRepository ); // Only translate the base directory for files in the source tree pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor ); @@ -173,7 +173,7 @@ public class DefaultMavenProjectBuilder Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository ); - return build( model, localRepository ); + return build( "Artifact [" + artifact.getId() + "]", model, localRepository ); } private Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, @@ -201,7 +201,7 @@ public class DefaultMavenProjectBuilder return model; } - private MavenProject build( Model model, ArtifactRepository localRepository ) + private MavenProject build( String pomLocation, Model model, ArtifactRepository localRepository ) throws ProjectBuildingException { Model superModel = getSuperModel(); @@ -225,11 +225,11 @@ public class DefaultMavenProjectBuilder try { - project = processProjectLogic( project, aggregatedRemoteWagonRepositories ); + project = processProjectLogic( pomLocation, project, aggregatedRemoteWagonRepositories ); } catch ( ModelInterpolationException e ) { - throw new ProjectBuildingException( "Error building project: " + model.getId(), e ); + throw new ProjectBuildingException( "Error building project from \'" + pomLocation + "\': " + model.getId(), e ); } return project; } @@ -241,7 +241,7 @@ public class DefaultMavenProjectBuilder * the resolved source roots, etc for the parent - that occurs for the parent when it is constructed independently * and projects are not cached or reused */ - private MavenProject processProjectLogic( MavenProject project, List remoteRepositories ) + private MavenProject processProjectLogic( String pomLocation, MavenProject project, List remoteRepositories ) throws ProjectBuildingException, ModelInterpolationException { Model model = project.getModel(); @@ -277,7 +277,7 @@ public class DefaultMavenProjectBuilder if ( validationResult.getMessageCount() > 0 ) { - throw new ProjectBuildingException( "Exception while building project: " + validationResult.toString() ); + throw new ProjectBuildingException( "Exception while building project from \'" + pomLocation + "\': " + validationResult.toString() ); } return project; @@ -489,7 +489,7 @@ public class DefaultMavenProjectBuilder List remoteRepositories = buildArtifactRepositories( superModel.getRepositories() ); - project = processProjectLogic( project, remoteRepositories ); + project = processProjectLogic( "", project, remoteRepositories ); return project; } diff --git a/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java b/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java index b11935490f..3f2ff76c3b 100644 --- a/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java +++ b/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java @@ -34,6 +34,8 @@ public class DefaultModelValidator public ModelValidationResult validate( Model model ) { ModelValidationResult result = new ModelValidationResult(); + + validateStringNotEmpty( "modelVersion", result, model.getModelVersion() ); validateStringNotEmpty( "groupId", result, model.getGroupId() ); diff --git a/maven-project/src/main/java/org/apache/maven/project/validation/ModelValidationResult.java b/maven-project/src/main/java/org/apache/maven/project/validation/ModelValidationResult.java index 6dc1571090..fd5cbce172 100644 --- a/maven-project/src/main/java/org/apache/maven/project/validation/ModelValidationResult.java +++ b/maven-project/src/main/java/org/apache/maven/project/validation/ModelValidationResult.java @@ -17,6 +17,7 @@ package org.apache.maven.project.validation; */ import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -45,6 +46,11 @@ public class ModelValidationResult { return messages.get( i ).toString(); } + + public List getMessages() + { + return Collections.unmodifiableList( messages ); + } public void addMessage( String message ) { diff --git a/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java b/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java index 2e6e1760ad..08c51247ee 100644 --- a/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java @@ -22,6 +22,7 @@ import org.apache.maven.project.MavenProjectTestCase; import java.io.FileReader; import java.io.Reader; +import java.util.List; /** * @author Trygve Laugstøl @@ -33,6 +34,15 @@ public class DefaultModelValidatorTest private Model model; private ModelValidator validator; + + public void testMissingModelVersion() throws Exception + { + ModelValidationResult result = validate( "missing-modelVersion-pom.xml" ); + + assertEquals( 1, result.getMessageCount() ); + + assertEquals( "'modelVersion' is missing.", result.getMessage( 0 ) ); + } public void testMissingArtifactId() throws Exception @@ -79,18 +89,21 @@ public class DefaultModelValidatorTest { ModelValidationResult result = validate( "missing-1-pom.xml" ); - assertEquals( 3, result.getMessageCount() ); + assertEquals( 4, result.getMessageCount() ); - assertEquals( "'groupId' is missing.", result.getMessage( 0 ) ); - assertEquals( "'artifactId' is missing.", result.getMessage( 1 ) ); + List messages = result.getMessages(); + + assertTrue( messages.contains("\'modelVersion\' is missing.")); + assertTrue( messages.contains("\'groupId\' is missing.")); + assertTrue( messages.contains("\'artifactId\' is missing.")); + assertTrue( messages.contains("\'version\' is missing.")); // type is inherited from the super pom - assertEquals( "'version' is missing.", result.getMessage( 2 ) ); } private ModelValidationResult validate( String testName ) throws Exception { - Reader input = new FileReader( getTestFile( "src/test/resources/validation/" + testName ) ); + Reader input = new FileReader( getFileForClasspathResource( "/validation/" + testName ) ); MavenXpp3Reader reader = new MavenXpp3Reader(); diff --git a/maven-project/src/test/resources/projects/scope/project-with-scoped-dependencies.xml b/maven-project/src/test/resources/projects/scope/project-with-scoped-dependencies.xml index e0022acd1d..f18b7c7389 100644 --- a/maven-project/src/test/resources/projects/scope/project-with-scoped-dependencies.xml +++ b/maven-project/src/test/resources/projects/scope/project-with-scoped-dependencies.xml @@ -1,6 +1,7 @@ + 4.0.0 maven maven-project-test Maven