incubator-easyant-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlboud...@apache.org
Subject svn commit: r1148895 - in /incubator/easyant/core/trunk: ./ bin/ src/main/java/org/apache/easyant/core/ src/main/java/org/apache/easyant/man/
Date Wed, 20 Jul 2011 18:53:35 GMT
Author: jlboudart
Date: Wed Jul 20 18:53:32 2011
New Revision: 1148895

URL: http://svn.apache.org/viewvc?rev=1148895&view=rev
Log:
EASYANT-30 Refactor EasyAnt main class to use commons-cli

Added:
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/EasyantOption.java
Removed:
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ManCommand.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ProjectMan.java
Modified:
    incubator/easyant/core/trunk/.classpath
    incubator/easyant/core/trunk/bin/easyant
    incubator/easyant/core/trunk/bin/easyant.bat
    incubator/easyant/core/trunk/build.xml
    incubator/easyant/core/trunk/module.ivy
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntMain.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/Describe.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListPhases.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListPlugins.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListProps.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListTargets.java

Modified: incubator/easyant/core/trunk/.classpath
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/.classpath?rev=1148895&r1=1148894&r2=1148895&view=diff
==============================================================================
--- incubator/easyant/core/trunk/.classpath (original)
+++ incubator/easyant/core/trunk/.classpath Wed Jul 20 18:53:32 2011
@@ -1,20 +1,4 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
--->
 <classpath>
 	<classpathentry kind="src" path="src/main/java"/>
 	<classpathentry kind="src" path="src/test/resources"/>
@@ -22,11 +6,10 @@
 	<classpathentry kind="src" path="src/test/java"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="lib" path="lib/main/ant-launcher.jar"/>
-	<classpathentry kind="lib" path="lib/main/ant-nodeps.jar"/>
 	<classpathentry kind="lib" path="lib/main/ant.jar"/>
-	<classpathentry kind="lib" path="lib/main/ivy.jar" sourcepath="/ivy"/>
+	<classpathentry kind="lib" path="lib/main/ivy.jar"/>
 	<classpathentry kind="lib" path="lib/main/ant-contrib.jar"/>
-	<classpathentry kind="lib" path="lib/test/ant-testutil-1.8.1.jar"/>
 	<classpathentry kind="lib" path="lib/test/junit-4.4.jar"/>
+	<classpathentry kind="lib" path="lib/main/commons-cli.jar"/>
 	<classpathentry kind="output" path="target/main/classes"/>
 </classpath>

Modified: incubator/easyant/core/trunk/bin/easyant
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/bin/easyant?rev=1148895&r1=1148894&r2=1148895&view=diff
==============================================================================
--- incubator/easyant/core/trunk/bin/easyant (original)
+++ incubator/easyant/core/trunk/bin/easyant Wed Jul 20 18:53:32 2011
@@ -405,7 +405,7 @@ else
 fi
 
 #set default EASYANT_ARGS
-EASYANT_ARGS="-config-file \"$EASYANT_HOME/easyant-conf.xml\" -Dbasedir=. -main org.apache.easyant.core.EasyAntMain -Deasyant.home=\"$EASYANT_HOME\" $EASYANT_ARGS"
+EASYANT_ARGS="-configfile \"$EASYANT_HOME/easyant-conf.xml\" -Dbasedir=. -main org.apache.easyant.core.EasyAntMain -Deasyant.home=\"$EASYANT_HOME\" $EASYANT_ARGS"
 
 ant_exec_command="exec \"$JAVACMD\" $ANT_OPTS $EASYANT_OPTS -classpath \"$LOCALCLASSPATH\" -Dant.home=\"$ANT_HOME\" -Dant.library.dir=\"$ANT_LIB\" $ant_sys_opts org.apache.tools.ant.launch.Launcher $ANT_ARGS $EASYANT_ARGS -cp \"$CLASSPATH\""
 if $ant_exec_debug ; then

Modified: incubator/easyant/core/trunk/bin/easyant.bat
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/bin/easyant.bat?rev=1148895&r1=1148894&r2=1148895&view=diff
==============================================================================
--- incubator/easyant/core/trunk/bin/easyant.bat (original)
+++ incubator/easyant/core/trunk/bin/easyant.bat Wed Jul 20 18:53:32 2011
@@ -33,7 +33,7 @@ goto end
 
 :run
 rem set the default parameters for easyant
-set EASYANT_ARGS=-Dbasedir=. -main org.apache.easyant.core.EasyAntMain -config-file %EASYANT_HOME%/easyant-conf.xml -Deasyant.home=%EASYANT_HOME% %EASYANT_ARGS%
+set EASYANT_ARGS=-Dbasedir=. -main org.apache.easyant.core.EasyAntMain -configfile %EASYANT_HOME%/easyant-conf.xml -Deasyant.home=%EASYANT_HOME% %EASYANT_ARGS%
 
 
 rem This part is fully inspirated by ant's script with some easyant customisation

Modified: incubator/easyant/core/trunk/build.xml
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/build.xml?rev=1148895&r1=1148894&r2=1148895&view=diff
==============================================================================
--- incubator/easyant/core/trunk/build.xml (original)
+++ incubator/easyant/core/trunk/build.xml Wed Jul 20 18:53:32 2011
@@ -66,11 +66,13 @@
         <path path="${java.class.path}"/>
             </classpath>
             <sysproperty key="easyant.home" file="${basedir}" />
-            <arg line="-config-file ${basedir}/easyant-conf.xml" />
+            <arg line="-configfile ${basedir}/easyant-conf.xml" />
             <arg line="-f ${basedir}/module.ivy" />
-            <arg line="dist" />
 	    <arg line="-Dskip.xooki=true"/>
+	    <arg line="-Dskip.svn=true"/>
 	    <arg line="-Dskip.emma=true"/>
+	    <arg line="-Dskip.antunit=true"/>
+            <arg line="dist" />
         </java>
     </target>
 

Modified: incubator/easyant/core/trunk/module.ivy
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/module.ivy?rev=1148895&r1=1148894&r2=1148895&view=diff
==============================================================================
--- incubator/easyant/core/trunk/module.ivy (original)
+++ incubator/easyant/core/trunk/module.ivy Wed Jul 20 18:53:32 2011
@@ -33,6 +33,7 @@
         <dependency org="org.apache.ant" name="ant" rev="1.8.2" conf="default->default"/>
         <dependency org="org.apache.ivy" name="ivy" rev="2.3.0-r1033912-patched" conf="default->core"/>
         <dependency org="ant-contrib" name="ant-contrib" rev="1.0b2" conf="default->default"/>
+        <dependency org="commons-cli" name="commons-cli" rev="1.2" conf="default->default"/>
         <!-- ivy uses a different namespace to reference ant -->
         <exclude org="ant" module="*"/>
 

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java?rev=1148895&r1=1148894&r2=1148895&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java Wed Jul 20 18:53:32 2011
@@ -537,6 +537,13 @@ public class EasyAntEngine {
      */
     public void doBuild() throws BuildException {
         final Project project = new Project();
+        configureProject(project);
+        initProject(project);
+        doBuild(project);
+        
+    }
+
+    private void doBuild(final Project project) throws Error {
         project.fireBuildStarted();
 
         Throwable error = null;
@@ -564,8 +571,6 @@ public class EasyAntEngine {
                         false)));
                 System.setErr(new PrintStream(new DemuxOutputStream(project,
                         true)));
-                configureProject(project);
-                initProject(project);
 
                 // make sure that we have a target to execute
                 if (configuration.getTargets().size() == 0) {
@@ -614,7 +619,6 @@ public class EasyAntEngine {
                 || configuration.getMsgOutputLevel() >= Project.MSG_VERBOSE) {
             printMemoryDetails(project);
         }
-
     }
 
     /**

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntMain.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntMain.java?rev=1148895&r1=1148894&r2=1148895&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntMain.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntMain.java Wed Jul 20 18:53:32 2011
@@ -32,12 +32,23 @@ import java.util.Properties;
 import java.util.Set;
 import java.util.Vector;
 
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
 import org.apache.easyant.core.ant.Phase;
 import org.apache.easyant.core.factory.EasyantConfigurationFactory;
-import org.apache.easyant.man.ProjectMan;
+import org.apache.easyant.man.Describe;
+import org.apache.easyant.man.EasyantOption;
+import org.apache.easyant.man.ListPhases;
+import org.apache.easyant.man.ListPlugins;
+import org.apache.easyant.man.ListProps;
+import org.apache.easyant.man.ListTargets;
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.DemuxInputStream;
-import org.apache.tools.ant.DemuxOutputStream;
 import org.apache.tools.ant.Diagnostics;
 import org.apache.tools.ant.ExitStatusException;
 import org.apache.tools.ant.Main;
@@ -72,20 +83,15 @@ public class EasyAntMain implements AntM
     }
     private EasyAntConfiguration easyAntConfiguration;
     private boolean projectHelp;
-    private boolean projectMan;
 
-    private ProjectMan man;
-    
+    private Options options = new Options();
+
     /**
      * Whether or not this instance has successfully been constructed and is
      * ready to run.
      */
     private boolean readyToRun;
     private Vector propertyFiles = new Vector(1);
-    private File buildFile;
-    private File buildModule;
-    private File easyantConfFile;
-    private String buildConf;
 
     /**
      * Prints the message of the Throwable if it (the message) is not
@@ -139,13 +145,16 @@ public class EasyAntMain implements AntM
     public void startAnt(String[] args, Properties additionalUserProperties,
             ClassLoader coreLoader) {
         easyAntConfiguration.setCoreLoader(coreLoader);
-        try {
-            Diagnostics.validateVersion();
-            processArgs(args);
-        } catch (Throwable exc) {
+        configureOptions();
+        CommandLineParser parser = new GnuParser();
+        CommandLine line = null;
+        try {
+            line = parser.parse(options, args);
+            processArgs(line);
+        } catch (ParseException exc) {
             if (easyAntConfiguration.getMsgOutputLevel() >= Project.MSG_VERBOSE) {
                 exc.printStackTrace();
-            } 
+            }
             handleLogfile();
             printMessage(exc);
             exit(1);
@@ -165,7 +174,7 @@ public class EasyAntMain implements AntM
         int exitCode = 1;
         try {
             try {
-                runBuild(coreLoader);
+                runBuild(line, coreLoader);
                 exitCode = 0;
             } catch (ExitStatusException ese) {
                 exitCode = ese.getStatus();
@@ -238,311 +247,164 @@ public class EasyAntMain implements AntM
      * 
      * @since Ant 1.6
      */
-    private void processArgs(String[] args) {
+    private void processArgs(CommandLine line) {
         String searchForThis = null;
         PrintStream logTo = null;
 
-        // cycle through given args
-
-        boolean justPrintUsage = false;
-        boolean justPrintVersion = false;
-        boolean justPrintDiagnostics = false;
-
-        for (int i = 0; i < args.length; i++) {
-            String arg = args[i];
-
-            if (arg.equals("-help") || arg.equals("-h")) {
-                justPrintUsage = true;
-            } else if (arg.equals("-version")) {
-                justPrintVersion = true;
-            } else if (arg.equals("-showMemoryDetails")) {
-                easyAntConfiguration.setShowMemoryDetails(true);
-            } else if (arg.equals("-diagnostics")) {
-                justPrintDiagnostics = true;
-            } else if (arg.equals("-quiet") || arg.equals("-q")) {
-                easyAntConfiguration.setMsgOutputLevel(Project.MSG_WARN);
-            } else if (arg.equals("-verbose") || arg.equals("-v")) {
-                easyAntConfiguration.setMsgOutputLevel(Project.MSG_VERBOSE);
-            } else if (arg.equals("-debug") || arg.equals("-d")) {
-                easyAntConfiguration.setMsgOutputLevel(Project.MSG_DEBUG);
-            } else if (arg.equals("-noinput")) {
-                easyAntConfiguration.setAllowInput(false);
-            } else if (arg.equals("-logfile") || arg.equals("-l")) {
-                try {
-                    File logFile = new File(args[i + 1]);
-                    i++;
-                    logTo = new PrintStream(new FileOutputStream(logFile));
-                    isLogFileUsed = true;
-                } catch (IOException ioe) {
-                    String msg = "Cannot write on the specified log file. "
-                            + "Make sure the path exists and you have write "
-                            + "permissions.";
-                    throw new BuildException(msg);
-                } catch (ArrayIndexOutOfBoundsException aioobe) {
-                    String msg = "You must specify a log file when "
-                            + "using the -log argument";
-                    throw new BuildException(msg);
-                }
-            } else if (arg.equals("-buildmodule") || arg.equals("-file")
-                    || arg.equals("-f")) {
-                i = handleArgBuildModule(args, i);
-                easyAntConfiguration.setBuildModule(buildModule);
-            } else if (arg.equals("-buildfile")) {
-                i = handleArgBuildFile(args, i);
-                easyAntConfiguration.setBuildFile(buildFile);
-            } else if (arg.equals("-buildconf") || arg.equals("-C")) {
-                i = handleArgBuildConf(args,i);
-                easyAntConfiguration.getActiveBuildConfigurations().add(buildConf);
-            } else if (arg.equals("-config-file")) {
-                i = handleArgEasyAntConf(args, i);
-                try {
-                    easyAntConfiguration = EasyantConfigurationFactory
-                            .getInstance().createConfigurationFromFile(
-                                    easyAntConfiguration,
-                                    easyantConfFile.toURL());
-                } catch (Exception e) {
-                    throw new BuildException(e);
-                }
-            } else if (arg.equals("-listener")) {
-                i = handleArgListener(args, i);
-            } else if (arg.startsWith("-D")) {
-                i = handleArgDefine(args, i);
-            } else if (arg.equals("-logger")) {
-                i = handleArgLogger(args, i);
-            } else if (arg.equals("-inputhandler")) {
-                i = handleArgInputHandler(args, i);
-            } else if (arg.equals("-emacs") || arg.equals("-e")) {
-                easyAntConfiguration.setEmacsMode(true);
-            } else if (arg.equals("-listTargets")
-                    || arg.equals("-describe")
-                    || arg.equals("-listProps")
-                    || arg.equals("-listPhases")
-                    || arg.equals("-listPlugins")) {
-                projectMan = true;
-                man = new ProjectMan();
-                man.setCommand(arg);
-                if(i < args.length-1 && !args[i+1].startsWith("-")) {
-                    man.addParam(args[++i]);
-                }
-            } else if(arg.equals("-projecthelp")
-                    || arg.equals("-p")) {
-                // set the flag to display the targets and quit
-                projectHelp = true;
-            } else if (arg.equals("-find") || arg.equals("-s")) {
-                // eat up next arg if present, default to module.ivy
-                if (i < args.length - 1) {
-                    searchForThis = args[++i];
-
-                } else {
-                    searchForThis = EasyAntConstants.DEFAULT_BUILD_MODULE;
-                }
-                easyAntConfiguration.setBuildModule(new File(searchForThis));
-                easyAntConfiguration.setBuildModuleLookupEnabled(true);
-            } else if (arg.startsWith("-propertyfile")) {
-                i = handleArgPropertyFile(args, i);
-            } else if (arg.equals("-k") || arg.equals("-keep-going")) {
-                easyAntConfiguration.setKeepGoingMode(true);
-            } else if (arg.equals("-offline") || arg.equals("-o")) {
-                easyAntConfiguration.setOffline(true);
-            } else if (arg.equals("-nice")) {
-                i = handleArgNice(args, i);
-            } else if (LAUNCH_COMMANDS.contains(arg)) {
-                // catch script/ant mismatch with a meaningful message
-                // we could ignore it, but there are likely to be other
-                // version problems, so we stamp down on the configuration now
-                String msg = "Ant's Main method is being handed "
-                        + "an option " + arg
-                        + " that is only for the launcher class."
-                        + "\nThis can be caused by a version mismatch between "
-                        + "the ant script/.bat file and Ant itself.";
-                throw new BuildException(msg);
-            } else if (arg.equals("-autoproxy")) {
-                easyAntConfiguration.setProxy(true);
-            } else if (arg.startsWith("-")) {
-                // we don't have any more args to recognize!
-                String msg = "Unknown argument: " + arg;
-                System.err.println(msg);
-                printUsage();
-                throw new BuildException("");
-            } else {
-                easyAntConfiguration.getTargets().addElement(arg);
-            }
+        if (line.hasOption("help")) {
+            printUsage();
+            return;
         }
-
         if (easyAntConfiguration.getMsgOutputLevel() >= Project.MSG_VERBOSE
-                || justPrintVersion) {
+                || line.hasOption("version")) {
             printVersion(easyAntConfiguration.getMsgOutputLevel());
-        }
-
-        if (justPrintUsage || justPrintVersion || justPrintDiagnostics) {
-            if (justPrintUsage) {
-                printUsage();
-            }
-            if (justPrintDiagnostics) {
-                Diagnostics.doReport(System.out, easyAntConfiguration
-                        .getMsgOutputLevel());
+            if (line.hasOption("version")) {
+                return;
             }
+        }
+        if (line.hasOption("showMemoryDetails")) {
+            easyAntConfiguration.setShowMemoryDetails(true);
+        }
+        if (line.hasOption("diagnostics")) {
+            Diagnostics.doReport(System.out,
+                    easyAntConfiguration.getMsgOutputLevel());
             return;
         }
-
-        // Load the property files specified by -propertyfile
-        loadPropertyFiles();
-
-        if (logTo != null) {
-            easyAntConfiguration.setOut(logTo);
-            easyAntConfiguration.setErr(logTo);
-            System.setOut(easyAntConfiguration.getOut());
-            System.setErr(easyAntConfiguration.getErr());
+        if (line.hasOption("quiet")) {
+            easyAntConfiguration.setMsgOutputLevel(Project.MSG_WARN);
         }
-        readyToRun = true;
-    }
-
-    // --------------------------------------------------------
-    // Methods for handling the command line arguments
-    // --------------------------------------------------------
-
-    /** Handle the -buildfile, -file, -f argument */
-    private int handleArgBuildFile(String[] args, int pos) {
-        try {
-            buildFile = new File(args[++pos].replace('/', File.separatorChar));
-            ++pos;
-        } catch (ArrayIndexOutOfBoundsException aioobe) {
-            throw new BuildException(
-                    "You must specify a buildfile when using the -buildfile argument");
+        if (line.hasOption("verbose")) {
+            easyAntConfiguration.setMsgOutputLevel(Project.MSG_VERBOSE);
         }
-        return pos;
-    }
-
-    private int handleArgBuildModule(String[] args, int pos) {
-        try {
-            buildModule = new File(args[++pos].replace('/', File.separatorChar));
-        } catch (ArrayIndexOutOfBoundsException aioobe) {
-            throw new BuildException(
-                    "You must specify a buildfile when using the -buildmodule argument");
+        if (line.hasOption("debug")) {
+            easyAntConfiguration.setMsgOutputLevel(Project.MSG_DEBUG);
         }
-        return pos;
-    }
-    
-    private int handleArgBuildConf(String[] args, int pos) {
-        try {
-            buildConf = args[++pos];
-        } catch (ArrayIndexOutOfBoundsException aioobe) {
-            throw new BuildException(
-                    "You must specify a build configuration when using the -buildconf argument");
+        if (line.hasOption("noinput")) {
+            easyAntConfiguration.setAllowInput(false);
         }
-        return pos;
-    }
-
-    /** Handle -config-file argument */
-    private int handleArgEasyAntConf(String[] args, int pos) {
-        try {
-            easyantConfFile = new File(args[++pos].replace('/',
-                    File.separatorChar));
-        } catch (ArrayIndexOutOfBoundsException aioobe) {
-            throw new BuildException(
-                    "You must specify an easyant ivy configuration when using the -easyantivyconf argument");
+        if (line.hasOption("logfile")) {
+            try {
+                File logFile = new File(line.getOptionValue("logfile"));
+                logTo = new PrintStream(new FileOutputStream(logFile));
+                isLogFileUsed = true;
+            } catch (IOException ioe) {
+                String msg = "Cannot write on the specified log file. "
+                        + "Make sure the path exists and you have write "
+                        + "permissions.";
+                throw new BuildException(msg);
+            } catch (ArrayIndexOutOfBoundsException aioobe) {
+                String msg = "You must specify a log file when "
+                        + "using the -log argument";
+                throw new BuildException(msg);
+            }
         }
-        return pos;
-    }
-
-    /** Handle -listener argument */
-    private int handleArgListener(String[] args, int pos) {
-        try {
-            easyAntConfiguration.getListeners().addElement(args[pos + 1]);
-            pos++;
-        } catch (ArrayIndexOutOfBoundsException aioobe) {
-            String msg = "You must specify a classname when "
-                    + "using the -listener argument";
-            throw new BuildException(msg);
-        }
-        return pos;
-    }
-
-    /** Handler -D argument */
-    private int handleArgDefine(String[] args, int argPos) {
-        /*
-         * Interestingly enough, we get to here when a user uses -Dname=value.
-         * However, in some cases, the OS goes ahead and parses this out to args
-         * {"-Dname", "value"} so instead of parsing on "=", we just make the
-         * "-D" characters go away and skip one argument forward.
-         * 
-         * I don't know how to predict when the JDK is going to help or not, so
-         * we simply look for the equals sign.
-         */
-        String arg = args[argPos];
-        String name = arg.substring(2, arg.length());
-        String value = null;
-        int posEq = name.indexOf("=");
-        if (posEq > 0) {
-            value = name.substring(posEq + 1);
-            name = name.substring(0, posEq);
-        } else if (argPos < args.length - 1) {
-            value = args[++argPos];
-        } else {
-            throw new BuildException("Missing value for property " + name);
+        if (line.hasOption("buildmodule")) {
+            File buildModule = new File(line.getOptionValue("buildmodule")
+                    .replace('/', File.separatorChar));
+            easyAntConfiguration.setBuildModule(buildModule);
+        }
+        if (line.hasOption("buildfile")) {
+            File buildFile = new File(line.getOptionValue("buildfile").replace(
+                    '/', File.separatorChar));
+            easyAntConfiguration.setBuildFile(buildFile);
+        }
+        if (line.hasOption("buildconf")) {
+            easyAntConfiguration.getActiveBuildConfigurations().add(
+                    line.getOptionValue("buildconf"));
         }
-        easyAntConfiguration.getDefinedProps().put(name, value);
-        return argPos;
-    }
-
-    /** Handle the -logger argument. */
-    private int handleArgLogger(String[] args, int pos) {
-        if (easyAntConfiguration.getLoggerClassname() != null) {
-            throw new BuildException("Only one logger class may be specified.");
+        if (line.hasOption("configfile")) {
+            try {
+                File easyantConfFile = new File(line.getOptionValue(
+                        "configfile").replace('/', File.separatorChar));
+                easyAntConfiguration = EasyantConfigurationFactory
+                        .getInstance().createConfigurationFromFile(
+                                easyAntConfiguration, easyantConfFile.toURL());
+            } catch (Exception e) {
+                throw new BuildException(e);
+            }
+        }
+        if (line.hasOption("listener")) {
+            easyAntConfiguration.getListeners().addElement(
+                    line.getOptionValue("listener"));
+        }
+        if (line.hasOption("D")) {
+            easyAntConfiguration.getDefinedProps().putAll(
+                    line.getOptionProperties("D"));
         }
-        try {
-            easyAntConfiguration.setLoggerClassname(args[++pos]);
-        } catch (ArrayIndexOutOfBoundsException aioobe) {
-            throw new BuildException(
-                    "You must specify a classname when using the -logger argument");
-        }
-        return pos;
-    }
+        if (line.hasOption("logger")) {
+            if (easyAntConfiguration.getLoggerClassname() != null) {
+                throw new BuildException(
+                        "Only one logger class may be specified.");
+            }
+            easyAntConfiguration.setLoggerClassname(line
+                    .getOptionValue("logger"));
+        }
+        if (line.hasOption("inputhandler")) {
+            if (easyAntConfiguration.getInputHandlerClassname() != null) {
+                throw new BuildException("Only one input handler class may "
+                        + "be specified.");
+            }
+            easyAntConfiguration.setInputHandlerClassname(line
+                    .getOptionValue("inputhandler"));
+        }
+        if (line.hasOption("emacs")) {
+            easyAntConfiguration.setEmacsMode(true);
+        }
+        if (line.hasOption("projecthelp")) {
+            // set the flag to display the targets and quit
+            projectHelp = true;
+        }
+        if (line.hasOption("find")) {
+            // eat up next arg if present, default to module.ivy
+            if (line.getOptionValues("find").length > 0) {
+                searchForThis = line.getOptionValue("find");
 
-    /** Handle the -inputhandler argument. */
-    private int handleArgInputHandler(String[] args, int pos) {
-        if (easyAntConfiguration.getInputHandlerClassname() != null) {
-            throw new BuildException("Only one input handler class may "
-                    + "be specified.");
+            } else {
+                searchForThis = EasyAntConstants.DEFAULT_BUILD_MODULE;
+            }
+            easyAntConfiguration.setBuildModule(new File(searchForThis));
+            easyAntConfiguration.setBuildModuleLookupEnabled(true);
         }
-        try {
-            easyAntConfiguration.setInputHandlerClassname(args[++pos]);
-        } catch (ArrayIndexOutOfBoundsException aioobe) {
-            throw new BuildException("You must specify a classname when"
-                    + " using the -inputhandler" + " argument");
+        if (line.hasOption("propertyfile")) {
+            propertyFiles.addElement(line.getOptionValue("propertyfile"));
         }
-        return pos;
-    }
-
-    /** Handle the -propertyfile argument. */
-    private int handleArgPropertyFile(String[] args, int pos) {
-        try {
-            propertyFiles.addElement(args[++pos]);
-        } catch (ArrayIndexOutOfBoundsException aioobe) {
-            String msg = "You must specify a property filename when "
-                    + "using the -propertyfile argument";
-            throw new BuildException(msg);
+        if (line.hasOption("keep-going")) {
+            easyAntConfiguration.setKeepGoingMode(true);
         }
-        return pos;
-    }
+        if (line.hasOption("offline")) {
+            easyAntConfiguration.setOffline(true);
+        }
+        if (line.hasOption("nice")) {
+            easyAntConfiguration.setThreadPriority(Integer.decode(line
+                    .getOptionValue("nice")));
 
-    /** Handle the -nice argument. */
-    private int handleArgNice(String[] args, int pos) {
-        try {
-            easyAntConfiguration.setThreadPriority(Integer.decode(args[++pos]));
-        } catch (ArrayIndexOutOfBoundsException aioobe) {
-            throw new BuildException("You must supply a niceness value (1-10)"
-                    + " after the -nice option");
-        } catch (NumberFormatException e) {
-            throw new BuildException("Unrecognized niceness value: "
-                    + args[pos]);
+            if (easyAntConfiguration.getThreadPriority().intValue() < Thread.MIN_PRIORITY
+                    || easyAntConfiguration.getThreadPriority().intValue() > Thread.MAX_PRIORITY) {
+                throw new BuildException(
+                        "Niceness value is out of the range 1-10");
+            }
         }
+        if (line.hasOption("autoproxy")) {
+            easyAntConfiguration.setProxy(true);
+        }
+        if (line.getArgList().size() > 0) {
+            for (Iterator iterator = line.getArgList().iterator(); iterator
+                    .hasNext();) {
+                String target = (String) iterator.next();
+                easyAntConfiguration.getTargets().addElement(target);
+            }
+        }
+
+        // Load the property files specified by -propertyfile
+        loadPropertyFiles();
 
-        if (easyAntConfiguration.getThreadPriority().intValue() < Thread.MIN_PRIORITY
-                || easyAntConfiguration.getThreadPriority().intValue() > Thread.MAX_PRIORITY) {
-            throw new BuildException("Niceness value is out of the range 1-10");
+        if (logTo != null) {
+            easyAntConfiguration.setOut(logTo);
+            easyAntConfiguration.setErr(logTo);
+            System.setOut(easyAntConfiguration.getOut());
+            System.setErr(easyAntConfiguration.getErr());
         }
-        return pos;
+        readyToRun = true;
     }
 
     // --------------------------------------------------------
@@ -591,27 +453,31 @@ public class EasyAntMain implements AntM
      * @exception BuildException
      *                if the build fails
      */
-    private void runBuild(ClassLoader coreLoader) throws BuildException {
-        Project project = new Project();
+    private void runBuild(CommandLine line, ClassLoader coreLoader)
+            throws BuildException {
+
         if (!readyToRun) {
             return;
         }
         if (projectHelp) {
             displayProjectHelp();
-        } else if(projectMan) {
-            EasyAntEngine.configureAndInitProject(project, easyAntConfiguration);
-            File moduleDescriptor =new File(project.getProperty(EasyAntMagicNames.EASYANT_FILE));
-            File optionalAntModule =new File(moduleDescriptor.getParent(),EasyAntConstants.DEFAULT_BUILD_FILE);
-            File overrideAntModule =new File(moduleDescriptor.getParent(),EasyAntConstants.DEFAULT_OVERRIDE_BUILD_FILE);
-            
-            if (moduleDescriptor.exists()||optionalAntModule.exists()||overrideAntModule.exists()) {
-                man.setContext(project, moduleDescriptor,optionalAntModule,overrideAntModule);
-                man.execute();
-            } else {
-                project.log("Can't print project manual, there is no module descriptor available.");
-            }
         } else {
-            EasyAntEngine.runBuild(easyAntConfiguration);
+            EasyAntEngine eaEngine = new EasyAntEngine(easyAntConfiguration);
+            Project project = new Project();
+            eaEngine.configureProject(project);
+            eaEngine.initProject(project);
+            // handle other easyant option (-listTargets,-describe,etc..)
+            for (int i = 0; i < line.getOptions().length; i++) {
+                if (line.getOptions()[i] instanceof EasyantOption) {
+                    EasyantOption eaoption = (EasyantOption) line.getOptions()[i];
+                    eaoption.setProject(project);
+                    eaoption.execute();
+                    if (eaoption.isStopBuild()) {
+                        return;
+                    }
+                }
+            }
+            eaEngine.doBuild();
         }
 
     }
@@ -722,8 +588,8 @@ public class EasyAntMain implements AntM
             msg.append(" ");
             msg.append(names.elementAt(i));
             if (descriptions != null) {
-                msg.append(spaces.substring(0, maxlen
-                        - ((String) names.elementAt(i)).length() + 2));
+                msg.append(spaces.substring(0,
+                        maxlen - ((String) names.elementAt(i)).length() + 2));
                 msg.append(descriptions.elementAt(i));
             }
             msg.append(lSep);
@@ -811,147 +677,139 @@ public class EasyAntMain implements AntM
 
         try {
 
-            PrintStream savedErr = System.err;
-            PrintStream savedOut = System.out;
-            InputStream savedIn = System.in;
-
-            // use a system manager that prevents from System.exit()
-            SecurityManager oldsm = null;
-            oldsm = System.getSecurityManager();
-
-            // SecurityManager can not be installed here for backwards
-            // compatibility reasons (PD). Needs to be loaded prior to
-            // ant class if we are going to implement it.
-            // System.setSecurityManager(new NoExitSecurityManager());
-            try {
-                if (easyAntConfiguration.isAllowInput()) {
-                    project.setDefaultInputStream(System.in);
-                }
-                System.setIn(new DemuxInputStream(project));
-                System.setOut(new PrintStream(new DemuxOutputStream(project,
-                        false)));
-                System.setErr(new PrintStream(new DemuxOutputStream(project,
-                        true)));
-                EasyAntEngine.configureAndInitProject(project, easyAntConfiguration);
-                printDescription(project);
-                printTargets(project,
-                        easyAntConfiguration.getMsgOutputLevel() > Project.MSG_INFO);
-            } finally {
-                // put back the original security manager
-                // The following will never eval to true. (PD)
-                if (oldsm != null) {
-                    System.setSecurityManager(oldsm);
-                }
+            EasyAntEngine
+                    .configureAndInitProject(project, easyAntConfiguration);
+            printDescription(project);
+            printTargets(project,
+                    easyAntConfiguration.getMsgOutputLevel() > Project.MSG_INFO);
 
-                System.setOut(savedOut);
-                System.setErr(savedErr);
-                System.setIn(savedIn);
-            }
         } catch (RuntimeException exc) {
             error = exc;
             throw exc;
-        } catch (Error e) {
-            error = e;
-            throw e;
         } finally {
             if (error != null) {
                 project.log(error.toString(), Project.MSG_ERR);
             }
         }
     }
-    
+
+    /**
+     * Configure command line options
+     */
+    public void configureOptions() {
+        options.addOption("h", "help", false, "print this message");
+
+        options.addOption("p", "projecthelp", false,
+                "print project help information");
+        options.addOption("version", false,
+                "print the version information and exit");
+        options.addOption("diagnostics", false,
+                "print information that might be helpful to diagnose or report problems");
+        options.addOption("showMemoryDetails", false,
+                "print memory details (used/free/total)");
+        options.addOption("q", "quiet", false, "be extra quiet");
+        options.addOption("v", "verbose", false, "be extra verbose");
+        options.addOption("d", "debug", false, "print debugging information");
+        options.addOption("e", "emacs", false,
+                "produce logging information without adornments");
+        Option lib = OptionBuilder
+                .withArgName("path")
+                .hasArg()
+                .withDescription(
+                        "specifies a path to search for jars and classes")
+                .create("lib");
+        options.addOption(lib);
+        Option logfile = OptionBuilder.withArgName("file").hasArg()
+                .withDescription("use given file for log").create("logfile");
+        options.addOption(logfile);
+        Option logger = OptionBuilder.withArgName("classname").hasArg()
+                .withDescription("the class which it to perform " + "logging")
+                .create("logger");
+        options.addOption(logger);
+        Option listener = OptionBuilder
+                .withArgName("classname")
+                .hasArg()
+                .withDescription(
+                        "add an instance of class as " + "a project listener")
+                .create("listener");
+        options.addOption(listener);
+        Option buildfile = OptionBuilder.withArgName("file").hasArg()
+                .withDescription("use given buildfile").create("buildfile");
+        options.addOption(buildfile);
+        Option find = OptionBuilder
+                .withArgName("file")
+                .hasOptionalArg()
+                .withDescription(
+                        "search for buildfile towards the "
+                                + "root of the filesystem and use it")
+                .withLongOpt("find").create("s");
+        options.addOption(find);
+        options.addOption("noinput", false, "do not allow interactive input");
+        Option buildmodule = OptionBuilder.withArgName("file").hasArg()
+                .withDescription("use given buildmodule")
+                .withLongOpt("buildmodule").create("f");
+        options.addOption(buildmodule);
+
+        Option buildconf = OptionBuilder.withArgName("confs").hasArg()
+                .withDescription("specify build configurations (profiles)")
+                .withLongOpt("buildconf").create("C");
+        options.addOption(buildconf);
+        Option configFile = OptionBuilder.withArgName("file").hasArg()
+                .withDescription("use given easyant configuration")
+                .create("configfile");
+        options.addOption(configFile);
+        Option property = OptionBuilder.withArgName("property=value")
+                .hasArgs(2).withValueSeparator()
+                .withDescription("use value for given property").create("D");
+        options.addOption(property);
+        options.addOption("k", "keep-going", false,
+                "execute all targets that do not depend on failed target(s)");
+        Option propertiesfile = OptionBuilder
+                .withArgName("file")
+                .hasArg()
+                .withDescription(
+                        "load all properties from file with -D properties taking precedence")
+                .create("propertyfile");
+        options.addOption(buildfile);
+        Option inputhandler = OptionBuilder.withArgName("classname").hasArg()
+                .withDescription("the class which will handle input requests")
+                .create("inputhandler");
+        options.addOption(listener);
+        Option nice = OptionBuilder
+                .withArgName("number")
+                .hasArg()
+                .withDescription(
+                        "A niceness value for the main thread: 1 (lowest) to 10 (highest); 5 is the default")
+                .create("nice");
+        options.addOption(nice);
+        options.addOption("nouserlib", false,
+                "Run ant without using the jar files from ${user.home}/.ant/lib");
+        options.addOption("noclasspath", false,
+                "Run ant without using CLASSPATH");
+        options.addOption("autoproxy", false,
+                "Java1.5+: use the OS proxy settings");
+        Option main = OptionBuilder.withArgName("classname").hasArg()
+                .withDescription("override EasyAnt's normal entry point")
+                .create("main");
+        options.addOption(main);
+        options.addOption("o", "offline", false,
+                "turns EasyAnt in offline mode");
+        options.addOption(new Describe());
+        options.addOption(new ListPhases());
+        options.addOption(new ListTargets());
+        options.addOption(new ListProps());
+        options.addOption(new ListPlugins());
+    }
+
     /**
      * Prints the usage information for this class to <code>System.out</code>.
      */
-    private static void printUsage() {
-        String lSep = System.getProperty("line.separator");
-        StringBuffer msg = new StringBuffer();
-        msg.append("easyant [options] [target [target2 [target3] ...]]" + lSep);
-        msg.append("Options: " + lSep);
-        msg.append("  -help, -h              print this message" + lSep);
-        msg.append("  -projecthelp, -p       print project help information"
-                + lSep);
-        msg
-                .append("  -version               print the version information and exit"
-                        + lSep);
-        msg
-                .append("  -diagnostics           print information that might be helpful to"
-                        + lSep);
-        msg.append("                         diagnose or report problems."
-                + lSep);
-        msg
-                .append("  -showMemoryDetails     print memory details (used/free/total)"
-                        + lSep);
-        msg.append("  -quiet, -q             be extra quiet" + lSep);
-        msg.append("  -verbose, -v           be extra verbose" + lSep);
-        msg.append("  -debug, -d             print debugging information"
-                + lSep);
-        msg
-                .append("  -emacs, -e             produce logging information without adornments"
-                        + lSep);
-        msg
-                .append("  -lib <path>            specifies a path to search for jars and classes"
-                        + lSep);
-        msg.append("  -logfile <file>        use given file for log" + lSep);
-        msg.append("    -l     <file>                ''" + lSep);
-        msg
-                .append("  -logger <classname>    the class which is to perform logging"
-                        + lSep);
-        msg
-                .append("  -listener <classname>  add an instance of class as a project listener"
-                        + lSep);
-        msg.append("  -noinput               do not allow interactive input"
-                + lSep);
-        msg.append("  -buildmodule <file>    use given buildmodule" + lSep);
-        msg.append("    -file    <file>              ''" + lSep);
-        msg.append("    -f       <file>              ''" + lSep);
-        msg.append("  -listTargets           Lists all targets available"+lSep);
-        msg.append("  -listTargets <arg>     Lists all targets associated with specified phase / plugin as argument"+lSep);
-        msg.append("  -listPhases            Lists all phases available"+lSep);
-        msg.append("  -listPlugins           Lists all plugins / modules imported by specified build module"+lSep);
-        msg.append("  -listProps <plugin>    Lists all properties available in the specified imported module"+lSep);
-        msg.append("  -describe <arg>        Describes the phase / target / property specified by the argument"+lSep);
-        msg.append("  -buildconf <confs>     specify build configurations (profiles)"+lSep);
-        msg.append("    -C  <confs>                  ''"+lSep);
-        msg.append("  -buildfile <file>      use given buildfile" + lSep);
-        msg.append("  -config-file <file>    use given easyant configuration"
-                + lSep);
-        msg.append("  -D<property>=<value>   use value for given property"
-                + lSep);
-        msg
-                .append("  -keep-going, -k        execute all targets that do not depend"
-                        + lSep);
-        msg.append("                         on failed target(s)" + lSep);
-        msg
-                .append("  -propertyfile <name>   load all properties from file with -D"
-                        + lSep);
-        msg.append("                         properties taking precedence"
-                + lSep);
-        msg
-                .append("  -inputhandler <class>  the class which will handle input requests"
-                        + lSep);
-        msg
-                .append("  -find <file>           (s)earch for buildfile towards the root of"
-                        + lSep);
-        msg.append("    -s  <file>           the filesystem and use it" + lSep);
-        msg
-                .append("  -nice  number          A niceness value for the main thread:"
-                        + lSep
-                        + "                         1 (lowest) to 10 (highest); 5 is the default"
-                        + lSep);
-        msg
-                .append("  -nouserlib             Run ant without using the jar files from"
-                        + lSep
-                        + "                         ${user.home}/.ant/lib"
-                        + lSep);
-        msg.append("  -noclasspath           Run ant without using CLASSPATH"
-                + lSep);
-        msg
-                .append("  -autoproxy             Java1.5+: use the OS proxy settings"
-                        + lSep);
-        msg
-                .append("  -main <class>          override Ant's normal entry point");
-        System.out.println(msg.toString());
+    private void printUsage() {
+
+        HelpFormatter help = new HelpFormatter();
+        help.printHelp("easyant [options] [target [target2 [target3] ...]]",
+                options);
+
     }
 
     /**

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/Describe.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/Describe.java?rev=1148895&r1=1148894&r2=1148895&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/Describe.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/Describe.java Wed Jul 20 18:53:32 2011
@@ -18,10 +18,8 @@
 package org.apache.easyant.man;
 
 import org.apache.easyant.core.descriptor.PropertyDescriptor;
-import org.apache.easyant.core.report.EasyAntReport;
 import org.apache.easyant.core.report.PhaseReport;
 import org.apache.easyant.core.report.TargetReport;
-import org.apache.tools.ant.Project;
 
 /**
  * Implements support for -describe easyant switch.
@@ -29,61 +27,81 @@ import org.apache.tools.ant.Project;
  * This command searches for a phase, target, and properties by the 
  * supplied search name and returns result for each of these sequentially. 
  */
-public class Describe implements ManCommand {
-    private String target;
+public class Describe extends EasyantOption {
     
+    public Describe()
+            throws IllegalArgumentException {
+        super("describe", true, "Describes the phase / target / property specified by the argument");
+        setStopBuild(true);
+    }
     // convenient string constants
     private static final String NONE = "NONE";
-    
-    public void addParam(String param) {
-        this.target = param;
-    }
-
-    public void execute(EasyAntReport earep, Project project) {
-        String lineSep = System.getProperty("line.separator");
-        
+    public void execute() {
+        String target = getValue();
         if(target == null || target.length() == 0) {
             throw new IllegalArgumentException("No parameter specified for -describe parameter.");
         }
         
-        project.log(lineSep + "--- Available references for: " + target +
-                " in current project: " + project.getName() + " ---" + lineSep);
+        getProject()
+        .log(LINE_SEP + "--- Available references for: " + target +
+                " in current project: " + getProject()
+        .getName() + " ---" + LINE_SEP);
         
-        PhaseReport phaseRep = earep.getPhaseReport(target, true);
+        PhaseReport phaseRep = getEareport().getPhaseReport(target, true);
         if(phaseRep != null) {
-            project.log("\tPhase: " + target);
-            project.log("\t\tDescription: " + (phaseRep.getDescription() == null ? NONE : phaseRep.getDescription()));
-            project.log("\t\tDepends: " + (phaseRep.getDepends() == null ? NONE : phaseRep.getDepends()));
-            project.log(lineSep + "\t\tFor information on targets attached to this phase, run:");
-            project.log("\t\teasyant -listTargets " + target);
+            getProject()
+        .log("\tPhase: " + target);
+            getProject()
+        .log("\t\tDescription: " + (phaseRep.getDescription() == null ? NONE : phaseRep.getDescription()));
+            getProject()
+        .log("\t\tDepends: " + (phaseRep.getDepends() == null ? NONE : phaseRep.getDepends()));
+            getProject()
+        .log(LINE_SEP+ "\t\tFor information on targets attached to this phase, run:");
+            getProject()
+        .log("\t\teasyant -listTargets " + target);
         } else {
-            project.log("\tNo Phase found for name: " + target);
+            getProject()
+        .log("\tNo Phase found for name: " + target);
         }
-        TargetReport targetRep = earep.getTargetReport(target, true);
+        TargetReport targetRep = getEareport().getTargetReport(target, true);
         if(targetRep != null) {
-            project.log("\tTarget: " + target);
-            project.log("\t\tPhase: " + (targetRep.getPhase() == null ? NONE : targetRep.getPhase()));
-            project.log("\t\tDescription: " + (targetRep.getDescription() == null ? NONE : targetRep.getDescription()));
-            project.log("\t\tDepends: " + (targetRep.getDepends() == null ? NONE : targetRep.getDepends()));
-            project.log("\t\tIF: " + (targetRep.getIfCase() == null ? NONE : targetRep.getIfCase()));
-            project.log("\t\tUNLESS: " + (targetRep.getUnlessCase() == null ? NONE : targetRep.getUnlessCase()));
+            getProject()
+        .log("\tTarget: " + target);
+            getProject()
+        .log("\t\tPhase: " + (targetRep.getPhase() == null ? NONE : targetRep.getPhase()));
+            getProject()
+        .log("\t\tDescription: " + (targetRep.getDescription() == null ? NONE : targetRep.getDescription()));
+            getProject()
+        .log("\t\tDepends: " + (targetRep.getDepends() == null ? NONE : targetRep.getDepends()));
+            getProject()
+        .log("\t\tIF: " + (targetRep.getIfCase() == null ? NONE : targetRep.getIfCase()));
+            getProject()
+        .log("\t\tUNLESS: " + (targetRep.getUnlessCase() == null ? NONE : targetRep.getUnlessCase()));
         } else {
-            project.log("\tNo Target found for name: " + target);
+            getProject()
+        .log("\tNo Target found for name: " + target);
         }
-        PropertyDescriptor prop = earep.getAvailableProperties().get(target);
+        PropertyDescriptor prop = getEareport().getAvailableProperties().get(target);
         if(prop != null) {
-            project.log("\tProperty: " + target);
-            project.log("\t\tDescription: " + (prop.getDescription() == null ? NONE : prop.getDescription()));
+            getProject()
+        .log("\tProperty: " + target);
+            getProject()
+        .log("\t\tDescription: " + (prop.getDescription() == null ? NONE : prop.getDescription()));
             String defaultValue = prop.getDefaultValue() == null ? NONE : prop.getDefaultValue();
-            project.log("\t\tDefault: " + defaultValue);
-            project.log("\t\tRequired: " + prop.isRequired());
+            getProject()
+        .log("\t\tDefault: " + defaultValue);
+            getProject()
+        .log("\t\tRequired: " + prop.isRequired());
             String currentValue = prop.getValue() == null ? defaultValue : prop.getValue();
-            project.log("\t\tCurrent value: " + currentValue);
+            getProject()
+        .log("\t\tCurrent value: " + currentValue);
         } else {
-            project.log("\tNo Property found for name: " + target);
+            getProject()
+        .log("\tNo Property found for name: " + target);
         }
         
-        project.log(lineSep + "--- End Of (Describe) ---");
+        getProject()
+        .log(LINE_SEP + "--- End Of (Describe) ---");
     }
 
 }

Added: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/EasyantOption.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/EasyantOption.java?rev=1148895&view=auto
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/EasyantOption.java (added)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/EasyantOption.java Wed Jul 20 18:53:32 2011
@@ -0,0 +1,109 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.easyant.man;
+
+import java.io.File;
+
+import org.apache.commons.cli.Option;
+import org.apache.easyant.core.EasyAntConstants;
+import org.apache.easyant.core.EasyAntMagicNames;
+import org.apache.easyant.core.report.EasyAntReport;
+import org.apache.easyant.core.services.PluginService;
+import org.apache.tools.ant.Project;
+
+/**
+ * Base class for all classes implementing functionality
+ * for project switches that are accepted on command
+ * line when invoking easyant.
+ * 
+ * For example,
+ * <br>
+ *      easyant -listTargets
+ * 
+ * <p />
+ * The -listTargets and similar switches (like -describe etc.) are
+ * all extending this class.
+ * 
+ * For each manual switch that is intended to be supported by easyant,
+ * a new implementing class for this class must be added that
+ * implements the switch functionality.
+ * 
+ */
+public abstract class EasyantOption extends Option {
+    public static final String LINE_SEP = System.getProperty("line.separator");
+    private Project project;
+    private EasyAntReport eareport;
+    private boolean stopBuild=false;
+    
+    public EasyantOption(String opt, boolean hasArg, String description)
+            throws IllegalArgumentException {
+        super(opt, hasArg, description);
+    }
+    public EasyantOption(String opt, String longOpt, boolean hasArg,
+            String description) throws IllegalArgumentException {
+        super(opt, longOpt, hasArg, description);
+    }
+    public EasyantOption(String opt, String description)
+            throws IllegalArgumentException {
+        super(opt, description);
+    }
+    public void execute() {
+        if (getProject()==null) {
+            throw new IllegalStateException("project can't be null");
+        }
+        project.log(LINE_SEP + "Project Manual");
+        project.log("--------------");
+    }
+    public Project getProject() {
+        return project;
+    }
+    public void setProject(Project project) {
+        this.project = project;
+    }
+    public EasyAntReport getEareport() {
+        if (eareport==null) {
+            try {
+                File moduleDescriptor = new File(
+                        project.getProperty(EasyAntMagicNames.EASYANT_FILE));
+                File optionalAntModule = new File(moduleDescriptor.getParent(),
+                        EasyAntConstants.DEFAULT_BUILD_FILE);
+                File overrideAntModule = new File(moduleDescriptor.getParent(),
+                        EasyAntConstants.DEFAULT_OVERRIDE_BUILD_FILE);
+
+                PluginService pluginService = (PluginService)project.getReference(EasyAntMagicNames.PLUGIN_SERVICE_INSTANCE);
+                setEareport(pluginService.generateEasyAntReport(moduleDescriptor,optionalAntModule,overrideAntModule));
+            } catch (Exception e) {
+                project.log("EasyAntMan could not be initialized. Details: " + e.getMessage(),Project.MSG_ERR);
+            }
+        }
+        return eareport;
+    }
+    public void setEareport(EasyAntReport eareport) {
+        this.eareport = eareport;
+    }
+    public boolean isStopBuild() {
+        return stopBuild;
+    }
+    public void setStopBuild(boolean stopBuild) {
+        this.stopBuild = stopBuild;
+    }
+    
+    
+    
+    
+}

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListPhases.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListPhases.java?rev=1148895&r1=1148894&r2=1148895&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListPhases.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListPhases.java Wed Jul 20 18:53:32 2011
@@ -19,9 +19,7 @@ package org.apache.easyant.man;
 
 import java.util.List;
 
-import org.apache.easyant.core.report.EasyAntReport;
 import org.apache.easyant.core.report.PhaseReport;
-import org.apache.tools.ant.Project;
 
 /**
  * ManCommand implementation to list all phases associated with specified 
@@ -29,23 +27,25 @@ import org.apache.tools.ant.Project;
  * 
  * Supports the -listPhases switch.
  */
-public class ListPhases implements ManCommand {
+public class ListPhases extends EasyantOption{
     
-    public void addParam(String param) {
-        // this command does not make use of params
+    public ListPhases()
+            throws IllegalArgumentException {
+        super("listPhases", false, "List all phases available");
+        setOptionalArg(true);
+        setStopBuild(true);
     }
 
-    public void execute(EasyAntReport earep, Project project) {
-        String lineSep = System.getProperty("line.separator");
-        project.log(lineSep + "--- Available Phases for current project: " + project.getName() + " ---" + lineSep);
+    public void execute() {
+        getProject().log(LINE_SEP+ "--- Available Phases for current project: " + getProject().getName() + " ---" + LINE_SEP);
         
-        List<PhaseReport> phases = earep.getAvailablePhases();
+        List<PhaseReport> phases = getEareport().getAvailablePhases();
         for(int i = 0; i<phases.size(); i++) {
-            project.log("\t" + phases.get(i).getName());
+            getProject().log("\t" + phases.get(i).getName());
         }
         
-        project.log(lineSep + lineSep + "For more information on a Phase, run:" + lineSep + "\t easyant -describe <PHASE>");
-        project.log(lineSep + "--- End Of (Phases Listing) ---");
+        getProject().log(LINE_SEP+ LINE_SEP+ "For more information on a Phase, run:" + LINE_SEP + "\t easyant -describe <PHASE>");
+        getProject().log(LINE_SEP+ "--- End Of (Phases Listing) ---");
     }
 
 }

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListPlugins.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListPlugins.java?rev=1148895&r1=1148894&r2=1148895&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListPlugins.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListPlugins.java Wed Jul 20 18:53:32 2011
@@ -19,32 +19,32 @@ package org.apache.easyant.man;
 
 import java.util.List;
 
-import org.apache.easyant.core.report.EasyAntReport;
 import org.apache.easyant.core.report.ImportedModuleReport;
-import org.apache.tools.ant.Project;
 
 /**
  * Lists all available plugins (imported modules) for the specified 
  * build module.
  */
-public class ListPlugins implements ManCommand {
+public class ListPlugins extends EasyantOption {
 
-    public void addParam(String param) {
-        // DO NOTHING - NOT REQUIRED, SINCE THIS IS A 'LIST-ALL' COMMAND
+    
+    public ListPlugins()
+            throws IllegalArgumentException {
+        super("listPlugins",false,"List all plugins used by the project");
+        setStopBuild(true);
     }
 
-    public void execute(EasyAntReport earep, Project project) {
-        String lineSep = System.getProperty("line.separator");
-        project.log(lineSep + "--- Available Plugins for current project: " + project.getName() + " ---" + lineSep);
+    public void execute() {
+        getProject().log(LINE_SEP + "--- Available Plugins for current project: " + getProject().getName() + " ---" + LINE_SEP);
         
-        List<ImportedModuleReport> moduleReps = earep.getImportedModuleReports();
+        List<ImportedModuleReport> moduleReps = getEareport().getImportedModuleReports();
         for(int i = 0; i<moduleReps.size(); i++) {
-            project.log("\t" + moduleReps.get(i).getModuleMrid() + (moduleReps.get(i).getAs() == null ? 
+            getProject().log("\t" + moduleReps.get(i).getModuleMrid() + (moduleReps.get(i).getAs() == null ? 
                     "" : ": Known as " + moduleReps.get(i).getAs()));
         }
         
-        project.log(lineSep + lineSep + "For more information on a Plugin, run:" + lineSep + "\t easyant -describe <PLUGIN>");
-        project.log(lineSep + "--- End Of (Plugins Listing) ---");
+        getProject().log(LINE_SEP + LINE_SEP + "For more information on a Plugin, run:" + LINE_SEP + "\t easyant -describe <PLUGIN>");
+        getProject().log(LINE_SEP + "--- End Of (Plugins Listing) ---");
     }
 
 }

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListProps.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListProps.java?rev=1148895&r1=1148894&r2=1148895&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListProps.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListProps.java Wed Jul 20 18:53:32 2011
@@ -22,40 +22,38 @@ import java.util.Map;
 import java.util.Map.Entry;
 
 import org.apache.easyant.core.descriptor.PropertyDescriptor;
-import org.apache.easyant.core.report.EasyAntReport;
 import org.apache.easyant.core.report.ImportedModuleReport;
-import org.apache.tools.ant.Project;
 
 /**
  * Lists all properties (deep search - includes all imported modules)
  * available in the specified build module.
  */
-public class ListProps implements ManCommand {
-    private String plugin = null;
+public class ListProps extends EasyantOption {
     
-    public void addParam(String param) {
-        this.plugin = param;
+    public ListProps()
+            throws IllegalArgumentException {
+        super("listProps", false, "List all properties available or specified in a given plugin as argument");
+        setOptionalArg(true);
+        setStopBuild(true);
     }
 
-    public void execute(EasyAntReport earep, Project project) {
-        String lineSep = System.getProperty("line.separator");
-
+    public void execute() {
         /*
          * the plugin specified to this class through the addParam method
          * needs to be searched for all properties, and those
          * properties will be displayed by this class.
          */
-        
+        String plugin = getValue();
         if(plugin == null || plugin.trim().length() == 0) {
             throw new IllegalArgumentException("No plugin found to list properties for.");
         }
 
-        project.log(lineSep + "--- Available Properties for current project: " + project.getName() + 
-                ":: Plugin: " + plugin + " ---" + lineSep);
+        getProject().log(LINE_SEP+ "--- Available Properties for current project: " + getProject().getName() + 
+                ":: Plugin: " + plugin + " ---" + LINE_SEP);
 
-        ImportedModuleReport moduleRep = earep.getImportedModuleReport(plugin);
+        ImportedModuleReport moduleRep = getEareport().getImportedModuleReport(plugin);
         if(moduleRep == null) {
-            project.log("\tNo Module / Plugin found by given name: " + plugin);
+            getProject().log("\tNo Module / Plugin found by given name: " + plugin);
         } else {
             Map<String, PropertyDescriptor> allprops = moduleRep.getEasyantReport().getPropertyDescriptors();
             
@@ -63,16 +61,16 @@ public class ListProps implements ManCom
                 for(Iterator<Entry<String, PropertyDescriptor>> it = allprops.entrySet().iterator(); it.hasNext(); ) {
                     Entry<String, PropertyDescriptor> entry = it.next();
                     PropertyDescriptor prop = entry.getValue();
-                    project.log("\tProperty: " + prop.getName());
+                    getProject().log("\tProperty: " + prop.getName());
                 }
         
-                project.log(lineSep + lineSep + "For more information on a Property, run:" + lineSep 
+                getProject().log(LINE_SEP+LINE_SEP+ "For more information on a Property, run:" + LINE_SEP 
                         + "\t easyant -describe <PROPERTY>");
             } else {
-                project.log(lineSep + "No property found in the plugin: " + plugin);
+                getProject().log(LINE_SEP + "No property found in the plugin: " + plugin);
             }
         }
-        project.log(lineSep + "--- End Of (Properties Listing) ---");
+        getProject().log(LINE_SEP + "--- End Of (Properties Listing) ---");
     }
 
 }

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListTargets.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListTargets.java?rev=1148895&r1=1148894&r2=1148895&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListTargets.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/man/ListTargets.java Wed Jul 20 18:53:32 2011
@@ -19,7 +19,6 @@ package org.apache.easyant.man;
 
 import java.util.List;
 
-import org.apache.easyant.core.report.EasyAntReport;
 import org.apache.easyant.core.report.ImportedModuleReport;
 import org.apache.easyant.core.report.PhaseReport;
 import org.apache.easyant.core.report.TargetReport;
@@ -34,22 +33,21 @@ import org.apache.tools.ant.Project;
  * If no phase / plugin name is specified, then this command
  * lists all targets available in the project (module.ivy)
  */
-public class ListTargets implements ManCommand {
-    /*
-     * name of the phase or plugin for which the targets 
-     * have been requested for.
-     */
-    private String container = null;
+public class ListTargets extends EasyantOption {
+    
     
+    public ListTargets() {
+        super("listTargets", false, "List all targets available or associated with a given phase or plugin as argument");
+        setOptionalArg(true);
+        setStopBuild(true);
+    }
+
+
     /*
      * defining some convenient string constants
      */
     private static final String NONE = "NONE";
     
-    public void addParam(String param) {
-        this.container = param;
-    }
-
     /*
      * simply look up for all targets belonging to a phase named <container>, is such
      * a phase exists. then list all targets listed in a module named <container>, is
@@ -58,28 +56,27 @@ public class ListTargets implements ManC
      * however, if the this.container variable has not been initialized then simply list
      * down all targets in the current module and all imported sub-modules.
      */
-    public void execute(EasyAntReport earep, Project project) {
-        String lineSep = System.getProperty("line.separator");
-        
-        project.log(lineSep + "--- Available Targets for current project: " + project.getName() + " ---" + lineSep);
+    public void execute() {
         
-        if(this.container == null || this.container.trim().length() == 0) {
-            project.log(lineSep + "No Phase / Plugin specified. Listing all targets available in the project.");
+        getProject().log(LINE_SEP + "--- Available Targets for current project: " + getProject().getName() + " ---" + LINE_SEP);
+        String container = getValue();
+        if(container == null || container.trim().length() == 0) {
+            getProject().log(LINE_SEP+ "No Phase / Plugin specified. Listing all targets available in the project.");
             
-            List<TargetReport> targets = earep.getAvailableTargets();
-            printTargets(targets, project);
+            List<TargetReport> targets = getEareport().getAvailableTargets();
+            printTargets(targets, getProject());
         } else {
-            PhaseReport phase = earep.getPhaseReport(this.container, true);
+            PhaseReport phase = getEareport().getPhaseReport(container, true);
             
             if(phase != null) {
-                project.log("Targets for Phase: " + this.container);
+                getProject().log("Targets for Phase: " + container);
                 List<TargetReport> targets = phase.getTargetReports();
-                printTargets(targets, project);
+                printTargets(targets, getProject());
             } else {
-                project.log("\tNo Phase found by name: " + this.container);
+                getProject().log("\tNo Phase found by name: " + container);
             }
             
-            List<ImportedModuleReport> modules = earep.getImportedModuleReports();
+            List<ImportedModuleReport> modules = getEareport().getImportedModuleReports();
             ImportedModuleReport selected = null;
             for(int i = 0; i<modules.size(); i++) {
                 selected = modules.get(i);
@@ -88,16 +85,16 @@ public class ListTargets implements ManC
                 }
             }
             if(selected != null) {
-                project.log(lineSep + "Targets for Module: " + this.container);
+                getProject().log(LINE_SEP + "Targets for Module: " + container);
                 List<TargetReport> targets = selected.getEasyantReport().getTargetReports();
-                printTargets(targets, project);
+                printTargets(targets, getProject());
             } else {
-                project.log(lineSep + "\tNo Module / Plugin found by name: " + this.container);
+                getProject().log(LINE_SEP + "\tNo Module / Plugin found by name: " + container);
             }
                 
-            project.log(lineSep + lineSep + "For more information on a Phase, run:" + lineSep + "\t easyant -describe <PHASE>");
+            getProject().log(LINE_SEP+LINE_SEP+ "For more information on a Phase, run:" + LINE_SEP + "\t easyant -describe <PHASE>");
         }
-        project.log(lineSep + "--- End Of (Phases Listing) ---");
+        getProject().log(LINE_SEP + "--- End Of (Phases Listing) ---");
     }
 
     /*



Mime
View raw message