Java Code Examples for java.util.spi.ToolProvider#run()

The following examples show how to use java.util.spi.ToolProvider#run() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocerPlugin.java    From pro with GNU General Public License v3.0 6 votes vote down vote up
private static int generateDoc(Log log, ToolProvider javadocTool, DocerConf docerConf, List<Path> sourcePath, Optional<Integer> release, Path input, Path output) {
  var javadoc = new Javadoc(output.resolve(input.getFileName().toString()), sourcePath);
  docerConf.rawArguments().ifPresent(javadoc::rawArguments);
  javadoc.modulePath(docerConf.moduleDependencyPath());
  docerConf.upgradeModulePath().ifPresent(javadoc::upgradeModulePath);
  docerConf.rootModules().ifPresent(javadoc::rootModules);
  javadoc.quiet(docerConf.quiet());
  javadoc.html5(docerConf.html5());
  release.ifPresent(javadoc::release);
  docerConf.enablePreview().ifPresent(javadoc::enablePreview);
  docerConf.link().filter(url -> isLinkHostOnline(log, url)).ifPresent(javadoc::link);
  
  var cmdLine = gatherAll(JavadocOption.class, option -> option.action).apply(javadoc, new CmdLine());
  var files = docerConf.files().orElseGet(
      () -> walkIfNecessary(List.of(input), pathFilenameEndsWith(".java")));  //FIXME, use rootNames ??
  files.forEach(cmdLine::add);
  var arguments = cmdLine.toArguments();
  log.verbose(files, fs -> OptionAction.toPrettyString(JavadocOption.class, option -> option.action).apply(javadoc, "javadoc") + "\n" + fs.stream().map(Path::toString).collect(Collectors.joining(" ")));
  
  return javadocTool.run(System.out, System.err, arguments);
}
 
Example 2
Source File: PackagerPlugin.java    From pro with GNU General Public License v3.0 6 votes vote down vote up
private static int packageModule(Log log, ToolProvider jarTool, Path moduleExploded,  Path moduleArtifact, PackagerConf packager, Map<String, Metadata> metadataMap, String prefix) {
  var modules = ModuleFinder.of(moduleExploded).findAll();
  if (modules.size() != 1) {
    throw new IllegalStateException("more than one module packaged in the exploded module " + moduleExploded);
  }
  
  var moduleName = modules.iterator().next().descriptor().name(); 
  
  var metadataOpt = Optional.ofNullable(metadataMap.get(moduleName));
  var version = metadataOpt.flatMap(Metadata::version).orElse("1.0");
  var jar = new Jar(moduleExploded, moduleArtifact.resolve(prefix + moduleName + "-" + version + ".jar"));
  jar.setModuleVersion(version);
  metadataOpt.flatMap(Metadata::mainClass).ifPresent(jar::setMainClass);
  packager.rawArguments().ifPresent(jar::rawArguments);
  
  var cmdLine = new CmdLine().add("--create");
  cmdLine = OptionAction.gatherAll(JarOption.class, option -> option.action).apply(jar, cmdLine);
  var arguments = cmdLine.add(".").toArguments();
  
  log.verbose(jar, _jar -> OptionAction.toPrettyString(JarOption.class, option -> option.action).apply(_jar, "jar"));
  var exitCode = jarTool.run(System.out, System.err, arguments);
  return exitCode;
}
 
Example 3
Source File: PackagerPlugin.java    From pro with GNU General Public License v3.0 6 votes vote down vote up
private static int packageSourceOrDoc(Log log, ToolProvider jarTool, Path input, Path outputPath, PackagerConf packager, Map<String, Metadata> metadataMap, String suffix) {
  var moduleName = input.getFileName().toString();
  
  var metadataOpt = Optional.ofNullable(metadataMap.get(moduleName));
  var version = metadataOpt.flatMap(Metadata::version).orElse("1.0");
  
  var jar = new Jar(input, outputPath.resolve(moduleName + "-" + suffix + "-" + version + ".jar"));
  packager.rawArguments().ifPresent(jar::rawArguments);
  
  var cmdLine = new CmdLine().add("--create");
  cmdLine = OptionAction.gatherAll(JarOption.class, option -> option.action).apply(jar, cmdLine);
  var arguments = cmdLine.add(".").toArguments();
  
  log.verbose(jar, _jar -> OptionAction.toPrettyString(JarOption.class, option -> option.action).apply(_jar, "jar"));
  var exitCode = jarTool.run(System.out, System.err, arguments);
  return exitCode;
}
 
Example 4
Source File: ToolProviderTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void test() throws Exception {
    ToolProvider testProvider = ToolProvider.findFirst("test").get();
    int rc = testProvider.run(System.out, System.err, "hello test");
    if (rc != 0) {
        throw new Exception("unexpected exit code: " + rc);
    }
}
 
Example 5
Source File: ImageModules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static ToolResult execTool(ToolProvider tool, String... args) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    List<String> filteredArgs = Stream.of(args)
                                      .map(s -> s.split(" ")).flatMap(Stream::of)
                                      .filter(s -> !s.equals(""))
                                      .collect(Collectors.toList());
    System.out.println(tool + " " + filteredArgs);
    int ec = tool.run(ps, ps, filteredArgs.toArray(new String[] {}));
    return new ToolResult(ec, new String(baos.toByteArray(), UTF_8));
}
 
Example 6
Source File: ModuleFixerPlugin.java    From pro with GNU General Public License v3.0 5 votes vote down vote up
private static int patchModularJar(ToolProvider jarTool, ModuleReference ref, Path generatedModuleInfo) {
  System.out.println("[modulefixer] fix " + ref.descriptor().name());
  return jarTool.run(System.out, System.err,
      "--update",
      "--file", Path.of(ref.location().orElseThrow()).toString(),
      "-C", generatedModuleInfo.getParent().toString(),
      generatedModuleInfo.getFileName().toString());
}
 
Example 7
Source File: CompilerPlugin.java    From pro with GNU General Public License v3.0 5 votes vote down vote up
private static int compileAllFiles(Log log, ToolProvider javacTool, Javac javac, Optional<Integer> release, List<Path> files) {
  release.ifPresent(javac::release);
  var cmdLine = gatherAll(JavacOption.class, option -> option.action).apply(javac, new CmdLine());
  files.forEach(cmdLine::add);

  var arguments = cmdLine.toArguments();
  log.verbose(files, fs -> toPrettyString(JavacOption.class, option -> option.action).apply(javac, "javac") + "\n" + fs.stream().map(Path::toString).collect(joining(" ")));

  return javacTool.run(System.out, System.err, arguments);
}