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/interfaces/oldmodel ProjectHelper.java Project.java
Date Tue, 11 Jun 2002 03:07:27 GMT
donaldp     2002/06/10 20:07:27

  Modified:    antlib/src/java/org/apache/antlib/project
                        AbstractWorkspaceTask.java AntCallTask.java
               container/src/test/org/apache/myrmidon/components/embeddor/test
                        DefaultEmbeddorTest.java
               container/src/java/org/apache/myrmidon/components/builder
                        DefaultProject.java
               container/src/java/org/apache/myrmidon/components/workspace
                        DefaultWorkspace.java
               container/src/java/org/apache/myrmidon/interfaces
                        EmbeddedAnt.java
               framework/src/java/org/apache/myrmidon/framework
                        ExecuteTarget.java
               container/src/java/org/apache/myrmidon/interfaces/model
                        Module.java
               container/src/java/org/apache/myrmidon/interfaces/oldmodel
                        Project.java
  Added:       container/src/java/org/apache/myrmidon/interfaces/oldmodel
                        ProjectHelper.java
  Log:
  Move execution method out of the Project and into a utility class.
  
  Note: This is a temporary ugly hack till the new structure gets put in place
  
  Revision  Changes    Path
  1.8       +10 -10    jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/AbstractWorkspaceTask.java
  
  Index: AbstractWorkspaceTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/AbstractWorkspaceTask.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AbstractWorkspaceTask.java	9 Jun 2002 04:53:34 -0000	1.7
  +++ AbstractWorkspaceTask.java	11 Jun 2002 03:07:26 -0000	1.8
  @@ -43,7 +43,7 @@
           getContext().debug( message );
   
           // Locate the referenced target
  -        final ProjectDescriptor project = getProject( dependency );
  +        final ProjectDescriptor project = getProjectDescriptor( dependency.getProjectName()
);
           final String targetName = dependency.getTargetName();
   
           executeTarget( project, targetName );
  @@ -66,17 +66,18 @@
       }
   
       /**
  -     * Get the project referenced in a dependency.
  +     * Get project descriptor for projecName.
  +     * If projecName is null then return descriptor for current project else
  +     * return descriptor for project referenced by current project.
        *
  -     * @param dependency the dependency
  -     * @return
  -     * @throws TaskException
  +     * @param projectName the project to get descriptor for
  +     * @return the descriptor
  +     * @throws TaskException if unable to locate descriptor
        */
  -    protected final ProjectDescriptor getProject( final Dependency dependency )
  +    protected ProjectDescriptor getProjectDescriptor( final String projectName )
           throws TaskException
       {
           final Project project = (Project)getContext().getService( Project.class );
  -        final String projectName = dependency.getProjectName();
           if( null == projectName )
           {
               return project.getProjectDescriptor();
  @@ -88,8 +89,7 @@
               {
                   final String message =
                       REZ.getString( "workspace.missing-ref.error",
  -                                   projectName,
  -                                   dependency );
  +                                   projectName );
                   throw new TaskException( message );
               }
               else
  
  
  
  1.6       +40 -13    jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/AntCallTask.java
  
  Index: AntCallTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/AntCallTask.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AntCallTask.java	9 Jun 2002 04:53:34 -0000	1.5
  +++ AntCallTask.java	11 Jun 2002 03:07:26 -0000	1.6
  @@ -7,11 +7,13 @@
    */
   package org.apache.antlib.project;
   
  +import org.apache.avalon.excalibur.i18n.ResourceManager;
  +import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.framework.ExecuteTarget;
   import org.apache.myrmidon.interfaces.oldmodel.Project;
  -import org.apache.myrmidon.interfaces.workspace.ProjectRef;
   import org.apache.myrmidon.interfaces.workspace.ProjectDescriptor;
  +import org.apache.myrmidon.interfaces.workspace.ProjectRef;
   
   /**
    * A task which executes a target in the current project,
  @@ -24,6 +26,9 @@
   public class AntCallTask
       extends AbstractAntTask
   {
  +    private final static Resources REZ =
  +        ResourceManager.getPackageResources( AntCallTask.class );
  +
       private String m_projectName;
   
       /**
  @@ -42,19 +47,41 @@
        */
       protected void prepare( final ExecuteTarget exe ) throws TaskException
       {
  -        final Project currentProject =
  -            (Project)getContext().getService( Project.class );
  -
  -        // By default, use the current project.
  -        ProjectDescriptor project = currentProject.getProjectDescriptor();
  +        final ProjectDescriptor project = getProjectDescriptor( m_projectName );
  +        exe.setProject( project );
  +    }
   
  -        if( null != m_projectName )
  +    /**
  +     * Get project descriptor for projecName.
  +     * If projecName is null then return descriptor for current project else
  +     * return descriptor for project referenced by current project.
  +     *
  +     * @param projectName the project to get descriptor for
  +     * @return the descriptor
  +     * @throws TaskException if unable to locate descriptor
  +     */
  +    protected ProjectDescriptor getProjectDescriptor( final String projectName )
  +        throws TaskException
  +    {
  +        final Project project = (Project)getContext().getService( Project.class );
  +        if( null == projectName )
           {
  -            final ProjectRef projectRef =
  -                currentProject.getProjectRef( m_projectName );
  -            project = projectRef.getProject();
  +            return project.getProjectDescriptor();
  +        }
  +        else
  +        {
  +            final ProjectRef projectRef = project.getProjectRef( projectName );
  +            if( null == projectRef )
  +            {
  +                final String message =
  +                    REZ.getString( "workspace.missing-ref.error",
  +                                   projectName );
  +                throw new TaskException( message );
  +            }
  +            else
  +            {
  +                return projectRef.getProject();
  +            }
           }
  -
  -        exe.setProject( project );
       }
   }
  
  
  
  1.25      +5 -3      jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/embeddor/test/DefaultEmbeddorTest.java
  
  Index: DefaultEmbeddorTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/embeddor/test/DefaultEmbeddorTest.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- DefaultEmbeddorTest.java	9 Jun 2002 03:58:35 -0000	1.24
  +++ DefaultEmbeddorTest.java	11 Jun 2002 03:07:26 -0000	1.25
  @@ -20,6 +20,7 @@
   import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
   import org.apache.myrmidon.interfaces.model.TargetMetaData;
   import org.apache.myrmidon.interfaces.oldmodel.Project;
  +import org.apache.myrmidon.interfaces.oldmodel.ProjectHelper;
   import org.apache.myrmidon.interfaces.workspace.ProjectDescriptor;
   
   /**
  @@ -137,8 +138,9 @@
           listener.addExpectedMessage( "main-target", "A log message" );
   
           // Execute the default target
  -        final TargetMetaData target = project.getDefaultTarget();
  -        project.execute( frame, target );
  +        final String defaultTargetName = project.getDefaultTargetName();
  +        final TargetMetaData target = project.getTarget( defaultTargetName );
  +        ProjectHelper.execute( frame, getLogger(), project, target );
   
           // Cleanup
           listener.assertComplete();
  
  
  
  1.28      +11 -34    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/builder/DefaultProject.java
  
  Index: DefaultProject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/builder/DefaultProject.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- DefaultProject.java	11 Jun 2002 02:27:50 -0000	1.27
  +++ DefaultProject.java	11 Jun 2002 03:07:26 -0000	1.28
  @@ -13,16 +13,12 @@
   import java.util.Map;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.api.metadata.ModelElement;
  -import org.apache.myrmidon.components.workspace.DefaultWorkspace;
  -import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
   import org.apache.myrmidon.interfaces.model.TargetMetaData;
   import org.apache.myrmidon.interfaces.oldmodel.Project;
   import org.apache.myrmidon.interfaces.workspace.ProjectDescriptor;
   import org.apache.myrmidon.interfaces.workspace.ProjectRef;
  -import org.apache.myrmidon.interfaces.workspace.Workspace;
   
   /**
    * Default project implementation.
  @@ -31,7 +27,6 @@
    * @version $Revision$ $Date$
    */
   public class DefaultProject
  -    extends AbstractLogEnabled
       implements Project
   {
       private static final Resources REZ =
  @@ -78,12 +73,18 @@
                              final ProjectRef[] projectRefs,
                              final ModelElement[] targets )
       {
  +        if( null == defaultTarget )
  +        {
  +            throw new NullPointerException( "defaultTarget" );
  +        }
  +
           m_name = name;
           m_descriptor = descriptor;
           m_baseDirectory = baseDirectory;
           m_defaultTarget = defaultTarget;
           m_projectRefs = projectRefs;
           m_targets = targets;
  +
           for( int i = 0; i < m_targets.length; i++ )
           {
               addTargetMetaData( m_targets[ i ] );
  @@ -104,7 +105,6 @@
       }
   
       public ProjectRef getProjectRef( String name )
  -        throws TaskException
       {
           for( int i = 0; i < m_projectRefs.length; i++ )
           {
  @@ -115,10 +115,7 @@
               }
           }
   
  -        final String message =
  -            REZ.getString( "project.missing-ref.error",
  -                           name );
  -        throw new TaskException( message );
  +        return null;
       }
   
       /**
  @@ -132,14 +129,13 @@
       }
   
       /**
  -     * Return the default target for this project.
  +     * Return the default target name for this project.
        *
        * @return the default target name
  -     * @throws TaskException if the project has no default target.
        */
  -    public TargetMetaData getDefaultTarget() throws TaskException
  +    public String getDefaultTargetName()
       {
  -        return getTarget( m_defaultTarget );
  +        return m_defaultTarget;
       }
   
       /**
  @@ -206,24 +202,5 @@
                                              targetMetaDatas );
           }
           return m_metaData;
  -    }
  -
  -    public void execute( final ExecutionFrame frame,
  -                         final TargetMetaData target )
  -        throws TaskException
  -    {
  -        final Workspace workspace = createWorkspace( frame );
  -        workspace.execute( getProjectDescriptor(), target.getName() );
  -    }
  -
  -    /**
  -     * Creates a new workspace to execute this project in.
  -     */
  -    private Workspace createWorkspace( final ExecutionFrame frame )
  -    {
  -        final DefaultWorkspace workspace = new DefaultWorkspace();
  -        setupLogger( workspace );
  -        workspace.setFrame( frame );
  -        return workspace;
       }
   }
  
  
  
  1.78      +3 -2      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java
  
  Index: DefaultWorkspace.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java,v
  retrieving revision 1.77
  retrieving revision 1.78
  diff -u -r1.77 -r1.78
  --- DefaultWorkspace.java	9 Jun 2002 03:58:35 -0000	1.77
  +++ DefaultWorkspace.java	11 Jun 2002 03:07:27 -0000	1.78
  @@ -79,7 +79,8 @@
           TargetMetaData target = project.getTarget( targetName );
           if( null == target )
           {
  -            target = project.getDefaultTarget();
  +            final String defaultTargetName = project.getDefaultTargetName();
  +            target = project.getTarget( defaultTargetName );
           }
           executeTarget( entry, target );
       }
  
  
  
  1.19      +7 -4      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/EmbeddedAnt.java
  
  Index: EmbeddedAnt.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/EmbeddedAnt.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- EmbeddedAnt.java	9 Jun 2002 03:58:35 -0000	1.18
  +++ EmbeddedAnt.java	11 Jun 2002 03:07:27 -0000	1.19
  @@ -26,6 +26,7 @@
   import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
   import org.apache.myrmidon.interfaces.model.TargetMetaData;
   import org.apache.myrmidon.interfaces.oldmodel.Project;
  +import org.apache.myrmidon.interfaces.oldmodel.ProjectHelper;
   import org.apache.myrmidon.interfaces.workspace.ProjectDescriptor;
   
   /**
  @@ -217,15 +218,17 @@
           //if we didn't specify a target, then choose default
           if( targets == null || targets.length == 0 )
           {
  -            final TargetMetaData target = project.getDefaultTarget();
  -            project.execute( frame, target );
  +            final String defaultTargetName = project.getDefaultTargetName();
  +            final TargetMetaData target = project.getTarget( defaultTargetName );
  +            //Next line an utter hack - need to rejif it completely
  +            ProjectHelper.execute( frame, getLogger(), project, target );
           }
           else
           {
               for( int i = 0; i < targets.length; i++ )
               {
                   final TargetMetaData target = project.getTarget( targets[ i ] );
  -                project.execute( frame, target );
  +                ProjectHelper.execute( frame, getLogger(), project, target );
               }
           }
       }
  
  
  
  1.14      +6 -2      jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/ExecuteTarget.java
  
  Index: ExecuteTarget.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/ExecuteTarget.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ExecuteTarget.java	9 Jun 2002 04:53:35 -0000	1.13
  +++ ExecuteTarget.java	11 Jun 2002 03:07:27 -0000	1.14
  @@ -19,7 +19,9 @@
   import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
   import org.apache.myrmidon.interfaces.model.TargetMetaData;
   import org.apache.myrmidon.interfaces.oldmodel.Project;
  +import org.apache.myrmidon.interfaces.oldmodel.ProjectHelper;
   import org.apache.myrmidon.interfaces.workspace.ProjectDescriptor;
  +import org.apache.myrmidon.interfaces.BasicLogger;
   
   /**
    * A utility class that simplifies executing a target in a project.
  @@ -111,7 +113,9 @@
               // TODO - need to be able to inherit services (TypeManager specifically)
               final ExecutionFrame frame =
                   embeddor.createExecutionFrame( properties );
  -            project.execute( frame, target );
  +
  +            //Next line an utter hack - need to rejif it completely
  +            ProjectHelper.execute( frame, new BasicLogger( "", BasicLogger.LEVEL_INFO ),
project, target );
           }
           catch( final Exception e )
           {
  
  
  
  1.4       +1 -16     jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/model/Module.java
  
  Index: Module.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/model/Module.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Module.java	7 Jun 2002 02:46:31 -0000	1.3
  +++ Module.java	11 Jun 2002 03:07:27 -0000	1.4
  @@ -7,9 +7,6 @@
    */
   package org.apache.myrmidon.interfaces.model;
   
  -import org.apache.myrmidon.api.TaskException;
  -import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
  -
   /**
    * A Module represents a executable module that Myrmidon is
    * capable of executing. ie Myrmidon as a Build tool would
  @@ -30,16 +27,4 @@
        * @return the MetaData for Module
        */
       TargetMetaData getMetaData();
  -
  -    /**
  -     * Execute the specified target in module
  -     * using specified {@link ExecutionFrame}.
  -     *
  -     * @param frame the frame in which to execute
  -     * @param target the target to execute
  -     * @throws TaskException if an error occurs executing module
  -     */
  -    void execute( ExecutionFrame frame,
  -                  TargetMetaData target )
  -        throws TaskException;
   }
  
  
  
  1.19      +5 -7      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/oldmodel/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/oldmodel/Project.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Project.java	9 Jun 2002 04:56:27 -0000	1.18
  +++ Project.java	11 Jun 2002 03:07:27 -0000	1.19
  @@ -46,18 +46,16 @@
        * Returns the project reference for specified name.
        *
        * @param name the project name
  -     * @return the project reference for specified name.
  -     * @throws TaskException if the request project is unknown.
  +     * @return the project reference for specified name (May be null).
        */
  -    ProjectRef getProjectRef( String name ) throws TaskException;
  +    ProjectRef getProjectRef( String name );
   
       /**
  -     * Return the default target for this project.
  +     * Return the default target name for this project.
        *
        * @return the default target name
  -     * @throws TaskException if the project has no default target.
        */
  -    TargetMetaData getDefaultTarget() throws TaskException;
  +    String getDefaultTargetName();
   
       /**
        * Retrieve a target by name.
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/oldmodel/ProjectHelper.java
  
  Index: ProjectHelper.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.interfaces.oldmodel;
  
  import org.apache.avalon.framework.container.ContainerUtil;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.myrmidon.components.workspace.DefaultWorkspace;
  import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
  import org.apache.myrmidon.interfaces.workspace.Workspace;
  import org.apache.myrmidon.interfaces.model.TargetMetaData;
  import org.apache.myrmidon.api.TaskException;
  
  /**
   * Hacksville USA. Delete me real fast!!!
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/11 03:07:27 $
   */
  public class ProjectHelper
  {
  
      public static void execute( final ExecutionFrame frame,
                                  final Logger logger,
                                  final Project project,
                                  final TargetMetaData target )
          throws TaskException
      {
          final Workspace workspace = createWorkspace( frame, logger );
          workspace.execute( project.getProjectDescriptor(), target.getName() );
      }
  
      /**
       * Creates a new workspace to execute this project in.
       */
      private static Workspace createWorkspace( final ExecutionFrame frame,
                                                final Logger logger )
      {
          final DefaultWorkspace workspace = new DefaultWorkspace();
          ContainerUtil.enableLogging( workspace, logger );
          workspace.setFrame( frame );
          return workspace;
      }
  }
  
  
  

--
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