import org.eclipse.jdt.internal.compiler.impl.*;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
+// FEATURE: add build dependencies like make (grab some Java dependency-checker code off the net?)
+
public class Compiler {
// Static Entry Point /////////////////////////////////////////////////////
public static void main(String[] args) throws IOException {
- boolean verbose = false, veryverbose = false;
+ boolean verbose = false, veryverbose = false, warnings = true;
List srcdir = new ArrayList();
String source = null, target = null, blddir = null, mainclass = null;
boolean buildjar = false;
System.out.println("Missing parameter: "+args[i]); return; }
mainclass = args[++i];
break;
+ case 'w':
+ if (i == args.length - 1) {
+ System.out.println("Missing parameter: "+args[i]); return; }
+ warnings = false;
+ break;
case 's':
if (i == args.length - 1) {
System.out.println("Missing parameter: "+args[i]); return; }
c.setSourceDirs(s);
c.setVerbose(verbose);
+ c.setWarnings(warnings);
c.setVeryVerbose(veryverbose);
c.compile();
}
private boolean hasErrors;
private boolean verbose = false;
private boolean veryverbose = false;
+ private boolean warnings = true;
public Compiler() {
List defs = Collections.EMPTY_LIST;
public void setSourceDirs(String[] dir) { sourcedirs = dir; }
/** Pass CompilerOptions.VERSION_1_*. A String of form "1.1", ".2", etc. */
- public void setSource(String v) { settings.put(CompilerOptions.OPTION_Source, v); }
+ public void setSource(String v) {
+ if (v.equals("1.1")) settings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_1);
+ else if (v.equals("1.2")) settings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_2);
+ else if (v.equals("1.3")) settings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
+ else if (v.equals("1.4")) settings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4);
+ else if (v.equals("1.5")) settings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
+ else throw new RuntimeException("I have no idea what Java " + v + " is. Ask David Crawshaw.");
+ }
/** Pass CompilerOptions.VERSION_1_*. A String of form "1.1", ".2", etc. */
- public void setTarget(String v) { settings.put(CompilerOptions.OPTION_TargetPlatform, v); }
+ public void setTarget(String v) {
+ if (v.equals("1.1")) settings.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
+ else if (v.equals("1.2")) settings.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2);
+ else if (v.equals("1.3")) settings.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_3);
+ else if (v.equals("1.4")) settings.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
+ else if (v.equals("1.5")) settings.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
+ else throw new RuntimeException("I have no idea what Java " + v + " is. Ask David Crawshaw.");
+ }
public void setVerbose(boolean v) { verbose = v; }
public void setVeryVerbose(boolean v) { veryverbose = v; }
+ public void setWarnings(boolean w) { warnings = w; }
public void compile() throws IOException {
List s = new ArrayList();
env, policy, settings, results, problems);
jdt.compile(units);
- if (!hasErrors) { out.write(w.toString()); out.flush(); }
+ if (warnings && !hasErrors) { out.write(w.toString()); out.flush(); }
warn = null;
try {
if (jarfile != null) jarfile.close();
} catch (Exception e) {
e.printStackTrace();
}
+ if (verbose) System.out.print(clearing + " \r");
}
private final FilenameFilter filterSrcs = new FilenameFilter() {
{
settings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
settings.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
- settings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
+ settings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
settings.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
};
}
ClassFile[] c = result.getClassFiles();
- String clearing = "\r";
for (int i=0; i < c.length; i++) {
try {
char[][] name = c[i].getCompoundName();
*/
String printme = " writing: " + pct + str(pack(name),'.') + "." + new String(name(name));
if (clearing.length() < printme.length()) clearing = "";
- else clearing = clearing.substring(0, clearing.length() - printme.length());
+ else clearing = clearing.substring(printme.length());
System.out.print(printme + clearing + "\r");
- for(clearing = ""; clearing.length() < printme.length() + 2; clearing += " ");
+ for(clearing = ""; clearing.length() < printme.length() + 5; clearing += " ");
}
if (buildzip) {
try {
};
int percent = 0;
+ String clearing = "";
/** Problem creater for compiler. */
private final IProblemFactory problems = new DefaultProblemFactory();