162 163 if (out == null) 164 context.put(Log.errKey, new PrintWriter(System.err, true)); 165 else 166 context.put(Log.errKey, new PrintWriter(out, true)); 167 168 if (fileManager == null) { 169 fileManager = getStandardFileManager(diagnosticListener, null, null); 170 if (fileManager instanceof BaseFileManager) { 171 ((BaseFileManager) fileManager).autoClose = true; 172 } 173 } 174 fileManager = ccw.wrap(fileManager); 175 176 context.put(JavaFileManager.class, fileManager); 177 178 Arguments args = Arguments.instance(context); 179 args.init("javac", options, classes, compilationUnits); 180 181 // init multi-release jar handling 182 if (fileManager.isSupportedOption(Option.MULTIRELEASE.text) == 1) { 183 Target target = Target.instance(context); 184 List<String> list = List.of(target.multiReleaseValue()); 185 fileManager.handleOption(Option.MULTIRELEASE.text, list.iterator()); 186 } 187 188 return new JavacTaskImpl(context); 189 } catch (PropagatedException ex) { 190 throw ex.getCause(); 191 } catch (ClientCodeException ex) { 192 throw new RuntimeException(ex.getCause()); 193 } 194 } 195 196 @Override @DefinedBy(Api.COMPILER) 197 public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) { 198 if (err == null) 199 err = System.err; 200 for (String argument : arguments) 201 Objects.requireNonNull(argument); 202 return com.sun.tools.javac.Main.compile(arguments, new PrintWriter(err, true)); 203 } 204 205 @Override @DefinedBy(Api.COMPILER) 206 public Set<SourceVersion> getSourceVersions() { 207 return Collections.unmodifiableSet(EnumSet.range(SourceVersion.RELEASE_3, 208 SourceVersion.latest())); 209 } 210 211 @Override @DefinedBy(Api.COMPILER) 212 public int isSupportedOption(String option) { 213 Set<Option> recognizedOptions = Option.getJavacToolOptions(); 214 for (Option o : recognizedOptions) { 215 if (o.matches(option)) 216 return o.hasArg() ? 1 : 0; 217 } 218 return -1; 219 } 220 221 } | 162 163 if (out == null) 164 context.put(Log.errKey, new PrintWriter(System.err, true)); 165 else 166 context.put(Log.errKey, new PrintWriter(out, true)); 167 168 if (fileManager == null) { 169 fileManager = getStandardFileManager(diagnosticListener, null, null); 170 if (fileManager instanceof BaseFileManager) { 171 ((BaseFileManager) fileManager).autoClose = true; 172 } 173 } 174 fileManager = ccw.wrap(fileManager); 175 176 context.put(JavaFileManager.class, fileManager); 177 178 Arguments args = Arguments.instance(context); 179 args.init("javac", options, classes, compilationUnits); 180 181 // init multi-release jar handling 182 if (fileManager.isSupportedOption(Option.MULTIRELEASE.primaryName) == 1) { 183 Target target = Target.instance(context); 184 List<String> list = List.of(target.multiReleaseValue()); 185 fileManager.handleOption(Option.MULTIRELEASE.primaryName, list.iterator()); 186 } 187 188 return new JavacTaskImpl(context); 189 } catch (PropagatedException ex) { 190 throw ex.getCause(); 191 } catch (ClientCodeException ex) { 192 throw new RuntimeException(ex.getCause()); 193 } 194 } 195 196 @Override @DefinedBy(Api.COMPILER) 197 public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) { 198 if (err == null) 199 err = System.err; 200 for (String argument : arguments) 201 Objects.requireNonNull(argument); 202 return com.sun.tools.javac.Main.compile(arguments, new PrintWriter(err, true)); 203 } 204 205 @Override @DefinedBy(Api.COMPILER) 206 public Set<SourceVersion> getSourceVersions() { 207 return Collections.unmodifiableSet(EnumSet.range(SourceVersion.RELEASE_3, 208 SourceVersion.latest())); 209 } 210 211 @Override @DefinedBy(Api.COMPILER) 212 public int isSupportedOption(String option) { 213 Set<Option> recognizedOptions = Option.getJavacToolOptions(); 214 for (Option o : recognizedOptions) { 215 if (o.matches(option)) { 216 return o.hasArg() ? 1 : 0; 217 } 218 } 219 return -1; 220 } 221 222 } |