Browse Source

Workaround for a problem when compiling many files on Windows.

I've modified Matt's patch a little to kick in only if we are actually
running on Windows and want to compile a lot of files.

Unfortunately File.createTempFile is not available on JDK 1.1. I use
java.util.Random to create a hopefully unique filename for a temporary
file. Hope this works - don't have a Windows box to check.

Submitted by:	mpfoemme@ThoughtWorks.com


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267810 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
a67f5b98b5
1 changed files with 52 additions and 13 deletions
  1. +52
    -13
      src/main/org/apache/tools/ant/taskdefs/Jikes.java

+ 52
- 13
src/main/org/apache/tools/ant/taskdefs/Jikes.java View File

@@ -3,6 +3,8 @@ package org.apache.tools.ant.taskdefs;
import java.io.*;
import org.apache.tools.ant.*;

import java.util.Random;

/**
* Encapsulates a Jikes compiler, by
* directly executing an external process.
@@ -28,20 +30,57 @@ public class Jikes {
* @param args - arguments to pass to process on command line
*/
protected void compile(String[] args) {
String[] commandArray = new String[args.length+1];
commandArray[0] = command;
System.arraycopy(args,0,commandArray,1,args.length);
// We assume, that everything jikes writes goes to
// standard output, not to standard error. The option
// -Xstdout that is given to Jikes in Javac.doJikesCompile()
// should guarantee this. At least I hope so. :)
String[] commandArray = null;
File tmpFile = null;

try {
Process jikes = Runtime.getRuntime().exec(commandArray);
BufferedReader reader = new BufferedReader(new InputStreamReader(jikes.getInputStream()));
jop.parseOutput(reader);
} catch (IOException e) {
throw new BuildException("Error running Jikes compiler", e);
String myos = System.getProperty("os.name");

// Windows has a 32k limit on total arg size, so
// create a temporary file to store all the arguments

// There have been reports that 300 files could be compiled
// so 250 is a conservative approach
if (myos.toLowerCase().indexOf("windows") >= 0
&& args.length > 250) {
PrintWriter out = null;
try {
tmpFile = new File("jikes"+(new Random(System.currentTimeMillis())).nextLong());
out = new PrintWriter(new FileWriter(tmpFile));
for (int i = 0; i < args.length; i++) {
out.println(args[i]);
}
out.flush();
commandArray = new String[] { command,
"@" + tmpFile.getAbsolutePath()};
} catch (IOException e) {
throw new BuildException("Error creating temporary file", e);
} finally {
if (out != null) {
try {out.close();} catch (Throwable t) {}
}
}
} else {
commandArray = new String[args.length+1];
commandArray[0] = command;
System.arraycopy(args,0,commandArray,1,args.length);
}
// We assume, that everything jikes writes goes to
// standard output, not to standard error. The option
// -Xstdout that is given to Jikes in Javac.doJikesCompile()
// should guarantee this. At least I hope so. :)
try {
Process jikes = Runtime.getRuntime().exec(commandArray);
BufferedReader reader = new BufferedReader(new InputStreamReader(jikes.getInputStream()));
jop.parseOutput(reader);
} catch (IOException e) {
throw new BuildException("Error running Jikes compiler", e);
}
} finally {
if (tmpFile != null) {
tmpFile.delete();
}
}
}
}

Loading…
Cancel
Save