mirror of https://github.com/apache/maven.git
Fine-tuning an error reporting pointcut, and also adding a method to the embedder to allow a third party access to the build plan for a specific project, given a set of goals to be invoked.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@616825 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6c103fff87
commit
f2d7a5aa5f
|
@ -41,11 +41,16 @@ import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.execution.ReactorManager;
|
import org.apache.maven.execution.ReactorManager;
|
||||||
import org.apache.maven.extension.BuildExtensionScanner;
|
import org.apache.maven.extension.BuildExtensionScanner;
|
||||||
import org.apache.maven.extension.ExtensionScanningException;
|
import org.apache.maven.extension.ExtensionScanningException;
|
||||||
|
import org.apache.maven.lifecycle.LifecycleException;
|
||||||
import org.apache.maven.lifecycle.LifecycleUtils;
|
import org.apache.maven.lifecycle.LifecycleUtils;
|
||||||
|
import org.apache.maven.lifecycle.plan.BuildPlan;
|
||||||
|
import org.apache.maven.lifecycle.plan.BuildPlanner;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||||
|
import org.apache.maven.monitor.event.DefaultEventDispatcher;
|
||||||
|
import org.apache.maven.monitor.event.EventDispatcher;
|
||||||
import org.apache.maven.plugin.InvalidPluginException;
|
import org.apache.maven.plugin.InvalidPluginException;
|
||||||
import org.apache.maven.plugin.MavenPluginCollector;
|
import org.apache.maven.plugin.MavenPluginCollector;
|
||||||
import org.apache.maven.plugin.MavenPluginDiscoverer;
|
import org.apache.maven.plugin.MavenPluginDiscoverer;
|
||||||
|
@ -55,6 +60,7 @@ import org.apache.maven.plugin.PluginNotFoundException;
|
||||||
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
|
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
|
||||||
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
|
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
|
||||||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
||||||
|
import org.apache.maven.project.DuplicateProjectException;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.project.MavenProjectBuilder;
|
import org.apache.maven.project.MavenProjectBuilder;
|
||||||
import org.apache.maven.project.MavenProjectBuildingResult;
|
import org.apache.maven.project.MavenProjectBuildingResult;
|
||||||
|
@ -84,7 +90,9 @@ import org.codehaus.plexus.configuration.PlexusConfigurationException;
|
||||||
import org.codehaus.plexus.logging.LoggerManager;
|
import org.codehaus.plexus.logging.LoggerManager;
|
||||||
import org.codehaus.plexus.util.IOUtil;
|
import org.codehaus.plexus.util.IOUtil;
|
||||||
import org.codehaus.plexus.util.ReaderFactory;
|
import org.codehaus.plexus.util.ReaderFactory;
|
||||||
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
import org.codehaus.plexus.util.WriterFactory;
|
import org.codehaus.plexus.util.WriterFactory;
|
||||||
|
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -93,6 +101,7 @@ import java.io.Reader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -153,6 +162,8 @@ public class MavenEmbedder
|
||||||
|
|
||||||
private MavenExecutionRequestPopulator populator;
|
private MavenExecutionRequestPopulator populator;
|
||||||
|
|
||||||
|
private BuildPlanner buildPlanner;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Configuration
|
// Configuration
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@ -509,6 +520,46 @@ public class MavenEmbedder
|
||||||
// Lifecycle information
|
// Lifecycle information
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
public BuildPlan getBuildPlan( List goals,
|
||||||
|
MavenProject project )
|
||||||
|
throws MavenEmbedderException
|
||||||
|
{
|
||||||
|
MavenExecutionRequest req = new DefaultMavenExecutionRequest( request );
|
||||||
|
req.setGoals( goals );
|
||||||
|
|
||||||
|
EventDispatcher dispatcher = new DefaultEventDispatcher( req.getEventMonitors() );
|
||||||
|
|
||||||
|
ReactorManager rm;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rm = new ReactorManager( Collections.singletonList( project ), ReactorManager.FAIL_FAST );
|
||||||
|
}
|
||||||
|
catch ( CycleDetectedException e )
|
||||||
|
{
|
||||||
|
// impossible, only one project.
|
||||||
|
throw new MavenEmbedderException( "Cycle detected in single-project reactor manager during build-plan lookup.", e );
|
||||||
|
}
|
||||||
|
catch ( DuplicateProjectException e )
|
||||||
|
{
|
||||||
|
// impossible, only one project.
|
||||||
|
throw new MavenEmbedderException( "Duplicate project detected in single-project reactor manager during build-plan lookup.", e );
|
||||||
|
}
|
||||||
|
|
||||||
|
MavenSession session = new MavenSession( container, request, dispatcher, rm );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return buildPlanner.constructBuildPlan( goals, project, session );
|
||||||
|
}
|
||||||
|
catch ( LifecycleException e )
|
||||||
|
{
|
||||||
|
throw new MavenEmbedderException( "Failed to construct build-plan for project: "
|
||||||
|
+ project.getId() + " using goals: '"
|
||||||
|
+ StringUtils.join( goals.iterator(), ", " ) + "'", e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public List getLifecyclePhases()
|
public List getLifecyclePhases()
|
||||||
{
|
{
|
||||||
return getBuildLifecyclePhases();
|
return getBuildLifecyclePhases();
|
||||||
|
@ -637,6 +688,8 @@ public class MavenEmbedder
|
||||||
populator = (MavenExecutionRequestPopulator) container.lookup(
|
populator = (MavenExecutionRequestPopulator) container.lookup(
|
||||||
MavenExecutionRequestPopulator.ROLE );
|
MavenExecutionRequestPopulator.ROLE );
|
||||||
|
|
||||||
|
buildPlanner = (BuildPlanner) container.lookup( BuildPlanner.class );
|
||||||
|
|
||||||
artifactHandlerManager = (ArtifactHandlerManager) container.lookup( ArtifactHandlerManager.ROLE );
|
artifactHandlerManager = (ArtifactHandlerManager) container.lookup( ArtifactHandlerManager.ROLE );
|
||||||
|
|
||||||
// This is temporary as we can probably cache a single request and use it for default values and
|
// This is temporary as we can probably cache a single request and use it for default values and
|
||||||
|
|
|
@ -66,7 +66,7 @@ public privileged aspect PBEDerivativeReporterAspect
|
||||||
}
|
}
|
||||||
|
|
||||||
private pointcut mavenTools_buildArtifactRepository( Repository repo ):
|
private pointcut mavenTools_buildArtifactRepository( Repository repo ):
|
||||||
call( ArtifactRepository MavenTools+.buildArtifactRepository( Repository ) )
|
execution( ArtifactRepository MavenTools+.buildArtifactRepository( Repository ) )
|
||||||
&& args( repo );
|
&& args( repo );
|
||||||
|
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
|
|
Loading…
Reference in New Issue