Java Code Examples for javax.tools.JavaFileManager#listLocationsForModules()

The following examples show how to use javax.tools.JavaFileManager#listLocationsForModules() . 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: SourceUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returns names of all modules within given scope.
 * @param info the CompilationInfo used to resolve modules
 * @param scope to search in {@see SearchScope}
 * @return set of module names
 * @since 2.23
 */
public static Set<String> getModuleNames(CompilationInfo info, final @NonNull Set<? extends ClassIndex.SearchScopeType> scope) {
    Set<String> ret = new HashSet<>();
    JavaFileManager jfm = info.impl.getJavacTask().getContext().get(JavaFileManager.class);
    if (jfm != null) {
        List<JavaFileManager.Location> toSearch = new ArrayList<>();
        for (ClassIndex.SearchScopeType s : scope) {
            if (s.isSources()) {
                toSearch.add(StandardLocation.MODULE_SOURCE_PATH);
            }
            if (s.isDependencies()) {
                toSearch.add(StandardLocation.MODULE_PATH);
                toSearch.add(StandardLocation.UPGRADE_MODULE_PATH);
                toSearch.add(StandardLocation.SYSTEM_MODULES);
            }
        }
        try {
            for (JavaFileManager.Location searchLocation : toSearch) {
                for (Set<JavaFileManager.Location> locations : jfm.listLocationsForModules(searchLocation)) {
                    for (JavaFileManager.Location location : locations) {
                        ret.add(jfm.inferModuleName(location));
                    }
                }
            }
        } catch (IOException ioe) {}
    }
    return ret;
}
 
Example 2
Source File: ModuleOraculumTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void assertPatchModules(JavacTaskImpl impl, String... expectedPatches) throws IOException {
    JavaFileManager fm = impl.getContext().get(JavaFileManager.class);
    for (String expected : expectedPatches) {
        assertNotNull(fm.getLocationForModule(StandardLocation.PATCH_MODULE_PATH, expected));
    }
    Set<String> actualNames = new HashSet<>();
    for (Set<Location> locations : fm.listLocationsForModules(StandardLocation.PATCH_MODULE_PATH)) {
        actualNames.add(fm.inferModuleName(locations.iterator().next()));
    }
    assertEquals(new HashSet<>(Arrays.asList(expectedPatches)), actualNames);
}