public static Map<Lang, Result> convertFromFiles(
     ClassLoader loader, List<Lang> lang, String file, String fqn, String method)
     throws Exception {
   DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
   StandardJavaFileManager manager = javac.getStandardFileManager(diagnostics, locale, charset);
   Iterable<? extends JavaFileObject> fileObjects = manager.getJavaFileObjects(file);
   StringWriter out = new StringWriter();
   JavaCompiler.CompilationTask task =
       javac.getTask(
           out,
           manager,
           diagnostics,
           Collections.<String>emptyList(),
           Collections.<String>emptyList(),
           fileObjects);
   task.setLocale(locale);
   ConvertingProcessor processor = new ConvertingProcessor(lang, fqn, method);
   task.setProcessors(Collections.<Processor>singletonList(processor));
   if (task.call()) {
     return processor.getResults();
   } else {
     StringWriter message = new StringWriter();
     PrintWriter writer = new PrintWriter(message);
     writer.append("Compilation of ").append(file).println(" failed:");
     for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) {
       writer.append(diagnostic.getMessage(locale));
     }
     writer.println("console:");
     writer.append(out.getBuffer());
     throw new Exception(message.toString());
   }
 }
예제 #2
0
 @NotNull
 public static CompilerConfiguration compilerConfigurationForTests(
     @NotNull ConfigurationKind configurationKind,
     @NotNull TestJdkKind jdkKind,
     @NotNull File... extraClasspath) {
   return compilerConfigurationForTests(
       configurationKind, jdkKind, Arrays.asList(extraClasspath), Collections.<File>emptyList());
 }
예제 #3
0
  private static List<String> parseDependencies(@Nullable String dependencies) {
    if (dependencies == null) return Collections.emptyList();

    Matcher matcher = Pattern.compile("\\w+").matcher(dependencies);
    List<String> result = new ArrayList<String>();
    while (matcher.find()) {
      result.add(matcher.group());
    }
    return result;
  }