public static synchronized CachingArchiveProvider getDefault () { if (instance == null) { instance = new CachingArchiveProvider (); } return instance; }
@Override public void propertyChange(PropertyChangeEvent evt) { if (ClassPath.PROP_ROOTS.equals(evt.getPropertyName())) { provider.clear(); } }
@NonNull static TypeCache newInstance(Iterable<? extends URL> bootClassPath) { Archive ctSym = null; final CachingArchiveProvider ap = CachingArchiveProvider.getDefault(); for (URL root : bootClassPath) { if (ap.hasCtSym(root)) { ctSym = ap.getArchive(root, true); break; } } if (ctSym == null) { throw new IllegalArgumentException( String.format( "No profile info for boot classpath: %s", //NOI18N bootClassPath)); } return new TypeCache(ctSym); }
public static File getIndex(URL url) throws IOException { url = CachingArchiveProvider.getDefault().mapCtSymToJar(url); FileObject indexBaseFolder = CacheFolder.getDataFolder(url); String path = SPIAccessor.getInstance().getIndexerPath(NAME, VERSION); FileObject indexFolder = FileUtil.createFolder(indexBaseFolder, path); return FileUtil.toFile(indexFolder); }
ClassPathSupport.createClassPath(CachingArchiveProvider.getDefault().ctSymRootsFor(bootPath)), bootPath, compilePath,
@Override public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { if (!hasLocation(location)) { throw new IllegalArgumentException(String.valueOf(location)); } final File root = new File(outputRoot); final String path = FileObjects.resolveRelativePath(packageName, relativeName); final String[] names = FileObjects.getFolderAndBaseName(path, FileObjects.NBFS_SEPARATOR_CHAR); final javax.tools.FileObject jfo = tx.readFileObject(location, names[0], names[1]); if (jfo != null) { return (JavaFileObject) jfo; } final Archive archive = provider.getArchive(BaseUtilities.toURI(root).toURL(), false); return archive != null ? archive.getFile(path) : null; }
public static ClassLoader forURLs( @NonNull final URL[] urls, @NullAllowed final ClassLoader parent, @NullAllowed final Consumer<? super URL> usedRoots) { Parameters.notNull("urls", urls); //NOI18N final List<Pair<URL,Archive>> archives = new ArrayList<>(urls.length); for (URL url : urls) { final Archive arch = CachingArchiveProvider.getDefault().getArchive(url, false); if (arch != null) { archives.add(Pair.of(url,arch)); } } return new CachingArchiveClassLoader( archives, parent, usedRoots); }
File f = BaseUtilities.toFile(URI.create(inner.toExternalForm())); if (f.isFile()) { final Pair<File,String> resolved = mapJarToCtSym(f); if (resolved.second() == null) { return Pair.<Archive,URI>of( URI uriInCtSym; try { uriInCtSym = toURI(resolved); } catch (IllegalArgumentException e) { uriInCtSym = null;
/** * Frees the {@link Archive} for given root. * @param root the root for which the {@link Archive} should be freed. */ public synchronized void removeArchive (@NonNull final URL root) { final URI rootURI = toURI(root); final Archive archive = archives.remove(rootURI); for (Iterator<Map.Entry<URI,URI>> it = ctSymToJar.entrySet().iterator(); it.hasNext();) { final Map.Entry<URI,URI> e = it.next(); if (e.getValue().equals(rootURI)) { it.remove(); break; } } if (archive != null) { archive.clear(); } }
@NullAllowed final Function<JavaFileManager.Location, JavaFileManager> jfmProvider) { return new ClasspathInfo( CachingArchiveProvider.getDefault(), bootPath, classPath,
/** * Checks if the given boot classpath root has the the ct.sym equivalent. * @param root the root to check * @return true if there is a ct.sym folder corresponding to given boot classpath * root */ public boolean hasCtSym (@NonNull final URL root) { final URL fileURL = FileUtil.getArchiveFile(root); if (fileURL == null) { return false; } final File f; try { f = BaseUtilities.toFile(fileURL.toURI()); } catch (URISyntaxException ex) { return false; } if (f == null || !f.exists()) { return false; } final Pair<File, String> res = mapJarToCtSym(f); return res.second() != null; }
final URL url = CachingArchiveProvider.getDefault().mapCtSymToJar(fo.toURL()); sourceRoot = JavaIndex.getSourceRootForClassFolder(url); if (sourceRoot == null) {
final ClassPath srcPath = info.getClassPath(ClasspathInfo.PathKind.SOURCE); final FileObject root = ClassPathSupport.createProxyClassPath( ClassPathSupport.createClassPath(CachingArchiveProvider.getDefault().ctSymRootsFor(bootPath)), bootPath, compilePath,
for(ClassPath.Entry entry : this.cp.entries()) { try { Archive archive = provider.getArchive( entry.getURL(), cacheFile ); if (archive != null) { Iterable<JavaFileObject> entries = archive.getFiles( folderName, ignoreExcludes?null:entry, kinds, filter);
/** * Clears the in memory cached {@link Archive} data for given root. * @param root the root for which the {@link Archive} data should be cleared. * @see Archive#clear() */ public synchronized void clearArchive (@NonNull final URL root) { Archive archive = archives.get(toURI(root)); if (archive != null) { archive.clear(); } }
return loc == StandardLocation.CLASS_OUTPUT ? new OutputFileManager( CachingArchiveProvider.getDefault(), srcFin) : null;
@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 }
/** * Maps ct.sym back to the base boot classpath root. * @param archiveOrCtSym the root or ct.sym folder to transform. * @return the boot classpath root corresponding to the ct.sym folder * or the given boot classpath root. */ @NonNull public synchronized URL mapCtSymToJar (@NonNull final URL archiveOrCtSym) { final URI result = ctSymToJar.get(toURI(archiveOrCtSym)); if (result != null) { try { return result.toURL(); } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); } } return archiveOrCtSym; }
/** * Creates new instance of {@link CachingArchiveProvider} for unit test purposes. * @return new <b>unshared</b> {@link CachingArchiveProvider} */ static CachingArchiveProvider newInstance() { return new CachingArchiveProvider(); }