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

The following examples show how to use javax.tools.JavaFileManager#list() . 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: EncoderManager.java    From PacketProxy with Apache License 2.0 6 votes vote down vote up
private void loadModules() throws Exception {
	isDuplicated = false;
	module_list = new HashMap<String,Class<Encoder>>();
	JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
	JavaFileManager fm = compiler.getStandardFileManager(new DiagnosticCollector<JavaFileObject>(), null, null);

	Set<JavaFileObject.Kind> kind = Sets.newHashSet(JavaFileObject.Kind.CLASS);
	for (JavaFileObject f : fm.list(StandardLocation.CLASS_PATH, encode_package, kind, false)) {
		Path encode_file_path = Paths.get(f.getName());
		Path encode_file_name = encode_file_path.getFileName();
		String encode_class_path = encode_package + "." + encode_file_name.toString().replaceAll("\\.class.*$", "");
		Class klass = Class.forName(encode_class_path);
		if(encode_class.isAssignableFrom(klass) && !Modifier.isAbstract(klass.getModifiers())){
               @SuppressWarnings("unchecked")
			Encoder encoder = createInstance((Class<Encoder>)klass, null);
			module_list.put(encoder.getName(), klass);
		}
	}
	loadModulesFromJar(module_list);
}
 
Example 2
Source File: PPContextMenuManager.java    From PacketProxy with Apache License 2.0 6 votes vote down vote up
private void loadItems() throws Exception {
	module_list = new ArrayList<PPContextMenu>();
	JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
	JavaFileManager fm = compiler.getStandardFileManager(new DiagnosticCollector<JavaFileObject>(), null, null);

	Set<JavaFileObject.Kind> kind = Sets.newHashSet(JavaFileObject.Kind.CLASS);
	for (JavaFileObject f : fm.list(StandardLocation.CLASS_PATH, item_package, kind, false)) {
		Path item_file_path = Paths.get(f.getName());
		Path item_file_name = item_file_path.getFileName();
		String item_class_path = item_package + "." + item_file_name.toString().replaceAll("\\.class.*$", "");

           @SuppressWarnings("rawtypes")
		Class klass = Class.forName(item_class_path);
		if(item_class.isAssignableFrom(klass) && !Modifier.isAbstract(klass.getModifiers())){
               @SuppressWarnings("unchecked")
			PPContextMenu ppcm = createInstance(klass);	
			module_list.add(ppcm);
		}
	}
}
 
Example 3
Source File: ClasspathInfoTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void DISABLEtestMemoryFileManager () throws Exception {
    final ClassPath scp = createSourcePath(FileUtil.toFileObject(this.getWorkDir()));
    createJavaFile(scp.getRoots()[0], "org/me/Lib.java", "package org.me;\n class Lib {}\n");
    TransactionContext tx = TransactionContext.beginStandardTransaction(scp.getRoots()[0].toURL(), true, ()->true, false);
    try {
        final ClasspathInfo cpInfo = ClasspathInfoAccessor.getINSTANCE().create( bootPath, ClassPath.EMPTY, classPath, ClassPath.EMPTY, ClassPath.EMPTY, scp, ClassPath.EMPTY, null, true, true, true, false, false, null);
        final JavaFileManager fm = ClasspathInfoAccessor.getINSTANCE().createFileManager(cpInfo, null);
        Iterable<JavaFileObject> jfos = fm.list(StandardLocation.SOURCE_PATH, "org.me", EnumSet.of(JavaFileObject.Kind.SOURCE), false);
        assertEquals (new String[] {"org.me.Lib"}, jfos, fm);
        ClasspathInfoAccessor.getINSTANCE().registerVirtualSource(cpInfo, FileObjects.memoryFileObject("org.me","Main.java",
        null,System.currentTimeMillis(),"package org.me;\n class Main{}\n"));
        jfos = fm.list(StandardLocation.SOURCE_PATH, "org.me", EnumSet.of(JavaFileObject.Kind.SOURCE), false);
        assertEquals (new String[] {"org.me.Lib","org.me.Main"}, jfos, fm);
        ClasspathInfoAccessor.getINSTANCE().unregisterVirtualSource(cpInfo, "org.me.Main");
        jfos = fm.list(StandardLocation.SOURCE_PATH, "org.me", EnumSet.of(JavaFileObject.Kind.SOURCE), false);
        assertEquals (new String[] {"org.me.Lib"}, jfos, fm);
    } finally {
        TransactionContext.get().commit();
    }
}
 
Example 4
Source File: DefaultSourceOnlyAbiRuleInfo.java    From buck with Apache License 2.0 6 votes vote down vote up
private Set<String> getBootclasspathPackageContents(String packageName) {
  Set<String> packageContents = packagesContents.get(packageName);
  if (packageContents == null) {
    packageContents = new HashSet<>();

    try {
      JavaFileManager fileManager = getFileManager();
      for (JavaFileObject javaFileObject :
          fileManager.list(
              StandardLocation.PLATFORM_CLASS_PATH,
              packageName,
              EnumSet.of(JavaFileObject.Kind.CLASS),
              true)) {
        packageContents.add(
            fileManager.inferBinaryName(StandardLocation.PLATFORM_CLASS_PATH, javaFileObject));
      }
    } catch (IOException e) {
      throw new HumanReadableException(e, "Failed to list boot classpath contents.");
      // Do nothing
    }
    packagesContents.put(packageName, packageContents);
  }
  return packageContents;
}
 
Example 5
Source File: JarTask.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void addPackage(JavaFileManager fm, JavaFileManager.Location l, String pkg, boolean recurse)
        throws IOException {
    for (JavaFileObject fo : fm.list(l, pkg, EnumSet.allOf(JavaFileObject.Kind.class), recurse)) {
        fileObjects.add(fo);
    }
}