mirror of https://github.com/apache/maven.git
o slowly (and safely) trying to make bits extractable from here so that i
can integration it into the embedder and then use the embedder for the o it-plugin o maven cli o ant tasks o eclipse m2 plugin git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@291435 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ea993565a8
commit
1936ab200b
|
@ -43,6 +43,7 @@ import org.apache.maven.profiles.ProfileManager;
|
||||||
import org.apache.maven.reactor.ReactorException;
|
import org.apache.maven.reactor.ReactorException;
|
||||||
import org.apache.maven.settings.MavenSettingsBuilder;
|
import org.apache.maven.settings.MavenSettingsBuilder;
|
||||||
import org.apache.maven.settings.Settings;
|
import org.apache.maven.settings.Settings;
|
||||||
|
import org.apache.maven.settings.RuntimeInfo;
|
||||||
import org.codehaus.classworlds.ClassWorld;
|
import org.codehaus.classworlds.ClassWorld;
|
||||||
import org.codehaus.plexus.PlexusContainerException;
|
import org.codehaus.plexus.PlexusContainerException;
|
||||||
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
|
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
|
||||||
|
@ -50,7 +51,6 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
|
||||||
import org.codehaus.plexus.embed.Embedder;
|
import org.codehaus.plexus.embed.Embedder;
|
||||||
import org.codehaus.plexus.logging.Logger;
|
import org.codehaus.plexus.logging.Logger;
|
||||||
import org.codehaus.plexus.logging.LoggerManager;
|
import org.codehaus.plexus.logging.LoggerManager;
|
||||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -65,6 +65,8 @@ import java.util.StringTokenizer;
|
||||||
*/
|
*/
|
||||||
public class MavenCli
|
public class MavenCli
|
||||||
{
|
{
|
||||||
|
private static Embedder embedder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @noinspection ConfusingMainMethod
|
* @noinspection ConfusingMainMethod
|
||||||
*/
|
*/
|
||||||
|
@ -132,7 +134,7 @@ public class MavenCli
|
||||||
// bring the maven component to life for use.
|
// bring the maven component to life for use.
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
Embedder embedder = new Embedder();
|
embedder = new Embedder();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -141,93 +143,34 @@ public class MavenCli
|
||||||
catch ( PlexusContainerException e )
|
catch ( PlexusContainerException e )
|
||||||
{
|
{
|
||||||
showFatalError( "Unable to start the embedded plexus container", e, showErrors );
|
showFatalError( "Unable to start the embedded plexus container", e, showErrors );
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String userSettingsPath = null;
|
|
||||||
|
|
||||||
if ( commandLine.hasOption( CLIManager.ALTERNATE_USER_SETTINGS ) )
|
|
||||||
{
|
|
||||||
userSettingsPath = commandLine.getOptionValue( CLIManager.ALTERNATE_USER_SETTINGS );
|
|
||||||
}
|
|
||||||
|
|
||||||
Settings settings = null;
|
Settings settings = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MavenSettingsBuilder settingsBuilder = (MavenSettingsBuilder) embedder.lookup( MavenSettingsBuilder.ROLE );
|
settings = buildSettings( commandLine );
|
||||||
|
|
||||||
if ( userSettingsPath != null )
|
|
||||||
{
|
|
||||||
File userSettingsFile = new File( userSettingsPath );
|
|
||||||
|
|
||||||
if ( userSettingsFile.exists() && !userSettingsFile.isDirectory() )
|
|
||||||
{
|
|
||||||
settings = settingsBuilder.buildSettings( userSettingsFile );
|
|
||||||
}
|
}
|
||||||
else
|
catch ( Exception e )
|
||||||
{
|
|
||||||
System.out.println( "WARNING: Alternate user settings file: " + userSettingsPath +
|
|
||||||
" is invalid. Using default path." );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( settings == null )
|
|
||||||
{
|
|
||||||
settings = settingsBuilder.buildSettings();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( IOException e )
|
|
||||||
{
|
{
|
||||||
showFatalError( "Unable to read settings.xml", e, showErrors );
|
showFatalError( "Unable to read settings.xml", e, showErrors );
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
catch ( XmlPullParserException e )
|
|
||||||
{
|
|
||||||
showFatalError( "Unable to read settings.xml", e, showErrors );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
catch ( ComponentLookupException e )
|
|
||||||
{
|
|
||||||
showFatalError( "Unable to read settings.xml", e, showErrors );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( commandLine.hasOption( CLIManager.BATCH_MODE ) )
|
|
||||||
{
|
|
||||||
settings.setInteractiveMode( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES ) ||
|
|
||||||
commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES2 ) )
|
|
||||||
{
|
|
||||||
settings.getRuntimeInfo().setPluginUpdateOverride( Boolean.TRUE );
|
|
||||||
}
|
|
||||||
else if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_UPDATES ) )
|
|
||||||
{
|
|
||||||
settings.getRuntimeInfo().setPluginUpdateOverride( Boolean.FALSE );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( commandLine.hasOption( CLIManager.FORCE_PLUGIN_LATEST_CHECK ) )
|
|
||||||
{
|
|
||||||
settings.getRuntimeInfo().setCheckLatestPluginVersion( Boolean.TRUE );
|
|
||||||
}
|
|
||||||
else if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_LATEST_CHECK ) )
|
|
||||||
{
|
|
||||||
settings.getRuntimeInfo().setCheckLatestPluginVersion( Boolean.FALSE );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_REGISTRY ) )
|
|
||||||
{
|
|
||||||
settings.setUsePluginRegistry( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
Maven maven = null;
|
Maven maven = null;
|
||||||
|
|
||||||
MavenExecutionRequest request = null;
|
MavenExecutionRequest request = null;
|
||||||
|
|
||||||
LoggerManager loggerManager = null;
|
LoggerManager loggerManager = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// logger must be created first
|
// logger must be created first
|
||||||
loggerManager = (LoggerManager) embedder.lookup( LoggerManager.ROLE );
|
loggerManager = (LoggerManager) embedder.lookup( LoggerManager.ROLE );
|
||||||
|
|
||||||
if ( debug )
|
if ( debug )
|
||||||
{
|
{
|
||||||
loggerManager.setThreshold( Logger.LEVEL_DEBUG );
|
loggerManager.setThreshold( Logger.LEVEL_DEBUG );
|
||||||
|
@ -261,15 +204,16 @@ public class MavenCli
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
request = createRequest( embedder, commandLine, settings, eventDispatcher, loggerManager, profileManager );
|
request = createRequest( commandLine, settings, eventDispatcher, loggerManager, profileManager );
|
||||||
|
|
||||||
setProjectFileOptions( commandLine, request );
|
setProjectFileOptions( commandLine, request );
|
||||||
|
|
||||||
maven = createMavenInstance( embedder, settings.isInteractiveMode() );
|
maven = createMavenInstance( settings.isInteractiveMode() );
|
||||||
}
|
}
|
||||||
catch ( ComponentLookupException e )
|
catch ( ComponentLookupException e )
|
||||||
{
|
{
|
||||||
showFatalError( "Unable to configure the Maven application", e, showErrors );
|
showFatalError( "Unable to configure the Maven application", e, showErrors );
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
@ -317,6 +261,86 @@ public class MavenCli
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Settings buildSettings( CommandLine commandLine )
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
String userSettingsPath = null;
|
||||||
|
|
||||||
|
if ( commandLine.hasOption( CLIManager.ALTERNATE_USER_SETTINGS ) )
|
||||||
|
{
|
||||||
|
userSettingsPath = commandLine.getOptionValue( CLIManager.ALTERNATE_USER_SETTINGS );
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings settings = null;
|
||||||
|
|
||||||
|
MavenSettingsBuilder settingsBuilder = (MavenSettingsBuilder) embedder.lookup( MavenSettingsBuilder.ROLE );
|
||||||
|
|
||||||
|
if ( userSettingsPath != null )
|
||||||
|
{
|
||||||
|
File userSettingsFile = new File( userSettingsPath );
|
||||||
|
|
||||||
|
if ( userSettingsFile.exists() && !userSettingsFile.isDirectory() )
|
||||||
|
{
|
||||||
|
settings = settingsBuilder.buildSettings( userSettingsFile );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.out.println( "WARNING: Alternate user settings file: " + userSettingsPath +
|
||||||
|
" is invalid. Using default path." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( settings == null )
|
||||||
|
{
|
||||||
|
settings = settingsBuilder.buildSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
// why aren't these part of the runtime info? jvz.
|
||||||
|
|
||||||
|
if ( commandLine.hasOption( CLIManager.BATCH_MODE ) )
|
||||||
|
{
|
||||||
|
settings.setInteractiveMode( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_REGISTRY ) )
|
||||||
|
{
|
||||||
|
settings.setUsePluginRegistry( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create settings runtime info
|
||||||
|
|
||||||
|
settings.setRuntimeInfo( createRuntimeInfo( commandLine, settings ) );
|
||||||
|
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RuntimeInfo createRuntimeInfo( CommandLine commandLine, Settings settings )
|
||||||
|
{
|
||||||
|
RuntimeInfo runtimeInfo = new RuntimeInfo( settings );
|
||||||
|
|
||||||
|
if ( commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES ) ||
|
||||||
|
commandLine.hasOption( CLIManager.FORCE_PLUGIN_UPDATES2 ) )
|
||||||
|
{
|
||||||
|
runtimeInfo.setPluginUpdateOverride( Boolean.TRUE );
|
||||||
|
}
|
||||||
|
else if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_UPDATES ) )
|
||||||
|
{
|
||||||
|
runtimeInfo.setPluginUpdateOverride( Boolean.FALSE );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( commandLine.hasOption( CLIManager.FORCE_PLUGIN_LATEST_CHECK ) )
|
||||||
|
{
|
||||||
|
runtimeInfo.setCheckLatestPluginVersion( Boolean.TRUE );
|
||||||
|
}
|
||||||
|
else if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_LATEST_CHECK ) )
|
||||||
|
{
|
||||||
|
runtimeInfo.setCheckLatestPluginVersion( Boolean.FALSE );
|
||||||
|
}
|
||||||
|
|
||||||
|
return runtimeInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
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 );
|
System.err.println( "FATAL ERROR: " + message );
|
||||||
|
@ -332,8 +356,10 @@ public class MavenCli
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MavenExecutionRequest createRequest( Embedder embedder, CommandLine commandLine, Settings settings,
|
private static MavenExecutionRequest createRequest( CommandLine commandLine,
|
||||||
EventDispatcher eventDispatcher, LoggerManager loggerManager,
|
Settings settings,
|
||||||
|
EventDispatcher eventDispatcher,
|
||||||
|
LoggerManager loggerManager,
|
||||||
ProfileManager profileManager )
|
ProfileManager profileManager )
|
||||||
throws ComponentLookupException
|
throws ComponentLookupException
|
||||||
{
|
{
|
||||||
|
@ -385,7 +411,7 @@ public class MavenCli
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Maven createMavenInstance( Embedder embedder, boolean interactive )
|
private static Maven createMavenInstance( boolean interactive )
|
||||||
throws ComponentLookupException
|
throws ComponentLookupException
|
||||||
{
|
{
|
||||||
// TODO [BP]: doing this here as it is CLI specific, though it doesn't feel like the right place (likewise logger).
|
// TODO [BP]: doing this here as it is CLI specific, though it doesn't feel like the right place (likewise logger).
|
||||||
|
@ -424,6 +450,7 @@ public class MavenCli
|
||||||
ArtifactRepository localRepository = new DefaultArtifactRepository( "local", url, repositoryLayout );
|
ArtifactRepository localRepository = new DefaultArtifactRepository( "local", url, repositoryLayout );
|
||||||
|
|
||||||
boolean snapshotPolicySet = false;
|
boolean snapshotPolicySet = false;
|
||||||
|
|
||||||
if ( commandLine.hasOption( CLIManager.OFFLINE ) )
|
if ( commandLine.hasOption( CLIManager.OFFLINE ) )
|
||||||
{
|
{
|
||||||
settings.setOffline( true );
|
settings.setOffline( true );
|
||||||
|
|
Loading…
Reference in New Issue