ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant Project.java Executor.java
Date Thu, 07 Apr 2005 19:31:39 GMT
mbenson     2005/04/07 12:31:39

  Modified:    src/main/org/apache/tools/ant/helper
                        SingleCheckExecutor.java DefaultExecutor.java
               src/main/org/apache/tools/ant/taskdefs Ant.java
               src/main/org/apache/tools/ant Project.java Executor.java
  Added:       src/etc/testcases/core executor.xml
               src/testcases/org/apache/tools/ant ExecutorTest.java
  Log:
  Add subproject Executor to Executor interface + its use to Project & Ant task.
  Move keep-going awareness to Executors.
  PR: 22901
  Submitted by: Alexey Solofnenko
  Reviewed by: Matt Benson
  
  Revision  Changes    Path
  1.1                  ant/src/etc/testcases/core/executor.xml
  
  Index: executor.xml
  ===================================================================
  <project>
    <target name="foo">
      <echo>foo</echo>
      <fail if="failfoo" message="failfoo" />
    </target>
    <target name="a" depends="foo">
      <echo>a</echo>
    </target>
    <target name="b" depends="foo">
      <echo>b</echo>
    </target>
  </project>
  
  
  
  1.1                  ant/src/testcases/org/apache/tools/ant/ExecutorTest.java
  
  Index: ExecutorTest.java
  ===================================================================
  /*
   * Copyright 2005 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  
  package org.apache.tools.ant;
  
  import java.util.Vector;
  
  import org.apache.tools.ant.taskdefs.Exit;
  
  /**
   * Executor tests
   */
  public class ExecutorTest extends BuildFileTest implements BuildListener {
      private static final String SINGLE_CHECK
          = "org.apache.tools.ant.helper.SingleCheckExecutor";
      private static final Vector targetNames;
      static {
          targetNames = new Vector();
          targetNames.add("a");
          targetNames.add("b");
      }
  
      private int targetCount;
  
      /* BuildListener stuff */
      public void targetStarted(BuildEvent event) {
          targetCount++;
      }
      public void buildStarted(BuildEvent event) {}
      public void buildFinished(BuildEvent event) {}
      public void targetFinished(BuildEvent event) {}
      public void taskStarted(BuildEvent event) {}
      public void taskFinished(BuildEvent event) {}
      public void messageLogged(BuildEvent event) {}
  
      public ExecutorTest(String name) {
          super(name);
      }
  
      public void setUp() {
          configureProject("src/etc/testcases/core/executor.xml");
          targetCount = 0;
          getProject().addBuildListener(this);
      }
  
      private Project getProject(String e) {
          return getProject(e, false);
      }
  
      private Project getProject(String e, boolean f) {
          return getProject(e, f, false);
      }
  
      private Project getProject(String e, boolean f, boolean k) {
          Project p = getProject();
          p.setNewProperty("ant.executor.class", e);
          p.setKeepGoingMode(k);
          if (f) {
              p.setNewProperty("failfoo", "foo");
          }
          return p;
      }
  
      public void testDefaultExecutor() {
          getProject().executeTargets(targetNames);
          assertEquals(targetCount, 4);
      }
  
      public void testSingleCheckExecutor() {
          getProject(SINGLE_CHECK).executeTargets(targetNames);
          assertEquals(targetCount, 3);
      }
  
      public void testDefaultFailure() {
          try {
              getProject(null, true).executeTargets(targetNames);
              fail("should fail");
          } catch (BuildException e) {
              assertTrue(e.getMessage().equals("failfoo"));
              assertEquals(targetCount, 1);
          }
      }
  
      public void testSingleCheckFailure() {
          try {
              getProject(SINGLE_CHECK, true).executeTargets(targetNames);
              fail("should fail");
          } catch (BuildException e) {
              assertTrue(e.getMessage().equals("failfoo"));
              assertEquals(targetCount, 1);
          }
      }
  
      public void testKeepGoingDefault() {
          try {
              getProject(null, true, true).executeTargets(targetNames);
              fail("should fail");
          } catch (BuildException e) {
              assertTrue(e.getMessage().equals("failfoo"));
              assertEquals(targetCount, 2);
          }
      }
  
      public void testKeepGoingSingleCheck() {
          try {
              getProject(SINGLE_CHECK, true, true).executeTargets(targetNames);
              fail("should fail");
          } catch (BuildException e) {
              assertTrue(e.getMessage().equals("failfoo"));
              assertEquals(targetCount, 1);
          }
      }
  
  }
  
  
  
  
  1.4       +5 -0      ant/src/main/org/apache/tools/ant/helper/SingleCheckExecutor.java
  
  Index: SingleCheckExecutor.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/helper/SingleCheckExecutor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SingleCheckExecutor.java	25 Jan 2005 15:42:58 -0000	1.3
  +++ SingleCheckExecutor.java	7 Apr 2005 19:31:39 -0000	1.4
  @@ -38,4 +38,9 @@
                   project.topoSort(targetNames, project.getTargets(), false));
       }
   
  +    //inherit doc
  +    public Executor getSubProjectExecutor() {
  +        return this;
  +    }
  +
   }
  
  
  
  1.4       +23 -5     ant/src/main/org/apache/tools/ant/helper/DefaultExecutor.java
  
  Index: DefaultExecutor.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/helper/DefaultExecutor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultExecutor.java	14 Dec 2004 20:54:00 -0000	1.3
  +++ DefaultExecutor.java	7 Apr 2005 19:31:39 -0000	1.4
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 2004 The Apache Software Foundation
  + * Copyright 2004-2005 The Apache Software Foundation
    *
    *  Licensed under the Apache License, Version 2.0 (the "License");
    *  you may not use this file except in compliance with the License.
  @@ -17,25 +17,43 @@
   
   package org.apache.tools.ant.helper;
   
  -
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.Executor;
   import org.apache.tools.ant.BuildException;
   
  -
   /**
    * Default Target executor implementation. Runs each target individually
  - * (including all of its dependencies), halting immediately upon error.
  + * (including all of its dependencies). If an error occurs, behavior is
  + * determined by the Project's "keep-going" mode.
    * @since Ant 1.6.3
    */
   public class DefaultExecutor implements Executor {
   
  +    private static final SingleCheckExecutor SUB_EXECUTOR = new SingleCheckExecutor();
  +
       //inherit doc
       public void executeTargets(Project project, String[] targetNames)
           throws BuildException {
  +        BuildException thrownException = null;
           for (int i = 0; i < targetNames.length; i++) {
  -            project.executeTarget(targetNames[i]);
  +            try {
  +                project.executeTarget(targetNames[i]);
  +            } catch (BuildException ex) {
  +                if (project.isKeepGoingMode()) {
  +                    thrownException = ex;
  +                } else {
  +                    throw ex;
  +                }
  +            }
  +        }
  +        if (thrownException != null) {
  +            throw thrownException;
           }
       }
   
  +    //inherit doc
  +    public Executor getSubProjectExecutor() {
  +        return SUB_EXECUTOR;
  +    }
  +
   }
  
  
  
  1.119     +2 -7      ant/src/main/org/apache/tools/ant/taskdefs/Ant.java
  
  Index: Ant.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
  retrieving revision 1.118
  retrieving revision 1.119
  diff -u -r1.118 -r1.119
  --- Ant.java	10 Mar 2005 12:50:57 -0000	1.118
  +++ Ant.java	7 Apr 2005 19:31:39 -0000	1.119
  @@ -64,9 +64,6 @@
    */
   public class Ant extends Task {
   
  -    /** Target Executor */
  -    private static final Executor EXECUTOR = new SingleCheckExecutor();
  -
       private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
   
       /** the basedir where is executed the build file */
  @@ -396,9 +393,7 @@
                   try {
                       log("Entering " + antFile + "...", Project.MSG_VERBOSE);
                       newProject.fireSubBuildStarted();
  -                    EXECUTOR.executeTargets(newProject,
  -                        (String[]) (locals.toArray(new String[locals.size()])));
  -
  +                    newProject.executeTargets(locals);
                   } catch (BuildException ex) {
                       t = ProjectHelper
                           .addLocationToBuildException(ex, getLocation());
  @@ -755,4 +750,4 @@
               return name;
           }
       }
  -}
  \ No newline at end of file
  +}
  
  
  
  1.191     +31 -21    ant/src/main/org/apache/tools/ant/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Project.java,v
  retrieving revision 1.190
  retrieving revision 1.191
  diff -u -r1.190 -r1.191
  --- Project.java	29 Mar 2005 21:46:36 -0000	1.190
  +++ Project.java	7 Apr 2005 19:31:39 -0000	1.191
  @@ -37,7 +37,6 @@
   import org.apache.tools.ant.input.DefaultInputHandler;
   import org.apache.tools.ant.input.InputHandler;
   import org.apache.tools.ant.helper.DefaultExecutor;
  -import org.apache.tools.ant.helper.KeepGoingExecutor;
   import org.apache.tools.ant.types.FilterSet;
   import org.apache.tools.ant.types.FilterSetCollection;
   import org.apache.tools.ant.types.Description;
  @@ -243,6 +242,7 @@
           ComponentHelper.getComponentHelper(subProject)
               .initSubProject(ComponentHelper.getComponentHelper(this));
           subProject.setKeepGoingMode(this.isKeepGoingMode());
  +        subProject.setExecutor(getExecutor().getSubProjectExecutor());
       }
   
       /**
  @@ -1015,23 +1015,23 @@
       }
   
       /**
  -     * Execute the specified sequence of targets, and the targets
  -     * they depend on.
  -     *
  -     * @param targetNames A vector of target name strings to execute.
  -     *                    Must not be <code>null</code>.
  -     *
  -     * @exception BuildException if the build failed.
  +     * Set the Executor instance for this Project.
  +     * @param e the Executor to use.
        */
  -    public void executeTargets(Vector targetNames) throws BuildException {
  +    public void setExecutor(Executor e) {
  +        addReference("ant.executor", e);
  +    }
   
  +    /**
  +     * Get this Project's Executor (setting it if necessary).
  +     * @return an Executor instance.
  +     */
  +    public Executor getExecutor() {
           Object o = getReference("ant.executor");
           if (o == null) {
               String classname = getProperty("ant.executor.class");
               if (classname == null) {
  -                classname = (keepGoingMode)
  -                    ? KeepGoingExecutor.class.getName()
  -                    : DefaultExecutor.class.getName();
  +                classname = DefaultExecutor.class.getName();
               }
               log("Attempting to create object of type " + classname, MSG_DEBUG);
               try {
  @@ -1046,17 +1046,27 @@
               } catch (Exception ex) {
                   log(ex.toString(), MSG_ERR);
               }
  -            if (o != null) {
  -                addReference("ant.executor", o);
  +            if (o == null) {
  +                throw new BuildException(
  +                    "Unable to obtain a Target Executor instance.");
               }
  +            setExecutor((Executor) o);
           }
  -        if (o == null) {
  -            throw new BuildException("Unable to obtain a Target Executor instance.");
  -        } else {
  -            String[] targetNameArray = (String[]) (targetNames.toArray(
  -                new String[targetNames.size()]));
  -            ((Executor) o).executeTargets(this, targetNameArray);
  -        }
  +        return (Executor) o;
  +    }
  +
  +    /**
  +     * Execute the specified sequence of targets, and the targets
  +     * they depend on.
  +     *
  +     * @param names A vector of target name strings to execute.
  +     *              Must not be <code>null</code>.
  +     *
  +     * @exception BuildException if the build failed.
  +     */
  +    public void executeTargets(Vector names) throws BuildException {
  +        getExecutor().executeTargets(this,
  +            (String[]) (names.toArray(new String[names.size()])));
       }
   
       /**
  
  
  
  1.3       +8 -1      ant/src/main/org/apache/tools/ant/Executor.java
  
  Index: Executor.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Executor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Executor.java	1 Dec 2004 17:52:25 -0000	1.2
  +++ Executor.java	7 Apr 2005 19:31:39 -0000	1.3
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 2004 The Apache Software Foundation
  + * Copyright 2004-2005 The Apache Software Foundation
    *
    *  Licensed under the Apache License, Version 2.0 (the "License");
    *  you may not use this file except in compliance with the License.
  @@ -31,4 +31,11 @@
        */
       void executeTargets(Project project, String[] targetNames)
           throws BuildException;
  +
  +    /**
  +     * Get the appropriate subproject Executor instance.
  +     * @return an Executor instance.
  +     */
  +    Executor getSubProjectExecutor();
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message