[Ts2-pm-cvs-commit] ts2-pm/ts2-pm-core/src/main/java/net/sf/ts2/pm/cli TS2PackageManagerCLI.java,NON
Status: Pre-Alpha
Brought to you by:
nchalumeau
From: Nicolas C. <nch...@us...> - 2005-05-24 20:49:28
|
Update of /cvsroot/ts2-pm/ts2-pm/ts2-pm-core/src/main/java/net/sf/ts2/pm/cli In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16431/cli Modified Files: CLIManager.java Added Files: TS2PackageManagerCLI.java Log Message: cli integration Index: CLIManager.java =================================================================== RCS file: /cvsroot/ts2-pm/ts2-pm/ts2-pm-core/src/main/java/net/sf/ts2/pm/cli/CLIManager.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CLIManager.java 17 May 2005 20:06:48 -0000 1.3 --- CLIManager.java 24 May 2005 20:49:19 -0000 1.4 *************** *** 20,23 **** --- 20,32 ---- package net.sf.ts2.pm.cli; + import org.apache.commons.cli.ParseException; + + import org.apache.commons.cli.CommandLine; + import org.apache.commons.cli.CommandLineParser; + import org.apache.commons.cli.HelpFormatter; + import org.apache.commons.cli.OptionBuilder; + import org.apache.commons.cli.Options; + import org.apache.commons.cli.PosixParser; + /** * @author chalumeau *************** *** 38,81 **** public static final char VERSION = 'v'; ! // private Options options = null; ! // ! // public CLIManager() ! // { ! // options = new Options(); ! // options.addOption( OptionBuilder.withLongOpt( "define" ).hasArg().withDescription( ! // "Define a system property" ).create( SET_SYSTEM_PROPERTY ) ); ! // options.addOption( OptionBuilder.withLongOpt( "offline" ).withDescription( "Work offline" ).create( ! // OFFLINE ) ); ! //// options.addOption( OptionBuilder.withLongOpt( "mojoDescriptors" ).withDescription( ! //// "Display available mojoDescriptors" ).create( LIST_GOALS ) ); ! // options.addOption( OptionBuilder.withLongOpt( "help" ).withDescription( "Display help information" ).create( ! // HELP ) ); ! // options.addOption( OptionBuilder.withLongOpt( "version" ).withDescription( "Display version information" ).create( ! // VERSION ) ); ! // options.addOption( OptionBuilder.withLongOpt( "debug" ).withDescription( "Produce execution debug output" ).create( ! // DEBUG ) ); ! // options.addOption( OptionBuilder.withLongOpt( "errors" ).withDescription( ! // "Produce execution error messages" ).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( ! // "Update all snapshots regardless of repository policies" ).create( UPDATE_SNAPSHOTS ) ); ! // } ! // ! // public CommandLine parse( String[] args ) ! // throws ParseException ! // { ! // CommandLineParser parser = new PosixParser(); ! // return parser.parse( options, args ); ! // } ! // ! // public void displayHelp() ! // { ! // System.out.println(); ! // ! // HelpFormatter formatter = new HelpFormatter(); ! // formatter.printHelp( "maven [options] [goal [goal2 [goal3] ...]]", "\nOptions:", options, "\n" ); ! // } } \ No newline at end of file --- 47,78 ---- public static final char VERSION = 'v'; ! private Options options = null; ! ! public CLIManager() ! { ! options = new Options(); ! options.addOption( OptionBuilder.withLongOpt( "define" ).hasArg().withDescription( ! "Define a system property" ).create( SET_SYSTEM_PROPERTY ) ); ! options.addOption( OptionBuilder.withLongOpt( "offline" ).withDescription( "Work offline" ).create( ! OFFLINE ) ); ! options.addOption( OptionBuilder.withLongOpt( "help" ).withDescription( "Display help information" ).create( ! HELP ) ); ! options.addOption( OptionBuilder.withLongOpt( "version" ).withDescription( "Display version information" ).create( ! VERSION ) ); ! } ! ! public CommandLine parse( String[] args ) ! throws ParseException ! { ! CommandLineParser parser = new PosixParser(); ! return parser.parse( options, args ); ! } ! ! public void displayHelp() ! { ! System.out.println(); ! ! HelpFormatter formatter = new HelpFormatter(); ! formatter.printHelp( "ts2-pm [options] [comand [comand2 [comand3] ...]]", "\nOptions:", options, "\n" ); ! } } \ No newline at end of file --- NEW FILE: TS2PackageManagerCLI.java --- /* * Created on 24 mai 2005 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package net.sf.ts2.pm.cli; import java.io.File; import net.sf.ts2.pm.TS2PackageManager; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.ParseException; import org.springframework.context.support.ClassPathXmlApplicationContext; /** * @author chalumeau */ public class TS2PackageManagerCLI { private static CLIManager cliManager; public static File userDir = new File( System.getProperty( "user.dir" ) ); public static int main( String[] args/*, ClassWorld classWorld*/ ) { cliManager = new CLIManager(); CommandLine commandLine; try { commandLine = cliManager.parse( args ); } catch ( ParseException e ) { System.err.println( "Unable to parse command line options: " + e.getMessage() ); cliManager.displayHelp(); return 1; } initializeSystemProperties( commandLine ); // ---------------------------------------------------------------------- // Process particular command line options // ---------------------------------------------------------------------- if ( commandLine.hasOption( CLIManager.HELP ) ) { cliManager.displayHelp(); return 0; } if ( commandLine.hasOption( CLIManager.VERSION ) ) { showVersion(); return 0; } // ---------------------------------------------------------------------- // Use Spring to instanciate a manager and execute the command list // ---------------------------------------------------------------------- ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( "/applicationContext.xml" ); TS2PackageManager manager = (TS2PackageManager) ctx.getBean( "ts2PackageManager" ); return manager.executeCommand( commandLine.getArgList() ); } /** * @todo print the curent version */ private static void showVersion() { System.out.println( "ts2-pm version: 0.1-SNAPSHOT" ); } // ---------------------------------------------------------------------- // System properties handling // ---------------------------------------------------------------------- private static void initializeSystemProperties( CommandLine commandLine ) { // ---------------------------------------------------------------------- // 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] ); } } } private static void setCliProperty( String property ) { String name = null; String value = null; 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(); } System.setProperty( name, value ); } } |