Java源码示例:org.netbeans.spi.java.classpath.support.ClassPathSupport

示例1
private List<PathResourceImplementation> getPath() {
    List<PathResourceImplementation> result = new ArrayList<>();
    for (String p : propertyNames) {
        String prop = evaluator.getProperty(p);
        if (prop != null) {
            for (String piece : PropertyUtils.tokenizePath(prop)) {
                File f = PropertyUtils.resolveFile(projectFolder, piece);
                URL entry = FileUtil.urlForArchiveOrDir(f);
                if (entry != null) {
                    result.add(ClassPathSupport.createResource(entry));
                } else {
                    Logger.getLogger(ProjectClassPathImplementation.class.getName()).log(Level.WARNING, "{0} does not look like a valid archive file", f);
                }
            }
        }
    }
    return Collections.unmodifiableList(result);
}
 
示例2
private static ClassPath extendClassPathWithJaxRsApisIfNecessary(ClassPath classPath) {
    if (classPath.findResource("javax/ws/rs/core/Application.class") != null) {
        return classPath;
    }
    File jerseyRoot = InstalledFileLocator.getDefault().locate(JERSEY_API_LOCATION, "org.netbeans.modules.websvc.restlib", false);
    if (jerseyRoot != null && jerseyRoot.isDirectory()) {
        File[] jsr311Jars = jerseyRoot.listFiles(new MiscPrivateUtilities.JerseyFilter(JSR311_JAR_PATTERN));
        if (jsr311Jars != null && jsr311Jars.length>0) {
            FileObject fo = FileUtil.toFileObject(jsr311Jars[0]);
            if (fo != null) {
                fo = FileUtil.getArchiveRoot(fo);
                if (fo != null) {
                    return ClassPathSupport.createProxyClassPath(classPath,
                            ClassPathSupport.createClassPath(fo));
                }
            }
        }
    }
    return classPath;
}
 
示例3
/**
 * This implementation simply reads and parses `java.class.path' property and creates a ClassPath
 * out of it.
 * @return  ClassPath that represents contents of system property java.class.path.
 */
@Override
public ClassPath getStandardLibraries() {
    synchronized (this) {
        ClassPath cp = (standardLibs == null ? null : standardLibs.get());
        if (cp != null)
            return cp;
        final String pathSpec = getSystemProperties().get(SYSPROP_JAVA_CLASS_PATH);
        if (pathSpec == null) {
            cp = ClassPathSupport.createClassPath(new URL[0]);
        }
        else {
            cp = Util.createClassPath (pathSpec);
        }
        standardLibs = new SoftReference<>(cp);
        return cp;
    }
}
 
示例4
public static ClassPath projecRuntimeClassPath(Project project) {
    if (project == null) {
        return null;
    }
    boolean modular = isModularProject(project);
    List<ClassPath> delegates = new ArrayList<>();
    for (SourceGroup sg : org.netbeans.api.project.ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
        if (!isNormalRoot(sg)) {
            continue;
        }
        ClassPath del; 
        if (modular) {
            del = ClassPath.getClassPath(sg.getRootFolder(), JavaClassPathConstants.MODULE_EXECUTE_CLASS_PATH);
        } else {
            del = ClassPath.getClassPath(sg.getRootFolder(), ClassPath.EXECUTE); 
        }
        if (del != null && !del.entries().isEmpty()) {
            delegates.add(del);
        }
    }
    return ClassPathSupport.createProxyClassPath(delegates.toArray(new ClassPath[delegates.size()]));
}
 
示例5
public void testCycle () throws Exception {
    GlobalPathRegistry regs = GlobalPathRegistry.getDefault();
    Set<ClassPath> toCleanUp = regs.getPaths(ClassPath.COMPILE);        
    regs.unregister(ClassPath.COMPILE, toCleanUp.toArray(new ClassPath[toCleanUp.size()]));
    toCleanUp = regs.getPaths(ClassPath.EXECUTE);        
    regs.unregister(ClassPath.EXECUTE, toCleanUp.toArray(new ClassPath[toCleanUp.size()]));
    File wdf = getWorkDir();
    FileObject wd = FileUtil.toFileObject(wdf);
    FileObject root1 = wd.createFolder("root1");
    FileObject root2 = wd.createFolder("root2");
    ClassPathProvider cpp = new DefaultClassPathProvider ();
    ClassPath dcp = cpp.findClassPath(root2, ClassPath.COMPILE);
    ClassPath cp = ClassPathSupport.createClassPath(new FileObject[] {root1});
    regs.register(ClassPath.COMPILE, new ClassPath[] {cp});        
    assertNotNull(dcp);
    FileObject[] roots = dcp.getRoots();
    assertEquals(1, roots.length);
    assertEquals(root1, roots[0]);
    
    regs.register(ClassPath.COMPILE, new ClassPath[] {dcp});
    roots = dcp.getRoots();
    assertEquals(1, roots.length);        
}
 
示例6
public ClassPath findClassPath(FileObject file, String type) {
    try {
    if (ClassPath.BOOT == type) {
        // XXX simpler to use JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries()
        return ClassPathSupport.createClassPath(getBootClassPath().toArray(new URL[0]));
    }

    if (ClassPath.SOURCE == type) {
        return sourcePath;
    }

    if (ClassPath.COMPILE == type) {
        return compileClassPath;
    }

    if (ClassPath.EXECUTE == type) {
        return ClassPathSupport.createClassPath(new FileObject[] {
            buildRoot
        });
    }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
示例7
public void testEmbeddingIndexerOrdering() throws InterruptedException {
    assertTrue(GlobalPathRegistry.getDefault().getPaths(SRC_EMB).isEmpty());
    final RepositoryUpdaterTest.TestHandler handler = new RepositoryUpdaterTest.TestHandler();
    final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests"); //NOI18N
    logger.setLevel (Level.FINEST);
    logger.addHandler(handler);
    try {
        final ClassPath cp = ClassPathSupport.createClassPath(eroot);
        calls.clear();
        globalPathRegistry_register(SRC_EMB, new ClassPath[]{cp});
        assertTrue (handler.await());
        assertEquals(5, calls.size());
        final Iterator<SourceIndexerFactory> callsIt = calls.iterator();
        for (int i=1; i<=5; i++) {
            assertEquals(
                String.format("EI%d",i),    //NOI18N
                callsIt.next().getIndexerName());
        }
        
    } finally {
        logger.removeHandler(handler);
    }
}
 
示例8
public synchronized static final ClassPath getClassPath(final String id, URL[] urls) {
    if (urls.length == 0) {
        return ClassPath.EMPTY;
    } else {
        ClassPath tmp[] = new ClassPath[urls.length];
        for (int i = 0; i < urls.length; i++) {
            ClassPath classPath = cache.get(urls[i]);
            if (classPath == null) {
                classPath = ClassPathSupport.createClassPath(urls[i]);
                cache.put(urls[i], classPath);
            }
            tmp[i] = classPath;
        }
        return ClassPathSupport.createProxyClassPath(tmp);
    }

}
 
示例9
public void DISABLEDtestTypeMirrorHandle196070() throws Exception {
    prepareTest();
    writeIntoFile(testSource, "package test; public class Test<T extends IA & IB> {} interface IA {} interface IB {}");
    ClassPath empty = ClassPathSupport.createClassPath(new URL[0]);
    JavaSource js = JavaSource.create(ClasspathInfo.create(ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0])), empty, empty), testSource);
    final boolean[] finished = new boolean[1];

    js.runUserActionTask(new Task<CompilationController>() {
        public void run(CompilationController info) throws Exception {
            info.toPhase(Phase.RESOLVED);
            TypeMirror tm = info.getTreeUtilities().parseType("T", info.getTopLevelElements().get(0));
            assertTrue(info.getTypes().isSameType(tm, TypeMirrorHandle.create(tm).resolve(info)));
            finished[0] = true;
        }
    }, true);

    assertTrue(finished[0]);
}
 
示例10
private static ClassPath getClassPath(Project project, String type) {
    ClassPathProvider provider = project.getLookup().lookup(
            ClassPathProvider.class);
    if (provider == null) {
        return null;
    }
    Sources sources = ProjectUtils.getSources(project);
    if (sources == null) {
        return null;
    }
    SourceGroup[] sourceGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    for (SourceGroup sourceGroup : sourceGroups) {
        FileObject rootFolder = sourceGroup.getRootFolder();
        ClassPath path = provider.findClassPath(rootFolder, type);
        // return classpath of the first source group, that is ignore test source roots:
        return ClassPathSupport.createProxyClassPath(path);
    }
    return null;
}
 
示例11
public void testCustomIndexerOrdering() throws InterruptedException {
    assertTrue(GlobalPathRegistry.getDefault().getPaths(SRC_FOO).isEmpty());
    final RepositoryUpdaterTest.TestHandler handler = new RepositoryUpdaterTest.TestHandler();
    final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests"); //NOI18N
    logger.setLevel (Level.FINEST);
    logger.addHandler(handler);
    try {
        final ClassPath cp = ClassPathSupport.createClassPath(froot);
        calls.clear();
        globalPathRegistry_register(SRC_FOO, new ClassPath[]{cp});
        assertTrue (handler.await());
        assertEquals(5, calls.size());
        final Iterator<SourceIndexerFactory> callsIt = calls.iterator();
        for (int i=1; i<=5; i++) {
            assertEquals(
                String.format("CI%d",i),    //NOI18N
                callsIt.next().getIndexerName());
        }
    } finally {
        logger.removeHandler(handler);
    }
}
 
示例12
/** Returns Array of the Javadoc Index roots
 */
public URL[] getDocRoots() {
    synchronized (this) {
        if (this.docRoots != null) {
            return docRoots();
        }
    }        
    //XXX must be called out of synchronized block to prevent
    // deadlock. throwCache is called under the ProjectManager.mutex
    // write lock and Project's SFBQI requires the ProjectManager.mutex readLock
    Set<ClassPath> _classpaths = new HashSet<ClassPath>();
    Set<JavadocForBinaryQuery.Result> _results = new HashSet<JavadocForBinaryQuery.Result>();
    Set<URL> s = readRoots(this, _classpaths, _results);
    synchronized (this) {
        if (this.docRoots == null) {
            this.docRoots = ClassPathSupport.createClassPath(s.toArray(new URL[s.size()]));
            this.classpaths = _classpaths;
            this.results = _results;
            registerListeners(this, _classpaths, _results, this.docRoots);
        }
        return docRoots();
    }
}
 
示例13
@CheckForNull
public static FileObject getFile(
        @NonNull final ElementHandle<TypeElement> toResolve,
        @NonNull final ClasspathInfo cpInfo) {
    FileObject res = SourceUtils.getFile(toResolve, cpInfo);
    if (res == null) {
        final ClassPath cp = ClassPathSupport.createProxyClassPath(
                cpInfo.getClassPath(ClasspathInfo.PathKind.BOOT),
                cpInfo.getClassPath(ClasspathInfo.PathKind.COMPILE));
        res = cp.findResource(String.format(
                "%s.%s",    //NOI18N
                toResolve.getBinaryName().replace('.', '/'),    //NOI18N
                CLASS_EXTENSION));
    }
    return res;
}
 
示例14
static ClassPath createJDKSourcePath (
    Project project,
    Path bootclasspath
) {
    if (bootclasspath == null) {
        // if current platform is default one, bootclasspath is set to null
        JavaPlatform jp = JavaPlatform.getDefault();
        if (jp != null) {
            return jp.getSourceFolders ();
        } else {
            return ClassPathSupport.createClassPath(java.util.Collections.EMPTY_LIST);
        }
    } else {
        return convertToSourcePath (project, bootclasspath, false);
    }
}
 
示例15
@Override
protected Map<String, ClassPath> createClassPathsForTest() {
    return Collections.singletonMap(
            PhpSourcePath.SOURCE_CP,
            ClassPathSupport.createClassPath(new FileObject[]{
                FileUtil.toFileObject(new File(getDataDir(), "/testfiles/completion/lib/netbeans68version/paramdecltypes"))
            }));
}
 
示例16
private ClassPath[] findClassPathOrNull(
        @NonNull final FileObject file,
        @NonNull final String type,
        @NonNull final Library lib) {
    if (lib.getType().equals(J2SELibraryTypeProvider.LIBRARY_TYPE)) {
        List<URL> resources = lib.getContent(J2SELibraryTypeProvider.VOLUME_TYPE_SRC);
        try {                
            FileObject root = getOwnerRoot(file,resources);
            if (root != null) {
                final JavaPlatform defPlatform = JavaPlatformManager.getDefault().getDefaultPlatform();
                setLastUsedLibrary(root, lib);
                if (ClassPath.SOURCE.equals(type)) {
                    return new ClassPath[] {ClassPathSupport.createClassPath(resources.toArray(new URL[resources.size()]))};
                } else if (ClassPath.COMPILE.equals(type)) {
                    resources = lib.getContent(J2SELibraryTypeProvider.VOLUME_TYPE_CLASSPATH);
                    return new ClassPath[] {ClassPathSupport.createClassPath(resources.toArray(new URL[resources.size()]))};
                } else if (ClassPath.BOOT.equals(type)) {
                    return new ClassPath[] {defPlatform.getBootstrapLibraries()};
                } else if (JavaClassPathConstants.MODULE_BOOT_PATH.equals(type) &&
                        Util.JDK9.compareTo(defPlatform.getSpecification().getVersion()) <= 0) {
                    return new ClassPath[] {defPlatform.getBootstrapLibraries()};
                } else {
                    return new ClassPath[] {null};
                }
            }
        } catch (final IllegalArgumentException e) {
            final IllegalArgumentException ne = new IllegalArgumentException("LibraryImplementation:["+getImplClassName(lib)+"] returned wrong root:" + e.getMessage());
            Exceptions.printStackTrace(ne.initCause(e));
        }
    }
    return null;
}
 
示例17
public final ClassPath createServletAPIClassPath() throws MalformedURLException, IOException {
    String path = System.getProperty("web.project.jars");
    String[] st = PropertyUtils.tokenizePath(path);
    List<FileObject> fos = new ArrayList<FileObject>();
    for (int i = 0; i < st.length; i++) {
        String token = st[i];
        File f = new File(token);
        if (!f.exists()) {
            fail("cannot find file " + token);
        }
        FileObject fo = FileUtil.toFileObject(f);
        fos.add(FileUtil.getArchiveRoot(fo));
    }
    return ClassPathSupport.createClassPath(fos.toArray(new FileObject[fos.size()]));
}
 
示例18
@NonNull
static ClassPath createClassPath(@NonNull final String classpath) {
    Parameters.notNull("classpath", classpath);
    List<PathResourceImplementation> list = new ArrayList<>();
    addPath(classpath, list);
    return ClassPathSupport.createClassPath(list);
}
 
示例19
@Override
protected Map<String, ClassPath> createClassPathsForTest() {
    return Collections.singletonMap(
        PhpSourcePath.SOURCE_CP,
        ClassPathSupport.createClassPath(new FileObject[] {
            FileUtil.toFileObject(new File(getDataDir(), "/testfiles/completion/lib/test209255/"))
        })
    );
}
 
示例20
@Override
protected Map<String, ClassPath> createClassPathsForTest() {
    return Collections.singletonMap(
        PhpSourcePath.SOURCE_CP,
        ClassPathSupport.createClassPath(new FileObject[] {
            FileUtil.toFileObject(new File(getDataDir(), getTestFolderPath()))
        })
    );
}
 
示例21
@Override
protected Map<String, ClassPath> createClassPathsForTest() {
    return Collections.singletonMap(
        PhpSourcePath.SOURCE_CP,
        ClassPathSupport.createClassPath(new FileObject[] {
            FileUtil.toFileObject(new File(getDataDir(), "/testfiles/completion/lib/tests225687/"))
        })
    );
}
 
示例22
@Override
protected Map<String, ClassPath> createClassPathsForTest() {
    return Collections.singletonMap(
        PhpSourcePath.SOURCE_CP,
        ClassPathSupport.createClassPath(new FileObject[] {
            FileUtil.toFileObject(new File(getDataDir(), "/testfiles/completion/lib/tests166339"))
        })
    );
}
 
示例23
@Override
protected Map<String, ClassPath> createClassPathsForTest() {
    return Collections.singletonMap(
        PhpSourcePath.SOURCE_CP,
        ClassPathSupport.createClassPath(new FileObject[] {
            FileUtil.toFileObject(new File(getDataDir(), "testfiles/php53/completion/namespaces")),
            FileUtil.toFileObject(new File(getDataDir(), "testfiles/php53/completion/constants53")),
        })
    );
}
 
示例24
@Override
protected Map<String, ClassPath> createClassPathsForTest() {
    List<FileObject> cpRoots = new LinkedList<FileObject>(ClasspathProviderImplAccessor.getJsStubs());
    cpRoots.add(FileUtil.toFileObject(new File(getDataDir(), "/testfiles/completion/issue245252")));
    return Collections.singletonMap(
        JS_SOURCE_ID,
        ClassPathSupport.createClassPath(cpRoots.toArray(new FileObject[cpRoots.size()]))
    );
}
 
示例25
@Override
protected Map<String, ClassPath> createClassPathsForTest() {
    return Collections.singletonMap(
        PhpSourcePath.SOURCE_CP,
        ClassPathSupport.createClassPath(new FileObject[] {
            FileUtil.toFileObject(new File(getDataDir(), "/testfiles/completion/lib/php70/contextSensitiveLexer/"))
        })
    );
}
 
示例26
@Override
protected Map<String, ClassPath> createClassPathsForTest() {
    return Collections.singletonMap(
        PhpSourcePath.SOURCE_CP,
        ClassPathSupport.createClassPath(new FileObject[] {
            FileUtil.toFileObject(new File(getDataDir(), "/testfiles/completion/lib/test194294"))
        })
    );
}
 
示例27
@Override
public ClassPath findClassPath(FileObject file, String type) {
    synchronized(ClassPathProviderImpl.class) {
        if (PATH_TOP_SOURCES.equals(type) &&
           (FileUtil.isParentOf(root, file) || root.equals(file))) {
           if (cp == null) {
               cp = ClassPathSupport.createClassPath(root);
           }
           return cp;
        }
    }
    return null;
}
 
示例28
@Override
public ClassPath getSourceFolders() {
    ClassPath res = src;
    if (res == null) {
        res = src = ClassPathSupport.createClassPath(
            getSources(getInstallFolders()));
    }
    return res;
}
 
示例29
protected void setUp() throws Exception {
    super.setUp();
    scratch = TestUtil.makeScratchDir(this);
    this.defaultPlatformBootRoot = scratch.createFolder("DefaultPlatformBootRoot");
    this.explicitPlatformBootRoot = scratch.createFolder("ExplicitPlatformBootRoot");
    ClassPath defBCP = ClassPathSupport.createClassPath(new URL[]{defaultPlatformBootRoot.toURL()});
    ClassPath expBCP = ClassPathSupport.createClassPath(new URL[]{explicitPlatformBootRoot.toURL()});
    tp = new TestPlatformProvider (defBCP, expBCP);
    MockLookup.setLayersAndInstances(
        new org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation(),
        tp
    );
}
 
示例30
@Override
protected Map<String, ClassPath> createClassPathsForTest() {
    List<FileObject> cpRoots = new LinkedList<FileObject>(ClasspathProviderImplAccessor.getJsStubs());
    cpRoots.add(FileUtil.toFileObject(new File(getDataDir(), "testfiles/completion/issue246060")));
    return Collections.singletonMap(
        JS_SOURCE_ID,
        ClassPathSupport.createClassPath(cpRoots.toArray(new FileObject[cpRoots.size()]))
    );
}