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/myrmidon/src/samples sample.ant
Date Fri, 24 May 2002 06:23:42 GMT
donaldp     02/05/23 23:23:42

  Modified:    antlib/src/java/org/apache/antlib/project
                        Resources.properties TargetTask.java
               container/src/java/org/apache/myrmidon/components/embeddor
                        DefaultEmbeddor.java
               myrmidon/src/samples sample.ant
  Added:       antlib/src/java/org/apache/antlib/project
                        AbstractWorkspaceTask.java DependsTask.java
  Log:
  Add in a depends task. This task allows you to run dependencies (like the depends tag on
target) from inside targets. So the following are valid and equivelent constructs.
  
  <target name="x" depends="a,b,c">
  </target>
  
  <target name="x" depends="a">
    <depends target="b"/>
    <depends target="c"/>
  </target>
  
  <target name="x">
    <depends target="a"/>
    <depends target="b"/>
    <depends target="c"/>
  </target>
  
  The advantage of this is that it allows you to declare dependencies in between other tasks
like
  <target name="x">
    <log message="Before depends evaluated!"/>
    <depends target="c"/>
    <log message="After depends evaluated!"/>
  </target>
  
  Revision  Changes    Path
  1.8       +5 -2      jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/Resources.properties,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Resources.properties	23 May 2002 04:31:14 -0000	1.7
  +++ Resources.properties	24 May 2002 06:23:42 -0000	1.8
  @@ -4,8 +4,11 @@
   target.bad-name.error=Target "{0}" has a invalid name (Reason: {1}).
   target.depends.notice=Dependencies for target "{0}": {1}
   target.bad-dependency.error=Discovered empty dependency in target "{0}" at {1}.
  -target.exec-depends.notice=Executing target "{0}"s dependencies: {1}
  -target.missing-dependency.error=Dependency "{1}" of target "{0}" is missing.
  +
  +workspace.exec-depends.notice=Executing dependency: {0}
  +workspace.missing-dependency.error=Dependency "{1}" at location "{0}" is missing.
  +
  +depends.no-target.error=No target specified in <depends/> task.
   
   param.noname.error=Missing name from parameter.
   param.novalue.error=Missing value from parameter "{0}".
  
  
  
  1.8       +3 -59     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TargetTask.java	24 May 2002 04:30:59 -0000	1.7
  +++ TargetTask.java	24 May 2002 06:23:42 -0000	1.8
  @@ -13,21 +13,17 @@
   import org.apache.avalon.excalibur.i18n.Resources;
   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.7 $ $Date: 2002/05/24 04:30:59 $
  + * @version $Revision: 1.8 $ $Date: 2002/05/24 06:23:42 $
    * @ant.task name="target"
    */
   public class TargetTask
  -    extends AbstractContainerTask
  +    extends AbstractWorkspaceTask
   {
       private static final Resources REZ =
           ResourceManager.getPackageResources( TargetTask.class );
  @@ -142,59 +138,7 @@
   
           for( int i = 0; i < m_dependencies.length; i++ )
           {
  -            final Dependency dependency = m_dependencies[ i ];
  -
  -            final String message =
  -                REZ.getString( "target.exec-depends.notice",
  -                               m_name,
  -                               dependency );
  -            getContext().debug( message );
  -
  -            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 );
  -            }
  +            executeDependency( m_dependencies[ i ] );
           }
       }
   
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/AbstractWorkspaceTask.java
  
  Index: AbstractWorkspaceTask.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.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.AbstractContainerTask;
  import org.apache.myrmidon.interfaces.oldmodel.Project;
  import org.apache.myrmidon.interfaces.oldmodel.ProjectRef;
  import org.apache.myrmidon.interfaces.workspace.Workspace;
  
  /**
   * An abstract class used to execute Ant files within same workspace.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/05/24 06:23:42 $
   */
  public abstract class AbstractWorkspaceTask
      extends AbstractContainerTask
  {
      private final static Resources REZ =
          ResourceManager.getPackageResources( AbstractWorkspaceTask.class );
  
      /**
       * Execute specified Dependency in the current Workspace.
       *
       * @param dependency the dependency to execute
       * @throws TaskException if error occurs executing dependency
       */
      protected final void executeDependency( final Dependency dependency )
          throws TaskException
      {
          final String message =
              REZ.getString( "workspace.exec-depends.notice",
                             dependency );
          getContext().debug( message );
  
          final String uri = getProjectURI( dependency );
          final String targetName = dependency.getTargetName();
          executeTarget( uri, targetName );
      }
  
      /**
       * Utility method to execute target in project file specified
       * by URI. The execution is take place in the same Workspace
       * as the current task.
       *
       * @param uri the projects URI
       * @param targetName the name of target to execute
       * @throws TaskException if error occurs executing target
       */
      protected final void executeTarget( final String uri,
                                          final String targetName )
          throws TaskException
      {
          final Workspace workspace =
              (Workspace)getContext().getService( Workspace.class );
          workspace.executeTarget( uri, targetName );
      }
  
      /**
       * Get the URI for project that specified in dependency.
       *
       * @param dependency the dependency
       * @return
       * @throws TaskException
       */
      protected final 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( "workspace.missing-dependency.error",
                                     getContext().getLocation(),
                                     projectName );
                  throw new TaskException( message );
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/DependsTask.java
  
  Index: DependsTask.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.antlib.project;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.myrmidon.api.TaskException;
  
  /**
   * A simple task to task to execute a group of tasks.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/05/24 06:23:42 $
   * @ant.task name="depends"
   */
  public class DependsTask
      extends AbstractWorkspaceTask
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( DependsTask.class );
  
      /**
       * The name of the target.
       */
      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
       * @see #m_target
       */
      public void setTarget( final String target )
      {
          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() );
      }
  
      /**
       * Validate task to make sure valid parameters are supplied.
       *
       * @throws TaskException if invalid parameters are specified
       */
      private void validate()
          throws TaskException
      {
          if( null == m_target )
          {
              final String message =
                  REZ.getString( "depends.no-target.error" );
              throw new TaskException( message );
          }
      }
  
      public String toString()
      {
          return "Depends['" + getDependency() + "]";
      }
  
      /**
       * Create dependency object.
       *
       * @return the created dependency object
       */
      private Dependency getDependency()
      {
          return new Dependency( m_project, m_target );
      }
  }
  
  
  
  1.75      +3 -2      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
  
  Index: DefaultEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java,v
  retrieving revision 1.74
  retrieving revision 1.75
  diff -u -r1.74 -r1.75
  --- DefaultEmbeddor.java	23 May 2002 04:32:36 -0000	1.74
  +++ DefaultEmbeddor.java	24 May 2002 06:23:42 -0000	1.75
  @@ -62,7 +62,7 @@
    * Instantiate this to embed inside other applications.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.74 $ $Date: 2002/05/23 04:32:36 $
  + * @version $Revision: 1.75 $ $Date: 2002/05/24 06:23:42 $
    */
   public class DefaultEmbeddor
       extends AbstractLogEnabled
  @@ -179,7 +179,8 @@
       public TaskListener createListener( final String name )
           throws Exception
       {
  -        final TypeFactory factory = m_typeManager.getFactory( TaskListener.ROLE );
  +        final TypeFactory factory =
  +            m_typeManager.getFactory( TaskListener.ROLE );
           return (TaskListener)factory.create( name );
       }
   
  
  
  
  1.9       +15 -1     jakarta-ant-myrmidon/myrmidon/src/samples/sample.ant
  
  Index: sample.ant
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/myrmidon/src/samples/sample.ant,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- sample.ant	23 May 2002 06:49:14 -0000	1.8
  +++ sample.ant	24 May 2002 06:23:42 -0000	1.9
  @@ -21,7 +21,8 @@
       <property name="year" value="2000"/>
   
       <target name="main"
  -        depends="typedef-test, typedef2-test, converterdef-test,
  +        depends="typedef-test, depends-test,
  +                 typedef2-test, converterdef-test,
                    datatype-test, namespace-test,
                    ant1-tasklib-test,
                    prim->extensions-test" />
  @@ -42,6 +43,19 @@
           <if test="${blah}">
               <log message="Sucessful if test!"/>
           </if>
  +    </target>
  +
  +    <target name="depends-test">
  +        <log message="Pre depends1"/>
  +        <depends target="depends-test-target"/>
  +        <log message="Post depends1"/>
  +        <log message="Pre depends2"/>
  +        <depends target="depends-test-target"/>
  +        <log message="Post depends2"/>
  +    </target>
  +
  +    <target name="depends-test-target">
  +        <log message="In depends"/>
       </target>
   
       <target name="property-test">
  
  
  

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