javax.tools.StandardJavaFileManager#setLocationFromPaths ( )源码实例Demo

下面列出了javax.tools.StandardJavaFileManager#setLocationFromPaths ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk9   文件: CompilerUtils.java
/**
 * 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 项目: openjdk-jdk9   文件: CompilerUtils.java
/**
 * 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 项目: openjdk-jdk9   文件: CompilerUtils.java
/**
 * 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 项目: openjdk-jdk9   文件: CompilerUtils.java
/**
 * 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.setLocation(StandardLocation.CLASS_PATH, Collections.EMPTY_LIST);
    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();
}
 
源代码5 项目: dragonwell8_jdk   文件: TestModularizedEvent.java
private 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,
            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();
}
 
源代码6 项目: TencentKona-8   文件: TestModularizedEvent.java
private 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,
            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();
}
 
源代码7 项目: TencentKona-8   文件: CompilerUtils.java
/**
  * Compile all the java sources in {@code <source>} and optionally its
  * subdirectories, 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.
  *
  * @param source Path to the source directory
  * @param destination Path to the destination directory
  * @param recurse If {@code true} recurse into any {@code source} subdirectories
  *        to compile all java source files; else only compile those directly in
  *        {@code source}.
  * @param options Any options to pass to the compiler
  *
  * @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, boolean recurse, 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, (recurse ? Integer.MAX_VALUE : 1),
             (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();
 }
 
源代码8 项目: openjdk-jdk8u   文件: TestModularizedEvent.java
private 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,
            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();
}
 
源代码9 项目: openjdk-jdk8u   文件: CompilerUtils.java
/**
  * Compile all the java sources in {@code <source>} and optionally its
  * subdirectories, 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.
  *
  * @param source Path to the source directory
  * @param destination Path to the destination directory
  * @param recurse If {@code true} recurse into any {@code source} subdirectories
  *        to compile all java source files; else only compile those directly in
  *        {@code source}.
  * @param options Any options to pass to the compiler
  *
  * @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, boolean recurse, 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, (recurse ? Integer.MAX_VALUE : 1),
             (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();
 }
 
源代码10 项目: openjdk-jdk9   文件: SJFM_Locations.java
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);
}
 
源代码11 项目: openjdk-jdk9   文件: SJFM_Locations.java
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);
}
 
源代码12 项目: openjdk-jdk9   文件: CompilerUtils.java
/**
 * 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.EMPTY_LIST);
    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();
}
 
源代码13 项目: openjdk-jdk9   文件: Arguments.java
/**
 * 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;
}