mirror of
https://github.com/apache/maven.git
synced 2025-02-21 01:15:42 +00:00
MNG-2722 Create a strategy for providing sane default values in the MavenExecutionRequest
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@491468 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
26f1777dba
commit
87b3775025
@ -19,13 +19,11 @@
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.maven.MavenTransferListener;
|
||||
import org.apache.maven.SettingsConfigurationException;
|
||||
import org.apache.maven.embedder.MavenEmbedder;
|
||||
import org.apache.maven.embedder.MavenEmbedderException;
|
||||
import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.reactor.MavenExecutionException;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.codehaus.plexus.classworlds.ClassWorld;
|
||||
|
||||
import java.io.File;
|
||||
@ -49,13 +47,12 @@ public static void main( String[] args )
|
||||
|
||||
int result = main( args, classWorld );
|
||||
|
||||
System.exit(result);
|
||||
System.exit( result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection ConfusingMainMethod
|
||||
*/
|
||||
public static int main( String[] args, ClassWorld classWorld )
|
||||
/** @noinspection ConfusingMainMethod */
|
||||
public static int main( String[] args,
|
||||
ClassWorld classWorld )
|
||||
{
|
||||
// ----------------------------------------------------------------------
|
||||
// Setup the command line parser
|
||||
@ -78,15 +75,15 @@ public static int main( String[] args, ClassWorld classWorld )
|
||||
// TODO: maybe classworlds could handle this requirement...
|
||||
if ( "1.4".compareTo( System.getProperty( "java.specification.version" ) ) > 0 )
|
||||
{
|
||||
System.err.println( "Sorry, but JDK 1.4 or above is required to execute Maven. You appear to be using "
|
||||
+ "Java:" );
|
||||
System.err.println( "java version \"" + System.getProperty( "java.version", "<unknown java version>" )
|
||||
+ "\"" );
|
||||
System.err.println( System.getProperty( "java.runtime.name", "<unknown runtime name>" ) + " (build "
|
||||
+ System.getProperty( "java.runtime.version", "<unknown runtime version>" ) + ")" );
|
||||
System.err.println( System.getProperty( "java.vm.name", "<unknown vm name>" ) + " (build "
|
||||
+ System.getProperty( "java.vm.version", "<unknown vm version>" ) + ", "
|
||||
+ System.getProperty( "java.vm.info", "<unknown vm info>" ) + ")" );
|
||||
System.err.println(
|
||||
"Sorry, but JDK 1.4 or above is required to execute Maven. You appear to be using " + "Java:" );
|
||||
System.err.println(
|
||||
"java version \"" + System.getProperty( "java.version", "<unknown java version>" ) + "\"" );
|
||||
System.err.println( System.getProperty( "java.runtime.name", "<unknown runtime name>" ) + " (build " +
|
||||
System.getProperty( "java.runtime.version", "<unknown runtime version>" ) + ")" );
|
||||
System.err.println( System.getProperty( "java.vm.name", "<unknown vm name>" ) + " (build " +
|
||||
System.getProperty( "java.vm.version", "<unknown vm version>" ) + ", " +
|
||||
System.getProperty( "java.vm.info", "<unknown vm info>" ) + ")" );
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -129,13 +126,11 @@ else if ( debug )
|
||||
|
||||
//** use CLI option values directly in request where possible
|
||||
|
||||
MavenEmbedder mavenEmbedder = new MavenEmbedder();
|
||||
MavenEmbedder mavenEmbedder;
|
||||
|
||||
try
|
||||
{
|
||||
mavenEmbedder.setClassWorld( classWorld );
|
||||
|
||||
mavenEmbedder.start();
|
||||
mavenEmbedder = new MavenEmbedder( classWorld );
|
||||
}
|
||||
catch ( MavenEmbedderException e )
|
||||
{
|
||||
@ -160,20 +155,21 @@ else if ( debug )
|
||||
usePluginRegistry = false;
|
||||
}
|
||||
|
||||
Boolean pluginUpdateOverride = Boolean.FALSE;
|
||||
boolean pluginUpdateOverride = false;
|
||||
|
||||
if ( commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES ) ||
|
||||
commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES2 ) )
|
||||
{
|
||||
pluginUpdateOverride = Boolean.TRUE;
|
||||
pluginUpdateOverride = true;
|
||||
}
|
||||
else if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_UPDATES ) )
|
||||
{
|
||||
pluginUpdateOverride = Boolean.FALSE;
|
||||
pluginUpdateOverride = false;
|
||||
}
|
||||
|
||||
boolean noSnapshotUpdates = false;
|
||||
if (commandLine.hasOption(CLIManager.SUPRESS_SNAPSHOT_UPDATES)) {
|
||||
if ( commandLine.hasOption( CLIManager.SUPRESS_SNAPSHOT_UPDATES ) )
|
||||
{
|
||||
noSnapshotUpdates = true;
|
||||
}
|
||||
|
||||
@ -361,53 +357,33 @@ else if ( quiet )
|
||||
|
||||
Properties executionProperties = getExecutionProperties( commandLine );
|
||||
|
||||
File userSettingsPath = mavenEmbedder.getUserSettingsPath( commandLine.getOptionValue( CLIManager.ALTERNATE_USER_SETTINGS ) );
|
||||
|
||||
File globalSettingsFile = mavenEmbedder.getGlobalSettingsPath();
|
||||
|
||||
Settings settings = mavenEmbedder.buildSettings( userSettingsPath,
|
||||
globalSettingsFile,
|
||||
interactive,
|
||||
offline,
|
||||
usePluginRegistry,
|
||||
pluginUpdateOverride );
|
||||
|
||||
String localRepositoryPath = mavenEmbedder.getLocalRepositoryPath( settings );
|
||||
|
||||
// @todo we either make Settings the official configuration mechanism or allow the indiviaul setting in the request
|
||||
// for each of the things in the settings object. Seems redundant to configure some things via settings and
|
||||
// some via the request. The Settings object is used in about 16 different places in the core so something
|
||||
// to consider.
|
||||
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
|
||||
.setBasedir( baseDirectory )
|
||||
.setGoals( goals )
|
||||
.setLocalRepositoryPath( localRepositoryPath ) // default: ~/.m2/repository
|
||||
.setProperties( executionProperties ) // optional
|
||||
.setReactorFailureBehavior( reactorFailureBehaviour ) // default: fail fast
|
||||
.setRecursive( recursive ) // default: false
|
||||
.setUseReactor( useReactor ) // default: true
|
||||
.setRecursive( recursive ) // default: true
|
||||
.setUseReactor( useReactor ) // default: false
|
||||
.setPomFile( alternatePomFile ) // optional
|
||||
.setShowErrors( showErrors ) // default: false
|
||||
// Settings
|
||||
.setSettingsFile( commandLine.getOptionValue( CLIManager.ALTERNATE_USER_SETTINGS ) )
|
||||
//.setLocalRepositoryPath( localRepositoryPath ) // default: ~/.m2/repository
|
||||
.setInteractiveMode( interactive ) // default: false
|
||||
.setUsePluginRegistry( usePluginRegistry )
|
||||
.setOffline( offline ) // default: false
|
||||
.setUsePluginUpdateOverride( pluginUpdateOverride )
|
||||
.addActiveProfiles( activeProfiles ) // optional
|
||||
.addInactiveProfiles( inactiveProfiles ) // optional
|
||||
//
|
||||
.setLoggingLevel( loggingLevel ) // default: info
|
||||
.setSettings( settings ) // default: ~/.m2/settings.xml
|
||||
.setTransferListener( transferListener ) // default: batch mode which goes along with interactive
|
||||
.setOffline( offline ) // default: false
|
||||
.setUpdateSnapshots( updateSnapshots ) // default: false
|
||||
.setNoSnapshotUpdates( noSnapshotUpdates ) // default: false
|
||||
.setGlobalChecksumPolicy( globalChecksumPolicy ); // default: warn
|
||||
|
||||
mavenEmbedder.execute( request );
|
||||
}
|
||||
catch ( SettingsConfigurationException e )
|
||||
{
|
||||
showError( "Error reading settings.xml: " + e.getMessage(), e, showErrors );
|
||||
|
||||
return 1;
|
||||
}
|
||||
catch ( MavenExecutionException e )
|
||||
{
|
||||
showFatalError( "Unable to configure the Maven application", e, showErrors );
|
||||
@ -418,7 +394,9 @@ else if ( quiet )
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static void showFatalError( String message, Exception e, boolean show )
|
||||
private static void showFatalError( String message,
|
||||
Exception e,
|
||||
boolean show )
|
||||
{
|
||||
System.err.println( "FATAL ERROR: " + message );
|
||||
if ( show )
|
||||
@ -433,7 +411,9 @@ private static void showFatalError( String message, Exception e, boolean show )
|
||||
}
|
||||
}
|
||||
|
||||
private static void showError( String message, Exception e, boolean show )
|
||||
private static void showError( String message,
|
||||
Exception e,
|
||||
boolean show )
|
||||
{
|
||||
System.err.println( message );
|
||||
if ( show )
|
||||
@ -456,8 +436,8 @@ private static void showVersion()
|
||||
|
||||
if ( properties.getProperty( "builtOn" ) != null )
|
||||
{
|
||||
System.out.println( "Maven version: " + properties.getProperty( "version", "unknown" )
|
||||
+ " built on " + properties.getProperty( "builtOn" ) );
|
||||
System.out.println( "Maven version: " + properties.getProperty( "version", "unknown" ) + " built on " +
|
||||
properties.getProperty( "builtOn" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -499,7 +479,8 @@ private static Properties getExecutionProperties( CommandLine commandLine )
|
||||
return executionProperties;
|
||||
}
|
||||
|
||||
private static void setCliProperty( String property, Properties executionProperties )
|
||||
private static void setCliProperty( String property,
|
||||
Properties executionProperties )
|
||||
{
|
||||
String name;
|
||||
|
||||
|
@ -122,6 +122,7 @@ public class DefaultMaven
|
||||
public MavenExecutionResult execute( MavenExecutionRequest request )
|
||||
throws MavenExecutionException
|
||||
{
|
||||
//*** Move this stuff to the embedder
|
||||
boolean snapshotPolicySet = false;
|
||||
|
||||
if ( request.isOffline() )
|
||||
@ -143,11 +144,6 @@ else if ( request.isNoSnapshotUpdates() )
|
||||
|
||||
artifactRepositoryFactory.setGlobalChecksumPolicy( request.getGlobalChecksumPolicy() );
|
||||
|
||||
if ( request.getLocalRepository() == null )
|
||||
{
|
||||
request.setLocalRepository( mavenTools.createLocalRepository( request.getLocalRepositoryPath() ) );
|
||||
}
|
||||
|
||||
Logger logger = loggerManager.getLoggerForComponent( Mojo.ROLE );
|
||||
|
||||
if ( request.getEventMonitors() == null )
|
||||
@ -165,6 +161,8 @@ else if ( request.isNoSnapshotUpdates() )
|
||||
|
||||
wagonManager.setOnline( !request.getSettings().isOffline() );
|
||||
|
||||
//***
|
||||
|
||||
EventDispatcher dispatcher = new DefaultEventDispatcher( request.getEventMonitors() );
|
||||
|
||||
String event = MavenEvents.REACTOR_EXECUTION;
|
||||
|
@ -16,16 +16,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.monitor.event.EventMonitor;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.apache.maven.wagon.events.TransferListener;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.ArrayList;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
@ -38,13 +38,17 @@ public class DefaultMavenExecutionRequest
|
||||
// Settings equivalents
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
private Settings settings;
|
||||
|
||||
private String settingsFile;
|
||||
|
||||
private ArtifactRepository localRepository;
|
||||
|
||||
private File localRepositoryPath;
|
||||
|
||||
private boolean offline;
|
||||
private boolean offline = false;
|
||||
|
||||
private boolean interactiveMode;
|
||||
private boolean interactiveMode = true;
|
||||
|
||||
private List proxies;
|
||||
|
||||
@ -59,6 +63,8 @@ public class DefaultMavenExecutionRequest
|
||||
// This is off by default because it causes so many problem. It should just be extracted and redone.
|
||||
private boolean usePluginRegistry = false;
|
||||
|
||||
private boolean usePluginUpdateOverride;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Request
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -67,19 +73,17 @@ public class DefaultMavenExecutionRequest
|
||||
|
||||
private List goals;
|
||||
|
||||
private Settings settings;
|
||||
|
||||
private boolean useReactor;
|
||||
private boolean useReactor = false;
|
||||
|
||||
private String pomFile;
|
||||
|
||||
private String reactorFailureBehavior;
|
||||
private String reactorFailureBehavior = REACTOR_FAIL_FAST;
|
||||
|
||||
private Properties properties;
|
||||
|
||||
private Date startTime;
|
||||
|
||||
private boolean showErrors;
|
||||
private boolean showErrors = false;
|
||||
|
||||
private List eventMonitors;
|
||||
|
||||
@ -89,20 +93,36 @@ public class DefaultMavenExecutionRequest
|
||||
|
||||
private TransferListener transferListener;
|
||||
|
||||
private int loggingLevel;
|
||||
private int loggingLevel = LOGGING_LEVEL_INFO;
|
||||
|
||||
private boolean updateSnapshots;
|
||||
private String globalChecksumPolicy = CHECKSUM_POLICY_WARN;
|
||||
|
||||
private String globalChecksumPolicy;
|
||||
|
||||
private boolean recursive;
|
||||
private boolean recursive = true;
|
||||
|
||||
private boolean updateSnapshots = false;
|
||||
|
||||
/**
|
||||
* Suppress SNAPSHOT updates.
|
||||
* @issue MNG-2681
|
||||
*/
|
||||
private boolean noSnapshotUpdates;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public String getSettingsFile()
|
||||
{
|
||||
return settingsFile;
|
||||
}
|
||||
|
||||
public MavenExecutionRequest setSettingsFile( String settingsFile )
|
||||
{
|
||||
this.settingsFile = settingsFile;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getBaseDirectory()
|
||||
{
|
||||
return basedir.getAbsolutePath();
|
||||
@ -474,6 +494,20 @@ public MavenExecutionRequest setUsePluginRegistry( boolean usePluginRegistry )
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isUsePluginUpdateOverride()
|
||||
{
|
||||
return usePluginUpdateOverride;
|
||||
}
|
||||
|
||||
public MavenExecutionRequest setUsePluginUpdateOverride( boolean usePluginUpdateOverride )
|
||||
{
|
||||
this.usePluginUpdateOverride = usePluginUpdateOverride;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
public MavenExecutionRequest setRecursive( boolean recursive )
|
||||
{
|
||||
this.recursive = recursive;
|
||||
|
@ -29,9 +29,8 @@
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @author Jason van Zyl
|
||||
* @version $Id$
|
||||
* @todo merge Settings,RuntimeInfo,MavenSession into this. make adapters for everything
|
||||
*/
|
||||
public interface MavenExecutionRequest
|
||||
{
|
||||
@ -74,149 +73,120 @@ public interface MavenExecutionRequest
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// Base directory
|
||||
|
||||
MavenExecutionRequest setBasedir( File basedir );
|
||||
|
||||
String getBaseDirectory();
|
||||
|
||||
// Settings
|
||||
MavenExecutionRequest setSettings( Settings settings );
|
||||
|
||||
Settings getSettings();
|
||||
|
||||
// Timing (remove this)
|
||||
MavenExecutionRequest setStartTime( Date start );
|
||||
|
||||
Date getStartTime();
|
||||
|
||||
// Goals
|
||||
MavenExecutionRequest setGoals( List goals );
|
||||
|
||||
List getGoals();
|
||||
|
||||
// Properties
|
||||
MavenExecutionRequest setProperties( Properties properties );
|
||||
|
||||
Properties getProperties();
|
||||
|
||||
// Reactor
|
||||
MavenExecutionRequest setReactorFailureBehavior( String failureBehavior );
|
||||
|
||||
String getReactorFailureBehavior();
|
||||
|
||||
MavenExecutionRequest setUseReactor( boolean useReactor );
|
||||
|
||||
boolean useReactor();
|
||||
|
||||
// Recursive (really to just process the top-level POM)
|
||||
MavenExecutionRequest setRecursive( boolean recursive );
|
||||
|
||||
boolean isRecursive();
|
||||
|
||||
// Event monitors
|
||||
MavenExecutionRequest addEventMonitor( EventMonitor monitor );
|
||||
|
||||
List getEventMonitors();
|
||||
|
||||
// Pom
|
||||
MavenExecutionRequest setPomFile( String pomFilename );
|
||||
|
||||
String getPomFile();
|
||||
|
||||
// Errors
|
||||
MavenExecutionRequest setShowErrors( boolean showErrors );
|
||||
|
||||
boolean isShowErrors();
|
||||
|
||||
// Transfer listeners
|
||||
MavenExecutionRequest setTransferListener( TransferListener transferListener );
|
||||
|
||||
TransferListener getTransferListener();
|
||||
|
||||
// Logging
|
||||
MavenExecutionRequest setLoggingLevel( int loggingLevel );
|
||||
|
||||
int getLoggingLevel();
|
||||
|
||||
// Update snapshots
|
||||
MavenExecutionRequest setUpdateSnapshots( boolean updateSnapshots );
|
||||
|
||||
boolean isUpdateSnapshots();
|
||||
|
||||
MavenExecutionRequest setNoSnapshotUpdates( boolean noSnapshotUpdates );
|
||||
boolean isNoSnapshotUpdates();
|
||||
|
||||
// Checksum policy
|
||||
MavenExecutionRequest setGlobalChecksumPolicy( String globalChecksumPolicy );
|
||||
|
||||
boolean isNoSnapshotUpdates();
|
||||
|
||||
String getGlobalChecksumPolicy();
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Settings equivalents
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Settings
|
||||
MavenExecutionRequest setSettingsFile( String settingsFile );
|
||||
String getSettingsFile();
|
||||
|
||||
// Local repository
|
||||
|
||||
MavenExecutionRequest setLocalRepositoryPath( String localRepository );
|
||||
|
||||
MavenExecutionRequest setLocalRepositoryPath( File localRepository );
|
||||
|
||||
File getLocalRepositoryPath();
|
||||
|
||||
MavenExecutionRequest setLocalRepository( ArtifactRepository repository );
|
||||
|
||||
ArtifactRepository getLocalRepository();
|
||||
|
||||
// Interactive
|
||||
MavenExecutionRequest setInteractiveMode( boolean interactive );
|
||||
|
||||
boolean isInteractiveMode();
|
||||
|
||||
// Offline
|
||||
MavenExecutionRequest setOffline( boolean offline );
|
||||
|
||||
boolean isOffline();
|
||||
|
||||
// Profiles
|
||||
List getProfiles();
|
||||
|
||||
MavenExecutionRequest setProfiles( List profiles );
|
||||
|
||||
MavenExecutionRequest addActiveProfile( String profile );
|
||||
|
||||
MavenExecutionRequest addActiveProfiles( List profiles );
|
||||
|
||||
List getActiveProfiles();
|
||||
|
||||
MavenExecutionRequest addInactiveProfile( String profile );
|
||||
|
||||
MavenExecutionRequest addInactiveProfiles( List profiles );
|
||||
|
||||
List getInactiveProfiles();
|
||||
|
||||
// Proxies
|
||||
List getProxies();
|
||||
|
||||
MavenExecutionRequest setProxies( List proxies );
|
||||
|
||||
// Servers
|
||||
List getServers();
|
||||
|
||||
MavenExecutionRequest setServers( List servers );
|
||||
|
||||
// Mirrors
|
||||
List getMirrors();
|
||||
|
||||
MavenExecutionRequest setMirrors( List mirrors );
|
||||
|
||||
// Plugin groups
|
||||
List getPluginGroups();
|
||||
|
||||
MavenExecutionRequest setPluginGroups( List pluginGroups );
|
||||
|
||||
// Plugin registry
|
||||
boolean isUsePluginRegistry();
|
||||
|
||||
MavenExecutionRequest setUsePluginRegistry( boolean usePluginRegistry );
|
||||
|
||||
boolean isUsePluginUpdateOverride();
|
||||
MavenExecutionRequest setUsePluginUpdateOverride( boolean usePluginUpdateOverride );
|
||||
}
|
||||
|
@ -53,6 +53,7 @@
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.PlexusContainerException;
|
||||
import org.codehaus.plexus.classworlds.ClassWorld;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
|
||||
import org.codehaus.plexus.component.repository.ComponentDescriptor;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
|
||||
@ -63,7 +64,6 @@
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -81,8 +81,6 @@
|
||||
*/
|
||||
public class MavenEmbedder
|
||||
{
|
||||
public static final String userHome = System.getProperty( "user.home" );
|
||||
|
||||
private PlexusContainer container;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
@ -91,8 +89,6 @@ public class MavenEmbedder
|
||||
|
||||
private MavenProjectBuilder mavenProjectBuilder;
|
||||
|
||||
private ArtifactRepositoryFactory artifactRepositoryFactory;
|
||||
|
||||
private WagonManager wagonManager;
|
||||
|
||||
private MavenXpp3Reader modelReader;
|
||||
@ -103,6 +99,8 @@ public class MavenEmbedder
|
||||
|
||||
private PluginDescriptorBuilder pluginDescriptorBuilder;
|
||||
|
||||
private ArtifactRepositoryFactory artifactRepositoryFactory;
|
||||
|
||||
private ArtifactFactory artifactFactory;
|
||||
|
||||
private ArtifactResolver artifactResolver;
|
||||
@ -121,39 +119,54 @@ public class MavenEmbedder
|
||||
|
||||
private ArtifactRepository localRepository;
|
||||
|
||||
private ClassLoader classLoader;
|
||||
|
||||
private ClassWorld classWorld;
|
||||
|
||||
private ClassRealm realm;
|
||||
|
||||
private MavenEmbedderLogger logger;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// User options
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private boolean started = false;
|
||||
|
||||
private MavenEmbedRequest embedderRequest;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constructors
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
public MavenEmbedder( ClassWorld classWorld )
|
||||
throws MavenEmbedderException
|
||||
{
|
||||
this( classWorld, null );
|
||||
}
|
||||
|
||||
public MavenEmbedder( ClassWorld classWorld, MavenEmbedderLogger logger )
|
||||
throws MavenEmbedderException
|
||||
{
|
||||
this.classWorld = classWorld;
|
||||
|
||||
this.logger = logger;
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
public MavenEmbedder( ClassLoader classLoader )
|
||||
throws MavenEmbedderException
|
||||
{
|
||||
this( classLoader, null );
|
||||
}
|
||||
|
||||
public MavenEmbedder( ClassLoader classLoader, MavenEmbedderLogger logger )
|
||||
throws MavenEmbedderException
|
||||
{
|
||||
this( new ClassWorld( "plexus.core", classLoader ), logger );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Accessors
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public void setClassLoader( ClassLoader classLoader )
|
||||
{
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
public ClassLoader getClassLoader()
|
||||
{
|
||||
return classLoader;
|
||||
}
|
||||
|
||||
public void setClassWorld( ClassWorld classWorld )
|
||||
{
|
||||
this.classWorld = classWorld;
|
||||
}
|
||||
|
||||
public ClassWorld getClassWorld()
|
||||
{
|
||||
return classWorld;
|
||||
@ -177,7 +190,6 @@ public void setLogger( MavenEmbedderLogger logger )
|
||||
public Model readModel( File model )
|
||||
throws XmlPullParserException, IOException
|
||||
{
|
||||
checkStarted();
|
||||
return modelReader.read( new FileReader( model ) );
|
||||
}
|
||||
|
||||
@ -185,7 +197,6 @@ public void writeModel( Writer writer,
|
||||
Model model )
|
||||
throws IOException
|
||||
{
|
||||
checkStarted();
|
||||
modelWriter.write( writer, model );
|
||||
}
|
||||
|
||||
@ -196,77 +207,62 @@ public void writeModel( Writer writer,
|
||||
public MavenProject readProject( File mavenProject )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
checkStarted();
|
||||
return mavenProjectBuilder.build( mavenProject, localRepository, profileManager );
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
/** @deprecated */
|
||||
public MavenProject readProjectWithDependencies( File mavenProject,
|
||||
TransferListener transferListener )
|
||||
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException
|
||||
{
|
||||
checkStarted();
|
||||
return mavenProjectBuilder.buildWithDependencies( mavenProject, localRepository, profileManager,
|
||||
transferListener );
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
/** @deprecated */
|
||||
public MavenProject readProjectWithDependencies( File mavenProject )
|
||||
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException
|
||||
{
|
||||
checkStarted();
|
||||
return mavenProjectBuilder.buildWithDependencies( mavenProject, localRepository, profileManager );
|
||||
}
|
||||
|
||||
private MavenExecutionRequest populateMavenExecutionRequestWithDefaults( MavenExecutionRequest request )
|
||||
private MavenExecutionRequest populateMavenExecutionRequestWithDefaults( MavenExecutionRequest r )
|
||||
throws MavenEmbedderException
|
||||
{
|
||||
// Local repository
|
||||
if ( request.getLocalRepository() == null )
|
||||
// Settings
|
||||
// Local repository
|
||||
// TransferListener
|
||||
// EventMonitor
|
||||
|
||||
if ( r.getSettings() == null )
|
||||
{
|
||||
request.setLocalRepository( localRepository );
|
||||
File userSettingsPath = mavenTools.getUserSettingsPath( r.getSettingsFile() );
|
||||
|
||||
File localRepository = new File( request.getLocalRepository().getBasedir() );
|
||||
File globalSettingsFile = mavenTools.getGlobalSettingsPath();
|
||||
|
||||
if ( !localRepository.exists() )
|
||||
try
|
||||
{
|
||||
localRepository.mkdirs();
|
||||
r.setSettings( mavenTools.buildSettings( userSettingsPath, globalSettingsFile, r.isInteractiveMode(),
|
||||
r.isOffline(), r.isUsePluginRegistry(),
|
||||
r.isUsePluginUpdateOverride() ) );
|
||||
}
|
||||
catch ( SettingsConfigurationException e )
|
||||
{
|
||||
throw new MavenEmbedderException( "Error processing settings.xml.", e );
|
||||
}
|
||||
}
|
||||
|
||||
// Settings
|
||||
|
||||
if ( request.getSettings() == null )
|
||||
if ( r.getLocalRepository() == null )
|
||||
{
|
||||
request.setSettings( settings );
|
||||
String localRepositoryPath = mavenTools.getLocalRepositoryPath( r.getSettings() );
|
||||
|
||||
if ( r.getLocalRepository() == null )
|
||||
{
|
||||
r.setLocalRepository( mavenTools.createLocalRepository( new File( localRepositoryPath ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
|
||||
.setBasedir( baseDirectory )
|
||||
.setGoals( goals )
|
||||
.setLocalRepositoryPath( localRepositoryPath ) // default: ~/.m2/repository
|
||||
.setReactorFailureBehavior( reactorFailureBehaviour ) // default: fail fast
|
||||
.setRecursive( recursive ) // default: false
|
||||
.setUseReactor( useReactor ) // default: true
|
||||
.setShowErrors( showErrors ) // default: false
|
||||
.setInteractiveMode( interactive ) // default: false
|
||||
.setLoggingLevel( loggingLevel ) // default: info
|
||||
.setSettings( settings ) // default: ~/.m2/settings.xml
|
||||
.setTransferListener( transferListener ) // default: batch mode which goes along with interactive
|
||||
.setOffline( offline ) // default: false
|
||||
.setUpdateSnapshots( updateSnapshots ) // default: false
|
||||
.setNoSnapshotUpdates( noSnapshotUpdates ) // default: false
|
||||
.setGlobalChecksumPolicy( globalChecksumPolicy ); // default: warn
|
||||
*/
|
||||
|
||||
// Classify settings as being used for the life of session or request
|
||||
|
||||
if ( request.getLocalRepository() == null )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
return request;
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -287,14 +283,18 @@ public MavenExecutionResult readProjectWithDependencies( MavenExecutionRequest r
|
||||
{
|
||||
MavenProject project = null;
|
||||
|
||||
request = populateMavenExecutionRequestWithDefaults( request );
|
||||
|
||||
try
|
||||
{
|
||||
request = populateMavenExecutionRequestWithDefaults( request );
|
||||
|
||||
project = mavenProjectBuilder.buildWithDependencies( new File( request.getPomFile() ),
|
||||
request.getLocalRepository(), profileManager,
|
||||
request.getTransferListener() );
|
||||
}
|
||||
catch ( MavenEmbedderException e )
|
||||
{
|
||||
return new DefaultMavenExecutionResult( project, Collections.singletonList( e ) );
|
||||
}
|
||||
catch ( ProjectBuildingException e )
|
||||
{
|
||||
return new DefaultMavenExecutionResult( project, Collections.singletonList( e ) );
|
||||
@ -321,7 +321,6 @@ public Artifact createArtifact( String groupId,
|
||||
String scope,
|
||||
String type )
|
||||
{
|
||||
checkStarted();
|
||||
return artifactFactory.createArtifact( groupId, artifactId, version, scope, type );
|
||||
}
|
||||
|
||||
@ -331,7 +330,6 @@ public Artifact createArtifactWithClassifier( String groupId,
|
||||
String type,
|
||||
String classifier )
|
||||
{
|
||||
checkStarted();
|
||||
return artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
|
||||
}
|
||||
|
||||
@ -340,7 +338,6 @@ public void resolve( Artifact artifact,
|
||||
ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||
{
|
||||
checkStarted();
|
||||
artifactResolver.resolve( artifact, remoteRepositories, localRepository );
|
||||
}
|
||||
|
||||
@ -367,7 +364,7 @@ public PluginDescriptor getPluginDescriptor( SummaryPluginDescriptor summaryPlug
|
||||
try
|
||||
{
|
||||
InputStream is =
|
||||
classLoader.getResourceAsStream( "/plugins/" + summaryPluginDescriptor.getArtifactId() + ".xml" );
|
||||
realm.getResourceAsStream( "/plugins/" + summaryPluginDescriptor.getArtifactId() + ".xml" );
|
||||
|
||||
pluginDescriptor = pluginDescriptorBuilder.build( new InputStreamReader( is ) );
|
||||
}
|
||||
@ -397,7 +394,6 @@ private SummaryPluginDescriptor makeMockPlugin( String groupId,
|
||||
public List getLifecyclePhases()
|
||||
throws MavenEmbedderException
|
||||
{
|
||||
checkStarted();
|
||||
List phases = new ArrayList();
|
||||
|
||||
ComponentDescriptor descriptor = container.getComponentDescriptor( LifecycleExecutor.ROLE );
|
||||
@ -459,7 +455,6 @@ public ArtifactRepository createLocalRepository( String url,
|
||||
public ArtifactRepository createRepository( String url,
|
||||
String repositoryId )
|
||||
{
|
||||
checkStarted();
|
||||
// snapshots vs releases
|
||||
// offline = to turning the update policy off
|
||||
|
||||
@ -483,7 +478,7 @@ public ArtifactRepository createRepository( String url,
|
||||
// Lifecycle
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public void start()
|
||||
private void start()
|
||||
throws MavenEmbedderException
|
||||
{
|
||||
start( new DefaultMavenEmbedRequest() );
|
||||
@ -494,31 +489,6 @@ public void start( MavenEmbedRequest req )
|
||||
{
|
||||
this.embedderRequest = req;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Set the maven.home system property which is need by components like
|
||||
// the plugin registry builder.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
if ( classWorld == null && classLoader == null )
|
||||
{
|
||||
throw new IllegalStateException(
|
||||
"A classWorld or classloader must be specified using setClassLoader|World(ClassLoader)." );
|
||||
}
|
||||
|
||||
if ( classWorld == null )
|
||||
{
|
||||
classWorld = new ClassWorld();
|
||||
|
||||
try
|
||||
{
|
||||
classWorld.newRealm( "plexus.core", classLoader );
|
||||
}
|
||||
catch ( DuplicateRealmException e )
|
||||
{
|
||||
// won't happen
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
container = new DefaultPlexusContainer( null, null, null, classWorld );
|
||||
@ -578,8 +548,6 @@ public void start( MavenEmbedRequest req )
|
||||
|
||||
wagonManager = (WagonManager) container.lookup( WagonManager.ROLE );
|
||||
|
||||
started = true;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Settings
|
||||
//
|
||||
@ -597,7 +565,7 @@ public void start( MavenEmbedRequest req )
|
||||
req.setGlobalSettingsFile( mavenTools.getGlobalSettingsPath() );
|
||||
}
|
||||
|
||||
settings = mavenTools.buildSettings( req.getUserSettingsFile(), req.getGlobalSettingsFile(), null );
|
||||
settings = mavenTools.buildSettings( req.getUserSettingsFile(), req.getGlobalSettingsFile(), false );
|
||||
|
||||
resolveParameters( settings );
|
||||
|
||||
@ -671,7 +639,6 @@ private void resolveParameters( Settings settings )
|
||||
public void stop()
|
||||
throws MavenEmbedderException
|
||||
{
|
||||
started = false;
|
||||
try
|
||||
{
|
||||
container.release( mavenProjectBuilder );
|
||||
@ -688,82 +655,18 @@ public void stop()
|
||||
// Start of new embedder API
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public void execute( MavenExecutionRequest request )
|
||||
public MavenExecutionResult execute( MavenExecutionRequest request )
|
||||
throws MavenExecutionException
|
||||
{
|
||||
checkStarted();
|
||||
|
||||
maven.execute( request );
|
||||
}
|
||||
|
||||
public Settings buildSettings( File userSettingsPath,
|
||||
File globalSettingsPath,
|
||||
boolean interactive,
|
||||
boolean offline,
|
||||
boolean usePluginRegistry,
|
||||
Boolean pluginUpdateOverride )
|
||||
throws SettingsConfigurationException
|
||||
{
|
||||
checkStarted();
|
||||
return mavenTools.buildSettings( userSettingsPath, globalSettingsPath, interactive, offline, usePluginRegistry,
|
||||
pluginUpdateOverride );
|
||||
}
|
||||
|
||||
public Settings buildSettings( File userSettingsPath,
|
||||
File globalSettingsPath,
|
||||
boolean interactive,
|
||||
boolean offline,
|
||||
boolean usePluginRegistry,
|
||||
boolean pluginUpdateOverride )
|
||||
throws SettingsConfigurationException
|
||||
{
|
||||
checkStarted();
|
||||
return mavenTools.buildSettings( userSettingsPath, globalSettingsPath, interactive, offline, usePluginRegistry,
|
||||
Boolean.valueOf( pluginUpdateOverride ) );
|
||||
}
|
||||
|
||||
public Settings buildSettings( File userSettingsPath,
|
||||
File globalSettingsPath,
|
||||
Boolean pluginUpdateOverride )
|
||||
throws SettingsConfigurationException
|
||||
{
|
||||
checkStarted();
|
||||
return mavenTools.buildSettings( userSettingsPath, globalSettingsPath, pluginUpdateOverride );
|
||||
}
|
||||
|
||||
public Settings buildSettings( File userSettingsPath,
|
||||
File globalSettingsPath,
|
||||
boolean pluginUpdateOverride )
|
||||
throws SettingsConfigurationException
|
||||
{
|
||||
checkStarted();
|
||||
return mavenTools.buildSettings( userSettingsPath, globalSettingsPath, Boolean.valueOf( pluginUpdateOverride ) );
|
||||
}
|
||||
|
||||
public File getUserSettingsPath( String optionalSettingsPath )
|
||||
{
|
||||
checkStarted();
|
||||
return mavenTools.getUserSettingsPath( optionalSettingsPath );
|
||||
}
|
||||
|
||||
public File getGlobalSettingsPath()
|
||||
{
|
||||
checkStarted();
|
||||
return mavenTools.getGlobalSettingsPath();
|
||||
}
|
||||
|
||||
public String getLocalRepositoryPath( Settings settings )
|
||||
{
|
||||
checkStarted();
|
||||
return mavenTools.getLocalRepositoryPath( settings );
|
||||
}
|
||||
|
||||
private void checkStarted()
|
||||
{
|
||||
if ( !started )
|
||||
try
|
||||
{
|
||||
throw new IllegalStateException(
|
||||
"The embedder is not started, you need to call start() on the embedder prior to calling this method" );
|
||||
request = populateMavenExecutionRequestWithDefaults( request );
|
||||
}
|
||||
catch ( MavenEmbedderException e )
|
||||
{
|
||||
throw new MavenExecutionException( "Error populating request with default values.", e );
|
||||
}
|
||||
|
||||
return maven.execute( request );
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public Settings buildSettings( File userSettingsPath,
|
||||
boolean interactive,
|
||||
boolean offline,
|
||||
boolean usePluginRegistry,
|
||||
Boolean pluginUpdateOverride )
|
||||
boolean pluginUpdateOverride )
|
||||
throws SettingsConfigurationException
|
||||
{
|
||||
Settings settings = buildSettings(userSettingsPath,
|
||||
@ -101,7 +101,7 @@ public Settings buildSettings( File userSettingsPath,
|
||||
|
||||
public Settings buildSettings( File userSettingsPath,
|
||||
File globalSettingsPath,
|
||||
Boolean pluginUpdateOverride )
|
||||
boolean pluginUpdateOverride )
|
||||
throws SettingsConfigurationException
|
||||
{
|
||||
Settings settings;
|
||||
@ -122,7 +122,7 @@ public Settings buildSettings( File userSettingsPath,
|
||||
|
||||
RuntimeInfo runtimeInfo = new RuntimeInfo( settings );
|
||||
|
||||
runtimeInfo.setPluginUpdateOverride( pluginUpdateOverride );
|
||||
runtimeInfo.setPluginUpdateOverride( Boolean.valueOf( pluginUpdateOverride ) );
|
||||
|
||||
settings.setRuntimeInfo( runtimeInfo );
|
||||
|
||||
@ -326,7 +326,7 @@ public String getLocalRepositoryPath()
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
Boolean.FALSE) );
|
||||
false ) );
|
||||
}
|
||||
|
||||
public ArtifactRepository getLocalRepository()
|
||||
|
@ -56,12 +56,12 @@ Settings buildSettings( File userSettingsPath,
|
||||
boolean interactive,
|
||||
boolean offline,
|
||||
boolean usePluginRegistry,
|
||||
Boolean pluginUpdateOverride )
|
||||
boolean pluginUpdateOverride )
|
||||
throws SettingsConfigurationException;
|
||||
|
||||
Settings buildSettings( File userSettingsPath,
|
||||
File globalSettingsPath,
|
||||
Boolean pluginUpdateOverride )
|
||||
boolean pluginUpdateOverride )
|
||||
throws SettingsConfigurationException;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user