From 284174e86e92dbaeb24202065bcc92157100989d Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Tue, 31 Aug 2004 22:32:53 +0000 Subject: [PATCH] Refactored Target invocation into org.apache.tools.ant.Executor implementations. PR: 21421, 29248 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276809 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 ++ docs/manual/running.html | 9 +++- src/main/org/apache/tools/ant/Executor.java | 34 +++++++++++++ src/main/org/apache/tools/ant/Project.java | 47 +++++++++++++----- .../tools/ant/helper/DefaultExecutor.java | 40 ++++++++++++++++ .../tools/ant/helper/KeepGoingExecutor.java | 48 +++++++++++++++++++ .../tools/ant/helper/SingleCheckExecutor.java | 41 ++++++++++++++++ .../org/apache/tools/ant/taskdefs/Ant.java | 11 +++-- 8 files changed, 216 insertions(+), 17 deletions(-) create mode 100755 src/main/org/apache/tools/ant/Executor.java create mode 100755 src/main/org/apache/tools/ant/helper/DefaultExecutor.java create mode 100755 src/main/org/apache/tools/ant/helper/KeepGoingExecutor.java create mode 100755 src/main/org/apache/tools/ant/helper/SingleCheckExecutor.java diff --git a/WHATSNEW b/WHATSNEW index b804e9ec5..10de3d127 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -44,6 +44,9 @@ Other changes: Compilers can be selected using the compiler attribute, which defaults to "microsoft" on windows, and "mono" on everything else. +* Refactored Target invocation into org.apache.tools.ant.Executor + implementations. Bugzilla Reports 21421, 29248. + Changes from Ant 1.6.2 to current Ant 1.6 CVS version ===================================================== diff --git a/docs/manual/running.html b/docs/manual/running.html index 72be279f9..7016d5d5e 100644 --- a/docs/manual/running.html +++ b/docs/manual/running.html @@ -229,6 +229,13 @@ And I filtered out the getPropertyHelper access.

valid values /default value description + + ant.executor.class + classname; default is org.apache.tools.ant.helper.DefaultExecutor + Since Ant 1.6.3 Ant will delegate Target invocation to the +org.apache.tools.ant.Executor implementation specified here. + + ant.input.properties filename (required) @@ -473,4 +480,4 @@ classpath possible, generally just the ant-launcher.jar. Reserved.

- \ No newline at end of file + diff --git a/src/main/org/apache/tools/ant/Executor.java b/src/main/org/apache/tools/ant/Executor.java new file mode 100755 index 000000000..00e338aaa --- /dev/null +++ b/src/main/org/apache/tools/ant/Executor.java @@ -0,0 +1,34 @@ +/* + * Copyright 2004 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; + +/** + * Target executor abstraction. + * @since Ant 1.6.3 + */ +public interface Executor { + + /** + * Execute the specified Targets for the specified Project. + * @param project the Ant Project. + * @param targetNames String[] of Target names. + * @throws BuildException. + */ + void executeTargets(Project project, String[] targetNames) + throws BuildException; +} diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index 0a337939b..2d8b4a459 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -33,6 +33,8 @@ import java.util.Set; import java.util.HashSet; 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; @@ -764,7 +766,9 @@ public class Project { /** * Sets "keep-going" mode. In this mode ANT will try to execute * as many targets as possible. All targets that do not depend - * on failed target(s) will be executed. + * on failed target(s) will be executed. If the keepGoing settor/getter + * methods are used in conjunction with the ant.executor.class + * property, they will have no effect. * @param keepGoingMode "keep-going" mode * @since Ant 1.6 */ @@ -773,7 +777,9 @@ public class Project { } /** - * Returns the keep-going mode. + * Returns the keep-going mode. If the keepGoing settor/getter + * methods are used in conjunction with the ant.executor.class + * property, they will have no effect. * @return "keep-going" mode * @since Ant 1.6 */ @@ -1054,19 +1060,38 @@ public class Project { */ public void executeTargets(Vector targetNames) throws BuildException { - BuildException thrownException = null; - for (int i = 0; i < targetNames.size(); i++) { + 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(); + } + log("Attempting to create object of type " + classname, MSG_DEBUG); try { - executeTarget((String) targetNames.elementAt(i)); - } catch (BuildException ex) { - if (!(keepGoingMode)) { - throw ex; // Throw further + o = Class.forName(classname, true, coreLoader).newInstance(); + } catch (ClassNotFoundException seaEnEfEx) { + //try the current classloader + try { + o = Class.forName(classname).newInstance(); + } catch (Exception ex) { + log(ex.toString(), MSG_ERR); } - thrownException = ex; + } catch (Exception ex) { + log(ex.toString(), MSG_ERR); + } + if (o != null) { + addReference("ant.executor", o); } } - if (thrownException != null) { - throw thrownException; + + 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); } } diff --git a/src/main/org/apache/tools/ant/helper/DefaultExecutor.java b/src/main/org/apache/tools/ant/helper/DefaultExecutor.java new file mode 100755 index 000000000..39911459e --- /dev/null +++ b/src/main/org/apache/tools/ant/helper/DefaultExecutor.java @@ -0,0 +1,40 @@ +/* + * Copyright 2004 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.helper; + + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Executor; +import org.apache.tools.ant.BuildException; + + +/** + * Default Target executor implementation. + * @since Ant 1.6.3 + */ +public class DefaultExecutor implements Executor { + + //inherit doc + public void executeTargets(Project project, String[] targetNames) + throws BuildException { + for (int i = 0; i < targetNames.length; i++) { + project.executeTarget(targetNames[i]); + } + } + +} diff --git a/src/main/org/apache/tools/ant/helper/KeepGoingExecutor.java b/src/main/org/apache/tools/ant/helper/KeepGoingExecutor.java new file mode 100755 index 000000000..41e608955 --- /dev/null +++ b/src/main/org/apache/tools/ant/helper/KeepGoingExecutor.java @@ -0,0 +1,48 @@ +/* + * Copyright 2004 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.helper; + + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Executor; +import org.apache.tools.ant.BuildException; + + +/** + * "Keep-going" Target executor implementation. + * @since Ant 1.6.3 + */ +public class KeepGoingExecutor implements Executor { + + //inherit doc + public void executeTargets(Project project, String[] targetNames) + throws BuildException { + BuildException thrownException = null; + for (int i = 0; i < targetNames.length; i++) { + try { + project.executeTarget(targetNames[i]); + } catch (BuildException ex) { + thrownException = ex; + } + } + if (thrownException != null) { + throw thrownException; + } + } + +} diff --git a/src/main/org/apache/tools/ant/helper/SingleCheckExecutor.java b/src/main/org/apache/tools/ant/helper/SingleCheckExecutor.java new file mode 100755 index 000000000..435a4b433 --- /dev/null +++ b/src/main/org/apache/tools/ant/helper/SingleCheckExecutor.java @@ -0,0 +1,41 @@ +/* + * Copyright 2004 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.helper; + + +import java.util.Vector; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Executor; +import org.apache.tools.ant.BuildException; + + +/** + * "Single-check" Target executor implementation. + * @since Ant 1.6.3 + */ +public class SingleCheckExecutor implements Executor { + + //inherit doc + public void executeTargets(Project project, String[] targetNames) + throws BuildException { + project.executeSortedTargets( + project.topoSort(targetNames, project.getTargets(), false)); + } + +} diff --git a/src/main/org/apache/tools/ant/taskdefs/Ant.java b/src/main/org/apache/tools/ant/taskdefs/Ant.java index 0bc0b7af5..bf9624857 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Ant.java +++ b/src/main/org/apache/tools/ant/taskdefs/Ant.java @@ -36,6 +36,7 @@ import org.apache.tools.ant.ProjectComponent; import org.apache.tools.ant.ProjectHelper; import org.apache.tools.ant.Target; import org.apache.tools.ant.Task; +import org.apache.tools.ant.helper.SingleCheckExecutor; import org.apache.tools.ant.types.PropertySet; import org.apache.tools.ant.util.FileUtils; @@ -62,6 +63,9 @@ import org.apache.tools.ant.util.FileUtils; */ public class Ant extends Task { + /** Target Executor */ + private static SingleCheckExecutor executor = new SingleCheckExecutor(); + /** the basedir where is executed the build file */ private File dir = null; @@ -394,11 +398,8 @@ public class Ant extends Task { try { log("Entering " + antFile + "...", Project.MSG_VERBOSE); newProject.fireSubBuildStarted(); - String[] nameArray = - (String[])(locals.toArray(new String[locals.size()])); - - newProject.executeSortedTargets(newProject.topoSort( - nameArray, newProject.getTargets(), false)); + executor.executeTargets(newProject, + (String[])(locals.toArray(new String[locals.size()]))); } catch (BuildException ex) { t = ProjectHelper