org.netbeans.api.java.classpath.ClassPath Java Examples
The following examples show how to use
org.netbeans.api.java.classpath.ClassPath.
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: ModuleFileManager.java From netbeans with Apache License 2.0 | 6 votes |
private Set<ModuleLocation> moduleLocations(final Location baseLocation) { if (!forLocation.equals(baseLocation)) { throw new IllegalStateException(String.format( "Locations computed for: %s, but queried for: %s", //NOI18N forLocation, baseLocation)); } if (moduleLocations == null) { final Set<ModuleLocation> moduleRoots = new HashSet<>(); final Set<URL> seen = new HashSet<>(); for (ClassPath.Entry e : modulePath.entries()) { final URL root = e.getURL(); if (!seen.contains(root)) { final String moduleName = SourceUtils.getModuleName(root); if (moduleName != null) { Collection<? extends URL> p = peers.apply(root); moduleRoots.add(ModuleLocation.create(baseLocation, p, moduleName)); seen.addAll(p); } } } moduleLocations = moduleRoots; } return moduleLocations; }
Example #2
Source File: ClassPathProviderImplTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testRecursiveCompileTestDependency() throws Exception { generateTestingSuite(); NbModuleProject modD = generateTestingSuiteComponent(testSuite,"d", "", "<test-dependency>\n" + "<code-name-base>org.example.a</code-name-base>\n" + "<recursive/>\n" + "<compile-dependency/>\n" + // "<test/>\n" + "</test-dependency>\n", ""); ClassPathProvider cpp = modD.getLookup().lookup(ClassPathProvider.class); ClassPath cp = cpp.findClassPath(modD.getTestSourceDirectory("unit"), ClassPath.COMPILE); Set<String> expectedRoots = new TreeSet<String>(); expectedRoots.addAll(TESTLIBS); expectedRoots.add(urlForJar(modD.getModuleJarLocation().getPath())); expectedRoots.add(urlForJar(modA.getModuleJarLocation().getPath())); expectedRoots.add(urlForJar(modB.getModuleJarLocation().getPath())); expectedRoots.add(urlForJar(modC.getModuleJarLocation().getPath())); assertEquals("correct TEST COMPILE classpath", expectedRoots, urlsOfCp4Tests(cp)); cp = cpp.findClassPath(modD.getTestSourceDirectory("unit"), ClassPath.EXECUTE); expectedRoots.add(urlForJar(modD.getTestClassesDirectory("unit").getPath())); assertEquals("correct TEST EXECUTE classpath", expectedRoots, urlsOfCp4Tests(cp)); }
Example #3
Source File: JavaFxRuntimeInclusion.java From netbeans with Apache License 2.0 | 6 votes |
/** * Returns status of the artifact at relative path runtimePath in platform javaPlatform * @param javaPlatform the {@link JavaPlatform} where the artifact is to be searched for * @param runtimePath relative path to artifact * @return status of artifact presence/inclusion in platform */ @NonNull private static Support forRuntime(@NonNull final JavaPlatform javaPlatform, @NonNull final String runtimePath) { Parameters.notNull("javaPlatform", javaPlatform); //NOI18N Parameters.notNull("rtPath", runtimePath); //NOI18N for (FileObject installFolder : javaPlatform.getInstallFolders()) { final FileObject jfxrtJar = installFolder.getFileObject(runtimePath); if (jfxrtJar != null && jfxrtJar.isData()) { final URL jfxrtRoot = FileUtil.getArchiveRoot(jfxrtJar.toURL()); for (ClassPath.Entry e : javaPlatform.getBootstrapLibraries().entries()) { if (jfxrtRoot.equals(e.getURL())) { return Support.INCLUDED; } } return Support.PRESENT; } } return Support.MISSING; }
Example #4
Source File: BatchSearchTest.java From netbeans with Apache License 2.0 | 6 votes |
public synchronized ClassPath findClassPath(FileObject file, String type) { if (ClassPath.BOOT.equals(type)) { return ClassPathSupport.createClassPath(getBootClassPath().toArray(new URL[0])); } if (ClassPath.COMPILE.equals(type)) { return ClassPathSupport.createClassPath(new URL[0]); } if (ClassPath.SOURCE.equals(type) && sourceRoots != null) { for (FileObject sr : sourceRoots) { if (file.equals(sr) || FileUtil.isParentOf(sr, file)) { return ClassPathSupport.createClassPath(sr); } } } return null; }
Example #5
Source File: JShellSourcePathTest.java From netbeans with Apache License 2.0 | 6 votes |
@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 #6
Source File: CfgPropsCompletionQuery.java From nb-springboot with Apache License 2.0 | 6 votes |
private void completeValueEnum(String dataType, String filter, CompletionResultSet completionResultSet, int startOffset, int caretOffset) { try { ClassPath cpExec = Utils.execClasspathForProj(proj); Object[] enumvals = cpExec.getClassLoader(true).loadClass(dataType).getEnumConstants(); if (enumvals != null) { for (Object val : enumvals) { final String valName = val.toString().toLowerCase(); if (valName.contains(filter)) { completionResultSet.addItem(new ValueCompletionItem(Utils.createEnumHint(valName), startOffset, caretOffset)); } } } } catch (ClassNotFoundException ex) { // enum not available in project classpath, no completion possible } }
Example #7
Source File: J2SEPlatformSourceJavadocAttacher.java From netbeans with Apache License 2.0 | 6 votes |
private J2SEPlatformImpl findOwner(final URL root) { for (JavaPlatform p : JavaPlatformManager.getDefault().getPlatforms(null, new Specification(J2SEPlatformImpl.PLATFORM_J2SE, null))) { if (!(p instanceof J2SEPlatformImpl)) { //Cannot handle unknown platform continue; } final J2SEPlatformImpl j2sep = (J2SEPlatformImpl) p; if (!j2sep.isValid()) { continue; } for (ClassPath.Entry entry : j2sep.getBootstrapLibraries().entries()) { if (root.equals(entry.getURL())) { return j2sep; } } } return null; }
Example #8
Source File: DefaultGlobalPathRegistryImplementation.java From netbeans with Apache License 2.0 | 6 votes |
@Override @NonNull protected Set<ClassPath> register( @NonNull final String id, @NonNull final ClassPath[] paths) { final Set<ClassPath> added = new HashSet<>(); List<ClassPath> l = this.paths.get(id); if (l == null) { l = new ArrayList<>(); this.paths.put(id, l); } for (ClassPath path : paths) { if (path == null) { throw new NullPointerException("Null path encountered in " + Arrays.asList(paths) + " of type " + id); // NOI18N } if (!added.contains(path) && !l.contains(path)) { added.add(path); } l.add(path); } return added; }
Example #9
Source File: ProjectOpenedHookImpl.java From netbeans with Apache License 2.0 | 6 votes |
protected @Override void projectClosed() { NbMavenProjectImpl project = proj.getLookup().lookup(NbMavenProjectImpl.class); //we stop listening for changes in external roots //but as before, we keep the latest known roots upon closing.. project.getProjectWatcher().removePropertyChangeListener(extRootChangeListener); synchronized (uriReferences) { uriReferences.clear(); } project.detachUpdater(); // unregister project's classpaths to GlobalPathRegistry ProjectSourcesClassPathProvider cpProvider = proj.getLookup().lookup(ProjectSourcesClassPathProvider.class); GlobalPathRegistry.getDefault().unregister(ClassPath.BOOT, cpProvider.getProjectClassPaths(ClassPath.BOOT)); GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, cpProvider.getProjectClassPaths(ClassPath.SOURCE)); GlobalPathRegistry.getDefault().unregister(ClassPath.COMPILE, cpProvider.getProjectClassPaths(ClassPath.COMPILE)); GlobalPathRegistry.getDefault().unregister(ClassPath.EXECUTE, cpProvider.getProjectClassPaths(ClassPath.EXECUTE)); BatchProblemNotifier.closed(project); project.getCopyOnSaveResources().closed(); if (transRepos != null) { // XXX #212555 projectOpened was not called first? transRepos.unregister(); } project.stopHardReferencingMavenPoject(); }
Example #10
Source File: ClassPathProviderImpl.java From netbeans with Apache License 2.0 | 6 votes |
private synchronized ClassPath getSourcepath(int type) { if (type < 0 || type > 1) { return null; } ClassPath cp = cache[type]; if (cp == null) { switch (type) { case 0: cp = ClassPathFactory.createClassPath( SourcePathImplementation.forProject(project, this.sourceRoots)); break; case 1: cp = ClassPathFactory.createClassPath( SourcePathImplementation.forProject(project, this.testSourceRoots)); break; } } cache[type] = cp; return cp; }
Example #11
Source File: LibrariesNode.java From netbeans with Apache License 2.0 | 6 votes |
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 #12
Source File: ScriptClassPathProvider.java From netbeans with Apache License 2.0 | 6 votes |
@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 #13
Source File: ClassPathProviderImplTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testCompileClasspathChanges() throws Exception { ClassPath cp = ClassPath.getClassPath(copyOfMiscDir.getFileObject("src"), ClassPath.COMPILE); Set<String> expectedRoots = new TreeSet<String>(); assertEquals("right initial COMPILE classpath", expectedRoots, urlsOfCp(cp)); TestBase.TestPCL l = new TestBase.TestPCL(); cp.addPropertyChangeListener(l); ModuleEntry ioEntry = copyOfMiscProject.getModuleList().getEntry("org.openide.io"); assertNotNull(ioEntry); copyOfMiscXMLManager.addDependencies(Collections.singleton(new ModuleDependency(ioEntry))); assertTrue("got changes", l.changed.contains(ClassPath.PROP_ROOTS)); l.changed.clear(); expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-io.jar")); assertEquals("right COMPILE classpath after changing project.xml", expectedRoots, urlsOfCp(cp)); ModuleEntry utilEntry = copyOfMiscProject.getModuleList().getEntry("org.openide.util"); assertNotNull(utilEntry); copyOfMiscXMLManager.addDependencies(Collections.singleton(new ModuleDependency(utilEntry))); assertTrue("got changes again", l.changed.contains(ClassPath.PROP_ROOTS)); l.changed.clear(); expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/lib/org-openide-util.jar")); assertEquals("right COMPILE classpath after changing project.xml again", expectedRoots, urlsOfCp(cp)); }
Example #14
Source File: AddGoogleDependencyAction.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
private void findCompileTimeDependencies(NbAndroidProject project, List<ArtifactData> compileDependecies) { final ClassPathProvider cpProvider = project.getLookup().lookup(ClassPathProvider.class); if (cpProvider != null) { Sources srcs = ProjectUtils.getSources(project); SourceGroup[] sourceGroups = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); Set<FileObject> roots = Sets.newHashSet(); for (SourceGroup sg : sourceGroups) { roots.add(sg.getRootFolder()); } Iterable<ClassPath> compileCPs = Iterables.transform(roots, new Function<FileObject, ClassPath>() { @Override public ClassPath apply(FileObject f) { return cpProvider.findClassPath(f, ClassPath.COMPILE); } }); ClassPath compileCP = ClassPathSupport.createProxyClassPath(Lists.newArrayList(compileCPs).toArray(new ClassPath[0])); if (cpProvider instanceof AndroidClassPath) { for (FileObject cpRoot : compileCP.getRoots()) { ArtifactData lib = ((AndroidClassPath) cpProvider).getArtifactData(cpRoot.toURL()); compileDependecies.add(lib); } } } }
Example #15
Source File: SourceGroupSupport.java From netbeans with Apache License 2.0 | 6 votes |
public static ElementHandle<TypeElement> getHandleClassName(String qualifiedClassName, Project project) throws IOException { FileObject root = MiscUtilities.findSourceRoot(project); ClassPathProvider provider = project.getLookup().lookup( ClassPathProvider.class); ClassPath sourceCp = provider.findClassPath(root, ClassPath.SOURCE); ClassPath compileCp = provider.findClassPath(root, ClassPath.COMPILE); ClassPath bootCp = provider.findClassPath(root, ClassPath.BOOT); ClasspathInfo cpInfo = ClasspathInfo.create(bootCp, compileCp, sourceCp); ClassIndex ci = cpInfo.getClassIndex(); int beginIndex = qualifiedClassName.lastIndexOf('.')+1; String simple = qualifiedClassName.substring(beginIndex); Set<ElementHandle<TypeElement>> handles = ci.getDeclaredTypes( simple, ClassIndex.NameKind.SIMPLE_NAME, EnumSet.of(ClassIndex.SearchScope.SOURCE, ClassIndex.SearchScope.DEPENDENCIES)); for (final ElementHandle<TypeElement> handle : handles) { if (qualifiedClassName.equals(handle.getQualifiedName())) { return handle; } } return null; }
Example #16
Source File: ActionProviderImplTest.java From netbeans with Apache License 2.0 | 6 votes |
private void doTestStandaloneLangtools(String langtoolsClassesDir) throws Exception { createDir("langtools/src/java.compiler/share/classes"); createDir(langtoolsClassesDir); FileObject langtoolsProject = createDir("langtools/make/netbeans/langtools"); FileObject testFile = createFile("langtools/test/Test.java"); FileOwnerQuery.markExternalOwner(testFile.getParent(), FileOwnerQuery.getOwner(langtoolsProject), FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT); ClassPath allSources = ActionProviderImpl.allSources(testFile); assertEquals(new HashSet<>(Arrays.asList("langtools/src/java.compiler/share/classes")), relative(FileUtil.toFileObject(getWorkDir()), Arrays.asList(allSources.getRoots()))); String builtClassesDirs = ActionProviderImpl.builtClassesDirsForBootClassPath(testFile); builtClassesDirs = builtClassesDirs.replace(getWorkDir().getAbsolutePath(), ""); assertEquals("/" + langtoolsClassesDir, builtClassesDirs); String jtregOutputDirs = Utilities.jtregOutputDir(testFile).getAbsolutePath(); jtregOutputDirs = jtregOutputDirs.replace(getWorkDir().getAbsolutePath(), ""); assertEquals("/langtools/build/nb-jtreg", jtregOutputDirs); }
Example #17
Source File: FXMLCompletionTestBase.java From netbeans with Apache License 2.0 | 5 votes |
private static ClassPath createClassPath(String classpath) { StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator); List/*<PathResourceImplementation>*/ list = new ArrayList(); while (tokenizer.hasMoreTokens()) { String item = tokenizer.nextToken(); File f = FileUtil.normalizeFile(new File(item)); URL url = getRootURL(f); if (url!=null) { list.add(ClassPathSupport.createResource(url)); } } return ClassPathSupport.createClassPath(list); }
Example #18
Source File: ClassPathProviderImpl.java From netbeans with Apache License 2.0 | 5 votes |
@Override public ClassPath findClassPath(FileObject file, String type) { if (type.equals(ClassPath.COMPILE)) { return getCompileTimeClasspath(file); } else if (type.equals(ClassPath.EXECUTE)) { return getRunTimeClasspath(file); } else if (type.equals(ClassPath.SOURCE)) { return getSourcepath(file); } else if (type.equals(ClassPath.BOOT)) { return getBootClassPath(); } else { return null; } }
Example #19
Source File: JsCodeCompletionArgumentsTest.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected Map<String, ClassPath> createClassPathsForTest() { List<FileObject> cpRoots = new LinkedList<FileObject>(ClasspathProviderImplAccessor.getJsStubs()); cpRoots.add(FileUtil.toFileObject(new File(getDataDir(), "/testfiles/completion/arguments"))); cpRoots.add(FileUtil.toFileObject(new File(getDataDir(), "/testfiles/completion/lib"))); return Collections.singletonMap( JS_SOURCE_ID, ClassPathSupport.createClassPath(cpRoots.toArray(new FileObject[cpRoots.size()])) ); }
Example #20
Source File: Icefaces2Implementation.java From netbeans with Apache License 2.0 | 5 votes |
@Override public boolean isInWebModule(WebModule webModule) { ClassPath classpath = ClassPath.getClassPath(webModule.getDocumentBase(), ClassPath.COMPILE); if (classpath.findResource(ICEFACES_CORE_CLASS.replace('.', '/') + ".class") != null) { //NOI18N return true; } return false; }
Example #21
Source File: RefactoringUtils.java From netbeans with Apache License 2.0 | 5 votes |
public static boolean isClasspathRoot(FileObject fo) { ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE); if (cp != null) { FileObject f = cp.findOwnerRoot(fo); if (f != null) { return fo.equals(f); } } return false; }
Example #22
Source File: JSFUtils.java From netbeans with Apache License 2.0 | 5 votes |
/** * Whether the given classpath contains support for Facelets. * * @param cp examined classpath * @return {@code true} if the facelets classes are present on the classpath, {@code false} otherwise */ public static boolean isFaceletsPresent(ClassPath cp) { if (cp == null) { return false; } return cp.findResource(JSFUtils.MYFACES_SPECIFIC_CLASS.replace('.', '/') + ".class") != null || //NOI18N cp.findResource("com/sun/facelets/Facelet.class") != null || //NOI18N cp.findResource("com/sun/faces/facelets/Facelet.class") != null || // NOI18N cp.findResource("javax/faces/view/facelets/FaceletContext.class") != null; //NOI18N }
Example #23
Source File: DeprTypeUsageSemanticAnalysisTest.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected Map<String, ClassPath> createClassPathsForTest() { return Collections.singletonMap( PhpSourcePath.SOURCE_CP, ClassPathSupport.createClassPath(new FileObject[] { FileUtil.toFileObject(new File(getDataDir(), "/testfiles/semantic/deprecatedTypeUsages")) }) ); }
Example #24
Source File: BootClassPathUtil.java From netbeans with Apache License 2.0 | 5 votes |
public static ClassPath getModuleBootPath() { if (System.getProperty("sun.boot.class.path") != null) { try { //JDK 8: return getModuleBootOnJDK8(); } catch (Exception ex) { throw new IllegalStateException(ex); } } else { return getBootClassPath(); } }
Example #25
Source File: PlatformSourceForBinaryQuery.java From netbeans with Apache License 2.0 | 5 votes |
static boolean contains( @NonNull final JavaPlatform platform, @NonNull final URL artifact) { for (ClassPath.Entry entry : platform.getBootstrapLibraries().entries()) { if (entry.getURL().equals (artifact)) { return true; } } return false; }
Example #26
Source File: PlatformClassPathProvider.java From netbeans with Apache License 2.0 | 5 votes |
@CheckForNull private static FileObject getArtefactOwner( @NonNull final FileObject file, @NonNull final ClassPath... cps) { for (ClassPath cp : cps) { FileObject root; if (cp != null && (root = cp.findOwnerRoot (file)) != null) { return root; } } return null; }
Example #27
Source File: ModelIndexTest.java From netbeans with Apache License 2.0 | 5 votes |
void performModelTest(AbstractTestModelTask task, String testFilePath) throws Exception { FileObject testFile = getTestFile(testFilePath); Source testSource = getTestSource(testFile); Map<String, ClassPath> classPaths = createClassPathsForTest(); if (classPaths == null || classPaths.isEmpty()) { ParserManager.parse(Collections.singleton(testSource), task); } else { Future<Void> future = ParserManager.parseWhenScanFinished(Collections.singleton(testSource), task); if (!future.isDone()) { future.get(); } } }
Example #28
Source File: PHPCodeCompletion208784Test.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected Map<String, ClassPath> createClassPathsForTest() { return Collections.singletonMap( PhpSourcePath.SOURCE_CP, ClassPathSupport.createClassPath(new FileObject[] { FileUtil.toFileObject(new File(getDataDir(), "/testfiles/completion/lib/test208784/")) }) ); }
Example #29
Source File: ModuleOraculum.java From netbeans with Apache License 2.0 | 5 votes |
boolean installModuleName( @NullAllowed FileObject root, @NullAllowed final FileObject fo) { if (fo != null && fo.isData() && (FileObjects.MODULE_INFO.equals(fo.getName()) || FileObjects.CLASS.equals(fo.getExt()))) { //No needed to install module name for module-info or class file return false; } if (root == null && fo != null) { root = computeRootIfAbsent(fo, (f) -> { final ClassPath src = ClassPath.getClassPath(f, ClassPath.SOURCE); FileObject owner = src != null ? src.findOwnerRoot(f) : null; if (owner == null && f.isData() && FileUtil.getMIMEType(f, null, JavacParser.MIME_TYPE) != null) { String pkg = parsePackage(f); String[] pkgElements = pkg.isEmpty() ? new String[0] : pkg.split("\\."); //NOI18N owner = f.getParent(); for (int i = 0; owner != null && i < pkgElements.length; i++) { owner = owner.getParent(); } } return owner; }); } if (root == null || JavaIndex.hasSourceCache(root.toURL(), false)) { return false; } String name = computeModuleIfAbsent(root, (r) -> { final FileObject moduleInfo = r.getFileObject(FileObjects.MODULE_INFO,FileObjects.JAVA); if (moduleInfo == null || !moduleInfo.isData() || !moduleInfo.canRead()) { return null; } return SourceUtils.parseModuleName(moduleInfo); }); moduleName.set(name); return true; }
Example #30
Source File: JavaTypeProviderTest.java From netbeans with Apache License 2.0 | 5 votes |
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; }