private static boolean hasClassPathesIdenticEntries(ClassPath cp1, ClassPath cp2) { if (cp1.entries().size() != cp2.entries().size()) { return false; } for (int i = 0; i < cp1.entries().size(); i++) { if (!cp1.entries().get(i).getURL().sameFile(cp2.entries().get(i).getURL())) { return false; } } return true; }
public static URL[] getClassPathRoots (final ClassPath cp) { assert cp != null; final List<ClassPath.Entry> entries = cp.entries(); final List<URL> result = new ArrayList<URL>(entries.size()); for (ClassPath.Entry entry : entries) { result.add (entry.getURL()); } return result.toArray(new URL[result.size()]); }
private static java.util.List<URL> getPathList (ClassPath cp) { java.util.List<URL> result = new ArrayList<URL> (); for (ClassPath.Entry entry : cp.entries()) { result.add (entry.getURL()); } return result; }
private URL getOwnerRootNoSib () { //todo: fix me, now supports just 1 src root final List<ClassPath.Entry> entries = userRoots.entries(); return entries.size() == 1 ? entries.get(0).getURL() : null; }
private static int computeClassPathHash(ClassPath classPath) { int hashCode = 0; for (ClassPath.Entry entry : classPath.entries()) { hashCode = 37*hashCode + entry.getURL().getPath().hashCode(); } return hashCode; }
private static java.util.List<URL> getPathList (ClassPath cp) { ArrayList<URL> result = new ArrayList<URL> (); for (ClassPath.Entry entry : (java.util.List<ClassPath.Entry>)cp.entries() ) { result.add (entry.getURL()); } return result; }
private static int computeClassPathHash(ClassPath classPath) { int hashValue = 0; for (ClassPath.Entry entry : classPath.entries()) { hashValue += entry.getURL().getPath().hashCode(); } return hashValue; } }
private static List<URL> getURLRoots(ClassPath cp) { List<URL> urls = new ArrayList<URL>(); for (Entry entry : cp.entries()) { URL url = entry.getURL(); urls.add(url); } return urls; }
void setSources (ClassPath sources) { String srcPath = null; if (sources.entries().size()>0) { URL folderRoot = ((ClassPath.Entry)sources.entries().get(0)).getURL(); if ("jar".equals(folderRoot.getProtocol())) { //NOI18N folderRoot = FileUtil.getArchiveFile (folderRoot); } srcPath = new File(URI.create(folderRoot.toExternalForm())).getAbsolutePath(); } setSources (srcPath); }
public TransformationClassLoader(ClassLoader parent, ClassPath cp, CompilerConfiguration config) { super(parent, config); for (ClassPath.Entry entry : cp.entries()) { this.addURL(entry.getURL()); } }
private List<URL> getChangedPaths(final GlobalPathRegistryEvent event) { if (!ClassPath.SOURCE.equals(event.getId())) { return null; } List<URL> urls = new ArrayList<URL>(); for (ClassPath cp : event.getChangedPaths()) { for (Entry entry : cp.entries()) { URL url = entry.getURL(); urls.add(url); } } return urls; }
private URL getOwnerRootSib (final URL sibling) throws MalformedURLException { assert sibling != null; for (ClassPath.Entry entry : userRoots.entries()) { final URL rootURL = entry.getURL(); if (FileObjects.isParentOf(rootURL, sibling)) { return rootURL; } } for (ClassPath.Entry entry : sourceRoots.entries()) { final URL rootURL = entry.getURL(); if (FileObjects.isParentOf(rootURL, sibling)) { return rootURL; } } return null; }
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); }
public static ClassLoader forClassPath( @NonNull final ClassPath classPath, @NullAllowed final ClassLoader parent, @NullAllowed final Consumer<? super URL> usedRoots) { Parameters.notNull("classPath", classPath); //NOI18N final List<ClassPath.Entry> entries = classPath.entries(); final URL[] urls = new URL[entries.size()]; final Iterator<ClassPath.Entry> eit = entries.iterator(); for (int i=0; eit.hasNext(); i++) { urls[i] = eit.next().getURL(); } return forURLs(urls, parent, usedRoots); }
@Override public javax.tools.FileObject getFileForOutput( Location l, String pkgName, String relativeName, javax.tools.FileObject sibling ) throws IOException, UnsupportedOperationException, IllegalArgumentException { if (!allowOutput) { throw new UnsupportedOperationException("Output is unsupported."); //NOI18N } javax.tools.JavaFileObject file = findFile (pkgName, relativeName); if (file == null) { final List<ClassPath.Entry> entries = this.cp.entries(); if (!entries.isEmpty()) { final String resourceName = FileObjects.resolveRelativePath(pkgName, relativeName); file = provider.getArchive(entries.get(0).getURL(), cacheFile).create(resourceName, filter); } } return file; //todo: wrap to make read only }
private FileObject[] findFile (final String relativePath) { for (ClassPath.Entry entry : this.sourceRoots.entries()) { if (ignoreExcludes || entry.includes(relativePath)) { FileObject root = entry.getRoot(); if (root != null) { FileObject file = root.getFileObject(relativePath); if (file != null) { return new FileObject[] {file, root}; } } } } return null; }
/** * Creates a {@link ReferencesCount} for source classpath represented by given * {@link ClasspathInfo}. * @param cpInfo the {@link ClasspathInfo} to create {@link ReferencesCount} for. * @return the {@link ReferencesCount} */ @NonNull public static ReferencesCount get(@NonNull final ClasspathInfo cpInfo) { Parameters.notNull("cpInfo", cpInfo); //NOI18N final List<? extends ClassPath.Entry> scp = cpInfo.getClassPath(ClasspathInfo.PathKind.SOURCE).entries(); final List<URL> roots = new ArrayList<URL>(scp.size()); for (ClassPath.Entry e : scp) { roots.add(e.getURL()); } return new ReferencesCount(roots); }
private File getClassFolderForApt(final @NonNull URL surl) { for (ClassPath.Entry entry : apt.entries()) { if (FileObjects.isParentOf(entry.getURL(), surl)) { final URL classFolder = AptCacheForSourceQuery.getClassFolder(entry.getURL()); if (classFolder != null) { try { return BaseUtilities.toFile(classFolder.toURI()); } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); } } } } return null; }
private static boolean isTest(final @NonNull FileObject root, final @NonNull Project project) { assert root != null; assert project != null; final ClassPath cp = ClassPath.getClassPath(root, ClassPath.COMPILE); for (ClassPath.Entry entry : cp.entries()) { final FileObject[] srcRoots = SourceForBinaryQuery.findSourceRoots(entry.getURL()).getRoots(); for (FileObject srcRoot : srcRoots) { if (project.equals(FileOwnerQuery.getOwner(srcRoot))) { return true; } } } return false; }
private static boolean isIncluded (final ElementHandle<TypeElement> element, final ClasspathInfo cpInfo) { FileObject fobj = getFile (element,cpInfo); if (fobj == null) { //Not source return true; } ClassPath sourcePath = cpInfo.getClassPath(ClasspathInfo.PathKind.SOURCE); for (ClassPath.Entry e : sourcePath.entries()) { FileObject root = e.getRoot (); if (root != null && FileUtil.isParentOf(root,fobj)) { return e.includes(fobj); } } return true; }