/** * Find a root from a path * * @param path the path * @return the root if found in the roots */ protected VirtualFile findRoot(String path) { VirtualFileInfo vfi = findVirtualFileInfo(path); if (vfi == null) return null; return vfi.getRoot(); }
/** * Find a child from a path * * @param path the path * @return the child if found in the roots */ protected VirtualFile findChild(String path) { VirtualFileInfo vfi = findVirtualFileInfo(path); if (vfi == null) return null; return vfi.getFile(); }
/** * Create a new VFSClassLoaderPolicy. * * @param roots the roots * @param excludedRoots the excluded roots * @return the classloader policy * @throws IllegalArgumentException for null roots */ public static VFSClassLoaderPolicy createVFSClassLoaderPolicy(VirtualFile[] roots, VirtualFile[] excludedRoots) { return new VFSClassLoaderPolicy(roots, excludedRoots); }
@Override protected VFSClassLoaderPolicy determinePolicy() { VFSClassLoaderPolicy policy = VFSClassLoaderPolicy.createVFSClassLoaderPolicy(getContextName(), vfsRoots, excludedRoots); String[] packageNames = getPackageNames(); policy.setExportedPackages(packageNames); policy.setIncluded(getIncluded()); policy.setExcluded(getExcluded()); policy.setExcludedExport(getExcludedExport()); policy.setExportAll(getExportAll()); policy.setImportAll(isImportAll()); policy.setCacheable(isCacheable()); policy.setBlackListable(isBlackListable()); policy.setDelegates(getDelegates()); return policy; }
/** * Initialize the boot libraries using the new classloader * * @return the classloader * @throws Exception for any error */ private ClassLoader initBootLibraries() throws Exception { ClassLoaderSystem system = ClassLoaderSystem.getInstance(); mbeanServer.registerMBean(system, new ObjectName("jboss.classloader:service=ClassLoaderSystem")); List<URL> list = getBootURLs(); VirtualFile[] files = new VirtualFile[list.size()]; for (int i = 0; i < list.size(); ++i) { URL url = list.get(i); files[i] = VFS.getChild(url); } VFSClassLoaderPolicy policy = new VFSClassLoaderPolicy(files); policy.setExportAll(ExportAll.NON_EMPTY); policy.setImportAll(true); ClassLoader classLoader = system.registerClassLoaderPolicy(policy); if (classLoader instanceof RealClassLoader) bootstrapUCLName = ((RealClassLoader) classLoader).getObjectName(); return classLoader; }
@Override public URL getResource(String path) { if (checkFilters(path, "getResource")) return null; VirtualFile child = findChild(path); if (child != null) { try { return child.toURL(); } catch (Exception ignored) { log.debug("Error determining URL for " + child, ignored); return null; } } return null; }
this.roots = roots; this.excludedRoots = excludedRoots; addClassFoundHandler(new VFSCacheRemove());
@Override protected ProtectionDomain getProtectionDomain(String className, String path) { VirtualFile clazz = findChild(path); if (clazz == null) { if (log.isTraceEnabled()) log.trace("Unable to determine class file for " + className); return null; } try { VirtualFile root = findRoot(path); URL codeSourceURL = root.toURL(); if (log.isTraceEnabled()) log.trace("getProtectionDomain:className="+ className + " path="+ path + " codeSourceURL=" + codeSourceURL); final CodeSigner[] signers = clazz.getCodeSigners(); final CodeSource cs = new CodeSource(codeSourceURL, signers); final PermissionCollection permissions = Policy.getPolicy().getPermissions(cs); return new ProtectionDomain(cs, permissions); } catch (Exception e) { throw new Error("Error determining protection domain for " + clazz, e); } }
/** * Create a new VFSClassLoaderPolicy. * * @param roots the roots * @throws IllegalArgumentException for null roots */ public VFSClassLoaderPolicy(VirtualFile[] roots) { this(determineName(roots), roots); }
@Override public DelegateLoader getExported() { if (getExportAll() != null) return new FilteredDelegateLoader(this, ClassFilterUtils.EVERYTHING); return super.getExported(); }
if (file.exists()) result = new VirtualFileInfo(file, root); vfsCache.put(path, result); return result;
@Override // FindBugs: The Set doesn't use equals/hashCode public void getResources(String name, Set<URL> urls) throws IOException { if (checkFilters(name, "getResources")) return; for (VirtualFile root : roots) { try { VirtualFile child = root.getChild(name); if (child.exists()) urls.add(child.toURL()); } catch (Exception e) { log.debug("Error getting resources for " + root, e); } } }
VirtualFile root = findRoot(path); Manifest manifest = null; String rootURL = null;
@Override protected VFSClassLoaderPolicy determinePolicy() { VirtualFile[] roots = determineVFSRoots(); VFSClassLoaderPolicy policy = VFSClassLoaderPolicy.createVFSClassLoaderPolicy(getContextName(), roots); String[] packageNames = getPackageNames(); policy.setExportedPackages(packageNames); policy.setIncluded(getIncluded()); policy.setExcluded(getExcluded()); policy.setExcludedExport(getExcludedExport()); policy.setExportAll(getExportAll()); policy.setImportAll(isImportAll()); policy.setShutdownPolicy(getShutdownPolicy()); policy.setCacheable(isCacheable()); policy.setBlackListable(isBlackListable()); policy.setDelegates(getDelegates()); return policy; }
/** * Create a new VFSClassLoaderPolicy. * * @param name a name of the policy * @param roots the roots * @param excludedRoots the excluded roots * @return the classloader policy * @throws IllegalArgumentException for null roots */ public static VFSClassLoaderPolicy createVFSClassLoaderPolicy(String name, VirtualFile[] roots, VirtualFile[] excludedRoots) { return new VFSClassLoaderPolicy(name, roots, excludedRoots); }
@Override public InputStream getResourceAsStream(String path) { if (checkFilters(path, "getResourceAsStream")) return null; VirtualFile child = findChild(path); if (child != null) { try { return child.openStream(); } catch (Exception ignored) { log.debug("Error opening stream for " + child, ignored); return null; } } return null; }
/** * Create a new VFSClassLoaderPolicy. * * @param roots the roots * @param excludedRoots the excluded roots * @throws IllegalArgumentException for null roots */ public VFSClassLoaderPolicy(VirtualFile[] roots, VirtualFile[] excludedRoots) { this(determineName(roots), roots, excludedRoots); }
/** * Create a new VFSClassLoaderPolicy. * * @param roots the roots * @return the classloader policy * @throws IllegalArgumentException for null roots */ public static VFSClassLoaderPolicy createVFSClassLoaderPolicy(VirtualFile... roots) { return new VFSClassLoaderPolicy(roots); }
/** * Create a new VFSClassLoaderPolicy. * * @param name a name of the policy * @param roots the roots * @return the classloader policy * @throws IllegalArgumentException for null roots */ public static VFSClassLoaderPolicy createVFSClassLoaderPolicy(String name, VirtualFile... roots) { return new VFSClassLoaderPolicy(name, roots); }