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

The following examples show how to use org.netbeans.api.java.classpath.ClassPath#COMPILE . 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: 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 2
Source File: Hk2JavaEEPlatformImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public boolean extendsJerseyProjectClasspath( Project project ) {
    Library library = libraryProvider.getJerseyLibrary();
    FileObject sourceRoot = getSourceRoot(project);
    if (sourceRoot == null) {
        return false;
    }
    try {
        String classPathType;
        if (hasJee6Profile()) {
            classPathType = JavaClassPathConstants.COMPILE_ONLY;
        }
        else {
            classPathType = ClassPath.COMPILE;
        }
        return ProjectClassPathModifier.addLibraries(
                new Library[] { library }, sourceRoot, classPathType);
    }
    catch (UnsupportedOperationException | IOException ex) {
        return false;
    }
    /*List<URL> urls = getJerseyLibraryURLs();
    if ( urls.sdkSize() >0 ){
        return addJars( project , urls );
    }*/
}
 
Example 3
Source File: LibrariesNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void addLibraries (Library[] libraries) {
    final FileObject[] roots = this.sources.get();
    if (roots.length == 0) {
        return;
    }
    final FileObject projectSourcesArtifact = roots[0];
    try {
        final FileObject moduleInfo = findModuleInfo(roots);
        final String cpType =  moduleInfo != null ?
                JavaClassPathConstants.MODULE_COMPILE_PATH :
                ClassPath.COMPILE;
        ProjectClassPathModifier.addLibraries(libraries,
                projectSourcesArtifact, cpType);
        DefaultProjectModulesModifier.extendModuleInfo(moduleInfo, Arrays.asList(toURLs(libraries)));
    } catch (IOException ioe) {
        Exceptions.printStackTrace(ioe);
    } catch (UnsupportedOperationException e) {
        handlePCPMUnsupported(sources, e);
    }
}
 
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: ManagerUtil.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Check if a project has a library reference to the named library qualified by the type parameter.
 * @param project Target project
 * @param library Library object
 * @param type Determines whether the library is to be referenced from the design-time classpath or deploy
 * time classpath
 * @return Returns true if the library is already referenced by the project, false otherwise
 */
public static boolean hasLibraryReference(Project project, Library library, String type) {
    List lst = library.getContent("classpath");
    if (lst.isEmpty()) {
        return false;
    }

    URL url = (URL) lst.get(0);
    FileObject obj = URLMapper.findFileObject(url);
    if (obj == null) {
        return false;
    }

    // XXX NetBeans API not finished yet
    type = ClassPath.COMPILE;
    ClassPath cp = ClassPath.getClassPath(getSourceRoot(project), type);

    if ( cp== null){
        return false;
    }
    return cp.contains(obj);
}
 
Example 6
Source File: ManagerUtil.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Check if a project has an root reference to the named root qualified by the type parameter.
 * @param project Target project
 * @param rootFile file object of the root
 * @param type Determines whether the root is to be referenced from the design-time classpath or deploy
 * time classpath
 * @return Returns true if the root is already referenced by the project, false otherwise
 */
public static boolean hasRootReference(Project project, URL rootFile, String type) {
    FileObject obj = URLMapper.findFileObject(rootFile);
    if (obj == null) {
        return false;
    }

    // XXX NetBeans API not finished yet
    type = ClassPath.COMPILE;
    ClassPath cp = ClassPath.getClassPath(getSourceRoot(project), type);

    if ( cp==null){
        return false;
    }
    return cp.contains(obj);
}
 
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: 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 9
Source File: Hk2JavaEEPlatformImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean addJars(final Project project, Collection<URL> jars ){
    final List<URL> urls = new ArrayList<>();
    for (URL url : jars) {
        if ( FileUtil.isArchiveFile( url)){
            urls.add(FileUtil.getArchiveRoot(url));
        }
    }
    final SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(
        JavaProjectConstants.SOURCES_TYPE_JAVA);
    if (sourceGroups == null || sourceGroups.length < 1) {
       return false;
    }
    final FileObject sourceRoot = sourceGroups[0].getRootFolder();
    try {
        final String classPathType;
        if ( hasJee6Profile() ){
            classPathType = JavaClassPathConstants.COMPILE_ONLY;
        }
        else {
            classPathType = ClassPath.COMPILE;
        }
        ProjectClassPathModifier.addRoots(urls.toArray( new URL[ urls.size()]), 
                sourceRoot, classPathType );
    } 
    catch (UnsupportedOperationException | IOException ex) {
        return false;
    }
    return true;
}
 
Example 10
Source File: IdeJaxRsSupportImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void removeJaxRsLibraries( Project project ) {
    List<Library> libraries = new ArrayList<Library>(2);
    Library swdpLibrary = LibraryManager.getDefault().getLibrary(SWDP_LIBRARY);
    if (swdpLibrary != null) {
        libraries.add( swdpLibrary );
    }

    Library restapiLibrary = LibraryManager.getDefault().getLibrary(RESTAPI_LIBRARY);
    if (restapiLibrary != null) {
        libraries.add( restapiLibrary );
    }
    SourceGroup[] sgs = ProjectUtils.getSources(project).getSourceGroups(
            JavaProjectConstants.SOURCES_TYPE_JAVA);
    FileObject sourceRoot = sgs[0].getRootFolder();
    String[] classPathTypes = new String[]{ ClassPath.COMPILE , ClassPath.EXECUTE };
    for (String type : classPathTypes) {
        try {
            ProjectClassPathModifier.removeLibraries(libraries.toArray( 
                    new Library[ libraries.size()]), sourceRoot, type);
        } 
        catch(UnsupportedOperationException ex) {
            Logger.getLogger( IdeJaxRsSupportImpl.class.getName() ).log( 
                    Level.INFO, null , ex );
        }
        catch( IOException e ){
            Logger.getLogger( IdeJaxRsSupportImpl.class.getName() ).log( 
                    Level.INFO, null , e );
        }
    }        
}
 
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: 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 13
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 14
Source File: ClassPathModifier.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public String[] getExtensibleClassPathTypes (SourceGroup sg) {
    return new String[] {
        ClassPath.COMPILE,
        ClassPath.EXECUTE,
        ClassPathSupport.ENDORSED,
        JavaClassPathConstants.PROCESSOR_PATH,
        JavaClassPathConstants.MODULE_COMPILE_PATH,
        JavaClassPathConstants.MODULE_EXECUTE_PATH,
    };
}
 
Example 15
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 16
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 17
Source File: JaxRsStackSupportImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean addJars( Project project, Collection<URL> jars ){
    List<URL> urls = new ArrayList<URL>();
    for (URL url : jars) {
        if ( FileUtil.isArchiveFile( url)){
            urls.add(FileUtil.getArchiveRoot(url));
        }
    }
    FileObject sourceRoot = getSourceRoot(project);
    if ( sourceRoot == null ){
        return false;
    }
    String classPathType;
    if ( hasJee6Profile() ){
        classPathType = JavaClassPathConstants.COMPILE_ONLY;
    }
    else {
        classPathType = ClassPath.COMPILE;
    }
    try {
        ProjectClassPathModifier.addRoots(urls.toArray( new URL[ urls.size()]), 
                sourceRoot, classPathType);
    } 
    catch(UnsupportedOperationException ex) {
        return false;
    }
    catch ( IOException e ){
        return false;
    }
    return true;
}
 
Example 18
Source File: MultiModuleClassPathProvider.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public String[] getPropertyName (SourceGroup sg, String type) {
    FileObject root = sg.getRootFolder();
    final Owner fOwner = getOwner(root);
    if (fOwner == null) {
        return null;
    } else if (fOwner.isTest()) {
        switch (type) {
            case ClassPath.COMPILE:
                return testJavacClassPath;
            case ClassPath.EXECUTE:
                return testExecuteClassPath;
            case JavaClassPathConstants.PROCESSOR_PATH:
                return testProcessorClassPath;
            case JavaClassPathConstants.MODULE_COMPILE_PATH:
                return testModulePath;
            case JavaClassPathConstants.MODULE_PROCESSOR_PATH:
                return testProcessorModulePath;
            case JavaClassPathConstants.MODULE_EXECUTE_PATH:
                return testExecuteModulePath;
            default:
                return null;
        }
    } else {
        switch (type) {
            case ClassPath.COMPILE:
                return javacClassPath;
            case ClassPath.EXECUTE:
                return executeClassPath;
            case JavaClassPathConstants.PROCESSOR_PATH:
                return processorClassPath;
            case JavaClassPathConstants.MODULE_COMPILE_PATH:
                return modulePath;
            case JavaClassPathConstants.MODULE_PROCESSOR_PATH:
                return processorModulePath;
            case JavaClassPathConstants.MODULE_EXECUTE_PATH:
                return executeModulePath;
            default:
                return null;
        }
    }
}
 
Example 19
Source File: ClassPathProviderImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public String[] getPropertyName (SourceGroup sg, String type) {
    if (ClassPathSupport.ENDORSED.equals(type)) {
        return endorsedClasspath;
    }
    FileObject root = sg.getRootFolder();
    FileObject[] path = getPrimarySrcPath();
    for (int i=0; i<path.length; i++) {
        if (root.equals(path[i])) {
            switch (type) {
                case ClassPath.COMPILE:
                    return javacClasspath;
                case ClassPath.EXECUTE:
                    return runClasspath;
                case JavaClassPathConstants.PROCESSOR_PATH:
                    return processorClasspath;
                case JavaClassPathConstants.MODULE_COMPILE_PATH:
                    return modulePath;
                case JavaClassPathConstants.MODULE_EXECUTE_PATH:
                    return moduleExecutePath;
                case JavaClassPathConstants.MODULE_PROCESSOR_PATH:
                    return processorModulePath;
                default:
                    return null;
            }
        }
    }
    path = getTestSrcDir();
    for (int i=0; i<path.length; i++) {
        if (root.equals(path[i])) {
            switch (type) {
                case ClassPath.COMPILE:
                    return javacTestClasspath;
                case ClassPath.EXECUTE:
                    return runTestClasspath;
                case JavaClassPathConstants.PROCESSOR_PATH:
                    return processorTestClasspath;
                case JavaClassPathConstants.MODULE_COMPILE_PATH:
                    return testModulePath;
                case JavaClassPathConstants.MODULE_EXECUTE_PATH:
                    return moduleExecutePath;
                case JavaClassPathConstants.MODULE_PROCESSOR_PATH:
                    return processorTestModulepath;
                default:
                    return null;
            }
        }
    }
    return null;
}
 
Example 20
Source File: Hk2JavaEEPlatformImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void removeJaxRsLibraries(final Project project) {
    final Library library = libraryProvider.getJerseyLibrary();
    final FileObject sourceRoot = getSourceRoot(project);
    if ( sourceRoot != null){
        final String[] classPathTypes = new String[]{ ClassPath.COMPILE , 
                JavaClassPathConstants.COMPILE_ONLY };
        for (String type : classPathTypes) {
            try {
                ProjectClassPathModifier.removeLibraries( new Library[]{
                        library} ,sourceRoot, type);
            }    
            catch (UnsupportedOperationException | IOException ex) {
                Logger.getLogger(JaxRsStackSupportImpl.class.getName()).
                        log (Level.INFO, null , ex );
            }
        }     
    }
    /*List<URL> urls = getJerseyLibraryURLs();
    if ( urls.sdkSize() >0 ){
        SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(
            JavaProjectConstants.SOURCES_TYPE_JAVA);
        if (sourceGroups == null || sourceGroups.length < 1) {
            return;
        }
        FileObject sourceRoot = sourceGroups[0].getRootFolder();
        String[] classPathTypes = new String[]{ ClassPath.COMPILE , ClassPath.EXECUTE };
        for (String type : classPathTypes) {
            try {
                ProjectClassPathModifier.removeRoots(urls.toArray( 
                    new URL[ urls.sdkSize()]), sourceRoot, type);
            }    
            catch(UnsupportedOperationException ex) {
                Logger.getLogger( JaxRsStackSupportImpl.class.getName() ).
                        log (Level.INFO, null , ex );
            }
            catch( IOException e ){
                Logger.getLogger( JaxRsStackSupportImpl.class.getName() ).
                        log(Level.INFO, null , e );
            }
        }     
    }*/
}