Java Code Examples for org.netbeans.api.java.classpath.ClassPath#BOOT

The following examples show how to use org.netbeans.api.java.classpath.ClassPath#BOOT . 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: BinaryUsagesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
@CheckForNull
public ClassPath findClassPath(FileObject file, String type) {
    final FileObject root = srcRoot;
    if (root != null && (root.equals(file) || FileUtil.isParentOf(root, file))) {
        switch (type) {
            case ClassPath.BOOT:
                return getBootCp();
            case ClassPath.SOURCE:
                return getSrcCp(root);
            case ClassPath.COMPILE:
                return getCompileCp();
        }
    }
    return null;
}
 
Example 2
Source File: GlobalClassPathProviderImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static int type2Index(String type, boolean excludeTests) {
    int index;
    switch (type) {
        case ClassPath.BOOT:
            index = BOOT;
            break;
        case ClassPath.SOURCE:
            index = SOURCE;
            break;
        case ClassPath.COMPILE:
            index = COMPILE;
            break;
        case ClassPath.EXECUTE:
            index = RUNTIME;
            break;
        default:
            index = -1;
    }

    return (index >= 0) && excludeTests ? index + 1 : index;
}
 
Example 3
Source File: GlobalClassPathProviderImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private ClassPath getClassPath(String type, boolean excludeTests) {
    int index = type2Index(type, excludeTests);
    if (index < 0) return null;
    ClassPath cp = cache[index];
    if (cp == null) {
        switch (type) {
            case ClassPath.BOOT:
                cp = createClassPath(new BootClassPathImpl(project));
                break;
            case ClassPath.SOURCE:
                cp = createClassPath(new GradleGlobalClassPathImpl.ProjectSourceClassPathImpl(project, excludeTests));
                break;
            case ClassPath.COMPILE:
                cp = createClassPath(new GradleGlobalClassPathImpl.ProjectCompileClassPathImpl(project, excludeTests));
                break;
            case ClassPath.EXECUTE:
                cp = createClassPath(new GradleGlobalClassPathImpl.ProjectRuntimeClassPathImpl(project, excludeTests));
                break;
        }
        cache[index] = cp;
    }
    return cp;
}
 
Example 4
Source File: ScriptClassPathProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public ClassPath findClassPath(FileObject fo, String type) {
    if ("classpath/html5".equals(type)) {
        return null;
    }
    boolean isGradle = "gradle".equals(fo.getExt());
    if (fo.isFolder() && (FileUtil.toFile(fo) != null)) {
        isGradle = GradleProjects.testForProject(FileUtil.toFile(fo));
    }

    if (isGradle) {
        switch (type) {
            case ClassPath.BOOT:    return BOOT_CP;
            case ClassPath.SOURCE:  return SOURCE_CP;
            case ClassPath.COMPILE: return GRADLE_CP;
            case ClassPath.EXECUTE: return GRADLE_CP;
            }
            }
    return null;
}
 
Example 5
Source File: JavaOperationsImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public ClassPath findClassPath(
        FileObject file,
        String type) {
    for (FileObject srcRoot : srcPath.getRoots()) {
        if (srcRoot.equals(file) || FileUtil.isParentOf(srcRoot, file)) {
            if (type == ClassPath.SOURCE) {
                return srcPath;
            } else if (type == ClassPath.BOOT) {
                return bootPath;
            } else if (type == ClassPath.COMPILE) {
                return compilePath;
            }
        }
    }
    return null;
}
 
Example 6
Source File: OpenAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@CheckForNull
private static FileObject findSource(
        @NonNull final FileObject file,
        @NonNull final ElementHandle<?> elementHandle) {
    FileObject owner = null;
    for (String id : new String[] {
            ClassPath.EXECUTE,
            ClassPath.COMPILE,
            ClassPath.BOOT}) {
        final ClassPath cp = ClassPath.getClassPath(file, id);
        if (cp != null) {
            owner = cp.findOwnerRoot(file);
            if (owner != null) {
                break;
            }
        }
    }
    return owner == null ?
        owner :
        SourceUtils.getFile(
            elementHandle,
            ClasspathInfo.create(
                ClassPathSupport.createClassPath(owner),
                ClassPath.EMPTY,
                ClassPath.EMPTY));
}
 
Example 7
Source File: JShellSourcePathTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized ClassPath findClassPath(
        final FileObject file,
        final String type) {
    if (root != null && file != null && (root.equals(file) || FileUtil.isParentOf(root, file))) {
        switch (type) {
            case ClassPath.BOOT:
                return cps[0];
            case ClassPath.COMPILE:
                return cps[1];
            case ClassPath.SOURCE:
                return cps[2];
        }
    }
    return null;
}
 
Example 8
Source File: HintTestBase.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 9
Source File: JavaSourceTaskFactoryTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    JavaSourceTaskFactory.SYNCHRONOUS_EVENTS = true;
    cpp = new ClassPathProvider() {
        public ClassPath findClassPath(FileObject file, String type) {
            if (type == ClassPath.SOURCE)
                return ClassPathSupport.createClassPath(new FileObject[] {FileUtil.toFileObject(getDataDir())});
                if (type == ClassPath.COMPILE)
                    return ClassPathSupport.createClassPath(new FileObject[0]);
                if (type == ClassPath.BOOT)
                    return createBootPath();
                return null;
        }
    };
    SourceUtilsTestUtil.setLookup(new Object[] {
        JavaDataLoader.getLoader(JavaDataLoader.class),
        cpp
    }, this.getClass().getClassLoader());


    jstf = new JavaSourceTaskFactoryImplImpl();
    JavaSourceTaskFactory.ACCESSOR2 = new AccessorImpl();
    testDir = SourceUtilsTestUtil.makeScratchDir(this);
    testFile1 = testDir.createData("test1.java");
    testFile2 = testDir.createData("test2.java");
    task1 = new DummyCancellableTask<CompilationInfo>();
    task2 = new DummyCancellableTask<CompilationInfo>();

    file2Task.put(testFile1, task1);
    file2Task.put(testFile2, task2);

    assertNotNull(JavaSource.forFileObject(testFile1));
    assertNotNull(JavaSource.forFileObject(testFile2));

    assertEquals(2, file2Task.size());

    JavaSourceTaskFactoryManager.register();
}
 
Example 10
Source File: GeneratorTestMDRCompat.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    ClassPathProvider cpp = new ClassPathProvider() {
        public ClassPath findClassPath(FileObject file, String type) {
            if (type == ClassPath.SOURCE)
                return ClassPathSupport.createClassPath(getSourcePath());
                if (type == ClassPath.COMPILE)
                    return ClassPathSupport.createClassPath(new FileObject[0]);
                if (type == ClassPath.BOOT)
                    return BootClassPathUtil.getBootClassPath();
                return null;
        }
    };
    SharedClassObject loader = JavaDataLoader.findObject(JavaDataLoader.class, true);
    SourceLevelQueryImplementation slq = new SourceLevelQueryImplementation() {
        @Override public String getSourceLevel(FileObject javaFile) {
            return GeneratorTestMDRCompat.this.getSourceLevel();
        }
    };
    SourceUtilsTestUtil.prepareTest(new String[] {"org/netbeans/modules/java/source/resources/layer.xml"}, new Object[] {loader, cpp});
    MockMimeLookup.setInstances(MimePath.get("text/x-java"), new Reindenter.Factory());
    
    TestUtil.setupEditorMockServices();
    JEditorPane.registerEditorKitForContentType("text/x-java", "org.netbeans.modules.editor.java.JavaKit");
    File cacheFolder = new File(getWorkDir(), "var/cache/index");
    cacheFolder.mkdirs();
    IndexUtil.setCacheFolder(cacheFolder);
}
 
Example 11
Source File: SourceUtilsTestUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ClassPath findClassPath(FileObject file, String type) {
    try {
        if (ClassPath.BOOT == type) {
           return ClassPathSupport.createClassPath(getBootClassPath().toArray(new URL[0]));
        }
     
        if (JavaClassPathConstants.MODULE_BOOT_PATH == type) {
            return BootClassPathUtil.getModuleBootPath();
        }
    
    if (ClassPath.SOURCE == type) {
        return sourcePath;
    }
    
    if (ClassPath.COMPILE == type) {
        return ClassPathSupport.createClassPath(classPathElements);
    }
    
    if (ClassPath.EXECUTE == type) {
        return ClassPathSupport.createClassPath(new FileObject[] {
            buildRoot
        });
    }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 12
Source File: ClassIndexTest.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: ShellClasspathProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public ClassPath findClassPath(FileObject file, String type) {
    JShellEnvironment jshe = ShellRegistry.get().getOwnerEnvironment(file);
    if (jshe == null) {
        return null;
    }
    ShellSession ss = jshe.getSession();
    if (ss == null) {
        return null;
    }
    ClasspathInfo cpi = ss.getClasspathInfo();
    if (cpi == null) {
        return null;
    }
    switch (type) {
        case JavaClassPathConstants.MODULE_BOOT_PATH:
            return cpi.getClassPath(PathKind.MODULE_BOOT);
            
        case JavaClassPathConstants.MODULE_COMPILE_PATH:
            return cpi.getClassPath(PathKind.MODULE_COMPILE);
            
        case JavaClassPathConstants.MODULE_CLASS_PATH:
            return cpi.getClassPath(PathKind.MODULE_CLASS);
            
        case JavaClassPathConstants.MODULE_SOURCE_PATH:
            return cpi.getClassPath(PathKind.MODULE_SOURCE);
            
        case ClassPath.COMPILE:
            return cpi.getClassPath(PathKind.COMPILE);
        case ClassPath.SOURCE:
            return cpi.getClassPath(PathKind.SOURCE);
        case ClassPath.BOOT:
            return cpi.getClassPath(PathKind.BOOT);
    }
    return null;
}
 
Example 14
Source File: AutoAndroidSourceForBinaryQuery.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Override
public ClassPath findClassPath(FileObject file, String type) {
    FileObject srcRoot = FileUtil.getArchiveFile(file);
    if (srcRoot != null) {
        AndroidClassPathProvider provider = backReferenceMap.get(srcRoot);
        if (provider != null) {
            switch (type) {
                case ClassPath.SOURCE:

                    ClassPath classPath = cache.get(srcRoot);
                    if (classPath == null) {
                        ClassPath srcClassPath = ClassPathSupport.createClassPath(FileUtil.getArchiveRoot(srcRoot));
                        GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[]{srcClassPath});
                        classPath = ClassPathSupport.createProxyClassPath(srcClassPath);
                        cache.put(srcRoot, classPath);
                    }
                    return classPath;
                case ClassPath.BOOT:
                    return provider.getClassPath(ClassPath.BOOT);
                case ClassPath.COMPILE:
                    return provider.getClassPath(ClassPath.COMPILE);

            }
        }
    }
    return null;
}
 
Example 15
Source File: HintTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ClassPath findClassPath(FileObject file, String type) {
    try {
    if (ClassPath.BOOT == type) {
        return BootClassPathUtil.getBootClassPath();
    }

    if (JavaClassPathConstants.MODULE_BOOT_PATH == type) {
        return BootClassPathUtil.getModuleBootPath();
    }

    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;
}
 
Example 16
Source File: UiUtilsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ClassPath findClassPath(FileObject file, String type) {
    try {
        if (type == ClassPath.SOURCE) {
            return createSourcePath(FileUtil.toFileObject(getWorkDir()));
        } else if (type == ClassPath.BOOT) {
            return createBootClassPath();
        }
    } catch (IOException ioe) {
        //Skeep it
    }
    return ClassPathSupport.createClassPath(Collections.<PathResourceImplementation>emptyList());
}
 
Example 17
Source File: IndexerTransactionTest.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 18
Source File: SourceAnalyzerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public ClassPath findClassPath(FileObject file, String type) {
    final FileObject _root = root;
    if (_root != null && (_root.equals(file) || FileUtil.isParentOf(_root, file))) {
        switch (type) {
            case ClassPath.SOURCE:
                return ClassPathSupport.createClassPath(_root);
            case ClassPath.COMPILE:
                return ClassPath.EMPTY;
            case ClassPath.BOOT:
                return BootClassPathUtil.getBootClassPath();
        }
    }
    return null;
}
 
Example 19
Source File: TestBase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ClassPath findClassPath(FileObject file, String type) {
    if (type == ClassPath.SOURCE) {
        return getSourceClassPath();
    } else if (type == ClassPath.COMPILE) {
        return getCompileClassPath();
    } else if (type == ClassPath.BOOT) {
        return getBootClassPath();
    }
    return null;
}
 
Example 20
Source File: GeneratorTestBase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected void setUp() throws Exception {
    super.setUp();
    SourceUtilsTestUtil.prepareTest(new String[0], new Object[0]);
    // ensure JavaKit is present, so that NbEditorDocument is eventually created.
    // it handles PositionRefs differently than PlainDocument/PlainEditorKit.
    MockMimeLookup.setInstances(MimePath.get("text/x-java"), 
            new Reindenter.Factory(), new JavaKit());
    dataDir = SourceUtilsTestUtil.makeScratchDir(this);
    FileObject dataTargetPackage = FileUtil.createFolder(dataDir, getSourcePckg());
    assertNotNull(dataTargetPackage);
    FileObject dataSourceFolder = FileUtil.toFileObject(getDataDir()).getFileObject(getSourcePckg());
    assertNotNull(dataSourceFolder);
    deepCopy(dataSourceFolder, dataTargetPackage);
    ClassPathProvider cpp = new ClassPathProvider() {
        public ClassPath findClassPath(FileObject file, String type) {
            if (type == ClassPath.SOURCE)
                return ClassPathSupport.createClassPath(new FileObject[] {dataDir});
                if (type == ClassPath.COMPILE)
                    return ClassPathSupport.createClassPath(new FileObject[0]);
                if (type == ClassPath.BOOT)
                    return BootClassPathUtil.getBootClassPath();
                return null;
        }
    };
    SharedClassObject loader = JavaDataLoader.findObject(JavaDataLoader.class, true);
    
    SourceUtilsTestUtil.prepareTest(
            new String[] {
                "org/netbeans/modules/java/project/ui/layer.xml", 
                "org/netbeans/modules/project/ui/resources/layer.xml",
                "META-INF/generated-layer.xml"
            },
            new Object[] {loader, cpp}
    );
    
    JEditorPane.registerEditorKitForContentType("text/x-java", "org.netbeans.modules.editor.java.JavaKit");
    File cacheFolder = new File(getWorkDir(), "var/cache/index");
    cacheFolder.mkdirs();
    IndexUtil.setCacheFolder(cacheFolder);
    ensureRootValid(dataDir.getURL());
    TestUtil.setupEditorMockServices();
    Main.initializeURLFactory();
}