List of usage examples for java.lang ClassLoader getParent
@CallerSensitive public final ClassLoader getParent()
From source file:SecuritySupport.java
ClassLoader getParentClassLoader(final ClassLoader cl) { return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { ClassLoader parent = null; try { parent = cl.getParent(); } catch (SecurityException ex) { }//from w ww . java 2s .c o m // eliminate loops in case of the boot // ClassLoader returning itself as a parent return (parent == cl) ? null : parent; } }); }
From source file:edu.umich.flowfence.sandbox.SandboxService.java
@Override public IBinder onBind(Intent i) { if (localLOGD) { Log.d(TAG, "Bound"); }//from ww w . jav a 2 s .c o m Bundle extras = i.getExtras(); if (extras == null) { throw new IllegalArgumentException("No extras"); } IBinder api = extras.getBinder(EXTRA_TRUSTED_API); if (api == null) { throw new IllegalArgumentException("Trusted API not found in extras"); } IBinder root = extras.getBinder(EXTRA_ROOT_SERVICE); if (root == null) { throw new IllegalArgumentException("FlowfenceService not found in extras"); } mTrustedAPI = ITrustedAPI.Stub.asInterface(api); mRootService = IFlowfenceService.Stub.asInterface(root); mID = extras.getInt(EXTRA_SANDBOX_ID, -1); if (localLOGV) { ClassLoader cl = getClassLoader(); Log.v(TAG, "ClassLoader chain:"); while (cl != null) { Log.v(TAG, cl.toString()); cl = cl.getParent(); } Log.v(TAG, "<end of chain>"); } final String[] packagesToLoad = extras.getStringArray(EXTRA_KNOWN_PACKAGES); getBackgroundHandler().post(new Runnable() { @Override public void run() { if (localLOGD) { Log.d(TAG, "Preloading resolve code"); } // Run through a fake transaction, to preload the appropriate classes. QMDescriptor preloadDesc = QMDescriptor.forStatic(SandboxService.this, SandboxService.class, "resolveStub"); Binder testBinder = new Binder() { @Override protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException { return mBinder.onTransact(code, data, reply, flags); } }; testBinder.attachInterface(null, ""); ISandboxService proxy = ISandboxService.Stub.asInterface(testBinder); try { proxy.resolveQM(preloadDesc, false, null); } catch (Exception e) { Log.w(TAG, "Couldn't preload resolve", e); } if (localLOGD) { Log.d(TAG, "Preloading packages"); } // Load up packages the trusted service tells us we might need. for (String packageName : ArrayUtils.nullToEmpty(packagesToLoad)) { try { if (localLOGD) { Log.d(TAG, "Preloading " + packageName); } getContextForPackage(packageName); } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "Can't preload package", e); } } Log.i(TAG, "Sandbox #" + mID + ": preload complete"); } }); return mBinder; }
From source file:edu.umich.oasis.sandbox.SandboxService.java
@Override public IBinder onBind(Intent i) { if (localLOGD) { Log.d(TAG, "Bound"); }//ww w.j av a2s .co m Bundle extras = i.getExtras(); if (extras == null) { throw new IllegalArgumentException("No extras"); } IBinder api = extras.getBinder(EXTRA_TRUSTED_API); if (api == null) { throw new IllegalArgumentException("Trusted API not found in extras"); } IBinder root = extras.getBinder(EXTRA_ROOT_SERVICE); if (root == null) { throw new IllegalArgumentException("OASISService not found in extras"); } mTrustedAPI = ITrustedAPI.Stub.asInterface(api); mRootService = IOASISService.Stub.asInterface(root); mID = extras.getInt(EXTRA_SANDBOX_ID, -1); if (localLOGV) { ClassLoader cl = getClassLoader(); Log.v(TAG, "ClassLoader chain:"); while (cl != null) { Log.v(TAG, cl.toString()); cl = cl.getParent(); } Log.v(TAG, "<end of chain>"); } final String[] packagesToLoad = extras.getStringArray(EXTRA_KNOWN_PACKAGES); getBackgroundHandler().post(new Runnable() { @Override public void run() { if (localLOGD) { Log.d(TAG, "Preloading resolve code"); } // Run through a fake transaction, to preload the appropriate classes. SodaDescriptor preloadDesc = SodaDescriptor.forStatic(SandboxService.this, SandboxService.class, "resolveStub"); Binder testBinder = new Binder() { @Override protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException { return mBinder.onTransact(code, data, reply, flags); } }; testBinder.attachInterface(null, ""); ISandboxService proxy = ISandboxService.Stub.asInterface(testBinder); try { proxy.resolveSoda(preloadDesc, false, null); } catch (Exception e) { Log.w(TAG, "Couldn't preload resolve", e); } if (localLOGD) { Log.d(TAG, "Preloading packages"); } // Load up packages the trusted service tells us we might need. for (String packageName : ArrayUtils.nullToEmpty(packagesToLoad)) { try { if (localLOGD) { Log.d(TAG, "Preloading " + packageName); } getContextForPackage(packageName); } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "Can't preload package", e); } } Log.i(TAG, "Sandbox #" + mID + ": preload complete"); } }); return mBinder; }
From source file:com.streamsets.datacollector.cluster.ClusterProviderImpl.java
private static Properties readDataCollectorProperties(ClassLoader cl) throws IOException { Properties properties = new Properties(); while (cl != null) { Enumeration<URL> urls = cl.getResources(DATA_COLLECTOR_LIBRARY_PROPERTIES); if (urls != null) { while (urls.hasMoreElements()) { URL url = urls.nextElement(); LOG.trace("Loading data collector library properties: {}", url); try (InputStream inputStream = url.openStream()) { properties.load(inputStream); }// w w w . j a va 2 s .c om } } cl = cl.getParent(); } LOG.trace("Final properties: {} ", properties); return properties; }
From source file:com.sun.socialsite.web.listeners.ContextListener.java
/** * Logs some information about the specified <code>ClassLoader</code> * (and its ancestors)./*from www . j a v a2 s .c om*/ * * @param classLoader the ClassLoader for which info will be logged. * @param name the name which will be included in log entries. */ private void logClassLoaderInfo(ClassLoader classLoader, String name) { log.debug(String.format("%s=%s", name, toSimpleString(classLoader))); if (classLoader instanceof URLClassLoader) { URL[] urls = ((URLClassLoader) classLoader).getURLs(); for (int i = 0; i < urls.length; i++) { log.debug(String.format("%s.classPath[%d]=%s", name, i, urls[i])); } } ClassLoader parent = classLoader.getParent(); if (parent != null) { logClassLoaderInfo(parent, (name + ".parent")); } }
From source file:com.github.drochetti.javassist.maven.ClassTransformer.java
private void debugClassLoader(final ClassPool classPool) { if (!logger.isDebugEnabled()) { return;//from ww w . j ava2 s. com } logger.debug(" - classPool: " + classPool.toString()); ClassLoader classLoader = classPool.getClassLoader(); while (classLoader != null) { logger.debug(" -- " + classLoader.getClass().getName() + ": " + classLoader.toString()); if (classLoader instanceof URLClassLoader) { logger.debug(" --- urls: " + Arrays.deepToString(((URLClassLoader) classLoader).getURLs())); } classLoader = classLoader.getParent(); } }
From source file:com.streamsets.datacollector.cluster.BaseClusterProvider.java
@VisibleForTesting static Properties readDataCollectorProperties(ClassLoader cl) throws IOException { Properties properties = new Properties(); while (cl != null) { Enumeration<URL> urls = cl.getResources(DATA_COLLECTOR_LIBRARY_PROPERTIES); if (urls != null) { while (urls.hasMoreElements()) { URL url = urls.nextElement(); LOG.trace("Loading data collector library properties: {}", url); try (InputStream inputStream = url.openStream()) { properties.load(inputStream); }//from w ww .j av a 2 s. c o m } } cl = cl.getParent(); } LOG.trace("Final properties: {} ", properties); return properties; }
From source file:net.testdriven.psiprobe.beans.LogResolverBean.java
private List<LogDestination> getAllLogDestinations() { if (Instruments.isInitialized()) { List<LogDestination> allAppenders = new ArrayList<>(); ///*from ww w . j av a 2 s . co m*/ // interrogate classloader hierarchy // ClassLoader cl2 = Thread.currentThread().getContextClassLoader().getParent(); while (cl2 != null) { interrogateClassLoader(cl2, null, allAppenders); cl2 = cl2.getParent(); } // // check for known stdout files, such as "catalina.out" // interrogateStdOutFiles(allAppenders); // // interrogate webapp classloaders and avilable loggers // List contexts = getContainerWrapper().getTomcatContainer().findContexts(); for (Object context : contexts) { Context ctx = (Context) context; interrogateContext(ctx, allAppenders); } return allAppenders; } return null; }
From source file:com.google.code.rees.scope.struts2.StrutsActionProvider.java
private UrlSet buildUrlSet(List<URL> resourceUrls) throws IOException { ClassLoaderInterface classLoaderInterface = getClassLoaderInterface(); UrlSet urlSet = new UrlSet(resourceUrls); urlSet.include(new UrlSet(classLoaderInterface, this.fileProtocols)); //excluding the urls found by the parent class loader is desired, but fails in JBoss (all urls are removed) if (excludeParentClassLoader) { //exclude parent of classloaders ClassLoaderInterface parent = classLoaderInterface.getParent(); //if reload is enabled, we need to step up one level, otherwise the UrlSet will be empty //this happens because the parent of the realoding class loader is the web app classloader if (parent != null && isReloadEnabled()) parent = parent.getParent(); if (parent != null) urlSet = urlSet.exclude(parent); try {/*from ww w. j ava 2s . c o m*/ // This may fail in some sandboxes, ie GAE ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); urlSet = urlSet.exclude(new ClassLoaderInterfaceDelegate(systemClassLoader.getParent())); } catch (SecurityException e) { if (LOG.isWarnEnabled()) LOG.warn( "Could not get the system classloader due to security constraints, there may be improper urls left to scan"); } } //try to find classes dirs inside war files urlSet = urlSet.includeClassesUrl(classLoaderInterface, new UrlSet.FileProtocolNormalizer() { public URL normalizeToFileProtocol(URL url) { return fileManager.normalizeToFileProtocol(url); } }); urlSet = urlSet.excludeJavaExtDirs(); urlSet = urlSet.excludeJavaEndorsedDirs(); try { urlSet = urlSet.excludeJavaHome(); } catch (NullPointerException e) { // This happens in GAE since the sandbox contains no java.home directory if (LOG.isWarnEnabled()) LOG.warn("Could not exclude JAVA_HOME, is this a sandbox jvm?"); } urlSet = urlSet.excludePaths(System.getProperty("sun.boot.class.path", "")); urlSet = urlSet.exclude(".*/JavaVM.framework/.*"); if (includeJars == null) { urlSet = urlSet.exclude(".*?\\.jar(!/|/)?"); } else { //jar urls regexes were specified List<URL> rawIncludedUrls = urlSet.getUrls(); Set<URL> includeUrls = new HashSet<URL>(); boolean[] patternUsed = new boolean[includeJars.length]; for (URL url : rawIncludedUrls) { if (fileProtocols.contains(url.getProtocol())) { //it is a jar file, make sure it macthes at least a url regex for (int i = 0; i < includeJars.length; i++) { String includeJar = includeJars[i]; if (Pattern.matches(includeJar, url.toExternalForm())) { includeUrls.add(url); patternUsed[i] = true; break; } } } else { //it is not a jar includeUrls.add(url); } } if (LOG.isWarnEnabled()) { for (int i = 0; i < patternUsed.length; i++) { if (!patternUsed[i]) { LOG.warn("The includeJars pattern [#0] did not match any jars in the classpath", includeJars[i]); } } } return new UrlSet(includeUrls); } return urlSet; }
From source file:com.googlecode.psiprobe.beans.LogResolverBean.java
private List getAllLogDestinations() { if (Instruments.isInitialized()) { List allAppenders = new ArrayList(); ////from w w w . j a v a 2 s .co m // interrogate classloader hierarchy // ClassLoader cl2 = Thread.currentThread().getContextClassLoader().getParent(); while (cl2 != null) { interrogateClassLoader(cl2, null, allAppenders); cl2 = cl2.getParent(); } // // check for known stdout files, such as "catalina.out" // interrogateStdOutFiles(allAppenders); // // interrogate webapp classloaders and available loggers // List contexts = getContainerWrapper().getTomcatContainer().findContexts(); for (int i = 0; i < contexts.size(); i++) { Context ctx = (Context) contexts.get(i); interrogateContext(ctx, allAppenders); } return allAppenders; } return null; }