Could be changed for example like this. Only checks for limitations on known
system and should do everything "as normal" on unknown system, except it
issued a "Note" to the log if an IOException occurs and no temporary file
was used. This note *must* be changed (if it should be included at all)
since it doesn't contain a valid contact for error reporting.
Another possibility would have been to use default limit of 4096 (defined by
POSIX if read the AIX includefile correcly), but I hope most OS today don't
have such a small limit?
Would it be better to include this in a config file (and how?)?
Index: Javac.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.jav
a,v
retrieving revision 1.41
diff -u -r1.41 Javac.java
--- Javac.java 2000/09/19 16:13:51 1.41
+++ Javac.java 2000/09/19 21:59:34
@@ -113,6 +113,8 @@
private Path bootclasspath;
private Path extdirs;
private static String lSep = System.getProperty("line.separator");
+ private static String antWorkingDirectory =
System.getProperty("user.dir");
+ private static String myos = System.getProperty("os.name");
protected Vector compileList = new Vector();
@@ -706,17 +708,11 @@
private int executeJikesCompile(String[] args, int firstFileName) {
String[] commandArray = null;
File tmpFile = null;
+
+ boolean useTmpFile = checkLimits(args, firstFileName);
try {
- 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) {
+ if (useTmpFile)
PrintWriter out = null;
try {
tmpFile = new File("jikes"+(new
Random(System.currentTimeMillis())).nextLong());
@@ -736,6 +732,7 @@
}
}
} else {
+ // Should be safe to let the JVM do it the "normal" way
commandArray = args;
}
@@ -749,6 +746,14 @@
exe.execute();
return exe.getExitValue();
} catch (IOException e) {
+ if (!useTmpFile)
+ log("Note: Using a large number of arguments is known
to be problematic", Project.MSG_INFO);
+ log(" on some operating systems. If you think this
error may be", Project.MSG_INFO);
+ log(" caused by such a cicumstance please mail
<???> with the", Project.MSG_INFO);
+ log(" maximum length a command line can take on
your OS.", Project.MSG_INFO);
+ log(" Please specify " + myos + " as the reference
for your OS", Project.MSG_INFO);
+ log(" including the version of the OS and the JDK
used. Thanks.", Project.MSG_INFO);
+ }
throw new BuildException("Error running Jikes compiler",
e);
}
} finally {
@@ -756,6 +761,50 @@
tmpFile.delete();
}
}
+ }
+
+ /**
+ * Given an array of commandline arguments checks if it's required
+ * to use a temporary file for compilation (if it's possible at
+ * all)
+ *
+ * @param args the arguments the compiler required
+ * @param firstFileName index of the first filename in the args
+ */
+ private boolean checkLimits(String[] args, int firstFileName)
+ boolean needTmpFile = false;
+
+ int limit = -1; // -1 means unlimited
+ int length = 0;
+
+ if (myos.toLowerCase().indexOf("windows") >= 0)
+ // Windows has a 32k limit on total arg size
+ limit = 32000;
+
+ // If we are not on JDK 1.3 and we need to do a chdir
+ // the Limit is only about 4k (using cmd.exe).
+ if (!Project.getJavaVersion().equals(Project.JAVA_1_3) &&
+
!project.getBaseDir().getAbsolutePath().equals(antWorkingDirectory))
+ limit = 4000;
+ }
+ } else if (myos.toLowerCase().indexOf("linux") >= 0) {
+ limit = 90000;
+ } else if (myos.toLowerCase().indexOf("aix") >= 0) {
+ limit = 20000;
+ }
+
+ // Is there a known limit on the current OS?
+ if (limit != -1)
+ for (int i = 0; i < args.length; i++)
+ length += args[i].length();
+ }
+
+ // If it's exceeded we need a tempfile
+ if (length > limit) {
+ needTmpFile = true;
+ }
+ }
+ return needTmpFile;
}
/**