Java Code Examples for org.netbeans.api.java.classpath.ClassPath#entries()
The following examples show how to use
org.netbeans.api.java.classpath.ClassPath#entries() .
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: ProjectRunnerImpl.java From netbeans with Apache License 2.0 | 6 votes |
@NonNull private static String pathToString(@NonNull final ClassPath path) { final StringBuilder cpBuilder = new StringBuilder(); for (ClassPath.Entry entry : path.entries()) { final URL u = entry.getURL(); boolean folder = "file".equals(u.getProtocol()); File f = FileUtil.archiveOrDirForURL(u); if (f != null) { if (cpBuilder.length() > 0) { cpBuilder.append(File.pathSeparatorChar); } cpBuilder.append(f.getAbsolutePath()); if (folder) { cpBuilder.append(File.separatorChar); } } } return cpBuilder.toString(); }
Example 2
Source File: MuxClassPathImplementation.java From netbeans with Apache License 2.0 | 6 votes |
@Override @NonNull public List<? extends PathResourceImplementation> getResources() { List<PathResourceImplementation> res; synchronized (this) { res = cache; } if (res == null) { final ClassPath cp = getActiveClassPath(); final List<ClassPath.Entry> entries = cp.entries(); res = new ArrayList<>(entries.size()); for (ClassPath.Entry entry : entries) { res.add(org.netbeans.spi.java.classpath.support.ClassPathSupport.createResource(entry.getURL())); } synchronized (this) { if (cache == null) { cache = Collections.unmodifiableList(res); } else { res = cache; } } } return res; }
Example 3
Source File: ProjectOperations.java From netbeans with Apache License 2.0 | 6 votes |
@NonNull private static Set<URI> classPathURIs(@NullAllowed final ClassPath cp) { final Set<URI> res = new HashSet<>(); if (cp != null) { for (ClassPath.Entry e : cp.entries()) { try { final URL rootUrl = e.getURL(); URL fileURL = FileUtil.getArchiveFile(rootUrl); if (fileURL == null) { fileURL = rootUrl; } res.add(fileURL.toURI()); } catch (URISyntaxException ex) { LOG.log( Level.WARNING, "Cannot convert to URI: {0}, reason: {1}", //NOI18N new Object[]{ e.getURL(), ex.getMessage() }); } } } return res; }
Example 4
Source File: ClassIndex.java From netbeans with Apache License 2.0 | 6 votes |
private void createQueriesForRoots (final ClassPath cp, final boolean sources, final Set<? super ClassIndexImpl> queries, final Set<? super URL> oldState) { final PathRegistry preg = PathRegistry.getDefault(); List<ClassPath.Entry> entries = cp.entries(); for (ClassPath.Entry entry : entries) { URL[] srcRoots; if (!sources) { srcRoots = preg.sourceForBinaryQuery(entry.getURL(), cp, true); if (srcRoots == null) { srcRoots = new URL[] {entry.getURL()}; } } else { srcRoots = new URL[] {entry.getURL()}; } for (URL srcRoot : srcRoots) { oldState.add (srcRoot); ClassIndexImpl ci = ClassIndexManager.getDefault().getUsagesQuery(srcRoot, true); if (ci != null) { ci.addClassIndexImplListener(spiListener); queries.add (ci); } } } }
Example 5
Source File: MultiModuleBinaryForSourceQueryImpl.java From netbeans with Apache License 2.0 | 6 votes |
@CheckForNull private R createResult( @NonNull final URL artifact, @NonNull final MultiModule modules, @NonNull final String[] templates) { for (String moduleName : modules.getModuleNames()) { final ClassPath scp = modules.getModuleSources(moduleName); if (scp != null) { for (ClassPath.Entry e : scp.entries()) { if (artifact.equals(e.getURL())) { return new R( artifact, modules, moduleName, templates); } } } } return null; }
Example 6
Source File: Launches.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
/** * Tries to convert a classpath with classes into a classpath containing * java source code. * * @param cp * @return */ public static ClassPath toSourcePath(final ClassPath cp) { final List<FileObject> resources = new ArrayList<FileObject>(); for (ClassPath.Entry e : cp.entries()) { final FileObject[] srcRoots = SourceForBinaryQuery.findSourceRoots(e.getURL()).getRoots(); resources.addAll(Arrays.asList(srcRoots)); } return ClassPathSupport.createClassPath(resources.toArray(new FileObject[resources.size()])); }
Example 7
Source File: ShellProjectUtils.java From netbeans with Apache License 2.0 | 5 votes |
public static Set<URL> to2Roots(ClassPath bootCP) { Set<URL> roots = new HashSet<>(); for (ClassPath.Entry e : bootCP.entries()) { roots.add(e.getURL()); } return roots; }
Example 8
Source File: JsfFacesComponentsProvider.java From netbeans with Apache License 2.0 | 5 votes |
/** * Gets the FQN of the class. * @return file */ public FileObject getComponentFile(Project project) { WebModule webModule = WebModule.getWebModule(project.getProjectDirectory()); if (webModule == null) { return null; } JavaSource js = JSFConfigUtilities.createJavaSource(webModule); if (js != null) { FileObject file = SourceUtils.getFile(handle, js.getClasspathInfo()); if (file != null) { return file; } else { String qualifiedName = handle.getQualifiedName(); String relPath = qualifiedName.replace('.', '/') + ".class"; //NOI18N ClassPath classPath = js.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.COMPILE); for (ClassPath.Entry entry : classPath.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) { file = root.getFileObject(relPath); if (file != null) { return file; } } } } } return null; }
Example 9
Source File: DeclarativeHintRegistry.java From netbeans with Apache License 2.0 | 5 votes |
private static Collection<? extends FileObject> findFiles(ClassPath cp) { List<FileObject> roots = new ArrayList<>(); for (Entry binaryEntry : cp.entries()) { Result2 sources = SourceForBinaryQuery.findSourceRoots2(binaryEntry.getURL()); if (sources.preferSources()) { roots.addAll(Arrays.asList(sources.getRoots())); } else { FileObject binaryRoot = binaryEntry.getRoot(); if (binaryRoot != null) roots.add(binaryRoot); } } List<FileObject> result = new LinkedList<>(); for (FileObject root : roots) { FileObject folder = root.getFileObject("META-INF/upgrade"); if (folder != null) { result.addAll(findFiles(folder)); } } return result; }
Example 10
Source File: ModuleClassPathsTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testPatchModuleWithSourcePatch_UnscannedBaseModule() 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 final ClassPath cp = ClassPathFactory.createClassPath(ModuleClassPaths.createModuleInfoBasedPath( userModules, testSourcePath, systemModules, userModules, ClassPath.EMPTY, null)); cp.entries(); assertEquals( Collections.singletonList(dist), collectEntries(cp)); }
Example 11
Source File: JavaCustomIndexer.java From netbeans with Apache License 2.0 | 5 votes |
private static boolean ensureSourcePath(final @NonNull FileObject root) throws IOException { final ClassPath srcPath = ClassPath.getClassPath(root, ClassPath.SOURCE); String srcPathStr; if (srcPath != null) { final StringBuilder sb = new StringBuilder(); for (ClassPath.Entry entry : srcPath.entries()) { sb.append(entry.getURL()).append(' '); //NOI18N } srcPathStr = sb.toString(); } else { srcPathStr = ""; //NOI18N } return JavaIndex.ensureAttributeValue(root.toURL(), SOURCE_PATH, srcPathStr); }
Example 12
Source File: ModuleClassPathsTest.java From netbeans with Apache License 2.0 | 5 votes |
private Collection<URL> collectEntries(@NonNull final ClassPath cp) { final List<URL> res = new ArrayList<>(); for (ClassPath.Entry e : cp.entries()) { res.add(e.getURL()); } Collections.sort(res, LEX_COMPARATOR); return res; }
Example 13
Source File: MultiModuleBinaryForSourceQueryImpl.java From netbeans with Apache License 2.0 | 5 votes |
private boolean isSourceRoot() { final ClassPath cp = modules.getModuleSources(moduleName); if (cp == null) { return false; } for (ClassPath.Entry e : cp.entries()) { if (e.getURL().equals(url)) { return true; } } return false; }
Example 14
Source File: SourcePathImplementationTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testWSClientSupport () throws Exception { ClassPathProviderImpl cpProvider = pp.getClassPathProvider(); ClassPath[] cps = cpProvider.getProjectClassPaths(ClassPath.SOURCE); ClassPath cp = cps[0]; List<ClassPath.Entry> entries = cp.entries(); assertNotNull ("Entries can not be null", entries); assertEquals ("There must be 3 src entries",1, entries.size()); assertEquals("There must be src root", entries.get(0).getRoot(), sources); }
Example 15
Source File: ProxyClassPathImplementationTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testResources () throws Exception { final URL url1 = new URL ("file:///tmp/a/"); final URL url2 = new URL ("file:///tmp/b/"); final URL url3 = new URL ("file:///tmp/b/"); final ClassPath cp1 = ClassPathSupport.createClassPath(new URL[] {url1, url2}); final ClassPath cp2 = ClassPathSupport.createClassPath(new URL[] {url3}); final ClassPath prxCp = ClassPathSupport.createProxyClassPath(new ClassPath[] {cp1,cp2}); List<ClassPath.Entry> entries = prxCp.entries(); assertEquals(3,entries.size()); assertEquals(url1,entries.get(0).getURL()); assertEquals(url2,entries.get(1).getURL()); assertEquals(url3,entries.get(2).getURL()); }
Example 16
Source File: ClassIndex.java From netbeans with Apache License 2.0 | 5 votes |
@org.netbeans.api.annotations.common.SuppressWarnings(value={"DMI_COLLECTION_OF_URLS"}, justification="URLs have never host part") //NOI18N private boolean containsRoot (final ClassPath cp, final Set<? extends URL> roots, final List<? super URL> affectedRoots, final boolean translate) { 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.contains(url)) { affectedRoots.add(url); result = true; } } else { for (URL _url : srcRoots) { if (roots.contains(_url)) { affectedRoots.add(url); result = true; } } } } return result; }
Example 17
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 18
Source File: ClasspathsTest.java From netbeans with Apache License 2.0 | 5 votes |
private Set<String> urlsOfCp(ClassPath cp) { Set<String> s = new TreeSet<String>(); for (ClassPath.Entry entry : cp.entries()) { s.add(entry.getURL().toExternalForm()); } return s; }
Example 19
Source File: MultiModule.java From netbeans with Apache License 2.0 | 5 votes |
@NonNull private Optional<Pair<String,ClassPath>> findImpl(@NonNull final FileObject artifact) { final Map<String,Pair<ClassPath,CPImpl>> data = getCache(); final URL artifactURL = artifact.toURL(); for (Map.Entry<String,Pair<ClassPath,CPImpl>> e : data.entrySet()) { final ClassPath cp = e.getValue().first(); for (ClassPath.Entry cpe : cp.entries()) { if (Utilities.isParentOf(cpe.getURL(), artifactURL)) { return Optional.of(Pair.of(e.getKey(), cp)); } } } return Optional.empty(); }
Example 20
Source File: PlatformConvertor.java From netbeans with Apache License 2.0 | 4 votes |
public static void generatePlatformProperties (JavaPlatform platform, String systemName, EditableProperties props) throws IOException { String homePropName = createName(systemName,"home"); //NOI18N String bootClassPathPropName = createName(systemName,"bootclasspath"); //NOI18N String compilerType= createName (systemName,"compiler"); //NOI18N if (props.getProperty(homePropName) != null || props.getProperty(bootClassPathPropName) != null || props.getProperty(compilerType)!=null) { //Already defined warn user final String msg = NbBundle.getMessage(J2SEWizardIterator.class,"ERROR_InvalidName"); //NOI18N throw Exceptions.attachLocalizedMessage( new IllegalStateException(msg), msg); } Collection installFolders = platform.getInstallFolders(); if (installFolders.size()>0) { File jdkHome = FileUtil.toFile ((FileObject)installFolders.iterator().next()); props.setProperty(homePropName, jdkHome.getAbsolutePath()); ClassPath bootCP = platform.getBootstrapLibraries(); StringBuilder sbootcp = new StringBuilder(); for (ClassPath.Entry entry : bootCP.entries()) { URL url = entry.getURL(); String pathInArchive = ""; //NOI18N boolean wasFolder = false; if (FileUtil.isArchiveArtifact(url)) { String path = url.getPath(); int index = path.lastIndexOf(URL_EMBEDDING); //NOI18N if (index >= 0) { wasFolder = index > 0 && path.charAt(index-1) == '/'; //NOI18N pathInArchive = path.substring(index+URL_EMBEDDING.length()); } url = FileUtil.getArchiveFile(url); } String rootPath = BaseUtilities.toFile(URI.create(url.toExternalForm())).getAbsolutePath(); if (!pathInArchive.isEmpty()) { final StringBuilder rpb = new StringBuilder( rootPath.length() + File.separator.length() + URL_EMBEDDING.length() + pathInArchive.length()); rpb.append(rootPath); if (wasFolder && !rootPath.endsWith(File.separator)) { rpb.append(File.separator); } rpb.append(URL_EMBEDDING); rpb.append(pathInArchive); rootPath = rpb.toString(); } if (sbootcp.length()>0) { sbootcp.append(File.pathSeparator); } sbootcp.append(normalizePath(rootPath, jdkHome, homePropName)); } if (sbootcp != null) { props.setProperty(bootClassPathPropName,sbootcp.toString()); } props.setProperty(compilerType,getCompilerType(platform)); for (int i = 0; i < IMPORTANT_TOOLS.length; i++) { String name = IMPORTANT_TOOLS[i]; FileObject tool = platform.findTool(name); if (tool != null) { if (!isDefaultLocation(tool, platform.getInstallFolders())) { String toolName = createName(systemName, name); props.setProperty(toolName, normalizePath(getToolPath(tool), jdkHome, homePropName)); } } else { throw new BrokenPlatformException (name); } } } }