diff --git a/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java b/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java index c6b03fed00..e8b349ee8f 100644 --- a/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java +++ b/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java @@ -20,6 +20,7 @@ package org.apache.maven.profiles; */ import org.apache.maven.model.Activation; +import org.apache.maven.model.InputLocation; import org.apache.maven.model.Profile; import org.apache.maven.model.building.ModelProblem; import org.apache.maven.model.building.ModelProblemCollector; @@ -194,7 +195,7 @@ public class DefaultProfileManager profileSelector.getActiveProfiles( profilesById.values(), context, new ModelProblemCollector() { - public void add( Severity severity, String message, Exception cause ) + public void add( Severity severity, String message, InputLocation location, Exception cause ) { if ( !ModelProblem.Severity.WARNING.equals( severity ) ) { diff --git a/maven-compat/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java b/maven-compat/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java index f31fea274e..7825808e0d 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java +++ b/maven-compat/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java @@ -19,6 +19,7 @@ package org.apache.maven.project.validation; * under the License. */ +import org.apache.maven.model.InputLocation; import org.apache.maven.model.Model; import org.apache.maven.model.building.DefaultModelBuildingRequest; import org.apache.maven.model.building.ModelBuildingRequest; @@ -66,7 +67,7 @@ public class DefaultModelValidator this.result = result; } - public void add( Severity severity, String message, Exception cause ) + public void add( Severity severity, String message, InputLocation location, Exception cause ) { if ( !ModelProblem.Severity.WARNING.equals( severity ) ) { diff --git a/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java b/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java index ec4c4dc858..cd38e43eca 100644 --- a/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java +++ b/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java @@ -64,7 +64,7 @@ public class DefaultLifecycleBindingsInjector if ( defaultPlugins == null ) { - problems.add( Severity.ERROR, "Unknown packaging: " + packaging, null ); + problems.add( Severity.ERROR, "Unknown packaging: " + packaging, model.getLocation( "packaging" ), null ); } else if ( !defaultPlugins.isEmpty() ) { diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java b/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java index f431d35067..f7d4cfea26 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java @@ -95,7 +95,7 @@ class DefaultModelBuildingListener } catch ( Exception e ) { - event.getProblems().add( Severity.ERROR, "Invalid plugin repository: " + e.getMessage(), e ); + event.getProblems().add( Severity.ERROR, "Invalid plugin repository: " + e.getMessage(), null, e ); } project.setPluginArtifactRepositories( pluginRepositories ); @@ -111,11 +111,11 @@ class DefaultModelBuildingListener } catch ( PluginResolutionException e ) { - event.getProblems().add( Severity.ERROR, "Unresolveable build extension: " + e.getMessage(), e ); + event.getProblems().add( Severity.ERROR, "Unresolveable build extension: " + e.getMessage(), null, e ); } catch ( PluginVersionResolutionException e ) { - event.getProblems().add( Severity.ERROR, "Unresolveable build extension: " + e.getMessage(), e ); + event.getProblems().add( Severity.ERROR, "Unresolveable build extension: " + e.getMessage(), null, e ); } projectBuildingHelper.selectProjectRealm( project ); @@ -130,7 +130,7 @@ class DefaultModelBuildingListener } catch ( Exception e ) { - event.getProblems().add( Severity.ERROR, "Invalid artifact repository: " + e.getMessage(), e ); + event.getProblems().add( Severity.ERROR, "Invalid artifact repository: " + e.getMessage(), null, e ); } project.setRemoteArtifactRepositories( remoteRepositories ); } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index c6b367d3e4..dc8989c5a7 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -110,6 +110,7 @@ public class DefaultProjectBuilder request.setPomFile( pomFile ); request.setModelSource( modelSource ); + request.setLocationTracking( pomFile != null ); ModelBuildingResult result; try @@ -310,6 +311,7 @@ public class DefaultProjectBuilder request.setPomFile( pomFile ); request.setTwoPhaseBuilding( true ); + request.setLocationTracking( true ); request.setModelCache( modelCache ); DefaultModelBuildingListener listener = diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index f8a78fc031..cc1d155e02 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -33,6 +33,8 @@ import java.util.Properties; import org.apache.maven.model.Build; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; +import org.apache.maven.model.InputLocation; +import org.apache.maven.model.InputSource; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; import org.apache.maven.model.Plugin; @@ -321,7 +323,7 @@ public class DefaultModelBuilder } message += currentData.getId(); - problems.add( ModelProblem.Severity.FATAL, message, null ); + problems.add( ModelProblem.Severity.FATAL, message, null, null ); throw new ModelBuildingException( problems.getRootModel(), problems.getRootModelId(), problems.getProblems() ); } @@ -448,9 +450,11 @@ public class DefaultModelBuilder try { boolean strict = request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0; + InputSource source = request.isLocationTracking() ? new InputSource() : null; Map options = new HashMap(); options.put( ModelProcessor.IS_STRICT, Boolean.valueOf( strict ) ); + options.put( ModelProcessor.INPUT_SOURCE, source ); options.put( ModelProcessor.SOURCE, modelSource ); try @@ -479,18 +483,24 @@ public class DefaultModelBuilder if ( pomFile != null ) { problems.add( Severity.ERROR, "Malformed POM " + modelSource.getLocation() + ": " + e.getMessage(), - e ); + null, e ); } else { problems.add( Severity.WARNING, "Malformed POM " + modelSource.getLocation() + ": " - + e.getMessage(), e ); + + e.getMessage(), null, e ); } } + + if ( source != null ) + { + source.setModelId( ModelProblemUtils.toId( model ) ); + source.setLocation( pomFile != null ? pomFile.getAbsolutePath() : null ); + } } catch ( ModelParseException e ) { - problems.add( Severity.FATAL, "Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage(), e ); + problems.add( Severity.FATAL, "Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage(), null, e ); throw new ModelBuildingException( problems.getRootModel(), problems.getRootModelId(), problems.getProblems() ); } @@ -509,7 +519,7 @@ public class DefaultModelBuilder msg = e.getClass().getSimpleName(); } } - problems.add( Severity.FATAL, "Non-readable POM " + modelSource.getLocation() + ": " + msg, e ); + problems.add( Severity.FATAL, "Non-readable POM " + modelSource.getLocation() + ": " + msg, null, e ); throw new ModelBuildingException( problems.getRootModel(), problems.getRootModelId(), problems.getProblems() ); } @@ -560,7 +570,8 @@ public class DefaultModelBuilder } catch ( InvalidRepositoryException e ) { - problems.add( Severity.ERROR, "Invalid repository " + repository.getId() + ": " + e.getMessage(), e ); + problems.add( Severity.ERROR, "Invalid repository " + repository.getId() + ": " + e.getMessage(), + repository.getLocation( "" ), e ); } } } @@ -573,10 +584,11 @@ public class DefaultModelBuilder return; } + Map plugins = new HashMap(); Map versions = new HashMap(); Map managedVersions = new HashMap(); - for ( int i = 0, n = lineage.size() - 1; i < n; i++ ) + for ( int i = lineage.size() - 1; i >= 0; i-- ) { Model model = lineage.get( i ).getModel(); Build build = model.getBuild(); @@ -588,6 +600,7 @@ public class DefaultModelBuilder if ( versions.get( key ) == null ) { versions.put( key, plugin.getVersion() ); + plugins.put( key, plugin ); } } PluginManagement mngt = build.getPluginManagement(); @@ -609,7 +622,9 @@ public class DefaultModelBuilder { if ( versions.get( key ) == null && managedVersions.get( key ) == null ) { - problems.add( Severity.WARNING, "'build.plugins.plugin.version' for " + key + " is missing.", null ); + InputLocation location = plugins.get( key ).getLocation( "" ); + problems.add( Severity.WARNING, "'build.plugins.plugin.version' for " + key + " is missing.", location, + null ); } } } @@ -685,7 +700,7 @@ public class DefaultModelBuilder { problems.add( Severity.ERROR, "Invalid packaging for parent POM " + ModelProblemUtils.toSourceHint( parentModel ) + ", must be \"pom\" but is \"" - + parentModel.getPackaging() + "\"", null ); + + parentModel.getPackaging() + "\"", parentModel.getLocation( "packaging" ), null ); } } else @@ -730,7 +745,7 @@ public class DefaultModelBuilder problems.add( Severity.WARNING, "'parent.relativePath' of POM " + ModelProblemUtils.toSourceHint( childModel ) + " points at " + groupId + ":" + artifactId + " instead of " + parent.getGroupId() + ":" + parent.getArtifactId() - + ", please verify your project structure", null ); + + ", please verify your project structure", childModel.getLocation( "parent" ), null ); return null; } if ( version == null || !version.equals( parent.getVersion() ) ) @@ -801,7 +816,7 @@ public class DefaultModelBuilder { problems.add( Severity.FATAL, "Non-resolvable parent POM " + ModelProblemUtils.toId( groupId, artifactId, version ) + " for " - + ModelProblemUtils.toId( childModel ) + ": " + e.getMessage(), e ); + + ModelProblemUtils.toId( childModel ) + ": " + e.getMessage(), childModel.getLocation( "parent" ), e ); throw new ModelBuildingException( problems.getRootModel(), problems.getRootModelId(), problems.getProblems() ); } @@ -877,7 +892,7 @@ public class DefaultModelBuilder message += modelId + " -> "; } message += imported; - problems.add( Severity.ERROR, message, null ); + problems.add( Severity.ERROR, message, null, null ); continue; } @@ -902,7 +917,8 @@ public class DefaultModelBuilder catch ( UnresolvableModelException e ) { problems.add( Severity.ERROR, "Non-resolvable import POM " - + ModelProblemUtils.toId( groupId, artifactId, version ) + ": " + e.getMessage(), e ); + + ModelProblemUtils.toId( groupId, artifactId, version ) + ": " + e.getMessage(), + dependency.getLocation( "" ), e ); continue; } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java index 5162771aa5..4dff1c4f73 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java @@ -47,6 +47,8 @@ public class DefaultModelBuildingRequest private boolean twoPhaseBuilding; + private boolean locationTracking; + private List profiles; private List activeProfileIds; @@ -155,6 +157,18 @@ public class DefaultModelBuildingRequest return this; } + public boolean isLocationTracking() + { + return locationTracking; + } + + public DefaultModelBuildingRequest setLocationTracking( boolean locationTracking ) + { + this.locationTracking = locationTracking; + + return this; + } + public List getProfiles() { if ( profiles == null ) diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblemCollector.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblemCollector.java index 42fc597513..2c349fad29 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblemCollector.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblemCollector.java @@ -24,6 +24,7 @@ import java.util.EnumSet; import java.util.List; 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.io.ModelParseException; @@ -139,25 +140,38 @@ class DefaultModelProblemCollector } } - public void add( Severity severity, String message, Exception cause ) + public void add( Severity severity, String message, InputLocation location, Exception cause ) { int line = -1; int column = -1; + String source = null; + String modelId = null; - if ( cause instanceof ModelParseException ) + if ( location != null ) + { + line = location.getLineNumber(); + column = location.getColumnNumber(); + if ( location.getSource() != null ) + { + modelId = location.getSource().getModelId(); + source = location.getSource().getLocation(); + } + } + + if ( modelId == null ) + { + modelId = getModelId(); + source = getSource(); + } + + if ( line <= 0 && column <= 0 && cause instanceof ModelParseException ) { ModelParseException e = (ModelParseException) cause; line = e.getLineNumber(); column = e.getColumnNumber(); } - add( severity, message, line, column, cause ); - } - - private void add( ModelProblem.Severity severity, String message, int line, int column, Exception cause ) - { - ModelProblem problem = - new DefaultModelProblem( message, severity, getSource(), line, column, getModelId(), cause ); + ModelProblem problem = new DefaultModelProblem( message, severity, source, line, column, modelId, cause ); add( problem ); } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/FilterModelBuildingRequest.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/FilterModelBuildingRequest.java index 42fcefbc93..b5c2ff3287 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/FilterModelBuildingRequest.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/FilterModelBuildingRequest.java @@ -104,6 +104,18 @@ class FilterModelBuildingRequest return this; } + public boolean isLocationTracking() + { + return request.isLocationTracking(); + } + + public FilterModelBuildingRequest setLocationTracking( boolean locationTracking ) + { + request.setLocationTracking( locationTracking ); + + return this; + } + public List getProfiles() { return request.getProfiles(); diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java index 63130078a4..ab1dba85f0 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java @@ -155,6 +155,22 @@ public interface ModelBuildingRequest */ ModelBuildingRequest setTwoPhaseBuilding( boolean twoPhaseBuilding ); + /** + * Indicates whether the model should track the line/column number of the model source from which it was parsed. + * + * @return {@code true} if location tracking is enabled, {@code false} otherwise. + */ + boolean isLocationTracking(); + + /** + * Enables/disables the tracking of line/column numbers for the model source being parsed. By default, input + * locations are not tracked. + * + * @param locationTracking {@code true} to enable location tracking, {@code false} to disable it. + * @return This request, never {@code null}. + */ + ModelBuildingRequest setLocationTracking( boolean locationTracking ); + /** * Gets the external profiles that should be considered for model building. * diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblemCollector.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblemCollector.java index 33baca239f..908449b168 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblemCollector.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblemCollector.java @@ -19,6 +19,8 @@ package org.apache.maven.model.building; * under the License. */ +import org.apache.maven.model.InputLocation; + /** * Collects problems that are encountered during model building. The primary purpose of this component is to account for * the fact that the problem reporter has/should not have information about the calling context and hence cannot provide @@ -36,8 +38,9 @@ public interface ModelProblemCollector * * @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}. */ - void add( ModelProblem.Severity severity, String message, Exception cause ); + void add( ModelProblem.Severity severity, String message, InputLocation location, Exception cause ); } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java b/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java index 892017ad72..e9421a4d7f 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java @@ -126,8 +126,7 @@ public class DefaultInheritanceAssembler { // NOTE: Enforce recursive merge to trigger merging/inheritance logic for executions Plugin plugin = new Plugin(); - plugin.setGroupId( element.getGroupId() ); - plugin.setArtifactId( element.getArtifactId() ); + plugin.setGroupId( null ); mergePlugin( plugin, element, sourceDominant, context ); Object key = getPluginKey( element ); @@ -209,8 +208,7 @@ public class DefaultInheritanceAssembler { // NOTE: Enforce recursive merge to trigger merging/inheritance logic for executions as well ReportPlugin plugin = new ReportPlugin(); - plugin.setGroupId( element.getGroupId() ); - plugin.setArtifactId( element.getArtifactId() ); + plugin.setGroupId( null ); mergeReportPlugin( plugin, element, sourceDominant, context ); merged.put( key, plugin ); diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java index 06bf2d9534..ddd247df91 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java @@ -242,7 +242,7 @@ public abstract class AbstractStringBasedModelInterpolator } catch ( InterpolationException e ) { - problems.add( Severity.ERROR, e.getMessage(), e ); + problems.add( Severity.ERROR, e.getMessage(), null, e ); } interpolator.clearFeedback(); diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/ProblemDetectingValueSource.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/ProblemDetectingValueSource.java index be5871886c..e65eecaad7 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/ProblemDetectingValueSource.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/ProblemDetectingValueSource.java @@ -62,7 +62,7 @@ class ProblemDetectingValueSource { msg += " Please use ${" + newPrefix + expression.substring( bannedPrefix.length() ) + "} instead."; } - problems.add( Severity.WARNING, msg, null ); + problems.add( Severity.WARNING, msg, null, null ); } return value; diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java index fddd0dfe96..7147dab44f 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java @@ -283,12 +283,12 @@ public class StringSearchModelInterpolator catch ( IllegalArgumentException e ) { problems.add( Severity.ERROR, "Failed to interpolate field3: " + currentField + - " on class: " + cls.getName(), e ); + " on class: " + cls.getName(), null, e ); } catch ( IllegalAccessException e ) { problems.add( Severity.ERROR, "Failed to interpolate field4: " + currentField + - " on class: " + cls.getName(), e ); + " on class: " + cls.getName(), null, e ); } finally { diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java b/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java index 3495db843f..c1c3891ce8 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java @@ -26,8 +26,10 @@ import java.io.InputStream; import java.io.Reader; import java.util.Map; +import org.apache.maven.model.InputSource; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.model.io.xpp3.MavenXpp3ReaderEx; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; @@ -68,7 +70,7 @@ public class DefaultModelReader try { - return read( input, isStrict( options ) ); + return read( input, isStrict( options ), getSource( options ) ); } finally { @@ -86,7 +88,7 @@ public class DefaultModelReader try { - return read( ReaderFactory.newXmlReader( input ), isStrict( options ) ); + return read( ReaderFactory.newXmlReader( input ), isStrict( options ), getSource( options ) ); } finally { @@ -100,13 +102,25 @@ public class DefaultModelReader return value == null || Boolean.parseBoolean( value.toString() ); } - private Model read( Reader reader, boolean strict ) + private InputSource getSource( Map options ) + { + Object value = ( options != null ) ? options.get( INPUT_SOURCE ) : null; + return (InputSource) value; + } + + private Model read( Reader reader, boolean strict, InputSource source ) throws IOException { try { - MavenXpp3Reader r = new MavenXpp3Reader(); - return r.read( reader, strict ); + if ( source != null ) + { + return new MavenXpp3ReaderEx().read( reader, strict, source ); + } + else + { + return new MavenXpp3Reader().read( reader, strict ); + } } catch ( XmlPullParserException e ) { diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelReader.java b/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelReader.java index 8a5f28cc49..75a5ebeea3 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelReader.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelReader.java @@ -34,12 +34,20 @@ import org.apache.maven.model.Model; */ public interface ModelReader { + /** * The key for the option to enable strict parsing. This option is of type {@link Boolean} and defaults to {@code * true}. If {@code false}, unknown elements will be ignored instead of causing a failure. */ String IS_STRICT = "org.apache.maven.model.io.isStrict"; + /** + * The key for the option to enable tracking of line/column numbers. This option is of type + * {@link org.apache.maven.model.InputSource} and defaults to {@code null}. Providing an input source enables + * location tracking. + */ + String INPUT_SOURCE = "org.apache.maven.model.io.inputSource"; + /** * Reads the model from the specified file. * diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/management/DefaultPluginManagementInjector.java b/maven-model-builder/src/main/java/org/apache/maven/model/management/DefaultPluginManagementInjector.java index cb45bca2dc..1d5809d9a7 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/management/DefaultPluginManagementInjector.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/management/DefaultPluginManagementInjector.java @@ -114,9 +114,7 @@ public class DefaultPluginManagementInjector for ( PluginExecution element : src ) { Object key = getPluginExecutionKey( element ); - PluginExecution clone = new PluginExecution(); - mergePluginExecution( clone, element, true, context ); - merged.put( key, clone ); + merged.put( key, element.clone() ); } for ( PluginExecution element : tgt ) diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java b/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java index 63ff03ad6c..50b7085e6e 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java @@ -34,6 +34,7 @@ import org.apache.maven.model.DeploymentRepository; import org.apache.maven.model.Developer; import org.apache.maven.model.DistributionManagement; import org.apache.maven.model.Extension; +import org.apache.maven.model.InputLocation; import org.apache.maven.model.IssueManagement; import org.apache.maven.model.License; import org.apache.maven.model.MailingList; @@ -85,6 +86,7 @@ public class MavenModelMerger if ( sourceDominant ) { target.setName( src ); + target.setLocation( "name", source.getLocation( "name" ) ); } } } @@ -98,10 +100,12 @@ public class MavenModelMerger if ( sourceDominant ) { target.setUrl( src ); + target.setLocation( "url", source.getLocation( "url" ) ); } else if ( target.getUrl() == null ) { target.setUrl( appendPath( src, context ) ); + target.setLocation( "url", source.getLocation( "url" ) ); } } } @@ -231,18 +235,27 @@ public class MavenModelMerger List src = source.getModules(); if ( !src.isEmpty() && sourceDominant ) { + List indices = new ArrayList(); List tgt = target.getModules(); Set excludes = new LinkedHashSet( tgt ); List merged = new ArrayList( tgt.size() + src.size() ); merged.addAll( tgt ); - for ( String s : src ) + for ( int i = 0, n = tgt.size(); i < n; i++ ) { + indices.add( Integer.valueOf( i ) ); + } + for ( int i = 0, n = src.size(); i < n; i++ ) + { + String s = src.get( i ); if ( !excludes.contains( s ) ) { merged.add( s ); + indices.add( Integer.valueOf( ~i ) ); } } target.setModules( merged ); + target.setLocation( "modules", InputLocation.merge( target.getLocation( "modules" ), + source.getLocation( "modules" ), indices ) ); } } @@ -398,10 +411,12 @@ public class MavenModelMerger if ( sourceDominant ) { target.setUrl( src ); + target.setLocation( "url", source.getLocation( "url" ) ); } else if ( target.getUrl() == null ) { target.setUrl( appendPath( src, context ) ); + target.setLocation( "url", source.getLocation( "url" ) ); } } } @@ -415,10 +430,12 @@ public class MavenModelMerger if ( sourceDominant ) { target.setUrl( src ); + target.setLocation( "url", source.getLocation( "url" ) ); } else if ( target.getUrl() == null ) { target.setUrl( appendPath( src, context ) ); + target.setLocation( "url", source.getLocation( "url" ) ); } } } @@ -432,10 +449,12 @@ public class MavenModelMerger if ( sourceDominant ) { target.setConnection( src ); + target.setLocation( "connection", source.getLocation( "connection" ) ); } else if ( target.getConnection() == null ) { target.setConnection( appendPath( src, context ) ); + target.setLocation( "connection", source.getLocation( "connection" ) ); } } } @@ -450,10 +469,12 @@ public class MavenModelMerger if ( sourceDominant ) { target.setDeveloperConnection( src ); + target.setLocation( "developerConnection", source.getLocation( "developerConnection" ) ); } else if ( target.getDeveloperConnection() == null ) { target.setDeveloperConnection( appendPath( src, context ) ); + target.setLocation( "developerConnection", source.getLocation( "developerConnection" ) ); } } } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/plugin/DefaultReportingConverter.java b/maven-model-builder/src/main/java/org/apache/maven/model/plugin/DefaultReportingConverter.java index c1cf2044d8..fe3031b639 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/plugin/DefaultReportingConverter.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/plugin/DefaultReportingConverter.java @@ -106,7 +106,8 @@ public class DefaultReportingConverter { problems.add( Severity.WARNING, "The section is deprecated" - + ", please move the reports to the section of the new Maven Site Plugin.", null ); + + ", please move the reports to the section of the new Maven Site Plugin.", + reporting.getLocation( "" ), null ); } for ( ReportPlugin plugin : reporting.getPlugins() ) diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java index 43f08f7855..bf3a8b6705 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java @@ -113,7 +113,8 @@ public class DefaultProfileSelector } catch ( RuntimeException e ) { - problems.add( Severity.ERROR, "Failed to determine activation for profile " + profile.getId(), e ); + problems.add( Severity.ERROR, "Failed to determine activation for profile " + profile.getId(), + profile.getLocation( "" ), e ); return false; } } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java index c1e62cc2ac..38395b5554 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java @@ -120,7 +120,7 @@ public class FileProfileActivator catch ( Exception e ) { problems.add( Severity.ERROR, "Failed to interpolate file location " + path + " for profile " - + profile.getId() + ": " + e.getMessage(), e ); + + profile.getId() + ": " + e.getMessage(), file.getLocation( missing ? "missing" : "exists" ), e ); return false; } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java index d307d04e47..cc36c95b1f 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java @@ -57,7 +57,7 @@ public class JdkVersionProfileActivator if ( version.length() <= 0 ) { problems.add( Severity.ERROR, "Failed to determine Java version for profile " + profile.getId(), - null ); + activation.getLocation( "jdk" ), null ); return false; } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java index 53746b4e53..8d64d32669 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java @@ -62,7 +62,7 @@ public class PropertyProfileActivator if ( name == null || name.length() <= 0 ) { problems.add( Severity.ERROR, "The property name is required to activate the profile " - + profile.getId(), null ); + + profile.getId(), property.getLocation( "" ), null ); return false; } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java index 9809cebd37..4291443977 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java @@ -31,6 +31,8 @@ import org.apache.maven.model.Build; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.DistributionManagement; +import org.apache.maven.model.InputLocation; +import org.apache.maven.model.InputLocationTracker; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; import org.apache.maven.model.Plugin; @@ -63,17 +65,17 @@ public class DefaultModelValidator Parent parent = model.getParent(); if ( parent != null ) { - validateStringNotEmpty( "parent.groupId", problems, Severity.FATAL, parent.getGroupId() ); + validateStringNotEmpty( "parent.groupId", problems, Severity.FATAL, parent.getGroupId(), parent ); - validateStringNotEmpty( "parent.artifactId", problems, Severity.FATAL, parent.getArtifactId() ); + validateStringNotEmpty( "parent.artifactId", problems, Severity.FATAL, parent.getArtifactId(), parent ); - validateStringNotEmpty( "parent.version", problems, Severity.FATAL, parent.getVersion() ); + validateStringNotEmpty( "parent.version", problems, Severity.FATAL, parent.getVersion(), parent ); if ( equals( parent.getGroupId(), model.getGroupId() ) && equals( parent.getArtifactId(), model.getArtifactId() ) ) { addViolation( problems, Severity.FATAL, "parent.artifactId", null, "must be changed" - + ", the parent element cannot have the same groupId:artifactId as the project." ); + + ", the parent element cannot have the same groupId:artifactId as the project.", parent ); } } @@ -81,10 +83,10 @@ public class DefaultModelValidator { Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 ); - validateEnum( "modelVersion", problems, Severity.ERROR, model.getModelVersion(), null, "4.0.0" ); - validateStringNoExpression( "groupId", problems, Severity.WARNING, model.getGroupId() ); - validateStringNoExpression( "artifactId", problems, Severity.WARNING, model.getArtifactId() ); - validateStringNoExpression( "version", problems, Severity.WARNING, model.getVersion() ); + validateEnum( "modelVersion", problems, Severity.ERROR, model.getModelVersion(), null, model, "4.0.0" ); + validateStringNoExpression( "groupId", problems, Severity.WARNING, model.getGroupId(), model ); + validateStringNoExpression( "artifactId", problems, Severity.WARNING, model.getArtifactId(), model ); + validateStringNoExpression( "version", problems, Severity.WARNING, model.getVersion(), model ); validateRawDependencies( problems, model.getDependencies(), "dependencies.dependency", request ); @@ -117,7 +119,7 @@ public class DefaultModelValidator if ( !profileIds.add( profile.getId() ) ) { addViolation( problems, errOn30, "profiles.profile.id", null, - "must be unique but found duplicate profile with id " + profile.getId() ); + "must be unique but found duplicate profile with id " + profile.getId(), profile ); } validateRawDependencies( problems, profile.getDependencies(), "profiles.profile[" + profile.getId() @@ -157,7 +159,7 @@ public class DefaultModelValidator if ( existing != null ) { addViolation( problems, errOn31, prefix + "(groupId:artifactId)", null, - "must be unique but found duplicate declaration of plugin " + key ); + "must be unique but found duplicate declaration of plugin " + key, plugin ); } else { @@ -172,7 +174,7 @@ public class DefaultModelValidator { addViolation( problems, Severity.ERROR, "build.plugins.plugin[" + plugin.getKey() + "].executions.execution.id", null, "must be unique but found duplicate execution with id " - + exec.getId() ); + + exec.getId(), exec ); } } } @@ -180,20 +182,20 @@ public class DefaultModelValidator public void validateEffectiveModel( Model model, ModelBuildingRequest request, ModelProblemCollector problems ) { - validateStringNotEmpty( "modelVersion", problems, Severity.ERROR, model.getModelVersion() ); + validateStringNotEmpty( "modelVersion", problems, Severity.ERROR, model.getModelVersion(), model ); - validateId( "groupId", problems, model.getGroupId() ); + validateId( "groupId", problems, model.getGroupId(), model ); - validateId( "artifactId", problems, model.getArtifactId() ); + validateId( "artifactId", problems, model.getArtifactId(), model ); - validateStringNotEmpty( "packaging", problems, Severity.ERROR, model.getPackaging() ); + validateStringNotEmpty( "packaging", problems, Severity.ERROR, model.getPackaging(), model ); if ( !model.getModules().isEmpty() ) { if ( !"pom".equals( model.getPackaging() ) ) { addViolation( problems, Severity.ERROR, "packaging", null, "with value '" + model.getPackaging() - + "' is invalid. Aggregator projects " + "require 'pom' as packaging." ); + + "' is invalid. Aggregator projects " + "require 'pom' as packaging.", model ); } for ( int i = 0, n = model.getModules().size(); i < n; i++ ) @@ -202,12 +204,13 @@ public class DefaultModelValidator if ( StringUtils.isBlank( module ) ) { addViolation( problems, Severity.WARNING, "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" ) ); } } } - validateStringNotEmpty( "version", problems, Severity.ERROR, model.getVersion() ); + validateStringNotEmpty( "version", problems, Severity.ERROR, model.getVersion(), model ); Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 ); @@ -228,7 +231,7 @@ public class DefaultModelValidator if ( !modules.add( module ) ) { addViolation( problems, Severity.ERROR, "modules.module[" + i + "]", null, - "specifies duplicate child module " + module ); + "specifies duplicate child module " + module, model.getLocation( "modules" ) ); } } @@ -240,18 +243,18 @@ public class DefaultModelValidator for ( Plugin p : build.getPlugins() ) { validateStringNotEmpty( "build.plugins.plugin.artifactId", problems, Severity.ERROR, - p.getArtifactId() ); + p.getArtifactId(), p ); - validateStringNotEmpty( "build.plugins.plugin.groupId", problems, Severity.ERROR, p.getGroupId() ); + validateStringNotEmpty( "build.plugins.plugin.groupId", problems, Severity.ERROR, p.getGroupId(), p ); - validatePluginVersion( "build.plugins.plugin.version", problems, p.getVersion(), p.getKey(), + validatePluginVersion( "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, p.getInherited(), p.getKey(), + p ); validateBoolean( "build.plugins.plugin.extensions", problems, errOn30, p.getExtensions(), - p.getKey() ); + p.getKey(), p ); validateEffectivePluginDependencies( problems, p, request ); } @@ -267,13 +270,13 @@ public class DefaultModelValidator for ( ReportPlugin p : reporting.getPlugins() ) { validateStringNotEmpty( "reporting.plugins.plugin.artifactId", problems, Severity.ERROR, - p.getArtifactId() ); + p.getArtifactId(), p ); validateStringNotEmpty( "reporting.plugins.plugin.groupId", problems, Severity.ERROR, - p.getGroupId() ); + p.getGroupId(), p ); validateStringNotEmpty( "reporting.plugins.plugin.version", problems, errOn31, p.getVersion(), - p.getKey() ); + p.getKey(), p ); } } @@ -293,7 +296,7 @@ public class DefaultModelValidator if ( distMgmt.getStatus() != null ) { addViolation( problems, Severity.ERROR, "distributionManagement.status", null, - "must not be specified." ); + "must not be specified.", distMgmt ); } validateRepository( problems, distMgmt.getRepository(), "distributionManagement.repository", request ); @@ -319,7 +322,7 @@ public class DefaultModelValidator && StringUtils.isNotEmpty( dependency.getClassifier() ) ) { addViolation( problems, errOn30, prefix + ".classifier", key, - "must be empty, imported POM cannot have a classifier." ); + "must be empty, imported POM cannot have a classifier.", dependency ); } else if ( "system".equals( dependency.getScope() ) ) { @@ -327,7 +330,7 @@ public class DefaultModelValidator if ( StringUtils.isNotEmpty( sysPath ) && !hasExpression( sysPath ) ) { addViolation( problems, Severity.WARNING, prefix + ".systemPath", key, - "should use a variable instead of a hard-coded path " + sysPath ); + "should use a variable instead of a hard-coded path " + sysPath, dependency ); } } @@ -350,7 +353,7 @@ public class DefaultModelValidator } addViolation( problems, errOn31, prefix + ".(groupId:artifactId:type:classifier)", null, - "must be unique: " + key + " -> " + msg ); + "must be unique: " + key + " -> " + msg, dependency ); } else { @@ -372,17 +375,17 @@ public class DefaultModelValidator if ( request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 ) { - validateBoolean( prefix + "optional", problems, errOn30, d.getOptional(), d.getManagementKey() ); + validateBoolean( prefix + "optional", problems, errOn30, d.getOptional(), d.getManagementKey(), d ); if ( !management ) { - validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey() ); + validateVersion( prefix + "version", problems, errOn30, 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(), + validateEnum( prefix + "scope", problems, Severity.WARNING, d.getScope(), d.getManagementKey(), d, "provided", "compile", "runtime", "test", "system" ); } } @@ -404,9 +407,9 @@ public class DefaultModelValidator { validateEffectiveDependency( problems, d, false, prefix, request ); - validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey() ); + validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d ); - validateEnum( prefix + "scope", problems, errOn30, d.getScope(), d.getManagementKey(), "compile", + validateEnum( prefix + "scope", problems, errOn30, d.getScope(), d.getManagementKey(), d, "compile", "runtime", "system" ); } } @@ -415,15 +418,16 @@ public class DefaultModelValidator private void validateEffectiveDependency( ModelProblemCollector problems, Dependency d, boolean management, String prefix, ModelBuildingRequest request ) { - validateId( prefix + "artifactId", problems, d.getArtifactId(), d.getManagementKey() ); + validateId( prefix + "artifactId", problems, d.getArtifactId(), d.getManagementKey(), d ); - validateId( prefix + "groupId", problems, d.getGroupId(), d.getManagementKey() ); + validateId( prefix + "groupId", problems, d.getGroupId(), d.getManagementKey(), d ); if ( !management ) { - validateStringNotEmpty( prefix + "type", problems, Severity.ERROR, d.getType(), d.getManagementKey() ); + validateStringNotEmpty( prefix + "type", problems, Severity.ERROR, d.getType(), d.getManagementKey(), d ); - validateStringNotEmpty( prefix + "version", problems, Severity.ERROR, d.getVersion(), d.getManagementKey() ); + validateStringNotEmpty( prefix + "version", problems, Severity.ERROR, d.getVersion(), d.getManagementKey(), + d ); } if ( "system".equals( d.getScope() ) ) @@ -432,7 +436,7 @@ public class DefaultModelValidator if ( StringUtils.isEmpty( systemPath ) ) { - addViolation( problems, Severity.ERROR, prefix + "systemPath", d.getManagementKey(), "is missing." ); + addViolation( problems, Severity.ERROR, prefix + "systemPath", d.getManagementKey(), "is missing.", d ); } else { @@ -440,7 +444,7 @@ public class DefaultModelValidator if ( !sysFile.isAbsolute() ) { addViolation( problems, Severity.ERROR, prefix + "systemPath", d.getManagementKey(), - "must specify an absolute path but is " + systemPath ); + "must specify an absolute path but is " + systemPath, d ); } else if ( !sysFile.isFile() ) { @@ -452,14 +456,14 @@ 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 ); + addViolation( problems, Severity.WARNING, prefix + "systemPath", d.getManagementKey(), msg, d ); } } } else if ( StringUtils.isNotEmpty( d.getSystemPath() ) ) { addViolation( problems, Severity.ERROR, prefix + "systemPath", d.getManagementKey(), "must be omitted." - + " This field may only be specified for a dependency with system scope." ); + + " This field may only be specified for a dependency with system scope.", d ); } } @@ -470,10 +474,10 @@ public class DefaultModelValidator for ( Repository repository : repositories ) { - validateStringNotEmpty( prefix + ".id", problems, Severity.ERROR, repository.getId() ); + validateStringNotEmpty( prefix + ".id", problems, Severity.ERROR, repository.getId(), repository ); validateStringNotEmpty( prefix + "[" + repository.getId() + "].url", problems, Severity.ERROR, - repository.getUrl() ); + repository.getUrl(), repository ); String key = repository.getId(); @@ -484,7 +488,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() + " -> " - + existing.getUrl() + " vs " + repository.getUrl() ); + + existing.getUrl() + " vs " + repository.getUrl(), repository ); } else { @@ -503,12 +507,12 @@ public class DefaultModelValidator Severity errOn31 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 ); addViolation( problems, errOn31, 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." ); + + ", using it for other repositories will corrupt your repository metadata.", repository ); } if ( "legacy".equals( repository.getLayout() ) ) { addViolation( problems, Severity.WARNING, prefix + ".layout", repository.getId(), - "uses the deprecated value 'legacy'." ); + "uses the deprecated value 'legacy'.", repository ); } } } @@ -519,10 +523,10 @@ public class DefaultModelValidator for ( Resource resource : resources ) { - validateStringNotEmpty( prefix + ".directory", problems, Severity.ERROR, resource.getDirectory() ); + validateStringNotEmpty( prefix + ".directory", problems, Severity.ERROR, resource.getDirectory(), resource ); validateBoolean( prefix + ".filtering", problems, errOn30, resource.getFiltering(), - resource.getDirectory() ); + resource.getDirectory(), resource ); } } @@ -530,14 +534,15 @@ public class DefaultModelValidator // Field validation // ---------------------------------------------------------------------- - private boolean validateId( String fieldName, ModelProblemCollector problems, String id ) + private boolean validateId( String fieldName, ModelProblemCollector problems, String id, InputLocationTracker tracker ) { - return validateId( fieldName, problems, id, null ); + return validateId( fieldName, problems, id, null, tracker ); } - private boolean validateId( String fieldName, ModelProblemCollector problems, String id, String sourceHint ) + private boolean validateId( String fieldName, ModelProblemCollector problems, String id, String sourceHint, + InputLocationTracker tracker ) { - if ( !validateStringNotEmpty( fieldName, problems, Severity.ERROR, id, sourceHint ) ) + if ( !validateStringNotEmpty( fieldName, problems, Severity.ERROR, id, sourceHint, tracker ) ) { return false; } @@ -547,21 +552,21 @@ public class DefaultModelValidator if ( !match ) { addViolation( problems, Severity.ERROR, fieldName, sourceHint, "with value '" + id - + "' does not match a valid id pattern." ); + + "' does not match a valid id pattern.", tracker ); } return match; } } private boolean validateStringNoExpression( String fieldName, ModelProblemCollector problems, Severity severity, - String string ) + String string, InputLocationTracker tracker ) { if ( !hasExpression( string ) ) { return true; } - addViolation( problems, severity, fieldName, null, "contains an expression but should be a constant." ); + addViolation( problems, severity, fieldName, null, "contains an expression but should be a constant.", tracker ); return false; } @@ -572,9 +577,9 @@ public class DefaultModelValidator } private boolean validateStringNotEmpty( String fieldName, ModelProblemCollector problems, Severity severity, - String string ) + String string, InputLocationTracker tracker ) { - return validateStringNotEmpty( fieldName, problems, severity, string, null ); + return validateStringNotEmpty( fieldName, problems, severity, string, null, tracker ); } /** @@ -586,9 +591,9 @@ public class DefaultModelValidator * */ private boolean validateStringNotEmpty( String fieldName, ModelProblemCollector problems, Severity severity, - String string, String sourceHint ) + String string, String sourceHint, InputLocationTracker tracker ) { - if ( !validateNotNull( fieldName, problems, severity, string, sourceHint ) ) + if ( !validateNotNull( fieldName, problems, severity, string, sourceHint, tracker ) ) { return false; } @@ -598,7 +603,7 @@ public class DefaultModelValidator return true; } - addViolation( problems, severity, fieldName, sourceHint, "is missing." ); + addViolation( problems, severity, fieldName, sourceHint, "is missing.", tracker ); return false; } @@ -611,20 +616,20 @@ public class DefaultModelValidator * */ private boolean validateNotNull( String fieldName, ModelProblemCollector problems, Severity severity, - Object object, String sourceHint ) + Object object, String sourceHint, InputLocationTracker tracker ) { if ( object != null ) { return true; } - addViolation( problems, severity, fieldName, sourceHint, "is missing." ); + addViolation( problems, severity, fieldName, sourceHint, "is missing.", tracker ); return false; } private boolean validateBoolean( String fieldName, ModelProblemCollector problems, Severity severity, String string, - String sourceHint ) + String sourceHint, InputLocationTracker tracker ) { if ( string == null || string.length() <= 0 ) { @@ -636,13 +641,14 @@ public class DefaultModelValidator return true; } - addViolation( problems, severity, fieldName, sourceHint, "must be 'true' or 'false' but is '" + string + "'." ); + addViolation( problems, severity, fieldName, sourceHint, "must be 'true' or 'false' but is '" + string + "'.", + tracker ); return false; } private boolean validateEnum( String fieldName, ModelProblemCollector problems, Severity severity, String string, - String sourceHint, String... validValues ) + String sourceHint, InputLocationTracker tracker, String... validValues ) { if ( string == null || string.length() <= 0 ) { @@ -657,13 +663,13 @@ public class DefaultModelValidator } addViolation( problems, severity, fieldName, sourceHint, "must be one of " + values + " but is '" + string - + "'." ); + + "'.", tracker ); return false; } private boolean validateVersion( String fieldName, ModelProblemCollector problems, Severity severity, String string, - String sourceHint ) + String sourceHint, InputLocationTracker tracker ) { if ( string == null || string.length() <= 0 ) { @@ -675,13 +681,14 @@ public class DefaultModelValidator return true; } - addViolation( problems, severity, fieldName, sourceHint, "must be a valid version but is '" + string + "'." ); + addViolation( problems, severity, fieldName, sourceHint, "must be a valid version but is '" + string + "'.", + tracker ); return false; } private boolean validatePluginVersion( String fieldName, ModelProblemCollector problems, String string, - String sourceHint, ModelBuildingRequest request ) + String sourceHint, InputLocationTracker tracker, ModelBuildingRequest request ) { Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 ); @@ -697,13 +704,14 @@ public class DefaultModelValidator return true; } - addViolation( problems, errOn30, fieldName, sourceHint, "must be a valid version but is '" + string + "'." ); + addViolation( problems, errOn30, fieldName, sourceHint, "must be a valid version but is '" + string + "'.", + tracker ); return false; } private static void addViolation( ModelProblemCollector problems, Severity severity, String fieldName, - String sourceHint, String message ) + String sourceHint, String message, InputLocationTracker tracker ) { StringBuilder buffer = new StringBuilder( 256 ); buffer.append( '\'' ).append( fieldName ).append( '\'' ); @@ -715,12 +723,48 @@ public class DefaultModelValidator buffer.append(' ').append( message ); - addViolation( problems, severity, buffer.toString() ); + problems.add( severity, buffer.toString(), getLocation( fieldName, tracker ), null ); } - private static void addViolation( ModelProblemCollector problems, Severity severity, String message ) + private static InputLocation getLocation( String fieldName, InputLocationTracker tracker ) { - problems.add( severity, message, null ); + InputLocation location = null; + + if ( tracker != null ) + { + if ( fieldName != null ) + { + Object key = fieldName; + + int idx = fieldName.lastIndexOf( '.' ); + if ( idx >= 0 ) + { + key = fieldName = fieldName.substring( idx + 1 ); + } + + if ( fieldName.endsWith( "]" ) ) + { + key = fieldName.substring( fieldName.lastIndexOf( '[' ) + 1, fieldName.length() - 1 ); + try + { + key = Integer.valueOf( key.toString() ); + } + catch ( NumberFormatException e ) + { + // use key as is + } + } + + location = tracker.getLocation( key ); + } + + if ( location == null ) + { + location = tracker.getLocation( "" ); + } + } + + return location; } private static boolean equals( String s1, String s2 ) diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/building/SimpleProblemCollector.java b/maven-model-builder/src/test/java/org/apache/maven/model/building/SimpleProblemCollector.java index 84edecde38..48dcc24cc7 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/building/SimpleProblemCollector.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/building/SimpleProblemCollector.java @@ -22,6 +22,7 @@ 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; /** @@ -54,7 +55,7 @@ public class SimpleProblemCollector return fatals; } - public void add( Severity severity, String message, Exception cause ) + public void add( Severity severity, String message, InputLocation location, Exception cause ) { switch ( severity ) { diff --git a/maven-model/pom.xml b/maven-model/pom.xml index 20fd7a992a..b148af2dcc 100644 --- a/maven-model/pom.xml +++ b/maven-model/pom.xml @@ -51,6 +51,17 @@ under the License. src/main/mdo/maven.mdo + + + standard + + java + xpp3-reader + xpp3-extended-reader + xpp3-writer + + + org.apache.maven.plugins diff --git a/maven-model/src/main/java/org/apache/maven/model/merge/ModelMerger.java b/maven-model/src/main/java/org/apache/maven/model/merge/ModelMerger.java index 4b076b1a8a..9685a4721f 100644 --- a/maven-model/src/main/java/org/apache/maven/model/merge/ModelMerger.java +++ b/maven-model/src/main/java/org/apache/maven/model/merge/ModelMerger.java @@ -40,6 +40,7 @@ import org.apache.maven.model.DistributionManagement; import org.apache.maven.model.Exclusion; import org.apache.maven.model.Extension; import org.apache.maven.model.FileSet; +import org.apache.maven.model.InputLocation; import org.apache.maven.model.IssueManagement; import org.apache.maven.model.License; import org.apache.maven.model.MailingList; @@ -146,6 +147,7 @@ public class ModelMerger if ( sourceDominant || target.getModelVersion() == null ) { target.setModelVersion( src ); + target.setLocation( "modelVersion", source.getLocation( "modelVersion" ) ); } } } @@ -173,6 +175,7 @@ public class ModelMerger if ( sourceDominant || target.getGroupId() == null ) { target.setGroupId( src ); + target.setLocation( "groupId", source.getLocation( "groupId" ) ); } } } @@ -186,6 +189,7 @@ public class ModelMerger if ( sourceDominant || target.getArtifactId() == null ) { target.setArtifactId( src ); + target.setLocation( "artifactId", source.getLocation( "artifactId" ) ); } } } @@ -198,6 +202,7 @@ public class ModelMerger if ( sourceDominant || target.getVersion() == null ) { target.setVersion( src ); + target.setLocation( "version", source.getLocation( "version" ) ); } } } @@ -210,6 +215,7 @@ public class ModelMerger if ( sourceDominant || target.getPackaging() == null ) { target.setPackaging( src ); + target.setLocation( "packaging", source.getLocation( "packaging" ) ); } } } @@ -222,6 +228,7 @@ public class ModelMerger if ( sourceDominant || target.getName() == null ) { target.setName( src ); + target.setLocation( "name", source.getLocation( "name" ) ); } } } @@ -235,6 +242,7 @@ public class ModelMerger if ( sourceDominant || target.getDescription() == null ) { target.setDescription( src ); + target.setLocation( "description", source.getLocation( "description" ) ); } } } @@ -247,6 +255,7 @@ public class ModelMerger if ( sourceDominant || target.getUrl() == null ) { target.setUrl( src ); + target.setLocation( "url", source.getLocation( "url" ) ); } } } @@ -260,6 +269,7 @@ public class ModelMerger if ( sourceDominant || target.getInceptionYear() == null ) { target.setInceptionYear( src ); + target.setLocation( "inceptionYear", source.getLocation( "inceptionYear" ) ); } } } @@ -670,6 +680,8 @@ public class ModelMerger merged.putAll( target.getProperties() ); } target.setProperties( merged ); + target.setLocation( "properties", InputLocation.merge( target.getLocation( "properties" ), + source.getLocation( "properties" ), sourceDominant ) ); } protected void mergeDistributionManagement( DistributionManagement target, DistributionManagement source, @@ -741,6 +753,7 @@ public class ModelMerger if ( sourceDominant || target.getStatus() == null ) { target.setStatus( src ); + target.setLocation( "status", source.getLocation( "status" ) ); } } } @@ -755,6 +768,7 @@ public class ModelMerger if ( sourceDominant || target.getDownloadUrl() == null ) { target.setDownloadUrl( src ); + target.setLocation( "downloadUrl", source.getLocation( "downloadUrl" ) ); } } } @@ -777,6 +791,7 @@ public class ModelMerger if ( sourceDominant || target.getGroupId() == null ) { target.setGroupId( src ); + target.setLocation( "groupId", source.getLocation( "groupId" ) ); } } } @@ -790,6 +805,7 @@ public class ModelMerger if ( sourceDominant || target.getArtifactId() == null ) { target.setArtifactId( src ); + target.setLocation( "artifactId", source.getLocation( "artifactId" ) ); } } } @@ -803,6 +819,7 @@ public class ModelMerger if ( sourceDominant || target.getVersion() == null ) { target.setVersion( src ); + target.setLocation( "version", source.getLocation( "version" ) ); } } } @@ -816,6 +833,7 @@ public class ModelMerger if ( sourceDominant || target.getMessage() == null ) { target.setMessage( src ); + target.setLocation( "message", source.getLocation( "message" ) ); } } } @@ -833,6 +851,7 @@ public class ModelMerger if ( sourceDominant ) { target.setUniqueVersion( source.isUniqueVersion() ); + target.setLocation( "uniqueVersion", source.getLocation( "uniqueVersion" ) ); } } @@ -851,6 +870,7 @@ public class ModelMerger if ( sourceDominant || target.getId() == null ) { target.setId( src ); + target.setLocation( "id", source.getLocation( "id" ) ); } } } @@ -863,6 +883,7 @@ public class ModelMerger if ( sourceDominant || target.getName() == null ) { target.setName( src ); + target.setLocation( "name", source.getLocation( "name" ) ); } } } @@ -875,6 +896,7 @@ public class ModelMerger if ( sourceDominant || target.getUrl() == null ) { target.setUrl( src ); + target.setLocation( "url", source.getLocation( "url" ) ); } } } @@ -937,6 +959,7 @@ public class ModelMerger if ( sourceDominant || target.getId() == null ) { target.setId( src ); + target.setLocation( "id", source.getLocation( "id" ) ); } } } @@ -950,6 +973,7 @@ public class ModelMerger if ( sourceDominant || target.getUrl() == null ) { target.setUrl( src ); + target.setLocation( "url", source.getLocation( "url" ) ); } } } @@ -963,6 +987,7 @@ public class ModelMerger if ( sourceDominant || target.getName() == null ) { target.setName( src ); + target.setLocation( "name", source.getLocation( "name" ) ); } } } @@ -976,6 +1001,7 @@ public class ModelMerger if ( sourceDominant || target.getLayout() == null ) { target.setLayout( src ); + target.setLocation( "layout", source.getLocation( "layout" ) ); } } } @@ -997,6 +1023,7 @@ public class ModelMerger if ( sourceDominant || target.getEnabled() == null ) { target.setEnabled( src ); + target.setLocation( "enabled", source.getLocation( "enabled" ) ); } } } @@ -1010,6 +1037,7 @@ public class ModelMerger if ( sourceDominant || target.getUpdatePolicy() == null ) { target.setUpdatePolicy( src ); + target.setLocation( "updatePolicy", source.getLocation( "updatePolicy" ) ); } } } @@ -1023,6 +1051,7 @@ public class ModelMerger if ( sourceDominant || target.getChecksumPolicy() == null ) { target.setChecksumPolicy( src ); + target.setLocation( "checksumPolicy", source.getLocation( "checksumPolicy" ) ); } } } @@ -1050,6 +1079,7 @@ public class ModelMerger if ( sourceDominant || target.getGroupId() == null ) { target.setGroupId( src ); + target.setLocation( "groupId", source.getLocation( "groupId" ) ); } } } @@ -1063,6 +1093,7 @@ public class ModelMerger if ( sourceDominant || target.getArtifactId() == null ) { target.setArtifactId( src ); + target.setLocation( "artifactId", source.getLocation( "artifactId" ) ); } } } @@ -1076,6 +1107,7 @@ public class ModelMerger if ( sourceDominant || target.getVersion() == null ) { target.setVersion( src ); + target.setLocation( "version", source.getLocation( "version" ) ); } } } @@ -1089,6 +1121,7 @@ public class ModelMerger if ( sourceDominant || target.getType() == null ) { target.setType( src ); + target.setLocation( "type", source.getLocation( "type" ) ); } } } @@ -1102,6 +1135,7 @@ public class ModelMerger if ( sourceDominant || target.getClassifier() == null ) { target.setClassifier( src ); + target.setLocation( "classifier", source.getLocation( "classifier" ) ); } } } @@ -1115,6 +1149,7 @@ public class ModelMerger if ( sourceDominant || target.getScope() == null ) { target.setScope( src ); + target.setLocation( "scope", source.getLocation( "scope" ) ); } } } @@ -1128,6 +1163,7 @@ public class ModelMerger if ( sourceDominant || target.getSystemPath() == null ) { target.setSystemPath( src ); + target.setLocation( "systemPath", source.getLocation( "systemPath" ) ); } } } @@ -1141,6 +1177,7 @@ public class ModelMerger if ( sourceDominant || target.getOptional() == null ) { target.setOptional( src ); + target.setLocation( "optional", source.getLocation( "optional" ) ); } } } @@ -1190,6 +1227,7 @@ public class ModelMerger if ( sourceDominant || target.getGroupId() == null ) { target.setGroupId( src ); + target.setLocation( "groupId", source.getLocation( "groupId" ) ); } } } @@ -1203,6 +1241,7 @@ public class ModelMerger if ( sourceDominant || target.getArtifactId() == null ) { target.setArtifactId( src ); + target.setLocation( "artifactId", source.getLocation( "artifactId" ) ); } } } @@ -1224,6 +1263,7 @@ public class ModelMerger if ( sourceDominant || target.getOutputDirectory() == null ) { target.setOutputDirectory( src ); + target.setLocation( "outputDirectory", source.getLocation( "outputDirectory" ) ); } } } @@ -1237,6 +1277,7 @@ public class ModelMerger if ( sourceDominant || target.getExcludeDefaults() == null ) { target.setExcludeDefaults( src ); + target.setLocation( "excludeDefaults", source.getLocation( "excludeDefaults" ) ); } } } @@ -1290,6 +1331,7 @@ public class ModelMerger if ( sourceDominant || target.getGroupId() == null ) { target.setGroupId( src ); + target.setLocation( "groupId", source.getLocation( "groupId" ) ); } } } @@ -1303,6 +1345,7 @@ public class ModelMerger if ( sourceDominant || target.getArtifactId() == null ) { target.setArtifactId( src ); + target.setLocation( "artifactId", source.getLocation( "artifactId" ) ); } } } @@ -1316,6 +1359,7 @@ public class ModelMerger if ( sourceDominant || target.getVersion() == null ) { target.setVersion( src ); + target.setLocation( "version", source.getLocation( "version" ) ); } } } @@ -1329,6 +1373,7 @@ public class ModelMerger if ( sourceDominant || target.getInherited() == null ) { target.setInherited( src ); + target.setLocation( "inherited", source.getLocation( "inherited" ) ); } } } @@ -1431,6 +1476,7 @@ public class ModelMerger if ( sourceDominant || target.getGroupId() == null ) { target.setGroupId( src ); + target.setLocation( "groupId", source.getLocation( "groupId" ) ); } } } @@ -1444,6 +1490,7 @@ public class ModelMerger if ( sourceDominant || target.getArtifactId() == null ) { target.setArtifactId( src ); + target.setLocation( "artifactId", source.getLocation( "artifactId" ) ); } } } @@ -1457,6 +1504,7 @@ public class ModelMerger if ( sourceDominant || target.getVersion() == null ) { target.setVersion( src ); + target.setLocation( "version", source.getLocation( "version" ) ); } } } @@ -1470,6 +1518,7 @@ public class ModelMerger if ( sourceDominant || target.getRelativePath() == null ) { target.setRelativePath( src ); + target.setLocation( "relativePath", source.getLocation( "relativePath" ) ); } } } @@ -1490,6 +1539,7 @@ public class ModelMerger if ( sourceDominant || target.getName() == null ) { target.setName( src ); + target.setLocation( "name", source.getLocation( "name" ) ); } } } @@ -1503,6 +1553,7 @@ public class ModelMerger if ( sourceDominant || target.getUrl() == null ) { target.setUrl( src ); + target.setLocation( "url", source.getLocation( "url" ) ); } } } @@ -1524,6 +1575,7 @@ public class ModelMerger if ( sourceDominant || target.getName() == null ) { target.setName( src ); + target.setLocation( "name", source.getLocation( "name" ) ); } } } @@ -1536,6 +1588,7 @@ public class ModelMerger if ( sourceDominant || target.getUrl() == null ) { target.setUrl( src ); + target.setLocation( "url", source.getLocation( "url" ) ); } } } @@ -1549,6 +1602,7 @@ public class ModelMerger if ( sourceDominant || target.getDistribution() == null ) { target.setDistribution( src ); + target.setLocation( "distribution", source.getLocation( "distribution" ) ); } } } @@ -1562,6 +1616,7 @@ public class ModelMerger if ( sourceDominant || target.getComments() == null ) { target.setComments( src ); + target.setLocation( "comments", source.getLocation( "comments" ) ); } } } @@ -1585,6 +1640,7 @@ public class ModelMerger if ( sourceDominant || target.getName() == null ) { target.setName( src ); + target.setLocation( "name", source.getLocation( "name" ) ); } } } @@ -1598,6 +1654,7 @@ public class ModelMerger if ( sourceDominant || target.getSubscribe() == null ) { target.setSubscribe( src ); + target.setLocation( "subscribe", source.getLocation( "subscribe" ) ); } } } @@ -1611,6 +1668,7 @@ public class ModelMerger if ( sourceDominant || target.getUnsubscribe() == null ) { target.setUnsubscribe( src ); + target.setLocation( "unsubscribe", source.getLocation( "unsubscribe" ) ); } } } @@ -1624,6 +1682,7 @@ public class ModelMerger if ( sourceDominant || target.getPost() == null ) { target.setPost( src ); + target.setLocation( "post", source.getLocation( "post" ) ); } } } @@ -1637,6 +1696,7 @@ public class ModelMerger if ( sourceDominant || target.getArchive() == null ) { target.setArchive( src ); + target.setLocation( "archive", source.getLocation( "archive" ) ); } } } @@ -1671,6 +1731,7 @@ public class ModelMerger if ( sourceDominant || target.getId() == null ) { target.setId( src ); + target.setLocation( "id", source.getLocation( "id" ) ); } } } @@ -1697,6 +1758,7 @@ public class ModelMerger if ( sourceDominant || target.getName() == null ) { target.setName( src ); + target.setLocation( "name", source.getLocation( "name" ) ); } } } @@ -1710,6 +1772,7 @@ public class ModelMerger if ( sourceDominant || target.getEmail() == null ) { target.setEmail( src ); + target.setLocation( "email", source.getLocation( "email" ) ); } } } @@ -1723,6 +1786,7 @@ public class ModelMerger if ( sourceDominant || target.getUrl() == null ) { target.setUrl( src ); + target.setLocation( "url", source.getLocation( "url" ) ); } } } @@ -1736,6 +1800,7 @@ public class ModelMerger if ( sourceDominant || target.getOrganization() == null ) { target.setOrganization( src ); + target.setLocation( "organization", source.getLocation( "organization" ) ); } } } @@ -1749,6 +1814,7 @@ public class ModelMerger if ( sourceDominant || target.getOrganizationUrl() == null ) { target.setOrganizationUrl( src ); + target.setLocation( "organizationUrl", source.getLocation( "organizationUrl" ) ); } } } @@ -1762,6 +1828,7 @@ public class ModelMerger if ( sourceDominant || target.getTimezone() == null ) { target.setTimezone( src ); + target.setLocation( "timezone", source.getLocation( "timezone" ) ); } } } @@ -1795,6 +1862,8 @@ public class ModelMerger merged.putAll( target.getProperties() ); } target.setProperties( merged ); + target.setLocation( "properties", InputLocation.merge( target.getLocation( "properties" ), + source.getLocation( "properties" ), sourceDominant ) ); } protected void mergeIssueManagement( IssueManagement target, IssueManagement source, boolean sourceDominant, @@ -1813,6 +1882,7 @@ public class ModelMerger if ( sourceDominant || target.getSystem() == null ) { target.setSystem( src ); + target.setLocation( "system", source.getLocation( "system" ) ); } } } @@ -1826,6 +1896,7 @@ public class ModelMerger if ( sourceDominant || target.getUrl() == null ) { target.setUrl( src ); + target.setLocation( "url", source.getLocation( "url" ) ); } } } @@ -1846,6 +1917,7 @@ public class ModelMerger if ( sourceDominant || target.getUrl() == null ) { target.setUrl( src ); + target.setLocation( "url", source.getLocation( "url" ) ); } } } @@ -1858,6 +1930,7 @@ public class ModelMerger if ( sourceDominant || target.getConnection() == null ) { target.setConnection( src ); + target.setLocation( "connection", source.getLocation( "connection" ) ); } } } @@ -1871,6 +1944,7 @@ public class ModelMerger if ( sourceDominant || target.getDeveloperConnection() == null ) { target.setDeveloperConnection( src ); + target.setLocation( "developerConnection", source.getLocation( "developerConnection" ) ); } } } @@ -1883,6 +1957,7 @@ public class ModelMerger if ( sourceDominant || target.getTag() == null ) { target.setTag( src ); + target.setLocation( "tag", source.getLocation( "tag" ) ); } } } @@ -1904,6 +1979,7 @@ public class ModelMerger if ( sourceDominant || target.getSystem() == null ) { target.setSystem( src ); + target.setLocation( "system", source.getLocation( "system" ) ); } } } @@ -1917,6 +1993,7 @@ public class ModelMerger if ( sourceDominant || target.getUrl() == null ) { target.setUrl( src ); + target.setLocation( "url", source.getLocation( "url" ) ); } } } @@ -2054,6 +2131,7 @@ public class ModelMerger if ( sourceDominant || target.getMaven() == null ) { target.setMaven( src ); + target.setLocation( "maven", source.getLocation( "maven" ) ); } } } @@ -2078,6 +2156,7 @@ public class ModelMerger if ( sourceDominant || target.getSourceDirectory() == null ) { target.setSourceDirectory( src ); + target.setLocation( "sourceDirectory", source.getLocation( "sourceDirectory" ) ); } } } @@ -2091,6 +2170,7 @@ public class ModelMerger if ( sourceDominant || target.getScriptSourceDirectory() == null ) { target.setScriptSourceDirectory( src ); + target.setLocation( "scriptSourceDirectory", source.getLocation( "scriptSourceDirectory" ) ); } } } @@ -2104,6 +2184,7 @@ public class ModelMerger if ( sourceDominant || target.getTestSourceDirectory() == null ) { target.setTestSourceDirectory( src ); + target.setLocation( "testSourceDirectory", source.getLocation( "testSourceDirectory" ) ); } } } @@ -2117,6 +2198,7 @@ public class ModelMerger if ( sourceDominant || target.getOutputDirectory() == null ) { target.setOutputDirectory( src ); + target.setLocation( "outputDirectory", source.getLocation( "outputDirectory" ) ); } } } @@ -2130,6 +2212,7 @@ public class ModelMerger if ( sourceDominant || target.getTestOutputDirectory() == null ) { target.setTestOutputDirectory( src ); + target.setLocation( "testOutputDirectory", source.getLocation( "testOutputDirectory" ) ); } } } @@ -2179,6 +2262,7 @@ public class ModelMerger if ( sourceDominant || target.getGroupId() == null ) { target.setGroupId( src ); + target.setLocation( "groupId", source.getLocation( "groupId" ) ); } } } @@ -2192,6 +2276,7 @@ public class ModelMerger if ( sourceDominant || target.getArtifactId() == null ) { target.setArtifactId( src ); + target.setLocation( "artifactId", source.getLocation( "artifactId" ) ); } } } @@ -2205,6 +2290,7 @@ public class ModelMerger if ( sourceDominant || target.getVersion() == null ) { target.setVersion( src ); + target.setLocation( "version", source.getLocation( "version" ) ); } } } @@ -2230,6 +2316,7 @@ public class ModelMerger if ( sourceDominant || target.getDefaultGoal() == null ) { target.setDefaultGoal( src ); + target.setLocation( "defaultGoal", source.getLocation( "defaultGoal" ) ); } } } @@ -2243,6 +2330,7 @@ public class ModelMerger if ( sourceDominant || target.getDirectory() == null ) { target.setDirectory( src ); + target.setLocation( "directory", source.getLocation( "directory" ) ); } } } @@ -2256,6 +2344,7 @@ public class ModelMerger if ( sourceDominant || target.getFinalName() == null ) { target.setFinalName( src ); + target.setLocation( "finalName", source.getLocation( "finalName" ) ); } } } @@ -2413,6 +2502,7 @@ public class ModelMerger if ( sourceDominant || target.getGroupId() == null ) { target.setGroupId( src ); + target.setLocation( "groupId", source.getLocation( "groupId" ) ); } } } @@ -2426,6 +2516,7 @@ public class ModelMerger if ( sourceDominant || target.getArtifactId() == null ) { target.setArtifactId( src ); + target.setLocation( "artifactId", source.getLocation( "artifactId" ) ); } } } @@ -2439,6 +2530,7 @@ public class ModelMerger if ( sourceDominant || target.getVersion() == null ) { target.setVersion( src ); + target.setLocation( "version", source.getLocation( "version" ) ); } } } @@ -2452,6 +2544,7 @@ public class ModelMerger if ( sourceDominant || target.getExtensions() == null ) { target.setExtensions( src ); + target.setLocation( "extensions", source.getLocation( "extensions" ) ); } } } @@ -2530,6 +2623,7 @@ public class ModelMerger if ( sourceDominant || target.getInherited() == null ) { target.setInherited( src ); + target.setLocation( "inherited", source.getLocation( "inherited" ) ); } } } @@ -2572,6 +2666,7 @@ public class ModelMerger if ( sourceDominant || target.getId() == null ) { target.setId( src ); + target.setLocation( "id", source.getLocation( "id" ) ); } } } @@ -2585,6 +2680,7 @@ public class ModelMerger if ( sourceDominant || target.getPhase() == null ) { target.setPhase( src ); + target.setLocation( "phase", source.getLocation( "phase" ) ); } } } @@ -2620,6 +2716,7 @@ public class ModelMerger if ( sourceDominant || target.getTargetPath() == null ) { target.setTargetPath( src ); + target.setLocation( "targetPath", source.getLocation( "targetPath" ) ); } } } @@ -2633,6 +2730,7 @@ public class ModelMerger if ( sourceDominant || target.getFiltering() == null ) { target.setFiltering( src ); + target.setLocation( "filtering", source.getLocation( "filtering" ) ); } } } @@ -2665,6 +2763,7 @@ public class ModelMerger if ( sourceDominant || target.getDirectory() == null ) { target.setDirectory( src ); + target.setLocation( "directory", source.getLocation( "directory" ) ); } } } diff --git a/maven-model/src/main/mdo/maven.mdo b/maven-model/src/main/mdo/maven.mdo index 2f06c51983..affe236c9b 100644 --- a/maven-model/src/main/mdo/maven.mdo +++ b/maven-model/src/main/mdo/maven.mdo @@ -3593,5 +3593,38 @@ + + InputLocation + 4.0.0+ + + + + + + InputSource + 4.0.0+ + + + modelId + 4.0.0+ + String + + + + + + location + 4.0.0+ + String + + + + + +