< prev index next >

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

Print this page




 159 
 160     /**
 161      * Internal version of compile, allowing context to be provided.
 162      * Note that the context needs to have a file manager set up.
 163      * @param argv  the command line parameters
 164      * @param context the context
 165      * @return the result of the compilation
 166      */
 167     public Result compile(String[] argv, Context context) {
 168         if (stdOut != null) {
 169             context.put(Log.outKey, stdOut);
 170         }
 171 
 172         if (stdErr != null) {
 173             context.put(Log.errKey, stdErr);
 174         }
 175 
 176         log = Log.instance(context);
 177 
 178         if (argv.length == 0) {
 179             Option.HELP.process(new OptionHelper.GrumpyHelper(log) {
 180                 @Override
 181                 public String getOwnName() { return ownName; }
 182                 @Override
 183                 public void put(String name, String value) { }
 184             }, "-help");

 185             return Result.CMDERR;
 186         }
 187 
 188         // prefix argv with contents of _JAVAC_OPTIONS if set
 189         String envOpt = System.getenv("_JAVAC_OPTIONS");
 190         if (envOpt != null && !envOpt.trim().isEmpty()) {
 191             String[] envv = envOpt.split("\\s+");
 192             String[] result = new String[envv.length + argv.length];
 193             System.arraycopy(envv, 0, result, 0, envv.length);
 194             System.arraycopy(argv, 0, result, envv.length, argv.length);
 195             argv = result;
 196         }
 197 
 198         // expand @-files
 199         try {
 200             argv = CommandLine.parse(argv);
 201         } catch (FileNotFoundException | NoSuchFileException e) {
 202             warning("err.file.not.found", e.getMessage());
 203             return Result.SYSERR;
 204         } catch (IOException ex) {


 249         ok &= args.validate();
 250         if (!ok || log.nerrors > 0)
 251             return Result.CMDERR;
 252 
 253         if (args.isEmpty())
 254             return Result.OK;
 255 
 256         // init Dependencies
 257         if (options.isSet("debug.completionDeps")) {
 258             Dependencies.GraphDependencies.preRegister(context);
 259         }
 260 
 261         // init plugins
 262         Set<List<String>> pluginOpts = args.getPluginOpts();
 263         if (!pluginOpts.isEmpty() || context.get(PlatformDescription.class) != null) {
 264             BasicJavacTask t = (BasicJavacTask) BasicJavacTask.instance(context);
 265             t.initPlugins(pluginOpts);
 266         }
 267 
 268         // init multi-release jar handling
 269         if (fileManager.isSupportedOption(Option.MULTIRELEASE.text) == 1) {
 270             Target target = Target.instance(context);
 271             List<String> list = List.of(target.multiReleaseValue());
 272             fileManager.handleOption(Option.MULTIRELEASE.text, list.iterator());
 273         }
 274 
 275         // init JavaCompiler
 276         JavaCompiler comp = JavaCompiler.instance(context);
 277 
 278         // init doclint
 279         List<String> docLintOpts = args.getDocLintOpts();
 280         if (!docLintOpts.isEmpty()) {
 281             BasicJavacTask t = (BasicJavacTask) BasicJavacTask.instance(context);
 282             t.initDocLint(docLintOpts);
 283         }
 284 
 285         if (options.get(Option.XSTDOUT) != null) {
 286             // Stdout reassigned - ask compiler to close it when it is done
 287             comp.closeables = comp.closeables.prepend(log.getWriter(WriterKind.NOTICE));
 288         }
 289 
 290         try {
 291             comp.compile(args.getFileObjects(), args.getClassNames(), null);
 292 




 159 
 160     /**
 161      * Internal version of compile, allowing context to be provided.
 162      * Note that the context needs to have a file manager set up.
 163      * @param argv  the command line parameters
 164      * @param context the context
 165      * @return the result of the compilation
 166      */
 167     public Result compile(String[] argv, Context context) {
 168         if (stdOut != null) {
 169             context.put(Log.outKey, stdOut);
 170         }
 171 
 172         if (stdErr != null) {
 173             context.put(Log.errKey, stdErr);
 174         }
 175 
 176         log = Log.instance(context);
 177 
 178         if (argv.length == 0) {
 179             OptionHelper h = new OptionHelper.GrumpyHelper(log) {
 180                 @Override
 181                 public String getOwnName() { return ownName; }
 182                 @Override
 183                 public void put(String name, String value) { }
 184             };
 185             Option.HELP.process(h, "-help");
 186             return Result.CMDERR;
 187         }
 188 
 189         // prefix argv with contents of _JAVAC_OPTIONS if set
 190         String envOpt = System.getenv("_JAVAC_OPTIONS");
 191         if (envOpt != null && !envOpt.trim().isEmpty()) {
 192             String[] envv = envOpt.split("\\s+");
 193             String[] result = new String[envv.length + argv.length];
 194             System.arraycopy(envv, 0, result, 0, envv.length);
 195             System.arraycopy(argv, 0, result, envv.length, argv.length);
 196             argv = result;
 197         }
 198 
 199         // expand @-files
 200         try {
 201             argv = CommandLine.parse(argv);
 202         } catch (FileNotFoundException | NoSuchFileException e) {
 203             warning("err.file.not.found", e.getMessage());
 204             return Result.SYSERR;
 205         } catch (IOException ex) {


 250         ok &= args.validate();
 251         if (!ok || log.nerrors > 0)
 252             return Result.CMDERR;
 253 
 254         if (args.isEmpty())
 255             return Result.OK;
 256 
 257         // init Dependencies
 258         if (options.isSet("debug.completionDeps")) {
 259             Dependencies.GraphDependencies.preRegister(context);
 260         }
 261 
 262         // init plugins
 263         Set<List<String>> pluginOpts = args.getPluginOpts();
 264         if (!pluginOpts.isEmpty() || context.get(PlatformDescription.class) != null) {
 265             BasicJavacTask t = (BasicJavacTask) BasicJavacTask.instance(context);
 266             t.initPlugins(pluginOpts);
 267         }
 268 
 269         // init multi-release jar handling
 270         if (fileManager.isSupportedOption(Option.MULTIRELEASE.primaryName) == 1) {
 271             Target target = Target.instance(context);
 272             List<String> list = List.of(target.multiReleaseValue());
 273             fileManager.handleOption(Option.MULTIRELEASE.primaryName, list.iterator());
 274         }
 275 
 276         // init JavaCompiler
 277         JavaCompiler comp = JavaCompiler.instance(context);
 278 
 279         // init doclint
 280         List<String> docLintOpts = args.getDocLintOpts();
 281         if (!docLintOpts.isEmpty()) {
 282             BasicJavacTask t = (BasicJavacTask) BasicJavacTask.instance(context);
 283             t.initDocLint(docLintOpts);
 284         }
 285 
 286         if (options.get(Option.XSTDOUT) != null) {
 287             // Stdout reassigned - ask compiler to close it when it is done
 288             comp.closeables = comp.closeables.prepend(log.getWriter(WriterKind.NOTICE));
 289         }
 290 
 291         try {
 292             comp.compile(args.getFileObjects(), args.getClassNames(), null);
 293 


< prev index next >