bodewig 00/07/21 03:19:23
Modified: src/main/org/apache/tools/ant/taskdefs Jikes.java
Log:
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: [EMAIL PROTECTED]
Revision Changes Path
1.4 +52 -13
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Jikes.java
Index: Jikes.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Jikes.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Jikes.java 2000/07/02 16:18:55 1.3
+++ Jikes.java 2000/07/21 10:19:23 1.4
@@ -3,6 +3,8 @@
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 @@
* @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();
+ }
}
}
}