You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ru...@locus.apache.org on 2000/01/04 03:18:06 UTC
cvs commit: jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs Jikes.java JikesOutputParser.java Javac.java
rubys 00/01/03 18:18:06
Modified: ant/src/main/org/apache/tools/ant/taskdefs Javac.java
Added: ant/src/main/org/apache/tools/ant/taskdefs Jikes.java
JikesOutputParser.java
Log:
Add Jikes support for Ant
Submitted by: Sebastian Kanthak <se...@muehlheim.de>
Revision Changes Path
1.17 +74 -4 jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/Javac.java
Index: Javac.java
===================================================================
RCS file: /home/cvs/jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/Javac.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Javac.java 1999/12/31 05:20:57 1.16
+++ Javac.java 2000/01/04 02:18:06 1.17
@@ -56,8 +56,7 @@
import org.apache.tools.ant.*;
-import java.io.File;
-import java.io.IOException;
+import java.io.*;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;
@@ -430,10 +429,81 @@
}
/**
- * Performs a compile using the Jikes compile.
+ * Performs a compile using the Jikes compiler from IBM..
+ * Mostly of this code is identical to doClassicCompile()
+ * However, it does not support all options like
+ * bootclasspath, extdirs, deprecation and so on, because
+ * there is no option in jikes and I don't understand
+ * what they should do.
+ *
+ * It has been successfully tested with jikes 1.10
+ *
+ * @author skanthak@muehlheim.de
*/
private void doJikesCompile() throws BuildException {
- project.log("Performing a Jikes COmpile");
+ project.log("Using jikes compiler",project.MSG_VERBOSE);
+ String classpath = getCompileClasspath();
+ Vector argList = new Vector();
+
+ if (deprecation == true)
+ argList.addElement("-deprecation");
+
+ // We want all output on stdout to make
+ // parsing easier
+ argList.addElement("-Xstdout");
+
+ argList.addElement("-d");
+ argList.addElement(destDir.getAbsolutePath());
+ argList.addElement("-classpath");
+ // Jikes has no option for source-path so we
+ // will add it to classpath.
+ // XXX is this correct?
+ argList.addElement(classpath+File.pathSeparator +
+ srcDir.getAbsolutePath());
+ if (debug) {
+ argList.addElement("-g");
+ }
+ if (optimize) {
+ argList.addElement("-O");
+ }
+
+ project.log("Compilation args: " + argList.toString(),
+ project.MSG_VERBOSE);
+
+ String[] args = new String[argList.size() + compileList.size()];
+ int counter = 0;
+
+ for (int i = 0; i < argList.size(); i++) {
+ args[i] = (String)argList.elementAt(i);
+ counter++;
+ }
+
+ // XXX
+ // should be using system independent line feed!
+
+ StringBuffer niceSourceList = new StringBuffer("Files to be compiled:"
+ + "\r\n");
+
+ Enumeration enum = compileList.elements();
+ while (enum.hasMoreElements()) {
+ args[counter] = (String)enum.nextElement();
+ niceSourceList.append(" " + args[counter] + "\r\n");
+ counter++;
+ }
+
+ project.log(niceSourceList.toString(), project.MSG_VERBOSE);
+
+ // XXX
+ // provide the compiler a different message sink - namely our own
+
+ JikesOutputParser jop = new JikesOutputParser(project);
+
+ Jikes compiler = new Jikes(jop,"jikes");
+ compiler.compile(args);
+ if (jop.getErrorFlag()) {
+ String msg = "Compile failed, messages should have been provided.";
+ throw new BuildException(msg);
+ }
}
}
1.1 jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/Jikes.java
Index: Jikes.java
===================================================================
package org.apache.tools.ant.taskdefs;
import java.io.*;
/**
* Encapsulates a Jikes compiler, by
* directly executing an external process.
* @author skanthak@muehlheim.de
*/
public class Jikes {
protected JikesOutputParser jop;
protected String command;
/**
* Constructs a new Jikes obect.
* @param jop - Parser to send jike's output to
* @param command - name of jikes executeable
*/
protected Jikes(JikesOutputParser jop,String command) {
super();
this.jop = jop;
this.command = command;
}
/**
* Do the compile with the specified arguments.
* @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. :)
try {
Process jikes = Runtime.getRuntime().exec(commandArray);
BufferedReader reader = new BufferedReader(new InputStreamReader(jikes.getInputStream()));
jop.parseOutput(reader);
} catch (IOException e) {
// Where could we log this to? We don't have an instance
// of project. Perhaps we should add one to our constructor?
}
}
}
1.1 jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/JikesOutputParser.java
Index: JikesOutputParser.java
===================================================================
package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.*;
import java.io.*;
/**
* Parses output from jikes and
* passes errors and warnings
* into the right logging channels of Project.
*
* TODO:
* Parsing could be much better
* Emacs-mode of jikes (+E) cannot be parsed right now
* @author skanthak@muehlheim.de
*/
public class JikesOutputParser {
protected Project project;
protected boolean errorFlag = false; // no errors so far
protected int errors,warnings;
/**
* Construct a new Parser object
* @param project - project in whichs context we are called
*/
protected JikesOutputParser(Project project) {
super();
this.project = project;
}
/**
* Parse the output of a jikes compiler
* @param reader - Reader used to read jikes's output
*/
protected void parseOutput(BufferedReader reader) throws IOException {
String line;
String lower;
// We assume, that every output, jike does, stands for an error/warning
// XXX
// Is this correct?
while ((line = reader.readLine()) != null) {
lower = line.toLowerCase();
if (line.trim().equals(""))
continue;
if (lower.indexOf("error") != -1)
logError(line);
else if (lower.indexOf("warning") != -1)
logWarning(line);
else
logError(line);
}
}
private void logWarning(String line) {
project.log("",Project.MSG_WARN); // Empty lines from jikes are alredy eaten, so print new ones
project.log(line,Project.MSG_WARN);
}
private void logError(String line) {
errorFlag = true;
project.log("",Project.MSG_ERR); // see above
project.log(line,Project.MSG_ERR);
}
/**
* Indicate if there were errors during the compile
* @return if errors ocured
*/
protected boolean getErrorFlag() {
return errorFlag;
}
}