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/workspace Workspace.java
Date Thu, 23 May 2002 04:29:45 GMT
donaldp     02/05/22 21:29:45

  Modified:    antlib/src/java/org/apache/antlib/project TargetTask.java
               container/src/java/org/apache/myrmidon/components/workspace
                        DefaultWorkspace.java
               container/src/java/org/apache/myrmidon/interfaces/workspace
                        Workspace.java
  Log:
  Make TargetTask responsible for executing its own dependencies.
  
  Revision  Changes    Path
  1.6       +49 -2     jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/TargetTask.java
  
  Index: TargetTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/TargetTask.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TargetTask.java	11 May 2002 12:44:00 -0000	1.5
  +++ TargetTask.java	23 May 2002 04:29:45 -0000	1.6
  @@ -14,13 +14,16 @@
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.api.metadata.ModelElement;
   import org.apache.myrmidon.framework.AbstractContainerTask;
  +import org.apache.myrmidon.interfaces.oldmodel.Project;
  +import org.apache.myrmidon.interfaces.oldmodel.ProjectRef;
   import org.apache.myrmidon.interfaces.property.NameValidator;
  +import org.apache.myrmidon.interfaces.workspace.Workspace;
   
   /**
    * A simple task to task to execute a group of tasks.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.5 $ $Date: 2002/05/11 12:44:00 $
  + * @version $Revision: 1.6 $ $Date: 2002/05/23 04:29:45 $
    * @ant.task name="target"
    */
   public class TargetTask
  @@ -153,7 +156,51 @@
                   getContext().debug( message );
               }
   
  -            //executeProjectTarget( dependency );
  +            executeProjectTarget( dependency );
  +        }
  +    }
  +
  +    private void executeProjectTarget( final Dependency dependency )
  +        throws TaskException
  +    {
  +        final String uri = getProjectURI( dependency );
  +
  +        final Workspace workspace =
  +            (Workspace)getContext().getService( Workspace.class );
  +        workspace.executeTarget( uri, dependency.getTargetName() );
  +    }
  +
  +    /**
  +     * Get the URI for project that specified in dependency.
  +     *
  +     * @param dependency the dependency
  +     * @return
  +     * @throws TaskException
  +     */
  +    private String getProjectURI( final Dependency dependency )
  +        throws TaskException
  +    {
  +        final Project project = (Project)getContext().getService( Project.class );
  +        final String projectName = dependency.getProjectName();
  +        if( null == projectName )
  +        {
  +            return project.getURI();
  +        }
  +        else
  +        {
  +            final ProjectRef projectRef = project.getProjectRef( projectName );
  +            if( null != projectRef )
  +            {
  +                return projectRef.getUri();
  +            }
  +            else
  +            {
  +                final String message =
  +                    REZ.getString( "target.missing-dependency.error",
  +                                   m_name,
  +                                   projectName );
  +                throw new TaskException( message );
  +            }
           }
       }
   
  
  
  
  1.68      +56 -58    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.67
  retrieving revision 1.68
  diff -u -r1.67 -r1.68
  --- DefaultWorkspace.java	23 May 2002 04:26:26 -0000	1.67
  +++ DefaultWorkspace.java	23 May 2002 04:29:45 -0000	1.68
  @@ -26,7 +26,6 @@
   import org.apache.myrmidon.interfaces.executor.Executor;
   import org.apache.myrmidon.interfaces.oldmodel.Dependency;
   import org.apache.myrmidon.interfaces.oldmodel.Project;
  -import org.apache.myrmidon.interfaces.oldmodel.ProjectRef;
   import org.apache.myrmidon.interfaces.oldmodel.Target;
   import org.apache.myrmidon.interfaces.service.ScopedService;
   import org.apache.myrmidon.interfaces.type.TypeManager;
  @@ -36,7 +35,7 @@
    * This is the default implementation of Workspace.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.67 $ $Date: 2002/05/23 04:26:26 $
  + * @version $Revision: 1.68 $ $Date: 2002/05/23 04:29:45 $
    * @todo Merge m_entries and m_projects
    */
   public class DefaultWorkspace
  @@ -58,20 +57,59 @@
       private HashMap m_projects = new HashMap();
   
       /**
  +     * The root execution frame.
  +     */
  +    private ExecutionFrame m_frame;
  +
  +    /**
  +     * The embeddor to use to build projects.
  +     */
  +    private Embeddor m_embeddor;
  +
  +    public void setFrame( final ExecutionFrame frame )
  +        throws TaskException
  +    {
  +        m_frame = frame;
  +        try
  +        {
  +            m_embeddor = (Embeddor)frame.getServiceManager().lookup( Embeddor.ROLE );
  +        }
  +        catch( final ServiceException se )
  +        {
  +            throw new TaskException( se.getMessage(), se );
  +        }
  +    }
  +
  +    /**
        * Execute a target in a particular project.
        * Execute in the project context.
        *
        * @param project the Project
        * @param target the name of the target
  -     * @exception TaskException if an error occurs
  +     * @throws TaskException if an error occurs
        */
       public void executeProject( final Project project,
  -                                final ExecutionFrame frame,
                                   final String target )
           throws TaskException
       {
  -        final ProjectEntry entry = getProjectEntry( project, frame );
  -        executeTarget( frame, entry, target );
  +        final ProjectEntry entry = getProjectEntry( project, m_frame );
  +        m_projects.put( project.getURI(), project );
  +        executeTarget( entry, target );
  +    }
  +
  +    /**
  +     * Executes a target in context of workspace.
  +     * The project is specified by URI.
  +     *
  +     * @param uri the URI of the Project
  +     * @param targetName the name of the target to execute
  +     * @throws TaskException if an error occurs
  +     */
  +    public void executeTarget( String uri, String targetName )
  +        throws TaskException
  +    {
  +        final Project project = getProject( uri );
  +        executeProject( project, targetName );
       }
   
       /**
  @@ -185,25 +223,15 @@
           return entry;
       }
   
  -    private Project getProject( final ExecutionFrame frame,
  -                                final String name,
  -                                final Project project )
  +    private Project getProject( final String uri )
           throws TaskException
       {
  -        final ProjectRef projectRef = project.getProjectRef( name );
  -
  -        if( null == projectRef )
  -        {
  -            final String message =
  -                REZ.getString( "no-project.error", name );
  -            throw new TaskException( message );
  -        }
  -
  -        final String uri = projectRef.getUri();
  +        System.out.println( "DefaultWorkspace.getProject(" + uri + ")" );
           Project other = (Project)m_projects.get( uri );
  +        System.out.println( "other = " + other );
           if( null == other )
           {
  -            other = createProject( frame, name, uri );
  +            other = createProject( uri );
               m_projects.put( uri, other );
           }
   
  @@ -214,29 +242,22 @@
        * Create project referred to by specified name and located
        * at specified URI.
        *
  -     * @param frame the frme in which to create project
  -     * @param name the name of the project reference
        * @param uri the URI of project
        * @return the created project
        * @throws TaskException if there is an error creating project
        */
  -    private Project createProject( final ExecutionFrame frame,
  -                                   final String name,
  -                                   final String uri )
  +    private Project createProject( final String uri )
           throws TaskException
       {
           Project other;
           try
           {
  -            final Embeddor embeddor =
  -                (Embeddor)frame.getServiceManager().lookup( Embeddor.ROLE );
  -            other = embeddor.createProject( uri, null, null );
  +            other = m_embeddor.createProject( uri, null, null );
           }
           catch( final Exception e )
           {
               final String message =
                   REZ.getString( "workspace.nobuild-project.error",
  -                               name,
                                  uri,
                                  e );
               throw new TaskException( message, e );
  @@ -249,10 +270,9 @@
        *
        * @param entry the project to execute
        * @param targetName the name of the target to execute
  -     * @exception TaskException if an error occurs
  +     * @throws TaskException if an error occurs
        */
  -    private void executeTarget( final ExecutionFrame frame,
  -                                final ProjectEntry entry,
  +    private void executeTarget( final ProjectEntry entry,
                                   final String targetName )
           throws TaskException
       {
  @@ -264,7 +284,7 @@
               throw new TaskException( message );
           }
   
  -        executeTarget( frame, entry, targetName, target );
  +        executeTarget( entry, targetName, target );
       }
   
       /**
  @@ -275,10 +295,9 @@
        * @param name the name of target
        * @param target the target
        * @param entry the project in which to execute
  -     * @exception TaskException if an error occurs
  +     * @throws TaskException if an error occurs
        */
  -    private void executeTarget( final ExecutionFrame frame,
  -                                final ProjectEntry entry,
  +    private void executeTarget( final ProjectEntry entry,
                                   final String name,
                                   final Target target )
           throws TaskException
  @@ -308,28 +327,7 @@
           // Implicit target first
           if( target != project.getImplicitTarget() )
           {
  -            executeTarget( frame, entry, IMPLICIT_TARGET_NAME, project.getImplicitTarget()
);
  -        }
  -
  -        // Named dependencies
  -        final Dependency[] dependencies = target.getDependencies();
  -        for( int i = 0; i < dependencies.length; i++ )
  -        {
  -            final Dependency dependency = dependencies[ i ];
  -            final String otherProjectName = dependency.getProjectName();
  -            if( otherProjectName != null )
  -            {
  -                // Dependency in a referenced project
  -                final Project otherProject =
  -                    getProject( frame, otherProjectName, project );
  -                final ProjectEntry otherEntry = getProjectEntry( otherProject, frame );
  -                executeTarget( frame, otherEntry, dependency.getTargetName() );
  -            }
  -            else
  -            {
  -                // Dependency in this project
  -                executeTarget( frame, entry, dependency.getTargetName() );
  -            }
  +            executeTarget( entry, IMPLICIT_TARGET_NAME, project.getImplicitTarget() );
           }
   
           // Now execute the target itself
  
  
  
  1.14      +18 -4     jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/workspace/Workspace.java
  
  Index: Workspace.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/workspace/Workspace.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Workspace.java	23 May 2002 01:12:02 -0000	1.13
  +++ Workspace.java	23 May 2002 04:29:45 -0000	1.14
  @@ -8,14 +8,14 @@
   package org.apache.myrmidon.interfaces.workspace;
   
   import org.apache.myrmidon.api.TaskException;
  -import org.apache.myrmidon.interfaces.oldmodel.Project;
   import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
  +import org.apache.myrmidon.interfaces.oldmodel.Project;
   
   /**
    * This is the abstraction through which Projects are executed.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.13 $ $Date: 2002/05/23 01:12:02 $
  + * @version $Revision: 1.14 $ $Date: 2002/05/23 04:29:45 $
    */
   public interface Workspace
   {
  @@ -26,10 +26,24 @@
        * Executes a target in a particular project.
        *
        * @param project the Project
  -     * @param frame the frame in which target is executed
        * @param target the name of the target
        * @throws TaskException if an error occurs
        */
  -    void executeProject( Project project, ExecutionFrame frame, String target )
  +    void executeProject( Project project, String target )
  +        throws TaskException;
  +
  +    //Yet another temporary hack
  +    void setFrame( ExecutionFrame frame )
  +        throws TaskException;
  +
  +    /**
  +     * Executes a target in context of workspace.
  +     * The project is specified by URI.
  +     *
  +     * @param uri the URI of the Project
  +     * @param targetName the name of the target to execute
  +     * @throws TaskException if an error occurs
  +     */
  +    void executeTarget( String uri, String targetName )
           throws TaskException;
   }
  
  
  

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