You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by br...@apache.org on 2005/09/15 06:36:20 UTC
svn commit: r289145 -
/maven/components/trunk/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java
Author: brett
Date: Wed Sep 14 21:36:15 2005
New Revision: 289145
URL: http://svn.apache.org/viewcvs?rev=289145&view=rev
Log:
clean up CLI
Modified:
maven/components/trunk/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java
Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java?rev=289145&r1=289144&r2=289145&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java Wed Sep 14 21:36:15 2005
@@ -61,11 +61,13 @@
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
+ * @noinspection UseOfSystemOutOrSystemErr,ACCESS_STATIC_VIA_INSTANCE
*/
public class MavenCli
{
- public static File userDir = new File( System.getProperty( "user.dir" ) );
-
+ /**
+ * @noinspection ConfusingMainMethod
+ */
public static int main( String[] args, ClassWorld classWorld )
{
// ----------------------------------------------------------------------
@@ -96,22 +98,6 @@
return 1;
}
- // ----------------------------------------------------------------------
- //
- // 1) maven user configuration directory ( ~/.m2 )
- // 2) maven home
- // 3) local repository
- //
- // ----------------------------------------------------------------------
-
- // File userConfigurationDirectory = getUserConfigurationDirectory();
-
- // Properties mavenProperties = getMavenProperties( userConfigurationDirectory );
-
- // ----------------------------------------------------------------------
- //
- // ----------------------------------------------------------------------
-
initializeSystemProperties( commandLine );
boolean debug = commandLine.hasOption( CLIManager.DEBUG );
@@ -157,9 +143,9 @@
showFatalError( "Unable to start the embedded plexus container", e, showErrors );
return 1;
}
-
+
String userSettingsPath = null;
-
+
if ( commandLine.hasOption( CLIManager.ALTERNATE_USER_SETTINGS ) )
{
userSettingsPath = commandLine.getOptionValue( CLIManager.ALTERNATE_USER_SETTINGS );
@@ -169,18 +155,19 @@
try
{
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." );
+ System.out.println( "WARNING: Alternate user settings file: " + userSettingsPath +
+ " is invalid. Using default path." );
}
}
@@ -245,26 +232,26 @@
{
loggerManager.setThreshold( Logger.LEVEL_DEBUG );
}
-
+
ProfileManager profileManager = new DefaultProfileManager( embedder.getContainer() );
-
+
if ( commandLine.hasOption( CLIManager.ACTIVATE_PROFILES ) )
{
String profilesLine = commandLine.getOptionValue( CLIManager.ACTIVATE_PROFILES );
-
+
StringTokenizer profileTokens = new StringTokenizer( profilesLine, "," );
-
- while( profileTokens.hasMoreTokens() )
+
+ while ( profileTokens.hasMoreTokens() )
{
String profileAction = profileTokens.nextToken().trim();
-
+
if ( profileAction.startsWith( "-" ) )
{
profileManager.explicitlyDeactivate( profileAction.substring( 1 ) );
}
else if ( profileAction.startsWith( "+" ) )
{
- profileManager.explicitlyActivate(profileAction.substring( 1 ) );
+ profileManager.explicitlyActivate( profileAction.substring( 1 ) );
}
else
{
@@ -275,7 +262,7 @@
}
request = createRequest( embedder, commandLine, settings, eventDispatcher, loggerManager, profileManager );
-
+
setProjectFileOptions( commandLine, request );
maven = createMavenInstance( embedder, settings.isInteractiveMode() );
@@ -296,7 +283,6 @@
catch ( ComponentLifecycleException e )
{
showFatalError( "Error releasing logging manager", e, showErrors );
- return 1;
}
}
}
@@ -310,7 +296,7 @@
return 1;
}
- MavenExecutionResponse response = null;
+ MavenExecutionResponse response;
try
{
response = maven.execute( request );
@@ -346,15 +332,16 @@
}
}
- private static MavenExecutionRequest createRequest( Embedder embedder, CommandLine commandLine,
- Settings settings, EventDispatcher eventDispatcher,
- LoggerManager loggerManager, ProfileManager profileManager )
+ private static MavenExecutionRequest createRequest( Embedder embedder, CommandLine commandLine, Settings settings,
+ EventDispatcher eventDispatcher, LoggerManager loggerManager,
+ ProfileManager profileManager )
throws ComponentLookupException
{
- MavenExecutionRequest request = null;
+ MavenExecutionRequest request;
ArtifactRepository localRepository = createLocalRepository( embedder, settings, commandLine );
+ File userDir = new File( System.getProperty( "user.dir" ) );
request = new DefaultMavenExecutionRequest( localRepository, settings, eventDispatcher,
commandLine.getArgList(), userDir.getPath(), profileManager );
@@ -369,7 +356,7 @@
{
request.setRecursive( false );
}
-
+
if ( commandLine.hasOption( CLIManager.FAIL_FAST ) )
{
request.setFailureBehavior( ReactorManager.FAIL_FAST );
@@ -382,7 +369,7 @@
{
request.setFailureBehavior( ReactorManager.FAIL_NEVER );
}
-
+
return request;
}
@@ -428,12 +415,12 @@
ArtifactRepositoryFactory.ROLE );
String url = settings.getLocalRepository();
-
+
if ( !url.startsWith( "file:" ) )
{
url = "file://" + url;
}
-
+
ArtifactRepository localRepository = new DefaultArtifactRepository( "local", url, repositoryLayout );
boolean snapshotPolicySet = false;
@@ -496,21 +483,24 @@
// are most dominant.
// ----------------------------------------------------------------------
+ Properties systemProperties = new Properties();
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] );
+ setCliProperty( defStrs[i], systemProperties );
}
}
+
+ System.setProperties( systemProperties );
}
- private static void setCliProperty( String property )
+ private static void setCliProperty( String property, Properties systemProperties )
{
- String name = null;
+ String name;
- String value = null;
+ String value;
int i = property.indexOf( "=" );
@@ -527,7 +517,7 @@
value = property.substring( i + 1 ).trim();
}
- System.setProperty( name, value );
+ systemProperties.setProperty( name, value );
}
// ----------------------------------------------------------------------
@@ -537,7 +527,7 @@
static class CLIManager
{
public static final char ALTERNATE_POM_FILE = 'f';
-
+
public static final char BATCH_MODE = 'B';
public static final char SET_SYSTEM_PROPERTY = 'D';
@@ -554,7 +544,7 @@
public static final char VERSION = 'v';
- private Options options = null;
+ private Options options;
public static final char NON_RECURSIVE = 'N';
@@ -589,9 +579,10 @@
public 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.withLongOpt( "file" ).hasArg().withDescription(
+ "Force the use of an alternate POM file." ).create( ALTERNATE_POM_FILE ) );
+
options.addOption(
OptionBuilder.withLongOpt( "define" ).hasArg().withDescription( "Define a system property" ).create(
SET_SYSTEM_PROPERTY ) );
@@ -641,16 +632,19 @@
options.addOption(
OptionBuilder.withLongOpt( "lax-checksums" ).withDescription( "Warn if checksums don't match" ).create(
CHECKSUM_WARNING_POLICY ) );
-
+
options.addOption( OptionBuilder.withLongOpt( "settings" )
.withDescription( "Alternate path for the user settings file" ).hasArg()
.create( ALTERNATE_USER_SETTINGS ) );
-
- options.addOption( OptionBuilder.withLongOpt( "fail-fast" ).withDescription( "Stop at first failure in reactorized builds" ).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 ) );
-
- options.addOption( OptionBuilder.withLongOpt( "fail-never" ).withDescription( "NEVER fail the build, regardless of project result" ).create( FAIL_NEVER ) );
+
+ options.addOption( OptionBuilder.withLongOpt( "fail-fast" ).withDescription(
+ "Stop at first failure in reactorized builds" ).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 ) );
+
+ options.addOption( OptionBuilder.withLongOpt( "fail-never" ).withDescription(
+ "NEVER fail the build, regardless of project result" ).create( FAIL_NEVER ) );
}
public CommandLine parse( String[] args )
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: svn commit: r289145 - /maven/components/trunk/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java
Posted by Brett Porter <br...@apache.org>.
To stop IntelliJ whining at me :)
- Brett
Emmanuel Venisse wrote:
> brett,
>
> What is @noinspection tag?
>
> Emmanuel
>
>> /**
>> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
>> * @version $Id$
>> + * @noinspection UseOfSystemOutOrSystemErr,ACCESS_STATIC_VIA_INSTANCE
>> */
>> public class MavenCli
>> {
>> - public static File userDir = new File( System.getProperty(
>> "user.dir" ) );
>> -
>> + /**
>> + * @noinspection ConfusingMainMethod
>> + */
>> public static int main( String[] args, ClassWorld classWorld )
>> {
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: svn commit: r289145 - /maven/components/trunk/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java
Posted by Emmanuel Venisse <em...@venisse.net>.
brett,
What is @noinspection tag?
Emmanuel
> /**
> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
> * @version $Id$
> + * @noinspection UseOfSystemOutOrSystemErr,ACCESS_STATIC_VIA_INSTANCE
> */
> public class MavenCli
> {
> - public static File userDir = new File( System.getProperty( "user.dir" ) );
> -
> + /**
> + * @noinspection ConfusingMainMethod
> + */
> public static int main( String[] args, ClassWorld classWorld )
> {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org