removed Makefile; lifted repo/org.ibex.tool/src/ to src/
[org.ibex.tool.git] / src / org / ibex / tool / Compiler.java
index d72d33f..382cf74 100644 (file)
@@ -21,11 +21,13 @@ import org.eclipse.jdt.internal.compiler.env.*;
 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;
@@ -58,6 +60,11 @@ public class Compiler {
                             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; }
@@ -95,6 +102,7 @@ public class Compiler {
         c.setSourceDirs(s);
 
         c.setVerbose(verbose);
+        c.setWarnings(warnings);
         c.setVeryVerbose(veryverbose);
         c.compile();
     }
@@ -133,6 +141,7 @@ public class Compiler {
     private boolean hasErrors;
     private boolean verbose = false;
     private boolean veryverbose = false;
+    private boolean warnings = true;
 
     public Compiler() {
         List defs = Collections.EMPTY_LIST;
@@ -159,13 +168,28 @@ public class Compiler {
     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();
@@ -207,13 +231,14 @@ public class Compiler {
                 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() {
@@ -593,7 +618,7 @@ public class Compiler {
     {
         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);
     };
 
@@ -621,7 +646,6 @@ public class Compiler {
             }
 
             ClassFile[] c = result.getClassFiles();
-           String clearing = "\r";
             for (int i=0; i < c.length; i++) {
                 try {
                    char[][] name = c[i].getCompoundName();
@@ -634,9 +658,9 @@ public class Compiler {
                        */
                        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 {
@@ -669,6 +693,7 @@ public class Compiler {
     };
 
     int percent = 0;
+    String clearing = "";
 
     /** Problem creater for compiler. */
     private final IProblemFactory problems = new DefaultProblemFactory();