Java Code Examples for javax.tools.StandardLocation#MODULE_PATH

The following examples show how to use javax.tools.StandardLocation#MODULE_PATH . 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: JavapTask.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Location findModule(String moduleName) throws IOException {
    Location[] locns = {
        StandardLocation.UPGRADE_MODULE_PATH,
        StandardLocation.SYSTEM_MODULES,
        StandardLocation.MODULE_PATH
    };
    for (Location segment: locns) {
        for (Set<Location> set: fileManager.listLocationsForModules(segment)) {
            Location result = null;
            for (Location l: set) {
                String name = fileManager.inferModuleName(l);
                if (name.equals(moduleName)) {
                    if (result == null)
                        result = l;
                    else
                        throw new IOException("multiple definitions found for " + moduleName);
                }
            }
            if (result != null)
                return result;
        }
    }
    return null;
}
 
Example 2
Source File: Locations.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void initHandlers() {
    handlersForLocation = new HashMap<>();
    handlersForOption = new EnumMap<>(Option.class);

    BasicLocationHandler[] handlers = {
        new BootClassPathLocationHandler(StandardLocation.PLATFORM_CLASS_PATH),
        new BootClassPathLocationHandler(StandardLocation.SYSTEM_MODULES),
        new ClassFileLocationHandler(),
        new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCE_PATH),
        new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSOR_PATH),
        new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, Option.PROCESSOR_MODULE_PATH),
        new OutputLocationHandler(StandardLocation.CLASS_OUTPUT, Option.D),
        new OutputLocationHandler(StandardLocation.SOURCE_OUTPUT, Option.S),
        new OutputLocationHandler(StandardLocation.NATIVE_HEADER_OUTPUT, Option.H),
        new ModuleSourceFileLocationHandler(),
        new PatchModulesLocationHandler(),
        new ModuleFileLocationHandler(StandardLocation.UPGRADE_MODULE_PATH, Option.UPGRADE_MODULE_PATH),
        new ModuleFileLocationHandler(StandardLocation.MODULE_PATH, Option.MODULE_PATH)
    };

    for (BasicLocationHandler h : handlers) {
        handlersForLocation.put(h.location, h);
        for (Option o : h.options) {
            handlersForOption.put(o, h);
        }
    }
}
 
Example 3
Source File: ProxyFileManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
private JavaFileManager createModuleFileManager() {
    if (emitted[USER_MODULES] == null) {
        emitted[USER_MODULES] = new ModuleFileManager(
            cap,
            moduleCompile,
            peersMap.getOrDefault(moduleCompile, ROOT_TO_COLLECTION),
            sourceLevel,
            StandardLocation.MODULE_PATH,
            false);
    }
    return emitted[USER_MODULES];
}
 
Example 4
Source File: ProxyFileManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@CheckForNull
private JavaFileManager createPatchFileManager() {
    if (emitted[MODULE_PATCHES] == null) {
        emitted[MODULE_PATCHES] = new PatchModuleFileManager(
                new ModuleFileManager(cap, ClassPath.EMPTY, ROOT_TO_COLLECTION, sourceLevel, StandardLocation.MODULE_PATH, false),
                new ModuleSourceFileManager(ClassPath.EMPTY, ClassPath.EMPTY, ignoreExcludes),
                this.src
        );
    }
    return emitted[MODULE_PATCHES];
}
 
Example 5
Source File: MRJARModuleFileManagerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testList() throws IOException {
    //Source level 9, broken jar
    ModuleFileManager fm = new ModuleFileManager(
            CachingArchiveProvider.getDefault(),
            bCp,
            (u)->Collections.singleton(u),
            SourceLevelUtils.JDK1_9,
            StandardLocation.MODULE_PATH,
            false);
    JavaFileManager.Location l = StreamSupport.stream(fm.listLocationsForModules(StandardLocation.MODULE_PATH).spliterator(), true)
            .flatMap((s)->s.stream())
            .findFirst()
            .orElse(null);
    assertNotNull(l);
    Iterable<JavaFileObject> res = fm.list(l, "org.me", EnumSet.of(JavaFileObject.Kind.CLASS), false);    //NOI18N
    assertEquals(Arrays.asList("A Base","B Base"), toContent(res));  //NOI18N
    assertEquals(Arrays.asList("org.me.A","org.me.B"), toInferedName(fm, res));  //NOI18N
    //Source level 9, multi release jar
    fm = new ModuleFileManager(
            CachingArchiveProvider.getDefault(),
            mvCp,
            (u)->Collections.singleton(u),
            SourceLevelUtils.JDK1_9,
            StandardLocation.MODULE_PATH,
            false);
    l = StreamSupport.stream(fm.listLocationsForModules(StandardLocation.MODULE_PATH).spliterator(), true)
            .flatMap((s)->s.stream())
            .findFirst()
            .orElse(null);
    assertNotNull(l);
    res = fm.list(l, "org.me", EnumSet.of(JavaFileObject.Kind.CLASS), false);    //NOI18N
    assertEquals(Arrays.asList("A 9","B Base"), toContent(res));  //NOI18N
    assertEquals(Arrays.asList("org.me.A","org.me.B"), toInferedName(fm, res));  //NOI18N
}
 
Example 6
Source File: MRJARModuleFileManagerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testListRecursive() throws IOException {
    //Source level 9, broken jar
    ModuleFileManager fm = new ModuleFileManager(
            CachingArchiveProvider.getDefault(),
            bCp,
            (u)->Collections.singleton(u),
            SourceLevelUtils.JDK1_9,
            StandardLocation.MODULE_PATH,
            false);
    JavaFileManager.Location l = StreamSupport.stream(fm.listLocationsForModules(StandardLocation.MODULE_PATH).spliterator(), true)
            .flatMap((s)->s.stream())
            .findFirst()
            .orElse(null);
    assertNotNull(l);
    Iterable<JavaFileObject> res = fm.list(l, "", EnumSet.of(JavaFileObject.Kind.CLASS), true);    //NOI18N
    assertEquals(Arrays.asList("A Base", "B Base", "N Base"), toContent(res));  //NOI18N
    assertEquals(Arrays.asList("org.me.A", "org.me.B", "org.nb.N"), toInferedName(fm, res));  //NOI18N
    //Source level 9, multi release jar
    fm = new ModuleFileManager(
            CachingArchiveProvider.getDefault(),
            mvCp,
            (u)->Collections.singleton(u),
            SourceLevelUtils.JDK1_9,
            StandardLocation.MODULE_PATH,
            false);
    l = StreamSupport.stream(fm.listLocationsForModules(StandardLocation.MODULE_PATH).spliterator(), true)
            .flatMap((s)->s.stream())
            .findFirst()
            .orElse(null);
    assertNotNull(l);
    res = fm.list(l, "", EnumSet.of(JavaFileObject.Kind.CLASS), true);    //NOI18N
    assertEquals(Arrays.asList("A 9", "B Base", "N Base"), toContent(res));  //NOI18N
    assertEquals(Arrays.asList("org.me.A", "org.me.B", "org.nb.N"), toInferedName(fm, res));  //NOI18N
}
 
Example 7
Source File: MRJARModuleFileManagerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testGetJavaFileForInput() throws IOException {
    //Source level 9, broken jar
    ModuleFileManager fm = new ModuleFileManager(
            CachingArchiveProvider.getDefault(),
            bCp,
            (u)->Collections.singleton(u),
            SourceLevelUtils.JDK1_9,
            StandardLocation.MODULE_PATH,
            false);
    JavaFileManager.Location l = StreamSupport.stream(fm.listLocationsForModules(StandardLocation.MODULE_PATH).spliterator(), true)
            .flatMap((s)->s.stream())
            .findFirst()
            .orElse(null);
    assertNotNull(l);
    JavaFileObject res = fm.getJavaFileForInput(l, "org.me.A", JavaFileObject.Kind.CLASS);
    assertEquals(Arrays.asList("A Base"), toContent(Collections.<JavaFileObject>singleton(res)));  //NOI18N
    assertEquals(Arrays.asList("org.me.A"), toInferedName(fm, Collections.<JavaFileObject>singleton(res)));  //NOI18N
    //Source level 9, multi release jar
    fm = new ModuleFileManager(
            CachingArchiveProvider.getDefault(),
            mvCp,
            (u)->Collections.singleton(u),
            SourceLevelUtils.JDK1_9,
            StandardLocation.MODULE_PATH,
            false);
    l = StreamSupport.stream(fm.listLocationsForModules(StandardLocation.MODULE_PATH).spliterator(), true)
            .flatMap((s)->s.stream())
            .findFirst()
            .orElse(null);
    assertNotNull(l);
    res = fm.getJavaFileForInput(l, "org.me.A", JavaFileObject.Kind.CLASS);
    assertEquals(Arrays.asList("A 9"), toContent(Collections.<JavaFileObject>singleton(res)));  //NOI18N
    assertEquals(Arrays.asList("org.me.A"), toInferedName(fm, Collections.<JavaFileObject>singleton(res)));  //NOI18N
}
 
Example 8
Source File: Locations.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void initHandlers() {
    handlersForLocation = new HashMap<>();
    handlersForOption = new EnumMap<>(Option.class);

    BasicLocationHandler[] handlers = {
        new BootClassPathLocationHandler(),
        new ClassPathLocationHandler(),
        new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCE_PATH),
        new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSOR_PATH),
        new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, Option.PROCESSOR_MODULE_PATH),
        new OutputLocationHandler(StandardLocation.CLASS_OUTPUT, Option.D),
        new OutputLocationHandler(StandardLocation.SOURCE_OUTPUT, Option.S),
        new OutputLocationHandler(StandardLocation.NATIVE_HEADER_OUTPUT, Option.H),
        new ModuleSourcePathLocationHandler(),
        new PatchModulesLocationHandler(),
        new ModulePathLocationHandler(StandardLocation.UPGRADE_MODULE_PATH, Option.UPGRADE_MODULE_PATH),
        new ModulePathLocationHandler(StandardLocation.MODULE_PATH, Option.MODULE_PATH),
        new SystemModulesLocationHandler(),
    };

    for (BasicLocationHandler h : handlers) {
        handlersForLocation.put(h.location, h);
        for (Option o : h.options) {
            handlersForOption.put(o, h);
        }
    }
}
 
Example 9
Source File: SetLocationForModule.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testModulePath(Path base) throws IOException {
    try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
        Path src = base.resolve("src");
        Path src_m = src.resolve("m");
        tb.writeJavaFiles(src_m, "module m { }");

        Location locn = StandardLocation.MODULE_PATH;

        Path modules1 = Files.createDirectories(base.resolve("modules1"));
        new JavacTask(tb)
                .outdir(modules1)
                .options("--module-source-path", src.toString())
                .files(tb.findJavaFiles(src))
                .run();
        fm.setLocationFromPaths(locn, List.of(modules1));

        Location m = fm.getLocationForModule(locn, "m");
        checkEqual("default setting",
                fm.getLocationAsPaths(m), modules1.resolve("m"));

        Path override1 = Files.createDirectories(base.resolve("override1"));
        fm.setLocationForModule(locn, "m", List.of(override1));
        checkEqual("override setting 1",
                fm.getLocationAsPaths(m), override1);

        Path override2 = Files.createDirectories(base.resolve("override2"));
        fm.setLocationFromPaths(m, List.of(override2));
        checkEqual("override setting 2",
                fm.getLocationAsPaths(m), override2);

        Path modules2 = Files.createDirectories(base.resolve("modules2"));
        fm.setLocationFromPaths(locn, List.of(modules2));

        checkEqual("updated setting",
                fm.getLocationAsPaths(m), modules2.resolve("m"));
    }
}