You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by ad...@apache.org on 2002/07/02 16:41:08 UTC

cvs commit: jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/project/test ant-call.ant projectref.ant

adammurdoch    2002/07/02 07:41:08

  Modified:    framework/src/java/org/apache/myrmidon/framework/project
                        AbstractWorkspaceTask.java Resources.properties
                        TargetImplTask.java
               container/src/java/org/apache/myrmidon/components/workspace
                        DefaultWorkspace.java
               container/src/java/org/apache/myrmidon/interfaces/model
                        Target.java
               antlib/src/java/org/apache/antlib/project AntCallTask.java
                        DependsTask.java
               antlib/src/test/org/apache/antlib/project/test ant-call.ant
                        projectref.ant
  Removed:     framework/src/java/org/apache/myrmidon/framework/project
                        Dependency.java
  Log:
  - Moved handling of qualified target names (ie project->target) from
    TargetImplTask to DefaultWorkspace.  Changed separator from '->' to  '/'
    (ie project/target), and added handling of recursive project references
    (eg project1/project2/target).
  
  - Can now use qualified target names on the command-line, and in the
    'target' attribute of <ant-call>, <ant>, and <depends>.
  
  - Removed 'project' attribute from <ant-call> and <depends> tasks.
  
  - Added 'myrmidon.target' property, which gets set to the current Target.
  
  Revision  Changes    Path
  1.6       +10 -11    jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/project/AbstractWorkspaceTask.java
  
  Index: AbstractWorkspaceTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/project/AbstractWorkspaceTask.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractWorkspaceTask.java	2 Jul 2002 10:48:38 -0000	1.5
  +++ AbstractWorkspaceTask.java	2 Jul 2002 14:41:07 -0000	1.6
  @@ -29,31 +29,30 @@
           ResourceManager.getPackageResources( AbstractWorkspaceTask.class );
   
       /**
  -     * Execute specified Dependency in the same Workspace as this task.
  +     * Executes a target in the same workspace as this task.
        *
  -     * @param dependency the dependency to execute
  -     * @throws org.apache.myrmidon.api.TaskException if error occurs executing dependency
  +     * @param target the qualified name of the target to execute
  +     * @throws TaskException if error occurs executing target
        */
  -    protected final void executeDependency( final Dependency dependency )
  +    protected final void executeTarget( final String target )
           throws TaskException
       {
           final String message =
               REZ.getString( "workspace.exec-depends.notice",
  -                           dependency );
  +                           target );
           getContext().debug( message );
   
  -        // Locate the referenced target
  -        final ProjectDescriptor project = getProjectDescriptor( dependency.getProjectName() );
  -        final String targetName = dependency.getTargetName();
  +        // Locate the current project
  +        final ProjectDescriptor project = getProjectDescriptor( null );
   
  -        executeTarget( project, targetName );
  +        executeTarget( project, target );
       }
   
       /**
        * Utility method to execute a target.  The execution takes place in the
        * same Workspace as this task.
        *
  -     * @param target the name of target to execute
  +     * @param target the qualified name of target to execute
        * @throws org.apache.myrmidon.api.TaskException if error occurs executing target
        */
       protected final void executeTarget( final ProjectDescriptor descriptor,
  
  
  
  1.3       +0 -2      jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/project/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/project/Resources.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Resources.properties	27 Jun 2002 11:13:07 -0000	1.2
  +++ Resources.properties	2 Jul 2002 14:41:07 -0000	1.3
  @@ -1,8 +1,6 @@
   target.no-name.error=Target does not specify the name attribute.
   target.exec.notice=Executing target: "{0}".
   target.task-exec.notice=Executing task: "{0}".
  -target.depends.notice=Dependencies for target "{0}": {1}
  -target.bad-dependency.error=Discovered empty dependency in target "{0}" at {1}.
   
   workspace.exec-depends.notice=Executing dependency: {0}
   workspace.missing-ref.error=Unable to locate project "{0}".
  
  
  
  1.2       +12 -74    jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/project/TargetImplTask.java
  
  Index: TargetImplTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/project/TargetImplTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TargetImplTask.java	2 Jul 2002 12:32:34 -0000	1.1
  +++ TargetImplTask.java	2 Jul 2002 14:41:07 -0000	1.2
  @@ -7,15 +7,13 @@
    */
   package org.apache.myrmidon.framework.project;
   
  -import org.apache.myrmidon.api.TaskException;
  -import org.apache.myrmidon.api.metadata.ModelElement;
  -import org.apache.myrmidon.framework.project.Dependency;
  -import org.apache.myrmidon.framework.project.AbstractWorkspaceTask;
  -import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.avalon.excalibur.i18n.ResourceManager;
   import java.util.ArrayList;
  -import java.util.StringTokenizer;
   import java.util.List;
  +import java.util.StringTokenizer;
  +import org.apache.avalon.excalibur.i18n.ResourceManager;
  +import org.apache.avalon.excalibur.i18n.Resources;
  +import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.api.metadata.ModelElement;
   
   /**
    * An abstract base class for implementing &gt;target&lt; tasks.
  @@ -46,7 +44,7 @@
       /**
        * The list of dependencies to execute before this target.
        */
  -    private final List m_dependencies = new ArrayList();
  +    private String[] m_dependencies = new String[ 0 ];
   
       /**
        * The name of target.
  @@ -76,7 +74,7 @@
       public void setDepends( final String depends )
           throws TaskException
       {
  -        buildDependsList( depends );
  +        m_dependencies = split( depends, "," );
       }
   
       /**
  @@ -127,11 +125,10 @@
       protected void executeDependencies()
           throws TaskException
       {
  -        final int count = m_dependencies.size();
  -        for( int i = 0; i < count; i++ )
  +        for( int i = 0; i < m_dependencies.length; i++ )
           {
  -            final Dependency dependency = (Dependency)m_dependencies.get( i );
  -            executeDependency( dependency );
  +            final String dependency = m_dependencies[ i ];
  +            executeTarget( dependency );
           }
       }
   
  @@ -161,65 +158,6 @@
       }
   
       /**
  -     * Utility method to parse a list of dependencies from depends
  -     * string, adding them to the Dependencies list.
  -     *
  -     * @param depends a comma separated string of dependencies
  -     * @throws TaskException on error
  -     */
  -    private void buildDependsList( final String depends )
  -        throws TaskException
  -    {
  -        m_dependencies.clear();
  -
  -        //apply depends attribute
  -        if( null == depends )
  -        {
  -            return;
  -        }
  -
  -        final String[] elements = split( depends, "," );
  -
  -        for( int i = 0; i < elements.length; i++ )
  -        {
  -            final String dependency = elements[ i ].trim();
  -
  -            // Split project->target dependencies
  -            final int sep = dependency.indexOf( "->" );
  -            final String projectName;
  -            final String targetName;
  -            if( sep != -1 )
  -            {
  -                projectName = dependency.substring( 0, sep );
  -                targetName = dependency.substring( sep + 2 );
  -            }
  -            else
  -            {
  -                projectName = null;
  -                targetName = dependency;
  -            }
  -
  -            if( targetName.length() == 0 ||
  -                ( projectName != null && projectName.length() == 0 ) )
  -            {
  -                final String message =
  -                    REZ.getString( "target.bad-dependency.error",
  -                                   getContext().getName(),
  -                                   getContext().getLocation() );
  -                throw new TaskException( message );
  -            }
  -
  -            m_dependencies.add( new Dependency( projectName, targetName ) );
  -        }
  -
  -        final String message =
  -            REZ.getString( "target.depends.notice",
  -                           m_name,
  -                           m_dependencies );
  -        getContext().debug( message );
  -    }
  -
  -    /**
        * Splits the string on every token into an array of strings.
        *
        * @param string the string
  @@ -233,7 +171,7 @@
   
           for( int i = 0; i < result.length; i++ )
           {
  -            result[ i ] = tokenizer.nextToken();
  +            result[ i ] = tokenizer.nextToken().trim();
           }
   
           return result;
  
  
  
  1.111     +56 -4     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.110
  retrieving revision 1.111
  diff -u -r1.110 -r1.111
  --- DefaultWorkspace.java	2 Jul 2002 10:48:38 -0000	1.110
  +++ DefaultWorkspace.java	2 Jul 2002 14:41:07 -0000	1.111
  @@ -26,6 +26,7 @@
   import org.apache.myrmidon.interfaces.workspace.ProjectRefSet;
   import org.apache.myrmidon.interfaces.workspace.Workspace;
   import org.apache.myrmidon.interfaces.workspace.TargetSet;
  +import org.apache.myrmidon.interfaces.workspace.ProjectRef;
   
   /**
    * This is the default implementation of Workspace.
  @@ -72,7 +73,7 @@
       }
   
       public void execute( final ProjectDescriptor descriptor,
  -                         final String targetName )
  +                         final String qualifiedTargetName )
           throws TaskException
       {
           final ProjectEntry entry = getProjectEntry( descriptor );
  @@ -80,8 +81,56 @@
           // First execute the implicit target.
           executeTarget( entry, Project.IMPLICIT_TARGET_NAME );
   
  -        // Now execute the called target.
  -        executeTarget( entry, getTargetName( entry.getProject(), targetName ) );
  +        // Split the target name into project name and residual
  +        final String[] splitName = splitTargetName( qualifiedTargetName );
  +        final String projectName = splitName[ 0 ];
  +        final String targetName = splitName[ 1 ];
  +
  +        if( projectName != null )
  +        {
  +            // A target in a referenced project
  +            final ProjectRef otherProject = entry.getProjectRef( projectName );
  +            if( otherProject == null )
  +            {
  +                final String message = REZ.getString( "no-project.error", projectName );
  +                throw new TaskException( message );
  +            }
  +
  +            // Recursively call this method, so that projects can be traversed
  +            execute( otherProject.getProject(), targetName );
  +        }
  +        else
  +        {
  +            // A target in this project
  +            executeTarget( entry, getTargetName( entry.getProject(), targetName ) );
  +        }
  +    }
  +
  +    /**
  +     * Splits a target name into project name and residual.
  +     */
  +    private String[] splitTargetName( final String name )
  +    {
  +        final String[] parts = new String[2];
  +        if( name != null )
  +        {
  +            final int pos = name.indexOf( "/" );
  +            if( pos == -1 )
  +            {
  +                parts[ 1 ] = name;
  +            }
  +            else if( pos == name.length() - 1 )
  +            {
  +                // Default target of referenced project
  +                parts[ 0 ] = name.substring( 0, pos );
  +            }
  +            else
  +            {
  +                parts[ 0 ] = name.substring( 0, pos );
  +                parts[ 1 ] = name.substring( pos+1 );
  +            }
  +        }
  +        return parts;
       }
   
       /**
  @@ -282,6 +331,9 @@
                                               targetModel.getLocation() );
           final Executor executor =
               (Executor)newContext.getService( Executor.class );
  +        final PropertyStore props =
  +            (PropertyStore)newContext.getService( PropertyStore.class );
  +        props.setProperty( Target.KEY, target );
   
           executor.execute( targetModel, newContext );
       }
  
  
  
  1.13      +3 -1      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/model/Target.java
  
  Index: Target.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/model/Target.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Target.java	13 Jun 2002 05:39:14 -0000	1.12
  +++ Target.java	2 Jul 2002 14:41:08 -0000	1.13
  @@ -18,6 +18,8 @@
   public class Target
       extends AbstractUnit
   {
  +    public static final String KEY = "myrmidon.target";
  +
       /**
        * The Model representing target.
        */
  
  
  
  1.11      +2 -15     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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AntCallTask.java	2 Jul 2002 02:50:55 -0000	1.10
  +++ AntCallTask.java	2 Jul 2002 14:41:08 -0000	1.11
  @@ -22,25 +22,12 @@
   public class AntCallTask
       extends AbstractAntTask
   {
  -    private String m_projectName;
  -
  -    /**
  -     * Specifies the project to execute. If not specified, the current
  -     * project is used.
  -     *
  -     * @param project the name of the Project to execute.
  -     */
  -    public void setProject( String project )
  -    {
  -        m_projectName = project;
  -    }
  -
       /**
        * Get/create/build the project which will be executed.
        */
       protected void prepare( final ExecuteTarget exe ) throws TaskException
       {
  -        final ProjectDescriptor project = getProjectDescriptor( m_projectName );
  +        final ProjectDescriptor project = getProjectDescriptor( null );
           exe.setProject( project );
       }
   }
  
  
  
  1.6       +3 -30     jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/DependsTask.java
  
  Index: DependsTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/DependsTask.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DependsTask.java	2 Jul 2002 10:39:47 -0000	1.5
  +++ DependsTask.java	2 Jul 2002 14:41:08 -0000	1.6
  @@ -10,7 +10,6 @@
   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.project.Dependency;
   import org.apache.myrmidon.framework.project.AbstractWorkspaceTask;
   
   /**
  @@ -32,11 +31,6 @@
       private String m_target;
   
       /**
  -     * The name of the project.
  -     */
  -    private String m_project;
  -
  -    /**
        * Specify the name of target.
        *
        * @param target the name of the target
  @@ -47,22 +41,11 @@
           m_target = target;
       }
   
  -    /**
  -     * Specify the name of project.
  -     *
  -     * @param project the name of the project
  -     * @see #m_project
  -     */
  -    public void setProject( final String project )
  -    {
  -        m_project = project;
  -    }
  -
       public void execute()
           throws TaskException
       {
           validate();
  -        executeDependency( getDependency() );
  +        executeTarget( m_target );
       }
   
       /**
  @@ -83,16 +66,6 @@
   
       public String toString()
       {
  -        return "Depends['" + getDependency() + "]";
  -    }
  -
  -    /**
  -     * Create dependency object.
  -     *
  -     * @return the created dependency object
  -     */
  -    private Dependency getDependency()
  -    {
  -        return new Dependency( m_project, m_target );
  +        return "Depends['" + m_target + "]";
       }
   }
  
  
  
  1.5       +7 -6      jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/project/test/ant-call.ant
  
  Index: ant-call.ant
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/project/test/ant-call.ant,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ant-call.ant	2 Jul 2002 02:50:55 -0000	1.4
  +++ ant-call.ant	2 Jul 2002 14:41:08 -0000	1.5
  @@ -82,7 +82,7 @@
                   </common-project>
               </out>
               <tasks>
  -                <ant-call project="common"/>
  +                <ant-call targets="common/"/>
               </tasks>
           </expect-output>
       </target>
  @@ -98,7 +98,7 @@
                   </common-project>
               </out>
               <tasks>
  -                <ant-call project="common" targets="other-target"/>
  +                <ant-call targets="common/other-target"/>
               </tasks>
           </expect-output>
       </target>
  @@ -106,10 +106,10 @@
       <!-- Call an unknown target in a referenced project -->
       <target name="ref-unknown-target">
           <expect-error>
  -            <exc>Execution of target "no-such-target" in project "${myrmidon.projectrefs/projectRefs/common/project/uri}" failed.</exc>
  +            <exc>Execution of target "common/no-such-target" in project "${myrmidon.project/projectDescriptor/uri}" failed.</exc>
               <exc>No target named "no-such-target" in project "${myrmidon.projectrefs/projectRefs/common/project/uri}".</exc>
               <tasks>
  -                <ant-call project="common" targets="no-such-target"/>
  +                <ant-call targets="common/no-such-target"/>
               </tasks>
           </expect-error>
       </target>
  @@ -117,9 +117,10 @@
       <!-- Call a target in an unknown referenced project -->
       <target name="ref-unknown-project">
           <expect-error>
  -            <exc>Unable to locate project "no-such-project".</exc>
  +            <exc>Execution of target "no-such-project/main" in project "${myrmidon.project/projectDescriptor/uri}" failed.</exc>
  +            <exc>Project no-such-project not found.</exc>
               <tasks>
  -                <ant-call project="no-such-project"/>
  +                <ant-call targets="no-such-project/main"/>
               </tasks>
           </expect-error>
       </target>
  
  
  
  1.2       +8 -8      jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/project/test/projectref.ant
  
  Index: projectref.ant
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/project/test/projectref.ant,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- projectref.ant	27 Jun 2002 11:13:08 -0000	1.1
  +++ projectref.ant	2 Jul 2002 14:41:08 -0000	1.2
  @@ -11,7 +11,7 @@
               </out>
               <tasks>
                   <projectref name="common" location="projectref-common.ant"/>
  -                <depends project="common" target="main"/>
  +                <depends target="common/main"/>
               </tasks>
           </expect-output>
       </target>
  @@ -19,16 +19,16 @@
       <!-- Make sure project is reused. -->
       <target name="project-reuse">
           <projectref name="common" location="projectref-common.ant"/>
  -        <depends project="common" target="target1"/>
  -        <depends project="common" target="check-target1"/>
  +        <depends target="common/target1"/>
  +        <depends target="common/check-target1"/>
       </target>
   
       <!-- Make sure the same project is used when 2 different references refer to it -->
       <target name="multi-ref">
           <projectref name="ref1" location="projectref-common.ant"/>
           <projectref name="ref2" location="projectref-common.ant"/>
  -        <depends project="ref1" target="target1"/>
  -        <depends project="ref2" target="check-target1"/>
  +        <depends target="ref1/target1"/>
  +        <depends target="ref2/check-target1"/>
       </target>
   
       <!-- Make sure target state is kept -->
  @@ -43,8 +43,8 @@
               </out>
               <tasks>
                   <projectref name="common" location="projectref-common.ant"/>
  -                <depends project="common" target="target2"/>
  -                <depends project="common" target="target2"/>
  +                <depends target="common/target2"/>
  +                <depends target="common/target2"/>
               </tasks>
           </expect-output>
       </target>
  @@ -52,7 +52,7 @@
       <!-- Use the reference to this project -->
       <target name="self-ref">
           <assert><not><is-set property="target1"/></not></assert>
  -        <depends project="projectref" target="target1"/>
  +        <depends target="projectref/target1"/>
           <assert><is-set property="target1"/></assert>
       </target>
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>