dion 2003/08/18 21:22:38
Modified: src/java/org/apache/maven/cli App.java CLIManager.java
Log:
Switch stable branch back to HEAD
Revision Changes Path
1.32 +122 -41 maven/src/java/org/apache/maven/cli/App.java
Index: App.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/cli/App.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- App.java 2 Aug 2003 22:26:20 -0000 1.31
+++ App.java 19 Aug 2003 04:22:38 -0000 1.32
@@ -61,16 +61,21 @@
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.ParseException;
import org.apache.commons.jelly.JellyException;
-import org.apache.maven.MavenConstants;
-import org.apache.maven.Maven;
+import org.apache.commons.jelly.XMLOutput;
+import org.apache.maven.MavenUtils;
+import org.apache.maven.MavenSession;
import org.apache.maven.NoGoalException;
-import org.apache.maven.UnknownGoalException;
-import org.apache.maven.verifier.ChecksumVerificationException;
import org.apache.maven.verifier.RepoConfigException;
import org.apache.maven.verifier.UnsatisfiedDependencyException;
+import org.apache.maven.verifier.ChecksumVerificationException;
+import org.apache.maven.UnknownGoalException;
+import org.apache.maven.jelly.MavenJellyContext;
import java.io.File;
import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintStream;
+import java.io.Writer;
import java.net.MalformedURLException;
import java.text.BreakIterator;
import java.util.ArrayList;
@@ -93,14 +98,10 @@
*
* @todo Separate the computation of the available goals from the display
* of the goals. The goal computation logic needs to be moved
- * out of this class and be placed in Maven.java proper.
+ * out of this class and be placed in MavenSession.java proper.
* @todo All logging needs to be done via commons-logging. No
* System.out.* and Jelly needs to be taught to take a
- * logger. In an attempt to isolate everything in Maven.java.
- * @todo All references to any classes that are internal to Maven need to
- * be removed from this class. Anything to do with Jelly or Werkz
- * or Maven internals can't be present here as this should simply
- * be a harness for running the Maven facade.
+ * logger. In an attempt to isolate everything in MavenSession.java.
*/
public class App
{
@@ -161,6 +162,9 @@
/** Display help option. */
private static final String DISPLAY_HELP = "h";
+ /** Display info option. */
+ private static final String DISPLAY_INFO = "i";
+
/** Display version option. */
private static final String DISPLAY_VERSION = "v";
@@ -179,6 +183,9 @@
/** Debug option. */
private static final String DEBUG = "X";
+ /** Working dir option. */
+ private static final String WORKING_DIR = "d";
+
// ------------------------------------------------------------
// C L A S S M E M B E R S
// ------------------------------------------------------------
@@ -190,8 +197,19 @@
/** CLI Parser */
private CommandLine commandLine;
- /** Facade for all Maven activity. */
- private Maven maven;
+ /** Saved original console System.out. */
+ private PrintStream consoleOut;
+
+ /** Saved original console System.err. */
+ private PrintStream consoleErr;
+
+ /** Jelly's underlying writer. */
+ private Writer writer;
+
+ /** MavenSession Jelly rootContext. */
+ private MavenJellyContext rootContext;
+
+ private MavenSession mavenSession;
/** Constructor. */
public App()
@@ -203,6 +221,26 @@
// ----------------------------------------------------------------------
/**
+ * Set Jelly rootContext.
+ *
+ * @param rootContext The mavenSession jelly rootContext.
+ */
+ public void setRootContext( MavenJellyContext rootContext )
+ {
+ this.rootContext = rootContext;
+ }
+
+ /**
+ * Retrieve the Jelly rootContext.
+ *
+ * @return The Jelly rootContext.
+ */
+ public MavenJellyContext getRootContext()
+ {
+ return rootContext;
+ }
+
+ /**
* Set the cli parser.
*
* @param commandLine The command line parser.
@@ -244,6 +282,7 @@
setCli( CLIManager.parse( args ) );
initializeSystemProperties();
+ initializeRootContext();
initializeMavenSession();
}
@@ -287,51 +326,85 @@
}
/**
- * Initialize the maven bean.
+ * Initialize the IO streams.
+ *
+ * @throws IOException on error creating XML output and handling System.err
+ * and out
*/
- private void initializeMavenSession()
- throws Exception
+ protected void initializeRootContext()
+ throws IOException
{
- maven = new Maven();
- }
+ this.consoleOut = System.out;
+ this.consoleErr = System.err;
- /**
- * Setup any system properties that have been specified on
- * the CLI.
- */
- public void initializeSystemProperties()
- {
- // Options that are set on the command line become system properties
- // and therefore are set in the session properties. System properties
- // are most dominant.
+ this.writer = new OutputStreamWriter( this.consoleOut );
+ XMLOutput output = XMLOutput.createXMLOutput( writer, false );
+ if ( getCli().hasOption( WORKING_DIR ) )
+ {
+ String workingDir = getCli().getOptionValue(WORKING_DIR);
+ System.setProperty("user.dir", workingDir);
+ }
+
+ // We will assume here that there might not be a project.xml file present
+ // and we will create the root context from the directory gleaned from
+ // the user.dir system property.
+ MavenJellyContext c = MavenUtils.createContext( new File(
System.getProperty("user.dir") ) );
+ setRootContext( c );
+
if ( getCli().hasOption( DEBUG ) )
{
- System.setProperty( MavenConstants.DEBUG_ON, "true" );
+ getRootContext().setXMLOutput( output );
+ getRootContext().setDebugOn( Boolean.TRUE );
}
else
{
- System.setProperty( MavenConstants.DEBUG_ON, "false" );
+ getRootContext().setXMLOutput( output );
+ getRootContext().setDebugOn( Boolean.FALSE );
}
if ( getCli().hasOption( EMACS_OUTPUT ) )
{
- System.setProperty( MavenConstants.EMACS_MODE_ON, "true" );
+ getRootContext().setEmacsModeOn( Boolean.TRUE );
}
else
{
- System.setProperty( MavenConstants.EMACS_MODE_ON, "false" );
+ getRootContext().setEmacsModeOn( Boolean.FALSE );
}
if ( getCli().hasOption( WORK_OFFLINE ) )
{
- System.setProperty( MavenConstants.ONLINE, "false" );
+ getRootContext().setOnline( Boolean.FALSE );
}
else
{
- System.setProperty( MavenConstants.ONLINE, "true" );
+ getRootContext().setOnline( Boolean.TRUE );
}
+ }
+ /**
+ * Initialize the mavenSession bean.
+ */
+ private void initializeMavenSession()
+ {
+ // Even though the rootProject contains the rootContext we set both in
+ // the even that there is no rootProject and the user is requesting goals
+ // to be attained that do not directly relate to a project. A goaly that
+ // may, say, generate the skeletal maven application build.
+
+ mavenSession = new MavenSession();
+ mavenSession.setRootContext( getRootContext() );
+ // note: setRootDescriptor file is a static method
+ MavenSession.setRootDescriptorFile( getDescriptorFile() );
+ mavenSession.addGoalNames( getCli().getArgList() );
+ }
+
+ /**
+ * Setup any system properties that have been specified on
+ * the CLI.
+ */
+ public void initializeSystemProperties()
+ {
if ( getCli().hasOption( SET_SYSTEM_PROPERTY ) )
{
String[] defStrs = getCli().getOptionValues( SET_SYSTEM_PROPERTY );
@@ -372,7 +445,7 @@
* Perform main operations in a non-static method.
*
* @param args Arguments passed in from main().
- * @param fullStart Date the maven process was started.
+ * @param fullStart Date the mavenSession process was started.
*/
public void doMain( String[] args, Date fullStart )
{
@@ -418,6 +491,14 @@
return;
}
+ if ( getCli().hasOption( DISPLAY_INFO ) )
+ {
+ CLIManager.displayInfo();
+ System.out.println( "" );
+ exit( returnCode );
+ return;
+ }
+
if ( getCli().hasOption( DISPLAY_VERSION ) )
{
printConsoleMavenHeader();
@@ -439,6 +520,8 @@
try
{
+ mavenSession.initialize();
+
if ( getCli().hasOption( DISPLAY_GOALS ) )
{
displayGoals();
@@ -448,7 +531,7 @@
}
else
{
- maven.attainGoals( getDescriptorFile() , getCli().getArgList());
+ mavenSession.attainGoals();
}
}
catch ( UnsatisfiedDependencyException e )
@@ -515,8 +598,6 @@
System.err.println( "Column.... " + column );
System.err.println( msg );
- // FIXME: Make sure it gets dumped out while we're fixing stuff
- e.printStackTrace();
}
catch ( Exception e )
{
@@ -674,7 +755,7 @@
System.out.println( " __ __" );
System.out.println( "| \\/ |__ _Apache__ ___" );
System.out.println( "| |\\/| / _` \\ V / -_) ' \\ ~ intelligent projects
~" );
- System.out.println( "|_| |_\\__,_|\\_/\\___|_||_| v. " +
org.apache.maven.Maven.APP_VERSION );
+ System.out.println( "|_| |_\\__,_|\\_/\\___|_||_| v. " +
org.apache.maven.MavenSession.APP_VERSION );
}
/**
@@ -701,7 +782,7 @@
System.out.println( format( "", title.length(), '`' ) );
- Set goals = maven.getAllGoalNames();
+ Set goals = mavenSession.getAllGoalNames();
List list = new ArrayList( goals );
@@ -727,7 +808,7 @@
for ( Iterator i = list.iterator(); i.hasNext(); )
{
String goalName = (String) i.next(); // goal name
- String goalDescription = maven.getGoalDescription( goalName );
+ String goalDescription = mavenSession.getGoalDescription( goalName );
StringTokenizer st = new StringTokenizer( goalName, ":" );
String pluginName = st.nextToken(); //ex. java
@@ -862,7 +943,7 @@
{
String goalName = (String) i.next();
- String goalDescription = maven.getGoalDescription( goalName );
+ String goalDescription = mavenSession.getGoalDescription( goalName );
boolean hasDesc = false;
1.12 +11 -0 maven/src/java/org/apache/maven/cli/CLIManager.java
Index: CLIManager.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/cli/CLIManager.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- CLIManager.java 28 Jul 2003 03:55:10 -0000 1.11
+++ CLIManager.java 19 Aug 2003 04:22:38 -0000 1.12
@@ -63,6 +63,7 @@
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
+import org.apache.env.Which;
/** Utility for managing and parsing MavenSession's command-line.
*
@@ -205,5 +206,15 @@
options,
"\n" );
+ }
+
+ /** Display system information. This is generally useful, maybe
+ * this could be made part of CLI? But it definitely shouldn't
+ * be stuck in MavenSession.
+ */
+ public static void displayInfo()
+ {
+ Which env = new Which();
+ env.doMain( new String[]{} );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]