Browse Source

Close PrintStreams if logfile is being used. Leaving the streams open causes test case failures on Windows.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272300 13f79535-47bb-0310-9956-ffa450edef68
master
Magesh Umasankar 23 years ago
parent
commit
8edaa455e6
3 changed files with 129 additions and 92 deletions
  1. +3
    -0
      WHATSNEW
  2. +91
    -67
      src/main/org/apache/tools/ant/Main.java
  3. +35
    -25
      src/main/org/apache/tools/ant/taskdefs/Ant.java

+ 3
- 0
WHATSNEW View File

@@ -52,6 +52,9 @@ Changes that could break older environments:


Fixed bugs: Fixed bugs:
----------- -----------
* A bug existed that prevented generated log files from being deleted as
part of the build process itself. This has now been fixed.

* Fixed bug where <move> ignored <filterset>s. * Fixed bug where <move> ignored <filterset>s.


* Ant works properly with the combination of Java1.4/WindowsXP. * Ant works properly with the combination of Java1.4/WindowsXP.


+ 91
- 67
src/main/org/apache/tools/ant/Main.java View File

@@ -88,10 +88,10 @@ public class Main {
private File buildFile; /* null */ private File buildFile; /* null */


/** Stream to use for logging. */ /** Stream to use for logging. */
private PrintStream out = System.out;
private static PrintStream out = System.out;


/** Stream that we are using for logging error messages. */ /** Stream that we are using for logging error messages. */
private PrintStream err = System.err;
private static PrintStream err = System.err;


/** The build targets. */ /** The build targets. */
private Vector targets = new Vector(5); private Vector targets = new Vector(5);
@@ -101,13 +101,13 @@ public class Main {


/** Names of classes to add as listeners to project. */ /** Names of classes to add as listeners to project. */
private Vector listeners = new Vector(5); private Vector listeners = new Vector(5);
/** File names of property files to load on startup. */ /** File names of property files to load on startup. */
private Vector propertyFiles = new Vector(5); private Vector propertyFiles = new Vector(5);
/** /**
* The Ant logger class. There may be only one logger. It will have
* the right to use the 'out' PrintStream. The class must implements the
* The Ant logger class. There may be only one logger. It will have
* the right to use the 'out' PrintStream. The class must implements the
* BuildLogger interface. * BuildLogger interface.
*/ */
private String loggerClassname = null; private String loggerClassname = null;
@@ -124,15 +124,21 @@ public class Main {
private boolean readyToRun = false; private boolean readyToRun = false;


/** /**
* Whether or not we should only parse and display the project help
* Whether or not we should only parse and display the project help
* information. * information.
*/ */
private boolean projectHelp = false; private boolean projectHelp = false;


/** /**
* Prints the message of the Throwable if it (the message) is not
* Is a logfile being used? This is used to
* check if the output streams must be closed.
*/
private static boolean isLogFileUsed = false;

/**
* Prints the message of the Throwable if it (the message) is not
* <code>null</code>. * <code>null</code>.
*
*
* @param t Throwable to print the message of. * @param t Throwable to print the message of.
* Must not be <code>null</code>. * Must not be <code>null</code>.
*/ */
@@ -147,12 +153,12 @@ public class Main {
* Creates a new instance of this class using the * Creates a new instance of this class using the
* arguments specified, gives it any extra user properties which have been * arguments specified, gives it any extra user properties which have been
* specified, and then runs the build using the classloader provided. * specified, and then runs the build using the classloader provided.
*
*
* @param args Command line arguments. Must not be <code>null</code>. * @param args Command line arguments. Must not be <code>null</code>.
* @param additionalUserProperties Any extra properties to use in this
* build. May be <code>null</code>, which is the equivalent to
* @param additionalUserProperties Any extra properties to use in this
* build. May be <code>null</code>, which is the equivalent to
* passing in an empty set of properties. * passing in an empty set of properties.
* @param coreLoader Classloader used for core classes. May be
* @param coreLoader Classloader used for core classes. May be
* <code>null</code> in which case the system classloader is used. * <code>null</code> in which case the system classloader is used.
*/ */
public static void start(String[] args, Properties additionalUserProperties, public static void start(String[] args, Properties additionalUserProperties,
@@ -167,14 +173,14 @@ public class Main {
} }


if (additionalUserProperties != null) { if (additionalUserProperties != null) {
for (Enumeration e = additionalUserProperties.keys();
for (Enumeration e = additionalUserProperties.keys();
e.hasMoreElements(); ) { e.hasMoreElements(); ) {
String key = (String) e.nextElement(); String key = (String) e.nextElement();
String property = additionalUserProperties.getProperty(key); String property = additionalUserProperties.getProperty(key);
m.definedProps.put(key, property); m.definedProps.put(key, property);
} }
} }
try { try {
m.runBuild(coreLoader); m.runBuild(coreLoader);
System.exit(0); System.exit(0);
@@ -187,9 +193,26 @@ public class Main {
exc.printStackTrace(); exc.printStackTrace();
printMessage(exc); printMessage(exc);
System.exit(1); System.exit(1);
} finally {
if (isLogFileUsed) {
if (out != null) {
try {
out.close();
} catch (final Exception e) {
//ignore
}
}
if (err != null) {
try {
err.close();
} catch (final Exception e) {
//ignore
}
}
}
} }
} }
/** /**
* Command line entry point. This method kicks off the building * Command line entry point. This method kicks off the building
* of a project object and executes a build using either a given * of a project object and executes a build using either a given
@@ -206,11 +229,11 @@ public class Main {
// BuildException is thrown. What's the rationale for when to do // BuildException is thrown. What's the rationale for when to do
// what? // what?
/** /**
* Sole constructor, which parses and deals with command line
* Sole constructor, which parses and deals with command line
* arguments. * arguments.
*
*
* @param args Command line arguments. Must not be <code>null</code>. * @param args Command line arguments. Must not be <code>null</code>.
*
*
* @exception BuildException if the specified build file doesn't exist * @exception BuildException if the specified build file doesn't exist
* or is a directory. * or is a directory.
*/ */
@@ -245,9 +268,10 @@ public class Main {
err = out; err = out;
System.setOut(out); System.setOut(out);
System.setErr(out); System.setErr(out);
isLogFileUsed = true;
} catch (IOException ioe) { } catch (IOException ioe) {
String msg = "Cannot write on the specified log file. "
+ "Make sure the path exists and you have write "
String msg = "Cannot write on the specified log file. "
+ "Make sure the path exists and you have write "
+ "permissions."; + "permissions.";
System.out.println(msg); System.out.println(msg);
return; return;
@@ -257,7 +281,7 @@ public class Main {
System.out.println(msg); System.out.println(msg);
return; return;
} }
} else if (arg.equals("-buildfile") || arg.equals("-file")
} else if (arg.equals("-buildfile") || arg.equals("-file")
|| arg.equals("-f")) { || arg.equals("-f")) {
try { try {
buildFile = new File(args[i + 1]); buildFile = new File(args[i + 1]);
@@ -304,13 +328,13 @@ public class Main {
definedProps.put(name, value); definedProps.put(name, value);
} else if (arg.equals("-logger")) { } else if (arg.equals("-logger")) {
if (loggerClassname != null) { if (loggerClassname != null) {
System.out.println("Only one logger class may "
System.out.println("Only one logger class may "
+ " be specified."); + " be specified.");
return; return;
} }
try { try {
loggerClassname = args[++i]; loggerClassname = args[++i];
}
}
catch (ArrayIndexOutOfBoundsException aioobe) { catch (ArrayIndexOutOfBoundsException aioobe) {
System.out.println("You must specify a classname when " + System.out.println("You must specify a classname when " +
"using the -logger argument"); "using the -logger argument");
@@ -349,12 +373,12 @@ public class Main {
targets.addElement(arg); targets.addElement(arg);
} }
} }
// if buildFile was not specified on the command line, // if buildFile was not specified on the command line,
if (buildFile == null) { if (buildFile == null) {
// but -find then search for it // but -find then search for it
if (searchForThis != null) { if (searchForThis != null) {
buildFile = findBuildFile(System.getProperty("user.dir"),
buildFile = findBuildFile(System.getProperty("user.dir"),
searchForThis); searchForThis);
} else { } else {
buildFile = new File(DEFAULT_BUILD_FILENAME); buildFile = new File(DEFAULT_BUILD_FILENAME);
@@ -379,7 +403,7 @@ public class Main {
for (int propertyFileIndex = 0; for (int propertyFileIndex = 0;
propertyFileIndex < propertyFiles.size(); propertyFileIndex < propertyFiles.size();
propertyFileIndex++) { propertyFileIndex++) {
String filename
String filename
= (String) propertyFiles.elementAt(propertyFileIndex); = (String) propertyFiles.elementAt(propertyFileIndex);
Properties props = new Properties(); Properties props = new Properties();
FileInputStream fis = null; FileInputStream fis = null;
@@ -398,7 +422,7 @@ public class Main {
} }
} }
} }
// ensure that -D properties take precedence // ensure that -D properties take precedence
Enumeration propertyNames = props.propertyNames(); Enumeration propertyNames = props.propertyNames();
while (propertyNames.hasMoreElements()) { while (propertyNames.hasMoreElements()) {
@@ -444,12 +468,12 @@ public class Main {
* Must not be <code>null</code>. * Must not be <code>null</code>.
* @param suffix Suffix filename to look for in parents. * @param suffix Suffix filename to look for in parents.
* Must not be <code>null</code>. * Must not be <code>null</code>.
*
*
* @return A handle to the build file if one is found * @return A handle to the build file if one is found
* *
* @exception BuildException if no build file is found * @exception BuildException if no build file is found
*/ */
private File findBuildFile(String start, String suffix)
private File findBuildFile(String start, String suffix)
throws BuildException { throws BuildException {
if (msgOutputLevel >= Project.MSG_INFO) { if (msgOutputLevel >= Project.MSG_INFO) {
System.out.println("Searching for " + suffix + " ..."); System.out.println("Searching for " + suffix + " ...");
@@ -457,22 +481,22 @@ public class Main {


File parent = new File(new File(start).getAbsolutePath()); File parent = new File(new File(start).getAbsolutePath());
File file = new File(parent, suffix); File file = new File(parent, suffix);
// check if the target file exists in the current directory // check if the target file exists in the current directory
while (!file.exists()) { while (!file.exists()) {
// change to parent directory // change to parent directory
parent = getParentFile(parent); parent = getParentFile(parent);
// if parent is null, then we are at the root of the fs, // if parent is null, then we are at the root of the fs,
// complain that we can't find the build file. // complain that we can't find the build file.
if (parent == null) { if (parent == null) {
throw new BuildException("Could not locate a build file!"); throw new BuildException("Could not locate a build file!");
} }
// refresh our file handle // refresh our file handle
file = new File(parent, suffix); file = new File(parent, suffix);
} }
return file; return file;
} }


@@ -480,11 +504,11 @@ public class Main {
* Executes the build. If the constructor for this instance failed * Executes the build. If the constructor for this instance failed
* (e.g. returned after issuing a warning), this method returns * (e.g. returned after issuing a warning), this method returns
* immediately. * immediately.
*
*
* @param coreLoader The classloader to use to find core classes. * @param coreLoader The classloader to use to find core classes.
* May be <code>null</code>, in which case the * May be <code>null</code>, in which case the
* system classloader is used. * system classloader is used.
*
*
* @exception BuildException if the build fails * @exception BuildException if the build fails
*/ */
private void runBuild(ClassLoader coreLoader) throws BuildException { private void runBuild(ClassLoader coreLoader) throws BuildException {
@@ -517,7 +541,7 @@ public class Main {
!Project.JAVA_1_1.equals(Project.getJavaVersion()) ){ !Project.JAVA_1_1.equals(Project.getJavaVersion()) ){
oldsm = System.getSecurityManager(); oldsm = System.getSecurityManager();


//SecurityManager can not be installed here for backwards
//SecurityManager can not be installed here for backwards
//compatability reasons (PD). Needs to be loaded prior to //compatability reasons (PD). Needs to be loaded prior to
//ant class if we are going to implement it. //ant class if we are going to implement it.
//System.setSecurityManager(new NoExitSecurityManager()); //System.setSecurityManager(new NoExitSecurityManager());
@@ -539,14 +563,14 @@ public class Main {
String value = (String)definedProps.get(arg); String value = (String)definedProps.get(arg);
project.setUserProperty(arg, value); project.setUserProperty(arg, value);
} }
project.setUserProperty("ant.file",
project.setUserProperty("ant.file",
buildFile.getAbsolutePath() ); buildFile.getAbsolutePath() );
// first use the ProjectHelper to create the project object // first use the ProjectHelper to create the project object
// from the given build file. // from the given build file.
String noParserMessage = "No JAXP compliant XML parser found. " String noParserMessage = "No JAXP compliant XML parser found. "
+ "Please visit http://xml.apache.org "
+ "Please visit http://xml.apache.org "
+ "for a suitable parser"; + "for a suitable parser";
try { try {
Class.forName("javax.xml.parsers.SAXParserFactory"); Class.forName("javax.xml.parsers.SAXParserFactory");
@@ -564,12 +588,12 @@ public class Main {
printTargets(project, msgOutputLevel > Project.MSG_INFO ); printTargets(project, msgOutputLevel > Project.MSG_INFO );
return; return;
} }
// make sure that we have a target to execute // make sure that we have a target to execute
if (targets.size() == 0) { if (targets.size() == 0) {
targets.addElement(project.getDefaultTarget()); targets.addElement(project.getDefaultTarget());
} }
project.executeTargets(targets); project.executeTargets(targets);
} }
finally { finally {
@@ -601,7 +625,7 @@ public class Main {
/** /**
* Adds the listeners specified in the command line arguments, * Adds the listeners specified in the command line arguments,
* along with the default listener, to the specified project. * along with the default listener, to the specified project.
*
*
* @param project The project to add listeners to. * @param project The project to add listeners to.
* Must not be <code>null</code>. * Must not be <code>null</code>.
*/ */
@@ -618,18 +642,18 @@ public class Main {
project.addBuildListener(listener); project.addBuildListener(listener);
} }
catch (Throwable exc) { catch (Throwable exc) {
throw new BuildException("Unable to instantiate listener "
throw new BuildException("Unable to instantiate listener "
+ className, exc); + className, exc);
} }
} }
} }


// XXX: (Jon Skeet) Any reason for writing a message and then using a bare
// XXX: (Jon Skeet) Any reason for writing a message and then using a bare
// RuntimeException rather than just using a BuildException here? Is it // RuntimeException rather than just using a BuildException here? Is it
// in case the message could end up being written to no loggers (as the
// in case the message could end up being written to no loggers (as the
// loggers could have failed to be created due to this failure)? // loggers could have failed to be created due to this failure)?
/** /**
* Creates the default build logger for sending build events to the ant
* Creates the default build logger for sending build events to the ant
* log. * log.
* *
* @return the logger instance for this build. * @return the logger instance for this build.
@@ -641,13 +665,13 @@ public class Main {
logger = (BuildLogger)(Class.forName(loggerClassname).newInstance()); logger = (BuildLogger)(Class.forName(loggerClassname).newInstance());
} }
catch (ClassCastException e) { catch (ClassCastException e) {
System.err.println("The specified logger class "
+ loggerClassname
System.err.println("The specified logger class "
+ loggerClassname
+ " does not implement the BuildLogger interface"); + " does not implement the BuildLogger interface");
throw new RuntimeException(); throw new RuntimeException();
} }
catch (Exception e) { catch (Exception e) {
System.err.println("Unable to instantiate specified logger "
System.err.println("Unable to instantiate specified logger "
+ "class " + loggerClassname + " : " + e.getClass().getName()); + "class " + loggerClassname + " : " + e.getClass().getName());
throw new RuntimeException(); throw new RuntimeException();
} }
@@ -693,7 +717,7 @@ public class Main {


/** /**
* Prints the Ant version information to <code>System.out</code>. * Prints the Ant version information to <code>System.out</code>.
*
*
* @exception BuildException if the version information is unavailable * @exception BuildException if the version information is unavailable
*/ */
private static void printVersion() throws BuildException { private static void printVersion() throws BuildException {
@@ -709,10 +733,10 @@ public class Main {
* Returns the Ant version information, if available. Once the information * Returns the Ant version information, if available. Once the information
* has been loaded once, it's cached and returned from the cache on future * has been loaded once, it's cached and returned from the cache on future
* calls. * calls.
*
* @return the Ant version information as a String
*
* @return the Ant version information as a String
* (always non-<code>null</code>) * (always non-<code>null</code>)
*
*
* @exception BuildException if the version information is unavailable * @exception BuildException if the version information is unavailable
*/ */
public static synchronized String getAntVersion() throws BuildException { public static synchronized String getAntVersion() throws BuildException {
@@ -723,7 +747,7 @@ public class Main {
Main.class.getResourceAsStream("/org/apache/tools/ant/version.txt"); Main.class.getResourceAsStream("/org/apache/tools/ant/version.txt");
props.load(in); props.load(in);
in.close(); in.close();
String lSep = System.getProperty("line.separator"); String lSep = System.getProperty("line.separator");
StringBuffer msg = new StringBuffer(); StringBuffer msg = new StringBuffer();
msg.append("Apache Ant version "); msg.append("Apache Ant version ");
@@ -742,9 +766,9 @@ public class Main {
} }


/** /**
* Prints the description of a project (if there is one) to
* Prints the description of a project (if there is one) to
* <code>System.out</code>. * <code>System.out</code>.
*
*
* @param project The project to display a description of. * @param project The project to display a description of.
* Must not be <code>null</code>. * Must not be <code>null</code>.
*/ */
@@ -755,9 +779,9 @@ public class Main {
} }


/** /**
* Prints a list of all targets in the specified project to
* Prints a list of all targets in the specified project to
* <code>System.out</code>, optionally including subtargets. * <code>System.out</code>, optionally including subtargets.
*
*
* @param project The project to display a description of. * @param project The project to display a description of.
* Must not be <code>null</code>. * Must not be <code>null</code>.
* @param printSubTargets Whether or not subtarget names should also be * @param printSubTargets Whether or not subtarget names should also be
@@ -795,13 +819,13 @@ public class Main {
} }


printTargets(topNames, topDescriptions, "Main targets:", maxLength); printTargets(topNames, topDescriptions, "Main targets:", maxLength);
if (printSubTargets) { if (printSubTargets) {
printTargets(subNames, null, "Subtargets:", 0); printTargets(subNames, null, "Subtargets:", 0);
} }


String defaultTarget = project.getDefaultTarget(); String defaultTarget = project.getDefaultTarget();
if (defaultTarget != null && !"".equals(defaultTarget)) {
if (defaultTarget != null && !"".equals(defaultTarget)) {
// shouldn't need to check but... // shouldn't need to check but...
System.out.println( "Default target: " + defaultTarget); System.out.println( "Default target: " + defaultTarget);
} }
@@ -810,11 +834,11 @@ public class Main {
/** /**
* Searches for the correct place to insert a name into a list so as * Searches for the correct place to insert a name into a list so as
* to keep the list sorted alphabetically. * to keep the list sorted alphabetically.
*
*
* @param names The current list of names. Must not be <code>null</code>. * @param names The current list of names. Must not be <code>null</code>.
* @param name The name to find a place for. * @param name The name to find a place for.
* Must not be <code>null</code>. * Must not be <code>null</code>.
*
*
* @return the correct place in the list for the given name * @return the correct place in the list for the given name
*/ */
private static int findTargetPosition(Vector names, String name) { private static int findTargetPosition(Vector names, String name) {
@@ -835,17 +859,17 @@ public class Main {
* Must not be <code>null</code>. * Must not be <code>null</code>.
* @param descriptions The associated target descriptions. * @param descriptions The associated target descriptions.
* May be <code>null</code>, in which case * May be <code>null</code>, in which case
* no descriptions are displayed.
* no descriptions are displayed.
* If non-<code>null</code>, this should have * If non-<code>null</code>, this should have
* as many elements as <code>names</code>. * as many elements as <code>names</code>.
* @param heading The heading to display.
* @param heading The heading to display.
* Should not be <code>null</code>. * Should not be <code>null</code>.
* @param maxlen The maximum length of the names of the targets. * @param maxlen The maximum length of the names of the targets.
* If descriptions are given, they are padded to this * If descriptions are given, they are padded to this
* position so they line up (so long as the names really * position so they line up (so long as the names really
* <i>are</i> shorter than this). * <i>are</i> shorter than this).
*/ */
private static void printTargets(Vector names, Vector descriptions,
private static void printTargets(Vector names, Vector descriptions,
String heading, int maxlen) { String heading, int maxlen) {
// now, start printing the targets and their descriptions // now, start printing the targets and their descriptions
String lSep = System.getProperty("line.separator"); String lSep = System.getProperty("line.separator");


+ 35
- 25
src/main/org/apache/tools/ant/taskdefs/Ant.java View File

@@ -96,31 +96,34 @@ public class Ant extends Task {


/** the basedir where is executed the build file */ /** the basedir where is executed the build file */
private File dir = null; private File dir = null;
/** the build.xml file (can be absolute) in this case dir will be ignored */ /** the build.xml file (can be absolute) in this case dir will be ignored */
private String antFile = null; private String antFile = null;
/** the target to call if any */ /** the target to call if any */
private String target = null; private String target = null;
/** the output */ /** the output */
private String output = null; private String output = null;
/** should we inherit properties from the parent ? */ /** should we inherit properties from the parent ? */
private boolean inheritAll = true; private boolean inheritAll = true;
/** should we inherit references from the parent ? */ /** should we inherit references from the parent ? */
private boolean inheritRefs = false; private boolean inheritRefs = false;
/** the properties to pass to the new project */ /** the properties to pass to the new project */
private Vector properties = new Vector(); private Vector properties = new Vector();
/** the references to pass to the new project */ /** the references to pass to the new project */
private Vector references = new Vector(); private Vector references = new Vector();


/** the temporary project created to run the build file */ /** the temporary project created to run the build file */
private Project newProject; private Project newProject;


/** The stream to which output is to be written. */
private PrintStream out = null;

/** /**
* If true, inherit all properties from parent Project * If true, inherit all properties from parent Project
* If false, inherit only userProperties and those defined * If false, inherit only userProperties and those defined
@@ -142,7 +145,7 @@ public class Ant extends Task {
public void init() { public void init() {
newProject = new Project(); newProject = new Project();
newProject.setJavaVersionProperty(); newProject.setJavaVersionProperty();
newProject.addTaskDefinition("property",
newProject.addTaskDefinition("property",
(Class)project.getTaskDefinitions().get("property")); (Class)project.getTaskDefinitions().get("property"));
} }


@@ -158,7 +161,7 @@ public class Ant extends Task {
} }
if (p.getFile() != null) { if (p.getFile() != null) {
newP.setFile(p.getFile()); newP.setFile(p.getFile());
}
}
if (p.getResource() != null) { if (p.getResource() != null) {
newP.setResource(p.getResource()); newP.setResource(p.getResource());
} }
@@ -181,7 +184,7 @@ public class Ant extends Task {
outfile = getProject().resolveFile(output); outfile = getProject().resolveFile(output);
} }
try { try {
PrintStream out = new PrintStream(new FileOutputStream(outfile));
out = new PrintStream(new FileOutputStream(outfile));
DefaultLogger logger = new DefaultLogger(); DefaultLogger logger = new DefaultLogger();
logger.setMessageOutputLevel(Project.MSG_INFO); logger.setMessageOutputLevel(Project.MSG_INFO);
logger.setOutputPrintStream(out); logger.setOutputPrintStream(out);
@@ -224,7 +227,7 @@ public class Ant extends Task {
// b/c we won't inherit them. // b/c we won't inherit them.
newProject.setSystemProperties(); newProject.setSystemProperties();
} }
e = prop1.keys(); e = prop1.keys();
while (e.hasMoreElements()) { while (e.hasMoreElements()) {
String arg = (String) e.nextElement(); String arg = (String) e.nextElement();
@@ -232,7 +235,7 @@ public class Ant extends Task {
// basedir and ant.file get special treatment in execute() // basedir and ant.file get special treatment in execute()
continue; continue;
} }
String value = (String) prop1.get(arg); String value = (String) prop1.get(arg);
if (inheritAll){ if (inheritAll){
newProject.setProperty(arg, value); newProject.setProperty(arg, value);
@@ -249,7 +252,7 @@ public class Ant extends Task {
super.handleOutput(line); super.handleOutput(line);
} }
} }
protected void handleErrorOutput(String line) { protected void handleErrorOutput(String line) {
if (newProject != null) { if (newProject != null) {
newProject.demuxOutput(line, true); newProject.demuxOutput(line, true);
@@ -257,7 +260,7 @@ public class Ant extends Task {
super.handleErrorOutput(line); super.handleErrorOutput(line);
} }
} }
/** /**
* Do the execution. * Do the execution.
*/ */
@@ -266,7 +269,7 @@ public class Ant extends Task {
if (newProject == null) { if (newProject == null) {
reinit(); reinit();
} }
if ( (dir == null) && (inheritAll) ) { if ( (dir == null) && (inheritAll) ) {
dir = project.getBaseDir(); dir = project.getBaseDir();
} }
@@ -289,13 +292,13 @@ public class Ant extends Task {
File file = FileUtils.newFileUtils().resolveFile(dir, antFile); File file = FileUtils.newFileUtils().resolveFile(dir, antFile);
antFile = file.getAbsolutePath(); antFile = file.getAbsolutePath();


log("calling target "+(target!=null?target:"[default]") log("calling target "+(target!=null?target:"[default]")
+ " in build file "+ antFile.toString(), + " in build file "+ antFile.toString(),
Project.MSG_VERBOSE); Project.MSG_VERBOSE);
newProject.setUserProperty( "ant.file" , antFile ); newProject.setUserProperty( "ant.file" , antFile );
ProjectHelper.configureProject(newProject, new File(antFile)); ProjectHelper.configureProject(newProject, new File(antFile));
if (target == null) { if (target == null) {
target = newProject.getDefaultTarget(); target = newProject.getDefaultTarget();
} }
@@ -306,7 +309,7 @@ public class Ant extends Task {
if (newProject.getBaseDir().equals(project.getBaseDir()) && if (newProject.getBaseDir().equals(project.getBaseDir()) &&
newProject.getProperty("ant.file").equals(project.getProperty("ant.file")) && newProject.getProperty("ant.file").equals(project.getProperty("ant.file")) &&
getOwningTarget() != null && getOwningTarget() != null &&
target.equals(this.getOwningTarget().getName())) {
target.equals(this.getOwningTarget().getName())) {


throw new BuildException("ant task calling its own parent target"); throw new BuildException("ant task calling its own parent target");
} }
@@ -315,6 +318,13 @@ public class Ant extends Task {
} finally { } finally {
// help the gc // help the gc
newProject = null; newProject = null;
if (output != null && out != null) {
try {
out.close();
} catch (final Exception e) {
//ignore
}
}
} }
} }


@@ -350,7 +360,7 @@ public class Ant extends Task {
} }
if (!thisReferences.containsKey(refid)) { if (!thisReferences.containsKey(refid)) {
log("Parent project doesn't contain any reference '" log("Parent project doesn't contain any reference '"
+ refid + "'",
+ refid + "'",
Project.MSG_WARN); Project.MSG_WARN);
continue; continue;
} }
@@ -397,13 +407,13 @@ public class Ant extends Task {
} catch (Exception e) { } catch (Exception e) {
// not Clonable // not Clonable
} }


if (copy instanceof ProjectComponent) { if (copy instanceof ProjectComponent) {
((ProjectComponent) copy).setProject(newProject); ((ProjectComponent) copy).setProject(newProject);
} else { } else {
try { try {
Method setProjectM =
Method setProjectM =
c.getMethod( "setProject", new Class[] {Project.class}); c.getMethod( "setProject", new Class[] {Project.class});
if(setProjectM != null) { if(setProjectM != null) {
setProjectM.invoke(copy, new Object[] {newProject}); setProjectM.invoke(copy, new Object[] {newProject});
@@ -413,7 +423,7 @@ public class Ant extends Task {
// a set project method. // a set project method.
} catch(Exception e2) { } catch(Exception e2) {
String msg = "Error setting new project instance for reference with id " String msg = "Error setting new project instance for reference with id "
+ oldKey;
+ oldKey;
throw new BuildException(msg, e2, location); throw new BuildException(msg, e2, location);
} }
} }
@@ -463,7 +473,7 @@ public class Ant extends Task {
return p; return p;
} }


/**
/**
* create a reference element that identifies a data type that * create a reference element that identifies a data type that
* should be carried over to the new project. * should be carried over to the new project.
*/ */
@@ -475,11 +485,11 @@ public class Ant extends Task {
* Helper class that implements the nested &lt;reference&gt; * Helper class that implements the nested &lt;reference&gt;
* element of &lt;ant&gt; and &lt;antcall&gt;. * element of &lt;ant&gt; and &lt;antcall&gt;.
*/ */
public static class Reference
public static class Reference
extends org.apache.tools.ant.types.Reference { extends org.apache.tools.ant.types.Reference {


public Reference() {super();} public Reference() {super();}
private String targetid=null; private String targetid=null;
public void setToRefid(String targetid) { this.targetid=targetid; } public void setToRefid(String targetid) { this.targetid=targetid; }
public String getToRefid() { return targetid; } public String getToRefid() { return targetid; }


Loading…
Cancel
Save