mirror of https://github.com/apache/maven.git
Cleaning up exception wrapping to allow better reporting of errors to end users. Also implementing the beginnings of a new error reporter, and bumping the version of plexus-container-default up to 1.0-alpha-33-SNAPSHOT to improve the accessibility to ClassRealm info for ComponentLookupException.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@584343 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
957a77435a
commit
0d0f7396b2
|
@ -17,7 +17,7 @@
|
|||
|
||||
classworlds.version=1.2-alpha-10
|
||||
plexus-active-collections.version=1.0-beta-1
|
||||
plexus.version=1.0-alpha-32
|
||||
plexus.version=1.0-alpha-33-SNAPSHOT
|
||||
plexus-utils.version=1.4.5
|
||||
maven-artifact.version=3.0-SNAPSHOT
|
||||
commons-cli.version=1.0
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package org.apache.maven;
|
||||
|
||||
import org.apache.maven.lifecycle.MojoBindingUtils;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
|
||||
/**
|
||||
* Exception which occurs when an @aggregator plugin fails to execute. This
|
||||
* exception is meant to wrap a {@link MojoFailureException}, and provide
|
||||
* additional details about the mojo that failed, via {@link MojoBinding} and
|
||||
* the root directory in which the build executes.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
public class AggregatedBuildFailureException
|
||||
extends BuildFailureException
|
||||
{
|
||||
|
||||
private final String executionRootDirectory;
|
||||
private final MojoBinding binding;
|
||||
|
||||
public AggregatedBuildFailureException( String executionRootDirectory,
|
||||
MojoBinding binding,
|
||||
MojoFailureException cause )
|
||||
{
|
||||
super( "Build in root directory: " + executionRootDirectory
|
||||
+ " failed during execution of aggregator mojo: "
|
||||
+ MojoBindingUtils.toString( binding ), cause );
|
||||
|
||||
this.executionRootDirectory = executionRootDirectory;
|
||||
this.binding = binding;
|
||||
}
|
||||
|
||||
public MojoFailureException getMojoFailureException()
|
||||
{
|
||||
return (MojoFailureException) getCause();
|
||||
}
|
||||
|
||||
public String getExecutionRootDirectory()
|
||||
{
|
||||
return executionRootDirectory;
|
||||
}
|
||||
|
||||
public MojoBinding getBinding()
|
||||
{
|
||||
return binding;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package org.apache.maven;
|
||||
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -25,15 +26,15 @@ package org.apache.maven;
|
|||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class BuildFailureException
|
||||
public abstract class BuildFailureException
|
||||
extends Exception
|
||||
{
|
||||
public BuildFailureException( String message )
|
||||
protected BuildFailureException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
public BuildFailureException( String message, Throwable cause )
|
||||
protected BuildFailureException( String message, Throwable cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ import org.apache.maven.monitor.event.DefaultEventDispatcher;
|
|||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.monitor.event.MavenEvents;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
import org.apache.maven.profiles.activation.ProfileActivationException;
|
||||
import org.apache.maven.project.DuplicateProjectException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
|
@ -117,10 +116,14 @@ public class DefaultMaven
|
|||
request.setProjectPresent( false );
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
catch ( ProjectBuildingException e )
|
||||
{
|
||||
result.addException( e );
|
||||
|
||||
result.addProjectBuildingException( e );
|
||||
return null;
|
||||
}
|
||||
catch ( MavenExecutionException e )
|
||||
{
|
||||
result.addMavenExecutionException( e );
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -136,19 +139,18 @@ public class DefaultMaven
|
|||
}
|
||||
catch ( CycleDetectedException e )
|
||||
{
|
||||
result.addException(
|
||||
new BuildFailureException(
|
||||
"The projects in the reactor contain a cyclic reference: " + e.getMessage(),
|
||||
e ) );
|
||||
String message = "The projects in the reactor contain a cyclic reference: "
|
||||
+ e.getMessage();
|
||||
|
||||
ProjectCycleException error = new ProjectCycleException( projects, message, e );
|
||||
|
||||
result.addBuildFailureException( error );
|
||||
|
||||
return null;
|
||||
}
|
||||
catch ( DuplicateProjectException e )
|
||||
{
|
||||
result.addException(
|
||||
new BuildFailureException(
|
||||
e.getMessage(),
|
||||
e ) );
|
||||
result.addDuplicateProjectException( e );
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -192,7 +194,7 @@ public class DefaultMaven
|
|||
|
||||
if ( !tvr.isTaskValid() )
|
||||
{
|
||||
result.addException( new BuildFailureException( tvr.getMessage() ) );
|
||||
result.addBuildFailureException( new InvalidTaskException( tvr ) );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -223,12 +225,12 @@ public class DefaultMaven
|
|||
}
|
||||
catch ( LifecycleExecutionException e )
|
||||
{
|
||||
result.addException( e );
|
||||
result.addLifecycleExecutionException( e );
|
||||
return result;
|
||||
}
|
||||
catch ( BuildFailureException e )
|
||||
{
|
||||
result.addException( e );
|
||||
result.addBuildFailureException( e );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -258,7 +260,7 @@ public class DefaultMaven
|
|||
}
|
||||
|
||||
private List getProjects( MavenExecutionRequest request )
|
||||
throws MavenExecutionException, BuildFailureException
|
||||
throws MavenExecutionException
|
||||
{
|
||||
List projects;
|
||||
|
||||
|
@ -298,10 +300,6 @@ public class DefaultMaven
|
|||
{
|
||||
throw new MavenExecutionException( e.getMessage(), e );
|
||||
}
|
||||
catch ( ProfileActivationException e )
|
||||
{
|
||||
throw new MavenExecutionException( e.getMessage(), e );
|
||||
}
|
||||
return projects;
|
||||
}
|
||||
|
||||
|
@ -310,8 +308,7 @@ public class DefaultMaven
|
|||
boolean recursive,
|
||||
ProfileManager globalProfileManager,
|
||||
boolean isRoot )
|
||||
throws ArtifactResolutionException, ProjectBuildingException, ProfileActivationException,
|
||||
MavenExecutionException, BuildFailureException
|
||||
throws ArtifactResolutionException, ProjectBuildingException, MavenExecutionException
|
||||
{
|
||||
List projects = new ArrayList( files.size() );
|
||||
|
||||
|
@ -341,7 +338,7 @@ public class DefaultMaven
|
|||
|
||||
if ( runtimeInformation.getApplicationVersion().compareTo( version ) < 0 )
|
||||
{
|
||||
throw new BuildFailureException(
|
||||
throw new MavenExecutionException(
|
||||
"Unable to build project '" + project.getFile() +
|
||||
"; it requires Maven version " + version.toString() );
|
||||
}
|
||||
|
@ -396,13 +393,9 @@ public class DefaultMaven
|
|||
moduleFiles.add( moduleFile );
|
||||
}
|
||||
|
||||
List collectedProjects =
|
||||
collectProjects(
|
||||
moduleFiles,
|
||||
localRepository,
|
||||
recursive,
|
||||
globalProfileManager,
|
||||
false );
|
||||
List collectedProjects = collectProjects( moduleFiles, localRepository, recursive,
|
||||
globalProfileManager, false );
|
||||
|
||||
projects.addAll( collectedProjects );
|
||||
project.setCollectedProjects( collectedProjects );
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package org.apache.maven;
|
||||
|
||||
import org.apache.maven.lifecycle.TaskValidationResult;
|
||||
|
||||
/**
|
||||
* Exception which occurs when a task or goal is specified on the command line
|
||||
* but cannot be resolved for execution. This validation is done up front, and
|
||||
* this exception wraps the {@link TaskValidationResult} generated as a result
|
||||
* of verifying the task.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
public class InvalidTaskException
|
||||
extends BuildFailureException
|
||||
{
|
||||
|
||||
private final String task;
|
||||
|
||||
public InvalidTaskException( TaskValidationResult result )
|
||||
{
|
||||
super( result.getMessage(), result.getCause() );
|
||||
task = result.getInvalidTask();
|
||||
}
|
||||
|
||||
public String getTask()
|
||||
{
|
||||
return task;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package org.apache.maven;
|
||||
|
||||
/**
|
||||
* Exception indicating that Maven has no instructions for what to execute. This
|
||||
* happens when no goals are specified on the command line, and there is no
|
||||
* defaultGoal specified in the POM itself.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
public class NoGoalsSpecifiedException
|
||||
extends BuildFailureException
|
||||
{
|
||||
|
||||
public NoGoalsSpecifiedException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package org.apache.maven;
|
||||
|
||||
import org.apache.maven.lifecycle.MojoBindingUtils;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
|
||||
/**
|
||||
* Exception which occurs when a normal (i.e. non-aggregator) mojo fails to
|
||||
* execute. In this case, the mojo failed while executing against a particular
|
||||
* project instance, so we can wrap the {@link MojoFailureException} with context
|
||||
* information including projectId and the {@link MojoBinding} that caused the
|
||||
* failure.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
public class ProjectBuildFailureException
|
||||
extends BuildFailureException
|
||||
{
|
||||
|
||||
private final String projectId;
|
||||
private final MojoBinding binding;
|
||||
|
||||
public ProjectBuildFailureException( String projectId,
|
||||
MojoBinding binding,
|
||||
MojoFailureException cause )
|
||||
{
|
||||
super( "Build for project: " + projectId + " failed during execution of mojo: "
|
||||
+ MojoBindingUtils.toString( binding ), cause );
|
||||
|
||||
this.projectId = projectId;
|
||||
this.binding = binding;
|
||||
}
|
||||
|
||||
public MojoFailureException getMojoFailureException()
|
||||
{
|
||||
return (MojoFailureException) getCause();
|
||||
}
|
||||
|
||||
public String getProjectId()
|
||||
{
|
||||
return projectId;
|
||||
}
|
||||
|
||||
public MojoBinding getBinding()
|
||||
{
|
||||
return binding;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package org.apache.maven;
|
||||
|
||||
import org.apache.maven.execution.ReactorManager;
|
||||
import org.apache.maven.project.ProjectSorter;
|
||||
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Exception which occurs when creating a new {@link ReactorManager} instance,
|
||||
* due to failure to sort the current projects. The embedded {@link CycleDetectedException}
|
||||
* is thrown by the {@link ProjectSorter}, and context of this wrapped exception
|
||||
* includes the list of projects that contain the cycle, along with a friendly
|
||||
* rendering of the cycle message indicating that it comes from the current projects list.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
public class ProjectCycleException
|
||||
extends BuildFailureException
|
||||
{
|
||||
|
||||
private final List projects;
|
||||
|
||||
public ProjectCycleException( List projects, String message,
|
||||
CycleDetectedException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projects = projects;
|
||||
}
|
||||
|
||||
public List getProjects()
|
||||
{
|
||||
return projects;
|
||||
}
|
||||
|
||||
}
|
|
@ -19,8 +19,13 @@ package org.apache.maven.execution;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.BuildFailureException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.lifecycle.LifecycleExecutionException;
|
||||
import org.apache.maven.project.DuplicateProjectException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.reactor.MavenExecutionException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -80,7 +85,49 @@ public class DefaultMavenExecutionResult
|
|||
return exceptions;
|
||||
}
|
||||
|
||||
public MavenExecutionResult addException( Throwable t )
|
||||
public MavenExecutionResult addProjectBuildingException( ProjectBuildingException e )
|
||||
{
|
||||
addException( e );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MavenExecutionResult addMavenExecutionException( MavenExecutionException e )
|
||||
{
|
||||
addException( e );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MavenExecutionResult addBuildFailureException( BuildFailureException e )
|
||||
{
|
||||
addException( e );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MavenExecutionResult addDuplicateProjectException( DuplicateProjectException e )
|
||||
{
|
||||
addException( e );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MavenExecutionResult addLifecycleExecutionException( LifecycleExecutionException e )
|
||||
{
|
||||
addException( e );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MavenExecutionResult addUnknownException( Throwable t )
|
||||
{
|
||||
addException( t );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private void addException( Throwable t )
|
||||
{
|
||||
if ( exceptions == null )
|
||||
{
|
||||
|
@ -88,13 +135,11 @@ public class DefaultMavenExecutionResult
|
|||
}
|
||||
|
||||
exceptions.add( t );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean hasExceptions()
|
||||
{
|
||||
return (exceptions != null && exceptions.size() > 0 );
|
||||
return (( exceptions != null ) && ( exceptions.size() > 0 ) );
|
||||
}
|
||||
|
||||
public ReactorManager getReactorManager()
|
||||
|
|
|
@ -19,8 +19,13 @@ package org.apache.maven.execution;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.BuildFailureException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.lifecycle.LifecycleExecutionException;
|
||||
import org.apache.maven.project.DuplicateProjectException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.reactor.MavenExecutionException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -47,6 +52,13 @@ public interface MavenExecutionResult
|
|||
// - invalid project model exception: list of markers
|
||||
// - xmlpull parser exception
|
||||
List getExceptions();
|
||||
MavenExecutionResult addException( Throwable t );
|
||||
|
||||
MavenExecutionResult addLifecycleExecutionException( LifecycleExecutionException e );
|
||||
MavenExecutionResult addDuplicateProjectException( DuplicateProjectException duplicateProjectException );
|
||||
MavenExecutionResult addBuildFailureException( BuildFailureException buildFailureException );
|
||||
MavenExecutionResult addMavenExecutionException( MavenExecutionException e );
|
||||
MavenExecutionResult addProjectBuildingException (ProjectBuildingException e );
|
||||
MavenExecutionResult addUnknownException( Throwable t );
|
||||
|
||||
boolean hasExceptions();
|
||||
}
|
||||
|
|
|
@ -19,12 +19,14 @@ package org.apache.maven.lifecycle;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.AggregatedBuildFailureException;
|
||||
import org.apache.maven.BuildFailureException;
|
||||
import org.apache.maven.NoGoalsSpecifiedException;
|
||||
import org.apache.maven.ProjectBuildFailureException;
|
||||
import org.apache.maven.artifact.handler.ArtifactHandler;
|
||||
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.context.BuildContextManager;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.execution.ReactorManager;
|
||||
|
@ -101,6 +103,7 @@ public class DefaultLifecycleExecutor
|
|||
* @param session
|
||||
* @param reactorManager
|
||||
* @param dispatcher
|
||||
* @throws MojoFailureException
|
||||
*/
|
||||
public void execute( final MavenSession session,
|
||||
final ReactorManager reactorManager,
|
||||
|
@ -125,7 +128,7 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
if ( goals.isEmpty() )
|
||||
{
|
||||
throw new BuildFailureException( "You must specify at least one goal. Try 'install'" );
|
||||
throw new NoGoalsSpecifiedException( "You must specify at least one goal. Try 'install'" );
|
||||
}
|
||||
|
||||
List taskSegments = segmentTaskListByAggregationNeeds(
|
||||
|
@ -143,7 +146,7 @@ public class DefaultLifecycleExecutor
|
|||
catch ( PluginNotFoundException e )
|
||||
{
|
||||
throw new LifecycleExecutionException(
|
||||
e.getMessage(),
|
||||
"Plugin could not be not found while searching for artifact-type handlers.",
|
||||
e );
|
||||
}
|
||||
|
||||
|
@ -210,6 +213,8 @@ public class DefaultLifecycleExecutor
|
|||
{
|
||||
MojoBinding binding = (MojoBinding) mojoIterator.next();
|
||||
|
||||
try
|
||||
{
|
||||
executeGoalAndHandleFailures(
|
||||
binding,
|
||||
session,
|
||||
|
@ -219,6 +224,21 @@ public class DefaultLifecycleExecutor
|
|||
buildStartTime,
|
||||
target );
|
||||
}
|
||||
catch ( MojoFailureException e )
|
||||
{
|
||||
AggregatedBuildFailureException error = new AggregatedBuildFailureException(
|
||||
session.getExecutionRootDirectory(),
|
||||
binding,
|
||||
e );
|
||||
|
||||
dispatcher.dispatchError( event, target, error );
|
||||
|
||||
if ( handleExecutionFailure( reactorManager, rootProject, error, binding, buildStartTime ) )
|
||||
{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// clean up the execution context, so we don't pollute for future project-executions.
|
||||
LifecycleExecutionContext.delete( buildContextManager );
|
||||
|
@ -285,19 +305,32 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
for ( Iterator mojoIterator = mojoBindings.iterator(); mojoIterator.hasNext(); )
|
||||
{
|
||||
MojoBinding mojoBinding = (MojoBinding) mojoIterator.next();
|
||||
MojoBinding binding = (MojoBinding) mojoIterator.next();
|
||||
|
||||
getLogger().debug(
|
||||
"Mojo: " + mojoBinding.getGoal() + " has config:\n"
|
||||
+ mojoBinding.getConfiguration() );
|
||||
executeGoalAndHandleFailures(
|
||||
mojoBinding,
|
||||
session,
|
||||
dispatcher,
|
||||
event,
|
||||
reactorManager,
|
||||
buildStartTime,
|
||||
target );
|
||||
"Mojo: " + binding.getGoal() + " has config:\n"
|
||||
+ binding.getConfiguration() );
|
||||
|
||||
try
|
||||
{
|
||||
executeGoalAndHandleFailures( binding, session, dispatcher,
|
||||
event, reactorManager,
|
||||
buildStartTime, target );
|
||||
}
|
||||
catch ( MojoFailureException e )
|
||||
{
|
||||
ProjectBuildFailureException error = new ProjectBuildFailureException(
|
||||
currentProject.getId(),
|
||||
binding,
|
||||
e );
|
||||
|
||||
dispatcher.dispatchError( event, target, error );
|
||||
|
||||
if ( handleExecutionFailure( reactorManager, currentProject, error, binding, buildStartTime ) )
|
||||
{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LifecycleExecutionContext.delete( buildContextManager );
|
||||
|
@ -373,7 +406,7 @@ public class DefaultLifecycleExecutor
|
|||
final ReactorManager rm,
|
||||
final long buildStartTime,
|
||||
final String target )
|
||||
throws BuildFailureException, LifecycleExecutionException
|
||||
throws LifecycleExecutionException, MojoFailureException
|
||||
{
|
||||
// NEW: Retrieve/use the current project stored in the execution context, for consistency.
|
||||
LifecycleExecutionContext ctx = LifecycleExecutionContext.read( buildContextManager );
|
||||
|
@ -446,12 +479,6 @@ public class DefaultLifecycleExecutor
|
|||
e.getMessage(),
|
||||
e );
|
||||
}
|
||||
catch ( MojoFailureException e )
|
||||
{
|
||||
throw new BuildFailureException(
|
||||
e.getMessage(),
|
||||
e );
|
||||
}
|
||||
catch ( MojoExecutionException e )
|
||||
{
|
||||
throw new LifecycleExecutionException(
|
||||
|
@ -474,34 +501,9 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
catch ( LifecycleExecutionException e )
|
||||
{
|
||||
dispatcher.dispatchError(
|
||||
event,
|
||||
target,
|
||||
e );
|
||||
dispatcher.dispatchError( event, target, e );
|
||||
|
||||
if ( handleExecutionFailure(
|
||||
rm,
|
||||
project,
|
||||
e,
|
||||
mojoBinding,
|
||||
buildStartTime ) )
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
catch ( BuildFailureException e )
|
||||
{
|
||||
dispatcher.dispatchError(
|
||||
event,
|
||||
target,
|
||||
e );
|
||||
|
||||
if ( handleExecutionFailure(
|
||||
rm,
|
||||
project,
|
||||
e,
|
||||
mojoBinding,
|
||||
buildStartTime ) )
|
||||
if ( handleExecutionFailure( rm, project, e, mojoBinding, buildStartTime ) )
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
|
@ -542,13 +544,13 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
if ( rootProject != null )
|
||||
{
|
||||
|
||||
if ( !LifecycleUtils.isValidPhaseName( task ) )
|
||||
{
|
||||
MojoDescriptor mojo = null;
|
||||
// definitely a CLI goal, can use prefix
|
||||
try
|
||||
{
|
||||
mojo = getMojoDescriptorForDirectInvocation(
|
||||
getMojoDescriptorForDirectInvocation(
|
||||
task,
|
||||
session,
|
||||
rootProject );
|
||||
|
@ -595,7 +597,6 @@ public class DefaultLifecycleExecutor
|
|||
private List segmentTaskListByAggregationNeeds( final List tasks,
|
||||
final MavenSession session,
|
||||
final MavenProject rootProject )
|
||||
throws LifecycleExecutionException, BuildFailureException
|
||||
{
|
||||
List segments = new ArrayList();
|
||||
|
||||
|
@ -782,12 +783,6 @@ public class DefaultLifecycleExecutor
|
|||
e.getMessage(),
|
||||
e );
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new LifecycleExecutionException(
|
||||
e.getMessage(),
|
||||
e );
|
||||
}
|
||||
catch ( InvalidPluginException e )
|
||||
{
|
||||
throw new LifecycleExecutionException(
|
||||
|
|
|
@ -1,5 +1,18 @@
|
|||
package org.apache.maven.lifecycle;
|
||||
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.plugin.InvalidPluginException;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.PluginConfigurationException;
|
||||
import org.apache.maven.plugin.PluginManagerException;
|
||||
import org.apache.maven.plugin.PluginNotFoundException;
|
||||
import org.apache.maven.plugin.loader.PluginLoaderException;
|
||||
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
|
||||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -31,13 +44,82 @@ public class LifecycleExecutionException
|
|||
super( message );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( Throwable cause )
|
||||
{
|
||||
super( cause );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message, Throwable cause )
|
||||
public LifecycleExecutionException( String message,
|
||||
PluginManagerException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message,
|
||||
PluginNotFoundException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message,
|
||||
PluginVersionResolutionException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message,
|
||||
InvalidVersionSpecificationException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message,
|
||||
InvalidPluginException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message,
|
||||
ArtifactNotFoundException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message,
|
||||
ArtifactResolutionException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message,
|
||||
PluginLoaderException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message,
|
||||
LifecycleException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message,
|
||||
InvalidDependencyVersionException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message,
|
||||
MojoExecutionException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message,
|
||||
PluginConfigurationException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public LifecycleExecutionException( String message,
|
||||
PluginVersionNotFoundException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@ package org.apache.maven.lifecycle;
|
|||
*/
|
||||
|
||||
import org.apache.maven.BuildFailureException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.execution.ReactorManager;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
|
|
|
@ -5,6 +5,8 @@ public class TaskValidationResult
|
|||
{
|
||||
private String invalidTask;
|
||||
|
||||
private Throwable cause;
|
||||
|
||||
private String message;
|
||||
|
||||
public TaskValidationResult()
|
||||
|
@ -14,10 +16,16 @@ public class TaskValidationResult
|
|||
public TaskValidationResult( String invalidTask, String message )
|
||||
{
|
||||
this.invalidTask = invalidTask;
|
||||
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public TaskValidationResult( String invalidTask, String message, Throwable cause )
|
||||
{
|
||||
this.message = message;
|
||||
this.cause = cause;
|
||||
this.invalidTask = invalidTask;
|
||||
}
|
||||
|
||||
public String getInvalidTask()
|
||||
{
|
||||
return invalidTask;
|
||||
|
@ -28,6 +36,11 @@ public class TaskValidationResult
|
|||
return message;
|
||||
}
|
||||
|
||||
public Throwable getCause()
|
||||
{
|
||||
return cause;
|
||||
}
|
||||
|
||||
public boolean isTaskValid()
|
||||
{
|
||||
return invalidTask == null;
|
||||
|
|
|
@ -166,7 +166,7 @@ public class DefaultPluginManager
|
|||
MavenProject project,
|
||||
MavenSession session )
|
||||
throws ArtifactResolutionException, PluginVersionResolutionException,
|
||||
ArtifactNotFoundException, InvalidVersionSpecificationException, InvalidPluginException,
|
||||
ArtifactNotFoundException, InvalidPluginException,
|
||||
PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException
|
||||
{
|
||||
// TODO: this should be possibly outside
|
||||
|
@ -187,7 +187,7 @@ public class DefaultPluginManager
|
|||
MavenProject project,
|
||||
MavenSession session )
|
||||
throws PluginVersionResolutionException, ArtifactNotFoundException,
|
||||
ArtifactResolutionException, InvalidVersionSpecificationException, InvalidPluginException,
|
||||
ArtifactResolutionException, InvalidPluginException,
|
||||
PluginManagerException, PluginNotFoundException
|
||||
{
|
||||
ArtifactRepository localRepository = session.getLocalRepository();
|
||||
|
@ -199,7 +199,7 @@ public class DefaultPluginManager
|
|||
MavenProject project,
|
||||
ArtifactRepository localRepository )
|
||||
throws PluginVersionResolutionException, ArtifactNotFoundException,
|
||||
ArtifactResolutionException, InvalidVersionSpecificationException, InvalidPluginException,
|
||||
ArtifactResolutionException, InvalidPluginException,
|
||||
PluginManagerException, PluginNotFoundException
|
||||
{
|
||||
getLogger().debug( "In verifyVersionedPlugin for: " + plugin.getKey() );
|
||||
|
@ -213,7 +213,15 @@ public class DefaultPluginManager
|
|||
// if the groupId is internal, don't try to resolve it...
|
||||
if ( !RESERVED_GROUP_IDS.contains( plugin.getGroupId() ) )
|
||||
{
|
||||
VersionRange versionRange = VersionRange.createFromVersionSpec( plugin.getVersion() );
|
||||
VersionRange versionRange;
|
||||
try
|
||||
{
|
||||
versionRange = VersionRange.createFromVersionSpec( plugin.getVersion() );
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new PluginManagerException( plugin, e );
|
||||
}
|
||||
|
||||
List remoteRepositories = new ArrayList();
|
||||
|
||||
|
@ -257,12 +265,12 @@ public class DefaultPluginManager
|
|||
|
||||
if ( ( groupId == null ) || ( artifactId == null ) || ( version == null ) )
|
||||
{
|
||||
throw new PluginNotFoundException( e );
|
||||
throw new PluginNotFoundException( plugin, e );
|
||||
}
|
||||
else if ( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId() )
|
||||
&& version.equals( e.getVersion() ) && "maven-plugin".equals( e.getType() ) )
|
||||
{
|
||||
throw new PluginNotFoundException( e );
|
||||
throw new PluginNotFoundException( plugin, e );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -412,12 +420,12 @@ public class DefaultPluginManager
|
|||
|
||||
componentRealm = container.createComponentRealm( projectPlugin.getKey(), jars );
|
||||
|
||||
String parentRealmId = componentRealm.getParentRealm().getId();
|
||||
|
||||
// adding for MNG-3012 to try to work around problems with Xpp3Dom (from plexus-utils)
|
||||
// spawning a ClassCastException when a mojo calls plugin.getConfiguration() from maven-model...
|
||||
componentRealm.importFrom( componentRealm.getParentRealm().getId(),
|
||||
Xpp3Dom.class.getName() );
|
||||
componentRealm.importFrom( componentRealm.getParentRealm().getId(),
|
||||
"org.codehaus.plexus.util.xml.pull" );
|
||||
componentRealm.importFrom( parentRealmId, Xpp3Dom.class.getName() );
|
||||
componentRealm.importFrom( parentRealmId, "org.codehaus.plexus.util.xml.pull" );
|
||||
|
||||
// Adding for MNG-2878, since maven-reporting-impl was removed from the
|
||||
// internal list of artifacts managed by maven, the classloader is different
|
||||
|
@ -425,17 +433,17 @@ public class DefaultPluginManager
|
|||
// is not available from the AbstractMavenReport since it uses:
|
||||
// getClass().getResourceAsStream( "/default-report.xml" )
|
||||
// (maven-reporting-impl version 2.0; line 134; affects: checkstyle plugin, and probably others)
|
||||
componentRealm.importFrom( componentRealm.getParentRealm().getId(), "/default-report.xml" );
|
||||
componentRealm.importFrom( parentRealmId, "/default-report.xml" );
|
||||
}
|
||||
catch ( PlexusContainerException e )
|
||||
{
|
||||
throw new PluginManagerException( "Failed to create realm for plugin '" + projectPlugin
|
||||
throw new PluginContainerException( plugin, componentRealm, "Failed to create realm for plugin '" + projectPlugin
|
||||
+ ".", e );
|
||||
}
|
||||
catch ( NoSuchRealmException e )
|
||||
{
|
||||
throw new PluginManagerException(
|
||||
"Failed to import Xpp3Dom from parent realm for plugin: '"
|
||||
throw new PluginContainerException( plugin, componentRealm,
|
||||
"Failed to import Xpp3Dom from core realm for plugin: '"
|
||||
+ projectPlugin + ".", e );
|
||||
}
|
||||
|
||||
|
@ -716,7 +724,7 @@ public class DefaultPluginManager
|
|||
MavenProject project,
|
||||
MavenSession session )
|
||||
throws PluginVersionResolutionException, ArtifactResolutionException,
|
||||
ArtifactNotFoundException, InvalidVersionSpecificationException, InvalidPluginException,
|
||||
ArtifactNotFoundException, InvalidPluginException,
|
||||
PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException
|
||||
{
|
||||
String version = reportPlugin.getVersion();
|
||||
|
@ -759,8 +767,6 @@ public class DefaultPluginManager
|
|||
|
||||
Mojo plugin;
|
||||
|
||||
try
|
||||
{
|
||||
ClassRealm realm = mojoDescriptor.getPluginDescriptor().getClassRealm();
|
||||
|
||||
// We are forcing the use of the plugin realm for all lookups that might occur during
|
||||
|
@ -776,7 +782,16 @@ public class DefaultPluginManager
|
|||
+ realm.getId() + " - descRealmId="
|
||||
+ mojoDescriptor.getRealmId() );
|
||||
|
||||
try
|
||||
{
|
||||
plugin = (Mojo) container.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint(), realm );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new PluginContainerException( mojoDescriptor, realm, "Unable to find the mojo '"
|
||||
+ mojoDescriptor.getRoleHint() + "' in the plugin '"
|
||||
+ pluginDescriptor.getPluginLookupKey() + "'", e );
|
||||
}
|
||||
|
||||
if ( plugin != null )
|
||||
{
|
||||
|
@ -799,7 +814,16 @@ public class DefaultPluginManager
|
|||
+ container.getLookupRealm() + " - descRealmId="
|
||||
+ mojoDescriptor.getRealmId() );
|
||||
|
||||
try
|
||||
{
|
||||
plugin = (Mojo) container.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new PluginContainerException( mojoDescriptor, container.getContainerRealm(), "Unable to find the mojo '"
|
||||
+ mojoDescriptor.getRoleHint() + "' in the plugin '"
|
||||
+ pluginDescriptor.getPluginLookupKey() + "' (using core class realm)", e );
|
||||
}
|
||||
|
||||
if ( plugin != null )
|
||||
{
|
||||
|
@ -819,13 +843,6 @@ public class DefaultPluginManager
|
|||
// TODO: the mojoDescriptor should actually capture this information so we don't get this far
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new PluginManagerException( "Unable to find the mojo '"
|
||||
+ mojoDescriptor.getRoleHint() + "' in the plugin '"
|
||||
+ pluginDescriptor.getPluginLookupKey() + "'", e );
|
||||
}
|
||||
|
||||
if ( plugin instanceof ContextEnabled )
|
||||
{
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package org.apache.maven.plugin;
|
||||
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -28,8 +31,14 @@ package org.apache.maven.plugin;
|
|||
public class InvalidPluginException
|
||||
extends Exception
|
||||
{
|
||||
public InvalidPluginException( String message, Exception e )
|
||||
public InvalidPluginException( String message, ProjectBuildingException e )
|
||||
{
|
||||
super( message, e );
|
||||
}
|
||||
|
||||
public InvalidPluginException( String message, InvalidDependencyVersionException e )
|
||||
{
|
||||
super( message, e );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@ package org.apache.maven.plugin;
|
|||
*/
|
||||
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
|
||||
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
|
@ -44,9 +47,29 @@ public class PluginConfigurationException
|
|||
public PluginConfigurationException(
|
||||
PluginDescriptor pluginDescriptor,
|
||||
String originalMessage,
|
||||
Throwable e )
|
||||
ExpressionEvaluationException cause )
|
||||
{
|
||||
super( e );
|
||||
super( cause );
|
||||
this.pluginDescriptor = pluginDescriptor;
|
||||
this.originalMessage = originalMessage;
|
||||
}
|
||||
|
||||
public PluginConfigurationException(
|
||||
PluginDescriptor pluginDescriptor,
|
||||
String originalMessage,
|
||||
ComponentConfigurationException cause )
|
||||
{
|
||||
super( cause );
|
||||
this.pluginDescriptor = pluginDescriptor;
|
||||
this.originalMessage = originalMessage;
|
||||
}
|
||||
|
||||
public PluginConfigurationException(
|
||||
PluginDescriptor pluginDescriptor,
|
||||
String originalMessage,
|
||||
ComponentLookupException cause )
|
||||
{
|
||||
super( cause );
|
||||
this.pluginDescriptor = pluginDescriptor;
|
||||
this.originalMessage = originalMessage;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package org.apache.maven.plugin;
|
||||
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.codehaus.plexus.PlexusContainerException;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
|
||||
/**
|
||||
* Exception which occurs to indicate that the plugin cannot be initialized due
|
||||
* to some deeper problem with Plexus. Context information includes the groupId,
|
||||
* artifactId, and version for the plugin; at times, the goal name for which
|
||||
* execution failed; a message detailing the problem; the ClassRealm used to
|
||||
* lookup the plugin; and the Plexus exception that caused this error.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
public class PluginContainerException
|
||||
extends PluginManagerException
|
||||
{
|
||||
|
||||
private final ClassRealm pluginRealm;
|
||||
|
||||
public PluginContainerException( MojoDescriptor mojoDescriptor,
|
||||
ClassRealm pluginRealm,
|
||||
String message,
|
||||
ComponentLookupException e )
|
||||
{
|
||||
super( mojoDescriptor, message, e );
|
||||
|
||||
this.pluginRealm = pluginRealm;
|
||||
}
|
||||
|
||||
public PluginContainerException( Plugin plugin,
|
||||
ClassRealm pluginRealm,
|
||||
String message,
|
||||
NoSuchRealmException e )
|
||||
{
|
||||
super( plugin, message, e );
|
||||
|
||||
this.pluginRealm = pluginRealm;
|
||||
}
|
||||
|
||||
public PluginContainerException( Plugin plugin,
|
||||
ClassRealm pluginRealm,
|
||||
String message,
|
||||
PlexusContainerException e )
|
||||
{
|
||||
super( plugin, message, e );
|
||||
|
||||
this.pluginRealm = pluginRealm;
|
||||
}
|
||||
|
||||
public ClassRealm getPluginRealm()
|
||||
{
|
||||
return pluginRealm;
|
||||
}
|
||||
}
|
|
@ -19,10 +19,8 @@ package org.apache.maven.plugin;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.ReportPlugin;
|
||||
|
@ -32,7 +30,6 @@ import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
|||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.reporting.MavenReport;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -67,14 +64,14 @@ public interface PluginManager
|
|||
MavenProject project,
|
||||
MavenSession session )
|
||||
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
|
||||
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
|
||||
InvalidPluginException, PluginManagerException, PluginNotFoundException,
|
||||
PluginVersionNotFoundException;
|
||||
|
||||
PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin,
|
||||
MavenProject project,
|
||||
MavenSession session )
|
||||
throws PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException,
|
||||
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
|
||||
InvalidPluginException, PluginManagerException, PluginNotFoundException,
|
||||
PluginVersionNotFoundException;
|
||||
|
||||
Object getPluginComponent( Plugin plugin,
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
package org.apache.maven.plugin;
|
||||
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.codehaus.plexus.PlexusContainerException;
|
||||
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -28,13 +35,74 @@ package org.apache.maven.plugin;
|
|||
public class PluginManagerException
|
||||
extends Exception
|
||||
{
|
||||
public PluginManagerException( String message )
|
||||
|
||||
private final String pluginGroupId;
|
||||
|
||||
private final String pluginArtifactId;
|
||||
|
||||
private final String pluginVersion;
|
||||
|
||||
private String goal;
|
||||
|
||||
protected PluginManagerException( Plugin plugin,
|
||||
String message,
|
||||
PlexusContainerException cause )
|
||||
{
|
||||
super( message );
|
||||
super( message, cause );
|
||||
|
||||
pluginGroupId = plugin.getGroupId();
|
||||
pluginArtifactId = plugin.getArtifactId();
|
||||
pluginVersion = plugin.getVersion();
|
||||
}
|
||||
|
||||
public PluginManagerException( String message, Exception e )
|
||||
protected PluginManagerException( Plugin plugin, String message,
|
||||
NoSuchRealmException cause )
|
||||
{
|
||||
super( message, e );
|
||||
super( message, cause );
|
||||
|
||||
pluginGroupId = plugin.getGroupId();
|
||||
pluginArtifactId = plugin.getArtifactId();
|
||||
pluginVersion = plugin.getVersion();
|
||||
}
|
||||
|
||||
protected PluginManagerException( MojoDescriptor mojoDescriptor,
|
||||
String message,
|
||||
ComponentLookupException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
|
||||
pluginArtifactId = mojoDescriptor.getPluginDescriptor().getArtifactId();
|
||||
pluginVersion = mojoDescriptor.getPluginDescriptor().getVersion();
|
||||
goal = mojoDescriptor.getGoal();
|
||||
}
|
||||
|
||||
public PluginManagerException( Plugin plugin,
|
||||
InvalidVersionSpecificationException cause )
|
||||
{
|
||||
super( cause );
|
||||
|
||||
pluginGroupId = plugin.getGroupId();
|
||||
pluginArtifactId = plugin.getArtifactId();
|
||||
pluginVersion = plugin.getVersion();
|
||||
}
|
||||
|
||||
public String getPluginGroupId()
|
||||
{
|
||||
return pluginGroupId;
|
||||
}
|
||||
|
||||
public String getPluginArtifactId()
|
||||
{
|
||||
return pluginArtifactId;
|
||||
}
|
||||
|
||||
public String getPluginVersion()
|
||||
{
|
||||
return pluginVersion;
|
||||
}
|
||||
|
||||
public String getGoal()
|
||||
{
|
||||
return goal;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.maven.plugin;
|
|||
|
||||
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.model.Plugin;
|
||||
|
||||
/**
|
||||
* Exception occurring trying to resolve a plugin.
|
||||
|
@ -31,9 +32,17 @@ import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
|||
public class PluginNotFoundException
|
||||
extends AbstractArtifactResolutionException
|
||||
{
|
||||
public PluginNotFoundException( ArtifactNotFoundException e )
|
||||
private final Plugin plugin;
|
||||
|
||||
public PluginNotFoundException( Plugin plugin, ArtifactNotFoundException e )
|
||||
{
|
||||
super( "Plugin could not be found - check that the goal name is correct: " + e.getMessage(), e.getGroupId(),
|
||||
e.getArtifactId(), e.getVersion(), "maven-plugin",null, e.getRemoteRepositories(), null, e.getCause() );
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public Plugin getPlugin()
|
||||
{
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,16 +44,6 @@ public class PluginParameterException
|
|||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public PluginParameterException( MojoDescriptor mojo, List parameters, Throwable cause )
|
||||
{
|
||||
super( mojo.getPluginDescriptor(),
|
||||
"Invalid or missing parameters: " + parameters + " for mojo: " + mojo.getRoleHint(), cause );
|
||||
|
||||
this.mojo = mojo;
|
||||
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public MojoDescriptor getMojoDescriptor()
|
||||
{
|
||||
return mojo;
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.apache.maven.plugin.loader;
|
|||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.context.BuildContextManager;
|
||||
import org.apache.maven.execution.SessionContext;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
|
@ -66,7 +65,7 @@ public class DefaultPluginLoader
|
|||
{
|
||||
Throwable cause = e.getCause();
|
||||
|
||||
if ( cause != null && ( cause instanceof ComponentLookupException ) )
|
||||
if ( ( cause != null ) && ( cause instanceof ComponentLookupException ) )
|
||||
{
|
||||
StringBuffer message = new StringBuffer();
|
||||
message.append( "ComponentLookupException in PluginManager while looking up a component in the realm of: " );
|
||||
|
@ -254,10 +253,6 @@ public class DefaultPluginLoader
|
|||
{
|
||||
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
|
||||
}
|
||||
catch ( InvalidPluginException e )
|
||||
{
|
||||
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
|
||||
|
@ -328,10 +323,6 @@ public class DefaultPluginLoader
|
|||
{
|
||||
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
|
||||
}
|
||||
catch ( InvalidPluginException e )
|
||||
{
|
||||
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
package org.apache.maven.plugin.loader;
|
||||
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.ReportPlugin;
|
||||
import org.apache.maven.plugin.InvalidPluginException;
|
||||
import org.apache.maven.plugin.PluginManagerException;
|
||||
import org.apache.maven.plugin.PluginNotFoundException;
|
||||
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
|
||||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
||||
|
||||
/**
|
||||
* Signifies a failure to load a plugin. This is used to abstract the specific errors which may be
|
||||
|
@ -16,16 +24,58 @@ public class PluginLoaderException
|
|||
|
||||
private String pluginKey;
|
||||
|
||||
public PluginLoaderException( Plugin plugin, String message, Throwable cause )
|
||||
public PluginLoaderException( Plugin plugin, String message, ArtifactResolutionException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.pluginKey = plugin.getKey();
|
||||
pluginKey = plugin.getKey();
|
||||
}
|
||||
|
||||
public PluginLoaderException( Plugin plugin, String message, ArtifactNotFoundException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
pluginKey = plugin.getKey();
|
||||
}
|
||||
|
||||
public PluginLoaderException( Plugin plugin, String message, PluginNotFoundException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
pluginKey = plugin.getKey();
|
||||
}
|
||||
|
||||
public PluginLoaderException( Plugin plugin, String message, PluginVersionResolutionException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
pluginKey = plugin.getKey();
|
||||
}
|
||||
|
||||
public PluginLoaderException( Plugin plugin, String message, InvalidVersionSpecificationException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
pluginKey = plugin.getKey();
|
||||
}
|
||||
|
||||
public PluginLoaderException( Plugin plugin, String message, InvalidPluginException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
pluginKey = plugin.getKey();
|
||||
}
|
||||
|
||||
public PluginLoaderException( Plugin plugin, String message, PluginManagerException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
pluginKey = plugin.getKey();
|
||||
}
|
||||
|
||||
public PluginLoaderException( Plugin plugin, String message, PluginVersionNotFoundException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
pluginKey = plugin.getKey();
|
||||
}
|
||||
|
||||
public PluginLoaderException( Plugin plugin, String message )
|
||||
{
|
||||
super( message );
|
||||
this.pluginKey = plugin.getKey();
|
||||
pluginKey = plugin.getKey();
|
||||
}
|
||||
|
||||
public PluginLoaderException( String message )
|
||||
|
@ -41,13 +91,13 @@ public class PluginLoaderException
|
|||
public PluginLoaderException( ReportPlugin plugin, String message, Throwable cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.pluginKey = plugin.getKey();
|
||||
pluginKey = plugin.getKey();
|
||||
}
|
||||
|
||||
public PluginLoaderException( ReportPlugin plugin, String message )
|
||||
{
|
||||
super( message );
|
||||
this.pluginKey = plugin.getKey();
|
||||
pluginKey = plugin.getKey();
|
||||
}
|
||||
|
||||
public String getPluginKey()
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package org.apache.maven.plugin.version;
|
||||
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -47,7 +50,16 @@ public class PluginVersionResolutionException
|
|||
|
||||
private final String baseMessage;
|
||||
|
||||
public PluginVersionResolutionException( String groupId, String artifactId, String baseMessage, Throwable cause )
|
||||
public PluginVersionResolutionException( String groupId, String artifactId, String baseMessage, ArtifactMetadataRetrievalException cause )
|
||||
{
|
||||
super( "Error resolving version for \'" + groupId + ":" + artifactId + "\': " + baseMessage, cause );
|
||||
|
||||
this.groupId = groupId;
|
||||
this.artifactId = artifactId;
|
||||
this.baseMessage = baseMessage;
|
||||
}
|
||||
|
||||
public PluginVersionResolutionException( String groupId, String artifactId, String baseMessage, InvalidVersionSpecificationException cause )
|
||||
{
|
||||
super( "Error resolving version for \'" + groupId + ":" + artifactId + "\': " + baseMessage, cause );
|
||||
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
package org.apache.maven.reactor;
|
||||
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.extension.ExtensionScanningException;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -59,7 +65,22 @@ public class MavenExecutionException
|
|||
super( cause );
|
||||
}
|
||||
|
||||
public MavenExecutionException( String message, Throwable cause )
|
||||
public MavenExecutionException( String message, IOException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public MavenExecutionException( String message, ProjectBuildingException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public MavenExecutionException( String message, ArtifactResolutionException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public MavenExecutionException( String message, ExtensionScanningException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
|
|
@ -245,4 +245,21 @@ under the License.
|
|||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<!--
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/TestEmbedderLogger.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
-->
|
||||
</project>
|
||||
|
|
|
@ -92,66 +92,52 @@ public class CLIManager
|
|||
{
|
||||
options = new Options();
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "file" ).hasArg().withDescription(
|
||||
"Force the use of an alternate POM file." ).create( ALTERNATE_POM_FILE ) );
|
||||
options.addOption( OptionBuilder.hasArg( true ).create( ALTERNATE_POM_FILE ) );
|
||||
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "define" ).hasArg().withDescription( "Define a system property" ).create(
|
||||
OptionBuilder.hasArg( true ).create(
|
||||
SET_SYSTEM_PROPERTY ) );
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "offline" ).withDescription( "Work offline" ).create( OFFLINE ) );
|
||||
OptionBuilder.create( OFFLINE ) );
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "help" ).withDescription( "Display help information" ).create( HELP ) );
|
||||
OptionBuilder.create( HELP ) );
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "version" ).withDescription( "Display version information" ).create(
|
||||
OptionBuilder.create(
|
||||
VERSION ) );
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "quiet" ).withDescription( "Quiet output - only show errors" ).create(
|
||||
OptionBuilder.create(
|
||||
QUIET ) );
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "debug" ).withDescription( "Produce execution debug output" ).create(
|
||||
OptionBuilder.create(
|
||||
DEBUG ) );
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "errors" ).withDescription( "Produce execution error messages" ).create(
|
||||
OptionBuilder.create(
|
||||
ERRORS ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "reactor" ).withDescription(
|
||||
"Execute goals for project found in the reactor" ).create( REACTOR ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "non-recursive" ).withDescription(
|
||||
"Do not recurse into sub-projects" ).create( NON_RECURSIVE ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "update-snapshots" ).withDescription(
|
||||
"Forces a check for updated releases and snapshots on remote repositories" ).create( UPDATE_SNAPSHOTS ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "activate-profiles" ).withDescription(
|
||||
"Comma-delimited list of profiles to activate" ).hasArg().create( ACTIVATE_PROFILES ) );
|
||||
options.addOption( OptionBuilder.create( REACTOR ) );
|
||||
options.addOption( OptionBuilder.create( NON_RECURSIVE ) );
|
||||
options.addOption( OptionBuilder.create( UPDATE_SNAPSHOTS ) );
|
||||
options.addOption( OptionBuilder.hasArg( true ).create( ACTIVATE_PROFILES ) );
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "batch-mode" ).withDescription(
|
||||
"Run in non-interactive (batch) mode" ).create( BATCH_MODE ) );
|
||||
options.addOption( OptionBuilder.create( BATCH_MODE ) );
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "check-plugin-updates" ).withDescription(
|
||||
"Force upToDate check for any relevant registered plugins" ).create( FORCE_PLUGIN_UPDATES ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "update-plugins" ).withDescription(
|
||||
"Synonym for " + FORCE_PLUGIN_UPDATES ).create( FORCE_PLUGIN_UPDATES2 ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "no-plugin-updates" ).withDescription(
|
||||
"Suppress upToDate check for any relevant registered plugins" ).create( SUPPRESS_PLUGIN_UPDATES ) );
|
||||
options.addOption( OptionBuilder.create( FORCE_PLUGIN_UPDATES ) );
|
||||
options.addOption( OptionBuilder.create( FORCE_PLUGIN_UPDATES2 ) );
|
||||
options.addOption( OptionBuilder.create( SUPPRESS_PLUGIN_UPDATES ) );
|
||||
|
||||
options.addOption(OptionBuilder.withLongOpt("no-snapshot-updates")
|
||||
.withDescription("Supress SNAPSHOT updates")
|
||||
options.addOption(OptionBuilder
|
||||
.create(SUPRESS_SNAPSHOT_UPDATES));
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "no-plugin-registry" ).withDescription(
|
||||
"Don't use ~/.m2/plugin-registry.xml for plugin versions" ).create( SUPPRESS_PLUGIN_REGISTRY ) );
|
||||
options.addOption( OptionBuilder.create( SUPPRESS_PLUGIN_REGISTRY ) );
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "strict-checksums" ).withDescription(
|
||||
"Fail the build if checksums don't match" ).create( CHECKSUM_FAILURE_POLICY ) );
|
||||
options.addOption( OptionBuilder.create( CHECKSUM_FAILURE_POLICY ) );
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "lax-checksums" ).withDescription( "Warn if checksums don't match" ).create(
|
||||
OptionBuilder.create(
|
||||
CHECKSUM_WARNING_POLICY ) );
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "settings" )
|
||||
.withDescription( "Alternate path for the user settings file" ).hasArg()
|
||||
options.addOption( OptionBuilder.hasArg( true )
|
||||
.create( ALTERNATE_USER_SETTINGS ) );
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "fail-fast" ).withDescription(
|
||||
"Stop at first failure in reactorized builds" ).create( FAIL_FAST ) );
|
||||
options.addOption( OptionBuilder.create( FAIL_FAST ) );
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "fail-at-end" ).withDescription(
|
||||
"Only fail the build afterwards; allow all non-impacted builds to continue" ).create( FAIL_AT_END ) );
|
||||
|
|
|
@ -0,0 +1,585 @@
|
|||
package org.apache.maven.cli;
|
||||
|
||||
import org.apache.maven.BuildFailureException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
|
||||
import org.apache.maven.embedder.MavenEmbedderLogger;
|
||||
import org.apache.maven.execution.BuildFailure;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionResult;
|
||||
import org.apache.maven.execution.ReactorManager;
|
||||
import org.apache.maven.extension.ExtensionScanningException;
|
||||
import org.apache.maven.lifecycle.LifecycleExecutionException;
|
||||
import org.apache.maven.plugin.AbstractMojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugin.PluginNotFoundException;
|
||||
import org.apache.maven.project.DuplicateProjectException;
|
||||
import org.apache.maven.project.InvalidProjectModelException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.reactor.MavenExecutionException;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Utility class used to report errors, statistics, application version info, etc.
|
||||
*
|
||||
* @author jdcasey
|
||||
*
|
||||
*/
|
||||
public final class CLIReportingUtils
|
||||
{
|
||||
|
||||
public static final long MB = 1024 * 1024;
|
||||
|
||||
public static final int MS_PER_SEC = 1000;
|
||||
|
||||
public static final int SEC_PER_MIN = 60;
|
||||
|
||||
public static final String OS_NAME = System.getProperty( "os.name" ).toLowerCase( Locale.US );
|
||||
|
||||
public static final String OS_ARCH = System.getProperty( "os.arch" ).toLowerCase( Locale.US );
|
||||
|
||||
public static final String OS_VERSION = System.getProperty( "os.version" )
|
||||
.toLowerCase( Locale.US );
|
||||
|
||||
private static final String NEWLINE = System.getProperty( "line.separator" );
|
||||
|
||||
private CLIReportingUtils()
|
||||
{
|
||||
}
|
||||
|
||||
static void showVersion()
|
||||
{
|
||||
InputStream resourceAsStream;
|
||||
try
|
||||
{
|
||||
Properties properties = new Properties();
|
||||
resourceAsStream = MavenCli.class.getClassLoader()
|
||||
.getResourceAsStream(
|
||||
"META-INF/maven/org.apache.maven/maven-core/pom.properties" );
|
||||
properties.load( resourceAsStream );
|
||||
|
||||
if ( properties.getProperty( "builtOn" ) != null )
|
||||
{
|
||||
System.out.println( "Maven version: "
|
||||
+ properties.getProperty( "version", "unknown" ) + " built on "
|
||||
+ properties.getProperty( "builtOn" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println( "Maven version: "
|
||||
+ properties.getProperty( "version", "unknown" ) );
|
||||
}
|
||||
|
||||
System.out.println( "Java version: "
|
||||
+ System.getProperty( "java.version", "<unknown java version>" ) );
|
||||
|
||||
//TODO: when plexus can return the family type, add that here because it will make it easier to know what profile activation settings to use.
|
||||
System.out.println( "OS name: \"" + OS_NAME + "\" version: \"" + OS_VERSION
|
||||
+ "\" arch: \"" + OS_ARCH + "\"" );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
System.err.println( "Unable determine version from JAR file: " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
static void logResult( MavenExecutionRequest request,
|
||||
MavenExecutionResult result,
|
||||
MavenEmbedderLogger logger )
|
||||
{
|
||||
ReactorManager reactorManager = result.getReactorManager();
|
||||
|
||||
logReactorSummary( reactorManager, logger );
|
||||
|
||||
if ( ( reactorManager != null ) && reactorManager.hasBuildFailures() )
|
||||
{
|
||||
logErrors( reactorManager, request.isShowErrors(), logger );
|
||||
|
||||
if ( !ReactorManager.FAIL_NEVER.equals( reactorManager.getFailureBehavior() ) )
|
||||
{
|
||||
logger.info( "BUILD FAILED" );
|
||||
|
||||
line( logger );
|
||||
|
||||
stats( request.getStartTime(), logger );
|
||||
|
||||
line( logger );
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.info( " + Ignoring build failures" );
|
||||
}
|
||||
}
|
||||
|
||||
if ( result.hasExceptions() )
|
||||
{
|
||||
for ( Iterator i = result.getExceptions().iterator(); i.hasNext(); )
|
||||
{
|
||||
Exception e = (Exception) i.next();
|
||||
|
||||
showError( e, request.isShowErrors(), logger );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
line( logger );
|
||||
|
||||
logger.info( "BUILD SUCCESSFUL" );
|
||||
|
||||
line( logger );
|
||||
|
||||
stats( request.getStartTime(), logger );
|
||||
|
||||
line( logger );
|
||||
}
|
||||
|
||||
logger.close();
|
||||
}
|
||||
|
||||
private static void logErrors( ReactorManager rm,
|
||||
boolean showErrors,
|
||||
MavenEmbedderLogger logger )
|
||||
{
|
||||
for ( Iterator it = rm.getSortedProjects().iterator(); it.hasNext(); )
|
||||
{
|
||||
MavenProject project = (MavenProject) it.next();
|
||||
|
||||
if ( rm.hasBuildFailure( project ) )
|
||||
{
|
||||
BuildFailure buildFailure = rm.getBuildFailure( project );
|
||||
|
||||
logger.info( "Error for project: " + project.getName() + " (during "
|
||||
+ buildFailure.getTask() + ")" );
|
||||
|
||||
line( logger );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !showErrors )
|
||||
{
|
||||
logger.info( "For more information, run Maven with the -e switch" );
|
||||
|
||||
line( logger );
|
||||
}
|
||||
}
|
||||
|
||||
static void showError( String message,
|
||||
Exception e,
|
||||
boolean showErrors )
|
||||
{
|
||||
showError( message, e, showErrors, new MavenEmbedderConsoleLogger() );
|
||||
}
|
||||
|
||||
static void showError( Exception e, boolean show, MavenEmbedderLogger logger )
|
||||
{
|
||||
showError( null, e, show, logger );
|
||||
}
|
||||
|
||||
static void showError( String message, Exception e,
|
||||
boolean showStackTraces,
|
||||
MavenEmbedderLogger logger )
|
||||
{
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
writer.write( NEWLINE );
|
||||
|
||||
if ( message != null )
|
||||
{
|
||||
writer.write( message );
|
||||
writer.write( NEWLINE );
|
||||
}
|
||||
|
||||
buildErrorMessage( e, showStackTraces, writer );
|
||||
|
||||
writer.write( NEWLINE );
|
||||
|
||||
if ( showStackTraces )
|
||||
{
|
||||
writer.write( "Error stacktrace:" );
|
||||
writer.write( NEWLINE );
|
||||
e.printStackTrace( new PrintWriter( writer ) );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.write( "For more information, run with the -e flag" );
|
||||
}
|
||||
|
||||
logger.error( writer.toString() );
|
||||
}
|
||||
|
||||
private static void buildErrorMessage( Exception e, boolean showStackTraces, StringWriter writer )
|
||||
{
|
||||
boolean handled = false;
|
||||
|
||||
if ( e instanceof BuildFailureException )
|
||||
{
|
||||
handled = handleBuildFailureException( (BuildFailureException) e, writer );
|
||||
}
|
||||
else if ( e instanceof ProjectBuildingException )
|
||||
{
|
||||
handled = handleProjectBuildingException( (ProjectBuildingException) e, writer );
|
||||
}
|
||||
else if ( e instanceof LifecycleExecutionException )
|
||||
{
|
||||
handled = handleLifecycleExecutionException( (LifecycleExecutionException) e, showStackTraces, writer );
|
||||
}
|
||||
else if ( e instanceof DuplicateProjectException )
|
||||
{
|
||||
handled = handleDuplicateProjectException( (DuplicateProjectException) e, writer );
|
||||
}
|
||||
else if ( e instanceof MavenExecutionException )
|
||||
{
|
||||
handled = handleMavenExecutionException( (MavenExecutionException) e, writer );
|
||||
}
|
||||
|
||||
|
||||
if ( !handled )
|
||||
{
|
||||
handleGenericException( e, writer );
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean handleMavenExecutionException( MavenExecutionException e,
|
||||
StringWriter writer )
|
||||
{
|
||||
writer.write( "While scanning for build extensions:" );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( NEWLINE );
|
||||
|
||||
Throwable cause = e.getCause();
|
||||
if ( cause != null )
|
||||
{
|
||||
if ( cause instanceof IOException )
|
||||
{
|
||||
writer.write( e.getMessage() );
|
||||
writer.write( NEWLINE );
|
||||
|
||||
handleGenericException( cause, writer );
|
||||
|
||||
return true;
|
||||
}
|
||||
else if ( cause instanceof ExtensionScanningException )
|
||||
{
|
||||
Throwable nestedCause = cause.getCause();
|
||||
if ( ( nestedCause != null ) && ( nestedCause instanceof ProjectBuildingException ) )
|
||||
{
|
||||
return handleProjectBuildingException( (ProjectBuildingException) nestedCause, writer );
|
||||
}
|
||||
else
|
||||
{
|
||||
handleGenericException( cause, writer );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if ( cause instanceof ProjectBuildingException )
|
||||
{
|
||||
return handleProjectBuildingException( (ProjectBuildingException) cause, writer );
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean handleDuplicateProjectException( DuplicateProjectException e,
|
||||
StringWriter writer )
|
||||
{
|
||||
File existing = e.getExistingProjectFile();
|
||||
File conflicting = e.getConflictingProjectFile();
|
||||
String projectId = e.getProjectId();
|
||||
|
||||
writer.write( "Duplicated project detected." );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( "Project: " + projectId );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( "File: " );
|
||||
writer.write( existing.getAbsolutePath() );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( "File: " );
|
||||
writer.write( conflicting.getAbsolutePath() );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void handleGenericException( Throwable exception, StringWriter writer )
|
||||
{
|
||||
writer.write( exception.getMessage() );
|
||||
writer.write( NEWLINE );
|
||||
}
|
||||
|
||||
private static boolean handleLifecycleExecutionException( LifecycleExecutionException e,
|
||||
boolean showStackTraces, StringWriter writer )
|
||||
{
|
||||
Throwable cause = e.getCause();
|
||||
if ( cause != null )
|
||||
{
|
||||
if ( cause instanceof PluginNotFoundException )
|
||||
{
|
||||
// Plugin plugin = ( (PluginNotFoundException) cause ).getPlugin();
|
||||
|
||||
ArtifactNotFoundException artifactException = (ArtifactNotFoundException) ( (PluginNotFoundException) cause ).getCause();
|
||||
|
||||
writer.write( NEWLINE );
|
||||
writer.write( NEWLINE );
|
||||
|
||||
handleGenericException( artifactException, writer );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean handleProjectBuildingException( ProjectBuildingException e,
|
||||
StringWriter writer )
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
Throwable cause = e.getCause();
|
||||
if ( cause instanceof XmlPullParserException )
|
||||
{
|
||||
writer.write( "Error parsing POM:" );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( cause.getMessage() );
|
||||
|
||||
writer.write( NEWLINE );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( "Line: " );
|
||||
writer.write( "" + ( (XmlPullParserException) cause ).getLineNumber() );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( "Column: " );
|
||||
writer.write( "" + ( (XmlPullParserException) cause ).getColumnNumber() );
|
||||
|
||||
result = true;
|
||||
}
|
||||
else if ( e instanceof InvalidProjectModelException )
|
||||
{
|
||||
InvalidProjectModelException error = (InvalidProjectModelException) e;
|
||||
writer.write( error.getMessage() );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( "The following POM validation errors occurred:" );
|
||||
writer.write( NEWLINE );
|
||||
|
||||
for ( Iterator it = error.getValidationResult().getMessages().iterator(); it.hasNext(); )
|
||||
{
|
||||
String message = (String) it.next();
|
||||
writer.write( NEWLINE );
|
||||
writer.write( " - " );
|
||||
writer.write( message );
|
||||
}
|
||||
|
||||
writer.write( NEWLINE );
|
||||
writer.write( NEWLINE );
|
||||
|
||||
result = true;
|
||||
}
|
||||
|
||||
writer.write( NEWLINE );
|
||||
writer.write( "Project Id: " );
|
||||
writer.write( e.getProjectId() );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( "Project File: " );
|
||||
writer.write( e.getPomLocation() );
|
||||
writer.write( NEWLINE );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean handleBuildFailureException( BuildFailureException e, StringWriter writer )
|
||||
{
|
||||
Throwable cause = e.getCause();
|
||||
if ( ( cause != null ) && ( cause instanceof MojoFailureException ) )
|
||||
{
|
||||
writer.write( ( (AbstractMojoExecutionException) cause ).getLongMessage() );
|
||||
writer.write( NEWLINE );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void logReactorSummary( ReactorManager rm,
|
||||
MavenEmbedderLogger logger )
|
||||
{
|
||||
if ( ( rm != null ) && rm.hasMultipleProjects() && rm.executedMultipleProjects() )
|
||||
{
|
||||
logger.info( "" );
|
||||
logger.info( "" );
|
||||
|
||||
// -------------------------
|
||||
// Reactor Summary:
|
||||
// -------------------------
|
||||
// o project-name...........FAILED
|
||||
// o project2-name..........SKIPPED (dependency build failed or was skipped)
|
||||
// o project-3-name.........SUCCESS
|
||||
|
||||
line( logger );
|
||||
logger.info( "Reactor Summary:" );
|
||||
line( logger );
|
||||
|
||||
for ( Iterator it = rm.getSortedProjects().iterator(); it.hasNext(); )
|
||||
{
|
||||
MavenProject project = (MavenProject) it.next();
|
||||
|
||||
if ( rm.hasBuildFailure( project ) )
|
||||
{
|
||||
logReactorSummaryLine( project.getName(), "FAILED",
|
||||
rm.getBuildFailure( project ).getTime(), logger );
|
||||
}
|
||||
else if ( rm.isBlackListed( project ) )
|
||||
{
|
||||
logReactorSummaryLine( project.getName(),
|
||||
"SKIPPED (dependency build failed or was skipped)",
|
||||
logger );
|
||||
}
|
||||
else if ( rm.hasBuildSuccess( project ) )
|
||||
{
|
||||
logReactorSummaryLine( project.getName(), "SUCCESS",
|
||||
rm.getBuildSuccess( project ).getTime(),
|
||||
logger );
|
||||
}
|
||||
else
|
||||
{
|
||||
logReactorSummaryLine( project.getName(), "NOT BUILT", logger );
|
||||
}
|
||||
}
|
||||
line( logger );
|
||||
}
|
||||
}
|
||||
|
||||
private static void stats( Date start,
|
||||
MavenEmbedderLogger logger )
|
||||
{
|
||||
Date finish = new Date();
|
||||
|
||||
long time = finish.getTime() - start.getTime();
|
||||
|
||||
logger.info( "Total time: " + formatTime( time ) );
|
||||
|
||||
logger.info( "Finished at: " + finish );
|
||||
|
||||
//noinspection CallToSystemGC
|
||||
System.gc();
|
||||
|
||||
Runtime r = Runtime.getRuntime();
|
||||
|
||||
logger.info( "Final Memory: " + ( r.totalMemory() - r.freeMemory() ) / MB + "M/"
|
||||
+ r.totalMemory() / MB + "M" );
|
||||
}
|
||||
|
||||
private static void line( MavenEmbedderLogger logger )
|
||||
{
|
||||
logger.info( "------------------------------------------------------------------------" );
|
||||
}
|
||||
|
||||
private static String formatTime( long ms )
|
||||
{
|
||||
long secs = ms / MS_PER_SEC;
|
||||
|
||||
long min = secs / SEC_PER_MIN;
|
||||
|
||||
secs = secs % SEC_PER_MIN;
|
||||
|
||||
String msg = "";
|
||||
|
||||
if ( min > 1 )
|
||||
{
|
||||
msg = min + " minutes ";
|
||||
}
|
||||
else if ( min == 1 )
|
||||
{
|
||||
msg = "1 minute ";
|
||||
}
|
||||
|
||||
if ( secs > 1 )
|
||||
{
|
||||
msg += secs + " seconds";
|
||||
}
|
||||
else if ( secs == 1 )
|
||||
{
|
||||
msg += "1 second";
|
||||
}
|
||||
else if ( min == 0 )
|
||||
{
|
||||
msg += "< 1 second";
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
private static void logReactorSummaryLine( String name,
|
||||
String status,
|
||||
MavenEmbedderLogger logger )
|
||||
{
|
||||
logReactorSummaryLine( name, status, -1, logger );
|
||||
}
|
||||
|
||||
private static void logReactorSummaryLine( String name,
|
||||
String status,
|
||||
long time,
|
||||
MavenEmbedderLogger logger )
|
||||
{
|
||||
StringBuffer messageBuffer = new StringBuffer();
|
||||
|
||||
messageBuffer.append( name );
|
||||
|
||||
int dotCount = 54;
|
||||
|
||||
dotCount -= name.length();
|
||||
|
||||
messageBuffer.append( " " );
|
||||
|
||||
for ( int i = 0; i < dotCount; i++ )
|
||||
{
|
||||
messageBuffer.append( '.' );
|
||||
}
|
||||
|
||||
messageBuffer.append( " " );
|
||||
|
||||
messageBuffer.append( status );
|
||||
|
||||
if ( time >= 0 )
|
||||
{
|
||||
messageBuffer.append( " [" );
|
||||
|
||||
messageBuffer.append( getFormattedTime( time ) );
|
||||
|
||||
messageBuffer.append( "]" );
|
||||
}
|
||||
|
||||
logger.info( messageBuffer.toString() );
|
||||
}
|
||||
|
||||
private static String getFormattedTime( long time )
|
||||
{
|
||||
String pattern = "s.SSS's'";
|
||||
if ( time / 60000L > 0 )
|
||||
{
|
||||
pattern = "m:s" + pattern;
|
||||
if ( time / 3600000L > 0 )
|
||||
{
|
||||
pattern = "H:m" + pattern;
|
||||
}
|
||||
}
|
||||
DateFormat fmt = new SimpleDateFormat( pattern );
|
||||
fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
|
||||
return fmt.format( new Date( time ) );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,281 @@
|
|||
package org.apache.maven.cli;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.maven.MavenTransferListener;
|
||||
import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public final class CLIRequestUtils
|
||||
{
|
||||
|
||||
private CLIRequestUtils()
|
||||
{
|
||||
}
|
||||
|
||||
public static MavenExecutionRequest buildRequest( CommandLine commandLine, boolean debug, boolean quiet, boolean showErrors )
|
||||
{
|
||||
// ----------------------------------------------------------------------
|
||||
// Now that we have everything that we need we will fire up plexus and
|
||||
// bring the maven component to life for use.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
boolean interactive = true;
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.BATCH_MODE ) )
|
||||
{
|
||||
interactive = false;
|
||||
}
|
||||
|
||||
boolean pluginUpdateOverride = false;
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES ) ||
|
||||
commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES2 ) )
|
||||
{
|
||||
pluginUpdateOverride = true;
|
||||
}
|
||||
else if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_UPDATES ) )
|
||||
{
|
||||
pluginUpdateOverride = false;
|
||||
}
|
||||
|
||||
boolean noSnapshotUpdates = false;
|
||||
if ( commandLine.hasOption( CLIManager.SUPRESS_SNAPSHOT_UPDATES ) )
|
||||
{
|
||||
noSnapshotUpdates = true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
List goals = commandLine.getArgList();
|
||||
|
||||
boolean recursive = true;
|
||||
|
||||
// this is the default behavior.
|
||||
String reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST;
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.NON_RECURSIVE ) )
|
||||
{
|
||||
recursive = false;
|
||||
}
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.FAIL_FAST ) )
|
||||
{
|
||||
reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST;
|
||||
}
|
||||
else if ( commandLine.hasOption( CLIManager.FAIL_AT_END ) )
|
||||
{
|
||||
reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_AT_END;
|
||||
}
|
||||
else if ( commandLine.hasOption( CLIManager.FAIL_NEVER ) )
|
||||
{
|
||||
reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_NEVER;
|
||||
}
|
||||
|
||||
boolean offline = false;
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.OFFLINE ) )
|
||||
{
|
||||
offline = true;
|
||||
}
|
||||
|
||||
boolean updateSnapshots = false;
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.UPDATE_SNAPSHOTS ) )
|
||||
{
|
||||
updateSnapshots = true;
|
||||
}
|
||||
|
||||
String globalChecksumPolicy = null;
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.CHECKSUM_FAILURE_POLICY ) )
|
||||
{
|
||||
// todo; log
|
||||
System.out.println( "+ Enabling strict checksum verification on all artifact downloads." );
|
||||
|
||||
globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_FAIL;
|
||||
}
|
||||
else if ( commandLine.hasOption( CLIManager.CHECKSUM_WARNING_POLICY ) )
|
||||
{
|
||||
// todo: log
|
||||
System.out.println( "+ Disabling strict checksum verification on all artifact downloads." );
|
||||
|
||||
globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN;
|
||||
}
|
||||
|
||||
File baseDirectory = new File( System.getProperty( "user.dir" ) );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Profile Activation
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
List activeProfiles = new ArrayList();
|
||||
|
||||
List inactiveProfiles = new ArrayList();
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.ACTIVATE_PROFILES ) )
|
||||
{
|
||||
String profilesLine = commandLine.getOptionValue( CLIManager.ACTIVATE_PROFILES );
|
||||
|
||||
StringTokenizer profileTokens = new StringTokenizer( profilesLine, "," );
|
||||
|
||||
while ( profileTokens.hasMoreTokens() )
|
||||
{
|
||||
String profileAction = profileTokens.nextToken().trim();
|
||||
|
||||
if ( profileAction.startsWith( "-" ) )
|
||||
{
|
||||
activeProfiles.add( profileAction.substring( 1 ) );
|
||||
}
|
||||
else if ( profileAction.startsWith( "+" ) )
|
||||
{
|
||||
inactiveProfiles.add( profileAction.substring( 1 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: deprecate this eventually!
|
||||
activeProfiles.add( profileAction );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MavenTransferListener transferListener;
|
||||
|
||||
if ( interactive )
|
||||
{
|
||||
transferListener = new ConsoleDownloadMonitor();
|
||||
}
|
||||
else
|
||||
{
|
||||
transferListener = new BatchModeDownloadMonitor();
|
||||
}
|
||||
|
||||
transferListener.setShowChecksumEvents( false );
|
||||
|
||||
// This means to scan a directory structure for POMs and process them.
|
||||
boolean useReactor = false;
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.REACTOR ) )
|
||||
{
|
||||
useReactor = true;
|
||||
}
|
||||
|
||||
String alternatePomFile = null;
|
||||
if ( commandLine.hasOption( CLIManager.ALTERNATE_POM_FILE ) )
|
||||
{
|
||||
alternatePomFile = commandLine.getOptionValue( CLIManager.ALTERNATE_POM_FILE );
|
||||
}
|
||||
|
||||
int loggingLevel;
|
||||
|
||||
if ( debug )
|
||||
{
|
||||
loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_DEBUG;
|
||||
}
|
||||
else if ( quiet )
|
||||
{
|
||||
// TODO: we need to do some more work here. Some plugins use sys out or log errors at info level.
|
||||
// Ideally, we could use Warn across the board
|
||||
loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_ERROR;
|
||||
// TODO:Additionally, we can't change the mojo level because the component key includes the version and it isn't known ahead of time. This seems worth changing.
|
||||
}
|
||||
else
|
||||
{
|
||||
loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_INFO;
|
||||
}
|
||||
|
||||
Properties executionProperties = getExecutionProperties( commandLine );
|
||||
|
||||
return new DefaultMavenExecutionRequest()
|
||||
.setBaseDirectory( baseDirectory )
|
||||
.setGoals( goals )
|
||||
.setProperties( executionProperties ) // optional
|
||||
.setReactorFailureBehavior( reactorFailureBehaviour ) // default: fail fast
|
||||
.setRecursive( recursive ) // default: true
|
||||
.setUseReactor( useReactor ) // default: false
|
||||
.setPomFile( alternatePomFile ) // optional
|
||||
.setShowErrors( showErrors ) // default: false
|
||||
.setInteractiveMode( interactive ) // default: false
|
||||
.setOffline( offline ) // default: false
|
||||
.setUsePluginUpdateOverride( pluginUpdateOverride )
|
||||
.addActiveProfiles( activeProfiles ) // optional
|
||||
.addInactiveProfiles( inactiveProfiles ) // optional
|
||||
.setLoggingLevel( loggingLevel ) // default: info
|
||||
.setTransferListener( transferListener ) // default: batch mode which goes along with interactive
|
||||
.setUpdateSnapshots( updateSnapshots ) // default: false
|
||||
.setNoSnapshotUpdates( noSnapshotUpdates ) // default: false
|
||||
.setGlobalChecksumPolicy( globalChecksumPolicy ); // default: warn
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// System properties handling
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private static Properties getExecutionProperties( CommandLine commandLine )
|
||||
{
|
||||
Properties executionProperties = new Properties();
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Options that are set on the command line become system properties
|
||||
// and therefore are set in the session properties. System properties
|
||||
// are most dominant.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.SET_SYSTEM_PROPERTY ) )
|
||||
{
|
||||
String[] defStrs = commandLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY );
|
||||
|
||||
if ( defStrs != null )
|
||||
{
|
||||
for ( int i = 0; i < defStrs.length; ++i )
|
||||
{
|
||||
setCliProperty( defStrs[i], executionProperties );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
executionProperties.putAll( System.getProperties() );
|
||||
|
||||
return executionProperties;
|
||||
}
|
||||
|
||||
private static void setCliProperty( String property,
|
||||
Properties executionProperties )
|
||||
{
|
||||
String name;
|
||||
|
||||
String value;
|
||||
|
||||
int i = property.indexOf( "=" );
|
||||
|
||||
if ( i <= 0 )
|
||||
{
|
||||
name = property.trim();
|
||||
|
||||
value = "true";
|
||||
}
|
||||
else
|
||||
{
|
||||
name = property.substring( 0, i ).trim();
|
||||
|
||||
value = property.substring( i + 1 ).trim();
|
||||
}
|
||||
|
||||
executionProperties.setProperty( name, value );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// I'm leaving the setting of system properties here as not to break
|
||||
// the SystemPropertyProfileActivator. This won't harm embedding. jvz.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
System.setProperty( name, value );
|
||||
}
|
||||
|
||||
}
|
|
@ -21,8 +21,6 @@ package org.apache.maven.cli;
|
|||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.maven.BuildFailureException;
|
||||
import org.apache.maven.MavenTransferListener;
|
||||
import org.apache.maven.embedder.Configuration;
|
||||
import org.apache.maven.embedder.ConfigurationValidationResult;
|
||||
import org.apache.maven.embedder.DefaultConfiguration;
|
||||
|
@ -31,28 +29,11 @@ import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
|
|||
import org.apache.maven.embedder.MavenEmbedderException;
|
||||
import org.apache.maven.embedder.MavenEmbedderFileLogger;
|
||||
import org.apache.maven.embedder.MavenEmbedderLogger;
|
||||
import org.apache.maven.execution.BuildFailure;
|
||||
import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionResult;
|
||||
import org.apache.maven.execution.ReactorManager;
|
||||
import org.apache.maven.plugin.AbstractMojoExecutionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.classworlds.ClassWorld;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* @author jason van zyl
|
||||
|
@ -63,12 +44,6 @@ public class MavenCli
|
|||
{
|
||||
public static final String LOCAL_REPO_PROPERTY = "maven.repo.local";
|
||||
|
||||
public static final String OS_NAME = System.getProperty( "os.name" ).toLowerCase( Locale.US );
|
||||
|
||||
public static final String OS_ARCH = System.getProperty( "os.arch" ).toLowerCase( Locale.US );
|
||||
|
||||
public static final String OS_VERSION = System.getProperty( "os.version" ).toLowerCase( Locale.US );
|
||||
|
||||
public static void main( String[] args )
|
||||
{
|
||||
ClassWorld classWorld = new ClassWorld( "plexus.core", Thread.currentThread().getContextClassLoader() );
|
||||
|
@ -148,208 +123,66 @@ public class MavenCli
|
|||
|
||||
if ( commandLine.hasOption( CLIManager.VERSION ) )
|
||||
{
|
||||
showVersion();
|
||||
CLIReportingUtils.showVersion();
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if ( debug )
|
||||
{
|
||||
showVersion();
|
||||
CLIReportingUtils.showVersion();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Now that we have everything that we need we will fire up plexus and
|
||||
// bring the maven component to life for use.
|
||||
// ----------------------------------------------------------------------
|
||||
MavenExecutionRequest request = CLIRequestUtils.buildRequest( commandLine, debug, quiet, showErrors );
|
||||
|
||||
boolean interactive = true;
|
||||
Configuration configuration = buildEmbedderConfiguration( request, commandLine, classWorld );
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.BATCH_MODE ) )
|
||||
ConfigurationValidationResult cvr = MavenEmbedder.validateConfiguration( configuration );
|
||||
|
||||
if ( cvr.isUserSettingsFilePresent() && !cvr.isUserSettingsFileParses() )
|
||||
{
|
||||
interactive = false;
|
||||
CLIReportingUtils.showError( "Error reading user settings: ", cvr.getUserSettingsException(), showErrors );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
boolean pluginUpdateOverride = false;
|
||||
if ( cvr.isGlobalSettingsFilePresent() && !cvr.isGlobalSettingsFileParses() )
|
||||
{
|
||||
CLIReportingUtils.showError( "Error reading global settings: ", cvr.getGlobalSettingsException(), showErrors );
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES ) ||
|
||||
commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES2 ) )
|
||||
{
|
||||
pluginUpdateOverride = true;
|
||||
}
|
||||
else if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_UPDATES ) )
|
||||
{
|
||||
pluginUpdateOverride = false;
|
||||
return 1;
|
||||
}
|
||||
|
||||
boolean noSnapshotUpdates = false;
|
||||
if ( commandLine.hasOption( CLIManager.SUPRESS_SNAPSHOT_UPDATES ) )
|
||||
MavenEmbedder mavenEmbedder;
|
||||
MavenEmbedderLogger logger;
|
||||
try
|
||||
{
|
||||
noSnapshotUpdates = true;
|
||||
mavenEmbedder = new MavenEmbedder( configuration );
|
||||
|
||||
logger = mavenEmbedder.getLogger();
|
||||
}
|
||||
catch ( MavenEmbedderException e )
|
||||
{
|
||||
CLIReportingUtils.showError( "Unable to start the embedder: ", e, showErrors );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
MavenExecutionResult result = mavenEmbedder.execute( request );
|
||||
|
||||
List goals = commandLine.getArgList();
|
||||
CLIReportingUtils.logResult( request, result, logger );
|
||||
|
||||
boolean recursive = true;
|
||||
|
||||
// this is the default behavior.
|
||||
String reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST;
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.NON_RECURSIVE ) )
|
||||
if ( result.hasExceptions() )
|
||||
{
|
||||
recursive = false;
|
||||
}
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.FAIL_FAST ) )
|
||||
{
|
||||
reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST;
|
||||
}
|
||||
else if ( commandLine.hasOption( CLIManager.FAIL_AT_END ) )
|
||||
{
|
||||
reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_AT_END;
|
||||
}
|
||||
else if ( commandLine.hasOption( CLIManager.FAIL_NEVER ) )
|
||||
{
|
||||
reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_NEVER;
|
||||
}
|
||||
|
||||
boolean offline = false;
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.OFFLINE ) )
|
||||
{
|
||||
offline = true;
|
||||
}
|
||||
|
||||
boolean updateSnapshots = false;
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.UPDATE_SNAPSHOTS ) )
|
||||
{
|
||||
updateSnapshots = true;
|
||||
}
|
||||
|
||||
String globalChecksumPolicy = null;
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.CHECKSUM_FAILURE_POLICY ) )
|
||||
{
|
||||
// todo; log
|
||||
System.out.println( "+ Enabling strict checksum verification on all artifact downloads." );
|
||||
|
||||
globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_FAIL;
|
||||
}
|
||||
else if ( commandLine.hasOption( CLIManager.CHECKSUM_WARNING_POLICY ) )
|
||||
{
|
||||
// todo: log
|
||||
System.out.println( "+ Disabling strict checksum verification on all artifact downloads." );
|
||||
|
||||
globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN;
|
||||
}
|
||||
|
||||
File baseDirectory = new File( System.getProperty( "user.dir" ) );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Profile Activation
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
List activeProfiles = new ArrayList();
|
||||
|
||||
List inactiveProfiles = new ArrayList();
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.ACTIVATE_PROFILES ) )
|
||||
{
|
||||
String profilesLine = commandLine.getOptionValue( CLIManager.ACTIVATE_PROFILES );
|
||||
|
||||
StringTokenizer profileTokens = new StringTokenizer( profilesLine, "," );
|
||||
|
||||
while ( profileTokens.hasMoreTokens() )
|
||||
{
|
||||
String profileAction = profileTokens.nextToken().trim();
|
||||
|
||||
if ( profileAction.startsWith( "-" ) )
|
||||
{
|
||||
activeProfiles.add( profileAction.substring( 1 ) );
|
||||
}
|
||||
else if ( profileAction.startsWith( "+" ) )
|
||||
{
|
||||
inactiveProfiles.add( profileAction.substring( 1 ) );
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: deprecate this eventually!
|
||||
activeProfiles.add( profileAction );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
MavenTransferListener transferListener;
|
||||
|
||||
if ( interactive )
|
||||
private Configuration buildEmbedderConfiguration( MavenExecutionRequest request, CommandLine commandLine, ClassWorld classWorld )
|
||||
{
|
||||
transferListener = new ConsoleDownloadMonitor();
|
||||
}
|
||||
else
|
||||
{
|
||||
transferListener = new BatchModeDownloadMonitor();
|
||||
}
|
||||
|
||||
transferListener.setShowChecksumEvents( false );
|
||||
|
||||
// This means to scan a directory structure for POMs and process them.
|
||||
boolean useReactor = false;
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.REACTOR ) )
|
||||
{
|
||||
useReactor = true;
|
||||
}
|
||||
|
||||
String alternatePomFile = null;
|
||||
if ( commandLine.hasOption( CLIManager.ALTERNATE_POM_FILE ) )
|
||||
{
|
||||
alternatePomFile = commandLine.getOptionValue( CLIManager.ALTERNATE_POM_FILE );
|
||||
}
|
||||
|
||||
int loggingLevel;
|
||||
|
||||
if ( debug )
|
||||
{
|
||||
loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_DEBUG;
|
||||
}
|
||||
else if ( quiet )
|
||||
{
|
||||
// TODO: we need to do some more work here. Some plugins use sys out or log errors at info level.
|
||||
// Ideally, we could use Warn across the board
|
||||
loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_ERROR;
|
||||
// TODO:Additionally, we can't change the mojo level because the component key includes the version and it isn't known ahead of time. This seems worth changing.
|
||||
}
|
||||
else
|
||||
{
|
||||
loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_INFO;
|
||||
}
|
||||
|
||||
Properties executionProperties = getExecutionProperties( commandLine );
|
||||
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
|
||||
.setBaseDirectory( baseDirectory )
|
||||
.setGoals( goals )
|
||||
.setProperties( executionProperties ) // optional
|
||||
.setReactorFailureBehavior( reactorFailureBehaviour ) // default: fail fast
|
||||
.setRecursive( recursive ) // default: true
|
||||
.setUseReactor( useReactor ) // default: false
|
||||
.setPomFile( alternatePomFile ) // optional
|
||||
.setShowErrors( showErrors ) // default: false
|
||||
.setInteractiveMode( interactive ) // default: false
|
||||
.setOffline( offline ) // default: false
|
||||
.setUsePluginUpdateOverride( pluginUpdateOverride )
|
||||
.addActiveProfiles( activeProfiles ) // optional
|
||||
.addInactiveProfiles( inactiveProfiles ) // optional
|
||||
.setLoggingLevel( loggingLevel ) // default: info
|
||||
.setTransferListener( transferListener ) // default: batch mode which goes along with interactive
|
||||
.setUpdateSnapshots( updateSnapshots ) // default: false
|
||||
.setNoSnapshotUpdates( noSnapshotUpdates ) // default: false
|
||||
.setGlobalChecksumPolicy( globalChecksumPolicy ); // default: warn
|
||||
|
||||
File userSettingsFile;
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.ALTERNATE_USER_SETTINGS ) )
|
||||
|
@ -369,7 +202,7 @@ public class MavenCli
|
|||
if ( commandLine.hasOption( CLIManager.LOG_FILE ) )
|
||||
{
|
||||
File logFile = new File(
|
||||
baseDirectory,
|
||||
request.getBaseDirectory(),
|
||||
commandLine.getOptionValue( CLIManager.LOG_FILE ) );
|
||||
|
||||
configuration.setMavenEmbedderLogger( new MavenEmbedderFileLogger( logFile ) );
|
||||
|
@ -379,475 +212,14 @@ public class MavenCli
|
|||
configuration.setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
|
||||
}
|
||||
|
||||
ConfigurationValidationResult cvr = MavenEmbedder.validateConfiguration( configuration );
|
||||
|
||||
if ( cvr.isUserSettingsFilePresent() && !cvr.isUserSettingsFileParses() )
|
||||
{
|
||||
showError( "Error reading user settings: ", cvr.getUserSettingsException(), showErrors );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( cvr.isGlobalSettingsFilePresent() && !cvr.isGlobalSettingsFileParses() )
|
||||
{
|
||||
showError( "Error reading global settings: ", cvr.getGlobalSettingsException(), showErrors );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
String localRepoProperty = executionProperties.getProperty( LOCAL_REPO_PROPERTY );
|
||||
String localRepoProperty = request.getProperties().getProperty( LOCAL_REPO_PROPERTY );
|
||||
|
||||
if ( localRepoProperty != null )
|
||||
{
|
||||
configuration.setLocalRepository( new File( localRepoProperty ) );
|
||||
}
|
||||
|
||||
MavenEmbedder mavenEmbedder;
|
||||
|
||||
try
|
||||
{
|
||||
mavenEmbedder = new MavenEmbedder( configuration );
|
||||
|
||||
logger = mavenEmbedder.getLogger();
|
||||
}
|
||||
catch ( MavenEmbedderException e )
|
||||
{
|
||||
showError( "Unable to start the embedder: ", e, showErrors );
|
||||
|
||||
return 1;
|
||||
return configuration;
|
||||
}
|
||||
|
||||
MavenExecutionResult result = mavenEmbedder.execute( request );
|
||||
|
||||
logResult( request, result );
|
||||
|
||||
if ( result.hasExceptions() )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static void showVersion()
|
||||
{
|
||||
InputStream resourceAsStream;
|
||||
try
|
||||
{
|
||||
Properties properties = new Properties();
|
||||
resourceAsStream = MavenCli.class.getClassLoader().getResourceAsStream(
|
||||
"META-INF/maven/org.apache.maven/maven-core/pom.properties" );
|
||||
properties.load( resourceAsStream );
|
||||
|
||||
if ( properties.getProperty( "builtOn" ) != null )
|
||||
{
|
||||
System.out.println( "Maven version: " + properties.getProperty( "version", "unknown" ) + " built on " +
|
||||
properties.getProperty( "builtOn" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println( "Maven version: " + properties.getProperty( "version", "unknown" ) );
|
||||
}
|
||||
|
||||
System.out.println( "Java version: " + System.getProperty( "java.version", "<unknown java version>" ) );
|
||||
|
||||
//TODO: when plexus can return the family type, add that here because it will make it easier to know what profile activation settings to use.
|
||||
System.out.println( "OS name: \"" + OS_NAME + "\" version: \"" + OS_VERSION + "\" arch: \"" + OS_ARCH + "\"" );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
System.err.println( "Unable determine version from JAR file: " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// System properties handling
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private static Properties getExecutionProperties( CommandLine commandLine )
|
||||
{
|
||||
Properties executionProperties = new Properties();
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Options that are set on the command line become system properties
|
||||
// and therefore are set in the session properties. System properties
|
||||
// are most dominant.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.SET_SYSTEM_PROPERTY ) )
|
||||
{
|
||||
String[] defStrs = commandLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY );
|
||||
|
||||
for ( int i = 0; i < defStrs.length; ++i )
|
||||
{
|
||||
setCliProperty( defStrs[i], executionProperties );
|
||||
}
|
||||
}
|
||||
|
||||
executionProperties.putAll( System.getProperties() );
|
||||
|
||||
return executionProperties;
|
||||
}
|
||||
|
||||
private static void setCliProperty( String property,
|
||||
Properties executionProperties )
|
||||
{
|
||||
String name;
|
||||
|
||||
String value;
|
||||
|
||||
int i = property.indexOf( "=" );
|
||||
|
||||
if ( i <= 0 )
|
||||
{
|
||||
name = property.trim();
|
||||
|
||||
value = "true";
|
||||
}
|
||||
else
|
||||
{
|
||||
name = property.substring( 0, i ).trim();
|
||||
|
||||
value = property.substring( i + 1 ).trim();
|
||||
}
|
||||
|
||||
executionProperties.setProperty( name, value );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// I'm leaving the setting of system properties here as not to break
|
||||
// the SystemPropertyProfileActivator. This won't harm embedding. jvz.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
System.setProperty( name, value );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Reporting / Logging
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private static final long MB = 1024 * 1024;
|
||||
|
||||
private static final int MS_PER_SEC = 1000;
|
||||
|
||||
private static final int SEC_PER_MIN = 60;
|
||||
|
||||
private MavenEmbedderLogger logger;
|
||||
|
||||
private MavenEmbedderLogger getLogger()
|
||||
{
|
||||
return logger;
|
||||
}
|
||||
|
||||
private void logResult( MavenExecutionRequest request, MavenExecutionResult result )
|
||||
{
|
||||
ReactorManager reactorManager = result.getReactorManager();
|
||||
|
||||
logReactorSummary( reactorManager );
|
||||
|
||||
if ( ( reactorManager != null ) && reactorManager.hasBuildFailures() )
|
||||
{
|
||||
logErrors(
|
||||
reactorManager,
|
||||
request.isShowErrors() );
|
||||
|
||||
if ( !ReactorManager.FAIL_NEVER.equals( reactorManager.getFailureBehavior() ) )
|
||||
{
|
||||
getLogger().info( "BUILD ERRORS" );
|
||||
|
||||
line();
|
||||
|
||||
stats( request.getStartTime() );
|
||||
|
||||
line();
|
||||
}
|
||||
else
|
||||
{
|
||||
getLogger().info( " + Ignoring failures" );
|
||||
}
|
||||
}
|
||||
|
||||
if ( result.hasExceptions() )
|
||||
{
|
||||
for ( Iterator i = result.getExceptions().iterator(); i.hasNext(); )
|
||||
{
|
||||
Exception e = (Exception) i.next();
|
||||
|
||||
if ( e instanceof BuildFailureException )
|
||||
{
|
||||
showFailure( e, request.isShowErrors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
showError( e.getMessage(), e, request.isShowErrors() );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
line();
|
||||
|
||||
getLogger().info( "BUILD SUCCESSFUL" );
|
||||
|
||||
line();
|
||||
|
||||
stats( request.getStartTime() );
|
||||
|
||||
line();
|
||||
}
|
||||
|
||||
logger.close();
|
||||
}
|
||||
|
||||
private void logErrors( ReactorManager rm,
|
||||
boolean showErrors )
|
||||
{
|
||||
for ( Iterator it = rm.getSortedProjects().iterator(); it.hasNext(); )
|
||||
{
|
||||
MavenProject project = (MavenProject) it.next();
|
||||
|
||||
if ( rm.hasBuildFailure( project ) )
|
||||
{
|
||||
BuildFailure buildFailure = rm.getBuildFailure( project );
|
||||
|
||||
getLogger().info(
|
||||
"Error for project: " + project.getName() + " (during " + buildFailure.getTask() + ")" );
|
||||
|
||||
line();
|
||||
}
|
||||
}
|
||||
|
||||
if ( !showErrors )
|
||||
{
|
||||
getLogger().info( "For more information, run Maven with the -e switch" );
|
||||
|
||||
line();
|
||||
}
|
||||
}
|
||||
|
||||
private static void showFailure( Exception e,
|
||||
boolean show )
|
||||
{
|
||||
String message = e.getMessage();
|
||||
Throwable cause = e.getCause();
|
||||
if ( ( cause != null ) && ( cause instanceof AbstractMojoExecutionException ) )
|
||||
{
|
||||
message = ((AbstractMojoExecutionException)cause).getLongMessage();
|
||||
if ( message == null )
|
||||
{
|
||||
message = cause.getMessage();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cause = e;
|
||||
}
|
||||
|
||||
System.err.println();
|
||||
System.err.println( message );
|
||||
System.err.println();
|
||||
|
||||
if ( show )
|
||||
{
|
||||
System.err.println( "Error stacktrace:" );
|
||||
|
||||
cause.printStackTrace();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.err.println( "For more information, run with the -e flag" );
|
||||
}
|
||||
}
|
||||
|
||||
private static void showError( String message,
|
||||
Exception e,
|
||||
boolean show )
|
||||
{
|
||||
System.err.println();
|
||||
System.err.println( message );
|
||||
System.err.println();
|
||||
|
||||
if ( show )
|
||||
{
|
||||
System.err.println( "Error stacktrace:" );
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.err.println( "For more information, run with the -e flag" );
|
||||
}
|
||||
}
|
||||
|
||||
private void logReactorSummary( ReactorManager rm )
|
||||
{
|
||||
if ( ( rm != null ) && rm.hasMultipleProjects() && rm.executedMultipleProjects() )
|
||||
{
|
||||
getLogger().info( "" );
|
||||
getLogger().info( "" );
|
||||
|
||||
// -------------------------
|
||||
// Reactor Summary:
|
||||
// -------------------------
|
||||
// o project-name...........FAILED
|
||||
// o project2-name..........SKIPPED (dependency build failed or was skipped)
|
||||
// o project-3-name.........SUCCESS
|
||||
|
||||
line();
|
||||
getLogger().info( "Reactor Summary:" );
|
||||
line();
|
||||
|
||||
for ( Iterator it = rm.getSortedProjects().iterator(); it.hasNext(); )
|
||||
{
|
||||
MavenProject project = (MavenProject) it.next();
|
||||
|
||||
if ( rm.hasBuildFailure( project ) )
|
||||
{
|
||||
logReactorSummaryLine(
|
||||
project.getName(),
|
||||
"FAILED",
|
||||
rm.getBuildFailure( project ).getTime() );
|
||||
}
|
||||
else if ( rm.isBlackListed( project ) )
|
||||
{
|
||||
logReactorSummaryLine(
|
||||
project.getName(),
|
||||
"SKIPPED (dependency build failed or was skipped)" );
|
||||
}
|
||||
else if ( rm.hasBuildSuccess( project ) )
|
||||
{
|
||||
logReactorSummaryLine(
|
||||
project.getName(),
|
||||
"SUCCESS",
|
||||
rm.getBuildSuccess( project ).getTime() );
|
||||
}
|
||||
else
|
||||
{
|
||||
logReactorSummaryLine(
|
||||
project.getName(),
|
||||
"NOT BUILT" );
|
||||
}
|
||||
}
|
||||
line();
|
||||
}
|
||||
}
|
||||
|
||||
private void stats( Date start )
|
||||
{
|
||||
Date finish = new Date();
|
||||
|
||||
long time = finish.getTime() - start.getTime();
|
||||
|
||||
getLogger().info( "Total time: " + formatTime( time ) );
|
||||
|
||||
getLogger().info( "Finished at: " + finish );
|
||||
|
||||
//noinspection CallToSystemGC
|
||||
System.gc();
|
||||
|
||||
Runtime r = Runtime.getRuntime();
|
||||
|
||||
getLogger().info(
|
||||
"Final Memory: " + ( r.totalMemory() - r.freeMemory() ) / MB + "M/" + r.totalMemory() / MB + "M" );
|
||||
}
|
||||
|
||||
private void line()
|
||||
{
|
||||
getLogger().info( "------------------------------------------------------------------------" );
|
||||
}
|
||||
|
||||
private static String formatTime( long ms )
|
||||
{
|
||||
long secs = ms / MS_PER_SEC;
|
||||
|
||||
long min = secs / SEC_PER_MIN;
|
||||
|
||||
secs = secs % SEC_PER_MIN;
|
||||
|
||||
String msg = "";
|
||||
|
||||
if ( min > 1 )
|
||||
{
|
||||
msg = min + " minutes ";
|
||||
}
|
||||
else if ( min == 1 )
|
||||
{
|
||||
msg = "1 minute ";
|
||||
}
|
||||
|
||||
if ( secs > 1 )
|
||||
{
|
||||
msg += secs + " seconds";
|
||||
}
|
||||
else if ( secs == 1 )
|
||||
{
|
||||
msg += "1 second";
|
||||
}
|
||||
else if ( min == 0 )
|
||||
{
|
||||
msg += "< 1 second";
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
private void logReactorSummaryLine( String name,
|
||||
String status )
|
||||
{
|
||||
logReactorSummaryLine(
|
||||
name,
|
||||
status,
|
||||
-1 );
|
||||
}
|
||||
|
||||
private void logReactorSummaryLine( String name,
|
||||
String status,
|
||||
long time )
|
||||
{
|
||||
StringBuffer messageBuffer = new StringBuffer();
|
||||
|
||||
messageBuffer.append( name );
|
||||
|
||||
int dotCount = 54;
|
||||
|
||||
dotCount -= name.length();
|
||||
|
||||
messageBuffer.append( " " );
|
||||
|
||||
for ( int i = 0; i < dotCount; i++ )
|
||||
{
|
||||
messageBuffer.append( '.' );
|
||||
}
|
||||
|
||||
messageBuffer.append( " " );
|
||||
|
||||
messageBuffer.append( status );
|
||||
|
||||
if ( time >= 0 )
|
||||
{
|
||||
messageBuffer.append( " [" );
|
||||
|
||||
messageBuffer.append( getFormattedTime( time ) );
|
||||
|
||||
messageBuffer.append( "]" );
|
||||
}
|
||||
|
||||
getLogger().info( messageBuffer.toString() );
|
||||
}
|
||||
|
||||
private static String getFormattedTime( long time )
|
||||
{
|
||||
String pattern = "s.SSS's'";
|
||||
if ( time / 60000L > 0 )
|
||||
{
|
||||
pattern = "m:s" + pattern;
|
||||
if ( time / 3600000L > 0 )
|
||||
{
|
||||
pattern = "H:m" + pattern;
|
||||
}
|
||||
}
|
||||
DateFormat fmt = new SimpleDateFormat( pattern );
|
||||
fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
|
||||
return fmt.format( new Date( time ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
|||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.embedder.execution.MavenExecutionRequestPopulator;
|
||||
import org.apache.maven.embedder.writer.WriterUtils;
|
||||
import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||
|
@ -319,7 +318,7 @@ public class MavenEmbedder
|
|||
protected void verifyPlugin( Plugin plugin,
|
||||
MavenProject project )
|
||||
throws ComponentLookupException, ArtifactResolutionException, PluginVersionResolutionException,
|
||||
ArtifactNotFoundException, InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException,
|
||||
ArtifactNotFoundException, InvalidPluginException, PluginManagerException,
|
||||
PluginNotFoundException, PluginVersionNotFoundException
|
||||
{
|
||||
PluginManager pluginManager = (PluginManager) container.lookup( PluginManager.ROLE );
|
||||
|
@ -353,7 +352,7 @@ public class MavenEmbedder
|
|||
* @todo Move this sort of thing to the tail end of the project-building process
|
||||
*/
|
||||
private Map findArtifactTypeHandlers( MavenProject project )
|
||||
throws Exception
|
||||
throws MavenEmbedderException
|
||||
{
|
||||
Map map = new HashMap();
|
||||
|
||||
|
@ -362,10 +361,52 @@ public class MavenEmbedder
|
|||
Plugin plugin = (Plugin) i.next();
|
||||
|
||||
if ( plugin.isExtensions() )
|
||||
{
|
||||
try
|
||||
{
|
||||
verifyPlugin( plugin, project );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new PluginLookupException( plugin, "Error resolving plugin.", e );
|
||||
}
|
||||
catch ( ArtifactNotFoundException e )
|
||||
{
|
||||
throw new PluginLookupException( plugin, "Error resolving plugin.", e );
|
||||
}
|
||||
catch ( PluginNotFoundException e )
|
||||
{
|
||||
throw new PluginLookupException( plugin, "Error resolving plugin.", e );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new PluginLookupException( plugin, "Error resolving plugin.", e );
|
||||
}
|
||||
catch ( PluginVersionResolutionException e )
|
||||
{
|
||||
throw new PluginLookupException( plugin, "Error resolving plugin.", e );
|
||||
}
|
||||
catch ( InvalidPluginException e )
|
||||
{
|
||||
throw new PluginLookupException( plugin, "Error resolving plugin.", e );
|
||||
}
|
||||
catch ( PluginManagerException e )
|
||||
{
|
||||
throw new PluginLookupException( plugin, "Error resolving plugin.", e );
|
||||
}
|
||||
catch ( PluginVersionNotFoundException e )
|
||||
{
|
||||
throw new PluginLookupException( plugin, "Error resolving plugin.", e );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
map.putAll( getPluginExtensionComponents( plugin ) );
|
||||
}
|
||||
catch ( PluginManagerException e )
|
||||
{
|
||||
throw new PluginLookupException( plugin, "Error looking up plugin components.", e );
|
||||
}
|
||||
|
||||
// shudder...
|
||||
for ( Iterator j = map.values().iterator(); j.hasNext(); )
|
||||
|
@ -425,9 +466,13 @@ public class MavenEmbedder
|
|||
|
||||
artifactHandlerManager.addHandlers( handlers );
|
||||
}
|
||||
catch ( Exception e )
|
||||
catch ( MavenEmbedderException e )
|
||||
{
|
||||
return result.addException( e );
|
||||
return result.addUnknownException( e );
|
||||
}
|
||||
catch ( ProjectBuildingException e )
|
||||
{
|
||||
return result.addProjectBuildingException( e );
|
||||
}
|
||||
|
||||
ReactorManager reactorManager = maven.createReactorManager( request, result );
|
||||
|
@ -448,7 +493,7 @@ public class MavenEmbedder
|
|||
}
|
||||
catch ( ProjectBuildingException e )
|
||||
{
|
||||
result.addException( e );
|
||||
return result.addProjectBuildingException( e );
|
||||
}
|
||||
|
||||
if ( reactorManager.hasMultipleProjects() )
|
||||
|
@ -561,9 +606,9 @@ public class MavenEmbedder
|
|||
private void start( Configuration configuration )
|
||||
throws MavenEmbedderException
|
||||
{
|
||||
this.classWorld = configuration.getClassWorld();
|
||||
classWorld = configuration.getClassWorld();
|
||||
|
||||
this.logger = configuration.getMavenEmbedderLogger();
|
||||
logger = configuration.getMavenEmbedderLogger();
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Don't override any existing SecurityManager if one has been installed. Our
|
||||
|
@ -572,7 +617,7 @@ public class MavenEmbedder
|
|||
|
||||
try
|
||||
{
|
||||
if ( System.getSecurityManager() == null && activateSystemManager )
|
||||
if ( ( System.getSecurityManager() == null ) && activateSystemManager )
|
||||
{
|
||||
System.setSecurityManager( new MavenEmbedderSecurityManager() );
|
||||
}
|
||||
|
@ -812,7 +857,7 @@ public class MavenEmbedder
|
|||
{
|
||||
MavenExecutionResult result = new DefaultMavenExecutionResult();
|
||||
|
||||
result.addException( e );
|
||||
result.addUnknownException( e );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package org.apache.maven.embedder;
|
||||
|
||||
import org.apache.maven.model.Plugin;
|
||||
|
||||
public class PluginLookupException
|
||||
extends MavenEmbedderException
|
||||
{
|
||||
|
||||
private final Plugin plugin;
|
||||
|
||||
public PluginLookupException( Plugin plugin, String message,
|
||||
Throwable cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public Plugin getPlugin()
|
||||
{
|
||||
return plugin;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
package org.apache.maven.cli;
|
||||
|
||||
import org.apache.maven.BuildFailureException;
|
||||
import org.apache.maven.ProjectBuildFailureException;
|
||||
import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||
import org.apache.maven.execution.DefaultMavenExecutionResult;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionResult;
|
||||
import org.apache.maven.execution.ReactorManager;
|
||||
import org.apache.maven.lifecycle.model.MojoBinding;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.project.DuplicateProjectException;
|
||||
import org.apache.maven.project.InvalidProjectModelException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.validation.ModelValidationResult;
|
||||
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class CLIReportingUtilsTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
private TestEmbedderLogger logger = new TestEmbedderLogger();
|
||||
|
||||
public void test_logResult_ShowLongMessageForMojoFailureException()
|
||||
throws CycleDetectedException, DuplicateProjectException
|
||||
{
|
||||
String longMessage = "This is a longer message.";
|
||||
|
||||
MojoFailureException e = new MojoFailureException( "test-id", "Short Message", longMessage );
|
||||
|
||||
MojoBinding binding = new MojoBinding();
|
||||
binding.setGroupId( "plugin.group" );
|
||||
binding.setArtifactId( "plugin-artifact" );
|
||||
binding.setVersion( "10" );
|
||||
|
||||
BuildFailureException buildError = new ProjectBuildFailureException( "test:project:1", binding, e );
|
||||
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
|
||||
MavenExecutionResult result = new DefaultMavenExecutionResult();
|
||||
|
||||
request.setStartTime( new Date() );
|
||||
|
||||
MavenProject project = createProject( "test", "project", "1" );
|
||||
|
||||
ReactorManager reactorManager = new ReactorManager( Collections.singletonList( project ),
|
||||
ReactorManager.FAIL_FAST );
|
||||
reactorManager.registerBuildFailure( project, e, "task", 0 );
|
||||
|
||||
result.setReactorManager( reactorManager );
|
||||
result.addBuildFailureException( buildError );
|
||||
|
||||
CLIReportingUtils.logResult( request, result, logger );
|
||||
assertPresent( longMessage, logger.getErrorMessages() );
|
||||
}
|
||||
|
||||
public void test_logResult_ShowReasonableMessageForInvalidProject()
|
||||
throws CycleDetectedException, DuplicateProjectException
|
||||
{
|
||||
String validationMessage = "dependencies.dependency.version is required";
|
||||
|
||||
ModelValidationResult results = new ModelValidationResult();
|
||||
results.addMessage( validationMessage );
|
||||
|
||||
String projectId = "test:project";
|
||||
String projectPath = "/path/to/somewhere";
|
||||
String message = "message";
|
||||
|
||||
InvalidProjectModelException e = new InvalidProjectModelException( projectId, projectPath, message, results );
|
||||
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
|
||||
MavenExecutionResult result = new DefaultMavenExecutionResult();
|
||||
|
||||
request.setStartTime( new Date() );
|
||||
|
||||
MavenProject project = createProject( "test", "project", "1" );
|
||||
|
||||
Dependency dep = new Dependency();
|
||||
dep.setGroupId( "test" );
|
||||
dep.setArtifactId( "dep" );
|
||||
|
||||
project.getModel().addDependency( dep );
|
||||
|
||||
ReactorManager reactorManager = new ReactorManager( Collections.singletonList( project ),
|
||||
ReactorManager.FAIL_FAST );
|
||||
reactorManager.registerBuildFailure( project, e, "task", 0 );
|
||||
|
||||
result.setReactorManager( reactorManager );
|
||||
result.addProjectBuildingException( e );
|
||||
|
||||
CLIReportingUtils.logResult( request, result, logger );
|
||||
assertPresent( projectId, logger.getErrorMessages() );
|
||||
assertPresent( projectPath, logger.getErrorMessages() );
|
||||
assertPresent( message, logger.getErrorMessages() );
|
||||
assertPresent( validationMessage, logger.getErrorMessages() );
|
||||
}
|
||||
|
||||
private MavenProject createProject( String groupId,
|
||||
String artifactId,
|
||||
String version )
|
||||
{
|
||||
Model model = new Model();
|
||||
model.setGroupId( groupId );
|
||||
model.setArtifactId( artifactId );
|
||||
model.setVersion( version );
|
||||
|
||||
return new MavenProject( model );
|
||||
}
|
||||
|
||||
private void assertPresent( String message,
|
||||
List messages )
|
||||
{
|
||||
for ( Iterator it = messages.iterator(); it.hasNext(); )
|
||||
{
|
||||
String entry = (String) it.next();
|
||||
|
||||
if ( entry.indexOf( message ) > -1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fail( "Message not found in output: \'" + message + "\'" );
|
||||
assertTrue( "Message: \'" + message + "\' is missing in output.",
|
||||
messages.contains( message ) );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package org.apache.maven.cli;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class CLIRequestUtilsTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
public void test_buildRequest_ParseCommandLineProperty()
|
||||
throws ParseException
|
||||
{
|
||||
String key = "key";
|
||||
String value = "value";
|
||||
|
||||
CLIManager cliManager = new CLIManager();
|
||||
|
||||
String[] args = {
|
||||
"-D" + key + "=" + value
|
||||
};
|
||||
|
||||
CommandLine commandLine = cliManager.parse( args );
|
||||
|
||||
assertTrue( commandLine.hasOption( CLIManager.SET_SYSTEM_PROPERTY ) );
|
||||
|
||||
System.out.println( commandLine.getOptionValue( CLIManager.SET_SYSTEM_PROPERTY ) );
|
||||
System.out.println( commandLine.getArgList() );
|
||||
|
||||
assertEquals( 1, commandLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY ).length );
|
||||
|
||||
MavenExecutionRequest request = CLIRequestUtils.buildRequest( commandLine, false, false, false );
|
||||
|
||||
Properties execProperties = request.getProperties();
|
||||
|
||||
assertEquals( value, execProperties.getProperty( key ) );
|
||||
|
||||
List goals = request.getGoals();
|
||||
assertTrue( ( goals == null ) || goals.isEmpty() );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
package org.apache.maven.cli;
|
||||
|
||||
import org.apache.maven.embedder.AbstractMavenEmbedderLogger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TestEmbedderLogger
|
||||
extends AbstractMavenEmbedderLogger
|
||||
{
|
||||
|
||||
private List debugMessages = new ArrayList();
|
||||
|
||||
private List errorMessages = new ArrayList();
|
||||
|
||||
private List fatalErrorMessages = new ArrayList();
|
||||
|
||||
private List infoMessages = new ArrayList();
|
||||
|
||||
private List warnMessages = new ArrayList();
|
||||
|
||||
private List debugErrors = new ArrayList();
|
||||
|
||||
private List errors = new ArrayList();
|
||||
|
||||
private List fatalErrors = new ArrayList();
|
||||
|
||||
private List infoErrors = new ArrayList();
|
||||
|
||||
private List warnErrors = new ArrayList();
|
||||
|
||||
public void close()
|
||||
{
|
||||
}
|
||||
|
||||
public void debug( String message,
|
||||
Throwable throwable )
|
||||
{
|
||||
log( "[debug] ", message, throwable, debugMessages, debugErrors );
|
||||
}
|
||||
|
||||
private void log( String header,
|
||||
String message, Throwable throwable,
|
||||
List messages,
|
||||
List errors )
|
||||
{
|
||||
if ( message != null )
|
||||
{
|
||||
messages.add( message );
|
||||
System.out.println( header + message );
|
||||
}
|
||||
|
||||
if ( throwable != null )
|
||||
{
|
||||
errors.add( throwable );
|
||||
throwable.printStackTrace( System.out );
|
||||
}
|
||||
}
|
||||
|
||||
public void error( String message,
|
||||
Throwable throwable )
|
||||
{
|
||||
log( "[error] ", message, throwable, errorMessages, errors );
|
||||
}
|
||||
|
||||
public void fatalError( String message,
|
||||
Throwable throwable )
|
||||
{
|
||||
log( "[fatal] ", message, throwable, fatalErrorMessages, fatalErrors );
|
||||
}
|
||||
|
||||
public void info( String message,
|
||||
Throwable throwable )
|
||||
{
|
||||
log( "[info] ", message, throwable, infoMessages, infoErrors );
|
||||
}
|
||||
|
||||
public void warn( String message,
|
||||
Throwable throwable )
|
||||
{
|
||||
log( "[warn] ", message, throwable, warnMessages, warnErrors );
|
||||
}
|
||||
|
||||
public List getDebugMessages()
|
||||
{
|
||||
return debugMessages;
|
||||
}
|
||||
|
||||
public List getErrorMessages()
|
||||
{
|
||||
return errorMessages;
|
||||
}
|
||||
|
||||
public List getFatalErrorMessages()
|
||||
{
|
||||
return fatalErrorMessages;
|
||||
}
|
||||
|
||||
public List getInfoMessages()
|
||||
{
|
||||
return infoMessages;
|
||||
}
|
||||
|
||||
public List getWarnMessages()
|
||||
{
|
||||
return warnMessages;
|
||||
}
|
||||
|
||||
public List getDebugErrors()
|
||||
{
|
||||
return debugErrors;
|
||||
}
|
||||
|
||||
public List getErrorErrors()
|
||||
{
|
||||
return errors;
|
||||
}
|
||||
|
||||
public List getFatalErrors()
|
||||
{
|
||||
return fatalErrors;
|
||||
}
|
||||
|
||||
public List getInfoErrors()
|
||||
{
|
||||
return infoErrors;
|
||||
}
|
||||
|
||||
public List getWarnErrors()
|
||||
{
|
||||
return warnErrors;
|
||||
}
|
||||
|
||||
}
|
|
@ -19,21 +19,13 @@ package org.apache.maven;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.artifact.UnknownRepositoryLayoutException;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
import org.apache.maven.model.DeploymentRepository;
|
||||
import org.apache.maven.model.Repository;
|
||||
import org.apache.maven.model.RepositoryBase;
|
||||
import org.apache.maven.model.RepositoryPolicy;
|
||||
import org.codehaus.plexus.PlexusConstants;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.codehaus.plexus.context.Context;
|
||||
import org.codehaus.plexus.context.ContextException;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
@ -41,21 +33,17 @@ import java.util.List;
|
|||
|
||||
/** @author Jason van Zyl */
|
||||
public class DefaultMavenTools
|
||||
implements MavenTools, Contextualizable
|
||||
implements MavenTools
|
||||
{
|
||||
private ArtifactRepositoryLayout repositoryLayout;
|
||||
|
||||
private ArtifactRepositoryFactory artifactRepositoryFactory;
|
||||
|
||||
private PlexusContainer container;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Code snagged from ProjectUtils: this will have to be moved somewhere else
|
||||
// but just trying to collect it all in one place right now.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
public List buildArtifactRepositories( List repositories )
|
||||
throws InvalidRepositoryException
|
||||
throws UnknownRepositoryLayoutException
|
||||
{
|
||||
List repos = new ArrayList();
|
||||
|
||||
|
@ -74,17 +62,14 @@ public class DefaultMavenTools
|
|||
}
|
||||
|
||||
public ArtifactRepository buildDeploymentArtifactRepository( DeploymentRepository repo )
|
||||
throws InvalidRepositoryException
|
||||
throws UnknownRepositoryLayoutException
|
||||
{
|
||||
if ( repo != null )
|
||||
{
|
||||
String id = repo.getId();
|
||||
String url = repo.getUrl();
|
||||
|
||||
// TODO: make this a map inside the factory instead, so no lookup needed
|
||||
ArtifactRepositoryLayout layout = getRepositoryLayout( repo );
|
||||
|
||||
return artifactRepositoryFactory.createDeploymentArtifactRepository( id, url, layout,
|
||||
return artifactRepositoryFactory.createDeploymentArtifactRepository( id, url, repo.getLayout(),
|
||||
repo.isUniqueVersion() );
|
||||
}
|
||||
else
|
||||
|
@ -94,21 +79,18 @@ public class DefaultMavenTools
|
|||
}
|
||||
|
||||
public ArtifactRepository buildArtifactRepository( Repository repo )
|
||||
throws InvalidRepositoryException
|
||||
throws UnknownRepositoryLayoutException
|
||||
{
|
||||
if ( repo != null )
|
||||
{
|
||||
String id = repo.getId();
|
||||
String url = repo.getUrl();
|
||||
|
||||
// TODO: make this a map inside the factory instead, so no lookup needed
|
||||
ArtifactRepositoryLayout layout = getRepositoryLayout( repo );
|
||||
|
||||
ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repo.getSnapshots() );
|
||||
|
||||
ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repo.getReleases() );
|
||||
|
||||
return artifactRepositoryFactory.createArtifactRepository( id, url, layout, snapshots, releases );
|
||||
return artifactRepositoryFactory.createArtifactRepository( id, url, repo.getLayout(), snapshots, releases );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -140,32 +122,4 @@ public class DefaultMavenTools
|
|||
|
||||
return new ArtifactRepositoryPolicy( enabled, updatePolicy, checksumPolicy );
|
||||
}
|
||||
|
||||
private ArtifactRepositoryLayout getRepositoryLayout( RepositoryBase mavenRepo )
|
||||
throws InvalidRepositoryException
|
||||
{
|
||||
String layout = mavenRepo.getLayout();
|
||||
|
||||
ArtifactRepositoryLayout repositoryLayout;
|
||||
try
|
||||
{
|
||||
repositoryLayout = (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE, layout );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new InvalidRepositoryException( "Cannot find layout implementation corresponding to: \'" + layout +
|
||||
"\' for remote repository with id: \'" + mavenRepo.getId() + "\'.", e );
|
||||
}
|
||||
return repositoryLayout;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Lifecycle
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
public void contextualize( Context context )
|
||||
throws ContextException
|
||||
{
|
||||
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.apache.maven;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.artifact.UnknownRepositoryLayoutException;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.model.DeploymentRepository;
|
||||
import org.apache.maven.model.Repository;
|
||||
|
@ -38,11 +38,11 @@ public interface MavenTools
|
|||
// ----------------------------------------------------------------------------
|
||||
|
||||
List buildArtifactRepositories( List repositories )
|
||||
throws InvalidRepositoryException;
|
||||
throws UnknownRepositoryLayoutException;
|
||||
|
||||
ArtifactRepository buildDeploymentArtifactRepository( DeploymentRepository repo )
|
||||
throws InvalidRepositoryException;
|
||||
throws UnknownRepositoryLayoutException;
|
||||
|
||||
ArtifactRepository buildArtifactRepository( Repository repo )
|
||||
throws InvalidRepositoryException;
|
||||
throws UnknownRepositoryLayoutException;
|
||||
}
|
||||
|
|
|
@ -62,12 +62,12 @@ public class DefaultProfileAdvisor
|
|||
|
||||
private PlexusContainer container;
|
||||
|
||||
public List applyActivatedProfiles( Model model, File projectDir, List explicitlyActiveIds, List explicitlyInactiveIds )
|
||||
public List applyActivatedProfiles( Model model, File pomFile, List explicitlyActiveIds, List explicitlyInactiveIds )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
ProfileManager profileManager = buildProfileManager( model, projectDir, explicitlyActiveIds, explicitlyInactiveIds );
|
||||
ProfileManager profileManager = buildProfileManager( model, pomFile, explicitlyActiveIds, explicitlyInactiveIds );
|
||||
|
||||
return applyActivatedProfiles( model, projectDir, profileManager );
|
||||
return applyActivatedProfiles( model, pomFile, profileManager );
|
||||
}
|
||||
|
||||
public List applyActivatedExternalProfiles( Model model, File projectDir, ProfileManager externalProfileManager )
|
||||
|
@ -76,7 +76,7 @@ public class DefaultProfileAdvisor
|
|||
return applyActivatedProfiles( model, projectDir, externalProfileManager );
|
||||
}
|
||||
|
||||
private List applyActivatedProfiles( Model model, File projectDir, ProfileManager profileManager )
|
||||
private List applyActivatedProfiles( Model model, File pomFile, ProfileManager profileManager )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
List activeProfiles;
|
||||
|
@ -103,7 +103,7 @@ public class DefaultProfileAdvisor
|
|||
|
||||
String projectId = ArtifactUtils.versionlessKey( groupId, artifactId );
|
||||
|
||||
throw new ProjectBuildingException( projectId, e.getMessage(), e );
|
||||
throw new ProjectBuildingException( projectId, e.getMessage(), pomFile.getAbsolutePath(), e );
|
||||
}
|
||||
|
||||
for ( Iterator it = activeProfiles.iterator(); it.hasNext(); )
|
||||
|
@ -121,7 +121,7 @@ public class DefaultProfileAdvisor
|
|||
return activeProfiles;
|
||||
}
|
||||
|
||||
private ProfileManager buildProfileManager( Model model, File projectDir, List explicitlyActiveIds, List explicitlyInactiveIds )
|
||||
private ProfileManager buildProfileManager( Model model, File pomFile, List explicitlyActiveIds, List explicitlyInactiveIds )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
ProfileManager profileManager = new DefaultProfileManager( container );
|
||||
|
@ -132,15 +132,20 @@ public class DefaultProfileAdvisor
|
|||
|
||||
profileManager.addProfiles( model.getProfiles() );
|
||||
|
||||
if ( pomFile != null )
|
||||
{
|
||||
File projectDir = pomFile.getParentFile();
|
||||
if ( projectDir != null )
|
||||
{
|
||||
loadExternalProjectProfiles( profileManager, model, projectDir );
|
||||
}
|
||||
}
|
||||
|
||||
return profileManager;
|
||||
}
|
||||
|
||||
public LinkedHashSet getArtifactRepositoriesFromActiveProfiles( ProfileManager profileManager,
|
||||
File pomFile,
|
||||
String modelId )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
|
@ -159,7 +164,7 @@ public class DefaultProfileAdvisor
|
|||
catch ( ProfileActivationException e )
|
||||
{
|
||||
throw new ProjectBuildingException( modelId,
|
||||
"Failed to compute active profiles for repository aggregation.", e );
|
||||
"Failed to compute active profiles for repository aggregation.", pomFile.getAbsolutePath(), e );
|
||||
}
|
||||
|
||||
LinkedHashSet remoteRepositories = new LinkedHashSet();
|
||||
|
@ -190,20 +195,21 @@ public class DefaultProfileAdvisor
|
|||
}
|
||||
}
|
||||
|
||||
public LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model, File projectDir,
|
||||
public LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model, File pomFile,
|
||||
List explicitlyActiveIds, List explicitlyInactiveIds )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
ProfileManager profileManager = buildProfileManager( model, projectDir, explicitlyActiveIds, explicitlyInactiveIds );
|
||||
ProfileManager profileManager = buildProfileManager( model, pomFile, explicitlyActiveIds, explicitlyInactiveIds );
|
||||
|
||||
return getArtifactRepositoriesFromActiveProfiles( profileManager, model.getId() );
|
||||
return getArtifactRepositoriesFromActiveProfiles( profileManager, pomFile, model.getId() );
|
||||
}
|
||||
|
||||
private void loadExternalProjectProfiles( ProfileManager profileManager, Model model, File projectDir )
|
||||
private void loadExternalProjectProfiles( ProfileManager profileManager, Model model, File pomFile )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
if ( projectDir != null )
|
||||
if ( pomFile != null )
|
||||
{
|
||||
File projectDir = pomFile.getParentFile();
|
||||
try
|
||||
{
|
||||
ProfilesRoot root = profilesBuilder.buildProfiles( projectDir );
|
||||
|
@ -230,13 +236,13 @@ public class DefaultProfileAdvisor
|
|||
catch ( IOException e )
|
||||
{
|
||||
throw new ProjectBuildingException( model.getId(), "Cannot read profiles.xml resource from directory: "
|
||||
+ projectDir, e );
|
||||
+ projectDir, pomFile.getAbsolutePath(), e );
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
throw new ProjectBuildingException( model.getId(),
|
||||
"Cannot parse profiles.xml resource from directory: " + projectDir,
|
||||
e );
|
||||
pomFile.getAbsolutePath(), e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,16 +37,16 @@ public interface ProfileAdvisor
|
|||
|
||||
String ROLE = ProfileAdvisor.class.getName();
|
||||
|
||||
LinkedHashSet getArtifactRepositoriesFromActiveProfiles( ProfileManager profileManager, String modelId )
|
||||
LinkedHashSet getArtifactRepositoriesFromActiveProfiles( ProfileManager profileManager, File pomFile, String modelId )
|
||||
throws ProjectBuildingException;
|
||||
|
||||
LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model, File projectDir, List explicitlyActiveIds, List explicitlyInactiveIds )
|
||||
LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model, File pomFile, List explicitlyActiveIds, List explicitlyInactiveIds )
|
||||
throws ProjectBuildingException;
|
||||
|
||||
List applyActivatedProfiles( Model model, File projectDir, List explicitlyActiveIds, List explicitlyInactiveIds )
|
||||
List applyActivatedProfiles( Model model, File pomFile, List explicitlyActiveIds, List explicitlyInactiveIds )
|
||||
throws ProjectBuildingException;
|
||||
|
||||
List applyActivatedExternalProfiles( Model model, File projectDir, ProfileManager externalProfileManager )
|
||||
List applyActivatedExternalProfiles( Model model, File pomFile, ProfileManager externalProfileManager )
|
||||
throws ProjectBuildingException;
|
||||
|
||||
}
|
||||
|
|
|
@ -66,13 +66,7 @@ import org.apache.maven.project.interpolation.ModelInterpolator;
|
|||
import org.apache.maven.project.path.PathTranslator;
|
||||
import org.apache.maven.project.validation.ModelValidationResult;
|
||||
import org.apache.maven.project.validation.ModelValidator;
|
||||
import org.codehaus.plexus.PlexusConstants;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.codehaus.plexus.context.Context;
|
||||
import org.codehaus.plexus.context.ContextException;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
@ -140,11 +134,8 @@ Notes
|
|||
public class DefaultMavenProjectBuilder
|
||||
extends AbstractLogEnabled
|
||||
implements MavenProjectBuilder,
|
||||
Initializable,
|
||||
Contextualizable
|
||||
Initializable
|
||||
{
|
||||
protected PlexusContainer container;
|
||||
|
||||
protected MavenProfilesBuilder profilesBuilder;
|
||||
|
||||
protected ArtifactResolver artifactResolver;
|
||||
|
@ -229,9 +220,9 @@ public class DefaultMavenProjectBuilder
|
|||
public MavenProject buildStandaloneSuperProject()
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
if ( this.superProject != null )
|
||||
if ( superProject != null )
|
||||
{
|
||||
return this.superProject;
|
||||
return superProject;
|
||||
}
|
||||
|
||||
Model superModel = getSuperModel();
|
||||
|
@ -252,7 +243,12 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
// This will never happen with the repositories in the SuperPOM
|
||||
// we shouldn't be swallowing exceptions, no matter how unlikely.
|
||||
// or, if we do, we should pay attention to the one coming from getSuperModel()...
|
||||
throw new ProjectBuildingException( STANDALONE_SUPERPOM_GROUPID + ":"
|
||||
+ STANDALONE_SUPERPOM_ARTIFACTID,
|
||||
"Maven super-POM contains an invalid repository!",
|
||||
e );
|
||||
}
|
||||
|
||||
superProject.setOriginalModel( superModel );
|
||||
|
@ -288,8 +284,6 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
Map managedVersions = project.getManagedVersionMap();
|
||||
|
||||
ensureMetadataSourceIsInitialized();
|
||||
|
||||
try
|
||||
{
|
||||
project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) );
|
||||
|
@ -298,7 +292,7 @@ public class DefaultMavenProjectBuilder
|
|||
{
|
||||
throw new ProjectBuildingException( projectId,
|
||||
"Unable to build project due to an invalid dependency version: " +
|
||||
e.getMessage(), e );
|
||||
e.getMessage(), projectDescriptor.getAbsolutePath(), e );
|
||||
}
|
||||
|
||||
ArtifactResolutionRequest request = new ArtifactResolutionRequest()
|
||||
|
@ -320,25 +314,8 @@ public class DefaultMavenProjectBuilder
|
|||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private void ensureMetadataSourceIsInitialized()
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
if ( artifactMetadataSource == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
artifactMetadataSource = (ArtifactMetadataSource) container.lookup( ArtifactMetadataSource.ROLE );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new ProjectBuildingException( "all", "Cannot lookup metadata source for building the project.",
|
||||
e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map createManagedVersionMap( String projectId,
|
||||
DependencyManagement dependencyManagement )
|
||||
DependencyManagement dependencyManagement, File pomFile )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
Map map = null;
|
||||
|
@ -397,7 +374,7 @@ public class DefaultMavenProjectBuilder
|
|||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new ProjectBuildingException( projectId, "Unable to parse version '" + d.getVersion() +
|
||||
"' for dependency '" + d.getManagementKey() + "': " + e.getMessage(), e );
|
||||
"' for dependency '" + d.getManagementKey() + "': " + e.getMessage(), pomFile.getAbsolutePath(), e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -560,13 +537,6 @@ public class DefaultMavenProjectBuilder
|
|||
boolean strict )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
File projectDir = null;
|
||||
|
||||
if ( projectDescriptor != null )
|
||||
{
|
||||
projectDir = projectDescriptor.getAbsoluteFile().getParentFile();
|
||||
}
|
||||
|
||||
Model superModel = getSuperModel();
|
||||
|
||||
MavenProject superProject = new MavenProject( superModel );
|
||||
|
@ -586,7 +556,7 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
catch ( ProfileActivationException e )
|
||||
{
|
||||
throw new ProjectBuildingException( projectId, "Failed to activate external profiles.", e );
|
||||
throw new ProjectBuildingException( projectId, "Failed to activate external profiles.", projectDescriptor.getAbsolutePath(), e );
|
||||
}
|
||||
|
||||
explicitlyActive = externalProfileManager.getExplicitlyActivatedIds();
|
||||
|
@ -600,14 +570,14 @@ public class DefaultMavenProjectBuilder
|
|||
explicitlyInactive = Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
superProject.setActiveProfiles( profileAdvisor.applyActivatedProfiles( superModel, null, explicitlyActive, explicitlyInactive ) );
|
||||
superProject.setActiveProfiles( profileAdvisor.applyActivatedProfiles( superModel, projectDescriptor, explicitlyActive, explicitlyInactive ) );
|
||||
|
||||
//noinspection CollectionDeclaredAsConcreteClass
|
||||
LinkedList lineage = new LinkedList();
|
||||
|
||||
LinkedHashSet aggregatedRemoteWagonRepositories = collectInitialRepositories( model, superModel,
|
||||
parentSearchRepositories,
|
||||
projectDir, explicitlyActive,
|
||||
projectDescriptor, explicitlyActive,
|
||||
explicitlyInactive );
|
||||
|
||||
Model originalModel = ModelUtils.cloneModel( model );
|
||||
|
@ -616,7 +586,7 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
try
|
||||
{
|
||||
project = assembleLineage( model, lineage, localRepository, projectDir, aggregatedRemoteWagonRepositories, externalProfileManager, strict );
|
||||
project = assembleLineage( model, lineage, localRepository, projectDescriptor, aggregatedRemoteWagonRepositories, externalProfileManager, strict );
|
||||
}
|
||||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
|
@ -672,7 +642,7 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
try
|
||||
{
|
||||
project = processProjectLogic( pomLocation, project, projectDir, strict );
|
||||
project = processProjectLogic( pomLocation, project, projectDescriptor, strict );
|
||||
}
|
||||
catch ( ModelInterpolationException e )
|
||||
{
|
||||
|
@ -718,7 +688,7 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
}
|
||||
|
||||
project.setManagedVersionMap( createManagedVersionMap( projectId, project.getDependencyManagement() ) );
|
||||
project.setManagedVersionMap( createManagedVersionMap( projectId, project.getDependencyManagement(), projectDescriptor ) );
|
||||
|
||||
return project;
|
||||
}
|
||||
|
@ -735,16 +705,16 @@ public class DefaultMavenProjectBuilder
|
|||
private LinkedHashSet collectInitialRepositories( Model model,
|
||||
Model superModel,
|
||||
List parentSearchRepositories,
|
||||
File projectDir,
|
||||
File pomFile,
|
||||
List explicitlyActive,
|
||||
List explicitlyInactive )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
LinkedHashSet collected = new LinkedHashSet();
|
||||
|
||||
collectInitialRepositoriesFromModel( collected, model, projectDir, explicitlyActive, explicitlyInactive );
|
||||
collectInitialRepositoriesFromModel( collected, model, pomFile, explicitlyActive, explicitlyInactive );
|
||||
|
||||
collectInitialRepositoriesFromModel( collected, superModel, projectDir, explicitlyActive, explicitlyInactive );
|
||||
collectInitialRepositoriesFromModel( collected, superModel, null, explicitlyActive, explicitlyInactive );
|
||||
|
||||
if ( ( parentSearchRepositories != null ) && !parentSearchRepositories.isEmpty() )
|
||||
{
|
||||
|
@ -756,12 +726,12 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
private void collectInitialRepositoriesFromModel( LinkedHashSet collected,
|
||||
Model model,
|
||||
File projectDir,
|
||||
File pomFile,
|
||||
List explicitlyActive,
|
||||
List explicitlyInactive )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
Set reposFromProfiles = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model, projectDir, explicitlyActive, explicitlyInactive );
|
||||
Set reposFromProfiles = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model, pomFile, explicitlyActive, explicitlyInactive );
|
||||
|
||||
if ( ( reposFromProfiles != null ) && !reposFromProfiles.isEmpty() )
|
||||
{
|
||||
|
@ -829,7 +799,7 @@ public class DefaultMavenProjectBuilder
|
|||
*/
|
||||
private MavenProject processProjectLogic( String pomLocation,
|
||||
MavenProject project,
|
||||
File projectDir,
|
||||
File pomFile,
|
||||
boolean strict )
|
||||
throws ProjectBuildingException, ModelInterpolationException, InvalidRepositoryException
|
||||
{
|
||||
|
@ -843,9 +813,9 @@ public class DefaultMavenProjectBuilder
|
|||
// mkleint - using System.getProperties() is almost definitely bad for embedding.
|
||||
Map context = new HashMap( System.getProperties() );
|
||||
|
||||
if ( projectDir != null )
|
||||
if ( pomFile != null )
|
||||
{
|
||||
context.put( "basedir", projectDir.getAbsolutePath() );
|
||||
context.put( "basedir", pomFile.getParentFile().getAbsolutePath() );
|
||||
}
|
||||
|
||||
// TODO: this is a hack to ensure MNG-2124 can be satisfied without triggering MNG-1927
|
||||
|
@ -919,11 +889,11 @@ public class DefaultMavenProjectBuilder
|
|||
mavenTools.buildArtifactRepositories( model.getRepositories() ) );
|
||||
|
||||
// TODO: these aren't taking active project artifacts into consideration in the reactor
|
||||
project.setPluginArtifacts( createPluginArtifacts( projectId, project.getBuildPlugins() ) );
|
||||
project.setPluginArtifacts( createPluginArtifacts( projectId, project.getBuildPlugins(), pomLocation ) );
|
||||
|
||||
project.setReportArtifacts( createReportArtifacts( projectId, project.getReportPlugins() ) );
|
||||
project.setReportArtifacts( createReportArtifacts( projectId, project.getReportPlugins(), pomLocation ) );
|
||||
|
||||
project.setExtensionArtifacts( createExtensionArtifacts( projectId, project.getBuildExtensions() ) );
|
||||
project.setExtensionArtifacts( createExtensionArtifacts( projectId, project.getBuildExtensions(), pomLocation ) );
|
||||
|
||||
return project;
|
||||
}
|
||||
|
@ -936,7 +906,7 @@ public class DefaultMavenProjectBuilder
|
|||
private MavenProject assembleLineage( Model model,
|
||||
LinkedList lineage,
|
||||
ArtifactRepository localRepository,
|
||||
File projectDir,
|
||||
File pomFile,
|
||||
Set aggregatedRemoteWagonRepositories,
|
||||
ProfileManager externalProfileManager,
|
||||
boolean strict )
|
||||
|
@ -944,7 +914,7 @@ public class DefaultMavenProjectBuilder
|
|||
{
|
||||
ModelLineage modelLineage = new DefaultModelLineage();
|
||||
|
||||
modelLineage.setOrigin( model, new File( projectDir, "pom.xml" ), new ArrayList( aggregatedRemoteWagonRepositories ) );
|
||||
modelLineage.setOrigin( model, pomFile, new ArrayList( aggregatedRemoteWagonRepositories ) );
|
||||
|
||||
modelLineageBuilder.resumeBuildingModelLineage( modelLineage, localRepository, externalProfileManager, !strict );
|
||||
|
||||
|
@ -983,7 +953,7 @@ public class DefaultMavenProjectBuilder
|
|||
projectContext.setCurrentProject( project );
|
||||
projectContext.store( buildContextManager );
|
||||
|
||||
project.setActiveProfiles( profileAdvisor.applyActivatedProfiles( currentModel, projectDir, explicitlyActive,
|
||||
project.setActiveProfiles( profileAdvisor.applyActivatedProfiles( currentModel, currentPom, explicitlyActive,
|
||||
explicitlyInactive ) );
|
||||
|
||||
if ( lastProject != null )
|
||||
|
@ -1011,7 +981,7 @@ public class DefaultMavenProjectBuilder
|
|||
active.addAll( existingActiveProfiles );
|
||||
}
|
||||
|
||||
profileAdvisor.applyActivatedExternalProfiles( result.getModel(), projectDir, externalProfileManager );
|
||||
profileAdvisor.applyActivatedExternalProfiles( result.getModel(), pomFile, externalProfileManager );
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -1031,12 +1001,12 @@ public class DefaultMavenProjectBuilder
|
|||
catch ( FileNotFoundException e )
|
||||
{
|
||||
throw new ProjectBuildingException( projectId,
|
||||
"Could not find the model file '" + file.getAbsolutePath() + "'.", e );
|
||||
"Could not find the model file '" + file.getAbsolutePath() + "'.", file.getAbsolutePath(), e );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new ProjectBuildingException( projectId, "Failed to build model from file '" +
|
||||
file.getAbsolutePath() + "'.\nError: \'" + e.getLocalizedMessage() + "\'", e );
|
||||
file.getAbsolutePath() + "'.\nError: \'" + e.getLocalizedMessage() + "\'", file.getAbsolutePath(), e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -1088,7 +1058,7 @@ public class DefaultMavenProjectBuilder
|
|||
catch ( IOException e )
|
||||
{
|
||||
throw new ProjectBuildingException( projectId, "Failed build model from URL \'" + url.toExternalForm() +
|
||||
"\'\nError: \'" + e.getLocalizedMessage() + "\'", e );
|
||||
"\'\nError: \'" + e.getLocalizedMessage() + "\'", url.toExternalForm(), e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -1096,15 +1066,8 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
}
|
||||
|
||||
private static String createCacheKey( String groupId,
|
||||
String artifactId,
|
||||
String version )
|
||||
{
|
||||
return groupId + ":" + artifactId + ":" + version;
|
||||
}
|
||||
|
||||
protected Set createPluginArtifacts( String projectId,
|
||||
List plugins )
|
||||
List plugins, String pomLocation )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
Set pluginArtifacts = new HashSet();
|
||||
|
@ -1133,7 +1096,7 @@ public class DefaultMavenProjectBuilder
|
|||
{
|
||||
throw new ProjectBuildingException( projectId, "Unable to parse version '" + version +
|
||||
"' for plugin '" + ArtifactUtils.versionlessKey( p.getGroupId(), p.getArtifactId() ) + "': " +
|
||||
e.getMessage(), e );
|
||||
e.getMessage(), pomLocation, e );
|
||||
}
|
||||
|
||||
if ( artifact != null )
|
||||
|
@ -1147,7 +1110,7 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
// TODO: share with createPluginArtifacts?
|
||||
protected Set createReportArtifacts( String projectId,
|
||||
List reports )
|
||||
List reports, String pomLocation )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
Set pluginArtifacts = new HashSet();
|
||||
|
@ -1178,7 +1141,7 @@ public class DefaultMavenProjectBuilder
|
|||
{
|
||||
throw new ProjectBuildingException( projectId, "Unable to parse version '" + version +
|
||||
"' for report '" + ArtifactUtils.versionlessKey( p.getGroupId(), p.getArtifactId() ) + "': " +
|
||||
e.getMessage(), e );
|
||||
e.getMessage(), pomLocation, e );
|
||||
}
|
||||
|
||||
if ( artifact != null )
|
||||
|
@ -1193,7 +1156,7 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
// TODO: share with createPluginArtifacts?
|
||||
protected Set createExtensionArtifacts( String projectId,
|
||||
List extensions )
|
||||
List extensions, String pomLocation )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
Set extensionArtifacts = new HashSet();
|
||||
|
@ -1225,7 +1188,7 @@ public class DefaultMavenProjectBuilder
|
|||
{
|
||||
throw new ProjectBuildingException( projectId, "Unable to parse version '" + version +
|
||||
"' for extension '" + ArtifactUtils.versionlessKey( ext.getGroupId(), ext.getArtifactId() ) +
|
||||
"': " + e.getMessage(), e );
|
||||
"': " + e.getMessage(), pomLocation, e );
|
||||
}
|
||||
|
||||
if ( artifact != null )
|
||||
|
@ -1251,10 +1214,4 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
return readModel( projectId, url, STRICT_MODEL_PARSING );
|
||||
}
|
||||
|
||||
public void contextualize( Context context )
|
||||
throws ContextException
|
||||
{
|
||||
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.apache.maven.project;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
|
@ -29,13 +30,35 @@ package org.apache.maven.project;
|
|||
public class DuplicateProjectException
|
||||
extends Exception
|
||||
{
|
||||
public DuplicateProjectException( String message )
|
||||
private final String projectId;
|
||||
|
||||
private final File existingProjectFile;
|
||||
|
||||
private final File conflictingProjectFile;
|
||||
|
||||
public DuplicateProjectException( String projectId,
|
||||
File existingProjectFile,
|
||||
File conflictingProjectFile,
|
||||
String message )
|
||||
{
|
||||
super( message );
|
||||
this.projectId = projectId;
|
||||
this.existingProjectFile = existingProjectFile;
|
||||
this.conflictingProjectFile = conflictingProjectFile;
|
||||
}
|
||||
|
||||
public DuplicateProjectException( String message, Exception e )
|
||||
public String getProjectId()
|
||||
{
|
||||
super( message, e );
|
||||
return projectId;
|
||||
}
|
||||
|
||||
public File getExistingProjectFile()
|
||||
{
|
||||
return existingProjectFile;
|
||||
}
|
||||
|
||||
public File getConflictingProjectFile()
|
||||
{
|
||||
return conflictingProjectFile;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,40 +19,55 @@ package org.apache.maven.project;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.project.validation.ModelValidationResult;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
public class InvalidProjectModelException
|
||||
extends ProjectBuildingException
|
||||
{
|
||||
private final String pomLocation;
|
||||
|
||||
private ModelValidationResult validationResult;
|
||||
|
||||
public InvalidProjectModelException( String projectId, String pomLocation, String message, Throwable cause )
|
||||
public InvalidProjectModelException( String projectId,
|
||||
String pomLocation,
|
||||
String message,
|
||||
ModelInterpolationException cause )
|
||||
{
|
||||
super( projectId, message, cause );
|
||||
this.pomLocation = pomLocation;
|
||||
super( projectId, message, pomLocation, cause );
|
||||
}
|
||||
|
||||
public InvalidProjectModelException( String projectId, String pomLocation, String message,
|
||||
public InvalidProjectModelException( String projectId,
|
||||
String pomLocation,
|
||||
String message,
|
||||
InvalidRepositoryException cause )
|
||||
{
|
||||
super( projectId, message, pomLocation, cause );
|
||||
}
|
||||
|
||||
public InvalidProjectModelException( String projectId,
|
||||
String pomLocation,
|
||||
String message,
|
||||
ModelValidationResult validationResult )
|
||||
{
|
||||
super( projectId, message );
|
||||
super( projectId, message, pomLocation );
|
||||
|
||||
this.pomLocation = pomLocation;
|
||||
this.validationResult = validationResult;
|
||||
}
|
||||
|
||||
public InvalidProjectModelException( String projectId, String pomLocation, String message )
|
||||
public InvalidProjectModelException( String projectId,
|
||||
String pomLocation,
|
||||
String message )
|
||||
{
|
||||
super( projectId, message );
|
||||
|
||||
this.pomLocation = pomLocation;
|
||||
super( projectId, message, pomLocation );
|
||||
}
|
||||
|
||||
public final String getPomLocation()
|
||||
public InvalidProjectModelException( String projectId,
|
||||
String pomLocation,
|
||||
String message,
|
||||
XmlPullParserException cause )
|
||||
{
|
||||
return pomLocation;
|
||||
super( projectId, message, pomLocation, cause );
|
||||
}
|
||||
|
||||
public final ModelValidationResult getValidationResult()
|
||||
|
@ -60,9 +75,4 @@ public class InvalidProjectModelException
|
|||
return validationResult;
|
||||
}
|
||||
|
||||
public String getMessage()
|
||||
{
|
||||
return super.getMessage() + " at " + this.pomLocation;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@ package org.apache.maven.project;
|
|||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
import org.apache.maven.wagon.events.TransferListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.maven.project;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.project.validation.ModelValidationResult;
|
||||
|
||||
/**
|
||||
* @author Jason van Zyl
|
||||
|
|
|
@ -1,5 +1,16 @@
|
|||
package org.apache.maven.project;
|
||||
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.profiles.activation.ProfileActivationException;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -28,16 +39,149 @@ public class ProjectBuildingException
|
|||
{
|
||||
private final String projectId;
|
||||
|
||||
public ProjectBuildingException( String projectId, String message )
|
||||
private String pomLocation;
|
||||
|
||||
public ProjectBuildingException( String projectId,
|
||||
String message )
|
||||
{
|
||||
super( message );
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
public ProjectBuildingException( String projectId, String message, Throwable cause )
|
||||
protected ProjectBuildingException( String projectId,
|
||||
String message,
|
||||
String pomLocation )
|
||||
{
|
||||
super( message );
|
||||
this.projectId = projectId;
|
||||
this.pomLocation = pomLocation;
|
||||
}
|
||||
|
||||
public ProjectBuildingException( String projectId,
|
||||
String message,
|
||||
String pomLocation,
|
||||
ProfileActivationException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projectId = projectId;
|
||||
this.pomLocation = pomLocation;
|
||||
}
|
||||
|
||||
public ProjectBuildingException( String projectId,
|
||||
String message,
|
||||
String pomLocation,
|
||||
IOException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projectId = projectId;
|
||||
this.pomLocation = pomLocation;
|
||||
}
|
||||
|
||||
public ProjectBuildingException( String projectId,
|
||||
String message,
|
||||
String pomLocation,
|
||||
XmlPullParserException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projectId = projectId;
|
||||
this.pomLocation = pomLocation;
|
||||
}
|
||||
|
||||
protected ProjectBuildingException( String projectId,
|
||||
String message,
|
||||
XmlPullParserException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
public ProjectBuildingException( String projectId,
|
||||
String message,
|
||||
String pomLocation,
|
||||
InvalidRepositoryException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projectId = projectId;
|
||||
this.pomLocation = pomLocation;
|
||||
}
|
||||
|
||||
public ProjectBuildingException( String projectId,
|
||||
String message,
|
||||
InvalidRepositoryException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
public ProjectBuildingException( String projectId,
|
||||
String message,
|
||||
ArtifactResolutionException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
public ProjectBuildingException( String projectId,
|
||||
String message,
|
||||
ArtifactNotFoundException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
public ProjectBuildingException( String projectId,
|
||||
String message,
|
||||
String pomLocation,
|
||||
ArtifactResolutionException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projectId = projectId;
|
||||
this.pomLocation = pomLocation;
|
||||
}
|
||||
|
||||
public ProjectBuildingException( String projectId,
|
||||
String message,
|
||||
String pomLocation,
|
||||
ArtifactNotFoundException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projectId = projectId;
|
||||
this.pomLocation = pomLocation;
|
||||
}
|
||||
|
||||
public ProjectBuildingException( String projectId,
|
||||
String message,
|
||||
String pomLocation,
|
||||
InvalidVersionSpecificationException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projectId = projectId;
|
||||
this.pomLocation = pomLocation;
|
||||
}
|
||||
|
||||
public ProjectBuildingException( String projectId,
|
||||
String message,
|
||||
String pomLocation,
|
||||
InvalidDependencyVersionException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projectId = projectId;
|
||||
this.pomLocation = pomLocation;
|
||||
}
|
||||
|
||||
protected ProjectBuildingException( String projectId,
|
||||
String message,
|
||||
String pomLocation,
|
||||
ModelInterpolationException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projectId = projectId;
|
||||
this.pomLocation = pomLocation;
|
||||
}
|
||||
|
||||
public String getPomLocation()
|
||||
{
|
||||
return pomLocation;
|
||||
}
|
||||
|
||||
public String getProjectId()
|
||||
|
@ -47,6 +191,8 @@ public class ProjectBuildingException
|
|||
|
||||
public String getMessage()
|
||||
{
|
||||
return super.getMessage() + " for project " + this.projectId;
|
||||
return super.getMessage() + " for project " + projectId
|
||||
+ ( ( pomLocation == null ? "" : " at " + pomLocation ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -87,7 +87,14 @@ public class ProjectSorter
|
|||
|
||||
if ( dag.getVertex( id ) != null )
|
||||
{
|
||||
throw new DuplicateProjectException( "Project '" + id + "' is duplicated in the reactor" );
|
||||
MavenProject conflictingProject = (MavenProject) projectMap.get( id );
|
||||
|
||||
throw new DuplicateProjectException( id,
|
||||
conflictingProject.getFile(),
|
||||
project.getFile(),
|
||||
"Project '"
|
||||
+ id
|
||||
+ "' is duplicated in the reactor" );
|
||||
}
|
||||
|
||||
dag.addVertex( id );
|
||||
|
@ -138,7 +145,7 @@ public class ProjectSorter
|
|||
{
|
||||
Plugin plugin = (Plugin) j.next();
|
||||
String pluginId = ArtifactUtils.versionlessKey( plugin.getGroupId(), plugin.getArtifactId() );
|
||||
if ( dag.getVertex( pluginId ) != null && !pluginId.equals( id ) )
|
||||
if ( ( dag.getVertex( pluginId ) != null ) && !pluginId.equals( id ) )
|
||||
{
|
||||
addEdgeWithParentCheck( projectMap, pluginId, project, id );
|
||||
}
|
||||
|
@ -152,7 +159,7 @@ public class ProjectSorter
|
|||
{
|
||||
ReportPlugin plugin = (ReportPlugin) j.next();
|
||||
String pluginId = ArtifactUtils.versionlessKey( plugin.getGroupId(), plugin.getArtifactId() );
|
||||
if ( dag.getVertex( pluginId ) != null && !pluginId.equals( id ) )
|
||||
if ( ( dag.getVertex( pluginId ) != null ) && !pluginId.equals( id ) )
|
||||
{
|
||||
addEdgeWithParentCheck( projectMap, pluginId, project, id );
|
||||
}
|
||||
|
@ -211,7 +218,7 @@ public class ProjectSorter
|
|||
{
|
||||
if ( topLevelProject == null )
|
||||
{
|
||||
for ( Iterator i = sortedProjects.iterator(); i.hasNext() && topLevelProject == null; )
|
||||
for ( Iterator i = sortedProjects.iterator(); i.hasNext() && ( topLevelProject == null ); )
|
||||
{
|
||||
MavenProject project = (MavenProject) i.next();
|
||||
if ( project.isExecutionRoot() )
|
||||
|
|
|
@ -19,17 +19,14 @@ package org.apache.maven.project;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.artifact.UnknownRepositoryLayoutException;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
import org.apache.maven.model.DeploymentRepository;
|
||||
import org.apache.maven.model.Repository;
|
||||
import org.apache.maven.model.RepositoryBase;
|
||||
import org.apache.maven.model.RepositoryPolicy;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
@ -44,7 +41,7 @@ public final class ProjectUtils
|
|||
public static List buildArtifactRepositories( List repositories,
|
||||
ArtifactRepositoryFactory artifactRepositoryFactory,
|
||||
PlexusContainer container )
|
||||
throws InvalidRepositoryException
|
||||
throws UnknownRepositoryLayoutException
|
||||
{
|
||||
|
||||
List repos = new ArrayList();
|
||||
|
@ -67,17 +64,14 @@ public final class ProjectUtils
|
|||
public static ArtifactRepository buildDeploymentArtifactRepository( DeploymentRepository repo,
|
||||
ArtifactRepositoryFactory artifactRepositoryFactory,
|
||||
PlexusContainer container )
|
||||
throws InvalidRepositoryException
|
||||
throws UnknownRepositoryLayoutException
|
||||
{
|
||||
if ( repo != null )
|
||||
{
|
||||
String id = repo.getId();
|
||||
String url = repo.getUrl();
|
||||
|
||||
// TODO: make this a map inside the factory instead, so no lookup needed
|
||||
ArtifactRepositoryLayout layout = getRepositoryLayout( repo, container );
|
||||
|
||||
return artifactRepositoryFactory.createDeploymentArtifactRepository( id, url, layout,
|
||||
return artifactRepositoryFactory.createDeploymentArtifactRepository( id, url, repo.getLayout(),
|
||||
repo.isUniqueVersion() );
|
||||
}
|
||||
else
|
||||
|
@ -89,20 +83,17 @@ public final class ProjectUtils
|
|||
public static ArtifactRepository buildArtifactRepository( Repository repo,
|
||||
ArtifactRepositoryFactory artifactRepositoryFactory,
|
||||
PlexusContainer container )
|
||||
throws InvalidRepositoryException
|
||||
throws UnknownRepositoryLayoutException
|
||||
{
|
||||
if ( repo != null )
|
||||
{
|
||||
String id = repo.getId();
|
||||
String url = repo.getUrl();
|
||||
|
||||
// TODO: make this a map inside the factory instead, so no lookup needed
|
||||
ArtifactRepositoryLayout layout = getRepositoryLayout( repo, container );
|
||||
|
||||
ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repo.getSnapshots() );
|
||||
ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repo.getReleases() );
|
||||
|
||||
return artifactRepositoryFactory.createArtifactRepository( id, url, layout, snapshots, releases );
|
||||
return artifactRepositoryFactory.createArtifactRepository( id, url, repo.getLayout(), snapshots, releases );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -132,22 +123,4 @@ public final class ProjectUtils
|
|||
return new ArtifactRepositoryPolicy( enabled, updatePolicy, checksumPolicy );
|
||||
}
|
||||
|
||||
private static ArtifactRepositoryLayout getRepositoryLayout( RepositoryBase mavenRepo, PlexusContainer container )
|
||||
throws InvalidRepositoryException
|
||||
{
|
||||
String layout = mavenRepo.getLayout();
|
||||
|
||||
ArtifactRepositoryLayout repositoryLayout;
|
||||
try
|
||||
{
|
||||
repositoryLayout = (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE, layout );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new InvalidRepositoryException( "Cannot find layout implementation corresponding to: \'" + layout +
|
||||
"\' for remote repository with id: \'" + mavenRepo.getId() + "\'.", e );
|
||||
}
|
||||
return repositoryLayout;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.apache.maven.project.artifact;
|
||||
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -28,7 +30,7 @@ package org.apache.maven.project.artifact;
|
|||
public class InvalidDependencyVersionException
|
||||
extends Exception
|
||||
{
|
||||
public InvalidDependencyVersionException( String message, Exception cause )
|
||||
public InvalidDependencyVersionException( String message, InvalidVersionSpecificationException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
|
|
@ -47,7 +47,13 @@ import org.apache.maven.project.MavenProjectBuilder;
|
|||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.project.build.ProjectBuildCache;
|
||||
import org.apache.maven.project.validation.ModelValidationResult;
|
||||
import org.codehaus.plexus.PlexusConstants;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.codehaus.plexus.context.Context;
|
||||
import org.codehaus.plexus.context.ContextException;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -65,7 +71,7 @@ import java.util.Set;
|
|||
*/
|
||||
public class MavenMetadataSource
|
||||
extends AbstractLogEnabled
|
||||
implements ArtifactMetadataSource
|
||||
implements ArtifactMetadataSource, Contextualizable
|
||||
{
|
||||
public static final String ROLE_HINT = "default";
|
||||
|
||||
|
@ -80,6 +86,8 @@ public class MavenMetadataSource
|
|||
// lazily instantiated and cached.
|
||||
private MavenProject superProject;
|
||||
|
||||
private PlexusContainer container;
|
||||
|
||||
/**
|
||||
* Retrieve the metadata for the project from the repository.
|
||||
* Uses the ProjectBuilder, to enable post-processing and inheritance calculation before retrieving the
|
||||
|
@ -88,6 +96,15 @@ public class MavenMetadataSource
|
|||
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
try
|
||||
{
|
||||
loadProjectBuilder();
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new ArtifactMetadataRetrievalException( "Cannot lookup MavenProjectBuilder component instance: " + e.getMessage(), e );
|
||||
}
|
||||
|
||||
ProjectBuildCache cache = ProjectBuildCache.read( buildContextManager );
|
||||
|
||||
MavenProject project = null;
|
||||
|
@ -174,7 +191,7 @@ public class MavenMetadataSource
|
|||
artifact.setVersionRange( VersionRange.createFromVersion( relocation.getVersion() ) );
|
||||
}
|
||||
|
||||
if ( artifact.getDependencyFilter() != null &&
|
||||
if ( ( artifact.getDependencyFilter() != null ) &&
|
||||
!artifact.getDependencyFilter().include( artifact ) )
|
||||
{
|
||||
return null;
|
||||
|
@ -188,7 +205,7 @@ public class MavenMetadataSource
|
|||
message += " " + relocation.getMessage() + "\n";
|
||||
}
|
||||
|
||||
if ( artifact.getDependencyTrail() != null && artifact.getDependencyTrail().size() == 1 )
|
||||
if ( ( artifact.getDependencyTrail() != null ) && ( artifact.getDependencyTrail().size() == 1 ) )
|
||||
{
|
||||
getLogger().warn( "While downloading " + artifact.getGroupId() + ":" +
|
||||
artifact.getArtifactId() + ":" + artifact.getVersion() + message + "\n" );
|
||||
|
@ -255,6 +272,15 @@ public class MavenMetadataSource
|
|||
return result;
|
||||
}
|
||||
|
||||
private void loadProjectBuilder()
|
||||
throws ComponentLookupException
|
||||
{
|
||||
if ( mavenProjectBuilder == null )
|
||||
{
|
||||
mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.class );
|
||||
}
|
||||
}
|
||||
|
||||
private List aggregateRepositoryLists( List remoteRepositories, List remoteArtifactRepositories )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
|
@ -353,9 +379,9 @@ public class MavenMetadataSource
|
|||
|
||||
ArtifactFilter artifactFilter = dependencyFilter;
|
||||
|
||||
if ( artifact != null && ( artifactFilter == null || artifactFilter.include( artifact ) ) )
|
||||
if ( ( artifact != null ) && ( ( artifactFilter == null ) || artifactFilter.include( artifact ) ) )
|
||||
{
|
||||
if ( d.getExclusions() != null && !d.getExclusions().isEmpty() )
|
||||
if ( ( d.getExclusions() != null ) && !d.getExclusions().isEmpty() )
|
||||
{
|
||||
List exclusions = new ArrayList();
|
||||
for ( Iterator j = d.getExclusions().iterator(); j.hasNext(); )
|
||||
|
@ -409,7 +435,7 @@ public class MavenMetadataSource
|
|||
|
||||
List versions;
|
||||
Metadata repoMetadata = metadata.getMetadata();
|
||||
if ( repoMetadata != null && repoMetadata.getVersioning() != null )
|
||||
if ( ( repoMetadata != null ) && ( repoMetadata.getVersioning() != null ) )
|
||||
{
|
||||
List metadataVersions = repoMetadata.getVersioning().getVersions();
|
||||
versions = new ArrayList( metadataVersions.size() );
|
||||
|
@ -426,4 +452,10 @@ public class MavenMetadataSource
|
|||
|
||||
return versions;
|
||||
}
|
||||
|
||||
public void contextualize( Context context )
|
||||
throws ContextException
|
||||
{
|
||||
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,11 +197,11 @@ public class DefaultModelLineageBuilder
|
|||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new ProjectBuildingException( "unknown", "Failed to read model from: " + pomFile, e );
|
||||
throw new ProjectBuildingException( "unknown", "Failed to read model from: " + pomFile, pomFile.getAbsolutePath(), e );
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
throw new ProjectBuildingException( "unknown", "Failed to parse model from: " + pomFile, e );
|
||||
throw new ProjectBuildingException( "unknown", "Failed to parse model from: " + pomFile, pomFile.getAbsolutePath(), e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -250,7 +250,7 @@ public class DefaultModelLineageBuilder
|
|||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
throw new ProjectBuildingException( model.getId(), "Failed to create ArtifactRepository list for: "
|
||||
+ pomFile, e );
|
||||
+ pomFile, pomFile.getAbsolutePath(), e );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -258,7 +258,7 @@ public class DefaultModelLineageBuilder
|
|||
}
|
||||
|
||||
private void loadActiveProfileRepositories( List repositories, Model model, ProfileManager profileManager,
|
||||
File projectDir )
|
||||
File pomFile )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
List explicitlyActive;
|
||||
|
@ -275,9 +275,9 @@ public class DefaultModelLineageBuilder
|
|||
explicitlyInactive = Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
LinkedHashSet profileRepos = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( profileManager, model.getId() );
|
||||
LinkedHashSet profileRepos = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( profileManager, pomFile, model.getId() );
|
||||
|
||||
profileRepos.addAll( profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model, projectDir,
|
||||
profileRepos.addAll( profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model, pomFile,
|
||||
explicitlyActive,
|
||||
explicitlyInactive ) );
|
||||
|
||||
|
@ -310,7 +310,7 @@ public class DefaultModelLineageBuilder
|
|||
|
||||
File parentPomFile = projectBuildCache.getCachedModelFile( modelParent );
|
||||
|
||||
if ( parentPomFile == null )
|
||||
if ( ( parentPomFile == null ) && ( modelPomFile != null ) )
|
||||
{
|
||||
parentPomFile = resolveParentWithRelativePath( modelParent, modelPomFile );
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ public class DefaultModelLineageBuilder
|
|||
{
|
||||
try
|
||||
{
|
||||
parentPomFile = resolveParentFromRepositories( modelParent, localRepository, remoteRepositories, modelPomFile );
|
||||
parentPomFile = resolveParentFromRepositories( modelParent, localRepository, remoteRepositories, model.getId() );
|
||||
}
|
||||
catch( ProjectBuildingException e )
|
||||
{
|
||||
|
@ -388,7 +388,7 @@ public class DefaultModelLineageBuilder
|
|||
}
|
||||
|
||||
private File resolveParentFromRepositories( Parent modelParent, ArtifactRepository localRepository,
|
||||
List remoteRepositories, File pomFile )
|
||||
List remoteRepositories, String childId )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
Artifact parentPomArtifact = artifactFactory.createBuildArtifact( modelParent.getGroupId(), modelParent
|
||||
|
@ -405,12 +405,12 @@ public class DefaultModelLineageBuilder
|
|||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new ProjectBuildingException( "Parent: " + modelParent.getId(),
|
||||
"Failed to resolve POM for parent of: " + pomFile, e );
|
||||
"Failed to resolve POM for parent of: " + childId, e );
|
||||
}
|
||||
catch ( ArtifactNotFoundException e )
|
||||
{
|
||||
throw new ProjectBuildingException( "Parent: " + modelParent.getId(), "Cannot find parent: "
|
||||
+ parentPomArtifact.getId() + " of: " + pomFile, e );
|
||||
+ parentPomArtifact.getId() + " of: " + childId, e );
|
||||
}
|
||||
|
||||
if ( parentPomArtifact.isResolved() )
|
||||
|
|
|
@ -147,6 +147,10 @@ under the License.
|
|||
<role>org.apache.maven.project.MavenProjectBuilder</role>
|
||||
<implementation>org.apache.maven.project.DefaultMavenProjectBuilder</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.metadata.ArtifactMetadataSource</role>
|
||||
<role-hint>default</role-hint>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.build.model.ModelLineageBuilder</role>
|
||||
<role-hint>default</role-hint>
|
||||
|
@ -311,9 +315,6 @@ under the License.
|
|||
<role-hint>maven</role-hint>
|
||||
<implementation>org.apache.maven.project.artifact.MavenMetadataSource</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.MavenProjectBuilder</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
||||
</requirement>
|
||||
|
@ -332,9 +333,6 @@ under the License.
|
|||
<role-hint>default</role-hint>
|
||||
<implementation>org.apache.maven.project.artifact.MavenMetadataSource</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.MavenProjectBuilder</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
||||
</requirement>
|
||||
|
@ -352,10 +350,6 @@ under the License.
|
|||
<role>org.apache.maven.MavenTools</role>
|
||||
<implementation>org.apache.maven.DefaultMavenTools</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout</role>
|
||||
<role-hint>default</role-hint>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
|
||||
</requirement>
|
||||
|
|
Loading…
Reference in New Issue