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

The following examples show how to use org.netbeans.api.java.classpath.ClassPath#EMPTY . 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: OutputFileManagerTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    final FileObject wd = FileUtil.toFileObject(getWorkDir());
    final FileObject src = FileUtil.createFolder(wd, "src");    //NOI18N
    final FileObject cache = FileUtil.createFolder(wd, "cache");    //NOI18N
    CacheFolder.setCacheFolder(cache);
    final File index = JavaIndex.getClassFolder(src.toURL(), false, true);
    srcCp = ClassPathSupport.createClassPath(src);
    outCp = ClassPathSupport.createClassPath(Utilities.toURI(index).toURL());
    sibling = SiblingSupport.create();
    wbTx = (WriteBackTransaction) FileManagerTransaction.writeBack(src.toURL());
    fm = new OutputFileManager(
            CachingArchiveProvider.getDefault(),
            outCp,
            srcCp,
            ClassPath.EMPTY,
            sibling.getProvider(),
            wbTx,
            null);
}
 
Example 2
Source File: GlobalAndroidClassPathRegistry.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
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);
    }

}
 
Example 3
Source File: ElementOpen.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static boolean binaryOpen(
        @NonNull final FileObject toSearch,
        @NonNull final ElementHandle<? extends Element> toOpen,
        @NonNull final AtomicBoolean cancel) {
    boolean res = false;
    final BinaryElementOpen beo = Lookup.getDefault().lookup(BinaryElementOpen.class);
    if (beo != null) {
        ClassPath bootCp = ClassPath.getClassPath(toSearch, ClassPath.BOOT);
        if (bootCp == null) {
            bootCp = JavaPlatform.getDefault().getBootstrapLibraries();
        }
        ClassPath cp = ClassPath.getClassPath(toSearch, ClassPath.COMPILE);
        if (cp == null || cp.findOwnerRoot(toSearch) == null) {
            cp = ClassPath.getClassPath(toSearch, ClassPath.EXECUTE);
            if (cp == null) {
                cp = ClassPath.EMPTY;
            }
        }
        final ClassPath src = ClassPath.getClassPath(toSearch, ClassPath.SOURCE);
        res = beo.open(ClasspathInfo.create(bootCp, cp, src), toOpen, cancel);
    }
    return res;
}
 
Example 4
Source File: BinaryUsagesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
private ClassPath getCompileCp() {
    ClassPath cp = cache.get(2);
    if (cp == null) {
        cp = ClassPath.EMPTY;
        if (!cache.compareAndSet(2, null, cp)) {
            cp = cache.get(2);
        }
    }
    return cp;
}
 
Example 5
Source File: EntityMappingsMetadataModelHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
public Builder setModuleClassPath(@NullAllowed ClassPath moduleClassPath) {
    if (moduleClassPath == null) {
        moduleClassPath = ClassPath.EMPTY;
    }
    this.moduleClassPath = moduleClassPath;
    return this;
}
 
Example 6
Source File: ClasspathInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
private static ClasspathInfo create (
        @NonNull final FileObject fo,
        @NullAllowed final JavaFileFilterImplementation filter,
        final boolean backgroundCompilation,
        final boolean ignoreExcludes,
        final boolean hasMemoryFileManager,
        final boolean useModifiedFiles) {
    ClassPath bootPath = ClassPath.getClassPath(fo, ClassPath.BOOT);
    if (bootPath == null) {
        //javac requires at least java.lang
        bootPath = JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries();
    }
    ClassPath moduleBootPath = ClassPath.getClassPath(fo, JavaClassPathConstants.MODULE_BOOT_PATH);
    if (moduleBootPath == null) {
        moduleBootPath = ClassPath.EMPTY;
    }
    ClassPath compilePath = ClassPath.getClassPath(fo, ClassPath.COMPILE);
    if (compilePath == null) {
        compilePath = ClassPath.EMPTY;
    }
    ClassPath moduleCompilePath = ClassPath.getClassPath(fo, JavaClassPathConstants.MODULE_COMPILE_PATH);
    if (moduleCompilePath == null) {
        moduleCompilePath = ClassPath.EMPTY;
    }
    ClassPath moduleClassPath = ClassPath.getClassPath(fo, JavaClassPathConstants.MODULE_CLASS_PATH);
    if (moduleClassPath == null) {
        moduleClassPath = ClassPath.EMPTY;
    }
    ClassPath srcPath = ClassPath.getClassPath(fo, ClassPath.SOURCE);
    ClassPath moduleSrcPath = ClassPath.getClassPath(fo, JavaClassPathConstants.MODULE_SOURCE_PATH);
    return create (bootPath, moduleBootPath, compilePath, moduleCompilePath, moduleClassPath, srcPath, moduleSrcPath, filter, backgroundCompilation, ignoreExcludes, hasMemoryFileManager, useModifiedFiles, false, null);
}
 
Example 7
Source File: ClasspathInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
public Builder setModuleCompilePath(@NullAllowed ClassPath moduleCompilePath) {
    if (moduleCompilePath == null) {
        moduleCompilePath = ClassPath.EMPTY;
    }
    this.moduleCompilePath = moduleCompilePath;
    return this;
}
 
Example 8
Source File: ClassPathProviderImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected ClassPath getActiveClassPath(boolean hasTestModuleDescriptor, boolean hasMainModuleDescriptor) {        
    // see how classpathElements are set in org.apache.maven.plugin.compiler.TestCompilerMojo
    // XXX at the moment the asumption is made that exec-maven-plugin (runtime) will follow symetric logic like maven-compiler-plugin
    if ( hasTestModuleDescriptor ) {
        return ClassPath.EMPTY;
    } else {
        if(hasMainModuleDescriptor) {
            return testScopedPath.get();
        } else {
            return testPath.get();
        }
    }
}
 
Example 9
Source File: EntityMappingsMetadataModelHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
public Builder setSourcePath(@NullAllowed ClassPath sourcePath) {
    if (sourcePath == null) {
        sourcePath = ClassPath.EMPTY;
    }
    this.sourcePath = sourcePath;
    return this;
}
 
Example 10
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 11
Source File: CompileWorkerTestBase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected ParsingOutput runIndexing(List<CompileTuple> files, List<CompileTuple> virtualFiles, List<CompileTuple> extraSourceFiles) throws Exception {
    TransactionContext txc = TransactionContext.beginStandardTransaction(src.toURL(), true, ()->false, false);
    Factory f = new JavaCustomIndexer.Factory();
    Context ctx = SPIAccessor.getInstance().createContext(CacheFolder.getDataFolder(src.toURL()), src.toURL(), f.getIndexerName(), f.getIndexVersion(), LuceneIndexFactory.getDefault(), false, false, true, SPIAccessor.getInstance().createSuspendStatus(new SuspendStatusImpl() {
        @Override
        public boolean isSuspendSupported() {
            return true;
        }
        @Override public boolean isSuspended() {
            return false;
        }
        @Override public void parkWhileSuspended() throws InterruptedException { }
    }), new CancelRequest() {
        @Override public boolean isRaised() {
            return false;
        }
    }, LogContext.create(EventType.PATH, ""));
    
    JavaParsingContext javaContext = new JavaParsingContext(ctx, ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0])), ClassPath.EMPTY, ClassPathSupport.createClassPath(new FileObject[0]), ClassPath.EMPTY, ClassPath.EMPTY, ClassPathSupport.createClassPath(new FileObject[] {src}), ClassPath.EMPTY, virtualFiles);
    List<CompileTuple> toIndex = new ArrayList<CompileTuple>();
    
    toIndex.addAll(files);
    toIndex.addAll(virtualFiles);
    
    for (CompileTuple extra : extraSourceFiles) {
        try (OutputStream out = FileUtil.createData(extraSrc, extra.indexable.getRelativePath()).getOutputStream();
             Writer w = new OutputStreamWriter(out)) {
            w.append(extra.jfo.getCharContent(true));
        }
    }

    ParsingOutput result = runCompileWorker(ctx, javaContext, toIndex);
    
    javaContext.finish();
    javaContext.store();
    txc.commit();
    
    return result;
}
 
Example 12
Source File: JShellSourcePathTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void init(final FileObject workDir) throws IOException {
    src = FileUtil.createFolder(
            workDir,
            "src"); //NOI18N
    sourcesImpl = ClassPathSupport.createClassPathImplementation(
            Collections.singletonList(ClassPathSupport.createResource(src.toURL())));
    sources = ClassPathFactory.createClassPath(sourcesImpl);
    boot = JavaPlatform.getDefault().getBootstrapLibraries();
    compile = ClassPath.EMPTY;
    final MockClassPathProvider cpp = Lookup.getDefault().lookup(MockClassPathProvider.class);
    if (cpp == null) {
        throw new IllegalStateException("No ClasspathProvider");    //NOI18N
    }
    cpp.setUp(src, boot, compile, sources);
}
 
Example 13
Source File: QuerySupportTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testGetDependentRootsJavaLikeDependenciesAllProjectsOpened() throws IOException, InterruptedException {
    final FileObject wd = FileUtil.toFileObject(getWorkDir());
    final FileObject src1 = FileUtil.createFolder(wd,"src1");   //NOI18N
    final URL build1 = FileUtil.urlForArchiveOrDir(new File (getWorkDir(),"build1"));//NOI18N
    final FileObject src2 = FileUtil.createFolder(wd,"src2");   //NOI18N
    final URL build2 = FileUtil.urlForArchiveOrDir(new File (getWorkDir(),"build2"));    //NOI18N
    final FileObject src3 = FileUtil.createFolder(wd,"src3");   //NOI18N
    final URL build3 = FileUtil.urlForArchiveOrDir(new File (getWorkDir(),"build3"));    //NOI18N
    final FileObject src4 = FileUtil.createFolder(wd,"src4");   //NOI18N
    final URL build4 = FileUtil.urlForArchiveOrDir(new File (getWorkDir(),"build4"));   //NOI18N

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

    final Map<URL,Pair<Boolean,List<FileObject>>> sfbq = new HashMap<URL, Pair<Boolean,List<FileObject>>>();
    sfbq.put(build1,Pair.of(true,Collections.singletonList(src1)));
    sfbq.put(build2,Pair.of(true,Collections.singletonList(src2)));
    sfbq.put(build3,Pair.of(true,Collections.singletonList(src3)));
    sfbq.put(build4,Pair.of(true,Collections.singletonList(src4)));
    SourceForBinaryQueryImpl.register(sfbq);


    final ClassPath boot = ClassPath.EMPTY;
    final Map<String,ClassPath> src1cps = new HashMap<String, ClassPath>();
    src1cps.put(JavaLikePathRecognizer.BOOT, boot);
    src1cps.put(JavaLikePathRecognizer.COMPILE, ClassPath.EMPTY);
    src1cps.put(JavaLikePathRecognizer.SRC, src1Source);
    final Map<String,ClassPath> src2cps = new HashMap<String, ClassPath>();
    src2cps.put(JavaLikePathRecognizer.BOOT, boot);
    src2cps.put(JavaLikePathRecognizer.COMPILE, src2Compile);
    src2cps.put(JavaLikePathRecognizer.SRC, src2Source);
    final Map<String,ClassPath> src3cps = new HashMap<String, ClassPath>();
    src3cps.put(JavaLikePathRecognizer.BOOT, boot);
    src3cps.put(JavaLikePathRecognizer.COMPILE, src3Compile);
    src3cps.put(JavaLikePathRecognizer.SRC, src3Source);
    final Map<String,ClassPath> src4cps = new HashMap<String, ClassPath>();
    src4cps.put(JavaLikePathRecognizer.BOOT, boot);
    src4cps.put(JavaLikePathRecognizer.COMPILE, src4Compile);
    src4cps.put(JavaLikePathRecognizer.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(
            JavaLikePathRecognizer.BOOT,
            new ClassPath[]{
                boot
            });
    globalPathRegistry_register(
            JavaLikePathRecognizer.COMPILE,
            new ClassPath[]{
                src2Compile,
                src3Compile,
                src4Compile
            });
    globalPathRegistry_register(
            JavaLikePathRecognizer.SRC,
            new ClassPath[]{
                src1Source,
                src2Source,
                src3Source,
                src4Source
            });

    RepositoryUpdater.getDefault().waitUntilFinished(RepositoryUpdaterTest.TIME);
    assertEquals(
            IndexingController.getDefault().getRootDependencies().keySet().toString(),
            4,
            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[] {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));
}
 
Example 14
Source File: RemotePlatform.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public ClassPath getSourceFolders() {
    return ClassPath.EMPTY;
}
 
Example 15
Source File: AndroidJavaPlatform.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
@Override
public ClassPath getStandardLibraries() {
    return ClassPath.EMPTY;
}
 
Example 16
Source File: ProfileSupportTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public ClassPath getSourceFolders() {
    return ClassPath.EMPTY;
}
 
Example 17
Source File: DefaultClassPathProviderTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public ClassPath getSourceFolders() {
    return ClassPath.EMPTY;
}
 
Example 18
Source File: DefaultClassPathProviderTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public ClassPath getStandardLibraries() {
    return ClassPath.EMPTY;
}
 
Example 19
Source File: ProfileSupportTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public ClassPath getStandardLibraries() {
    return ClassPath.EMPTY;
}
 
Example 20
Source File: QuerySupportTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testGetDependentRootsJavaLikeDependenciesProjectsClosed() throws IOException, InterruptedException {
    final FileObject wd = FileUtil.toFileObject(getWorkDir());
    final FileObject src1 = FileUtil.createFolder(wd,"src1");   //NOI18N
    final URL build1 = FileUtil.urlForArchiveOrDir(new File (getWorkDir(),"build1"));//NOI18N
    final FileObject src2 = FileUtil.createFolder(wd,"src2");   //NOI18N
    final URL build2 = FileUtil.urlForArchiveOrDir(new File (getWorkDir(),"build2"));    //NOI18N
    final FileObject src3 = FileUtil.createFolder(wd,"src3");   //NOI18N
    final URL build3 = FileUtil.urlForArchiveOrDir(new File (getWorkDir(),"build3"));    //NOI18N
    final FileObject src4 = FileUtil.createFolder(wd,"src4");   //NOI18N
    final URL build4 = FileUtil.urlForArchiveOrDir(new File (getWorkDir(),"build4"));   //NOI18N

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

    final Map<URL,Pair<Boolean,List<FileObject>>> sfbq = new HashMap<URL, Pair<Boolean,List<FileObject>>>();
    sfbq.put(build1,Pair.of(true,Collections.singletonList(src1)));
    sfbq.put(build2,Pair.of(true,Collections.singletonList(src2)));
    sfbq.put(build3,Pair.of(true,Collections.singletonList(src3)));
    sfbq.put(build4,Pair.of(true,Collections.singletonList(src4)));
    SourceForBinaryQueryImpl.register(sfbq);


    final ClassPath boot = ClassPath.EMPTY;
    final Map<String,ClassPath> src1cps = new HashMap<String, ClassPath>();
    src1cps.put(JavaLikePathRecognizer.BOOT, boot);
    src1cps.put(JavaLikePathRecognizer.COMPILE, ClassPath.EMPTY);
    src1cps.put(JavaLikePathRecognizer.SRC, src1Source);
    final Map<String,ClassPath> src2cps = new HashMap<String, ClassPath>();
    src2cps.put(JavaLikePathRecognizer.BOOT, boot);
    src2cps.put(JavaLikePathRecognizer.COMPILE, src2Compile);
    src2cps.put(JavaLikePathRecognizer.SRC, src2Source);
    final Map<String,ClassPath> src3cps = new HashMap<String, ClassPath>();
    src3cps.put(JavaLikePathRecognizer.BOOT, boot);
    src3cps.put(JavaLikePathRecognizer.COMPILE, src3Compile);
    src3cps.put(JavaLikePathRecognizer.SRC, src3Source);
    final Map<String,ClassPath> src4cps = new HashMap<String, ClassPath>();
    src4cps.put(JavaLikePathRecognizer.BOOT, boot);
    src4cps.put(JavaLikePathRecognizer.COMPILE, src4Compile);
    src4cps.put(JavaLikePathRecognizer.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(
            JavaLikePathRecognizer.BOOT,
            new ClassPath[]{
                boot
            });
    globalPathRegistry_register(
            JavaLikePathRecognizer.COMPILE,
            new ClassPath[]{
                src4Compile
            });
    globalPathRegistry_register(
            JavaLikePathRecognizer.SRC,
            new ClassPath[]{
                src4Source
            });

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

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


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