LOG.debug("CLASSLOADER LOADED WITH: {}", STELLAR_VFS_PATHS.get(stellarConfig, String.class)); if(LOG.isDebugEnabled()) { for (FileObject fo : ((VFSClassLoader) vfsLoader.get()).getFileObjects()) { LOG.error("{} - {}", fo.getURL(), fo.exists());
return Optional.of(new VFSClassLoader(objects, vfs, vfs.getClass().getClassLoader()));
/** * Constructors a new VFSClassLoader for the given FileObjects. The FileObjects will be searched in the order * specified. * * @param files the FileObjects to load the classes and resources from. * @param manager the FileManager to use when trying create a layered Jar file system. * @param parent the parent class loader for delegation. * @throws FileSystemException if an error occurs. */ public VFSClassLoader(final FileObject[] files, final FileSystemManager manager, final ClassLoader parent) throws FileSystemException { super(parent); addFileObjects(manager, files); }
/** * Loads and verifies the class with name and located with res. */ private Class<?> defineClass(final String name, final Resource res) throws IOException { final URL url = res.getCodeSourceURL(); final String pkgName = res.getPackageName(); if (pkgName != null) { final Package pkg = getPackage(pkgName); if (pkg != null) { if (pkg.isSealed()) { if (!pkg.isSealed(url)) { throw new FileSystemException("vfs.impl/pkg-sealed-other-url", pkgName); } } else { if (isSealed(res)) { throw new FileSystemException("vfs.impl/pkg-sealing-unsealed", pkgName); } } } else { definePackage(pkgName, res); } } final byte[] bytes = res.getBytes(); final Certificate[] certs = res.getFileObject().getContent().getCertificates(); final CodeSource cs = new CodeSource(url, certs); return defineClass(name, bytes, 0, bytes.length, cs); }
/** * Tests retrieving resources (from local directory with .jar extension). * <p> * This test is repeated with various provider configurations but works on local files, only. */ public void testGetResourcesNoLayerLocal() throws Exception { final FileSystemManager manager = getManager(); try { // hasProvider("file") cannot be used as it triggers default provider URL manager.toFileObject(new File(".")); } catch (final FileSystemException e) { System.out.println("VfsClassLoaderTests no local file provider, skipping."); return; } final File baseDir = AbstractVfsTestCase.getTestDirectoryFile(); // setup test folder final FileObject dir = manager.resolveFile(baseDir, "read-tests/dir1/subdir4.jar"); assertTrue("subdir4.jar/ is required for testing " + dir, dir.getType() == FileType.FOLDER); assertFalse(manager.canCreateFileSystem(dir)); // prepare classloader final FileObject[] search = new FileObject[] { dir }; final ClassLoader mockClassloader = new MockClassloader(); final VFSClassLoader loader = new VFSClassLoader(search, getManager(), mockClassloader); // verify resource loading final Enumeration<URL> urls = loader.getResources("file1.txt"); final URL url1 = urls.nextElement(); assertFalse("Only one hit expected", urls.hasMoreElements()); assertTrue("not pointing to resource " + url1, url1.toString().endsWith("subdir4.jar/file1.txt")); }
/** * Reads attributes for the package and defines it. */ private Package definePackage(final String name, final Resource res) throws FileSystemException { // TODO - check for MANIFEST_ATTRIBUTES capability first final String specTitle = res.getPackageAttribute(Name.SPECIFICATION_TITLE); final String specVendor = res.getPackageAttribute(Attributes.Name.SPECIFICATION_VENDOR); final String specVersion = res.getPackageAttribute(Name.SPECIFICATION_VERSION); final String implTitle = res.getPackageAttribute(Name.IMPLEMENTATION_TITLE); final String implVendor = res.getPackageAttribute(Name.IMPLEMENTATION_VENDOR); final String implVersion = res.getPackageAttribute(Name.IMPLEMENTATION_VERSION); final URL sealBase; if (isSealed(res)) { sealBase = res.getCodeSourceURL(); } else { sealBase = null; } return definePackage(name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase); }
/** * Finds and loads the class with the specified name from the search path. * * @throws ClassNotFoundException if the class is not found. */ @Override protected Class<?> findClass(final String name) throws ClassNotFoundException { try { final String path = name.replace('.', '/').concat(".class"); final Resource res = loadResource(path); if (res == null) { throw new ClassNotFoundException(name); } return defineClass(name, res); } catch (final IOException ioe) { throw new ClassNotFoundException(name, ioe); } }
try { final String url = cs.getLocation().toString(); final FileObject file = lookupFileObject(url); if (file == null) { return super.getPermissions(cs); copyPermissions(permCollect, combi); copyPermissions(permCollect, combi);
@Override protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { Class<?> c = findLoadedClass(name); if (c != null) return c; try { // try finding this class here instead of parent return findClass(name); } catch (ClassNotFoundException e) { } return super.loadClass(name, resolve); }
/** * Loads and verifies the class with name and located with res. */ private Class<?> defineClass(final String name, final Resource res) throws IOException { final URL url = res.getCodeSourceURL(); final String pkgName = res.getPackageName(); if (pkgName != null) { final Package pkg = getPackage(pkgName); if (pkg != null) { if (pkg.isSealed()) { if (!pkg.isSealed(url)) { throw new FileSystemException("vfs.impl/pkg-sealed-other-url", pkgName); } } else { if (isSealed(res)) { throw new FileSystemException("vfs.impl/pkg-sealing-unsealed", pkgName); } } } else { definePackage(pkgName, res); } } final byte[] bytes = res.getBytes(); final Certificate[] certs = res.getFileObject().getContent().getCertificates(); final CodeSource cs = new CodeSource(url, certs); return defineClass(name, bytes, 0, bytes.length, cs); }
/** * Tests retrieving resources (from local directory with .jar extension). * <p> * This test is repeated with various provider configurations but works on local files, only. */ public void testGetResourcesNoLayerLocal() throws Exception { final FileSystemManager manager = getManager(); try { // hasProvider("file") cannot be used as it triggers default provider URL manager.toFileObject(new File(".")); } catch (final FileSystemException e) { System.out.println("VfsClassLoaderTests no local file provider, skipping."); return; } final File baseDir = AbstractVfsTestCase.getTestDirectoryFile(); // setup test folder final FileObject dir = manager.resolveFile(baseDir, "read-tests/dir1/subdir4.jar"); assertTrue("subdir4.jar/ is required for testing " + dir, dir.getType() == FileType.FOLDER); assertFalse(manager.canCreateFileSystem(dir)); // prepare classloader final FileObject[] search = new FileObject[] { dir }; final ClassLoader mockClassloader = new MockClassloader(); final VFSClassLoader loader = new VFSClassLoader(search, getManager(), mockClassloader); // verify resource loading final Enumeration<URL> urls = loader.getResources("file1.txt"); final URL url1 = urls.nextElement(); assertFalse("Only one hit expected", urls.hasMoreElements()); assertTrue("not pointing to resource " + url1, url1.toString().endsWith("subdir4.jar/file1.txt")); }
/** * Reads attributes for the package and defines it. */ private Package definePackage(final String name, final Resource res) throws FileSystemException { // TODO - check for MANIFEST_ATTRIBUTES capability first final String specTitle = res.getPackageAttribute(Name.SPECIFICATION_TITLE); final String specVendor = res.getPackageAttribute(Attributes.Name.SPECIFICATION_VENDOR); final String specVersion = res.getPackageAttribute(Name.SPECIFICATION_VERSION); final String implTitle = res.getPackageAttribute(Name.IMPLEMENTATION_TITLE); final String implVendor = res.getPackageAttribute(Name.IMPLEMENTATION_VENDOR); final String implVersion = res.getPackageAttribute(Name.IMPLEMENTATION_VERSION); final URL sealBase; if (isSealed(res)) { sealBase = res.getCodeSourceURL(); } else { sealBase = null; } return definePackage(name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase); }
/** * Finds and loads the class with the specified name from the search path. * * @throws ClassNotFoundException if the class is not found. */ @Override protected Class<?> findClass(final String name) throws ClassNotFoundException { try { final String path = name.replace('.', '/').concat(".class"); final Resource res = loadResource(path); if (res == null) { throw new ClassNotFoundException(name); } return defineClass(name, res); } catch (final IOException ioe) { throw new ClassNotFoundException(name, ioe); } }
try { final String url = cs.getLocation().toString(); final FileObject file = lookupFileObject(url); if (file == null) { return super.getPermissions(cs); copyPermissions(permCollect, combi); copyPermissions(permCollect, combi);
@Override protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { Class<?> c = findLoadedClass(name); if (c != null) return c; try { // try finding this class here instead of parent return findClass(name); } catch (ClassNotFoundException e) { } return super.loadClass(name, resolve); }
out.print("Level " + classLoaderDescription + " VFS classpaths items are:\n"); VFSClassLoader vcl = (VFSClassLoader) classLoader; for (FileObject f : vcl.getFileObjects()) { printJar(out, f.getURL().getFile(), debug, sawFirst); sawFirst = true;
/** * Loads and verifies the class with name and located with res. */ private Class<?> defineClass(final String name, final Resource res) throws IOException { final URL url = res.getCodeSourceURL(); final String pkgName = res.getPackageName(); if (pkgName != null) { final Package pkg = getPackage(pkgName); if (pkg != null) { if (pkg.isSealed()) { if (!pkg.isSealed(url)) { throw new FileSystemException("vfs.impl/pkg-sealed-other-url", pkgName); } } else { if (isSealed(res)) { throw new FileSystemException("vfs.impl/pkg-sealing-unsealed", pkgName); } } } else { definePackage(pkgName, res); } } final byte[] bytes = res.getBytes(); final Certificate[] certs = res.getFileObject().getContent().getCertificates(); final CodeSource cs = new CodeSource(url, certs); return defineClass(name, bytes, 0, bytes.length, cs); }
cl = new VFSClassLoader(files, vfs, parent.getClassLoader()); else cl = new PostDelegatingVFSClassLoader(files, vfs, parent.getClassLoader());
final VFSClassLoader loader = new VFSClassLoader(search, getManager(), mockClassloader); final Enumeration<URL> urls = loader.getResources("META-INF/MANIFEST.MF"); final URL url1 = urls.nextElement(); final URL url2 = urls.nextElement();
/** * Reads attributes for the package and defines it. */ private Package definePackage(final String name, final Resource res) throws FileSystemException { // TODO - check for MANIFEST_ATTRIBUTES capability first final String specTitle = res.getPackageAttribute(Name.SPECIFICATION_TITLE); final String specVendor = res.getPackageAttribute(Attributes.Name.SPECIFICATION_VENDOR); final String specVersion = res.getPackageAttribute(Name.SPECIFICATION_VERSION); final String implTitle = res.getPackageAttribute(Name.IMPLEMENTATION_TITLE); final String implVendor = res.getPackageAttribute(Name.IMPLEMENTATION_VENDOR); final String implVersion = res.getPackageAttribute(Name.IMPLEMENTATION_VERSION); final URL sealBase; if (isSealed(res)) { sealBase = res.getCodeSourceURL(); } else { sealBase = null; } return definePackage(name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase); }