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/antlib/src/java/org/apache/antlib/project Dependency.java Resources.properties TargetTask.java
Date Sun, 05 May 2002 12:46:59 GMT
donaldp     02/05/05 05:46:59

  Modified:    antlib/src/java/org/apache/antlib/project
                        Resources.properties TargetTask.java
  Added:       antlib/src/java/org/apache/antlib/project Dependency.java
  Log:
  Flesh out the "Target" task further such that it parses dependcies correctly, and emits
all the same messages as the Target/Workspace combo does now.
  
  Revision  Changes    Path
  1.5       +3 -0      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Resources.properties	3 May 2002 10:34:02 -0000	1.4
  +++ Resources.properties	5 May 2002 12:46:59 -0000	1.5
  @@ -2,6 +2,9 @@
   target.exec.notice=Executing target: "{0}".
   target.task-exec.notice=Executing task: "{0}".
   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}
   
   typelib.missing-library.error=Missing library attribute from typelib statement.
   typelib.missing-name.error=Specified role ("{0}") but missing name from typelib statement.
  
  
  
  1.3       +172 -7    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TargetTask.java	3 May 2002 09:26:13 -0000	1.2
  +++ TargetTask.java	5 May 2002 12:46:59 -0000	1.3
  @@ -8,6 +8,7 @@
   package org.apache.antlib.project;
   
   import java.util.ArrayList;
  +import java.util.StringTokenizer;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.myrmidon.api.TaskException;
  @@ -20,7 +21,7 @@
    * A simple task to task to execute a group of tasks.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.2 $ $Date: 2002/05/03 09:26:13 $
  + * @version $Revision: 1.3 $ $Date: 2002/05/05 12:46:59 $
    * @ant.task name="target"
    */
   public class TargetTask
  @@ -46,6 +47,11 @@
       private ExecutionFrame m_frame;
   
       /**
  +     * The list of dependencies to execute before this target.
  +     */
  +    private Dependency[] m_dependencies;
  +
  +    /**
        * Specify the name of target.
        *
        * @param name the name of the target
  @@ -57,6 +63,18 @@
       }
   
       /**
  +     * Specify the list of dependencies for target.
  +     *
  +     * @param depends the list of dependencies for target
  +     * @see #m_dependencies
  +     */
  +    public void setDepends( final String depends )
  +        throws TaskException
  +    {
  +        m_dependencies = buildDependsList( depends );
  +    }
  +
  +    /**
        * Add a task to the target.
        *
        * @param task a model representing a task
  @@ -70,6 +88,30 @@
       public void execute()
           throws TaskException
       {
  +        validate();
  +
  +        executeDependencies();
  +
  +        if( getContext().isInfoEnabled() )
  +        {
  +            final String message =
  +                REZ.getString( "target.exec.notice", m_name );
  +            getContext().info( message );
  +        }
  +
  +        setupFrame();
  +
  +        executeContainedTasks();
  +    }
  +
  +    /**
  +     * Validate task to make sure valid parameters are supplied.
  +     *
  +     * @throws TaskException if invalid parameters are specified
  +     */
  +    private void validate()
  +        throws TaskException
  +    {
           if( null == m_name )
           {
               final String message =
  @@ -91,17 +133,56 @@
                                  e );
               throw new TaskException( message, e );
           }
  +    }
   
  -        if( getContext().isInfoEnabled() )
  +    /**
  +     * Setuip the execution frame in preparation for running
  +     * containe dtasks.
  +     */
  +    private void setupFrame()
  +    {
  +        final ExecutionFrame parentFrame = super.getExecutionFrame();
  +        m_frame = parentFrame.createChildFrame( m_name, null, false );
  +    }
  +
  +    /**
  +     * Execute depencies of target (if any).
  +     *
  +     * @throws TaskException if theres an eror executing dependencies.
  +     */
  +    private void executeDependencies()
  +        throws TaskException
  +    {
  +        if( null == m_dependencies )
           {
  -            final String message =
  -                REZ.getString( "target.exec.notice", m_name );
  -            getContext().info( message );
  +            return;
           }
   
  -        final ExecutionFrame parentFrame = super.getExecutionFrame();
  -        m_frame = parentFrame.createChildFrame( m_name, null, false );
  +        for( int i = 0; i < m_dependencies.length; i++ )
  +        {
  +            final Dependency dependency = m_dependencies[ i ];
  +
  +            if( getContext().isInfoEnabled() )
  +            {
  +                final String message =
  +                    REZ.getString( "target.exec-depends.notice",
  +                                   m_name,
  +                                   dependency );
  +                getContext().info( message );
  +            }
   
  +            //executeProjectTarget( dependency );
  +        }
  +    }
  +
  +    /**
  +     * Execute all the tasks contained within target.
  +     *
  +     * @throws TaskException if theres an eror executing contained tasks.
  +     */
  +    private void executeContainedTasks()
  +        throws TaskException
  +    {
           final ModelElement[] tasks =
               (ModelElement[])m_tasks.toArray( new ModelElement[ m_tasks.size() ] );
   
  @@ -133,5 +214,89 @@
       public String toString()
       {
           return "Target['" + m_name + "]";
  +    }
  +
  +    /**
  +     * Utility method to parse a list of dependencies from depends
  +     * string.
  +     *
  +     * @param depends a comma separated string of dependencies
  +     * @return an array of Dependency objects
  +     * @throws TaskException on error
  +     */
  +    private Dependency[] buildDependsList( final String depends )
  +        throws TaskException
  +    {
  +        //apply depends attribute
  +        if( null == depends )
  +        {
  +            return null;
  +        }
  +
  +        final String[] elements = split( depends, "," );
  +        final ArrayList dependsList = new ArrayList();
  +
  +        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 );
  +            }
  +
  +            dependsList.add( new Dependency( projectName, targetName ) );
  +        }
  +
  +        if( getContext().isDebugEnabled() )
  +        {
  +            final String message =
  +                REZ.getString( "target.depends.notice",
  +                               m_name,
  +                               dependsList );
  +            getContext().debug( message );
  +        }
  +
  +        return (Dependency[])dependsList.toArray( new Dependency[ dependsList.size() ]
);
  +    }
  +
  +    /**
  +     * Splits the string on every token into an array of strings.
  +     *
  +     * @param string the string
  +     * @param onToken the token
  +     * @return the resultant array
  +     */
  +    private String[] split( final String string, final String onToken )
  +    {
  +        final StringTokenizer tokenizer = new StringTokenizer( string, onToken );
  +        final String[] result = new String[ tokenizer.countTokens() ];
  +
  +        for( int i = 0; i < result.length; i++ )
  +        {
  +            result[ i ] = tokenizer.nextToken();
  +        }
  +
  +        return result;
       }
   }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/Dependency.java
  
  Index: Dependency.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;
  
  /**
   * A dependency for a target.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/05/05 12:46:59 $
   */
  class Dependency
  {
      private final String m_projectName;
      private final String m_targetName;
  
      /**
       * @param projectName The project containing the depended-on target.
       * @param targetName The name of the depended-on target.
       */
      public Dependency( final String projectName, final String targetName )
      {
          m_projectName = projectName;
          m_targetName = targetName;
      }
  
      /**
       * @return The name of the project containing the depended-on target.
       */
      public String getProjectName()
      {
          return m_projectName;
      }
  
      /**
       * @return The name of the depended-on target.
       */
      public String getTargetName()
      {
          return m_targetName;
      }
  
      /**
       * Return human readable string for dependency.
       *
       * @return human readable string.
       */
      public String toString()
      {
          if( null == m_projectName )
          {
              return m_targetName;
          }
          else
          {
              return m_projectName + "->" + m_targetName;
          }
      }
  }
  
  
  

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