src/share/classes/com/sun/tools/javac/main/Main.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File langtools Sdiff src/share/classes/com/sun/tools/javac/main

src/share/classes/com/sun/tools/javac/main/Main.java

Print this page




  32 import java.security.DigestInputStream;
  33 import java.security.MessageDigest;
  34 import java.util.Arrays;
  35 import java.util.Collection;
  36 import java.util.Iterator;
  37 import java.util.LinkedHashSet;
  38 import java.util.ServiceLoader;
  39 import java.util.Set;
  40 
  41 import javax.annotation.processing.Processor;
  42 import javax.tools.JavaFileManager;
  43 import javax.tools.JavaFileObject;
  44 
  45 import com.sun.source.util.JavacTask;
  46 import com.sun.source.util.Plugin;
  47 import com.sun.tools.doclint.DocLint;
  48 import com.sun.tools.javac.api.BasicJavacTask;
  49 import com.sun.tools.javac.code.Source;
  50 import com.sun.tools.javac.file.CacheFSInfo;
  51 import com.sun.tools.javac.file.JavacFileManager;

  52 import com.sun.tools.javac.jvm.Target;
  53 import com.sun.tools.javac.processing.AnnotationProcessingError;
  54 import com.sun.tools.javac.processing.JavacProcessingEnvironment;
  55 import com.sun.tools.javac.util.*;
  56 import com.sun.tools.javac.util.Log.PrefixKind;
  57 import com.sun.tools.javac.util.Log.WriterKind;
  58 import static com.sun.tools.javac.main.Option.*;
  59 
  60 /** This class provides a command line interface to the javac compiler.
  61  *
  62  *  <p><b>This is NOT part of any supported API.
  63  *  If you write code that depends on this, you do so at your own risk.
  64  *  This code and its internal interfaces are subject to change or
  65  *  deletion without notice.</b>
  66  */
  67 public class Main {
  68 
  69     /** The name of the compiler, for use in diagnostics.
  70      */
  71     String ownName;
  72 
  73     /** The writer to use for diagnostic output.
  74      */
  75     PrintWriter out;
  76 
  77     /** The log to use for diagnostic output.
  78      */
  79     Log log;
  80 
  81     /**
  82      * If true, certain errors will cause an exception, such as command line
  83      * arg errors, or exceptions in user provided code.
  84      */
  85     boolean apiMode;
  86 
  87 
  88     /** Result codes.
  89      */
  90     public enum Result {
  91         OK(0),        // Compilation completed with no errors.
  92         ERROR(1),     // Completed but reported errors.
  93         CMDERR(2),    // Bad command-line arguments
  94         SYSERR(3),    // System error or resource exhaustion.
  95         ABNORMAL(4);  // Compiler terminated abnormally
  96 
  97         Result(int exitCode) {
  98             this.exitCode = exitCode;
  99         }


 148         public void addClassName(String s) {
 149             classnames.append(s);
 150         }
 151 
 152     };
 153 
 154     /**
 155      * Construct a compiler instance.
 156      */
 157     public Main(String name) {
 158         this(name, new PrintWriter(System.err, true));
 159     }
 160 
 161     /**
 162      * Construct a compiler instance.
 163      */
 164     public Main(String name, PrintWriter out) {
 165         this.ownName = name;
 166         this.out = out;
 167     }

 168     /** A table of all options that's passed to the JavaCompiler constructor.  */
 169     private Options options = null;
 170 
 171     /** The list of source files to process
 172      */
 173     public Set<File> filenames = null; // XXX sb protected
 174 
 175     /** List of class files names passed on the command line
 176      */
 177     public ListBuffer<String> classnames = null; // XXX sb protected
 178 
 179     /** Report a usage error.
 180      */
 181     void error(String key, Object... args) {
 182         if (apiMode) {
 183             String msg = log.localize(PrefixKind.JAVAC, key, args);
 184             throw new PropagatedException(new IllegalStateException(msg));
 185         }
 186         warning(key, args);
 187         log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);


 290                                 targetString,
 291                                 source.requiredTarget().name);
 292                     } else {
 293                         warning("warn.source.target.conflict",
 294                                 sourceString,
 295                                 source.requiredTarget().name);
 296                     }
 297                     return null;
 298                 } else {
 299                     target = source.requiredTarget();
 300                     options.put("-target", target.name);
 301                 }
 302             } else {
 303                 if (targetString == null && !source.allowGenerics()) {
 304                     target = Target.JDK1_4;
 305                     options.put("-target", target.name);
 306                 }
 307             }
 308         }
 309 









 310         // handle this here so it works even if no other options given
 311         String showClass = options.get("showClass");
 312         if (showClass != null) {
 313             if (showClass.equals("showClass")) // no value given for option
 314                 showClass = "com.sun.tools.javac.Main";
 315             showClass(showClass);
 316         }
 317 
 318         options.notifyListeners();
 319 
 320         return filenames;
 321     }
 322     // where
 323         private boolean checkDirectory(Option option) {
 324             String value = options.get(option);
 325             if (value == null)
 326                 return true;
 327             File file = new File(value);
 328             if (!file.exists()) {
 329                 error("err.dir.not.found", value);




  32 import java.security.DigestInputStream;
  33 import java.security.MessageDigest;
  34 import java.util.Arrays;
  35 import java.util.Collection;
  36 import java.util.Iterator;
  37 import java.util.LinkedHashSet;
  38 import java.util.ServiceLoader;
  39 import java.util.Set;
  40 
  41 import javax.annotation.processing.Processor;
  42 import javax.tools.JavaFileManager;
  43 import javax.tools.JavaFileObject;
  44 
  45 import com.sun.source.util.JavacTask;
  46 import com.sun.source.util.Plugin;
  47 import com.sun.tools.doclint.DocLint;
  48 import com.sun.tools.javac.api.BasicJavacTask;
  49 import com.sun.tools.javac.code.Source;
  50 import com.sun.tools.javac.file.CacheFSInfo;
  51 import com.sun.tools.javac.file.JavacFileManager;
  52 import com.sun.tools.javac.jvm.Profile;
  53 import com.sun.tools.javac.jvm.Target;
  54 import com.sun.tools.javac.processing.AnnotationProcessingError;
  55 import com.sun.tools.javac.processing.JavacProcessingEnvironment;
  56 import com.sun.tools.javac.util.*;
  57 import com.sun.tools.javac.util.Log.PrefixKind;
  58 import com.sun.tools.javac.util.Log.WriterKind;
  59 import static com.sun.tools.javac.main.Option.*;
  60 
  61 /** This class provides a command line interface to the javac compiler.
  62  *
  63  *  <p><b>This is NOT part of any supported API.
  64  *  If you write code that depends on this, you do so at your own risk.
  65  *  This code and its internal interfaces are subject to change or
  66  *  deletion without notice.</b>
  67  */
  68 public class Main {
  69 
  70     /** The name of the compiler, for use in diagnostics.
  71      */
  72     String ownName;
  73 
  74     /** The writer to use for diagnostic output.
  75      */
  76     PrintWriter out;
  77 
  78     /** The log to use for diagnostic output.
  79      */
  80     public Log log;
  81 
  82     /**
  83      * If true, certain errors will cause an exception, such as command line
  84      * arg errors, or exceptions in user provided code.
  85      */
  86     boolean apiMode;
  87 
  88 
  89     /** Result codes.
  90      */
  91     public enum Result {
  92         OK(0),        // Compilation completed with no errors.
  93         ERROR(1),     // Completed but reported errors.
  94         CMDERR(2),    // Bad command-line arguments
  95         SYSERR(3),    // System error or resource exhaustion.
  96         ABNORMAL(4);  // Compiler terminated abnormally
  97 
  98         Result(int exitCode) {
  99             this.exitCode = exitCode;
 100         }


 149         public void addClassName(String s) {
 150             classnames.append(s);
 151         }
 152 
 153     };
 154 
 155     /**
 156      * Construct a compiler instance.
 157      */
 158     public Main(String name) {
 159         this(name, new PrintWriter(System.err, true));
 160     }
 161 
 162     /**
 163      * Construct a compiler instance.
 164      */
 165     public Main(String name, PrintWriter out) {
 166         this.ownName = name;
 167         this.out = out;
 168     }
 169     
 170     /** A table of all options that's passed to the JavaCompiler constructor.  */
 171     private Options options = null;
 172 
 173     /** The list of source files to process
 174      */
 175     public Set<File> filenames = null; // XXX sb protected
 176 
 177     /** List of class files names passed on the command line
 178      */
 179     public ListBuffer<String> classnames = null; // XXX sb protected
 180 
 181     /** Report a usage error.
 182      */
 183     void error(String key, Object... args) {
 184         if (apiMode) {
 185             String msg = log.localize(PrefixKind.JAVAC, key, args);
 186             throw new PropagatedException(new IllegalStateException(msg));
 187         }
 188         warning(key, args);
 189         log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);


 292                                 targetString,
 293                                 source.requiredTarget().name);
 294                     } else {
 295                         warning("warn.source.target.conflict",
 296                                 sourceString,
 297                                 source.requiredTarget().name);
 298                     }
 299                     return null;
 300                 } else {
 301                     target = source.requiredTarget();
 302                     options.put("-target", target.name);
 303                 }
 304             } else {
 305                 if (targetString == null && !source.allowGenerics()) {
 306                     target = Target.JDK1_4;
 307                     options.put("-target", target.name);
 308                 }
 309             }
 310         }
 311         
 312         String profileString = options.get(PROFILE);
 313         if (profileString != null) {
 314             Profile profile = Profile.lookup(profileString);
 315             if (!profile.isValid(target)) {
 316                 warning("warn.profile.target.conflict", profileString, target.name);
 317                 return null;
 318             }
 319         }
 320         
 321         // handle this here so it works even if no other options given
 322         String showClass = options.get("showClass");
 323         if (showClass != null) {
 324             if (showClass.equals("showClass")) // no value given for option
 325                 showClass = "com.sun.tools.javac.Main";
 326             showClass(showClass);
 327         }
 328 
 329         options.notifyListeners();
 330 
 331         return filenames;
 332     }
 333     // where
 334         private boolean checkDirectory(Option option) {
 335             String value = options.get(option);
 336             if (value == null)
 337                 return true;
 338             File file = new File(value);
 339             if (!file.exists()) {
 340                 error("err.dir.not.found", value);


src/share/classes/com/sun/tools/javac/main/Main.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File