Java Code Examples for org.netbeans.spi.java.classpath.support.ClassPathSupport#createClassPath()

The following examples show how to use org.netbeans.spi.java.classpath.support.ClassPathSupport#createClassPath() . 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: DefaultClassPathProviderTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);        
}
 
Example 2
Source File: ELTypeUtilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Gets {@code ClasspathInfo} extended for the el-impl.jar. It guarantees to find Stream class on the classpath.
 * @param file file to be used for getting classpaths
 * @return extended classpath for the el-impl.jar
 * @since 1.39
 */
public static ClasspathInfo getElimplExtendedCPI(FileObject file) {
    ClassPath bootPath = ClassPath.getClassPath(file, ClassPath.BOOT);
    if (bootPath == null) {
        bootPath = JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries();
    }
    ClassPath compilePath = ClassPath.getClassPath(file, ClassPath.COMPILE);
    if (compilePath == null) {
        compilePath = ClassPathSupport.createClassPath(new URL[0]);
    }
    ClassPath srcPath = ClassPath.getClassPath(file, ClassPath.SOURCE);
    return ClasspathInfo.create(
            bootPath,
            ClassPathSupport.createProxyClassPath(compilePath, ClassPathSupport.createClassPath(EL_IMPL_JAR_FO)),
            srcPath);
}
 
Example 3
Source File: JPDAReload.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String classToSourceURL (FileObject fo) {
    try {
        ClassPath cp = ClassPath.getClassPath (fo, ClassPath.EXECUTE);
        FileObject root = cp.findOwnerRoot (fo);
        String resourceName = cp.getResourceName (fo, '/', false);
        if (resourceName == null) {
            getProject().log("Can not find classpath resource for "+fo+", skipping...", Project.MSG_ERR);
            return null;
        }
        int i = resourceName.indexOf ('$');
        if (i > 0)
            resourceName = resourceName.substring (0, i);
        FileObject[] sRoots = SourceForBinaryQuery.findSourceRoots 
            (root.getURL ()).getRoots ();
        ClassPath sourcePath = ClassPathSupport.createClassPath (sRoots);
        FileObject rfo = sourcePath.findResource (resourceName + ".java");
        if (rfo == null) return null;
        return rfo.getURL ().toExternalForm ();
    } catch (FileStateInvalidException ex) {
        ex.printStackTrace ();
        return null;
    }
}
 
Example 4
Source File: FallbackDefaultJavaPlatform.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static ClassPath sysProp2CP(String propname) {
    String sbcp = System.getProperty(propname);
    if (sbcp == null) {
        return null;
    }
    List<URL> roots = new ArrayList<>();
    StringTokenizer tok = new StringTokenizer(sbcp, File.pathSeparator);
    while (tok.hasMoreTokens()) {
        File f = new File(tok.nextToken());
        if (!f.exists()) {
            continue;
        }
        URL u;
        try {
            File normf = FileUtil.normalizeFile(f);
            u = Utilities.toURI(normf).toURL();
        } catch (MalformedURLException x) {
            throw new AssertionError(x);
        } 
        if (FileUtil.isArchiveFile(u)) {
            u = FileUtil.getArchiveRoot(u);
        }
        roots.add(u);
    }
    return ClassPathSupport.createClassPath(roots.toArray(new URL[roots.size()]));
}
 
Example 5
Source File: ELTestBase.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
     * Creates boot {@link ClassPath} for platform the test is running on,
     * it uses the sun.boot.class.path property to find out the boot path roots.
     * @return ClassPath
     * @throws java.io.IOException when boot path property contains non valid path
     */
    public static ClassPath createBootClassPath() throws IOException {
        String bootPath = System.getProperty("sun.boot.class.path");
        String[] paths = bootPath.split(File.pathSeparator);
        List<URL> roots = new ArrayList<URL>(paths.length);
        for (String path : paths) {
            File f = new File(path);
            if (!f.exists()) {
                continue;
            }
            URL url = f.toURI().toURL();
            if (FileUtil.isArchiveFile(url)) {
                url = FileUtil.getArchiveRoot(url);
            }
            roots.add(url);
//            System.out.println(url);
        }
//        System.out.println("-----------");
        return ClassPathSupport.createClassPath(roots.toArray(new URL[roots.size()]));
    }
 
Example 6
Source File: ProjectRunnerImplTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Test
public void testComputeProperties1() throws IOException {
    ClassPath cp = ClassPathSupport.createClassPath(new URL("file:///E/"));
    final String wd = workDir.getAbsolutePath();
    checkProperties(Arrays.asList("classname", "A", "platform.java", "J", "execute.classpath", cp, "work.dir", wd,"boot.classpath",cp,"runtime.encoding",Charset.defaultCharset()),
                    Arrays.asList("classname", "A", "platform.java", "J", "classpath", "/E/", "work.dir", wd, "application.args", "", "run.jvmargs", "", "platform.bootcp", "/E","encoding",Charset.defaultCharset().name()));
}
 
Example 7
Source File: TreeUtilitiesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testJavacInitializationTypes() throws Exception {
    ClassPath boot = ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0]));
    JavaSource js = JavaSource.create(ClasspathInfo.create(boot, ClassPath.EMPTY, ClassPath.EMPTY));
    js.runUserActionTask(new Task<CompilationController>() {
        @Override
        public void run(CompilationController parameter) throws Exception {
            assertNotNull(parameter.getTypes());
        }
    }, true);
}
 
Example 8
Source File: ProjectImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public ClassPath findClassPath(FileObject file, String type) {
    if (ClassPath.SOURCE.equals(type)) {
        return ClassPathSupport.createClassPath(projectDirectory.getFileObject("src").getFileObject("java"));
    } else if (ClassPath.COMPILE.equals(type)) {
        return ClassPathSupport.createClassPath(projectDirectory.getFileObject("src").getFileObject("java"));
    } else if (ClassPath.BOOT.equals(type)) {
        return JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries();
    }
    return null;
}
 
Example 9
Source File: WebModules.java    From netbeans with Apache License 2.0 5 votes vote down vote up
FFWebModule (FileObject docRootFO, String j2eeSpec, String contextPath, FileObject sourcesFOs[], ClassPath classPath, FileObject webInf) {
    this.docRootFO = docRootFO;
    this.j2eeSpec = j2eeSpec;
    this.contextPath = (contextPath == null ? "" : contextPath);
    this.sourcesFOs = sourcesFOs;
    this.compileClasspath = classPath;
    this.webClassPath = (classPath ==  null ? 
        ClassPathSupport.createClassPath(Collections.<PathResourceImplementation>emptyList()) :
        classPath);
    this.webInf = webInf;
    javaSourcesClassPath = (sourcesFOs == null ? 
        ClassPathSupport.createClassPath(Collections.<PathResourceImplementation>emptyList()) :
        ClassPathSupport.createClassPath(sourcesFOs)); 
}
 
Example 10
Source File: AndroidClassPathProvider.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private ClassPath createCompile() {
    List<PathResourceBase> pathResources = Lists.newArrayList();
    CompilePathResources compilePathResources = new CompilePathResources();
    refreshables.add(compilePathResources);
    pathResources.add(compilePathResources);
    return ClassPathSupport.createClassPath(pathResources);
}
 
Example 11
Source File: TreeUtilitiesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testStaticBlock() throws Exception {
    ClassPath boot = ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0]));
    JavaSource js = JavaSource.create(ClasspathInfo.create(boot, ClassPath.EMPTY, ClassPath.EMPTY));
    js.runUserActionTask(new Task<CompilationController>() {
        @Override
        public void run(CompilationController parameter) throws Exception {
            final SourcePositions[] sp = new SourcePositions[1];
            BlockTree block = parameter.getTreeUtilities().parseStaticBlock("static { }", sp);
            assertNotNull(block);
            assertEquals(0, sp[0].getStartPosition(null, block));
            assertEquals(10, sp[0].getEndPosition(null, block));
            assertNull(parameter.getTreeUtilities().parseStaticBlock("static", new SourcePositions[1]));
        }
    }, true);
}
 
Example 12
Source File: JavaTypeProviderTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ClassPath findClassPath(final FileObject file, final String type) {
    final FileObject[] roots = sourcePath.getRoots();
    for (FileObject root : roots) {
        if (root.equals(file) || FileUtil.isParentOf(root, file)) {
            if (type == ClassPath.SOURCE) {
                return sourcePath;
            }
            if (type == ClassPath.COMPILE) {
                return compilePath;
            }
            if (type == ClassPath.BOOT) {
                return bootPath;
            }
        }
    }
    if (libSrc2.equals(file) || FileUtil.isParentOf(libSrc2, file)) {
        if (type == ClassPath.SOURCE) {
            return ClassPathSupport.createClassPath(new FileObject[]{libSrc2});
        }
        if (type == ClassPath.COMPILE) {
            return ClassPathSupport.createClassPath(new URL[0]);
        }
        if (type == ClassPath.BOOT) {
            return bootPath;
        }
    }
    return null;
}
 
Example 13
Source File: MRJARCachingFileManagerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    final File wd = FileUtil.normalizeFile(getWorkDir());
    final File bJar = createTestJar(new File(wd,"broken.jar"), false); //NOI18N
    final File mvJar = createTestJar(new File(wd,"mr.jar"), true); //NOI18N
    bCp = ClassPathSupport.createClassPath(FileUtil.urlForArchiveOrDir(bJar));
    mvCp = ClassPathSupport.createClassPath(FileUtil.urlForArchiveOrDir(mvJar));
}
 
Example 14
Source File: ProjectImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public ClassPath findClassPath(FileObject file, String type) {
    if (ClassPath.SOURCE.equals(type)) {
        return ClassPathSupport.createClassPath(projectDirectory.getFileObject("src").getFileObject("java"));
    } else if (ClassPath.COMPILE.equals(type)) {
        return ClassPathSupport.createClassPath(projectDirectory.getFileObject("src").getFileObject("java"));
    } else if (ClassPath.BOOT.equals(type)) {
        return JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries();
    }
    return null;
}
 
Example 15
Source File: AppletSupportTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public ClassPath getBootstrapLibraries() {
    return ClassPathSupport.createClassPath(new URL[0]);
}
 
Example 16
Source File: QuerySupportTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testGetDependentRootsScriptingLikeDependenciesAllProjectsOpened() throws IOException, InterruptedException {
    final FileObject wd = FileUtil.toFileObject(getWorkDir());
    final FileObject libSrc = FileUtil.createFolder(wd,"libSrc");   //NOI18N
    final FileObject src1 = FileUtil.createFolder(wd,"src1");   //NOI18N
    final FileObject src2 = FileUtil.createFolder(wd,"src2");   //NOI18N
    final FileObject src3 = FileUtil.createFolder(wd,"src3");   //NOI18N
    final FileObject src4 = FileUtil.createFolder(wd,"src4");   //NOI18N

    final ClassPath src1Source = ClassPathSupport.createClassPath(src1);
    final ClassPath src1Compile = ClassPathSupport.createClassPath(libSrc);
    final ClassPath src2Source = ClassPathSupport.createClassPath(src2);
    final ClassPath src2Compile = ClassPathSupport.createClassPath(src1);
    final ClassPath src3Source = ClassPathSupport.createClassPath(src3);
    final ClassPath src3Compile = ClassPathSupport.createClassPath(src1);
    final ClassPath src4Source = ClassPathSupport.createClassPath(src4);
    final ClassPath src4Compile = ClassPathSupport.createClassPath(src2);


    final Map<String,ClassPath> src1cps = new HashMap<String, ClassPath>();
    src1cps.put(ScriptingLikePathRecognizer.COMPILE, src1Compile);
    src1cps.put(ScriptingLikePathRecognizer.SRC, src1Source);
    final Map<String,ClassPath> src2cps = new HashMap<String, ClassPath>();
    src2cps.put(ScriptingLikePathRecognizer.COMPILE, src2Compile);
    src2cps.put(ScriptingLikePathRecognizer.SRC, src2Source);
    final Map<String,ClassPath> src3cps = new HashMap<String, ClassPath>();
    src3cps.put(ScriptingLikePathRecognizer.COMPILE, src3Compile);
    src3cps.put(ScriptingLikePathRecognizer.SRC, src3Source);
    final Map<String,ClassPath> src4cps = new HashMap<String, ClassPath>();
    src4cps.put(ScriptingLikePathRecognizer.COMPILE, src4Compile);
    src4cps.put(ScriptingLikePathRecognizer.SRC, src4Source);
    final Map<FileObject,Map<String,ClassPath>> cps = new HashMap<FileObject, Map<String, ClassPath>>();
    cps.put(src1,src1cps);
    cps.put(src2,src2cps);
    cps.put(src3,src3cps);
    cps.put(src4,src4cps);
    ClassPathProviderImpl.register(cps);

    globalPathRegistry_register(
            ScriptingLikePathRecognizer.COMPILE,
            new ClassPath[]{
                src2Compile,
                src3Compile,
                src4Compile
            });
    globalPathRegistry_register(
            ScriptingLikePathRecognizer.SRC,
            new ClassPath[]{
                src1Source,
                src2Source,
                src3Source,
                src4Source
            });

    RepositoryUpdater.getDefault().waitUntilFinished(RepositoryUpdaterTest.TIME);
    assertEquals(
            IndexingController.getDefault().getRootDependencies().keySet().toString(),
            5,
            IndexingController.getDefault().getRootDependencies().size());

    assertEquals(new FileObject[] {src4}, QuerySupport.findDependentRoots(src4, true));
    assertEquals(new FileObject[] {src3}, QuerySupport.findDependentRoots(src3, true));
    assertEquals(new FileObject[] {src2, src4}, QuerySupport.findDependentRoots(src2, true));
    assertEquals(new FileObject[] {src1, src2, src3, src4}, QuerySupport.findDependentRoots(src1, true));
    assertEquals(new FileObject[] {src1, src2, src3, src4}, QuerySupport.findDependentRoots(libSrc, true));

    assertEquals(new FileObject[] {src4}, QuerySupport.findDependentRoots(src4, false));
    assertEquals(new FileObject[] {src3}, QuerySupport.findDependentRoots(src3, false));
    assertEquals(new FileObject[] {src2, src4}, QuerySupport.findDependentRoots(src2, false));
    assertEquals(new FileObject[] {src1, src2, src3, src4}, QuerySupport.findDependentRoots(src1, false));
    assertEquals(new FileObject[] {libSrc, src1, src2, src3, src4}, QuerySupport.findDependentRoots(libSrc, false));
}
 
Example 17
Source File: ImportBlueprintEarWizardIteratorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public ClassPath getBootstrapLibraries() {
    return ClassPathSupport.createClassPath(new URL[0]);
}
 
Example 18
Source File: VisibilityChangeTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    final File wd = getWorkDir();
    final FileObject wdo = FileUtil.toFileObject(wd);
    assertNotNull("No masterfs",wdo);   //NOI18N
    final FileObject cache = wdo.createFolder("cache"); //NOI18N
    CacheFolder.setCacheFolder(cache);
    src1 = wdo.createFolder("src1");        //NOI18N
    assertNotNull(src1);
    src2 = wdo.createFolder("src2");        //NOI18N
    assertNotNull(src2);
    src3 = wdo.createFolder("src3");        //NOI18N
    assertNotNull(src3);
    src4 = wdo.createFolder("src4");        //NOI18N
    assertNotNull(src4);
    outside = wdo.createFolder("outside");    //NOI18N
    assertNotNull(outside);
    src1file1 = src1.createData("test", FOO_EXT);   //NOI18N
    assertNotNull(src1file1);
    src1file2 = src1.createData("test2", FOO_EXT);  //NOI18N
    assertNotNull(src1file2);
    src2fld = src2.createFolder("folder"); //NOI18N
    assertNotNull(src2fld);
    src2file1 = src2fld.createData("test", FOO_EXT);   //NOI18N
    assertNotNull(src2file1);
    src2file2 = src2fld.createData("test2", FOO_EXT);  //NOI18N
    assertNotNull(src2file2);
    src3file1 = src3.createData("test", FOO_EXT);   //NOI18N
    assertNotNull(src3file1);
    src3file2 = src3.createData("test2", FOO_EXT);  //NOI18N
    assertNotNull(src3file2);
    src4file1 = src4.createData("test", FOO_EXT);   //NOI18N
    assertNotNull(src4file1);
    src4file2 = src4.createData("test2", FOO_EXT);  //NOI18N
    assertNotNull(src4file2);

    FileUtil.setMIMEType(FOO_EXT, FOO_MIME);
    cp1 = ClassPathSupport.createClassPath(src1,src2,src3,src4);
    MockMimeLookup.setInstances(MimePath.get(FOO_MIME), new FooIndexerFactory());
    RepositoryUpdaterTest.setMimeTypes(FOO_MIME);
    RepositoryUpdaterTest.waitForRepositoryUpdaterInit();
}
 
Example 19
Source File: ConstrainedBinaryIndexerTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Tests ConstrainedBinaryIndexer with required resource predicate,
 * the resource exists in archive.
 */
public void testRequiredResourcePredicate_res_exists() throws Exception {
    final String[] reqRes = new String[]{"required_resource.txt"};  //NOI18N
    final MockConstrainedIndexer indexer = new MockConstrainedIndexer();
    registerProxyBinaryIndexer(indexer,reqRes,null,null);
    final URL root = createArchive (getWorkDir(), "resPred.jar", reqRes); //NOI18N
    final ClassPath cp = ClassPathSupport.createClassPath(root);

    //Jar registered for first time (never seen before) scanStarted, index, scanFinished shoud be called.
    indexer.expect(MockConstrainedIndexer.Event.STARTED, MockConstrainedIndexer.Event.INDEXED, MockConstrainedIndexer.Event.FINISHED);
    globalPathRegistry_register(PATH_LIB, cp);
    assertTrue(indexer.await(5));
    assertTrue(indexer.hasResources(Collections.<String,Set<String>>emptyMap()));

    //Jar unregistered rootsRemoved should be called
    indexer.expect(MockConstrainedIndexer.Event.REMOVED);
    globalPathRegistry_unregister(PATH_LIB, cp);
    assertTrue(indexer.await(5));

    //Jar registered for second time (seen before) scanStarted should be called.
    //The ConstrainedBinaryIndexer accepted the jar in prev scan -> the scanStarted
    //has to be called to give a chance to indexer to force rescan of it when needed.
    indexer.expect(MockConstrainedIndexer.Event.STARTED);
    globalPathRegistry_register(PATH_LIB, cp);
    assertTrue(indexer.await(5));

    //Jar unregistered rootsRemoved should be called
    indexer.expect(MockConstrainedIndexer.Event.REMOVED);
    globalPathRegistry_unregister(PATH_LIB, cp);
    assertTrue(indexer.await(5));

    //Jar registered for second time (seen before) scanStarted should be called and returns false (rescan).
    //The ConstrainedBinaryIndexer accepted the jar in prev scan -> the scanStarted returned false ->
    // scanStarted,index, scanFinished should be called.
    indexer.expect(MockConstrainedIndexer.Event.STARTED, MockConstrainedIndexer.Event.INDEXED, MockConstrainedIndexer.Event.FINISHED);
    indexer.setVote(false);
    globalPathRegistry_register(PATH_LIB, cp);
    assertTrue(indexer.await(5));
    assertTrue(indexer.hasResources(Collections.<String,Set<String>>emptyMap()));

    //Jar unregistered rootsRemoved should be called
    indexer.expect(MockConstrainedIndexer.Event.REMOVED);
    globalPathRegistry_unregister(PATH_LIB, cp);
    assertTrue(indexer.await(5));
}
 
Example 20
Source File: ClassPathProviderImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public ClassPathProviderImpl(FileObject[] sources){
    this.classPath = ClassPathSupport.createClassPath(sources);
}