Browse Source

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
master
Matthew Jason Benson 21 years ago
parent
commit
284174e86e
8 changed files with 216 additions and 17 deletions
  1. +3
    -0
      WHATSNEW
  2. +8
    -1
      docs/manual/running.html
  3. +34
    -0
      src/main/org/apache/tools/ant/Executor.java
  4. +36
    -11
      src/main/org/apache/tools/ant/Project.java
  5. +40
    -0
      src/main/org/apache/tools/ant/helper/DefaultExecutor.java
  6. +48
    -0
      src/main/org/apache/tools/ant/helper/KeepGoingExecutor.java
  7. +41
    -0
      src/main/org/apache/tools/ant/helper/SingleCheckExecutor.java
  8. +6
    -5
      src/main/org/apache/tools/ant/taskdefs/Ant.java

+ 3
- 0
WHATSNEW View File

@@ -44,6 +44,9 @@ Other changes:
Compilers can be selected using the compiler attribute, which defaults Compilers can be selected using the compiler attribute, which defaults
to "microsoft" on windows, and "mono" on everything else. 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 Changes from Ant 1.6.2 to current Ant 1.6 CVS version
===================================================== =====================================================




+ 8
- 1
docs/manual/running.html View File

@@ -229,6 +229,13 @@ And I filtered out the <i>getPropertyHelper</i> access.</p>
<th>valid values /default value</th> <th>valid values /default value</th>
<th>description</th> <th>description</th>
</tr> </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> <tr>
<td><code>ant.input.properties</code></td> <td><code>ant.input.properties</code></td>
<td>filename (required)</td> <td>filename (required)</td>
@@ -473,4 +480,4 @@ classpath possible, generally just the ant-launcher.jar.
Reserved.</p> Reserved.</p>


</body> </body>
</html>
</html>

+ 34
- 0
src/main/org/apache/tools/ant/Executor.java View File

@@ -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;
}

+ 36
- 11
src/main/org/apache/tools/ant/Project.java View File

@@ -33,6 +33,8 @@ import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
import org.apache.tools.ant.input.DefaultInputHandler; import org.apache.tools.ant.input.DefaultInputHandler;
import org.apache.tools.ant.input.InputHandler; 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.FilterSet;
import org.apache.tools.ant.types.FilterSetCollection; import org.apache.tools.ant.types.FilterSetCollection;
import org.apache.tools.ant.types.Description; 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 * Sets "keep-going" mode. In this mode ANT will try to execute
* as many targets as possible. All targets that do not depend * 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 * @param keepGoingMode "keep-going" mode
* @since Ant 1.6 * @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 * @return "keep-going" mode
* @since Ant 1.6 * @since Ant 1.6
*/ */
@@ -1054,19 +1060,38 @@ public class Project {
*/ */
public void executeTargets(Vector targetNames) throws BuildException { 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 { 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);
} }
} }




+ 40
- 0
src/main/org/apache/tools/ant/helper/DefaultExecutor.java View File

@@ -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]);
}
}

}

+ 48
- 0
src/main/org/apache/tools/ant/helper/KeepGoingExecutor.java View File

@@ -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;
}
}

}

+ 41
- 0
src/main/org/apache/tools/ant/helper/SingleCheckExecutor.java View File

@@ -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));
}

}

+ 6
- 5
src/main/org/apache/tools/ant/taskdefs/Ant.java View File

@@ -36,6 +36,7 @@ import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.ProjectHelper; import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.Target; import org.apache.tools.ant.Target;
import org.apache.tools.ant.Task; 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.types.PropertySet;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;


@@ -62,6 +63,9 @@ import org.apache.tools.ant.util.FileUtils;
*/ */
public class Ant extends Task { public class Ant extends Task {


/** Target Executor */
private static SingleCheckExecutor executor = new SingleCheckExecutor();

/** the basedir where is executed the build file */ /** the basedir where is executed the build file */
private File dir = null; private File dir = null;


@@ -394,11 +398,8 @@ public class Ant extends Task {
try { try {
log("Entering " + antFile + "...", Project.MSG_VERBOSE); log("Entering " + antFile + "...", Project.MSG_VERBOSE);
newProject.fireSubBuildStarted(); 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) { } catch (BuildException ex) {
t = ProjectHelper t = ProjectHelper


Loading…
Cancel
Save