mirror of https://github.com/apache/maven.git
MNG-5306 : introduce ModelProblemCollectorRequest and a new ModelProblem property - version which denotes on which validation level the error/warning applies. Additionally move the logic on failing the ModelBuilding from ModelProblemCollector to ModelBuilder's protected method to allow overriding. Default maven behaviour should stay the same.
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1357589 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
26d610db6e
commit
4fcfcb8f73
|
@ -36,11 +36,14 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
|
||||||
import org.codehaus.plexus.logging.Logger;
|
import org.codehaus.plexus.logging.Logger;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Version;
|
||||||
|
import org.apache.maven.model.building.ModelProblemCollectorRequest;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class DefaultProfileManager
|
public class DefaultProfileManager
|
||||||
|
@ -195,14 +198,13 @@ public class DefaultProfileManager
|
||||||
profileSelector.getActiveProfiles( profilesById.values(), context, new ModelProblemCollector()
|
profileSelector.getActiveProfiles( profilesById.values(), context, new ModelProblemCollector()
|
||||||
{
|
{
|
||||||
|
|
||||||
public void add( Severity severity, String message, InputLocation location, Exception cause )
|
public void add( ModelProblemCollectorRequest req )
|
||||||
{
|
{
|
||||||
if ( !ModelProblem.Severity.WARNING.equals( severity ) )
|
if ( !ModelProblem.Severity.WARNING.equals( req.getSeverity() ) )
|
||||||
{
|
{
|
||||||
errors.add( new ProfileActivationException( message, cause ) );
|
errors.add( new ProfileActivationException( req.getMessage(), req.getException() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
if ( !errors.isEmpty() )
|
if ( !errors.isEmpty() )
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.maven.project.validation;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import org.apache.maven.model.InputLocation;
|
import org.apache.maven.model.InputLocation;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.building.DefaultModelBuildingRequest;
|
import org.apache.maven.model.building.DefaultModelBuildingRequest;
|
||||||
|
@ -26,6 +27,8 @@ import org.apache.maven.model.building.ModelBuildingRequest;
|
||||||
import org.apache.maven.model.building.ModelProblem;
|
import org.apache.maven.model.building.ModelProblem;
|
||||||
import org.apache.maven.model.building.ModelProblemCollector;
|
import org.apache.maven.model.building.ModelProblemCollector;
|
||||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Version;
|
||||||
|
import org.apache.maven.model.building.ModelProblemCollectorRequest;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
import org.codehaus.plexus.component.annotations.Requirement;
|
import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
|
|
||||||
|
@ -66,14 +69,12 @@ public class DefaultModelValidator
|
||||||
this.result = result;
|
this.result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add( Severity severity, String message, InputLocation location, Exception cause )
|
public void add( ModelProblemCollectorRequest req )
|
||||||
{
|
{
|
||||||
if ( !ModelProblem.Severity.WARNING.equals( severity ) )
|
if ( !ModelProblem.Severity.WARNING.equals( req.getSeverity() ) )
|
||||||
{
|
{
|
||||||
result.addMessage( message );
|
result.addMessage( req.getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,8 @@ import org.apache.maven.model.PluginManagement;
|
||||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||||
import org.apache.maven.model.building.ModelProblemCollector;
|
import org.apache.maven.model.building.ModelProblemCollector;
|
||||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Version;
|
||||||
|
import org.apache.maven.model.building.ModelProblemCollectorRequest;
|
||||||
import org.apache.maven.model.merge.MavenModelMerger;
|
import org.apache.maven.model.merge.MavenModelMerger;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
import org.codehaus.plexus.component.annotations.Requirement;
|
import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
|
@ -64,7 +66,9 @@ public class DefaultLifecycleBindingsInjector
|
||||||
|
|
||||||
if ( defaultPlugins == null )
|
if ( defaultPlugins == null )
|
||||||
{
|
{
|
||||||
problems.add( Severity.ERROR, "Unknown packaging: " + packaging, model.getLocation( "packaging" ), null );
|
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
|
||||||
|
.setMessage( "Unknown packaging: " + packaging )
|
||||||
|
.setLocation( model.getLocation( "packaging" )));
|
||||||
}
|
}
|
||||||
else if ( !defaultPlugins.isEmpty() )
|
else if ( !defaultPlugins.isEmpty() )
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,8 @@ import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.building.AbstractModelBuildingListener;
|
import org.apache.maven.model.building.AbstractModelBuildingListener;
|
||||||
import org.apache.maven.model.building.ModelBuildingEvent;
|
import org.apache.maven.model.building.ModelBuildingEvent;
|
||||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Version;
|
||||||
|
import org.apache.maven.model.building.ModelProblemCollectorRequest;
|
||||||
import org.apache.maven.plugin.PluginResolutionException;
|
import org.apache.maven.plugin.PluginResolutionException;
|
||||||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
||||||
|
|
||||||
|
@ -95,7 +97,9 @@ class DefaultModelBuildingListener
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
{
|
{
|
||||||
event.getProblems().add( Severity.ERROR, "Invalid plugin repository: " + e.getMessage(), null, e );
|
event.getProblems().add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
|
||||||
|
.setMessage( "Invalid plugin repository: " + e.getMessage() )
|
||||||
|
.setException( e ));
|
||||||
}
|
}
|
||||||
project.setPluginArtifactRepositories( pluginRepositories );
|
project.setPluginArtifactRepositories( pluginRepositories );
|
||||||
|
|
||||||
|
@ -111,11 +115,15 @@ class DefaultModelBuildingListener
|
||||||
}
|
}
|
||||||
catch ( PluginResolutionException e )
|
catch ( PluginResolutionException e )
|
||||||
{
|
{
|
||||||
event.getProblems().add( Severity.ERROR, "Unresolveable build extension: " + e.getMessage(), null, e );
|
event.getProblems().add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
|
||||||
|
.setMessage( "Unresolveable build extension: " + e.getMessage())
|
||||||
|
.setException( e ));
|
||||||
}
|
}
|
||||||
catch ( PluginVersionResolutionException e )
|
catch ( PluginVersionResolutionException e )
|
||||||
{
|
{
|
||||||
event.getProblems().add( Severity.ERROR, "Unresolveable build extension: " + e.getMessage(), null, e );
|
event.getProblems().add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
|
||||||
|
.setMessage( "Unresolveable build extension: " + e.getMessage() )
|
||||||
|
.setException( e ));
|
||||||
}
|
}
|
||||||
|
|
||||||
projectBuildingHelper.selectProjectRealm( project );
|
projectBuildingHelper.selectProjectRealm( project );
|
||||||
|
@ -130,7 +138,9 @@ class DefaultModelBuildingListener
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
{
|
{
|
||||||
event.getProblems().add( Severity.ERROR, "Invalid artifact repository: " + e.getMessage(), null, e );
|
event.getProblems().add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
|
||||||
|
.setMessage( "Invalid artifact repository: " + e.getMessage() )
|
||||||
|
.setException( e ));
|
||||||
}
|
}
|
||||||
project.setRemoteArtifactRepositories( remoteRepositories );
|
project.setRemoteArtifactRepositories( remoteRepositories );
|
||||||
}
|
}
|
||||||
|
|
|
@ -442,7 +442,7 @@ public class DefaultProjectBuilder
|
||||||
{
|
{
|
||||||
ModelProblem problem =
|
ModelProblem problem =
|
||||||
new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile
|
new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile
|
||||||
+ " does not exist", ModelProblem.Severity.ERROR, model, -1, -1, null );
|
+ " does not exist", ModelProblem.Severity.ERROR, ModelProblem.Version.BASE, model, -1, -1, null );
|
||||||
result.getProblems().add( problem );
|
result.getProblems().add( problem );
|
||||||
|
|
||||||
noErrors = false;
|
noErrors = false;
|
||||||
|
@ -478,7 +478,7 @@ public class DefaultProjectBuilder
|
||||||
|
|
||||||
ModelProblem problem =
|
ModelProblem problem =
|
||||||
new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile
|
new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile
|
||||||
+ " forms aggregation cycle " + buffer, ModelProblem.Severity.ERROR, model, -1, -1,
|
+ " forms aggregation cycle " + buffer, ModelProblem.Severity.ERROR, ModelProblem.Version.BASE, model, -1, -1,
|
||||||
null );
|
null );
|
||||||
result.getProblems().add( problem );
|
result.getProblems().add( problem );
|
||||||
|
|
||||||
|
@ -630,7 +630,7 @@ public class DefaultProjectBuilder
|
||||||
ModelProblem problem =
|
ModelProblem problem =
|
||||||
new DefaultModelProblem( "Detected profiles.xml alongside " + modelId
|
new DefaultModelProblem( "Detected profiles.xml alongside " + modelId
|
||||||
+ ", this file is no longer supported and was ignored" + ", please use the settings.xml instead",
|
+ ", this file is no longer supported and was ignored" + ", please use the settings.xml instead",
|
||||||
ModelProblem.Severity.WARNING, model, -1, -1, null );
|
ModelProblem.Severity.WARNING, ModelProblem.Version.V30, model, -1, -1, null );
|
||||||
result.getProblems().add( problem );
|
result.getProblems().add( problem );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ import org.apache.maven.model.PluginManagement;
|
||||||
import org.apache.maven.model.Profile;
|
import org.apache.maven.model.Profile;
|
||||||
import org.apache.maven.model.Repository;
|
import org.apache.maven.model.Repository;
|
||||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Version;
|
||||||
import org.apache.maven.model.composition.DependencyManagementImporter;
|
import org.apache.maven.model.composition.DependencyManagementImporter;
|
||||||
import org.apache.maven.model.inheritance.InheritanceAssembler;
|
import org.apache.maven.model.inheritance.InheritanceAssembler;
|
||||||
import org.apache.maven.model.interpolation.ModelInterpolator;
|
import org.apache.maven.model.interpolation.ModelInterpolator;
|
||||||
|
@ -322,7 +323,7 @@ public class DefaultModelBuilder
|
||||||
}
|
}
|
||||||
message += currentData.getId();
|
message += currentData.getId();
|
||||||
|
|
||||||
problems.add( ModelProblem.Severity.FATAL, message, null, null );
|
problems.add( new ModelProblemCollectorRequest(ModelProblem.Severity.FATAL, ModelProblem.Version.BASE).setMessage(message));
|
||||||
throw problems.newModelBuildingException();
|
throw problems.newModelBuildingException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -414,7 +415,7 @@ public class DefaultModelBuilder
|
||||||
|
|
||||||
modelValidator.validateEffectiveModel( resultModel, request, problems );
|
modelValidator.validateEffectiveModel( resultModel, request, problems );
|
||||||
|
|
||||||
if ( problems.hasErrors() )
|
if ( hasModelErrors(problems) )
|
||||||
{
|
{
|
||||||
throw problems.newModelBuildingException();
|
throw problems.newModelBuildingException();
|
||||||
}
|
}
|
||||||
|
@ -476,13 +477,15 @@ public class DefaultModelBuilder
|
||||||
|
|
||||||
if ( pomFile != null )
|
if ( pomFile != null )
|
||||||
{
|
{
|
||||||
problems.add( Severity.ERROR, "Malformed POM " + modelSource.getLocation() + ": " + e.getMessage(),
|
problems.add( new ModelProblemCollectorRequest(Severity.ERROR, Version.V20)
|
||||||
null, e );
|
.setMessage("Malformed POM " + modelSource.getLocation() + ": " + e.getMessage())
|
||||||
|
.setException(e ));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
problems.add( Severity.WARNING, "Malformed POM " + modelSource.getLocation() + ": "
|
problems.add( new ModelProblemCollectorRequest(Severity.WARNING, Version.V20)
|
||||||
+ e.getMessage(), null, e );
|
.setMessage("Malformed POM " + modelSource.getLocation() + ": " + e.getMessage())
|
||||||
|
.setException(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,8 +497,9 @@ public class DefaultModelBuilder
|
||||||
}
|
}
|
||||||
catch ( ModelParseException e )
|
catch ( ModelParseException e )
|
||||||
{
|
{
|
||||||
problems.add( Severity.FATAL, "Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage(),
|
problems.add( new ModelProblemCollectorRequest(Severity.FATAL, Version.BASE)
|
||||||
null, e );
|
.setMessage("Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage())
|
||||||
|
.setException(e));
|
||||||
throw problems.newModelBuildingException();
|
throw problems.newModelBuildingException();
|
||||||
}
|
}
|
||||||
catch ( IOException e )
|
catch ( IOException e )
|
||||||
|
@ -513,7 +517,9 @@ public class DefaultModelBuilder
|
||||||
msg = e.getClass().getSimpleName();
|
msg = e.getClass().getSimpleName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
problems.add( Severity.FATAL, "Non-readable POM " + modelSource.getLocation() + ": " + msg, null, e );
|
problems.add( new ModelProblemCollectorRequest(Severity.FATAL, Version.BASE)
|
||||||
|
.setMessage("Non-readable POM " + modelSource.getLocation() + ": " + msg)
|
||||||
|
.setException(e ));
|
||||||
throw problems.newModelBuildingException();
|
throw problems.newModelBuildingException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -522,7 +528,7 @@ public class DefaultModelBuilder
|
||||||
problems.setSource( model );
|
problems.setSource( model );
|
||||||
modelValidator.validateRawModel( model, request, problems );
|
modelValidator.validateRawModel( model, request, problems );
|
||||||
|
|
||||||
if ( problems.hasFatalErrors() )
|
if ( hasFatalErrors(problems) )
|
||||||
{
|
{
|
||||||
throw problems.newModelBuildingException();
|
throw problems.newModelBuildingException();
|
||||||
}
|
}
|
||||||
|
@ -562,8 +568,10 @@ public class DefaultModelBuilder
|
||||||
}
|
}
|
||||||
catch ( InvalidRepositoryException e )
|
catch ( InvalidRepositoryException e )
|
||||||
{
|
{
|
||||||
problems.add( Severity.ERROR, "Invalid repository " + repository.getId() + ": " + e.getMessage(),
|
problems.add( new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
|
||||||
repository.getLocation( "" ), e );
|
.setMessage( "Invalid repository " + repository.getId() + ": " + e.getMessage())
|
||||||
|
.setLocation(repository.getLocation( "" ))
|
||||||
|
.setException(e) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -615,8 +623,9 @@ public class DefaultModelBuilder
|
||||||
if ( versions.get( key ) == null && managedVersions.get( key ) == null )
|
if ( versions.get( key ) == null && managedVersions.get( key ) == null )
|
||||||
{
|
{
|
||||||
InputLocation location = plugins.get( key ).getLocation( "" );
|
InputLocation location = plugins.get( key ).getLocation( "" );
|
||||||
problems.add( Severity.WARNING, "'build.plugins.plugin.version' for " + key + " is missing.", location,
|
problems.add( new ModelProblemCollectorRequest(Severity.WARNING, Version.V20)
|
||||||
null );
|
.setMessage( "'build.plugins.plugin.version' for " + key + " is missing.")
|
||||||
|
.setLocation(location));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -691,9 +700,10 @@ public class DefaultModelBuilder
|
||||||
|
|
||||||
if ( !"pom".equals( parentModel.getPackaging() ) )
|
if ( !"pom".equals( parentModel.getPackaging() ) )
|
||||||
{
|
{
|
||||||
problems.add( Severity.ERROR, "Invalid packaging for parent POM "
|
problems.add( new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
|
||||||
+ ModelProblemUtils.toSourceHint( parentModel ) + ", must be \"pom\" but is \""
|
.setMessage( "Invalid packaging for parent POM " + ModelProblemUtils.toSourceHint( parentModel ) + ", must be \"pom\" but is \""
|
||||||
+ parentModel.getPackaging() + "\"", parentModel.getLocation( "packaging" ), null );
|
+ parentModel.getPackaging() + "\"")
|
||||||
|
.setLocation(parentModel.getLocation( "packaging" )));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -745,7 +755,9 @@ public class DefaultModelBuilder
|
||||||
buffer.append( ", please verify your project structure" );
|
buffer.append( ", please verify your project structure" );
|
||||||
|
|
||||||
problems.setSource( childModel );
|
problems.setSource( childModel );
|
||||||
problems.add( Severity.WARNING, buffer.toString(), parent.getLocation( "" ), null );
|
problems.add( new ModelProblemCollectorRequest( Severity.WARNING, Version.BASE)
|
||||||
|
.setMessage( buffer.toString())
|
||||||
|
.setLocation( parent.getLocation( "" )));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ( version == null || !version.equals( parent.getVersion() ) )
|
if ( version == null || !version.equals( parent.getVersion() ) )
|
||||||
|
@ -837,7 +849,10 @@ public class DefaultModelBuilder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
problems.add( Severity.FATAL, buffer.toString(), parent.getLocation( "" ), e );
|
problems.add( new ModelProblemCollectorRequest(Severity.FATAL, Version.BASE)
|
||||||
|
.setMessage( buffer.toString())
|
||||||
|
.setLocation(parent.getLocation( "" ))
|
||||||
|
.setException(e));
|
||||||
throw problems.newModelBuildingException();
|
throw problems.newModelBuildingException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -903,20 +918,23 @@ public class DefaultModelBuilder
|
||||||
|
|
||||||
if ( groupId == null || groupId.length() <= 0 )
|
if ( groupId == null || groupId.length() <= 0 )
|
||||||
{
|
{
|
||||||
problems.add( Severity.ERROR, "'dependencyManagement.dependencies.dependency.groupId' for "
|
problems.add( new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
|
||||||
+ dependency.getManagementKey() + " is missing.", dependency.getLocation( "" ), null );
|
.setMessage( "'dependencyManagement.dependencies.dependency.groupId' for " + dependency.getManagementKey() + " is missing.")
|
||||||
|
.setLocation( dependency.getLocation( "" )));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( artifactId == null || artifactId.length() <= 0 )
|
if ( artifactId == null || artifactId.length() <= 0 )
|
||||||
{
|
{
|
||||||
problems.add( Severity.ERROR, "'dependencyManagement.dependencies.dependency.artifactId' for "
|
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
|
||||||
+ dependency.getManagementKey() + " is missing.", dependency.getLocation( "" ), null );
|
.setMessage( "'dependencyManagement.dependencies.dependency.artifactId' for " + dependency.getManagementKey() + " is missing.")
|
||||||
|
.setLocation( dependency.getLocation( "" )));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( version == null || version.length() <= 0 )
|
if ( version == null || version.length() <= 0 )
|
||||||
{
|
{
|
||||||
problems.add( Severity.ERROR, "'dependencyManagement.dependencies.dependency.version' for "
|
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
|
||||||
+ dependency.getManagementKey() + " is missing.", dependency.getLocation( "" ), null );
|
.setMessage( "'dependencyManagement.dependencies.dependency.version' for " + dependency.getManagementKey() + " is missing.")
|
||||||
|
.setLocation( dependency.getLocation( "" )));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -930,7 +948,7 @@ public class DefaultModelBuilder
|
||||||
message += modelId + " -> ";
|
message += modelId + " -> ";
|
||||||
}
|
}
|
||||||
message += imported;
|
message += imported;
|
||||||
problems.add( Severity.ERROR, message, null, null );
|
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE ).setMessage( message ));
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -962,7 +980,10 @@ public class DefaultModelBuilder
|
||||||
}
|
}
|
||||||
buffer.append( ": " ).append( e.getMessage() );
|
buffer.append( ": " ).append( e.getMessage() );
|
||||||
|
|
||||||
problems.add( Severity.ERROR, buffer.toString(), dependency.getLocation( "" ), e );
|
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
|
||||||
|
.setMessage( buffer.toString() )
|
||||||
|
.setLocation( dependency.getLocation( "" ))
|
||||||
|
.setException( e ));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1061,4 +1082,25 @@ public class DefaultModelBuilder
|
||||||
&& ( version == null || message.contains( version ) );
|
&& ( version == null || message.contains( version ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean hasModelErrors(ModelProblemCollectorExt problems) {
|
||||||
|
if (problems instanceof DefaultModelProblemCollector) {
|
||||||
|
return ((DefaultModelProblemCollector)problems).hasErrors();
|
||||||
|
} else {
|
||||||
|
//the default execution path only knows the DefaultModelProblemCollector,
|
||||||
|
// only reason it's not in signature is because it's package private
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean hasFatalErrors(ModelProblemCollectorExt problems) {
|
||||||
|
if (problems instanceof DefaultModelProblemCollector) {
|
||||||
|
return ((DefaultModelProblemCollector)problems).hasFatalErrors();
|
||||||
|
} else {
|
||||||
|
//the default execution path only knows the DefaultModelProblemCollector,
|
||||||
|
// only reason it's not in signature is because it's package private
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,9 @@ public class DefaultModelProblem
|
||||||
|
|
||||||
private final Severity severity;
|
private final Severity severity;
|
||||||
|
|
||||||
|
private final Version version;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new problem with the specified message and exception.
|
* Creates a new problem with the specified message and exception.
|
||||||
*
|
*
|
||||||
|
@ -57,10 +60,11 @@ public class DefaultModelProblem
|
||||||
* @param columnNumber The one-based index of the column containing the error or {@code -1} if unknown.
|
* @param columnNumber The one-based index of the column containing the error or {@code -1} if unknown.
|
||||||
* @param exception The exception that caused this problem, may be {@code null}.
|
* @param exception The exception that caused this problem, may be {@code null}.
|
||||||
*/
|
*/
|
||||||
public DefaultModelProblem( String message, Severity severity, Model source, int lineNumber, int columnNumber,
|
//mkleint: does this need to be public?
|
||||||
|
public DefaultModelProblem( String message, Severity severity, Version version, Model source, int lineNumber, int columnNumber,
|
||||||
Exception exception )
|
Exception exception )
|
||||||
{
|
{
|
||||||
this( message, severity, ModelProblemUtils.toPath( source ), lineNumber, columnNumber,
|
this( message, severity, version, ModelProblemUtils.toPath( source ), lineNumber, columnNumber,
|
||||||
ModelProblemUtils.toId( source ), exception );
|
ModelProblemUtils.toId( source ), exception );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,13 +74,15 @@ public class DefaultModelProblem
|
||||||
* @param message The message describing the problem, may be {@code null}.
|
* @param message The message describing the problem, may be {@code null}.
|
||||||
* @param severity The severity level of the problem, may be {@code null} to default to
|
* @param severity The severity level of the problem, may be {@code null} to default to
|
||||||
* {@link ModelProblem.Severity#ERROR}.
|
* {@link ModelProblem.Severity#ERROR}.
|
||||||
|
* @param version The version since the problem is relevant
|
||||||
* @param source A hint about the source of the problem like a file path, may be {@code null}.
|
* @param source A hint about the source of the problem like a file path, may be {@code null}.
|
||||||
* @param lineNumber The one-based index of the line containing the problem or {@code -1} if unknown.
|
* @param lineNumber The one-based index of the line containing the problem or {@code -1} if unknown.
|
||||||
* @param columnNumber The one-based index of the column containing the problem or {@code -1} if unknown.
|
* @param columnNumber The one-based index of the column containing the problem or {@code -1} if unknown.
|
||||||
* @param modelId The identifier of the model that exhibits the problem, may be {@code null}.
|
* @param modelId The identifier of the model that exhibits the problem, may be {@code null}.
|
||||||
* @param exception The exception that caused this problem, may be {@code null}.
|
* @param exception The exception that caused this problem, may be {@code null}.
|
||||||
*/
|
*/
|
||||||
public DefaultModelProblem( String message, Severity severity, String source, int lineNumber, int columnNumber,
|
//mkleint: does this need to be public?
|
||||||
|
public DefaultModelProblem( String message, Severity severity, Version version, String source, int lineNumber, int columnNumber,
|
||||||
String modelId, Exception exception )
|
String modelId, Exception exception )
|
||||||
{
|
{
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
@ -86,6 +92,7 @@ public class DefaultModelProblem
|
||||||
this.columnNumber = columnNumber;
|
this.columnNumber = columnNumber;
|
||||||
this.modelId = ( modelId != null ) ? modelId : "";
|
this.modelId = ( modelId != null ) ? modelId : "";
|
||||||
this.exception = exception;
|
this.exception = exception;
|
||||||
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSource()
|
public String getSource()
|
||||||
|
@ -139,6 +146,11 @@ public class DefaultModelProblem
|
||||||
return severity;
|
return severity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Version getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.util.Set;
|
||||||
import org.apache.maven.model.InputLocation;
|
import org.apache.maven.model.InputLocation;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Version;
|
||||||
import org.apache.maven.model.io.ModelParseException;
|
import org.apache.maven.model.io.ModelParseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,7 +39,7 @@ import org.apache.maven.model.io.ModelParseException;
|
||||||
* @author Benjamin Bentmann
|
* @author Benjamin Bentmann
|
||||||
*/
|
*/
|
||||||
class DefaultModelProblemCollector
|
class DefaultModelProblemCollector
|
||||||
implements ModelProblemCollector
|
implements ModelProblemCollectorExt
|
||||||
{
|
{
|
||||||
|
|
||||||
private final ModelBuildingResult result;
|
private final ModelBuildingResult result;
|
||||||
|
@ -142,21 +143,21 @@ class DefaultModelProblemCollector
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add( Severity severity, String message, InputLocation location, Exception cause )
|
public void add( ModelProblemCollectorRequest req )
|
||||||
{
|
{
|
||||||
int line = -1;
|
int line = -1;
|
||||||
int column = -1;
|
int column = -1;
|
||||||
String source = null;
|
String source = null;
|
||||||
String modelId = null;
|
String modelId = null;
|
||||||
|
|
||||||
if ( location != null )
|
if ( req.getLocation() != null )
|
||||||
{
|
{
|
||||||
line = location.getLineNumber();
|
line = req.getLocation().getLineNumber();
|
||||||
column = location.getColumnNumber();
|
column = req.getLocation().getColumnNumber();
|
||||||
if ( location.getSource() != null )
|
if ( req.getLocation().getSource() != null )
|
||||||
{
|
{
|
||||||
modelId = location.getSource().getModelId();
|
modelId = req.getLocation().getSource().getModelId();
|
||||||
source = location.getSource().getLocation();
|
source = req.getLocation().getSource().getLocation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,14 +167,14 @@ class DefaultModelProblemCollector
|
||||||
source = getSource();
|
source = getSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( line <= 0 && column <= 0 && cause instanceof ModelParseException )
|
if ( line <= 0 && column <= 0 && req.getException() instanceof ModelParseException )
|
||||||
{
|
{
|
||||||
ModelParseException e = (ModelParseException) cause;
|
ModelParseException e = (ModelParseException) req.getException();
|
||||||
line = e.getLineNumber();
|
line = e.getLineNumber();
|
||||||
column = e.getColumnNumber();
|
column = e.getColumnNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelProblem problem = new DefaultModelProblem( message, severity, source, line, column, modelId, cause );
|
ModelProblem problem = new DefaultModelProblem( req.getMessage(), req.getSeverity(), req.getVersion(), source, line, column, modelId, req.getException() );
|
||||||
|
|
||||||
add( problem );
|
add( problem );
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,14 @@ public interface ModelProblem
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Version {
|
||||||
|
//based on ModeBuildingResult.validationLevel
|
||||||
|
BASE,
|
||||||
|
V20,
|
||||||
|
V30,
|
||||||
|
V31
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the hint about the source of the problem. While the syntax of this hint is unspecified and depends on the
|
* Gets the hint about the source of the problem. While the syntax of this hint is unspecified and depends on the
|
||||||
* creator of the problem, the general expectation is that the hint provides sufficient information to the user to
|
* creator of the problem, the general expectation is that the hint provides sufficient information to the user to
|
||||||
|
@ -99,4 +107,10 @@ public interface ModelProblem
|
||||||
*/
|
*/
|
||||||
Severity getSeverity();
|
Severity getSeverity();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the applicable maven version/validation level of this problem
|
||||||
|
* @return The version, never {@code null}.
|
||||||
|
*/
|
||||||
|
Version getVersion();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.maven.model.building;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import org.apache.maven.model.InputLocation;
|
import org.apache.maven.model.InputLocation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,11 +37,8 @@ public interface ModelProblemCollector
|
||||||
/**
|
/**
|
||||||
* Adds the specified problem.
|
* Adds the specified problem.
|
||||||
*
|
*
|
||||||
* @param severity The severity of the problem, must not be {@code null}.
|
* @param req must not be null
|
||||||
* @param message The detail message of the problem, may be {@code null}.
|
|
||||||
* @param location The location of the problem, may be {@code null}.
|
|
||||||
* @param cause The cause of the problem, may be {@code null}.
|
|
||||||
*/
|
*/
|
||||||
void add( ModelProblem.Severity severity, String message, InputLocation location, Exception cause );
|
void add( ModelProblemCollectorRequest req );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package org.apache.maven.model.building;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends the ModelproblemCollector by the capacity of returning the collected problems.
|
||||||
|
* @author Milos Kleint
|
||||||
|
*/
|
||||||
|
public interface ModelProblemCollectorExt extends ModelProblemCollector
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The collected problems.
|
||||||
|
* @return a list of model problems encountered, never {@code null}
|
||||||
|
*/
|
||||||
|
List<ModelProblem> getProblems();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012 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.
|
||||||
|
*/
|
||||||
|
package org.apache.maven.model.building;
|
||||||
|
|
||||||
|
import org.apache.maven.model.InputLocation;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to wrap request parameters to ModelProblemCollector.addProblem
|
||||||
|
*
|
||||||
|
* @author mkleint
|
||||||
|
*/
|
||||||
|
public final class ModelProblemCollectorRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
private final ModelProblem.Severity severity;
|
||||||
|
private final ModelProblem.Version version;
|
||||||
|
private Exception exception;
|
||||||
|
private String message;
|
||||||
|
private InputLocation location;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new request with mandatory parameters.
|
||||||
|
* @param severity
|
||||||
|
* @param version
|
||||||
|
*/
|
||||||
|
public ModelProblemCollectorRequest(Severity severity, Version version)
|
||||||
|
{
|
||||||
|
this.severity = severity;
|
||||||
|
this.version = version;
|
||||||
|
if (severity == null)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException("No severity declared");
|
||||||
|
}
|
||||||
|
if (version == null)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException("No version declared.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Severity getSeverity()
|
||||||
|
{
|
||||||
|
return severity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Version getVersion()
|
||||||
|
{
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Exception getException()
|
||||||
|
{
|
||||||
|
return exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModelProblemCollectorRequest setException(Exception exception)
|
||||||
|
{
|
||||||
|
this.exception = exception;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage()
|
||||||
|
{
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModelProblemCollectorRequest setMessage(String message)
|
||||||
|
{
|
||||||
|
this.message = message;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputLocation getLocation()
|
||||||
|
{
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModelProblemCollectorRequest setLocation(InputLocation location)
|
||||||
|
{
|
||||||
|
this.location = location;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -45,6 +45,9 @@ import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import org.apache.maven.model.building.ModelProblem;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Version;
|
||||||
|
import org.apache.maven.model.building.ModelProblemCollectorRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use a regular expression search to find and resolve expressions within the POM.
|
* Use a regular expression search to find and resolve expressions within the POM.
|
||||||
|
@ -241,7 +244,7 @@ public abstract class AbstractStringBasedModelInterpolator
|
||||||
}
|
}
|
||||||
catch ( InterpolationException e )
|
catch ( InterpolationException e )
|
||||||
{
|
{
|
||||||
problems.add( Severity.ERROR, e.getMessage(), null, e );
|
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE ).setMessage( e.getMessage() ).setException( e ));
|
||||||
}
|
}
|
||||||
|
|
||||||
interpolator.clearFeedback();
|
interpolator.clearFeedback();
|
||||||
|
|
|
@ -20,9 +20,12 @@ package org.apache.maven.model.interpolation;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.apache.maven.model.building.ModelProblem;
|
||||||
|
|
||||||
import org.apache.maven.model.building.ModelProblemCollector;
|
import org.apache.maven.model.building.ModelProblemCollector;
|
||||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Version;
|
||||||
|
import org.apache.maven.model.building.ModelProblemCollectorRequest;
|
||||||
import org.codehaus.plexus.interpolation.ValueSource;
|
import org.codehaus.plexus.interpolation.ValueSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,7 +65,7 @@ class ProblemDetectingValueSource
|
||||||
{
|
{
|
||||||
msg += " Please use ${" + newPrefix + expression.substring( bannedPrefix.length() ) + "} instead.";
|
msg += " Please use ${" + newPrefix + expression.substring( bannedPrefix.length() ) + "} instead.";
|
||||||
}
|
}
|
||||||
problems.add( Severity.WARNING, msg, null, null );
|
problems.add( new ModelProblemCollectorRequest( Severity.WARNING, Version.V20 ).setMessage( msg ));
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
|
|
|
@ -41,6 +41,9 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import org.apache.maven.model.building.ModelProblem;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Version;
|
||||||
|
import org.apache.maven.model.building.ModelProblemCollectorRequest;
|
||||||
|
|
||||||
@Component( role = ModelInterpolator.class )
|
@Component( role = ModelInterpolator.class )
|
||||||
public class StringSearchModelInterpolator
|
public class StringSearchModelInterpolator
|
||||||
|
@ -191,13 +194,15 @@ public class StringSearchModelInterpolator
|
||||||
}
|
}
|
||||||
catch ( IllegalArgumentException e )
|
catch ( IllegalArgumentException e )
|
||||||
{
|
{
|
||||||
problems.add( Severity.ERROR, "Failed to interpolate field3: " + field + " on class: " + cls.getName(),
|
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
|
||||||
null, e );
|
.setMessage( "Failed to interpolate field3: " + field + " on class: " + cls.getName())
|
||||||
|
.setException(e));
|
||||||
}
|
}
|
||||||
catch ( IllegalAccessException e )
|
catch ( IllegalAccessException e )
|
||||||
{
|
{
|
||||||
problems.add( Severity.ERROR, "Failed to interpolate field4: " + field + " on class: " + cls.getName(),
|
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
|
||||||
null, e );
|
.setMessage( "Failed to interpolate field4: " + field + " on class: " + cls.getName())
|
||||||
|
.setException(e));
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,8 +27,11 @@ import org.apache.maven.model.ReportPlugin;
|
||||||
import org.apache.maven.model.ReportSet;
|
import org.apache.maven.model.ReportSet;
|
||||||
import org.apache.maven.model.Reporting;
|
import org.apache.maven.model.Reporting;
|
||||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
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.ModelProblemCollector;
|
||||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Version;
|
||||||
|
import org.apache.maven.model.building.ModelProblemCollectorRequest;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||||
|
@ -105,9 +108,9 @@ public class DefaultReportingConverter
|
||||||
&& request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 )
|
&& request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 )
|
||||||
{
|
{
|
||||||
|
|
||||||
problems.add( Severity.WARNING, "The <reporting> section is deprecated"
|
problems.add( new ModelProblemCollectorRequest( Severity.WARNING, Version.V31)
|
||||||
+ ", please move the reports to the <configuration> section of the new Maven Site Plugin.",
|
.setMessage( "The <reporting> section is deprecated, please move the reports to the <configuration> section of the new Maven Site Plugin.")
|
||||||
reporting.getLocation( "" ), null );
|
.setLocation( reporting.getLocation( "" ) ));
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( ReportPlugin plugin : reporting.getPlugins() )
|
for ( ReportPlugin plugin : reporting.getPlugins() )
|
||||||
|
|
|
@ -26,8 +26,11 @@ import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.model.Activation;
|
import org.apache.maven.model.Activation;
|
||||||
import org.apache.maven.model.Profile;
|
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.ModelProblemCollector;
|
||||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Version;
|
||||||
|
import org.apache.maven.model.building.ModelProblemCollectorRequest;
|
||||||
import org.apache.maven.model.profile.activation.ProfileActivator;
|
import org.apache.maven.model.profile.activation.ProfileActivator;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
import org.codehaus.plexus.component.annotations.Requirement;
|
import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
|
@ -113,8 +116,10 @@ public class DefaultProfileSelector
|
||||||
}
|
}
|
||||||
catch ( RuntimeException e )
|
catch ( RuntimeException e )
|
||||||
{
|
{
|
||||||
problems.add( Severity.ERROR, "Failed to determine activation for profile " + profile.getId(),
|
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
|
||||||
profile.getLocation( "" ), e );
|
.setMessage( "Failed to determine activation for profile " + profile.getId())
|
||||||
|
.setLocation( profile.getLocation( "" ))
|
||||||
|
.setException( e ));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ import org.apache.maven.model.ActivationFile;
|
||||||
import org.apache.maven.model.Profile;
|
import org.apache.maven.model.Profile;
|
||||||
import org.apache.maven.model.building.ModelProblemCollector;
|
import org.apache.maven.model.building.ModelProblemCollector;
|
||||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Version;
|
||||||
|
import org.apache.maven.model.building.ModelProblemCollectorRequest;
|
||||||
import org.apache.maven.model.path.PathTranslator;
|
import org.apache.maven.model.path.PathTranslator;
|
||||||
import org.apache.maven.model.profile.ProfileActivationContext;
|
import org.apache.maven.model.profile.ProfileActivationContext;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
|
@ -125,8 +127,10 @@ public class FileProfileActivator
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
{
|
{
|
||||||
problems.add( Severity.ERROR, "Failed to interpolate file location " + path + " for profile "
|
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
|
||||||
+ profile.getId() + ": " + e.getMessage(), file.getLocation( missing ? "missing" : "exists" ), e );
|
.setMessage( "Failed to interpolate file location " + path + " for profile " + profile.getId() + ": " + e.getMessage())
|
||||||
|
.setLocation( file.getLocation( missing ? "missing" : "exists" ))
|
||||||
|
.setException( e ));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ import org.apache.maven.model.Activation;
|
||||||
import org.apache.maven.model.Profile;
|
import org.apache.maven.model.Profile;
|
||||||
import org.apache.maven.model.building.ModelProblemCollector;
|
import org.apache.maven.model.building.ModelProblemCollector;
|
||||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Version;
|
||||||
|
import org.apache.maven.model.building.ModelProblemCollectorRequest;
|
||||||
import org.apache.maven.model.profile.ProfileActivationContext;
|
import org.apache.maven.model.profile.ProfileActivationContext;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
|
|
||||||
|
@ -56,8 +58,9 @@ public class JdkVersionProfileActivator
|
||||||
|
|
||||||
if ( version == null || version.length() <= 0 )
|
if ( version == null || version.length() <= 0 )
|
||||||
{
|
{
|
||||||
problems.add( Severity.ERROR, "Failed to determine Java version for profile " + profile.getId(),
|
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
|
||||||
activation.getLocation( "jdk" ), null );
|
.setMessage( "Failed to determine Java version for profile " + profile.getId())
|
||||||
|
.setLocation(activation.getLocation( "jdk" )));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@ import org.apache.maven.model.ActivationProperty;
|
||||||
import org.apache.maven.model.Profile;
|
import org.apache.maven.model.Profile;
|
||||||
import org.apache.maven.model.building.ModelProblemCollector;
|
import org.apache.maven.model.building.ModelProblemCollector;
|
||||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Version;
|
||||||
|
import org.apache.maven.model.building.ModelProblemCollectorRequest;
|
||||||
import org.apache.maven.model.profile.ProfileActivationContext;
|
import org.apache.maven.model.profile.ProfileActivationContext;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
@ -61,8 +63,9 @@ public class PropertyProfileActivator
|
||||||
|
|
||||||
if ( name == null || name.length() <= 0 )
|
if ( name == null || name.length() <= 0 )
|
||||||
{
|
{
|
||||||
problems.add( Severity.ERROR, "The property name is required to activate the profile "
|
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
|
||||||
+ profile.getId(), property.getLocation( "" ), null );
|
.setMessage( "The property name is required to activate the profile " + profile.getId())
|
||||||
|
.setLocation( property.getLocation( "" )));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,9 @@ import org.apache.maven.model.Repository;
|
||||||
import org.apache.maven.model.Resource;
|
import org.apache.maven.model.Resource;
|
||||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||||
|
import org.apache.maven.model.building.ModelProblem.Version;
|
||||||
import org.apache.maven.model.building.ModelProblemCollector;
|
import org.apache.maven.model.building.ModelProblemCollector;
|
||||||
|
import org.apache.maven.model.building.ModelProblemCollectorRequest;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
|
||||||
|
@ -72,16 +74,16 @@ public class DefaultModelValidator
|
||||||
Parent parent = model.getParent();
|
Parent parent = model.getParent();
|
||||||
if ( parent != null )
|
if ( parent != null )
|
||||||
{
|
{
|
||||||
validateStringNotEmpty( "parent.groupId", problems, Severity.FATAL, parent.getGroupId(), parent );
|
validateStringNotEmpty( "parent.groupId", problems, Severity.FATAL, Version.BASE, parent.getGroupId(), parent );
|
||||||
|
|
||||||
validateStringNotEmpty( "parent.artifactId", problems, Severity.FATAL, parent.getArtifactId(), parent );
|
validateStringNotEmpty( "parent.artifactId", problems, Severity.FATAL, Version.BASE, parent.getArtifactId(), parent );
|
||||||
|
|
||||||
validateStringNotEmpty( "parent.version", problems, Severity.FATAL, parent.getVersion(), parent );
|
validateStringNotEmpty( "parent.version", problems, Severity.FATAL, Version.BASE, parent.getVersion(), parent );
|
||||||
|
|
||||||
if ( equals( parent.getGroupId(), model.getGroupId() )
|
if ( equals( parent.getGroupId(), model.getGroupId() )
|
||||||
&& equals( parent.getArtifactId(), model.getArtifactId() ) )
|
&& equals( parent.getArtifactId(), model.getArtifactId() ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, Severity.FATAL, "parent.artifactId", null, "must be changed"
|
addViolation( problems, Severity.FATAL, Version.BASE, "parent.artifactId", null, "must be changed"
|
||||||
+ ", the parent element cannot have the same groupId:artifactId as the project.", parent );
|
+ ", the parent element cannot have the same groupId:artifactId as the project.", parent );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,45 +92,45 @@ public class DefaultModelValidator
|
||||||
{
|
{
|
||||||
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
||||||
|
|
||||||
validateEnum( "modelVersion", problems, Severity.ERROR, model.getModelVersion(), null, model, "4.0.0" );
|
validateEnum( "modelVersion", problems, Severity.ERROR, Version.V20, model.getModelVersion(), null, model, "4.0.0" );
|
||||||
|
|
||||||
validateStringNoExpression( "groupId", problems, Severity.WARNING, model.getGroupId(), model );
|
validateStringNoExpression( "groupId", problems, Severity.WARNING, Version.V20, model.getGroupId(), model );
|
||||||
if ( parent == null )
|
if ( parent == null )
|
||||||
{
|
{
|
||||||
validateStringNotEmpty( "groupId", problems, Severity.FATAL, model.getGroupId(), model );
|
validateStringNotEmpty( "groupId", problems, Severity.FATAL, Version.V20, model.getGroupId(), model );
|
||||||
}
|
}
|
||||||
|
|
||||||
validateStringNoExpression( "artifactId", problems, Severity.WARNING, model.getArtifactId(), model );
|
validateStringNoExpression( "artifactId", problems, Severity.WARNING, Version.V20, model.getArtifactId(), model );
|
||||||
validateStringNotEmpty( "artifactId", problems, Severity.FATAL, model.getArtifactId(), model );
|
validateStringNotEmpty( "artifactId", problems, Severity.FATAL, Version.V20, model.getArtifactId(), model );
|
||||||
|
|
||||||
validateStringNoExpression( "version", problems, Severity.WARNING, model.getVersion(), model );
|
validateStringNoExpression( "version", problems, Severity.WARNING, Version.V20, model.getVersion(), model );
|
||||||
if ( parent == null )
|
if ( parent == null )
|
||||||
{
|
{
|
||||||
validateStringNotEmpty( "version", problems, Severity.FATAL, model.getVersion(), model );
|
validateStringNotEmpty( "version", problems, Severity.FATAL, Version.V20, model.getVersion(), model );
|
||||||
}
|
}
|
||||||
|
|
||||||
validateRawDependencies( problems, model.getDependencies(), "dependencies.dependency", request );
|
validate20RawDependencies( problems, model.getDependencies(), "dependencies.dependency", request );
|
||||||
|
|
||||||
if ( model.getDependencyManagement() != null )
|
if ( model.getDependencyManagement() != null )
|
||||||
{
|
{
|
||||||
validateRawDependencies( problems, model.getDependencyManagement().getDependencies(),
|
validate20RawDependencies( problems, model.getDependencyManagement().getDependencies(),
|
||||||
"dependencyManagement.dependencies.dependency", request );
|
"dependencyManagement.dependencies.dependency", request );
|
||||||
}
|
}
|
||||||
|
|
||||||
validateRepositories( problems, model.getRepositories(), "repositories.repository", request );
|
validateRawRepositories( problems, model.getRepositories(), "repositories.repository", request );
|
||||||
|
|
||||||
validateRepositories( problems, model.getPluginRepositories(), "pluginRepositories.pluginRepository",
|
validateRawRepositories( problems, model.getPluginRepositories(), "pluginRepositories.pluginRepository",
|
||||||
request );
|
request );
|
||||||
|
|
||||||
Build build = model.getBuild();
|
Build build = model.getBuild();
|
||||||
if ( build != null )
|
if ( build != null )
|
||||||
{
|
{
|
||||||
validateRawPlugins( problems, build.getPlugins(), "build.plugins.plugin", request );
|
validate20RawPlugins( problems, build.getPlugins(), "build.plugins.plugin", request );
|
||||||
|
|
||||||
PluginManagement mngt = build.getPluginManagement();
|
PluginManagement mngt = build.getPluginManagement();
|
||||||
if ( mngt != null )
|
if ( mngt != null )
|
||||||
{
|
{
|
||||||
validateRawPlugins( problems, mngt.getPlugins(), "build.pluginManagement.plugins.plugin",
|
validate20RawPlugins( problems, mngt.getPlugins(), "build.pluginManagement.plugins.plugin",
|
||||||
request );
|
request );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,34 +143,34 @@ public class DefaultModelValidator
|
||||||
|
|
||||||
if ( !profileIds.add( profile.getId() ) )
|
if ( !profileIds.add( profile.getId() ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, errOn30, "profiles.profile.id", null,
|
addViolation( problems, errOn30, Version.V20, "profiles.profile.id", null,
|
||||||
"must be unique but found duplicate profile with id " + profile.getId(), profile );
|
"must be unique but found duplicate profile with id " + profile.getId(), profile );
|
||||||
}
|
}
|
||||||
|
|
||||||
validateRawDependencies( problems, profile.getDependencies(), prefix + ".dependencies.dependency",
|
validate20RawDependencies( problems, profile.getDependencies(), prefix + ".dependencies.dependency",
|
||||||
request );
|
request );
|
||||||
|
|
||||||
if ( profile.getDependencyManagement() != null )
|
if ( profile.getDependencyManagement() != null )
|
||||||
{
|
{
|
||||||
validateRawDependencies( problems, profile.getDependencyManagement().getDependencies(), prefix
|
validate20RawDependencies( problems, profile.getDependencyManagement().getDependencies(), prefix
|
||||||
+ ".dependencyManagement.dependencies.dependency", request );
|
+ ".dependencyManagement.dependencies.dependency", request );
|
||||||
}
|
}
|
||||||
|
|
||||||
validateRepositories( problems, profile.getRepositories(), prefix + ".repositories.repository",
|
validateRawRepositories( problems, profile.getRepositories(), prefix + ".repositories.repository",
|
||||||
request );
|
request );
|
||||||
|
|
||||||
validateRepositories( problems, profile.getPluginRepositories(), prefix
|
validateRawRepositories( problems, profile.getPluginRepositories(), prefix
|
||||||
+ ".pluginRepositories.pluginRepository", request );
|
+ ".pluginRepositories.pluginRepository", request );
|
||||||
|
|
||||||
BuildBase buildBase = profile.getBuild();
|
BuildBase buildBase = profile.getBuild();
|
||||||
if ( buildBase != null )
|
if ( buildBase != null )
|
||||||
{
|
{
|
||||||
validateRawPlugins( problems, buildBase.getPlugins(), prefix + ".plugins.plugin", request );
|
validate20RawPlugins( problems, buildBase.getPlugins(), prefix + ".plugins.plugin", request );
|
||||||
|
|
||||||
PluginManagement mngt = buildBase.getPluginManagement();
|
PluginManagement mngt = buildBase.getPluginManagement();
|
||||||
if ( mngt != null )
|
if ( mngt != null )
|
||||||
{
|
{
|
||||||
validateRawPlugins( problems, mngt.getPlugins(), prefix + ".pluginManagement.plugins.plugin",
|
validate20RawPlugins( problems, mngt.getPlugins(), prefix + ".pluginManagement.plugins.plugin",
|
||||||
request );
|
request );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,7 +178,7 @@ public class DefaultModelValidator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateRawPlugins( ModelProblemCollector problems, List<Plugin> plugins, String prefix,
|
private void validate20RawPlugins( ModelProblemCollector problems, List<Plugin> plugins, String prefix,
|
||||||
ModelBuildingRequest request )
|
ModelBuildingRequest request )
|
||||||
{
|
{
|
||||||
Severity errOn31 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
|
Severity errOn31 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
|
||||||
|
@ -191,7 +193,7 @@ public class DefaultModelValidator
|
||||||
|
|
||||||
if ( existing != null )
|
if ( existing != null )
|
||||||
{
|
{
|
||||||
addViolation( problems, errOn31, prefix + ".(groupId:artifactId)", null,
|
addViolation( problems, errOn31, Version.V20, prefix + ".(groupId:artifactId)", null,
|
||||||
"must be unique but found duplicate declaration of plugin " + key, plugin );
|
"must be unique but found duplicate declaration of plugin " + key, plugin );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -205,7 +207,7 @@ public class DefaultModelValidator
|
||||||
{
|
{
|
||||||
if ( !executionIds.add( exec.getId() ) )
|
if ( !executionIds.add( exec.getId() ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, Severity.ERROR, prefix + "[" + plugin.getKey()
|
addViolation( problems, Severity.ERROR, Version.V20, prefix + "[" + plugin.getKey()
|
||||||
+ "].executions.execution.id", null, "must be unique but found duplicate execution with id "
|
+ "].executions.execution.id", null, "must be unique but found duplicate execution with id "
|
||||||
+ exec.getId(), exec );
|
+ exec.getId(), exec );
|
||||||
}
|
}
|
||||||
|
@ -215,19 +217,19 @@ public class DefaultModelValidator
|
||||||
|
|
||||||
public void validateEffectiveModel( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
|
public void validateEffectiveModel( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
|
||||||
{
|
{
|
||||||
validateStringNotEmpty( "modelVersion", problems, Severity.ERROR, model.getModelVersion(), model );
|
validateStringNotEmpty( "modelVersion", problems, Severity.ERROR, Version.BASE, model.getModelVersion(), model );
|
||||||
|
|
||||||
validateId( "groupId", problems, model.getGroupId(), model );
|
validateId( "groupId", problems, model.getGroupId(), model );
|
||||||
|
|
||||||
validateId( "artifactId", problems, model.getArtifactId(), model );
|
validateId( "artifactId", problems, model.getArtifactId(), model );
|
||||||
|
|
||||||
validateStringNotEmpty( "packaging", problems, Severity.ERROR, model.getPackaging(), model );
|
validateStringNotEmpty( "packaging", problems, Severity.ERROR, Version.BASE, model.getPackaging(), model );
|
||||||
|
|
||||||
if ( !model.getModules().isEmpty() )
|
if ( !model.getModules().isEmpty() )
|
||||||
{
|
{
|
||||||
if ( !"pom".equals( model.getPackaging() ) )
|
if ( !"pom".equals( model.getPackaging() ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, Severity.ERROR, "packaging", null, "with value '" + model.getPackaging()
|
addViolation( problems, Severity.ERROR, Version.BASE,"packaging", null, "with value '" + model.getPackaging()
|
||||||
+ "' is invalid. Aggregator projects " + "require 'pom' as packaging.", model );
|
+ "' is invalid. Aggregator projects " + "require 'pom' as packaging.", model );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,14 +238,14 @@ public class DefaultModelValidator
|
||||||
String module = model.getModules().get( i );
|
String module = model.getModules().get( i );
|
||||||
if ( StringUtils.isBlank( module ) )
|
if ( StringUtils.isBlank( module ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, Severity.WARNING, "modules.module[" + i + "]", null,
|
addViolation( problems, Severity.WARNING, Version.BASE, "modules.module[" + i + "]", null,
|
||||||
"has been specified without a path to the project directory.",
|
"has been specified without a path to the project directory.",
|
||||||
model.getLocation( "modules" ) );
|
model.getLocation( "modules" ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
validateStringNotEmpty( "version", problems, Severity.ERROR, model.getVersion(), model );
|
validateStringNotEmpty( "version", problems, Severity.ERROR, Version.BASE, model.getVersion(), model );
|
||||||
|
|
||||||
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
||||||
|
|
||||||
|
@ -263,43 +265,43 @@ public class DefaultModelValidator
|
||||||
String module = model.getModules().get( i );
|
String module = model.getModules().get( i );
|
||||||
if ( !modules.add( module ) )
|
if ( !modules.add( module ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, Severity.ERROR, "modules.module[" + i + "]", null,
|
addViolation( problems, Severity.ERROR, Version.V20, "modules.module[" + i + "]", null,
|
||||||
"specifies duplicate child module " + module, model.getLocation( "modules" ) );
|
"specifies duplicate child module " + module, model.getLocation( "modules" ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Severity errOn31 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
|
Severity errOn31 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
|
||||||
|
|
||||||
validateBannedCharacters( "version", problems, errOn31, model.getVersion(), null, model,
|
validateBannedCharacters( "version", problems, errOn31, Version.V20, model.getVersion(), null, model,
|
||||||
ILLEGAL_VERSION_CHARS );
|
ILLEGAL_VERSION_CHARS );
|
||||||
validateProperSnapshotVersion( "version", problems, errOn31, model.getVersion(), null, model );
|
validate20ProperSnapshotVersion( "version", problems, errOn31, Version.V20, model.getVersion(), null, model );
|
||||||
|
|
||||||
Build build = model.getBuild();
|
Build build = model.getBuild();
|
||||||
if ( build != null )
|
if ( build != null )
|
||||||
{
|
{
|
||||||
for ( Plugin p : build.getPlugins() )
|
for ( Plugin p : build.getPlugins() )
|
||||||
{
|
{
|
||||||
validateStringNotEmpty( "build.plugins.plugin.artifactId", problems, Severity.ERROR,
|
validateStringNotEmpty( "build.plugins.plugin.artifactId", problems, Severity.ERROR, Version.V20,
|
||||||
p.getArtifactId(), p );
|
p.getArtifactId(), p );
|
||||||
|
|
||||||
validateStringNotEmpty( "build.plugins.plugin.groupId", problems, Severity.ERROR, p.getGroupId(),
|
validateStringNotEmpty( "build.plugins.plugin.groupId", problems, Severity.ERROR, Version.V20, p.getGroupId(),
|
||||||
p );
|
p );
|
||||||
|
|
||||||
validatePluginVersion( "build.plugins.plugin.version", problems, p.getVersion(), p.getKey(), p,
|
validate20PluginVersion( "build.plugins.plugin.version", problems, p.getVersion(), p.getKey(), p,
|
||||||
request );
|
request );
|
||||||
|
|
||||||
validateBoolean( "build.plugins.plugin.inherited", problems, errOn30, p.getInherited(), p.getKey(),
|
validateBoolean( "build.plugins.plugin.inherited", problems, errOn30, Version.V20, p.getInherited(), p.getKey(),
|
||||||
p );
|
p );
|
||||||
|
|
||||||
validateBoolean( "build.plugins.plugin.extensions", problems, errOn30, p.getExtensions(),
|
validateBoolean( "build.plugins.plugin.extensions", problems, errOn30, Version.V20, p.getExtensions(),
|
||||||
p.getKey(), p );
|
p.getKey(), p );
|
||||||
|
|
||||||
validateEffectivePluginDependencies( problems, p, request );
|
validate20EffectivePluginDependencies( problems, p, request );
|
||||||
}
|
}
|
||||||
|
|
||||||
validateResources( problems, build.getResources(), "build.resources.resource", request );
|
validate20RawResources( problems, build.getResources(), "build.resources.resource", request );
|
||||||
|
|
||||||
validateResources( problems, build.getTestResources(), "build.testResources.testResource", request );
|
validate20RawResources( problems, build.getTestResources(), "build.testResources.testResource", request );
|
||||||
}
|
}
|
||||||
|
|
||||||
Reporting reporting = model.getReporting();
|
Reporting reporting = model.getReporting();
|
||||||
|
@ -307,25 +309,25 @@ public class DefaultModelValidator
|
||||||
{
|
{
|
||||||
for ( ReportPlugin p : reporting.getPlugins() )
|
for ( ReportPlugin p : reporting.getPlugins() )
|
||||||
{
|
{
|
||||||
validateStringNotEmpty( "reporting.plugins.plugin.artifactId", problems, Severity.ERROR,
|
validateStringNotEmpty( "reporting.plugins.plugin.artifactId", problems, Severity.ERROR, Version.V20,
|
||||||
p.getArtifactId(), p );
|
p.getArtifactId(), p );
|
||||||
|
|
||||||
validateStringNotEmpty( "reporting.plugins.plugin.groupId", problems, Severity.ERROR,
|
validateStringNotEmpty( "reporting.plugins.plugin.groupId", problems, Severity.ERROR, Version.V20,
|
||||||
p.getGroupId(), p );
|
p.getGroupId(), p );
|
||||||
|
|
||||||
validateStringNotEmpty( "reporting.plugins.plugin.version", problems, errOn31, p.getVersion(),
|
validateStringNotEmpty( "reporting.plugins.plugin.version", problems, errOn31, Version.V20, p.getVersion(),
|
||||||
p.getKey(), p );
|
p.getKey(), p );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( Repository repository : model.getRepositories() )
|
for ( Repository repository : model.getRepositories() )
|
||||||
{
|
{
|
||||||
validateRepository( problems, repository, "repositories.repository", request );
|
validate20EffectiveRepository( problems, repository, "repositories.repository", request );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( Repository repository : model.getPluginRepositories() )
|
for ( Repository repository : model.getPluginRepositories() )
|
||||||
{
|
{
|
||||||
validateRepository( problems, repository, "pluginRepositories.pluginRepository", request );
|
validate20EffectiveRepository( problems, repository, "pluginRepositories.pluginRepository", request );
|
||||||
}
|
}
|
||||||
|
|
||||||
DistributionManagement distMgmt = model.getDistributionManagement();
|
DistributionManagement distMgmt = model.getDistributionManagement();
|
||||||
|
@ -333,18 +335,18 @@ public class DefaultModelValidator
|
||||||
{
|
{
|
||||||
if ( distMgmt.getStatus() != null )
|
if ( distMgmt.getStatus() != null )
|
||||||
{
|
{
|
||||||
addViolation( problems, Severity.ERROR, "distributionManagement.status", null,
|
addViolation( problems, Severity.ERROR, Version.V20, "distributionManagement.status", null,
|
||||||
"must not be specified.", distMgmt );
|
"must not be specified.", distMgmt );
|
||||||
}
|
}
|
||||||
|
|
||||||
validateRepository( problems, distMgmt.getRepository(), "distributionManagement.repository", request );
|
validate20EffectiveRepository( problems, distMgmt.getRepository(), "distributionManagement.repository", request );
|
||||||
validateRepository( problems, distMgmt.getSnapshotRepository(),
|
validate20EffectiveRepository( problems, distMgmt.getSnapshotRepository(),
|
||||||
"distributionManagement.snapshotRepository", request );
|
"distributionManagement.snapshotRepository", request );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateRawDependencies( ModelProblemCollector problems, List<Dependency> dependencies, String prefix,
|
private void validate20RawDependencies( ModelProblemCollector problems, List<Dependency> dependencies, String prefix,
|
||||||
ModelBuildingRequest request )
|
ModelBuildingRequest request )
|
||||||
{
|
{
|
||||||
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
||||||
|
@ -360,12 +362,12 @@ public class DefaultModelValidator
|
||||||
{
|
{
|
||||||
if ( !"pom".equals( dependency.getType() ) )
|
if ( !"pom".equals( dependency.getType() ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, Severity.WARNING, prefix + ".type", key,
|
addViolation( problems, Severity.WARNING, Version.V20, prefix + ".type", key,
|
||||||
"must be 'pom' to import the managed dependencies.", dependency );
|
"must be 'pom' to import the managed dependencies.", dependency );
|
||||||
}
|
}
|
||||||
else if ( StringUtils.isNotEmpty( dependency.getClassifier() ) )
|
else if ( StringUtils.isNotEmpty( dependency.getClassifier() ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, errOn30, prefix + ".classifier", key,
|
addViolation( problems, errOn30, Version.V20, prefix + ".classifier", key,
|
||||||
"must be empty, imported POM cannot have a classifier.", dependency );
|
"must be empty, imported POM cannot have a classifier.", dependency );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -376,12 +378,12 @@ public class DefaultModelValidator
|
||||||
{
|
{
|
||||||
if ( !hasExpression( sysPath ) )
|
if ( !hasExpression( sysPath ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, Severity.WARNING, prefix + ".systemPath", key,
|
addViolation( problems, Severity.WARNING, Version.V20, prefix + ".systemPath", key,
|
||||||
"should use a variable instead of a hard-coded path " + sysPath, dependency );
|
"should use a variable instead of a hard-coded path " + sysPath, dependency );
|
||||||
}
|
}
|
||||||
else if ( sysPath.contains( "${basedir}" ) || sysPath.contains( "${project.basedir}" ) )
|
else if ( sysPath.contains( "${basedir}" ) || sysPath.contains( "${project.basedir}" ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, Severity.WARNING, prefix + ".systemPath", key,
|
addViolation( problems, Severity.WARNING, Version.V20, prefix + ".systemPath", key,
|
||||||
"should not point at files within the project directory, " + sysPath
|
"should not point at files within the project directory, " + sysPath
|
||||||
+ " will be unresolvable by dependent projects", dependency );
|
+ " will be unresolvable by dependent projects", dependency );
|
||||||
}
|
}
|
||||||
|
@ -406,7 +408,7 @@ public class DefaultModelValidator
|
||||||
+ StringUtils.defaultString( dependency.getVersion(), "(?)" );
|
+ StringUtils.defaultString( dependency.getVersion(), "(?)" );
|
||||||
}
|
}
|
||||||
|
|
||||||
addViolation( problems, errOn31, prefix + ".(groupId:artifactId:type:classifier)", null,
|
addViolation( problems, errOn31, Version.V20, prefix + ".(groupId:artifactId:type:classifier)", null,
|
||||||
"must be unique: " + key + " -> " + msg, dependency );
|
"must be unique: " + key + " -> " + msg, dependency );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -429,24 +431,24 @@ public class DefaultModelValidator
|
||||||
|
|
||||||
if ( request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 )
|
if ( request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 )
|
||||||
{
|
{
|
||||||
validateBoolean( prefix + "optional", problems, errOn30, d.getOptional(), d.getManagementKey(), d );
|
validateBoolean( prefix + "optional", problems, errOn30, Version.V20, d.getOptional(), d.getManagementKey(), d );
|
||||||
|
|
||||||
if ( !management )
|
if ( !management )
|
||||||
{
|
{
|
||||||
validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
|
validateVersion( prefix + "version", problems, errOn30, Version.V20, d.getVersion(), d.getManagementKey(), d );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: Extensions like Flex Mojos use custom scopes like "merged", "internal", "external", etc.
|
* 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.
|
* In order to don't break backward-compat with those, only warn but don't error out.
|
||||||
*/
|
*/
|
||||||
validateEnum( prefix + "scope", problems, Severity.WARNING, d.getScope(), d.getManagementKey(), d,
|
validateEnum( prefix + "scope", problems, Severity.WARNING, Version.V20, d.getScope(), d.getManagementKey(), d,
|
||||||
"provided", "compile", "runtime", "test", "system" );
|
"provided", "compile", "runtime", "test", "system" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateEffectivePluginDependencies( ModelProblemCollector problems, Plugin plugin,
|
private void validate20EffectivePluginDependencies( ModelProblemCollector problems, Plugin plugin,
|
||||||
ModelBuildingRequest request )
|
ModelBuildingRequest request )
|
||||||
{
|
{
|
||||||
List<Dependency> dependencies = plugin.getDependencies();
|
List<Dependency> dependencies = plugin.getDependencies();
|
||||||
|
@ -461,9 +463,9 @@ public class DefaultModelValidator
|
||||||
{
|
{
|
||||||
validateEffectiveDependency( problems, d, false, prefix, request );
|
validateEffectiveDependency( problems, d, false, prefix, request );
|
||||||
|
|
||||||
validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
|
validateVersion( prefix + "version", problems, errOn30, Version.BASE, d.getVersion(), d.getManagementKey(), d );
|
||||||
|
|
||||||
validateEnum( prefix + "scope", problems, errOn30, d.getScope(), d.getManagementKey(), d, "compile",
|
validateEnum( prefix + "scope", problems, errOn30, Version.BASE, d.getScope(), d.getManagementKey(), d, "compile",
|
||||||
"runtime", "system" );
|
"runtime", "system" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -472,15 +474,15 @@ public class DefaultModelValidator
|
||||||
private void validateEffectiveDependency( ModelProblemCollector problems, Dependency d, boolean management,
|
private void validateEffectiveDependency( ModelProblemCollector problems, Dependency d, boolean management,
|
||||||
String prefix, ModelBuildingRequest request )
|
String prefix, ModelBuildingRequest request )
|
||||||
{
|
{
|
||||||
validateId( prefix + "artifactId", problems, Severity.ERROR, d.getArtifactId(), d.getManagementKey(), d );
|
validateId( prefix + "artifactId", problems, Severity.ERROR, Version.BASE, d.getArtifactId(), d.getManagementKey(), d );
|
||||||
|
|
||||||
validateId( prefix + "groupId", problems, Severity.ERROR, d.getGroupId(), d.getManagementKey(), d );
|
validateId( prefix + "groupId", problems, Severity.ERROR, Version.BASE, d.getGroupId(), d.getManagementKey(), d );
|
||||||
|
|
||||||
if ( !management )
|
if ( !management )
|
||||||
{
|
{
|
||||||
validateStringNotEmpty( prefix + "type", problems, Severity.ERROR, d.getType(), d.getManagementKey(), d );
|
validateStringNotEmpty( prefix + "type", problems, Severity.ERROR, Version.BASE, d.getType(), d.getManagementKey(), d );
|
||||||
|
|
||||||
validateStringNotEmpty( prefix + "version", problems, Severity.ERROR, d.getVersion(), d.getManagementKey(),
|
validateStringNotEmpty( prefix + "version", problems, Severity.ERROR, Version.BASE, d.getVersion(), d.getManagementKey(),
|
||||||
d );
|
d );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,7 +492,7 @@ public class DefaultModelValidator
|
||||||
|
|
||||||
if ( StringUtils.isEmpty( systemPath ) )
|
if ( StringUtils.isEmpty( systemPath ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, Severity.ERROR, prefix + "systemPath", d.getManagementKey(), "is missing.",
|
addViolation( problems, Severity.ERROR, Version.BASE, prefix + "systemPath", d.getManagementKey(), "is missing.",
|
||||||
d );
|
d );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -498,7 +500,7 @@ public class DefaultModelValidator
|
||||||
File sysFile = new File( systemPath );
|
File sysFile = new File( systemPath );
|
||||||
if ( !sysFile.isAbsolute() )
|
if ( !sysFile.isAbsolute() )
|
||||||
{
|
{
|
||||||
addViolation( problems, Severity.ERROR, prefix + "systemPath", d.getManagementKey(),
|
addViolation( problems, Severity.ERROR, Version.BASE, prefix + "systemPath", d.getManagementKey(),
|
||||||
"must specify an absolute path but is " + systemPath, d );
|
"must specify an absolute path but is " + systemPath, d );
|
||||||
}
|
}
|
||||||
else if ( !sysFile.isFile() )
|
else if ( !sysFile.isFile() )
|
||||||
|
@ -511,13 +513,13 @@ public class DefaultModelValidator
|
||||||
{
|
{
|
||||||
msg += ". Please verify that you run Maven using a JDK and not just a JRE.";
|
msg += ". Please verify that you run Maven using a JDK and not just a JRE.";
|
||||||
}
|
}
|
||||||
addViolation( problems, Severity.WARNING, prefix + "systemPath", d.getManagementKey(), msg, d );
|
addViolation( problems, Severity.WARNING, Version.BASE, prefix + "systemPath", d.getManagementKey(), msg, d );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( StringUtils.isNotEmpty( d.getSystemPath() ) )
|
else if ( StringUtils.isNotEmpty( d.getSystemPath() ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, Severity.ERROR, prefix + "systemPath", d.getManagementKey(), "must be omitted."
|
addViolation( problems, Severity.ERROR, Version.BASE, prefix + "systemPath", d.getManagementKey(), "must be omitted."
|
||||||
+ " This field may only be specified for a dependency with system scope.", d );
|
+ " This field may only be specified for a dependency with system scope.", d );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,25 +527,25 @@ public class DefaultModelValidator
|
||||||
{
|
{
|
||||||
for ( Exclusion exclusion : d.getExclusions() )
|
for ( Exclusion exclusion : d.getExclusions() )
|
||||||
{
|
{
|
||||||
validateId( prefix + "exclusions.exclusion.groupId", problems, Severity.WARNING,
|
validateId( prefix + "exclusions.exclusion.groupId", problems, Severity.WARNING, Version.V20,
|
||||||
exclusion.getGroupId(), d.getManagementKey(), exclusion );
|
exclusion.getGroupId(), d.getManagementKey(), exclusion );
|
||||||
|
|
||||||
validateId( prefix + "exclusions.exclusion.artifactId", problems, Severity.WARNING,
|
validateId( prefix + "exclusions.exclusion.artifactId", problems, Severity.WARNING, Version.V20,
|
||||||
exclusion.getArtifactId(), d.getManagementKey(), exclusion );
|
exclusion.getArtifactId(), d.getManagementKey(), exclusion );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateRepositories( ModelProblemCollector problems, List<Repository> repositories, String prefix,
|
private void validateRawRepositories( ModelProblemCollector problems, List<Repository> repositories, String prefix,
|
||||||
ModelBuildingRequest request )
|
ModelBuildingRequest request )
|
||||||
{
|
{
|
||||||
Map<String, Repository> index = new HashMap<String, Repository>();
|
Map<String, Repository> index = new HashMap<String, Repository>();
|
||||||
|
|
||||||
for ( Repository repository : repositories )
|
for ( Repository repository : repositories )
|
||||||
{
|
{
|
||||||
validateStringNotEmpty( prefix + ".id", problems, Severity.ERROR, repository.getId(), repository );
|
validateStringNotEmpty( prefix + ".id", problems, Severity.ERROR, Version.V20, repository.getId(), repository );
|
||||||
|
|
||||||
validateStringNotEmpty( prefix + "[" + repository.getId() + "].url", problems, Severity.ERROR,
|
validateStringNotEmpty( prefix + "[" + repository.getId() + "].url", problems, Severity.ERROR, Version.V20,
|
||||||
repository.getUrl(), repository );
|
repository.getUrl(), repository );
|
||||||
|
|
||||||
String key = repository.getId();
|
String key = repository.getId();
|
||||||
|
@ -554,7 +556,7 @@ public class DefaultModelValidator
|
||||||
{
|
{
|
||||||
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
||||||
|
|
||||||
addViolation( problems, errOn30, prefix + ".id", null, "must be unique: " + repository.getId() + " -> "
|
addViolation( problems, errOn30, Version.V20, prefix + ".id", null, "must be unique: " + repository.getId() + " -> "
|
||||||
+ existing.getUrl() + " vs " + repository.getUrl(), repository );
|
+ existing.getUrl() + " vs " + repository.getUrl(), repository );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -564,42 +566,42 @@ public class DefaultModelValidator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateRepository( ModelProblemCollector problems, Repository repository, String prefix,
|
private void validate20EffectiveRepository( ModelProblemCollector problems, Repository repository, String prefix,
|
||||||
ModelBuildingRequest request )
|
ModelBuildingRequest request )
|
||||||
{
|
{
|
||||||
if ( repository != null )
|
if ( repository != null )
|
||||||
{
|
{
|
||||||
Severity errOn31 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
|
Severity errOn31 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
|
||||||
|
|
||||||
validateBannedCharacters( prefix + ".id", problems, errOn31, repository.getId(), null, repository,
|
validateBannedCharacters( prefix + ".id", problems, errOn31, Version.V20, repository.getId(), null, repository,
|
||||||
ILLEGAL_REPO_ID_CHARS );
|
ILLEGAL_REPO_ID_CHARS );
|
||||||
|
|
||||||
if ( "local".equals( repository.getId() ) )
|
if ( "local".equals( repository.getId() ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, errOn31, prefix + ".id", null, "must not be 'local'"
|
addViolation( problems, errOn31, Version.V20, prefix + ".id", null, "must not be 'local'"
|
||||||
+ ", this identifier is reserved for the local repository"
|
+ ", this identifier is reserved for the local repository"
|
||||||
+ ", using it for other repositories will corrupt your repository metadata.", repository );
|
+ ", using it for other repositories will corrupt your repository metadata.", repository );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( "legacy".equals( repository.getLayout() ) )
|
if ( "legacy".equals( repository.getLayout() ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, Severity.WARNING, prefix + ".layout", repository.getId(),
|
addViolation( problems, Severity.WARNING, Version.V20, prefix + ".layout", repository.getId(),
|
||||||
"uses the unsupported value 'legacy', artifact resolution might fail.", repository );
|
"uses the unsupported value 'legacy', artifact resolution might fail.", repository );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateResources( ModelProblemCollector problems, List<Resource> resources, String prefix,
|
private void validate20RawResources( ModelProblemCollector problems, List<Resource> resources, String prefix,
|
||||||
ModelBuildingRequest request )
|
ModelBuildingRequest request )
|
||||||
{
|
{
|
||||||
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
||||||
|
|
||||||
for ( Resource resource : resources )
|
for ( Resource resource : resources )
|
||||||
{
|
{
|
||||||
validateStringNotEmpty( prefix + ".directory", problems, Severity.ERROR, resource.getDirectory(),
|
validateStringNotEmpty( prefix + ".directory", problems, Severity.ERROR, Version.V20, resource.getDirectory(),
|
||||||
resource );
|
resource );
|
||||||
|
|
||||||
validateBoolean( prefix + ".filtering", problems, errOn30, resource.getFiltering(),
|
validateBoolean( prefix + ".filtering", problems, errOn30, Version.V20, resource.getFiltering(),
|
||||||
resource.getDirectory(), resource );
|
resource.getDirectory(), resource );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -611,13 +613,13 @@ public class DefaultModelValidator
|
||||||
private boolean validateId( String fieldName, ModelProblemCollector problems, String id,
|
private boolean validateId( String fieldName, ModelProblemCollector problems, String id,
|
||||||
InputLocationTracker tracker )
|
InputLocationTracker tracker )
|
||||||
{
|
{
|
||||||
return validateId( fieldName, problems, Severity.ERROR, id, null, tracker );
|
return validateId( fieldName, problems, Severity.ERROR, Version.BASE, id, null, tracker );
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateId( String fieldName, ModelProblemCollector problems, Severity severity, String id,
|
private boolean validateId( String fieldName, ModelProblemCollector problems, Severity severity, Version version, String id,
|
||||||
String sourceHint, InputLocationTracker tracker )
|
String sourceHint, InputLocationTracker tracker )
|
||||||
{
|
{
|
||||||
if ( !validateStringNotEmpty( fieldName, problems, severity, id, sourceHint, tracker ) )
|
if ( !validateStringNotEmpty( fieldName, problems, severity, version, id, sourceHint, tracker ) )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -626,14 +628,14 @@ public class DefaultModelValidator
|
||||||
boolean match = id.matches( ID_REGEX );
|
boolean match = id.matches( ID_REGEX );
|
||||||
if ( !match )
|
if ( !match )
|
||||||
{
|
{
|
||||||
addViolation( problems, severity, fieldName, sourceHint, "with value '" + id
|
addViolation( problems, severity, version, fieldName, sourceHint, "with value '" + id
|
||||||
+ "' does not match a valid id pattern.", tracker );
|
+ "' does not match a valid id pattern.", tracker );
|
||||||
}
|
}
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateStringNoExpression( String fieldName, ModelProblemCollector problems, Severity severity,
|
private boolean validateStringNoExpression( String fieldName, ModelProblemCollector problems, Severity severity, Version version,
|
||||||
String string, InputLocationTracker tracker )
|
String string, InputLocationTracker tracker )
|
||||||
{
|
{
|
||||||
if ( !hasExpression( string ) )
|
if ( !hasExpression( string ) )
|
||||||
|
@ -641,7 +643,7 @@ public class DefaultModelValidator
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
addViolation( problems, severity, fieldName, null, "contains an expression but should be a constant.",
|
addViolation( problems, severity, version, fieldName, null, "contains an expression but should be a constant.",
|
||||||
tracker );
|
tracker );
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -652,10 +654,10 @@ public class DefaultModelValidator
|
||||||
return value != null && value.contains( "${" );
|
return value != null && value.contains( "${" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateStringNotEmpty( String fieldName, ModelProblemCollector problems, Severity severity,
|
private boolean validateStringNotEmpty( String fieldName, ModelProblemCollector problems, Severity severity, Version version,
|
||||||
String string, InputLocationTracker tracker )
|
String string, InputLocationTracker tracker )
|
||||||
{
|
{
|
||||||
return validateStringNotEmpty( fieldName, problems, severity, string, null, tracker );
|
return validateStringNotEmpty( fieldName, problems, severity, version, string, null, tracker );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -666,10 +668,10 @@ public class DefaultModelValidator
|
||||||
* <li><code>string.length > 0</code>
|
* <li><code>string.length > 0</code>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
private boolean validateStringNotEmpty( String fieldName, ModelProblemCollector problems, Severity severity,
|
private boolean validateStringNotEmpty( String fieldName, ModelProblemCollector problems, Severity severity, Version version,
|
||||||
String string, String sourceHint, InputLocationTracker tracker )
|
String string, String sourceHint, InputLocationTracker tracker )
|
||||||
{
|
{
|
||||||
if ( !validateNotNull( fieldName, problems, severity, string, sourceHint, tracker ) )
|
if ( !validateNotNull( fieldName, problems, severity, version, string, sourceHint, tracker ) )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -679,7 +681,7 @@ public class DefaultModelValidator
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
addViolation( problems, severity, fieldName, sourceHint, "is missing.", tracker );
|
addViolation( problems, severity, version, fieldName, sourceHint, "is missing.", tracker );
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -691,7 +693,7 @@ public class DefaultModelValidator
|
||||||
* <li><code>string != null</code>
|
* <li><code>string != null</code>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
private boolean validateNotNull( String fieldName, ModelProblemCollector problems, Severity severity,
|
private boolean validateNotNull( String fieldName, ModelProblemCollector problems, Severity severity, Version version,
|
||||||
Object object, String sourceHint, InputLocationTracker tracker )
|
Object object, String sourceHint, InputLocationTracker tracker )
|
||||||
{
|
{
|
||||||
if ( object != null )
|
if ( object != null )
|
||||||
|
@ -699,12 +701,12 @@ public class DefaultModelValidator
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
addViolation( problems, severity, fieldName, sourceHint, "is missing.", tracker );
|
addViolation( problems, severity, version, fieldName, sourceHint, "is missing.", tracker );
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateBoolean( String fieldName, ModelProblemCollector problems, Severity severity,
|
private boolean validateBoolean( String fieldName, ModelProblemCollector problems, Severity severity, Version version,
|
||||||
String string, String sourceHint, InputLocationTracker tracker )
|
String string, String sourceHint, InputLocationTracker tracker )
|
||||||
{
|
{
|
||||||
if ( string == null || string.length() <= 0 )
|
if ( string == null || string.length() <= 0 )
|
||||||
|
@ -717,13 +719,13 @@ public class DefaultModelValidator
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
addViolation( problems, severity, fieldName, sourceHint, "must be 'true' or 'false' but is '" + string + "'.",
|
addViolation( problems, severity, version, fieldName, sourceHint, "must be 'true' or 'false' but is '" + string + "'.",
|
||||||
tracker );
|
tracker );
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateEnum( String fieldName, ModelProblemCollector problems, Severity severity, String string,
|
private boolean validateEnum( String fieldName, ModelProblemCollector problems, Severity severity, Version version, String string,
|
||||||
String sourceHint, InputLocationTracker tracker, String... validValues )
|
String sourceHint, InputLocationTracker tracker, String... validValues )
|
||||||
{
|
{
|
||||||
if ( string == null || string.length() <= 0 )
|
if ( string == null || string.length() <= 0 )
|
||||||
|
@ -738,13 +740,13 @@ public class DefaultModelValidator
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
addViolation( problems, severity, fieldName, sourceHint, "must be one of " + values + " but is '" + string
|
addViolation( problems, severity, version, fieldName, sourceHint, "must be one of " + values + " but is '" + string
|
||||||
+ "'.", tracker );
|
+ "'.", tracker );
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateBannedCharacters( String fieldName, ModelProblemCollector problems, Severity severity,
|
private boolean validateBannedCharacters( String fieldName, ModelProblemCollector problems, Severity severity, Version version,
|
||||||
String string, String sourceHint, InputLocationTracker tracker,
|
String string, String sourceHint, InputLocationTracker tracker,
|
||||||
String banned )
|
String banned )
|
||||||
{
|
{
|
||||||
|
@ -754,7 +756,7 @@ public class DefaultModelValidator
|
||||||
{
|
{
|
||||||
if ( banned.indexOf( string.charAt( i ) ) >= 0 )
|
if ( banned.indexOf( string.charAt( i ) ) >= 0 )
|
||||||
{
|
{
|
||||||
addViolation( problems, severity, fieldName, sourceHint,
|
addViolation( problems, severity, version, fieldName, sourceHint,
|
||||||
"must not contain any of these characters " + banned + " but found "
|
"must not contain any of these characters " + banned + " but found "
|
||||||
+ string.charAt( i ), tracker );
|
+ string.charAt( i ), tracker );
|
||||||
return false;
|
return false;
|
||||||
|
@ -765,7 +767,7 @@ public class DefaultModelValidator
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateVersion( String fieldName, ModelProblemCollector problems, Severity severity,
|
private boolean validateVersion( String fieldName, ModelProblemCollector problems, Severity severity, Version version,
|
||||||
String string, String sourceHint, InputLocationTracker tracker )
|
String string, String sourceHint, InputLocationTracker tracker )
|
||||||
{
|
{
|
||||||
if ( string == null || string.length() <= 0 )
|
if ( string == null || string.length() <= 0 )
|
||||||
|
@ -775,12 +777,12 @@ public class DefaultModelValidator
|
||||||
|
|
||||||
if ( hasExpression( string ) )
|
if ( hasExpression( string ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, severity, fieldName, sourceHint,
|
addViolation( problems, severity, version, fieldName, sourceHint,
|
||||||
"must be a valid version but is '" + string + "'.", tracker );
|
"must be a valid version but is '" + string + "'.", tracker );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !validateBannedCharacters( fieldName, problems, severity, string, sourceHint, tracker,
|
if ( !validateBannedCharacters( fieldName, problems, severity, version, string, sourceHint, tracker,
|
||||||
ILLEGAL_VERSION_CHARS ) )
|
ILLEGAL_VERSION_CHARS ) )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -789,7 +791,7 @@ public class DefaultModelValidator
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateProperSnapshotVersion( String fieldName, ModelProblemCollector problems, Severity severity,
|
private boolean validate20ProperSnapshotVersion( String fieldName, ModelProblemCollector problems, Severity severity, Version version,
|
||||||
String string, String sourceHint, InputLocationTracker tracker )
|
String string, String sourceHint, InputLocationTracker tracker )
|
||||||
{
|
{
|
||||||
if ( string == null || string.length() <= 0 )
|
if ( string == null || string.length() <= 0 )
|
||||||
|
@ -799,7 +801,7 @@ public class DefaultModelValidator
|
||||||
|
|
||||||
if ( string.endsWith( "SNAPSHOT" ) && !string.endsWith( "-SNAPSHOT" ) )
|
if ( string.endsWith( "SNAPSHOT" ) && !string.endsWith( "-SNAPSHOT" ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, severity, fieldName, sourceHint, "uses an unsupported snapshot version format"
|
addViolation( problems, severity, version, fieldName, sourceHint, "uses an unsupported snapshot version format"
|
||||||
+ ", should be '*-SNAPSHOT' instead.", tracker );
|
+ ", should be '*-SNAPSHOT' instead.", tracker );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -807,7 +809,7 @@ public class DefaultModelValidator
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validatePluginVersion( String fieldName, ModelProblemCollector problems, String string,
|
private boolean validate20PluginVersion( String fieldName, ModelProblemCollector problems, String string,
|
||||||
String sourceHint, InputLocationTracker tracker,
|
String sourceHint, InputLocationTracker tracker,
|
||||||
ModelBuildingRequest request )
|
ModelBuildingRequest request )
|
||||||
{
|
{
|
||||||
|
@ -819,14 +821,14 @@ public class DefaultModelValidator
|
||||||
|
|
||||||
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
|
||||||
|
|
||||||
if ( !validateVersion( fieldName, problems, errOn30, string, sourceHint, tracker ) )
|
if ( !validateVersion( fieldName, problems, errOn30, Version.V20, string, sourceHint, tracker ) )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( string.length() <= 0 || "RELEASE".equals( string ) || "LATEST".equals( string ) )
|
if ( string.length() <= 0 || "RELEASE".equals( string ) || "LATEST".equals( string ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, errOn30, fieldName, sourceHint, "must be a valid version but is '" + string + "'.",
|
addViolation( problems, errOn30, Version.V20, fieldName, sourceHint, "must be a valid version but is '" + string + "'.",
|
||||||
tracker );
|
tracker );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -834,7 +836,7 @@ public class DefaultModelValidator
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addViolation( ModelProblemCollector problems, Severity severity, String fieldName,
|
private static void addViolation( ModelProblemCollector problems, Severity severity, Version version, String fieldName,
|
||||||
String sourceHint, String message, InputLocationTracker tracker )
|
String sourceHint, String message, InputLocationTracker tracker )
|
||||||
{
|
{
|
||||||
StringBuilder buffer = new StringBuilder( 256 );
|
StringBuilder buffer = new StringBuilder( 256 );
|
||||||
|
@ -847,7 +849,7 @@ public class DefaultModelValidator
|
||||||
|
|
||||||
buffer.append( ' ' ).append( message );
|
buffer.append( ' ' ).append( message );
|
||||||
|
|
||||||
problems.add( severity, buffer.toString(), getLocation( fieldName, tracker ), null );
|
problems.add( new ModelProblemCollectorRequest( severity, version ).setMessage( buffer.toString() ).setLocation( getLocation( fieldName, tracker )));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static InputLocation getLocation( String fieldName, InputLocationTracker tracker )
|
private static InputLocation getLocation( String fieldName, InputLocationTracker tracker )
|
||||||
|
|
|
@ -22,8 +22,6 @@ package org.apache.maven.model.building;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.model.InputLocation;
|
|
||||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple model problem collector for testing the model building components.
|
* A simple model problem collector for testing the model building components.
|
||||||
|
@ -55,21 +53,20 @@ public class SimpleProblemCollector
|
||||||
return fatals;
|
return fatals;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add( Severity severity, String message, InputLocation location, Exception cause )
|
public void add( ModelProblemCollectorRequest req )
|
||||||
{
|
{
|
||||||
switch ( severity )
|
switch ( req.getSeverity() )
|
||||||
{
|
{
|
||||||
case FATAL:
|
case FATAL:
|
||||||
fatals.add( message );
|
fatals.add( req.getMessage() );
|
||||||
break;
|
break;
|
||||||
case ERROR:
|
case ERROR:
|
||||||
errors.add( message );
|
errors.add( req.getMessage() );
|
||||||
break;
|
break;
|
||||||
case WARNING:
|
case WARNING:
|
||||||
warnings.add( message );
|
warnings.add( req.getMessage() );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue