implementations. PR: 21421, 29248 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276809 13f79535-47bb-0310-9956-ffa450edef68master
@@ -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 | |||
===================================================== | |||
@@ -229,6 +229,13 @@ And I filtered out the <i>getPropertyHelper</i> access.</p> | |||
<th>valid values /default value</th> | |||
<th>description</th> | |||
</tr> | |||
<tr> | |||
<td><code>ant.executor.class</code></td> | |||
<td>classname; default is org.apache.tools.ant.helper.DefaultExecutor</td> | |||
<td><b>Since Ant 1.6.3</b> Ant will delegate Target invocation to the | |||
org.apache.tools.ant.Executor implementation specified here. | |||
</td> | |||
</tr> | |||
<tr> | |||
<td><code>ant.input.properties</code></td> | |||
<td>filename (required)</td> | |||
@@ -473,4 +480,4 @@ classpath possible, generally just the ant-launcher.jar. | |||
Reserved.</p> | |||
</body> | |||
</html> | |||
</html> |
@@ -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; | |||
} |
@@ -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 <code>ant.executor.class</code> | |||
* 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 <code>ant.executor.class</code> | |||
* 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); | |||
} | |||
} | |||
@@ -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]); | |||
} | |||
} | |||
} |
@@ -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; | |||
} | |||
} | |||
} |
@@ -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)); | |||
} | |||
} |
@@ -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 | |||