本文整理汇总了Java中javax.tools.StandardJavaFileManager.setLocationFromPaths方法的典型用法代码示例。如果您正苦于以下问题:Java StandardJavaFileManager.setLocationFromPaths方法的具体用法?Java StandardJavaFileManager.setLocationFromPaths怎么用?Java StandardJavaFileManager.setLocationFromPaths使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.tools.StandardJavaFileManager
的用法示例。
在下文中一共展示了StandardJavaFileManager.setLocationFromPaths方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compile
import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
/**
* Compile all the java sources in {@code <source>/**} to
* {@code <destination>/**}. The destination directory will be created if
* it doesn't exist.
*
* All warnings/errors emitted by the compiler are output to System.out/err.
*
* @return true if the compilation is successful
*
* @throws IOException if there is an I/O error scanning the source tree or
* creating the destination directory
*/
public static boolean compile(Path source, Path destination, String ... options)
throws IOException
{
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager jfm = compiler.getStandardFileManager(null, null, null);
List<Path> sources
= Files.find(source, Integer.MAX_VALUE,
(file, attrs) -> (file.toString().endsWith(".java")))
.collect(Collectors.toList());
Files.createDirectories(destination);
jfm.setLocationFromPaths(StandardLocation.CLASS_OUTPUT,
Arrays.asList(destination));
List<String> opts = Arrays.asList(options);
JavaCompiler.CompilationTask task
= compiler.getTask(null, jfm, null, opts, null,
jfm.getJavaFileObjectsFromPaths(sources));
return task.call();
}
示例2: compile
import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
/**
* Compile all the java sources in {@code <source>/**} to
* {@code <destination>/**}. The destination directory will be created if
* it doesn't exist.
*
* All warnings/errors emitted by the compiler are output to System.out/err.
*
* @return true if the compilation is successful
*
* @throws IOException if there is an I/O error scanning the source tree or
* creating the destination directory
*/
public static boolean compile(Path source, Path destination, String... options)
throws IOException
{
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager jfm = compiler.getStandardFileManager(null, null, null);
List<Path> sources
= Files.find(source, Integer.MAX_VALUE,
(file, attrs) -> (file.toString().endsWith(".java")))
.collect(Collectors.toList());
Files.createDirectories(destination);
jfm.setLocationFromPaths(StandardLocation.CLASS_OUTPUT,
Arrays.asList(destination));
List<String> opts = Arrays.asList(options);
JavaCompiler.CompilationTask task
= compiler.getTask(null, jfm, null, opts, null,
jfm.getJavaFileObjectsFromPaths(sources));
return task.call();
}
示例3: compileModule
import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
/**
* Compile the specified module from the given module sourcepath
*
* All warnings/errors emitted by the compiler are output to System.out/err.
*
* @return true if the compilation is successful
*
* @throws IOException if there is an I/O error scanning the source tree or
* creating the destination directory
*/
public static boolean compileModule(Path source, Path destination,
String moduleName, String... options) {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager jfm = compiler.getStandardFileManager(null, null, null);
try {
Files.createDirectories(destination);
jfm.setLocationFromPaths(StandardLocation.CLASS_OUTPUT,
Arrays.asList(destination));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Stream<String> opts = Arrays.stream(new String[] {
"--module-source-path", source.toString(), "-m", moduleName
});
List<String> javacOpts = Stream.concat(opts, Arrays.stream(options))
.collect(Collectors.toList());
JavaCompiler.CompilationTask task
= compiler.getTask(null, jfm, null, javacOpts, null, null);
return task.call();
}
示例4: test_setPaths_getFiles
import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
void test_setPaths_getFiles(StandardJavaFileManager fm, List<Path> inPaths) throws IOException {
System.err.println("test_setPaths_getFiles");
JavaFileManager.Location l = newLocation();
fm.setLocationFromPaths(l, inPaths);
Iterable<? extends File> outFiles = fm.getLocation(l);
compare(inPaths, outFiles);
}
示例5: test_setPaths_getPaths
import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
void test_setPaths_getPaths(StandardJavaFileManager fm, List<Path> inPaths) throws IOException {
System.err.println("test_setPaths_getPaths");
JavaFileManager.Location l = newLocation();
fm.setLocationFromPaths(l, inPaths);
Iterable<? extends Path> outPaths = fm.getLocationAsPaths(l);
compare(inPaths, outPaths);
}
示例6: compile
import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
/**
* Compile all the java sources in {@code <source>/**} to
* {@code <destination>/**}. The destination directory will be created if
* it doesn't exist.
*
* All warnings/errors emitted by the compiler are output to System.out/err.
*
* @return true if the compilation is successful
*
* @throws IOException
* if there is an I/O error scanning the source tree or
* creating the destination directory
* @throws UnsupportedOperationException
* if there is no system java compiler
*/
public static boolean compile(Path source, Path destination, String... options)
throws IOException
{
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler == null) {
// no compiler available
throw new UnsupportedOperationException("Unable to get system java compiler. "
+ "Perhaps, jdk.compiler module is not available.");
}
StandardJavaFileManager jfm = compiler.getStandardFileManager(null, null, null);
List<Path> sources
= Files.find(source, Integer.MAX_VALUE,
(file, attrs) -> (file.toString().endsWith(".java")))
.collect(Collectors.toList());
Files.createDirectories(destination);
jfm.setLocation(StandardLocation.CLASS_PATH, Collections.emptyList());
jfm.setLocationFromPaths(StandardLocation.CLASS_OUTPUT,
Collections.singletonList(destination));
List<String> opts = Arrays.asList(options);
JavaCompiler.CompilationTask task
= compiler.getTask(null, jfm, null, opts, null,
jfm.getJavaFileObjectsFromPaths(sources));
return task.call();
}
示例7: handleReleaseOptions
import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
/**
* Handles the {@code --release} option.
*
* @param additionalOptions a predicate to handle additional options implied by the
* {@code --release} option. The predicate should return true if all the additional
* options were processed successfully.
* @return true if successful, false otherwise
*/
public boolean handleReleaseOptions(Predicate<Iterable<String>> additionalOptions) {
String platformString = options.get(Option.RELEASE);
checkOptionAllowed(platformString == null,
option -> error("err.release.bootclasspath.conflict", option.getPrimaryName()),
Option.BOOT_CLASS_PATH, Option.XBOOTCLASSPATH, Option.XBOOTCLASSPATH_APPEND,
Option.XBOOTCLASSPATH_PREPEND,
Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS,
Option.EXTDIRS, Option.DJAVA_EXT_DIRS,
Option.SOURCE, Option.TARGET,
Option.SYSTEM, Option.UPGRADE_MODULE_PATH);
if (platformString != null) {
PlatformDescription platformDescription = PlatformUtils.lookupPlatformDescription(platformString);
if (platformDescription == null) {
error("err.unsupported.release.version", platformString);
return false;
}
options.put(Option.SOURCE, platformDescription.getSourceVersion());
options.put(Option.TARGET, platformDescription.getTargetVersion());
context.put(PlatformDescription.class, platformDescription);
if (!additionalOptions.test(platformDescription.getAdditionalOptions()))
return false;
Collection<Path> platformCP = platformDescription.getPlatformPath();
if (platformCP != null) {
JavaFileManager fm = getFileManager();
if (!(fm instanceof StandardJavaFileManager)) {
error("err.release.not.standard.file.manager");
return false;
}
try {
StandardJavaFileManager sfm = (StandardJavaFileManager) fm;
if (Source.instance(context).allowModules()) {
sfm.handleOption("--system", Arrays.asList("none").iterator());
sfm.setLocationFromPaths(StandardLocation.UPGRADE_MODULE_PATH, platformCP);
} else {
sfm.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, platformCP);
}
} catch (IOException ex) {
log.printLines(PrefixKind.JAVAC, "msg.io");
ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
return false;
}
}
}
return true;
}