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