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
This commit is contained in:
John Dennis Casey 2005-05-06 17:41:03 +00:00
parent d4c059226c
commit 76c4ceda28
25 changed files with 182 additions and 113 deletions

View File

@ -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 + "." );

View File

@ -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 )

View File

@ -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 )

View File

@ -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 );
}
}

View File

@ -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 )
{

View File

@ -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 );
}

View File

@ -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()

View File

@ -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() );

View File

@ -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() )

View File

@ -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 <a href="mailto:brett@apache.org">Brett Porter</a>
* @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 );
}
}

View File

@ -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;
}

View File

@ -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() );
// ----------------------------------------------------------------------
//

View File

@ -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 );
}
}
}

View File

@ -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;
}

View File

@ -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();

View File

@ -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 ) );

View File

@ -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();

View File

@ -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 );
}
}
}
}

View File

@ -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 );
}

View File

@ -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 );
}
}
}

View File

@ -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( "<Super-POM>", project, remoteRepositories );
return project;
}

View File

@ -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() );

View File

@ -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 )
{

View File

@ -22,6 +22,7 @@ import org.apache.maven.project.MavenProjectTestCase;
import java.io.FileReader;
import java.io.Reader;
import java.util.List;
/**
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
@ -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();

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<model>
<modelVersion>4.0.0</modelVersion>
<groupId>maven</groupId>
<artifactId>maven-project-test</artifactId>
<name>Maven</name>