mirror of https://github.com/apache/maven.git
o Extended lifecycle injector to collect model problems
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@800353 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a52a5e8623
commit
0373dfb46b
|
@ -32,6 +32,9 @@ import org.apache.maven.model.Build;
|
|||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginContainer;
|
||||
import org.apache.maven.model.building.ModelBuildingProblems;
|
||||
import org.apache.maven.model.building.ModelProblem;
|
||||
import org.apache.maven.model.building.ModelProblemUtils;
|
||||
import org.apache.maven.model.merge.MavenModelMerger;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
|
@ -51,15 +54,19 @@ public class DefaultLifecycleBindingsInjector
|
|||
@Requirement
|
||||
private LifecycleExecutor lifecycle;
|
||||
|
||||
public void injectLifecycleBindings( Model model )
|
||||
public void injectLifecycleBindings( Model model, ModelBuildingProblems problems )
|
||||
{
|
||||
String packaging = model.getPackaging();
|
||||
|
||||
Collection<Plugin> defaultPlugins = lifecycle.getPluginsBoundByDefaultToAllLifecycles( packaging );
|
||||
|
||||
// TODO: A bad packaging is a model error, we need to report this as such!
|
||||
|
||||
if ( defaultPlugins != null && !defaultPlugins.isEmpty() )
|
||||
if ( defaultPlugins == null )
|
||||
{
|
||||
String source = ModelProblemUtils.toSourceHint( model );
|
||||
problems.add( new ModelProblem( "Invalid POM " + source + ": Unknown packaging: " + packaging,
|
||||
ModelProblem.Severity.ERROR, source ) );
|
||||
}
|
||||
else if ( !defaultPlugins.isEmpty() )
|
||||
{
|
||||
Model lifecycleModel = new Model();
|
||||
lifecycleModel.setBuild( new Build() );
|
||||
|
|
|
@ -115,13 +115,13 @@ public class DefaultModelBuilder
|
|||
{
|
||||
DefaultModelBuildingResult result = new DefaultModelBuildingResult();
|
||||
|
||||
List<ModelProblem> problems = new ArrayList<ModelProblem>();
|
||||
DefaultModelBuildingProblems problems = new DefaultModelBuildingProblems( null );
|
||||
|
||||
ProfileActivationContext profileActivationContext = getProfileActivationContext( request );
|
||||
|
||||
List<Profile> activeExternalProfiles = getActiveExternalProfiles( request, profileActivationContext, problems );
|
||||
|
||||
Model inputModel = readModel( request.getModelSource(), request.getPomFile(), request, problems );
|
||||
Model inputModel = readModel( request.getModelSource(), request.getPomFile(), request, problems.getProblems() );
|
||||
|
||||
ModelData resultData = new ModelData( inputModel );
|
||||
|
||||
|
@ -156,7 +156,7 @@ public class DefaultModelBuilder
|
|||
|
||||
configureResolver( request.getModelResolver(), tmpModel, problems );
|
||||
|
||||
currentData = readParent( tmpModel, request, problems );
|
||||
currentData = readParent( tmpModel, request, problems.getProblems() );
|
||||
}
|
||||
|
||||
ModelData superData = new ModelData( getSuperModel() );
|
||||
|
@ -175,7 +175,7 @@ public class DefaultModelBuilder
|
|||
resultData.setArtifactId( resultModel.getArtifactId() );
|
||||
resultData.setVersion( resultModel.getVersion() );
|
||||
|
||||
result.setProblems( problems );
|
||||
result.setProblems( problems.getProblems() );
|
||||
|
||||
result.setEffectiveModel( resultModel );
|
||||
|
||||
|
@ -203,7 +203,7 @@ public class DefaultModelBuilder
|
|||
{
|
||||
Model resultModel = result.getEffectiveModel();
|
||||
|
||||
List<ModelProblem> problems = result.getProblems();
|
||||
DefaultModelBuildingProblems problems = new DefaultModelBuildingProblems( result.getProblems() );
|
||||
|
||||
modelPathTranslator.alignToBaseDirectory( resultModel, resultModel.getProjectDirectory(), request );
|
||||
|
||||
|
@ -213,7 +213,7 @@ public class DefaultModelBuilder
|
|||
|
||||
if ( request.isProcessPlugins() )
|
||||
{
|
||||
lifecycleBindingsInjector.injectLifecycleBindings( resultModel );
|
||||
lifecycleBindingsInjector.injectLifecycleBindings( resultModel, problems );
|
||||
}
|
||||
|
||||
pluginManagementInjector.injectManagement( resultModel, request );
|
||||
|
@ -230,11 +230,11 @@ public class DefaultModelBuilder
|
|||
}
|
||||
|
||||
ModelValidationResult validationResult = modelValidator.validateEffectiveModel( resultModel, request );
|
||||
addProblems( resultModel, validationResult, problems );
|
||||
addProblems( resultModel, validationResult, problems.getProblems() );
|
||||
|
||||
if ( hasErrors( problems ) )
|
||||
if ( hasErrors( problems.getProblems() ) )
|
||||
{
|
||||
throw new ModelBuildingException( problems );
|
||||
throw new ModelBuildingException( problems.getProblems() );
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -308,7 +308,7 @@ public class DefaultModelBuilder
|
|||
{
|
||||
if ( !result.getWarnings().isEmpty() || !result.getErrors().isEmpty() )
|
||||
{
|
||||
String source = toSourceHint( model );
|
||||
String source = ModelProblemUtils.toSourceHint( model );
|
||||
|
||||
for ( String message : result.getWarnings() )
|
||||
{
|
||||
|
@ -338,7 +338,7 @@ public class DefaultModelBuilder
|
|||
}
|
||||
|
||||
private List<Profile> getActiveExternalProfiles( ModelBuildingRequest request, ProfileActivationContext context,
|
||||
List<ModelProblem> problems )
|
||||
ModelBuildingProblems problems )
|
||||
{
|
||||
ProfileSelectionResult result = profileSelector.getActiveProfiles( request.getProfiles(), context );
|
||||
|
||||
|
@ -352,21 +352,23 @@ public class DefaultModelBuilder
|
|||
}
|
||||
|
||||
private List<Profile> getActivePomProfiles( Model model, ProfileActivationContext context,
|
||||
List<ModelProblem> problems )
|
||||
ModelBuildingProblems problems )
|
||||
{
|
||||
ProfileSelectionResult result = profileSelector.getActiveProfiles( model.getProfiles(), context );
|
||||
|
||||
for ( ProfileActivationException e : result.getActivationExceptions() )
|
||||
{
|
||||
problems.add( new ModelProblem( "Invalid activation condition for project profile "
|
||||
+ e.getProfile().getId() + " in POM " + toSourceHint( model ) + ": " + e.getMessage(),
|
||||
ModelProblem.Severity.ERROR, toSourceHint( model ), e ) );
|
||||
problems.add( new ModelProblem(
|
||||
"Invalid activation condition for project profile "
|
||||
+ e.getProfile().getId() + " in POM "
|
||||
+ ModelProblemUtils.toSourceHint( model ) + ": " + e.getMessage(),
|
||||
ModelProblem.Severity.ERROR, ModelProblemUtils.toSourceHint( model ), e ) );
|
||||
}
|
||||
|
||||
return result.getActiveProfiles();
|
||||
}
|
||||
|
||||
private void configureResolver( ModelResolver modelResolver, Model model, List<ModelProblem> problems )
|
||||
private void configureResolver( ModelResolver modelResolver, Model model, ModelBuildingProblems problems )
|
||||
{
|
||||
if ( modelResolver == null )
|
||||
{
|
||||
|
@ -385,8 +387,8 @@ public class DefaultModelBuilder
|
|||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
problems.add( new ModelProblem( "Invalid repository " + repository.getId() + " in POM "
|
||||
+ toSourceHint( model ) + ": " + e.getMessage(), ModelProblem.Severity.ERROR,
|
||||
toSourceHint( model ), e ) );
|
||||
+ ModelProblemUtils.toSourceHint( model ) + ": " + e.getMessage(), ModelProblem.Severity.ERROR,
|
||||
ModelProblemUtils.toSourceHint( model ), e ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -401,7 +403,7 @@ public class DefaultModelBuilder
|
|||
}
|
||||
}
|
||||
|
||||
private Model interpolateModel( Model model, ModelBuildingRequest request, List<ModelProblem> problems )
|
||||
private Model interpolateModel( Model model, ModelBuildingRequest request, ModelBuildingProblems problems )
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -411,8 +413,8 @@ public class DefaultModelBuilder
|
|||
}
|
||||
catch ( ModelInterpolationException e )
|
||||
{
|
||||
problems.add( new ModelProblem( "Invalid expression in POM " + toSourceHint( model ) + ": "
|
||||
+ e.getMessage(), ModelProblem.Severity.ERROR, toSourceHint( model ), e ) );
|
||||
problems.add( new ModelProblem( "Invalid expression in POM " + ModelProblemUtils.toSourceHint( model )
|
||||
+ ": " + e.getMessage(), ModelProblem.Severity.ERROR, ModelProblemUtils.toSourceHint( model ), e ) );
|
||||
|
||||
return model;
|
||||
}
|
||||
|
@ -552,7 +554,8 @@ public class DefaultModelBuilder
|
|||
if ( modelResolver == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "no model resolver provided, cannot resolve parent POM "
|
||||
+ toId( groupId, artifactId, version ) + " for POM " + toSourceHint( childModel ) );
|
||||
+ ModelProblemUtils.toId( groupId, artifactId, version ) + " for POM "
|
||||
+ ModelProblemUtils.toSourceHint( childModel ) );
|
||||
}
|
||||
|
||||
ModelSource modelSource;
|
||||
|
@ -562,9 +565,10 @@ public class DefaultModelBuilder
|
|||
}
|
||||
catch ( UnresolvableModelException e )
|
||||
{
|
||||
problems.add( new ModelProblem( "Non-resolvable parent POM " + toId( groupId, artifactId, version )
|
||||
+ " for POM " + toSourceHint( childModel ) + ": " + e.getMessage(), ModelProblem.Severity.FATAL,
|
||||
toSourceHint( childModel ), e ) );
|
||||
problems.add( new ModelProblem( "Non-resolvable parent POM "
|
||||
+ ModelProblemUtils.toId( groupId, artifactId, version ) + " for POM "
|
||||
+ ModelProblemUtils.toSourceHint( childModel ) + ": " + e.getMessage(), ModelProblem.Severity.FATAL,
|
||||
ModelProblemUtils.toSourceHint( childModel ), e ) );
|
||||
throw new ModelBuildingException( problems );
|
||||
}
|
||||
|
||||
|
@ -581,7 +585,7 @@ public class DefaultModelBuilder
|
|||
return ModelUtils.cloneModel( superPomProvider.getSuperModel( "4.0.0" ) );
|
||||
}
|
||||
|
||||
private void importDependencyManagement( Model model, ModelBuildingRequest request, List<ModelProblem> problems )
|
||||
private void importDependencyManagement( Model model, ModelBuildingRequest request, ModelBuildingProblems problems )
|
||||
{
|
||||
DependencyManagement depMngt = model.getDependencyManagement();
|
||||
|
||||
|
@ -619,7 +623,8 @@ public class DefaultModelBuilder
|
|||
if ( modelResolver == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "no model resolver provided, cannot resolve import POM "
|
||||
+ toId( groupId, artifactId, version ) + " for POM " + toSourceHint( model ) );
|
||||
+ ModelProblemUtils.toId( groupId, artifactId, version ) + " for POM "
|
||||
+ ModelProblemUtils.toSourceHint( model ) );
|
||||
}
|
||||
|
||||
ModelSource importSource;
|
||||
|
@ -629,9 +634,10 @@ public class DefaultModelBuilder
|
|||
}
|
||||
catch ( UnresolvableModelException e )
|
||||
{
|
||||
problems.add( new ModelProblem( "Non-resolvable import POM " + toId( groupId, artifactId, version )
|
||||
+ " for POM " + toSourceHint( model ) + ": " + e.getMessage(), ModelProblem.Severity.ERROR,
|
||||
toSourceHint( model ), e ) );
|
||||
problems.add( new ModelProblem( "Non-resolvable import POM "
|
||||
+ ModelProblemUtils.toId( groupId, artifactId, version ) + " for POM "
|
||||
+ ModelProblemUtils.toSourceHint( model ) + ": " + e.getMessage(), ModelProblem.Severity.ERROR,
|
||||
ModelProblemUtils.toSourceHint( model ), e ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -703,7 +709,7 @@ public class DefaultModelBuilder
|
|||
return null;
|
||||
}
|
||||
|
||||
private void fireBuildExtensionsAssembled( Model model, ModelBuildingRequest request, List<ModelProblem> problems )
|
||||
private void fireBuildExtensionsAssembled( Model model, ModelBuildingRequest request, ModelBuildingProblems problems )
|
||||
throws ModelBuildingException
|
||||
{
|
||||
if ( request.getModelBuildingListeners().isEmpty() )
|
||||
|
@ -722,56 +728,9 @@ public class DefaultModelBuilder
|
|||
catch ( Exception e )
|
||||
{
|
||||
problems.add( new ModelProblem( "Invalid build extensions: " + e.getMessage(),
|
||||
ModelProblem.Severity.ERROR, toSourceHint( model ), e ) );
|
||||
ModelProblem.Severity.ERROR, ModelProblemUtils.toSourceHint( model ), e ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String toSourceHint( Model model )
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder( 192 );
|
||||
|
||||
buffer.append( toId( model ) );
|
||||
|
||||
File pomFile = model.getPomFile();
|
||||
if ( pomFile != null )
|
||||
{
|
||||
buffer.append( " (" ).append( pomFile ).append( ")" );
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private String toId( Model model )
|
||||
{
|
||||
String groupId = model.getGroupId();
|
||||
if ( groupId == null && model.getParent() != null )
|
||||
{
|
||||
groupId = model.getParent().getGroupId();
|
||||
}
|
||||
|
||||
String artifactId = model.getArtifactId();
|
||||
|
||||
String version = model.getVersion();
|
||||
if ( version == null && model.getParent() != null )
|
||||
{
|
||||
version = model.getParent().getVersion();
|
||||
}
|
||||
|
||||
return toId( groupId, artifactId, version );
|
||||
}
|
||||
|
||||
private String toId( String groupId, String artifactId, String version )
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder( 96 );
|
||||
|
||||
buffer.append( ( groupId != null ) ? groupId : "[unknown-group-id]" );
|
||||
buffer.append( ':' );
|
||||
buffer.append( ( artifactId != null ) ? artifactId : "[unknown-artifact-id]" );
|
||||
buffer.append( ':' );
|
||||
buffer.append( ( version != null ) ? version : "[unknown-version]" );
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
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.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Collects the problems that were encountered during model building.
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
*/
|
||||
class DefaultModelBuildingProblems
|
||||
implements ModelBuildingProblems
|
||||
{
|
||||
|
||||
private List<ModelProblem> problems;
|
||||
|
||||
public DefaultModelBuildingProblems( List<ModelProblem> problems )
|
||||
{
|
||||
this.problems = ( problems != null ) ? problems : new ArrayList<ModelProblem>();
|
||||
}
|
||||
|
||||
public List<ModelProblem> getProblems()
|
||||
{
|
||||
return problems;
|
||||
}
|
||||
|
||||
public void add( ModelProblem problem )
|
||||
{
|
||||
if ( problem == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "model problem missing" );
|
||||
}
|
||||
|
||||
problems.add( problem );
|
||||
}
|
||||
|
||||
public void addAll( Collection<ModelProblem> problems )
|
||||
{
|
||||
if ( problems == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "model problems missing" );
|
||||
}
|
||||
|
||||
for ( ModelProblem problem : problems )
|
||||
{
|
||||
add( problem );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
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.Collection;
|
||||
|
||||
/**
|
||||
* Collects the problems that are encountered during model building.
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
*/
|
||||
public interface ModelBuildingProblems
|
||||
{
|
||||
|
||||
/**
|
||||
* Adds the specified problem.
|
||||
*
|
||||
* @param problem The problem to add, must not be {@code null}.
|
||||
*/
|
||||
void add( ModelProblem problem );
|
||||
|
||||
/**
|
||||
* Adds the specified problems.
|
||||
*
|
||||
* @param problems The problems to add, must not be {@code null} nor contain {@code null} elements.
|
||||
*/
|
||||
void addAll( Collection<ModelProblem> problems );
|
||||
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
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.io.File;
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
|
||||
/**
|
||||
* Assists in the creation of model problems.
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
*/
|
||||
public class ModelProblemUtils
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates a user-friendly source hint for the specified model.
|
||||
*
|
||||
* @param model The model to create a source hint for, must not be {@code null}.
|
||||
* @return The user-friendly source hint, never {@code null}.
|
||||
*/
|
||||
public static String toSourceHint( Model model )
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder( 192 );
|
||||
|
||||
buffer.append( toId( model ) );
|
||||
|
||||
File pomFile = model.getPomFile();
|
||||
if ( pomFile != null )
|
||||
{
|
||||
buffer.append( " (" ).append( pomFile ).append( ")" );
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private static String toId( Model model )
|
||||
{
|
||||
String groupId = model.getGroupId();
|
||||
if ( groupId == null && model.getParent() != null )
|
||||
{
|
||||
groupId = model.getParent().getGroupId();
|
||||
}
|
||||
|
||||
String artifactId = model.getArtifactId();
|
||||
|
||||
String version = model.getVersion();
|
||||
if ( version == null && model.getParent() != null )
|
||||
{
|
||||
version = model.getParent().getVersion();
|
||||
}
|
||||
|
||||
return toId( groupId, artifactId, version );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a user-friendly artifact id from the specified coordinates.
|
||||
*
|
||||
* @param groupId The group id, may be {@code null}.
|
||||
* @param artifactId The artifact id, may be {@code null}.
|
||||
* @param version The version, may be {@code null}.
|
||||
* @return The user-friendly artifact id, never {@code null}.
|
||||
*/
|
||||
public static String toId( String groupId, String artifactId, String version )
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder( 96 );
|
||||
|
||||
buffer.append( ( groupId != null && groupId.length() > 0 ) ? groupId : "[unknown-group-id]" );
|
||||
buffer.append( ':' );
|
||||
buffer.append( ( artifactId != null && artifactId.length() > 0 ) ? artifactId : "[unknown-artifact-id]" );
|
||||
buffer.append( ':' );
|
||||
buffer.append( ( version != null && version.length() > 0 ) ? version : "[unknown-version]" );
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -20,6 +20,7 @@ package org.apache.maven.model.plugin;
|
|||
*/
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.building.ModelBuildingProblems;
|
||||
|
||||
/**
|
||||
* Handles injection of plugin executions induced by the lifecycle bindings for a packaging.
|
||||
|
@ -34,7 +35,8 @@ public interface LifecycleBindingsInjector
|
|||
*
|
||||
* @param model The model into which to inject the default plugin executions for its packaging, must not be
|
||||
* <code>null</code>.
|
||||
* @param problems The container used to collect problems that were encountered, must not be {@code null}.
|
||||
*/
|
||||
void injectLifecycleBindings( Model model );
|
||||
void injectLifecycleBindings( Model model, ModelBuildingProblems problems );
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue