本文整理汇总了Java中javax.tools.Tool类的典型用法代码示例。如果您正苦于以下问题:Java Tool类的具体用法?Java Tool怎么用?Java Tool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Tool类属于javax.tools包,在下文中一共展示了Tool类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.tools.Tool; //导入依赖的package包/类
public static void main(String... args) {
Tool compiler = ToolProvider.getSystemJavaCompiler();
Set<SourceVersion> expected = EnumSet.noneOf(SourceVersion.class);
for (String arg : args)
expected.add(SourceVersion.valueOf(arg));
Set<SourceVersion> found = compiler.getSourceVersions();
Set<SourceVersion> notExpected = EnumSet.copyOf(found);
for (SourceVersion version : expected) {
if (!found.contains(version))
throw new AssertionError("Expected source version not found: " + version);
else
notExpected.remove(version);
}
if (!notExpected.isEmpty())
throw new AssertionError("Unexpected source versions: " + notExpected);
}
示例2: run
import javax.tools.Tool; //导入依赖的package包/类
public void run() throws Exception {
Optional<Tool> opt = findFirst("javadoc");
if (!opt.isPresent()) {
throw new Exception("tool not found");
}
if (!(opt.get() instanceof JavadocTool)) {
throw new Exception("unexpected tool found");
}
}
示例3: findFirst
import javax.tools.Tool; //导入依赖的package包/类
Optional<Tool> findFirst(String name) {
getClass().getModule().addUses(Tool.class);
for (Tool p : ServiceLoader.load(Tool.class,
ClassLoader.getSystemClassLoader())) {
if (p.name().equals(name)) {
return Optional.of(p);
}
}
return Optional.empty();
}
示例4: runShellServiceLoader
import javax.tools.Tool; //导入依赖的package包/类
private int runShellServiceLoader(String... args) {
ServiceLoader<Tool> sl = ServiceLoader.load(Tool.class);
for (Tool provider : sl) {
if (provider.name().equals("jshell")) {
return provider.run(cmdInStream, cmdout, cmderr, args);
}
}
throw new AssertionError("Repl tool not found by ServiceLoader: " + sl);
}
示例5: compile
import javax.tools.Tool; //导入依赖的package包/类
static void compile(String... args) {
StringBuffer sb = new StringBuffer("compile:");
for (String a: args)
sb.append(' ').append(a);
System.err.println(sb);
Tool t = ToolProvider.getSystemJavaCompiler();
int rc = t.run(System.in, System.out, System.err, args);
System.out.flush();
System.err.flush();
if (rc != 0)
throw new Error("compilation failed");
}
示例6: run
import javax.tools.Tool; //导入依赖的package包/类
public void run() throws Exception {
Optional<Tool> opt = findFirst("javac");
if (!opt.isPresent()) {
throw new Exception("tool not found");
}
if (!(opt.get() instanceof JavacTool)) {
throw new Exception("unexpected tool found");
}
}
示例7: compileJava
import javax.tools.Tool; //导入依赖的package包/类
public void compileJava(List<JavacOption> options, List<File> sourceFiles)
{
List<String> args = ImmutableList.<String>builder()
.addAll(options.stream().map(JavacOption::getArgs).flatMap(List::stream).iterator())
.addAll(sourceFiles.stream().map(File::getPath).iterator())
.build();
Tool javac = ToolProvider.getSystemJavaCompiler();
javac.run(null, null, null, args.toArray(new String[args.size()]));
}
示例8: run
import javax.tools.Tool; //导入依赖的package包/类
static int run(InputStream in, OutputStream out, OutputStream err, String... arguments) {
ServiceLoader<Tool> loader = ServiceLoader.load(Tool.class, JShellConfigRunner.class.getClassLoader());
Tool jshell = loader.stream()
.map(provider -> provider.get())
.filter(tool -> tool.name().equals("jshell"))
.findFirst()
.orElseThrow(() -> new IllegalStateException("can not find jshell"));
return jshell.run(in, out, err, arguments);
}
示例9: doCompile
import javax.tools.Tool; //导入依赖的package包/类
protected static int doCompile(String dir, String classpath, List<String> files, OutputStream out, OutputStream err) {
List<String> args = new ArrayList<String>();
args.add("-target");
args.add("1.5");
args.add("-d");
args.add(dir);
args.add("-cp");
args.add(classpath);
Tool compiler = null;
for (String f : files) {
Tool ftool;
if (f.endsWith(".f3"))
ftool = f3c;
else if (f.endsWith(".java"))
ftool = javac;
else
ftool = null;
if (compiler != null && ftool != null && ftool != compiler) {
throw new IllegalArgumentException("cannot compile both .java and .f3 with same compiler");
}
compiler = ftool;
args.add(f);
}
if (compiler == null)
compiler = f3c;
return compiler.run(null, out, err, args.toArray(new String[args.size()]));
}