mirror of https://github.com/apache/maven.git
[MNG-4454] Incomplete <parent> element causes NPE
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@881784 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8b21cd1567
commit
1068ab557c
|
@ -21,7 +21,9 @@ package org.apache.maven.profiles;
|
|||
|
||||
import org.apache.maven.model.Activation;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.model.building.ModelProblem;
|
||||
import org.apache.maven.model.building.ModelProblemCollector;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.apache.maven.model.profile.DefaultProfileActivationContext;
|
||||
import org.apache.maven.model.profile.ProfileActivationContext;
|
||||
import org.apache.maven.model.profile.ProfileSelector;
|
||||
|
@ -192,25 +194,14 @@ public class DefaultProfileManager
|
|||
profileSelector.getActiveProfiles( profilesById.values(), context, new ModelProblemCollector()
|
||||
{
|
||||
|
||||
public void addWarning( String message, Exception cause )
|
||||
public void add( Severity severity, String message, Exception cause )
|
||||
{
|
||||
// ignored
|
||||
if ( !ModelProblem.Severity.WARNING.equals( severity ) )
|
||||
{
|
||||
errors.add( new ProfileActivationException( message, cause ) );
|
||||
}
|
||||
}
|
||||
|
||||
public void addWarning( String message )
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
public void addError( String message, Exception cause )
|
||||
{
|
||||
errors.add( new ProfileActivationException( message, cause ) );
|
||||
}
|
||||
|
||||
public void addError( String message )
|
||||
{
|
||||
errors.add( new ProfileActivationException( message ) );
|
||||
}
|
||||
} );
|
||||
|
||||
if ( !errors.isEmpty() )
|
||||
|
|
|
@ -22,7 +22,9 @@ package org.apache.maven.project.validation;
|
|||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.building.DefaultModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelProblem;
|
||||
import org.apache.maven.model.building.ModelProblemCollector;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
|
||||
|
@ -64,24 +66,12 @@ public class DefaultModelValidator
|
|||
this.result = result;
|
||||
}
|
||||
|
||||
public void addError( String message )
|
||||
public void add( Severity severity, String message, Exception cause )
|
||||
{
|
||||
result.addMessage( message );
|
||||
}
|
||||
|
||||
public void addError( String message, Exception cause )
|
||||
{
|
||||
result.addMessage( message );
|
||||
}
|
||||
|
||||
public void addWarning( String message )
|
||||
{
|
||||
// not supported
|
||||
}
|
||||
|
||||
public void addWarning( String message, Exception cause )
|
||||
{
|
||||
// not supported
|
||||
if ( !ModelProblem.Severity.WARNING.equals( severity ) )
|
||||
{
|
||||
result.addMessage( message );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.apache.maven.model.PluginExecution;
|
|||
import org.apache.maven.model.PluginManagement;
|
||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelProblemCollector;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.apache.maven.model.merge.MavenModelMerger;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
|
@ -63,7 +64,7 @@ public class DefaultLifecycleBindingsInjector
|
|||
|
||||
if ( defaultPlugins == null )
|
||||
{
|
||||
problems.addError( "Unknown packaging: " + packaging );
|
||||
problems.add( Severity.ERROR, "Unknown packaging: " + packaging, null );
|
||||
}
|
||||
else if ( !defaultPlugins.isEmpty() )
|
||||
{
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.maven.artifact.repository.RepositoryRequest;
|
|||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.building.AbstractModelBuildingListener;
|
||||
import org.apache.maven.model.building.ModelBuildingEvent;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.apache.maven.plugin.PluginResolutionException;
|
||||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
||||
|
||||
|
@ -96,7 +97,7 @@ class DefaultModelBuildingListener
|
|||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
event.getProblems().addError( "Invalid plugin repository: " + e.getMessage(), e );
|
||||
event.getProblems().add( Severity.ERROR, "Invalid plugin repository: " + e.getMessage(), e );
|
||||
}
|
||||
project.setPluginArtifactRepositories( pluginRepositories );
|
||||
|
||||
|
@ -118,11 +119,11 @@ class DefaultModelBuildingListener
|
|||
}
|
||||
catch ( PluginResolutionException e )
|
||||
{
|
||||
event.getProblems().addError( "Unresolveable build extension: " + e.getMessage(), e );
|
||||
event.getProblems().add( Severity.ERROR, "Unresolveable build extension: " + e.getMessage(), e );
|
||||
}
|
||||
catch ( PluginVersionResolutionException e )
|
||||
{
|
||||
event.getProblems().addError( "Unresolveable build extension: " + e.getMessage(), e );
|
||||
event.getProblems().add( Severity.ERROR, "Unresolveable build extension: " + e.getMessage(), e );
|
||||
}
|
||||
|
||||
if ( project.getClassRealm() != null )
|
||||
|
@ -152,7 +153,7 @@ class DefaultModelBuildingListener
|
|||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
event.getProblems().addError( "Invalid artifact repository: " + e.getMessage(), e );
|
||||
event.getProblems().add( Severity.ERROR, "Invalid artifact repository: " + e.getMessage(), e );
|
||||
}
|
||||
project.setRemoteArtifactRepositories( remoteRepositories );
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.apache.maven.model.Model;
|
|||
import org.apache.maven.model.Parent;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.model.Repository;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.apache.maven.model.composition.DependencyManagementImporter;
|
||||
import org.apache.maven.model.inheritance.InheritanceAssembler;
|
||||
import org.apache.maven.model.interpolation.ModelInterpolator;
|
||||
|
@ -267,7 +268,7 @@ public class DefaultModelBuilder
|
|||
|
||||
modelValidator.validateEffectiveModel( resultModel, request, problems );
|
||||
|
||||
if ( hasErrors( problems.getProblems() ) )
|
||||
if ( problems.hasErrors() )
|
||||
{
|
||||
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
|
||||
}
|
||||
|
@ -320,22 +321,24 @@ public class DefaultModelBuilder
|
|||
|
||||
if ( pomFile != null )
|
||||
{
|
||||
problems.addError( "Malformed POM " + modelSource.getLocation() + ": " + e.getMessage(), e );
|
||||
problems.add( Severity.ERROR, "Malformed POM " + modelSource.getLocation() + ": " + e.getMessage(),
|
||||
e );
|
||||
}
|
||||
else
|
||||
{
|
||||
problems.addWarning( "Malformed POM " + modelSource.getLocation() + ": " + e.getMessage(), e );
|
||||
problems.add( Severity.WARNING, "Malformed POM " + modelSource.getLocation() + ": "
|
||||
+ e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( ModelParseException e )
|
||||
{
|
||||
problems.addFatalError( "Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage(), e );
|
||||
problems.add( Severity.FATAL, "Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage(), e );
|
||||
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
problems.addFatalError( "Non-readable POM " + modelSource.getLocation() + ": " + e.getMessage(), e );
|
||||
problems.add( Severity.FATAL, "Non-readable POM " + modelSource.getLocation() + ": " + e.getMessage(), e );
|
||||
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
|
||||
}
|
||||
|
||||
|
@ -344,23 +347,12 @@ public class DefaultModelBuilder
|
|||
problems.setSource( model );
|
||||
modelValidator.validateRawModel( model, request, problems );
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
private boolean hasErrors( List<ModelProblem> problems )
|
||||
{
|
||||
if ( problems != null )
|
||||
if ( problems.hasFatalErrors() )
|
||||
{
|
||||
for ( ModelProblem problem : problems )
|
||||
{
|
||||
if ( ModelProblem.Severity.ERROR.compareTo( problem.getSeverity() ) >= 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
|
||||
}
|
||||
|
||||
return false;
|
||||
return model;
|
||||
}
|
||||
|
||||
private ProfileActivationContext getProfileActivationContext( ModelBuildingRequest request )
|
||||
|
@ -395,7 +387,7 @@ public class DefaultModelBuilder
|
|||
}
|
||||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
problems.addError( "Invalid repository " + repository.getId() + ": " + e.getMessage(), e );
|
||||
problems.add( Severity.ERROR, "Invalid repository " + repository.getId() + ": " + e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -469,8 +461,9 @@ public class DefaultModelBuilder
|
|||
|
||||
if ( !"pom".equals( parentModel.getPackaging() ) )
|
||||
{
|
||||
problems.addError( "Invalid packaging for parent POM " + ModelProblemUtils.toSourceHint( parentModel )
|
||||
+ ", must be \"pom\" but is \"" + parentModel.getPackaging() + "\"" );
|
||||
problems.add( Severity.ERROR, "Invalid packaging for parent POM "
|
||||
+ ModelProblemUtils.toSourceHint( parentModel ) + ", must be \"pom\" but is \""
|
||||
+ parentModel.getPackaging() + "\"", null );
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -575,7 +568,7 @@ public class DefaultModelBuilder
|
|||
}
|
||||
catch ( UnresolvableModelException e )
|
||||
{
|
||||
problems.addFatalError( "Non-resolvable parent POM "
|
||||
problems.add( Severity.FATAL, "Non-resolvable parent POM "
|
||||
+ ModelProblemUtils.toId( groupId, artifactId, version ) + " for "
|
||||
+ ModelProblemUtils.toId( childModel ) + ": " + e.getMessage(), e );
|
||||
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
|
||||
|
@ -639,7 +632,7 @@ public class DefaultModelBuilder
|
|||
message += modelId + " -> ";
|
||||
}
|
||||
message += imported;
|
||||
problems.addError( message );
|
||||
problems.add( Severity.ERROR, message, null );
|
||||
|
||||
continue;
|
||||
}
|
||||
|
@ -663,7 +656,7 @@ public class DefaultModelBuilder
|
|||
}
|
||||
catch ( UnresolvableModelException e )
|
||||
{
|
||||
problems.addError( "Non-resolvable import POM "
|
||||
problems.add( Severity.ERROR, "Non-resolvable import POM "
|
||||
+ ModelProblemUtils.toId( groupId, artifactId, version ) + ": " + e.getMessage(), e );
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -20,9 +20,12 @@ package org.apache.maven.model.building;
|
|||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.apache.maven.model.io.ModelParseException;
|
||||
|
||||
/**
|
||||
|
@ -46,9 +49,26 @@ class DefaultModelProblemCollector
|
|||
|
||||
private Model rootModel;
|
||||
|
||||
private Set<ModelProblem.Severity> severities = EnumSet.noneOf( ModelProblem.Severity.class );
|
||||
|
||||
public DefaultModelProblemCollector( List<ModelProblem> problems )
|
||||
{
|
||||
this.problems = ( problems != null ) ? problems : new ArrayList<ModelProblem>();
|
||||
|
||||
for ( ModelProblem problem : this.problems )
|
||||
{
|
||||
severities.add( problem.getSeverity() );
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasFatalErrors()
|
||||
{
|
||||
return severities.contains( ModelProblem.Severity.FATAL );
|
||||
}
|
||||
|
||||
public boolean hasErrors()
|
||||
{
|
||||
return severities.contains( ModelProblem.Severity.ERROR ) || severities.contains( ModelProblem.Severity.FATAL );
|
||||
}
|
||||
|
||||
public List<ModelProblem> getProblems()
|
||||
|
@ -100,14 +120,21 @@ class DefaultModelProblemCollector
|
|||
public void add( ModelProblem problem )
|
||||
{
|
||||
problems.add( problem );
|
||||
|
||||
severities.add( problem.getSeverity() );
|
||||
}
|
||||
|
||||
public void addAll( List<ModelProblem> problems )
|
||||
{
|
||||
problems.addAll( problems );
|
||||
this.problems.addAll( problems );
|
||||
|
||||
for ( ModelProblem problem : problems )
|
||||
{
|
||||
severities.add( problem.getSeverity() );
|
||||
}
|
||||
}
|
||||
|
||||
public void addFatalError( String message, Exception cause )
|
||||
public void add( Severity severity, String message, Exception cause )
|
||||
{
|
||||
int line = -1;
|
||||
int column = -1;
|
||||
|
@ -119,52 +146,15 @@ class DefaultModelProblemCollector
|
|||
column = e.getColumnNumber();
|
||||
}
|
||||
|
||||
add( message, ModelProblem.Severity.FATAL, line, column, cause );
|
||||
add( severity, message, line, column, cause );
|
||||
}
|
||||
|
||||
public void addError( String message )
|
||||
private void add( ModelProblem.Severity severity, String message, int line, int column, Exception cause )
|
||||
{
|
||||
addError( message, null );
|
||||
}
|
||||
ModelProblem problem =
|
||||
new DefaultModelProblem( message, severity, getSource(), line, column, getModelId(), cause );
|
||||
|
||||
public void addError( String message, Exception cause )
|
||||
{
|
||||
int line = -1;
|
||||
int column = -1;
|
||||
|
||||
if ( cause instanceof ModelParseException )
|
||||
{
|
||||
ModelParseException e = (ModelParseException) cause;
|
||||
line = e.getLineNumber();
|
||||
column = e.getColumnNumber();
|
||||
}
|
||||
|
||||
add( message, ModelProblem.Severity.ERROR, line, column, cause );
|
||||
}
|
||||
|
||||
public void addWarning( String message )
|
||||
{
|
||||
addWarning( message, null );
|
||||
}
|
||||
|
||||
public void addWarning( String message, Exception cause )
|
||||
{
|
||||
int line = -1;
|
||||
int column = -1;
|
||||
|
||||
if ( cause instanceof ModelParseException )
|
||||
{
|
||||
ModelParseException e = (ModelParseException) cause;
|
||||
line = e.getLineNumber();
|
||||
column = e.getColumnNumber();
|
||||
}
|
||||
|
||||
add( message, ModelProblem.Severity.WARNING, line, column, cause );
|
||||
}
|
||||
|
||||
private void add( String message, ModelProblem.Severity severity, int line, int column, Exception cause )
|
||||
{
|
||||
problems.add( new DefaultModelProblem( message, severity, getSource(), line, column, getModelId(), cause ) );
|
||||
add( problem );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,33 +32,12 @@ public interface ModelProblemCollector
|
|||
{
|
||||
|
||||
/**
|
||||
* Adds the specified error.
|
||||
* Adds the specified problem.
|
||||
*
|
||||
* @param message The detail message of the error, may be {@code null}.
|
||||
* @param severity The severity of the problem, must not be {@code null}.
|
||||
* @param message The detail message of the problem, may be {@code null}.
|
||||
* @param cause The cause of the problem, may be {@code null}.
|
||||
*/
|
||||
void addError( String message );
|
||||
|
||||
/**
|
||||
* Adds the specified error.
|
||||
*
|
||||
* @param message The detail message of the error, may be {@code null}.
|
||||
* @param cause The cause of the error, may be {@code null}.
|
||||
*/
|
||||
void addError( String message, Exception cause );
|
||||
|
||||
/**
|
||||
* Adds the specified warning.
|
||||
*
|
||||
* @param message The detail message of the warning, may be {@code null}.
|
||||
*/
|
||||
void addWarning( String message );
|
||||
|
||||
/**
|
||||
* Adds the specified warning.
|
||||
*
|
||||
* @param message The detail message of the warning, may be {@code null}.
|
||||
* @param cause The cause of the warning, may be {@code null}.
|
||||
*/
|
||||
void addWarning( String message, Exception cause );
|
||||
void add( ModelProblem.Severity severity, String message, Exception cause );
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.apache.maven.model.interpolation;
|
|||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelProblemCollector;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.apache.maven.model.path.PathTranslator;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
import org.codehaus.plexus.interpolation.AbstractValueSource;
|
||||
|
@ -229,7 +230,7 @@ public abstract class AbstractStringBasedModelInterpolator
|
|||
}
|
||||
catch ( InterpolationException e )
|
||||
{
|
||||
problems.addError( e.getMessage(), e );
|
||||
problems.add( Severity.ERROR, e.getMessage(), e );
|
||||
}
|
||||
|
||||
interpolator.clearFeedback();
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.apache.maven.model.interpolation;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.maven.model.building.ModelProblemCollector;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.codehaus.plexus.interpolation.ValueSource;
|
||||
|
||||
/**
|
||||
|
@ -61,7 +62,7 @@ class ProblemDetectingValueSource
|
|||
{
|
||||
msg += " Please use ${" + newPrefix + expression.substring( bannedPrefix.length() ) + "} instead.";
|
||||
}
|
||||
problems.addWarning( msg );
|
||||
problems.add( Severity.WARNING, msg, null );
|
||||
}
|
||||
|
||||
return value;
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.apache.maven.model.interpolation;
|
|||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelProblemCollector;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.interpolation.InterpolationPostProcessor;
|
||||
import org.codehaus.plexus.interpolation.Interpolator;
|
||||
|
@ -285,13 +286,13 @@ public class StringSearchModelInterpolator
|
|||
}
|
||||
catch ( IllegalArgumentException e )
|
||||
{
|
||||
problems.addError( "Failed to interpolate field: " + fields[i] + " on class: "
|
||||
+ cls.getName(), e );
|
||||
problems.add( Severity.ERROR, "Failed to interpolate field: " + fields[i]
|
||||
+ " on class: " + cls.getName(), e );
|
||||
}
|
||||
catch ( IllegalAccessException e )
|
||||
{
|
||||
problems.addError( "Failed to interpolate field: " + fields[i] + " on class: "
|
||||
+ cls.getName(), e );
|
||||
problems.add( Severity.ERROR, "Failed to interpolate field: " + fields[i]
|
||||
+ " on class: " + cls.getName(), e );
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.apache.maven.model.ReportSet;
|
|||
import org.apache.maven.model.Reporting;
|
||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelProblemCollector;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
|
@ -98,8 +99,8 @@ public class DefaultReportingConverter
|
|||
&& request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 )
|
||||
{
|
||||
|
||||
problems.addWarning( "The <reporting> section is deprecated"
|
||||
+ ", please move the reports to the <configuration> section of the new Maven Site Plugin." );
|
||||
problems.add( Severity.WARNING, "The <reporting> section is deprecated"
|
||||
+ ", please move the reports to the <configuration> section of the new Maven Site Plugin.", null );
|
||||
}
|
||||
|
||||
for ( ReportPlugin plugin : reporting.getPlugins() )
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.List;
|
|||
import org.apache.maven.model.Activation;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.model.building.ModelProblemCollector;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.apache.maven.model.profile.activation.ProfileActivator;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
|
@ -103,7 +104,7 @@ public class DefaultProfileSelector
|
|||
}
|
||||
catch ( RuntimeException e )
|
||||
{
|
||||
problems.addError( "Failed to determine activation for profile " + profile.getId(), e );
|
||||
problems.add( Severity.ERROR, "Failed to determine activation for profile " + profile.getId(), e );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.maven.model.Activation;
|
|||
import org.apache.maven.model.ActivationFile;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.model.building.ModelProblemCollector;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.apache.maven.model.path.PathTranslator;
|
||||
import org.apache.maven.model.profile.ProfileActivationContext;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
@ -118,8 +119,8 @@ public class FileProfileActivator
|
|||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
problems.addError( "Failed to interpolate file location " + path + " for profile " + profile.getId() + ": "
|
||||
+ e.getMessage(), e );
|
||||
problems.add( Severity.ERROR, "Failed to interpolate file location " + path + " for profile "
|
||||
+ profile.getId() + ": " + e.getMessage(), e );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.List;
|
|||
import org.apache.maven.model.Activation;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.model.building.ModelProblemCollector;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.apache.maven.model.profile.ProfileActivationContext;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
|
@ -55,7 +56,8 @@ public class JdkVersionProfileActivator
|
|||
|
||||
if ( version.length() <= 0 )
|
||||
{
|
||||
problems.addError( "Failed to determine Java version for profile " + profile.getId() );
|
||||
problems.add( Severity.ERROR, "Failed to determine Java version for profile " + profile.getId(),
|
||||
null );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.maven.model.Activation;
|
|||
import org.apache.maven.model.ActivationProperty;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.model.building.ModelProblemCollector;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.apache.maven.model.profile.ProfileActivationContext;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
@ -60,7 +61,8 @@ public class PropertyProfileActivator
|
|||
|
||||
if ( name == null || name.length() <= 0 )
|
||||
{
|
||||
problems.addError( "The property name is required to activate the profile " + profile.getId() );
|
||||
problems.add( Severity.ERROR, "The property name is required to activate the profile "
|
||||
+ profile.getId(), null );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.apache.maven.model.Reporting;
|
|||
import org.apache.maven.model.Repository;
|
||||
import org.apache.maven.model.Resource;
|
||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.apache.maven.model.building.ModelProblemCollector;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
@ -60,25 +61,25 @@ public class DefaultModelValidator
|
|||
Parent parent = model.getParent();
|
||||
if ( parent != null )
|
||||
{
|
||||
validateStringNotEmpty( "parent.groupId", problems, false, parent.getGroupId() );
|
||||
validateStringNotEmpty( "parent.groupId", problems, Severity.FATAL, parent.getGroupId() );
|
||||
|
||||
validateStringNotEmpty( "parent.artifactId", problems, false, parent.getArtifactId() );
|
||||
validateStringNotEmpty( "parent.artifactId", problems, Severity.FATAL, parent.getArtifactId() );
|
||||
|
||||
validateStringNotEmpty( "parent.version", problems, false, parent.getVersion() );
|
||||
validateStringNotEmpty( "parent.version", problems, Severity.FATAL, parent.getVersion() );
|
||||
|
||||
if ( parent.getGroupId().equals( model.getGroupId() )
|
||||
&& parent.getArtifactId().equals( model.getArtifactId() ) )
|
||||
if ( equals( parent.getGroupId(), model.getGroupId() )
|
||||
&& equals( parent.getArtifactId(), model.getArtifactId() ) )
|
||||
{
|
||||
addViolation( problems, false, "The parent element cannot have the same ID as the project." );
|
||||
addViolation( problems, Severity.ERROR, "The parent element cannot have the same ID as the project." );
|
||||
}
|
||||
}
|
||||
|
||||
if ( request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 )
|
||||
{
|
||||
validateEnum( "modelVersion", problems, false, model.getModelVersion(), null, "4.0.0" );
|
||||
validateStringNoExpression( "groupId", problems, true, model.getGroupId() );
|
||||
validateStringNoExpression( "artifactId", problems, true, model.getArtifactId() );
|
||||
validateStringNoExpression( "version", problems, true, model.getVersion() );
|
||||
validateEnum( "modelVersion", problems, Severity.ERROR, model.getModelVersion(), null, "4.0.0" );
|
||||
validateStringNoExpression( "groupId", problems, Severity.WARNING, model.getGroupId() );
|
||||
validateStringNoExpression( "artifactId", problems, Severity.WARNING, model.getArtifactId() );
|
||||
validateStringNoExpression( "version", problems, Severity.WARNING, model.getVersion() );
|
||||
|
||||
validateDependencies( problems, model.getDependencies(), "dependencies.dependency", request );
|
||||
|
||||
|
@ -98,7 +99,7 @@ public class DefaultModelValidator
|
|||
{
|
||||
if ( !profileIds.add( profile.getId() ) )
|
||||
{
|
||||
addViolation( problems, false, "profiles.profile.id must be unique"
|
||||
addViolation( problems, Severity.ERROR, "profiles.profile.id must be unique"
|
||||
+ " but found duplicate profile with id " + profile.getId() );
|
||||
}
|
||||
|
||||
|
@ -123,33 +124,23 @@ public class DefaultModelValidator
|
|||
|
||||
public void validateEffectiveModel( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
|
||||
{
|
||||
validateStringNotEmpty( "modelVersion", problems, false, model.getModelVersion() );
|
||||
validateStringNotEmpty( "modelVersion", problems, Severity.ERROR, model.getModelVersion() );
|
||||
|
||||
validateId( "groupId", problems, model.getGroupId() );
|
||||
|
||||
validateId( "artifactId", problems, model.getArtifactId() );
|
||||
|
||||
validateStringNotEmpty( "packaging", problems, false, model.getPackaging() );
|
||||
validateStringNotEmpty( "packaging", problems, Severity.ERROR, model.getPackaging() );
|
||||
|
||||
if ( !model.getModules().isEmpty() && !"pom".equals( model.getPackaging() ) )
|
||||
{
|
||||
addViolation( problems, false, "Packaging '" + model.getPackaging() + "' is invalid. Aggregator projects "
|
||||
+ "require 'pom' as packaging." );
|
||||
addViolation( problems, Severity.ERROR, "Packaging '" + model.getPackaging()
|
||||
+ "' is invalid. Aggregator projects " + "require 'pom' as packaging." );
|
||||
}
|
||||
|
||||
Parent parent = model.getParent();
|
||||
if ( parent != null )
|
||||
{
|
||||
if ( parent.getGroupId().equals( model.getGroupId() )
|
||||
&& parent.getArtifactId().equals( model.getArtifactId() ) )
|
||||
{
|
||||
addViolation( problems, false, "The parent element cannot have the same ID as the project." );
|
||||
}
|
||||
}
|
||||
validateStringNotEmpty( "version", problems, Severity.ERROR, model.getVersion() );
|
||||
|
||||
validateStringNotEmpty( "version", problems, false, model.getVersion() );
|
||||
|
||||
boolean warnOnly = request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0;
|
||||
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
||||
|
||||
for ( Dependency d : model.getDependencies() )
|
||||
{
|
||||
|
@ -157,9 +148,10 @@ public class DefaultModelValidator
|
|||
|
||||
validateId( "dependencies.dependency.groupId", problems, d.getGroupId(), d.getManagementKey() );
|
||||
|
||||
validateStringNotEmpty( "dependencies.dependency.type", problems, false, d.getType(), d.getManagementKey() );
|
||||
validateStringNotEmpty( "dependencies.dependency.type", problems, Severity.ERROR, d.getType(),
|
||||
d.getManagementKey() );
|
||||
|
||||
validateStringNotEmpty( "dependencies.dependency.version", problems, false, d.getVersion(),
|
||||
validateStringNotEmpty( "dependencies.dependency.version", problems, Severity.ERROR, d.getVersion(),
|
||||
d.getManagementKey() );
|
||||
|
||||
if ( "system".equals( d.getScope() ) )
|
||||
|
@ -168,37 +160,37 @@ public class DefaultModelValidator
|
|||
|
||||
if ( StringUtils.isEmpty( systemPath ) )
|
||||
{
|
||||
addViolation( problems, false, "For dependency " + d.getManagementKey()
|
||||
addViolation( problems, Severity.ERROR, "For dependency " + d.getManagementKey()
|
||||
+ ": system-scoped dependency must specify systemPath." );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !new File( systemPath ).isAbsolute() )
|
||||
{
|
||||
addViolation( problems, false, "For dependency " + d.getManagementKey()
|
||||
addViolation( problems, Severity.ERROR, "For dependency " + d.getManagementKey()
|
||||
+ ": system-scoped dependency must specify an absolute systemPath but is " + systemPath );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( StringUtils.isNotEmpty( d.getSystemPath() ) )
|
||||
{
|
||||
addViolation( problems, false, "For dependency " + d.getManagementKey()
|
||||
addViolation( problems, Severity.ERROR, "For dependency " + d.getManagementKey()
|
||||
+ ": only dependency with system scope can specify systemPath." );
|
||||
}
|
||||
|
||||
if ( request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 )
|
||||
{
|
||||
validateVersion( "dependencies.dependency.version", problems, warnOnly, d.getVersion(),
|
||||
validateVersion( "dependencies.dependency.version", problems, errOn30, d.getVersion(),
|
||||
d.getManagementKey() );
|
||||
|
||||
validateBoolean( "dependencies.dependency.optional", problems, warnOnly, d.getOptional(),
|
||||
validateBoolean( "dependencies.dependency.optional", problems, errOn30, d.getOptional(),
|
||||
d.getManagementKey() );
|
||||
|
||||
/*
|
||||
* TODO: Extensions like Flex Mojos use custom scopes like "merged", "internal", "external", etc. In
|
||||
* order to don't break backward-compat with those, only warn but don't error out.
|
||||
*/
|
||||
validateEnum( "dependencies.dependency.scope", problems, true, d.getScope(),
|
||||
validateEnum( "dependencies.dependency.scope", problems, Severity.WARNING, d.getScope(),
|
||||
d.getManagementKey(), "provided", "compile", "runtime", "test", "system" );
|
||||
}
|
||||
}
|
||||
|
@ -208,11 +200,11 @@ public class DefaultModelValidator
|
|||
{
|
||||
for ( Dependency d : mgmt.getDependencies() )
|
||||
{
|
||||
validateStringNotEmpty( "dependencyManagement.dependencies.dependency.artifactId", problems, false,
|
||||
d.getArtifactId(), d.getManagementKey() );
|
||||
validateStringNotEmpty( "dependencyManagement.dependencies.dependency.artifactId", problems,
|
||||
Severity.ERROR, d.getArtifactId(), d.getManagementKey() );
|
||||
|
||||
validateStringNotEmpty( "dependencyManagement.dependencies.dependency.groupId", problems, false,
|
||||
d.getGroupId(), d.getManagementKey() );
|
||||
validateStringNotEmpty( "dependencyManagement.dependencies.dependency.groupId", problems,
|
||||
Severity.ERROR, d.getGroupId(), d.getManagementKey() );
|
||||
|
||||
if ( "system".equals( d.getScope() ) )
|
||||
{
|
||||
|
@ -220,28 +212,27 @@ public class DefaultModelValidator
|
|||
|
||||
if ( StringUtils.isEmpty( systemPath ) )
|
||||
{
|
||||
addViolation( problems, false, "For managed dependency " + d.getManagementKey()
|
||||
addViolation( problems, Severity.ERROR, "For managed dependency " + d.getManagementKey()
|
||||
+ ": system-scoped dependency must specify systemPath." );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !new File( systemPath ).isAbsolute() )
|
||||
{
|
||||
addViolation( problems, false, "For managed dependency " + d.getManagementKey()
|
||||
+ ": system-scoped dependency must specify an absolute systemPath but is "
|
||||
+ systemPath );
|
||||
addViolation( problems, Severity.ERROR, "For managed dependency " + d.getManagementKey()
|
||||
+ ": system-scoped dependency must specify an absolute systemPath but is " + systemPath );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( StringUtils.isNotEmpty( d.getSystemPath() ) )
|
||||
{
|
||||
addViolation( problems, false, "For managed dependency " + d.getManagementKey()
|
||||
addViolation( problems, Severity.ERROR, "For managed dependency " + d.getManagementKey()
|
||||
+ ": only dependency with system scope can specify systemPath." );
|
||||
}
|
||||
|
||||
if ( request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 )
|
||||
{
|
||||
validateBoolean( "dependencyManagement.dependencies.dependency.optional", problems, warnOnly,
|
||||
validateBoolean( "dependencyManagement.dependencies.dependency.optional", problems, errOn30,
|
||||
d.getOptional(), d.getManagementKey() );
|
||||
}
|
||||
}
|
||||
|
@ -254,37 +245,37 @@ public class DefaultModelValidator
|
|||
{
|
||||
if ( !modules.add( module ) )
|
||||
{
|
||||
addViolation( problems, false, "Duplicate child module: " + module );
|
||||
addViolation( problems, Severity.ERROR, "Duplicate child module: " + module );
|
||||
}
|
||||
}
|
||||
|
||||
boolean warnOnMissingPluginVersion =
|
||||
request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1;
|
||||
Severity errOn31 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
|
||||
|
||||
Build build = model.getBuild();
|
||||
if ( build != null )
|
||||
{
|
||||
for ( Plugin p : build.getPlugins() )
|
||||
{
|
||||
validateStringNotEmpty( "build.plugins.plugin.artifactId", problems, false, p.getArtifactId() );
|
||||
validateStringNotEmpty( "build.plugins.plugin.artifactId", problems, Severity.ERROR,
|
||||
p.getArtifactId() );
|
||||
|
||||
validateStringNotEmpty( "build.plugins.plugin.groupId", problems, false, p.getGroupId() );
|
||||
validateStringNotEmpty( "build.plugins.plugin.groupId", problems, Severity.ERROR, p.getGroupId() );
|
||||
|
||||
validateStringNotEmpty( "build.plugins.plugin.version", problems, warnOnMissingPluginVersion,
|
||||
p.getVersion(), p.getKey() );
|
||||
validateStringNotEmpty( "build.plugins.plugin.version", problems, errOn31, p.getVersion(),
|
||||
p.getKey() );
|
||||
|
||||
validateVersion( "build.plugins.plugin.version", problems, warnOnly, p.getVersion(), p.getKey() );
|
||||
validateVersion( "build.plugins.plugin.version", problems, errOn30, p.getVersion(), p.getKey() );
|
||||
|
||||
validateBoolean( "build.plugins.plugin.inherited", problems, warnOnly, p.getInherited(),
|
||||
validateBoolean( "build.plugins.plugin.inherited", problems, errOn30, p.getInherited(),
|
||||
p.getKey() );
|
||||
|
||||
validateBoolean( "build.plugins.plugin.extensions", problems, warnOnly, p.getExtensions(),
|
||||
validateBoolean( "build.plugins.plugin.extensions", problems, errOn30, p.getExtensions(),
|
||||
p.getKey() );
|
||||
|
||||
for ( Dependency d : p.getDependencies() )
|
||||
{
|
||||
validateEnum( "build.plugins.plugin[" + p.getKey() + "].dependencies.dependency.scope",
|
||||
problems, warnOnly, d.getScope(), d.getManagementKey(),
|
||||
problems, errOn30, d.getScope(), d.getManagementKey(),
|
||||
"compile", "runtime", "system" );
|
||||
}
|
||||
}
|
||||
|
@ -299,12 +290,14 @@ public class DefaultModelValidator
|
|||
{
|
||||
for ( ReportPlugin p : reporting.getPlugins() )
|
||||
{
|
||||
validateStringNotEmpty( "reporting.plugins.plugin.artifactId", problems, false, p.getArtifactId() );
|
||||
validateStringNotEmpty( "reporting.plugins.plugin.artifactId", problems, Severity.ERROR,
|
||||
p.getArtifactId() );
|
||||
|
||||
validateStringNotEmpty( "reporting.plugins.plugin.groupId", problems, false, p.getGroupId() );
|
||||
validateStringNotEmpty( "reporting.plugins.plugin.groupId", problems, Severity.ERROR,
|
||||
p.getGroupId() );
|
||||
|
||||
validateStringNotEmpty( "reporting.plugins.plugin.version", problems, warnOnMissingPluginVersion,
|
||||
p.getVersion(), p.getKey() );
|
||||
validateStringNotEmpty( "reporting.plugins.plugin.version", problems, errOn31, p.getVersion(),
|
||||
p.getKey() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -325,7 +318,7 @@ public class DefaultModelValidator
|
|||
{
|
||||
if ( distMgmt.getStatus() != null )
|
||||
{
|
||||
addViolation( problems, false, "'distributionManagement.status' must not be specified" );
|
||||
addViolation( problems, Severity.ERROR, "'distributionManagement.status' must not be specified" );
|
||||
}
|
||||
|
||||
validateRepositoryLayout( problems, distMgmt.getRepository(), "distributionManagement.repository",
|
||||
|
@ -343,7 +336,7 @@ public class DefaultModelValidator
|
|||
|
||||
private boolean validateId( String fieldName, ModelProblemCollector problems, String id, String sourceHint )
|
||||
{
|
||||
if ( !validateStringNotEmpty( fieldName, problems, false, id, sourceHint ) )
|
||||
if ( !validateStringNotEmpty( fieldName, problems, Severity.ERROR, id, sourceHint ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -352,7 +345,7 @@ public class DefaultModelValidator
|
|||
boolean match = id.matches( ID_REGEX );
|
||||
if ( !match )
|
||||
{
|
||||
addViolation( problems, false, "'" + fieldName + "'"
|
||||
addViolation( problems, Severity.ERROR, "'" + fieldName + "'"
|
||||
+ ( sourceHint != null ? " for " + sourceHint : "" ) + " with value '" + id
|
||||
+ "' does not match a valid id pattern." );
|
||||
}
|
||||
|
@ -372,17 +365,17 @@ public class DefaultModelValidator
|
|||
if ( "pom".equals( dependency.getType() ) && "import".equals( dependency.getScope() )
|
||||
&& StringUtils.isNotEmpty( dependency.getClassifier() ) )
|
||||
{
|
||||
addViolation( problems, false, "'" + prefix + ".classifier' must be empty for imported POM: " + key );
|
||||
addViolation( problems, Severity.ERROR, "'" + prefix + ".classifier' must be empty for imported POM: " + key );
|
||||
}
|
||||
|
||||
Dependency existing = index.get( key );
|
||||
|
||||
if ( existing != null )
|
||||
{
|
||||
boolean warning = request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0;
|
||||
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
||||
|
||||
String msg;
|
||||
if ( StringUtils.clean( existing.getVersion() ).equals( StringUtils.clean( dependency.getVersion() ) ) )
|
||||
if ( equals( existing.getVersion(), dependency.getVersion() ) )
|
||||
{
|
||||
msg =
|
||||
"duplicate declaration of version "
|
||||
|
@ -395,7 +388,7 @@ public class DefaultModelValidator
|
|||
+ StringUtils.defaultString( dependency.getVersion(), "(?)" );
|
||||
}
|
||||
|
||||
addViolation( problems, warning, "'" + prefix
|
||||
addViolation( problems, errOn30, "'" + prefix
|
||||
+ ".(groupId:artifactId:type:classifier)' must be unique: " + key + " -> " + msg );
|
||||
}
|
||||
else
|
||||
|
@ -412,9 +405,10 @@ public class DefaultModelValidator
|
|||
|
||||
for ( Repository repository : repositories )
|
||||
{
|
||||
validateStringNotEmpty( prefix + ".id", problems, false, repository.getId() );
|
||||
validateStringNotEmpty( prefix + ".id", problems, Severity.ERROR, repository.getId() );
|
||||
|
||||
validateStringNotEmpty( prefix + "[" + repository.getId() + "].url", problems, false, repository.getUrl() );
|
||||
validateStringNotEmpty( prefix + "[" + repository.getId() + "].url", problems, Severity.ERROR,
|
||||
repository.getUrl() );
|
||||
|
||||
String key = repository.getId();
|
||||
|
||||
|
@ -422,9 +416,9 @@ public class DefaultModelValidator
|
|||
|
||||
if ( existing != null )
|
||||
{
|
||||
boolean warning = request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0;
|
||||
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
||||
|
||||
addViolation( problems, warning, "'" + prefix + ".id' must be unique: " + repository.getId() + " -> "
|
||||
addViolation( problems, errOn30, "'" + prefix + ".id' must be unique: " + repository.getId() + " -> "
|
||||
+ existing.getUrl() + " vs " + repository.getUrl() );
|
||||
}
|
||||
else
|
||||
|
@ -439,19 +433,20 @@ public class DefaultModelValidator
|
|||
{
|
||||
if ( repository != null && "legacy".equals( repository.getLayout() ) )
|
||||
{
|
||||
addViolation( problems, true, "'" + prefix + ".layout = legacy' is deprecated: " + repository.getId() );
|
||||
addViolation( problems, Severity.WARNING, "'" + prefix + ".layout = legacy' is deprecated: "
|
||||
+ repository.getId() );
|
||||
}
|
||||
}
|
||||
|
||||
private void validateResources( ModelProblemCollector problems, List<Resource> resources, String prefix, ModelBuildingRequest request )
|
||||
{
|
||||
boolean warnOnBadBoolean = request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0;
|
||||
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
||||
|
||||
for ( Resource resource : resources )
|
||||
{
|
||||
validateStringNotEmpty( prefix + ".directory", problems, false, resource.getDirectory() );
|
||||
validateStringNotEmpty( prefix + ".directory", problems, Severity.ERROR, resource.getDirectory() );
|
||||
|
||||
validateBoolean( prefix + ".filtering", problems, warnOnBadBoolean, resource.getFiltering(),
|
||||
validateBoolean( prefix + ".filtering", problems, errOn30, resource.getFiltering(),
|
||||
resource.getDirectory() );
|
||||
}
|
||||
}
|
||||
|
@ -475,7 +470,7 @@ public class DefaultModelValidator
|
|||
}
|
||||
catch ( IllegalStateException collisionException )
|
||||
{
|
||||
addViolation( problems, false, collisionException.getMessage() );
|
||||
addViolation( problems, Severity.ERROR, collisionException.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -486,7 +481,7 @@ public class DefaultModelValidator
|
|||
// Field validation
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private boolean validateStringNoExpression( String fieldName, ModelProblemCollector problems, boolean warning,
|
||||
private boolean validateStringNoExpression( String fieldName, ModelProblemCollector problems, Severity severity,
|
||||
String string )
|
||||
{
|
||||
if ( !hasExpression( string ) )
|
||||
|
@ -494,7 +489,7 @@ public class DefaultModelValidator
|
|||
return true;
|
||||
}
|
||||
|
||||
addViolation( problems, warning, "'" + fieldName + "' contains an expression but should be a constant." );
|
||||
addViolation( problems, severity, "'" + fieldName + "' contains an expression but should be a constant." );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -504,9 +499,10 @@ public class DefaultModelValidator
|
|||
return value != null && value.indexOf( "${" ) >= 0;
|
||||
}
|
||||
|
||||
private boolean validateStringNotEmpty( String fieldName, ModelProblemCollector problems, boolean warning, String string )
|
||||
private boolean validateStringNotEmpty( String fieldName, ModelProblemCollector problems, Severity severity,
|
||||
String string )
|
||||
{
|
||||
return validateStringNotEmpty( fieldName, problems, warning, string, null );
|
||||
return validateStringNotEmpty( fieldName, problems, severity, string, null );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -517,10 +513,10 @@ public class DefaultModelValidator
|
|||
* <li><code>string.length > 0</code>
|
||||
* </ul>
|
||||
*/
|
||||
private boolean validateStringNotEmpty( String fieldName, ModelProblemCollector problems, boolean warning,
|
||||
private boolean validateStringNotEmpty( String fieldName, ModelProblemCollector problems, Severity severity,
|
||||
String string, String sourceHint )
|
||||
{
|
||||
if ( !validateNotNull( fieldName, problems, warning, string, sourceHint ) )
|
||||
if ( !validateNotNull( fieldName, problems, severity, string, sourceHint ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -532,11 +528,11 @@ public class DefaultModelValidator
|
|||
|
||||
if ( sourceHint != null )
|
||||
{
|
||||
addViolation( problems, warning, "'" + fieldName + "' is missing for " + sourceHint );
|
||||
addViolation( problems, severity, "'" + fieldName + "' is missing for " + sourceHint );
|
||||
}
|
||||
else
|
||||
{
|
||||
addViolation( problems, warning, "'" + fieldName + "' is missing." );
|
||||
addViolation( problems, severity, "'" + fieldName + "' is missing." );
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -549,7 +545,8 @@ public class DefaultModelValidator
|
|||
* <li><code>string != null</code>
|
||||
* </ul>
|
||||
*/
|
||||
private boolean validateNotNull( String fieldName, ModelProblemCollector problems, boolean warning, Object object, String sourceHint )
|
||||
private boolean validateNotNull( String fieldName, ModelProblemCollector problems, Severity severity,
|
||||
Object object, String sourceHint )
|
||||
{
|
||||
if ( object != null )
|
||||
{
|
||||
|
@ -558,17 +555,17 @@ public class DefaultModelValidator
|
|||
|
||||
if ( sourceHint != null )
|
||||
{
|
||||
addViolation( problems, warning, "'" + fieldName + "' is missing for " + sourceHint );
|
||||
addViolation( problems, severity, "'" + fieldName + "' is missing for " + sourceHint );
|
||||
}
|
||||
else
|
||||
{
|
||||
addViolation( problems, warning, "'" + fieldName + "' is missing." );
|
||||
addViolation( problems, severity, "'" + fieldName + "' is missing." );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean validateBoolean( String fieldName, ModelProblemCollector problems, boolean warning, String string,
|
||||
private boolean validateBoolean( String fieldName, ModelProblemCollector problems, Severity severity, String string,
|
||||
String sourceHint )
|
||||
{
|
||||
if ( string == null || string.length() <= 0 )
|
||||
|
@ -583,18 +580,18 @@ public class DefaultModelValidator
|
|||
|
||||
if ( sourceHint != null )
|
||||
{
|
||||
addViolation( problems, warning, "'" + fieldName + "' must be 'true' or 'false' for " + sourceHint
|
||||
addViolation( problems, severity, "'" + fieldName + "' must be 'true' or 'false' for " + sourceHint
|
||||
+ " but is '" + string + "'." );
|
||||
}
|
||||
else
|
||||
{
|
||||
addViolation( problems, warning, "'" + fieldName + "' must be 'true' or 'false' but is '" + string + "'." );
|
||||
addViolation( problems, severity, "'" + fieldName + "' must be 'true' or 'false' but is '" + string + "'." );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean validateEnum( String fieldName, ModelProblemCollector problems, boolean warning, String string,
|
||||
private boolean validateEnum( String fieldName, ModelProblemCollector problems, Severity severity, String string,
|
||||
String sourceHint, String... validValues )
|
||||
{
|
||||
if ( string == null || string.length() <= 0 )
|
||||
|
@ -611,19 +608,19 @@ public class DefaultModelValidator
|
|||
|
||||
if ( sourceHint != null )
|
||||
{
|
||||
addViolation( problems, warning, "'" + fieldName + "' must be one of " + values + " for " + sourceHint
|
||||
addViolation( problems, severity, "'" + fieldName + "' must be one of " + values + " for " + sourceHint
|
||||
+ " but is '" + string + "'." );
|
||||
}
|
||||
else
|
||||
{
|
||||
addViolation( problems, warning, "'" + fieldName + "' must be one of " + values + " but is '" + string
|
||||
addViolation( problems, severity, "'" + fieldName + "' must be one of " + values + " but is '" + string
|
||||
+ "'." );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean validateVersion( String fieldName, ModelProblemCollector problems, boolean warning, String string,
|
||||
private boolean validateVersion( String fieldName, ModelProblemCollector problems, Severity severity, String string,
|
||||
String sourceHint )
|
||||
{
|
||||
if ( string == null || string.length() <= 0 )
|
||||
|
@ -638,26 +635,36 @@ public class DefaultModelValidator
|
|||
|
||||
if ( sourceHint != null )
|
||||
{
|
||||
addViolation( problems, warning, "'" + fieldName + "' must be a valid version for " + sourceHint
|
||||
addViolation( problems, severity, "'" + fieldName + "' must be a valid version for " + sourceHint
|
||||
+ " but is '" + string + "'." );
|
||||
}
|
||||
else
|
||||
{
|
||||
addViolation( problems, warning, "'" + fieldName + "' must be a valid version but is '" + string + "'." );
|
||||
addViolation( problems, severity, "'" + fieldName + "' must be a valid version but is '" + string + "'." );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void addViolation( ModelProblemCollector problems, boolean warning, String message )
|
||||
private static void addViolation( ModelProblemCollector problems, Severity severity, String message )
|
||||
{
|
||||
if ( warning )
|
||||
problems.add( severity, message, null );
|
||||
}
|
||||
|
||||
private static boolean equals( String s1, String s2 )
|
||||
{
|
||||
return StringUtils.clean( s1 ).equals( StringUtils.clean( s2 ) );
|
||||
}
|
||||
|
||||
private static Severity getSeverity( ModelBuildingRequest request, int errorThreshold )
|
||||
{
|
||||
if ( request.getValidationLevel() < errorThreshold )
|
||||
{
|
||||
problems.addWarning( message );
|
||||
return Severity.WARNING;
|
||||
}
|
||||
else
|
||||
{
|
||||
problems.addError( message );
|
||||
return Severity.ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ package org.apache.maven.model.building;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
|
||||
/**
|
||||
* A simple model problem collector for testing the model building components.
|
||||
*
|
||||
|
@ -35,25 +37,7 @@ public class SimpleProblemCollector
|
|||
|
||||
private List<String> errors = new ArrayList<String>();
|
||||
|
||||
public void addError( String message )
|
||||
{
|
||||
errors.add( message );
|
||||
}
|
||||
|
||||
public void addError( String message, Exception cause )
|
||||
{
|
||||
addError( message );
|
||||
}
|
||||
|
||||
public void addWarning( String message )
|
||||
{
|
||||
warnings.add( message );
|
||||
}
|
||||
|
||||
public void addWarning( String message, Exception cause )
|
||||
{
|
||||
addWarning( message );
|
||||
}
|
||||
private List<String> fatals = new ArrayList<String>();
|
||||
|
||||
public List<String> getWarnings()
|
||||
{
|
||||
|
@ -65,4 +49,26 @@ public class SimpleProblemCollector
|
|||
return errors;
|
||||
}
|
||||
|
||||
public List<String> getFatals()
|
||||
{
|
||||
return fatals;
|
||||
}
|
||||
|
||||
public void add( Severity severity, String message, Exception cause )
|
||||
{
|
||||
switch ( severity )
|
||||
{
|
||||
case FATAL:
|
||||
fatals.add( message );
|
||||
break;
|
||||
case ERROR:
|
||||
errors.add( message );
|
||||
break;
|
||||
case WARNING:
|
||||
warnings.add( message );
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -102,8 +102,9 @@ public class DefaultModelValidatorTest
|
|||
super.tearDown();
|
||||
}
|
||||
|
||||
private void assertViolations( SimpleProblemCollector result, int errors, int warnings )
|
||||
private void assertViolations( SimpleProblemCollector result, int fatals, int errors, int warnings )
|
||||
{
|
||||
assertEquals( fatals, result.getFatals().size() );
|
||||
assertEquals( errors, result.getErrors().size() );
|
||||
assertEquals( warnings, result.getWarnings().size() );
|
||||
}
|
||||
|
@ -113,7 +114,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "missing-modelVersion-pom.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertEquals( "'modelVersion' is missing.", result.getErrors().get( 0 ) );
|
||||
}
|
||||
|
@ -124,7 +125,7 @@ public class DefaultModelValidatorTest
|
|||
SimpleProblemCollector result =
|
||||
validateRaw( "bad-modelVersion.xml", ModelBuildingRequest.VALIDATION_LEVEL_STRICT );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertTrue( result.getErrors().get( 0 ).indexOf( "modelVersion" ) > -1 );
|
||||
}
|
||||
|
@ -134,7 +135,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "missing-artifactId-pom.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertEquals( "'artifactId' is missing.", result.getErrors().get( 0 ) );
|
||||
}
|
||||
|
@ -144,7 +145,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "missing-groupId-pom.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertEquals( "'groupId' is missing.", result.getErrors().get( 0 ) );
|
||||
}
|
||||
|
@ -154,7 +155,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "invalid-ids-pom.xml" );
|
||||
|
||||
assertViolations( result, 2, 0 );
|
||||
assertViolations( result, 0, 2, 0 );
|
||||
|
||||
assertEquals( "'groupId' with value 'o/a/m' does not match a valid id pattern.", result.getErrors().get( 0 ) );
|
||||
|
||||
|
@ -166,7 +167,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "missing-type-pom.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertEquals( "'packaging' is missing.", result.getErrors().get( 0 ) );
|
||||
}
|
||||
|
@ -176,7 +177,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "missing-version-pom.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertEquals( "'version' is missing.", result.getErrors().get( 0 ) );
|
||||
}
|
||||
|
@ -186,7 +187,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "invalid-aggregator-packaging-pom.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertTrue( result.getErrors().get( 0 ).indexOf( "Aggregator projects require 'pom' as packaging." ) > -1 );
|
||||
}
|
||||
|
@ -196,7 +197,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "missing-dependency-artifactId-pom.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertTrue( result.getErrors().get( 0 ).indexOf( "'dependencies.dependency.artifactId' is missing" ) > -1 );
|
||||
}
|
||||
|
@ -206,7 +207,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "missing-dependency-groupId-pom.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertTrue( result.getErrors().get( 0 ).indexOf( "'dependencies.dependency.groupId' is missing" ) > -1 );
|
||||
}
|
||||
|
@ -216,7 +217,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "missing-dependency-version-pom.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertTrue( result.getErrors().get( 0 ).indexOf( "'dependencies.dependency.version' is missing" ) > -1 );
|
||||
}
|
||||
|
@ -226,7 +227,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "missing-dependency-mgmt-artifactId-pom.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertTrue( result.getErrors().get( 0 ).indexOf(
|
||||
"'dependencyManagement.dependencies.dependency.artifactId' is missing" ) > -1 );
|
||||
|
@ -237,7 +238,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "missing-dependency-mgmt-groupId-pom.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertTrue( result.getErrors().get( 0 ).indexOf(
|
||||
"'dependencyManagement.dependencies.dependency.groupId' is missing" ) > -1 );
|
||||
|
@ -248,7 +249,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "missing-1-pom.xml" );
|
||||
|
||||
assertViolations( result, 4, 0 );
|
||||
assertViolations( result, 0, 4, 0 );
|
||||
|
||||
List<String> messages = result.getErrors();
|
||||
|
||||
|
@ -264,7 +265,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "missing-plugin-artifactId-pom.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertEquals( "'build.plugins.plugin.artifactId' is missing.", result.getErrors().get( 0 ) );
|
||||
}
|
||||
|
@ -275,14 +276,14 @@ public class DefaultModelValidatorTest
|
|||
SimpleProblemCollector result =
|
||||
validateEffective( "missing-plugin-version-pom.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertEquals( "'build.plugins.plugin.version' is missing for org.apache.maven.plugins:maven-it-plugin",
|
||||
result.getErrors().get( 0 ) );
|
||||
|
||||
result = validateEffective( "missing-plugin-version-pom.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
||||
|
||||
assertViolations( result, 0, 1 );
|
||||
assertViolations( result, 0, 0, 1 );
|
||||
}
|
||||
|
||||
public void testMissingRepositoryId()
|
||||
|
@ -291,7 +292,7 @@ public class DefaultModelValidatorTest
|
|||
SimpleProblemCollector result =
|
||||
validateRaw( "missing-repository-id-pom.xml", ModelBuildingRequest.VALIDATION_LEVEL_STRICT );
|
||||
|
||||
assertViolations( result, 4, 0 );
|
||||
assertViolations( result, 0, 4, 0 );
|
||||
|
||||
assertEquals( "'repositories.repository.id' is missing.", result.getErrors().get( 0 ) );
|
||||
|
||||
|
@ -307,7 +308,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "missing-resource-directory-pom.xml" );
|
||||
|
||||
assertViolations( result, 2, 0 );
|
||||
assertViolations( result, 0, 2, 0 );
|
||||
|
||||
assertEquals( "'build.resources.resource.directory' is missing.", result.getErrors().get( 0 ) );
|
||||
|
||||
|
@ -319,7 +320,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "bad-plugin-dependency-scope.xml" );
|
||||
|
||||
assertViolations( result, 3, 0 );
|
||||
assertViolations( result, 0, 3, 0 );
|
||||
|
||||
assertTrue( result.getErrors().get( 0 ).contains( "test:d" ) );
|
||||
|
||||
|
@ -333,7 +334,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "bad-dependency-scope.xml" );
|
||||
|
||||
assertViolations( result, 0, 2 );
|
||||
assertViolations( result, 0, 0, 2 );
|
||||
|
||||
assertTrue( result.getWarnings().get( 0 ).contains( "test:f" ) );
|
||||
|
||||
|
@ -345,7 +346,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "bad-dependency-version.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertTrue( result.getErrors().get( 0 ).contains( "test:b" ) );
|
||||
}
|
||||
|
@ -355,7 +356,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "duplicate-module.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertTrue( result.getErrors().get( 0 ).contains( "child" ) );
|
||||
}
|
||||
|
@ -365,7 +366,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validateRaw( "duplicate-profile-id.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertTrue( result.getErrors().get( 0 ).contains( "non-unique-id" ) );
|
||||
}
|
||||
|
@ -375,7 +376,7 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "bad-plugin-version.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertTrue( result.getErrors().get( 0 ).contains( "test:mip" ) );
|
||||
}
|
||||
|
@ -385,9 +386,21 @@ public class DefaultModelValidatorTest
|
|||
{
|
||||
SimpleProblemCollector result = validate( "distribution-management-status.xml" );
|
||||
|
||||
assertViolations( result, 1, 0 );
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertTrue( result.getErrors().get( 0 ).contains( "distributionManagement.status" ) );
|
||||
}
|
||||
|
||||
public void testIncompleteParent()
|
||||
throws Exception
|
||||
{
|
||||
SimpleProblemCollector result = validateRaw( "incomplete-parent.xml" );
|
||||
|
||||
assertViolations( result, 3, 0, 0 );
|
||||
|
||||
assertTrue( result.getFatals().get( 0 ).contains( "parent.groupId" ) );
|
||||
assertTrue( result.getFatals().get( 1 ).contains( "parent.artifactId" ) );
|
||||
assertTrue( result.getFatals().get( 2 ).contains( "parent.version" ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<!-- all fields missing -->
|
||||
</parent>
|
||||
|
||||
<artifactId>aid</artifactId>
|
||||
<groupId>gid</groupId>
|
||||
<version>0.1</version>
|
||||
</project>
|
Loading…
Reference in New Issue