ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/frontends CLIMain.java Resources.properties
Date Tue, 28 May 2002 07:05:15 GMT
donaldp     02/05/28 00:05:15

  Modified:    container/src/java/org/apache/myrmidon/frontends
                        CLIMain.java Resources.properties
  Log:
  Start to create a basic SwingGUI for executing build files similar to junits SwingRunner
  
  Revision  Changes    Path
  1.45      +66 -70    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/frontends/CLIMain.java
  
  Index: CLIMain.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/frontends/CLIMain.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- CLIMain.java	21 May 2002 05:17:47 -0000	1.44
  +++ CLIMain.java	28 May 2002 07:05:15 -0000	1.45
  @@ -20,14 +20,13 @@
   import org.apache.avalon.excalibur.cli.CLUtil;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.avalon.framework.CascadingException;
   import org.apache.avalon.framework.ExceptionUtil;
   import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.myrmidon.Constants;
   import org.apache.myrmidon.api.TaskException;
  -import org.apache.myrmidon.interfaces.executor.Executor;
  -import org.apache.myrmidon.interfaces.EmbeddedAnt;
   import org.apache.myrmidon.interfaces.BasicLogger;
  +import org.apache.myrmidon.interfaces.EmbeddedAnt;
  +import org.apache.myrmidon.interfaces.executor.Executor;
   
   /**
    * The class to kick the tires and light the fires.
  @@ -35,13 +34,16 @@
    * to run project.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.44 $ $Date: 2002/05/21 05:17:47 $
  + * @version $Revision: 1.45 $ $Date: 2002/05/28 07:05:15 $
    */
   public class CLIMain
   {
       private static final Resources REZ =
           ResourceManager.getPackageResources( CLIMain.class );
   
  +    private static final String PRINTING_EXECUTOR =
  +        "org.apache.myrmidon.components.executor.PrintingExecutor";
  +
       //defines for the Command Line options
       private static final int HELP_OPT = 'h';
       private static final int QUIET_OPT = 'q';
  @@ -51,6 +53,7 @@
       private static final int DEFINE_OPT = 'D';
       private static final int BUILDER_PARAM_OPT = 'B';
       private static final int NO_PREFIX_OPT = 'p';
  +    private static final int GUI_OPT = 'g';
       private static final int VERSION_OPT = 1;
       private static final int LISTENER_OPT = 2;
       private static final int EXTLIB_DIR_OPT = 6;
  @@ -81,6 +84,12 @@
           LISTENER_OPT, NO_PREFIX_OPT
       };
   
  +    //incompatible options for listener options
  +    private static final int[] RUNSTYLE_OPT_INCOMPAT = new int[]
  +    {
  +        GUI_OPT, INCREMENTAL_OPT
  +    };
  +
       ///List of targets supplied on command line to execute
       private ArrayList m_targets = new ArrayList();
   
  @@ -91,12 +100,17 @@
       private boolean m_incremental;
   
       ///The launcher
  -    private EmbeddedAnt m_embedded = new EmbeddedAnt();
  +    private final EmbeddedAnt m_embedded = new EmbeddedAnt();
   
       ///Log level to use
       private static int m_priority = BasicLogger.LEVEL_WARN;
   
       /**
  +     * Run the GUI.
  +     */
  +    private boolean m_gui;
  +
  +    /**
        * Main entry point called to run standard Myrmidon.
        *
        * @param args the args
  @@ -202,7 +216,8 @@
               new CLOptionDescriptor( "incremental",
                                       CLOptionDescriptor.ARGUMENT_DISALLOWED,
                                       INCREMENTAL_OPT,
  -                                    REZ.getString( "incremental.opt" ) ),
  +                                    REZ.getString( "incremental.opt" ),
  +                                    CLIMain.RUNSTYLE_OPT_INCOMPAT ),
               new CLOptionDescriptor( "ant-home",
                                       CLOptionDescriptor.ARGUMENT_REQUIRED,
                                       HOME_DIR_OPT,
  @@ -223,7 +238,12 @@
               new CLOptionDescriptor( "type",
                                       CLOptionDescriptor.ARGUMENT_REQUIRED,
                                       TYPE_OPT,
  -                                    REZ.getString( "type.opt" ) )
  +                                    REZ.getString( "type.opt" ) ),
  +            new CLOptionDescriptor( "gui",
  +                                    CLOptionDescriptor.ARGUMENT_DISALLOWED,
  +                                    GUI_OPT,
  +                                    REZ.getString( "gui.opt" ),
  +                                    CLIMain.RUNSTYLE_OPT_INCOMPAT )
           };
   
           return options;
  @@ -241,13 +261,13 @@
               throw new Exception( message );
           }
   
  +        final EmbeddedAnt embeddedAnt = m_embedded;
  +
           final List clOptions = parser.getArguments();
           final int size = clOptions.size();
  -
           for( int i = 0; i < size; i++ )
           {
               final CLOption option = (CLOption)clOptions.get( i );
  -
               switch( option.getId() )
               {
                   case HELP_OPT:
  @@ -258,14 +278,14 @@
                       return false;
   
                   case HOME_DIR_OPT:
  -                    m_embedded.setEmbeddorProperty( "myrmidon.home", option.getArgument()
);
  +                    embeddedAnt.setEmbeddorProperty( "myrmidon.home", option.getArgument()
);
                       break;
                   case EXTLIB_DIR_OPT:
  -                    m_embedded.setEmbeddorProperty( "myrmidon.ext.path", option.getArgument()
);
  +                    embeddedAnt.setEmbeddorProperty( "myrmidon.ext.path", option.getArgument()
);
                       break;
   
                   case LOG_LEVEL_OPT:
  -                    m_priority = mapLogLevel( option.getArgument() );
  +                    m_priority = BasicLogger.mapLogLevel( option.getArgument() );
                       break;
                   case VERBOSE_OPT:
                       m_priority = BasicLogger.LEVEL_INFO;
  @@ -282,22 +302,26 @@
                       break;
   
                   case FILE_OPT:
  -                    m_embedded.setProjectFile( option.getArgument() );
  +                    embeddedAnt.setProjectFile( option.getArgument() );
                       break;
   
                   case LISTENER_OPT:
  -                    m_embedded.setProjectListener( option.getArgument() );
  +                    embeddedAnt.setProjectListener( option.getArgument() );
                       break;
                   case NO_PREFIX_OPT:
  -                    m_embedded.setProjectListener( "noprefix" );
  +                    embeddedAnt.setProjectListener( "noprefix" );
                       break;
   
                   case DEFINE_OPT:
  -                    m_embedded.setWorkspaceProperty( option.getArgument( 0 ), option.getArgument(
1 ) );
  +                    embeddedAnt.setWorkspaceProperty( option.getArgument( 0 ), option.getArgument(
1 ) );
                       break;
   
                   case BUILDER_PARAM_OPT:
  -                    m_embedded.setBuilderProperty( option.getArgument( 0 ), option.getArgument(
1 ) );
  +                    embeddedAnt.setBuilderProperty( option.getArgument( 0 ), option.getArgument(
1 ) );
  +                    break;
  +
  +                case GUI_OPT:
  +                    m_gui = true;
                       break;
   
                   case DRY_RUN_OPT:
  @@ -305,7 +329,7 @@
                       break;
   
                   case TYPE_OPT:
  -                    m_embedded.setProjectType( option.getArgument( 0 ) );
  +                    embeddedAnt.setProjectType( option.getArgument( 0 ) );
                       break;
   
                   case 0:
  @@ -317,13 +341,14 @@
           return true;
       }
   
  -    private void execute( final Map properties, final String[] args )
  +    protected void execute( final Map properties, final String[] args )
           throws Exception
       {
  +        final EmbeddedAnt embeddedAnt = m_embedded;
           try
           {
               // Set system properties set up by launcher
  -            m_embedded.setHomeDirectory( (File)properties.get( "myrmidon.home" ) );
  +            embeddedAnt.setHomeDirectory( (File)properties.get( "myrmidon.home" ) );
   
               // Command line
               if( !parseCommandLineOptions( args ) )
  @@ -332,40 +357,43 @@
               }
   
               // Setup logging
  -            final BasicLogger logger =
  -                new BasicLogger( "[myrmidon] ", m_priority );
  -            ContainerUtil.enableLogging( m_embedded, logger );
  +            final BasicLogger logger = new BasicLogger( "[myrmidon] ", m_priority );
  +            ContainerUtil.enableLogging( embeddedAnt, logger );
   
               if( m_dryRun )
               {
  -                m_embedded.setEmbeddorProperty( Executor.ROLE,
  -                                                "org.apache.myrmidon.components.executor.PrintingExecutor"
);
  +                embeddedAnt.setEmbeddorProperty( Executor.ROLE, PRINTING_EXECUTOR );
               }
   
               // Set the common and container classloaders
               final ClassLoader sharedClassLoader = (ClassLoader)properties.get( "myrmidon.shared.classloader"
);
  -            m_embedded.setSharedClassLoader( sharedClassLoader );
  +            embeddedAnt.setSharedClassLoader( sharedClassLoader );
               final ClassLoader containerClassLoader = (ClassLoader)properties.get( "myrmidon.container.classloader"
);
  -            m_embedded.setContainerClassLoader( containerClassLoader );
  +            embeddedAnt.setContainerClassLoader( containerClassLoader );
   
               //loop over build if we are in incremental mode..
  -            if( !m_incremental )
  +            if( m_gui )
               {
  -                executeBuild();
  +                final SwingUI ui = new SwingUI();
  +                ui.setVisible( true );
               }
  -            else
  +            else if( m_incremental )
               {
                   executeIncrementalBuild();
               }
  +            else
  +            {
  +                executeBuild();
  +            }
           }
           catch( final Exception e )
           {
               final String message = REZ.getString( "build-failed.error" );
  -            throw new CascadingException( message, e );
  +            throw new TaskException( message, e );
           }
           finally
           {
  -            m_embedded.stop();
  +            embeddedAnt.stop();
           }
       }
   
  @@ -402,17 +430,19 @@
           }
       }
   
  -    private void executeBuild() throws Exception
  +    private void executeBuild()
  +        throws Exception
       {
           //actually do the build ...
  -        final String[] targets = (String[])m_targets.toArray( new String[ m_targets.size()
] );
  +        final String[] targets =
  +            (String[])m_targets.toArray( new String[ m_targets.size() ] );
           m_embedded.executeTargets( targets );
       }
   
       /**
        * Builds the error message for an exception
        */
  -    private void reportError( final Throwable throwable )
  +    protected void reportError( final Throwable throwable )
       {
           // Build the message
           final String message;
  @@ -439,38 +469,4 @@
           // Write the message out
           System.err.println( message );
       }
  -
  -    /**
  -     * Sets the log level.
  -     */
  -    private int mapLogLevel( final String logLevel )
  -        throws Exception
  -    {
  -        final String logLevelCapitalized = logLevel.toUpperCase();
  -        if( "DEBUG".equals( logLevelCapitalized ) )
  -        {
  -            return BasicLogger.LEVEL_DEBUG;
  -        }
  -        else if( "VERBOSE".equals( logLevelCapitalized ) )
  -        {
  -            return BasicLogger.LEVEL_INFO;
  -        }
  -        else if( "INFO".equals( logLevelCapitalized ) )
  -        {
  -            return BasicLogger.LEVEL_WARN;
  -        }
  -        else if( "WARN".equals( logLevelCapitalized ) )
  -        {
  -            return BasicLogger.LEVEL_ERROR;
  -        }
  -        else if( "ERROR".equals( logLevelCapitalized ) )
  -        {
  -            return BasicLogger.LEVEL_FATAL;
  -        }
  -        else
  -        {
  -            final String message = REZ.getString( "bad-loglevel.error", logLevel );
  -            throw new Exception( message );
  -        }
  -    }
  -}
  +}
  \ No newline at end of file
  
  
  
  1.12      +1 -0      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/frontends/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/frontends/Resources.properties,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Resources.properties	10 May 2002 06:27:32 -0000	1.11
  +++ Resources.properties	28 May 2002 07:05:15 -0000	1.12
  @@ -15,6 +15,7 @@
   define.opt=Define a property (ie -Dfoo=var).
   build.opt=Define a builder parameter (ie -Bfoo=var).
   dry-run.opt=Do not execute tasks - just print them out.
  +gui.opt=Run the GUI frontend.
   type.opt=Specify the project file type.
   
   file-no-exist.error={0} {1} does not exist.
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message