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:
Milos Kleint 2012-07-05 13:11:15 +00:00
parent 26d610db6e
commit 4fcfcb8f73
22 changed files with 447 additions and 201 deletions

View File

@ -36,11 +36,14 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
import org.codehaus.plexus.logging.Logger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.maven.model.building.ModelProblem.Version;
import org.apache.maven.model.building.ModelProblemCollectorRequest;
@Deprecated
public class DefaultProfileManager
@ -195,14 +198,13 @@ public class DefaultProfileManager
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() )

View File

@ -19,6 +19,7 @@ package org.apache.maven.project.validation;
* under the License.
*/
import java.util.List;
import org.apache.maven.model.InputLocation;
import org.apache.maven.model.Model;
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.ModelProblemCollector;
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.Requirement;
@ -66,14 +69,12 @@ public class DefaultModelValidator
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() );
}
}
}
}

View File

@ -37,6 +37,8 @@ import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblem.Version;
import org.apache.maven.model.building.ModelProblemCollectorRequest;
import org.apache.maven.model.merge.MavenModelMerger;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
@ -64,7 +66,9 @@ public class DefaultLifecycleBindingsInjector
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() )
{

View File

@ -26,6 +26,8 @@ import org.apache.maven.model.Model;
import org.apache.maven.model.building.AbstractModelBuildingListener;
import org.apache.maven.model.building.ModelBuildingEvent;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblem.Version;
import org.apache.maven.model.building.ModelProblemCollectorRequest;
import org.apache.maven.plugin.PluginResolutionException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
@ -95,7 +97,9 @@ class DefaultModelBuildingListener
}
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 );
@ -111,11 +115,15 @@ class DefaultModelBuildingListener
}
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 )
{
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 );
@ -130,7 +138,9 @@ class DefaultModelBuildingListener
}
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 );
}

View File

@ -442,7 +442,7 @@ public class DefaultProjectBuilder
{
ModelProblem problem =
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 );
noErrors = false;
@ -478,7 +478,7 @@ public class DefaultProjectBuilder
ModelProblem problem =
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 );
result.getProblems().add( problem );
@ -630,7 +630,7 @@ public class DefaultProjectBuilder
ModelProblem problem =
new DefaultModelProblem( "Detected profiles.xml alongside " + modelId
+ ", 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 );
}
}

View File

@ -42,6 +42,7 @@ import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.Profile;
import org.apache.maven.model.Repository;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblem.Version;
import org.apache.maven.model.composition.DependencyManagementImporter;
import org.apache.maven.model.inheritance.InheritanceAssembler;
import org.apache.maven.model.interpolation.ModelInterpolator;
@ -322,7 +323,7 @@ public class DefaultModelBuilder
}
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();
}
}
@ -414,7 +415,7 @@ public class DefaultModelBuilder
modelValidator.validateEffectiveModel( resultModel, request, problems );
if ( problems.hasErrors() )
if ( hasModelErrors(problems) )
{
throw problems.newModelBuildingException();
}
@ -476,13 +477,15 @@ public class DefaultModelBuilder
if ( pomFile != null )
{
problems.add( Severity.ERROR, "Malformed POM " + modelSource.getLocation() + ": " + e.getMessage(),
null, e );
problems.add( new ModelProblemCollectorRequest(Severity.ERROR, Version.V20)
.setMessage("Malformed POM " + modelSource.getLocation() + ": " + e.getMessage())
.setException(e ));
}
else
{
problems.add( Severity.WARNING, "Malformed POM " + modelSource.getLocation() + ": "
+ e.getMessage(), null, e );
problems.add( new ModelProblemCollectorRequest(Severity.WARNING, Version.V20)
.setMessage("Malformed POM " + modelSource.getLocation() + ": " + e.getMessage())
.setException(e));
}
}
@ -494,8 +497,9 @@ public class DefaultModelBuilder
}
catch ( ModelParseException e )
{
problems.add( Severity.FATAL, "Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage(),
null, e );
problems.add( new ModelProblemCollectorRequest(Severity.FATAL, Version.BASE)
.setMessage("Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage())
.setException(e));
throw problems.newModelBuildingException();
}
catch ( IOException e )
@ -513,7 +517,9 @@ public class DefaultModelBuilder
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();
}
@ -522,7 +528,7 @@ public class DefaultModelBuilder
problems.setSource( model );
modelValidator.validateRawModel( model, request, problems );
if ( problems.hasFatalErrors() )
if ( hasFatalErrors(problems) )
{
throw problems.newModelBuildingException();
}
@ -562,8 +568,10 @@ public class DefaultModelBuilder
}
catch ( InvalidRepositoryException e )
{
problems.add( Severity.ERROR, "Invalid repository " + repository.getId() + ": " + e.getMessage(),
repository.getLocation( "" ), e );
problems.add( new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
.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 )
{
InputLocation location = plugins.get( key ).getLocation( "" );
problems.add( Severity.WARNING, "'build.plugins.plugin.version' for " + key + " is missing.", location,
null );
problems.add( new ModelProblemCollectorRequest(Severity.WARNING, Version.V20)
.setMessage( "'build.plugins.plugin.version' for " + key + " is missing.")
.setLocation(location));
}
}
}
@ -691,9 +700,10 @@ public class DefaultModelBuilder
if ( !"pom".equals( parentModel.getPackaging() ) )
{
problems.add( Severity.ERROR, "Invalid packaging for parent POM "
+ ModelProblemUtils.toSourceHint( parentModel ) + ", must be \"pom\" but is \""
+ parentModel.getPackaging() + "\"", parentModel.getLocation( "packaging" ), null );
problems.add( new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
.setMessage( "Invalid packaging for parent POM " + ModelProblemUtils.toSourceHint( parentModel ) + ", must be \"pom\" but is \""
+ parentModel.getPackaging() + "\"")
.setLocation(parentModel.getLocation( "packaging" )));
}
}
else
@ -745,7 +755,9 @@ public class DefaultModelBuilder
buffer.append( ", please verify your project structure" );
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;
}
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();
}
@ -903,20 +918,23 @@ public class DefaultModelBuilder
if ( groupId == null || groupId.length() <= 0 )
{
problems.add( Severity.ERROR, "'dependencyManagement.dependencies.dependency.groupId' for "
+ dependency.getManagementKey() + " is missing.", dependency.getLocation( "" ), null );
problems.add( new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
.setMessage( "'dependencyManagement.dependencies.dependency.groupId' for " + dependency.getManagementKey() + " is missing.")
.setLocation( dependency.getLocation( "" )));
continue;
}
if ( artifactId == null || artifactId.length() <= 0 )
{
problems.add( Severity.ERROR, "'dependencyManagement.dependencies.dependency.artifactId' for "
+ dependency.getManagementKey() + " is missing.", dependency.getLocation( "" ), null );
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
.setMessage( "'dependencyManagement.dependencies.dependency.artifactId' for " + dependency.getManagementKey() + " is missing.")
.setLocation( dependency.getLocation( "" )));
continue;
}
if ( version == null || version.length() <= 0 )
{
problems.add( Severity.ERROR, "'dependencyManagement.dependencies.dependency.version' for "
+ dependency.getManagementKey() + " is missing.", dependency.getLocation( "" ), null );
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
.setMessage( "'dependencyManagement.dependencies.dependency.version' for " + dependency.getManagementKey() + " is missing.")
.setLocation( dependency.getLocation( "" )));
continue;
}
@ -930,7 +948,7 @@ public class DefaultModelBuilder
message += modelId + " -> ";
}
message += imported;
problems.add( Severity.ERROR, message, null, null );
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE ).setMessage( message ));
continue;
}
@ -962,7 +980,10 @@ public class DefaultModelBuilder
}
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;
}
@ -1061,4 +1082,25 @@ public class DefaultModelBuilder
&& ( 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();
}
}
}

View File

@ -46,6 +46,9 @@ public class DefaultModelProblem
private final Severity severity;
private final Version version;
/**
* 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 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 )
{
this( message, severity, ModelProblemUtils.toPath( source ), lineNumber, columnNumber,
this( message, severity, version, ModelProblemUtils.toPath( source ), lineNumber, columnNumber,
ModelProblemUtils.toId( source ), exception );
}
@ -70,13 +74,15 @@ public class DefaultModelProblem
* @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
* {@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 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 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}.
*/
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 )
{
this.message = message;
@ -86,6 +92,7 @@ public class DefaultModelProblem
this.columnNumber = columnNumber;
this.modelId = ( modelId != null ) ? modelId : "";
this.exception = exception;
this.version = version;
}
public String getSource()
@ -139,6 +146,11 @@ public class DefaultModelProblem
return severity;
}
public Version getVersion() {
return version;
}
@Override
public String toString()
{

View File

@ -26,6 +26,7 @@ import java.util.Set;
import org.apache.maven.model.InputLocation;
import org.apache.maven.model.Model;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblem.Version;
import org.apache.maven.model.io.ModelParseException;
/**
@ -38,7 +39,7 @@ import org.apache.maven.model.io.ModelParseException;
* @author Benjamin Bentmann
*/
class DefaultModelProblemCollector
implements ModelProblemCollector
implements ModelProblemCollectorExt
{
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 column = -1;
String source = null;
String modelId = null;
if ( location != null )
if ( req.getLocation() != null )
{
line = location.getLineNumber();
column = location.getColumnNumber();
if ( location.getSource() != null )
line = req.getLocation().getLineNumber();
column = req.getLocation().getColumnNumber();
if ( req.getLocation().getSource() != null )
{
modelId = location.getSource().getModelId();
source = location.getSource().getLocation();
modelId = req.getLocation().getSource().getModelId();
source = req.getLocation().getSource().getLocation();
}
}
@ -166,14 +167,14 @@ class DefaultModelProblemCollector
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();
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 );
}

View File

@ -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
* 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();
/**
* Gets the applicable maven version/validation level of this problem
* @return The version, never {@code null}.
*/
Version getVersion();
}

View File

@ -19,6 +19,7 @@ package org.apache.maven.model.building;
* under the License.
*/
import java.util.List;
import org.apache.maven.model.InputLocation;
/**
@ -36,11 +37,8 @@ public interface ModelProblemCollector
/**
* Adds the specified problem.
*
* @param severity The severity of the problem, must not be {@code null}.
* @param message The detail message of the problem, may be {@code null}.
* @param location The location of the problem, may be {@code null}.
* @param cause The cause of the problem, may be {@code null}.
* @param req must not be null
*/
void add( ModelProblem.Severity severity, String message, InputLocation location, Exception cause );
void add( ModelProblemCollectorRequest req );
}

View File

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

View File

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

View File

@ -45,6 +45,9 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.List;
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.
@ -241,7 +244,7 @@ public abstract class AbstractStringBasedModelInterpolator
}
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();

View File

@ -20,9 +20,12 @@ package org.apache.maven.model.interpolation;
*/
import java.util.List;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblem.Version;
import org.apache.maven.model.building.ModelProblemCollectorRequest;
import org.codehaus.plexus.interpolation.ValueSource;
/**
@ -62,7 +65,7 @@ class ProblemDetectingValueSource
{
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;

View File

@ -41,6 +41,9 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
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 )
public class StringSearchModelInterpolator
@ -191,13 +194,15 @@ public class StringSearchModelInterpolator
}
catch ( IllegalArgumentException e )
{
problems.add( Severity.ERROR, "Failed to interpolate field3: " + field + " on class: " + cls.getName(),
null, e );
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
.setMessage( "Failed to interpolate field3: " + field + " on class: " + cls.getName())
.setException(e));
}
catch ( IllegalAccessException e )
{
problems.add( Severity.ERROR, "Failed to interpolate field4: " + field + " on class: " + cls.getName(),
null, e );
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
.setMessage( "Failed to interpolate field4: " + field + " on class: " + cls.getName())
.setException(e));
}
finally
{

View File

@ -27,8 +27,11 @@ import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.ReportSet;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.building.ModelProblemCollector;
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.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
@ -105,9 +108,9 @@ public class DefaultReportingConverter
&& request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 )
{
problems.add( Severity.WARNING, "The <reporting> section is deprecated"
+ ", please move the reports to the <configuration> section of the new Maven Site Plugin.",
reporting.getLocation( "" ), null );
problems.add( new ModelProblemCollectorRequest( Severity.WARNING, Version.V31)
.setMessage( "The <reporting> section is deprecated, please move the reports to the <configuration> section of the new Maven Site Plugin.")
.setLocation( reporting.getLocation( "" ) ));
}
for ( ReportPlugin plugin : reporting.getPlugins() )

View File

@ -26,8 +26,11 @@ import java.util.List;
import org.apache.maven.model.Activation;
import org.apache.maven.model.Profile;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblem.Version;
import org.apache.maven.model.building.ModelProblemCollectorRequest;
import org.apache.maven.model.profile.activation.ProfileActivator;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
@ -113,8 +116,10 @@ public class DefaultProfileSelector
}
catch ( RuntimeException e )
{
problems.add( Severity.ERROR, "Failed to determine activation for profile " + profile.getId(),
profile.getLocation( "" ), e );
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
.setMessage( "Failed to determine activation for profile " + profile.getId())
.setLocation( profile.getLocation( "" ))
.setException( e ));
return false;
}
}

View File

@ -26,6 +26,8 @@ import org.apache.maven.model.ActivationFile;
import org.apache.maven.model.Profile;
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblem.Version;
import org.apache.maven.model.building.ModelProblemCollectorRequest;
import org.apache.maven.model.path.PathTranslator;
import org.apache.maven.model.profile.ProfileActivationContext;
import org.codehaus.plexus.component.annotations.Component;
@ -125,8 +127,10 @@ public class FileProfileActivator
}
catch ( Exception e )
{
problems.add( Severity.ERROR, "Failed to interpolate file location " + path + " for profile "
+ profile.getId() + ": " + e.getMessage(), file.getLocation( missing ? "missing" : "exists" ), e );
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
.setMessage( "Failed to interpolate file location " + path + " for profile " + profile.getId() + ": " + e.getMessage())
.setLocation( file.getLocation( missing ? "missing" : "exists" ))
.setException( e ));
return false;
}

View File

@ -27,6 +27,8 @@ import org.apache.maven.model.Activation;
import org.apache.maven.model.Profile;
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblem.Version;
import org.apache.maven.model.building.ModelProblemCollectorRequest;
import org.apache.maven.model.profile.ProfileActivationContext;
import org.codehaus.plexus.component.annotations.Component;
@ -56,8 +58,9 @@ public class JdkVersionProfileActivator
if ( version == null || version.length() <= 0 )
{
problems.add( Severity.ERROR, "Failed to determine Java version for profile " + profile.getId(),
activation.getLocation( "jdk" ), null );
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
.setMessage( "Failed to determine Java version for profile " + profile.getId())
.setLocation(activation.getLocation( "jdk" )));
return false;
}

View File

@ -24,6 +24,8 @@ import org.apache.maven.model.ActivationProperty;
import org.apache.maven.model.Profile;
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblem.Version;
import org.apache.maven.model.building.ModelProblemCollectorRequest;
import org.apache.maven.model.profile.ProfileActivationContext;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.util.StringUtils;
@ -61,8 +63,9 @@ public class PropertyProfileActivator
if ( name == null || name.length() <= 0 )
{
problems.add( Severity.ERROR, "The property name is required to activate the profile "
+ profile.getId(), property.getLocation( "" ), null );
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE)
.setMessage( "The property name is required to activate the profile " + profile.getId())
.setLocation( property.getLocation( "" )));
return false;
}

View File

@ -47,7 +47,9 @@ import org.apache.maven.model.Repository;
import org.apache.maven.model.Resource;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblem.Version;
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.util.StringUtils;
@ -72,16 +74,16 @@ public class DefaultModelValidator
Parent parent = model.getParent();
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() )
&& 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 );
}
}
@ -90,45 +92,45 @@ public class DefaultModelValidator
{
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 )
{
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 );
validateStringNotEmpty( "artifactId", problems, Severity.FATAL, model.getArtifactId(), model );
validateStringNoExpression( "artifactId", problems, Severity.WARNING, Version.V20, 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 )
{
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 )
{
validateRawDependencies( problems, model.getDependencyManagement().getDependencies(),
validate20RawDependencies( problems, model.getDependencyManagement().getDependencies(),
"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 );
Build build = model.getBuild();
if ( build != null )
{
validateRawPlugins( problems, build.getPlugins(), "build.plugins.plugin", request );
validate20RawPlugins( problems, build.getPlugins(), "build.plugins.plugin", request );
PluginManagement mngt = build.getPluginManagement();
if ( mngt != null )
{
validateRawPlugins( problems, mngt.getPlugins(), "build.pluginManagement.plugins.plugin",
validate20RawPlugins( problems, mngt.getPlugins(), "build.pluginManagement.plugins.plugin",
request );
}
}
@ -141,34 +143,34 @@ public class DefaultModelValidator
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 );
}
validateRawDependencies( problems, profile.getDependencies(), prefix + ".dependencies.dependency",
validate20RawDependencies( problems, profile.getDependencies(), prefix + ".dependencies.dependency",
request );
if ( profile.getDependencyManagement() != null )
{
validateRawDependencies( problems, profile.getDependencyManagement().getDependencies(), prefix
validate20RawDependencies( problems, profile.getDependencyManagement().getDependencies(), prefix
+ ".dependencyManagement.dependencies.dependency", request );
}
validateRepositories( problems, profile.getRepositories(), prefix + ".repositories.repository",
validateRawRepositories( problems, profile.getRepositories(), prefix + ".repositories.repository",
request );
validateRepositories( problems, profile.getPluginRepositories(), prefix
validateRawRepositories( problems, profile.getPluginRepositories(), prefix
+ ".pluginRepositories.pluginRepository", request );
BuildBase buildBase = profile.getBuild();
if ( buildBase != null )
{
validateRawPlugins( problems, buildBase.getPlugins(), prefix + ".plugins.plugin", request );
validate20RawPlugins( problems, buildBase.getPlugins(), prefix + ".plugins.plugin", request );
PluginManagement mngt = buildBase.getPluginManagement();
if ( mngt != null )
{
validateRawPlugins( problems, mngt.getPlugins(), prefix + ".pluginManagement.plugins.plugin",
validate20RawPlugins( problems, mngt.getPlugins(), prefix + ".pluginManagement.plugins.plugin",
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 )
{
Severity errOn31 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
@ -191,7 +193,7 @@ public class DefaultModelValidator
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 );
}
else
@ -205,7 +207,7 @@ public class DefaultModelValidator
{
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 "
+ exec.getId(), exec );
}
@ -215,19 +217,19 @@ public class DefaultModelValidator
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( "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 ( !"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 );
}
@ -236,14 +238,14 @@ public class DefaultModelValidator
String module = model.getModules().get( i );
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.",
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 );
@ -263,43 +265,43 @@ public class DefaultModelValidator
String module = model.getModules().get( i );
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" ) );
}
}
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 );
validateProperSnapshotVersion( "version", problems, errOn31, model.getVersion(), null, model );
validate20ProperSnapshotVersion( "version", problems, errOn31, Version.V20, model.getVersion(), null, model );
Build build = model.getBuild();
if ( build != null )
{
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 );
validateStringNotEmpty( "build.plugins.plugin.groupId", problems, Severity.ERROR, p.getGroupId(),
validateStringNotEmpty( "build.plugins.plugin.groupId", problems, Severity.ERROR, Version.V20, p.getGroupId(),
p );
validatePluginVersion( "build.plugins.plugin.version", problems, p.getVersion(), p.getKey(), p,
validate20PluginVersion( "build.plugins.plugin.version", problems, p.getVersion(), p.getKey(), p,
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 );
validateBoolean( "build.plugins.plugin.extensions", problems, errOn30, p.getExtensions(),
validateBoolean( "build.plugins.plugin.extensions", problems, errOn30, Version.V20, p.getExtensions(),
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();
@ -307,25 +309,25 @@ public class DefaultModelValidator
{
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 );
validateStringNotEmpty( "reporting.plugins.plugin.groupId", problems, Severity.ERROR,
validateStringNotEmpty( "reporting.plugins.plugin.groupId", problems, Severity.ERROR, Version.V20,
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 );
}
}
for ( Repository repository : model.getRepositories() )
{
validateRepository( problems, repository, "repositories.repository", request );
validate20EffectiveRepository( problems, repository, "repositories.repository", request );
}
for ( Repository repository : model.getPluginRepositories() )
{
validateRepository( problems, repository, "pluginRepositories.pluginRepository", request );
validate20EffectiveRepository( problems, repository, "pluginRepositories.pluginRepository", request );
}
DistributionManagement distMgmt = model.getDistributionManagement();
@ -333,18 +335,18 @@ public class DefaultModelValidator
{
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 );
}
validateRepository( problems, distMgmt.getRepository(), "distributionManagement.repository", request );
validateRepository( problems, distMgmt.getSnapshotRepository(),
validate20EffectiveRepository( problems, distMgmt.getRepository(), "distributionManagement.repository", request );
validate20EffectiveRepository( problems, distMgmt.getSnapshotRepository(),
"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 )
{
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
@ -360,12 +362,12 @@ public class DefaultModelValidator
{
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 );
}
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 );
}
}
@ -376,12 +378,12 @@ public class DefaultModelValidator
{
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 );
}
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
+ " will be unresolvable by dependent projects", dependency );
}
@ -406,7 +408,7 @@ public class DefaultModelValidator
+ 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 );
}
else
@ -429,24 +431,24 @@ public class DefaultModelValidator
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 )
{
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.
* 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" );
}
}
}
}
private void validateEffectivePluginDependencies( ModelProblemCollector problems, Plugin plugin,
private void validate20EffectivePluginDependencies( ModelProblemCollector problems, Plugin plugin,
ModelBuildingRequest request )
{
List<Dependency> dependencies = plugin.getDependencies();
@ -461,9 +463,9 @@ public class DefaultModelValidator
{
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" );
}
}
@ -472,15 +474,15 @@ public class DefaultModelValidator
private void validateEffectiveDependency( ModelProblemCollector problems, Dependency d, boolean management,
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 )
{
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 );
}
@ -490,7 +492,7 @@ public class DefaultModelValidator
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 );
}
else
@ -498,7 +500,7 @@ public class DefaultModelValidator
File sysFile = new File( systemPath );
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 );
}
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.";
}
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() ) )
{
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 );
}
@ -525,25 +527,25 @@ public class DefaultModelValidator
{
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 );
validateId( prefix + "exclusions.exclusion.artifactId", problems, Severity.WARNING,
validateId( prefix + "exclusions.exclusion.artifactId", problems, Severity.WARNING, Version.V20,
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 )
{
Map<String, Repository> index = new HashMap<String, Repository>();
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 );
String key = repository.getId();
@ -554,7 +556,7 @@ public class DefaultModelValidator
{
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 );
}
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 )
{
if ( repository != null )
{
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 );
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"
+ ", using it for other repositories will corrupt your repository metadata.", repository );
}
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 );
}
}
}
private void validateResources( ModelProblemCollector problems, List<Resource> resources, String prefix,
private void validate20RawResources( ModelProblemCollector problems, List<Resource> resources, String prefix,
ModelBuildingRequest request )
{
Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
for ( Resource resource : resources )
{
validateStringNotEmpty( prefix + ".directory", problems, Severity.ERROR, resource.getDirectory(),
validateStringNotEmpty( prefix + ".directory", problems, Severity.ERROR, Version.V20, resource.getDirectory(),
resource );
validateBoolean( prefix + ".filtering", problems, errOn30, resource.getFiltering(),
validateBoolean( prefix + ".filtering", problems, errOn30, Version.V20, resource.getFiltering(),
resource.getDirectory(), resource );
}
}
@ -611,13 +613,13 @@ public class DefaultModelValidator
private boolean validateId( String fieldName, ModelProblemCollector problems, String id,
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 )
{
if ( !validateStringNotEmpty( fieldName, problems, severity, id, sourceHint, tracker ) )
if ( !validateStringNotEmpty( fieldName, problems, severity, version, id, sourceHint, tracker ) )
{
return false;
}
@ -626,14 +628,14 @@ public class DefaultModelValidator
boolean match = id.matches( ID_REGEX );
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 );
}
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 )
{
if ( !hasExpression( string ) )
@ -641,7 +643,7 @@ public class DefaultModelValidator
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 );
return false;
@ -652,10 +654,10 @@ public class DefaultModelValidator
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 )
{
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>
* </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 )
{
if ( !validateNotNull( fieldName, problems, severity, string, sourceHint, tracker ) )
if ( !validateNotNull( fieldName, problems, severity, version, string, sourceHint, tracker ) )
{
return false;
}
@ -679,7 +681,7 @@ public class DefaultModelValidator
return true;
}
addViolation( problems, severity, fieldName, sourceHint, "is missing.", tracker );
addViolation( problems, severity, version, fieldName, sourceHint, "is missing.", tracker );
return false;
}
@ -691,7 +693,7 @@ public class DefaultModelValidator
* <li><code>string != null</code>
* </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 )
{
if ( object != null )
@ -699,12 +701,12 @@ public class DefaultModelValidator
return true;
}
addViolation( problems, severity, fieldName, sourceHint, "is missing.", tracker );
addViolation( problems, severity, version, fieldName, sourceHint, "is missing.", tracker );
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 )
{
if ( string == null || string.length() <= 0 )
@ -717,13 +719,13 @@ public class DefaultModelValidator
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 );
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 )
{
if ( string == null || string.length() <= 0 )
@ -738,13 +740,13 @@ public class DefaultModelValidator
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 );
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 banned )
{
@ -754,7 +756,7 @@ public class DefaultModelValidator
{
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 "
+ string.charAt( i ), tracker );
return false;
@ -765,7 +767,7 @@ public class DefaultModelValidator
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 )
{
if ( string == null || string.length() <= 0 )
@ -775,12 +777,12 @@ public class DefaultModelValidator
if ( hasExpression( string ) )
{
addViolation( problems, severity, fieldName, sourceHint,
addViolation( problems, severity, version, fieldName, sourceHint,
"must be a valid version but is '" + string + "'.", tracker );
return false;
}
if ( !validateBannedCharacters( fieldName, problems, severity, string, sourceHint, tracker,
if ( !validateBannedCharacters( fieldName, problems, severity, version, string, sourceHint, tracker,
ILLEGAL_VERSION_CHARS ) )
{
return false;
@ -789,7 +791,7 @@ public class DefaultModelValidator
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 )
{
if ( string == null || string.length() <= 0 )
@ -799,7 +801,7 @@ public class DefaultModelValidator
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 );
return false;
}
@ -807,7 +809,7 @@ public class DefaultModelValidator
return true;
}
private boolean validatePluginVersion( String fieldName, ModelProblemCollector problems, String string,
private boolean validate20PluginVersion( String fieldName, ModelProblemCollector problems, String string,
String sourceHint, InputLocationTracker tracker,
ModelBuildingRequest request )
{
@ -819,14 +821,14 @@ public class DefaultModelValidator
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;
}
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 );
return false;
}
@ -834,7 +836,7 @@ public class DefaultModelValidator
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 )
{
StringBuilder buffer = new StringBuilder( 256 );
@ -847,7 +849,7 @@ public class DefaultModelValidator
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 )

View File

@ -22,8 +22,6 @@ package org.apache.maven.model.building;
import java.util.ArrayList;
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.
@ -55,21 +53,20 @@ public class SimpleProblemCollector
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:
fatals.add( message );
fatals.add( req.getMessage() );
break;
case ERROR:
errors.add( message );
errors.add( req.getMessage() );
break;
case WARNING:
warnings.add( message );
warnings.add( req.getMessage() );
break;
}
}
}