Java Code Examples for org.netbeans.api.java.classpath.ClassPath#Entry
The following examples show how to use
org.netbeans.api.java.classpath.ClassPath#Entry .
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: SourcePathImplAddonsTest.java From netbeans with Apache License 2.0 | 6 votes |
private void assertContainsURL(List<ClassPath.Entry> list, URL url, boolean present){ ClassPath.Entry cpe = null; Iterator<ClassPath.Entry> itr = itr = list.iterator(); if (present){ boolean found = false; while (itr.hasNext()){ cpe = itr.next(); if (url.equals(cpe.getURL())){ found = true; } } assertTrue(found); } else { while (itr.hasNext()){ cpe = itr.next(); assertFalse(url.equals(cpe.getURL())); } } }
Example 2
Source File: OutputFileManager.java From netbeans with Apache License 2.0 | 6 votes |
private File getClassFolderForSourceImpl (final URL sibling) throws IOException { List<ClassPath.Entry> entries = this.scp.entries(); int eSize = entries.size(); if ( eSize == 1) { return getClassFolder(entries.get(0).getURL()); } if (eSize == 0) { return null; } try { for (ClassPath.Entry entry : entries) { URL rootUrl = entry.getURL(); if (FileObjects.isParentOf(rootUrl, sibling)) { return getClassFolder(rootUrl); } } } catch (IllegalArgumentException e) { //Logging for issue #151416 String message = String.format("uri: %s", sibling.toString()); throw Exceptions.attachMessage(e, message); } return null; }
Example 3
Source File: ClassPathProviderImplTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testCompileClassPath() throws Exception { TestFileUtils.writeFile(d, "pom.xml", "<project xmlns='http://maven.apache.org/POM/4.0.0'>" + "<modelVersion>4.0.0</modelVersion>" + "<groupId>grp</groupId>" + "<artifactId>art</artifactId>" + "<packaging>jar</packaging>" + "<version>1.0-SNAPSHOT</version>" + "<name>Test</name>" + "</project>"); FileObject src = FileUtil.createFolder(d, "src/main/java"); ClassPath cp = ClassPath.getClassPath(src, ClassPath.COMPILE); assertNotNull(cp); List<ClassPath.Entry> entries = cp.entries(); assertFalse(entries.isEmpty()); }
Example 4
Source File: OutputFileManager.java From netbeans with Apache License 2.0 | 6 votes |
private File getClassFolderForApt( final Location l, final String baseName) { String[] parentName = splitParentName(baseName); final Collection<? extends URL> roots = getLocationRoots(l); for (ClassPath.Entry entry : this.apt.entries()) { FileObject root = entry.getRoot(); if (root != null) { FileObject parentFile = root.getFileObject(parentName[0]); if (parentFile != null) { if (parentFile.getFileObject(parentName[1], FileObjects.JAVA) != null) { final URL classFolder = AptCacheForSourceQuery.getClassFolder(entry.getURL()); if (classFolder != null && roots.contains(classFolder)) { try { return BaseUtilities.toFile(classFolder.toURI()); } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); } } } } } } return null; }
Example 5
Source File: SourcePathImplAddonsTest.java From netbeans with Apache License 2.0 | 6 votes |
private void assertContainsURL(List<ClassPath.Entry> list, URL url, boolean present){ ClassPath.Entry cpe = null; Iterator<ClassPath.Entry> itr = itr = list.iterator(); if (present){ boolean found = false; while (itr.hasNext()){ cpe = itr.next(); if (url.equals(cpe.getURL())){ found = true; } } assertTrue(found); } else { while (itr.hasNext()){ cpe = itr.next(); assertFalse(url.equals(cpe.getURL())); } } }
Example 6
Source File: SpringBeanImpl.java From netbeans with Apache License 2.0 | 6 votes |
private static FileObject getFileFromClasspath(ClassPath cp, String classRelativePath) { for (ClassPath.Entry entry : cp.entries()) { FileObject roots[]; if (entry.isValid()) { roots = new FileObject[]{entry.getRoot()}; } else { SourceForBinaryQuery.Result res = SourceForBinaryQuery.findSourceRoots(entry.getURL()); roots = res.getRoots(); } for (FileObject root : roots) { FileObject metaInf = root.getFileObject(classRelativePath); if (metaInf != null) { return metaInf; } } } return null; }
Example 7
Source File: JavaBinaryIndexer.java From netbeans with Apache License 2.0 | 6 votes |
public static void preBuildArgs( @NonNull final FileObject root, @NonNull final FileObject file) throws IOException { final String relativePath = FileObjects.convertFolder2Package( FileObjects.stripExtension( FileUtil.getRelativePath(root, file))); final TransactionContext txCtx = TransactionContext.beginTrans() .register(FileManagerTransaction.class, FileManagerTransaction.writeThrough()) .register(ProcessorGenerated.class, ProcessorGenerated.nullWrite()); try { final Collection<ClassPath.Entry> entries = JavaPlatform.getDefault().getBootstrapLibraries().entries(); final URL[] roots = new URL[1+entries.size()]; roots[0] = root.toURL(); final Iterator<ClassPath.Entry> eit = entries.iterator(); for (int i=1; eit.hasNext(); i++) { roots[i] = eit.next().getURL(); } preBuildArgs(relativePath, roots); } finally { txCtx.commit(); } }
Example 8
Source File: JSFUtils.java From netbeans with Apache License 2.0 | 5 votes |
/** * Use {@link JSFVersion#get(org.netbeans.modules.web.api.webmodule.WebModule, boolean) } instead. */ @Deprecated private static boolean isJSFPlus(WebModule webModule, boolean includingPlatformCP, String versionSpecificClass) { if (webModule == null) { return false; } final ClassPath compileCP = ClassPath.getClassPath(webModule.getDocumentBase(), ClassPath.COMPILE); if (compileCP == null) { return false; } if (includingPlatformCP) { return compileCP.findResource(versionSpecificClass.replace('.', '/') + ".class") != null; //NOI18N } else { Project project = FileOwnerQuery.getOwner(getFileObject(webModule)); if (project == null) { return false; } List<File> platformClasspath = Arrays.asList(ClasspathUtil.getJ2eePlatformClasspathEntries(project, ProjectUtil.getPlatform(project))); List<URL> projectDeps = new ArrayList<URL>(); for (ClassPath.Entry entry : compileCP.entries()) { File archiveOrDir = FileUtil.archiveOrDirForURL(entry.getURL()); if (archiveOrDir == null || !platformClasspath.contains(archiveOrDir)) { projectDeps.add(entry.getURL()); } } try { return ClasspathUtil.containsClass(projectDeps, versionSpecificClass); //NOI18N } catch (IOException ex) { Exceptions.printStackTrace(ex); } } return false; }
Example 9
Source File: ClassIndex.java From netbeans with Apache License 2.0 | 5 votes |
private boolean containsNewRoot (final ClassPath cp, final Set<? extends URL> roots, final List<? super URL> newRoots, final List<? super URL> removedRoots, final Set<? super URL> attachListener, final boolean translate) throws IOException { final List<ClassPath.Entry> entries = cp.entries(); final PathRegistry preg = PathRegistry.getDefault(); boolean result = false; for (ClassPath.Entry entry : entries) { URL url = entry.getURL(); URL[] srcRoots = null; if (translate) { srcRoots = preg.sourceForBinaryQuery(entry.getURL(), cp, false); } if (srcRoots == null) { if (!roots.remove(url)) { if (JavaIndex.isIndexed(url)) { newRoots.add (url); result = true; } else { attachListener.add(url); } } } else { for (URL _url : srcRoots) { if (!roots.remove(_url)) { if (JavaIndex.isIndexed(_url)) { newRoots.add (_url); result = true; } else { attachListener.add(_url); } } } } } result |= !roots.isEmpty(); Collection<? super URL> c = removedRoots; c.addAll(roots); return result; }
Example 10
Source File: OutputFileManager.java From netbeans with Apache License 2.0 | 5 votes |
private File getClassFolderForSourceImpl ( final Location l, final String baseName) throws IOException { List<ClassPath.Entry> entries = this.scp.entries(); int eSize = entries.size(); if (eSize == 1) { return getClassFolder(entries.get(0).getURL()); } if (eSize == 0) { return null; } final String[] parentName = splitParentName(baseName); final Collection<? extends URL> roots = getLocationRoots(l); for (ClassPath.Entry entry : entries) { FileObject root = entry.getRoot(); if (root != null) { FileObject parentFile = root.getFileObject(parentName[0]); if (parentFile != null) { if (parentFile.getFileObject(parentName[1], FileObjects.JAVA) != null) { final File cacheFolder = getClassFolder(entry.getURL()); if (roots.contains(BaseUtilities.toURI(cacheFolder).toURL())) { return cacheFolder; } } } } } return null; }
Example 11
Source File: AptSourcePath.java From netbeans with Apache License 2.0 | 5 votes |
@Override public List<PathResourceImplementation> apply(List<ClassPath.Entry> entries) { final Set<? extends URL> aptGenerated = getAptBuildGeneratedFolders(entries); final List<PathResourceImplementation> resources = new ArrayList<PathResourceImplementation>(aptGenerated.size()); for (URL agr : aptGenerated) { resources.add(ClassPathSupport.createResource(agr)); } return resources; }
Example 12
Source File: ResourcePathCompleter.java From netbeans with Apache License 2.0 | 5 votes |
private Collection<FileObject> collectFromClasspath(ClassPath cp, String parentDir, Collection<FileObject> result, Set<String> names, String filesMatch, String extMatch) { if (cp == null) { return result; } if (extMatch != null) { extMatch = extMatch.toLowerCase(); } if (filesMatch != null) { filesMatch = filesMatch.toLowerCase(); } for (ClassPath.Entry en : cp.entries()) { FileObject root = en.getRoot(); FileObject dir = root.getFileObject(parentDir); if (dir == null) { continue; } for (FileObject f : dir.getChildren()) { if (filesMatch != null && !filesMatch.isEmpty() && !f.getNameExt().toLowerCase().startsWith(filesMatch)) { continue; } if (f.isFolder() || extMatch == null || extMatch.equals(f.getExt().toLowerCase())) { String k = f.getNameExt(); if (names.add(k)) { result.add(f); } } } } return result; }
Example 13
Source File: EjbFacadeWizardPanel2.java From netbeans with Apache License 2.0 | 5 votes |
public static Project findProject(Project project, String clazz) { SourceGroup[] groups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); for (SourceGroup group : groups) { if (group.getRootFolder().getFileObject(clazz) != null) { return project; } ClassPath cp = ClassPath.getClassPath(group.getRootFolder(), ClassPath.COMPILE); if (cp == null) { continue; } FileObject clazzFo = null; LOOP: for (ClassPath.Entry entry : cp.entries()) { FileObject fos[] = SourceForBinaryQuery.findSourceRoots2(entry.getURL()).getRoots(); for (FileObject fo : fos) { FileObject ff = fo.getFileObject(clazz); if (ff != null) { clazzFo = ff; break LOOP; } } } if (clazzFo == null) { continue; } Project p = FileOwnerQuery.getOwner(clazzFo); if (p == null) { continue; } if (p.getProjectDirectory().equals(project.getProjectDirectory())) { return project; } return p; } return null; }
Example 14
Source File: SourcePathCheck.java From netbeans with Apache License 2.0 | 5 votes |
@Override @org.netbeans.api.annotations.common.SuppressWarnings(value={"DMI_COLLECTION_OF_URLS"}, justification="URLs have never host part") //NOI18N public void run(final Result result, final SchedulerEvent event) { final CompilationInfo info = CompilationInfo.get(result); final ClasspathInfo cpInfo = info.getClasspathInfo(); if (cpInfo != null) { final ClassPath src = cpInfo.getClassPath(PathKind.SOURCE); final ClassPath boot = cpInfo.getClassPath(PathKind.BOOT); final ClassPath compile = cpInfo.getClassPath(PathKind.COMPILE); if (!isIncomplete(src, boot, compile)) { final ClassPath cachedSrc = ClasspathInfoAccessor.getINSTANCE().getCachedClassPath(cpInfo, PathKind.SOURCE); try { final Set<URL> unknown = new HashSet<URL>(); if (cachedSrc.entries().isEmpty() && !src.entries().isEmpty()) { for (ClassPath.Entry entry : src.entries()) { final URL url = entry.getURL(); if (!this.factory.firedFor.contains(url) && !JavaIndex.hasSourceCache(url,false) && FileOwnerQuery.getOwner(url.toURI()) != null) { unknown.add(url); this.factory.firedFor.add(url); } } } if (!unknown.isEmpty()) { PathRegistry.getDefault().registerUnknownSourceRoots(src, unknown); } } catch (URISyntaxException e) { Exceptions.printStackTrace(e); } } } }
Example 15
Source File: ClassPathProviderImplTest.java From netbeans with Apache License 2.0 | 5 votes |
private static final boolean classPathContainsURL(ClassPath cp, URL url) { if (FileUtil.isArchiveFile(url)) { url = FileUtil.getArchiveRoot(url); } for (Iterator i = cp.entries().iterator(); i.hasNext();) { ClassPath.Entry e = (ClassPath.Entry)i.next(); if (e.getURL().equals(url)) { return true; } } return false; }
Example 16
Source File: EjbModuleProviderImpl.java From netbeans with Apache License 2.0 | 5 votes |
@Override public FileObject[] getSourceRoots() { ProjectSourcesClassPathProvider cppImpl = project.getLookup().lookup(ProjectSourcesClassPathProvider.class); ClassPath cp = cppImpl.getProjectSourcesClassPath(ClassPath.SOURCE); List<URL> resUris = new ArrayList<URL>(); for (URI uri : project.getLookup().lookup(NbMavenProject.class).getResources(false)) { try { resUris.add(uri.toURL()); } catch (MalformedURLException ex) { // Exceptions.printStackTrace(ex); } } Iterator<ClassPath.Entry> en = cp.entries().listIterator(); List<FileObject> toRet = new ArrayList<FileObject>(); int index = 0; while (en.hasNext()) { ClassPath.Entry ent = en.next(); if (ent.getRoot() == null) continue; if (resUris.contains(ent.getURL())) { //put resources up front.. toRet.add(index, ent.getRoot()); index = index + 1; } else { toRet.add(ent.getRoot()); } } return toRet.toArray(new FileObject[0]); }
Example 17
Source File: ModuleSourceFileManager.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Iterable<JavaFileObject> list( @NonNull final Location l, @NonNull final String packageName, @NonNull final Set<JavaFileObject.Kind> kinds, final boolean recursive ) { final List<JavaFileObject> result = new ArrayList<> (); String folderName = FileObjects.convertPackage2Folder(packageName); if (folderName.length() > 0) { folderName += FileObjects.NBFS_SEPARATOR_CHAR; } final ModuleLocation.WithExcludes ml = asSourceModuleLocation(l); for (ClassPath.Entry entry : ml.getModuleEntries()) { if (ignoreExcludes || entry.includes(folderName)) { FileObject root = entry.getRoot(); if (root != null) { FileObject tmpFile = root.getFileObject(folderName); if (tmpFile != null && tmpFile.isFolder()) { Enumeration<? extends FileObject> files = tmpFile.getChildren (recursive); while (files.hasMoreElements()) { FileObject file = files.nextElement(); if (ignoreExcludes || entry.includes(file)) { final JavaFileObject.Kind kind = FileObjects.getKind(file.getExt()); if (kinds.contains(kind)) { result.add (FileObjects.sourceFileObject(file, root)); } } } } } } } return result; }
Example 18
Source File: ModuleClassPathsTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testPatchModuleWithSourcePatch_UserModules() throws Exception { if (systemModules == null) { System.out.println("No jdk 9 home configured."); //NOI18N return; } assertNotNull(tp); assertNotNull(src); createModuleInfo(src, "Modle", "java.logging"); //NOI18N final FileObject tests = tp.getProjectDirectory().createFolder("tests"); final ClassPath testSourcePath = org.netbeans.spi.java.classpath.support.ClassPathSupport.createClassPath(tests); final URL dist = BinaryForSourceQuery.findBinaryRoots(src.entries().get(0).getURL()).getRoots()[1]; final ClassPath userModules = org.netbeans.spi.java.classpath.support.ClassPathSupport.createClassPath(dist); MockCompilerOptions.getInstance().forRoot(tests) .apply("--patch-module") //NOI18N .apply(String.format("Modle=%s", FileUtil.toFile(tests).getAbsolutePath())) //NOI18N .apply("--add-modules") //NOI18N .apply("Modle") //NOI18N .apply("--add-reads") //NOI18N .apply("Modle=ALL-UNNAMED"); //NOI18N for (ClassPath.Entry e : src.entries()) { MockClassPathProvider.getInstance().forRoot(e.getRoot()) .apply(JavaClassPathConstants.MODULE_BOOT_PATH, systemModules) .apply(ClassPath.BOOT, systemModules); IndexingManager.getDefault().refreshIndexAndWait(e.getURL(), null, true); } final ClassPath cp = ClassPathFactory.createClassPath(ModuleClassPaths.createModuleInfoBasedPath( userModules, testSourcePath, systemModules, userModules, ClassPath.EMPTY, null)); assertEquals( Collections.singletonList(dist), collectEntries(cp)); }
Example 19
Source File: FolderArchive.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Iterable<JavaFileObject> getFiles( @NonNull String folderName, @NullAllowed final ClassPath.Entry entry, @NullAllowed final Set<JavaFileObject.Kind> kinds, @NullAllowed final JavaFileFilterImplementation filter, final boolean recursive) throws IOException { assert folderName != null; if (folderName.length()>0) { folderName+='/'; //NOI18N } if (entry == null || entry.includes(folderName)) { File folder = new File (this.root, folderName.replace('/', File.separatorChar)); //NOI18N //Issue: #126392 on Mac //The problem when File ("A/").listFiles()[0].equals(new File("a/").listFiles[0]) returns false //Normalization is slow - turn on this workaround only for users which require it. //The problem only happens in case when there is file with wrong case in import. if (normalize) { folder = FileUtil.normalizeFile(folder); } return visit(folder, root, encoding(), filter, recursive, (f) -> { final JavaFileObject.Kind fKind = FileObjects.getKind(FileObjects.getExtension(f.getName())); try { if ((kinds == null || kinds.contains(fKind)) && f.isFile() && (entry == null || entry.includes(BaseUtilities.toURI(f).toURL()))) { return fKind; } } catch (MalformedURLException e) { //pass } return null; }); } return Collections.<JavaFileObject>emptyList(); }
Example 20
Source File: Archive.java From netbeans with Apache License 2.0 | 2 votes |
/** Gets all files in given folder * @param folderName name of folder to list, path elements separated by / char * @param entry owning ClassPath.Entry to check the excludes or null if everything should be included * @param kinds to list, may be null => all types * @param filter to filter the file content * @param recursive if true content of subfolders is included * @return the listed files */ public Iterable<JavaFileObject> getFiles( String folderName, ClassPath.Entry entry, Set<JavaFileObject.Kind> kinds, JavaFileFilterImplementation filter, boolean recursive) throws IOException;