/** * Gets the parent of the given class. * * @param path * e.g. "jar:file:/a/b/c.jar!/d/e.class * @param clazz * e.gl. "d.e.class" * @return e.g. "jar:file:/a/b/c.jar" */ public static URI getParent(final URI path, final Class<?> clazz) { String resource = Converter.toResource(clazz); return getParent(path, resource); }
private URI getClasspathOf(final Class<?> clazz) { URI classpathUri = this.usedClasspathCache.get(clazz); if (classpathUri == null) { URI classUri = this.whichClass(clazz); if (classUri == null) { LOG.trace("URI for {} was not found (probably a proxy class).", clazz); classpathUri = NullConstants.NULL_URI; } else { classpathUri = ClasspathHelper.getParent(classUri, clazz); } this.usedClasspathCache.put(clazz, classpathUri); } return classpathUri; }
/** * Returns the jar file or path where the given resource was found. * * @param resource e.g. log4j.properties * * @return jar or path as URI */ public URI whichResourcePath(final String resource) { URI uri = this.whichResource(resource); if (uri == null) { return null; } return ClasspathHelper.getParent(uri, resource); }
/** * Returns the jar file or path where the given resource was found. * * @param resource * e.g. log4j.properties * * @return jar or path as URI */ public URI whichResourcePath(final String resource) { URI uri = this.classpathDigger.whichResource(resource); if (uri == null) { return null; } return ClasspathHelper.getParent(uri, resource); }
/** * It is only tested for Jamon 2.4 and 2.7 so we look for it * * @return true if Jamon 2.4 or 2.7 (or greater) was found */ public static boolean isJamonAvailable() { String resource = "/com/jamonapi/MonitorFactory.class"; URL classURL = Environment.class.getResource(resource); if (classURL == null) { LOG.debug("JAMon and {} not available, using simple profiling.", resource); return false; } try (JarFile jarfile = ClasspathMonitor .whichResourceJar(ClasspathHelper.getParent(classURL.toURI(), resource))) { Manifest manifest = jarfile.getManifest(); Attributes attributes = manifest.getMainAttributes(); String version = attributes.getValue("version"); if ("JAMon 2.4".equalsIgnoreCase(version) || (version.compareTo("JAMon 2.7") >= 0)) { LOG.info("{} available for profiling.", version); return true; } else { LOG.info("{} not supported (only JAMon 2.4 and 2.7 or higher), using simple profiling.", version); } } catch (IOException | URISyntaxException ex) { LOG.info("Will use simple profiling because cannot read manifest for {}:", classURL, ex); } return false; }
String resource = "/com/jamonapi/MonitorFactory.class"; URL classURL = ProfileStatistic.class.getResource(resource); URI jarURI = ClasspathHelper.getParent(classURL.toURI(), resource); JarFile jarfile = ClasspathMonitor.whichResourceJar(jarURI); Manifest manifest = jarfile.getManifest();
/** * Gets the resourcepathes which belongs to the given collection of * resources. * * @param resources the resources * @return the resourcepath set * @since 1.6.3 */ public SortedSet<URI> getResourcepathSet(Collection<String> resources) { SortedSet<URI> rscPath = new TreeSet<>(); for (String rsc : resources) { Enumeration<URL> urls = this.getResources(rsc); while (urls.hasMoreElements()) { URL url = urls.nextElement(); URI path = Converter.toURI(url); rscPath.add(ClasspathHelper.getParent(path, rsc)); } } return rscPath; }
/** * Gets the classpath set. * * @param classes the classes * * @return the classpath set */ private SortedSet<URI> getClasspathSet(final List<Class<?>> classes) { SortedSet<URI> classpath = new TreeSet<URI>(); for (Class<?> cl : classes) { String resource = Converter.toResource(cl); Enumeration<URL> resources = this.getResources(resource); while (resources.hasMoreElements()) { URL url = resources.nextElement(); URI path = Converter.toURI(url); classpath.add(ClasspathHelper.getParent(path, resource)); } } return classpath; }
public static URI getParent(final URI path, final Class<?> clazz) { String resource = Converter.toResource(clazz); return getParent(path, resource);
/** * Gets the loaded classpath (without the bootclasspath) as sorted set. <br/> * TODO: this method lets place for more performance (e.g. using a * Hashtable<Class, URI> for caching) * * @return the loaded classpath (excluding the bootclasspath) */ @ProfileMe public SortedSet<URI> getUsedClasspathSet() { List<Class<?>> loadedClassList = this.getLoadedClassList(); SortedSet<URI> usedClasspathSet = new TreeSet<URI>(); for (Class<?> clazz : loadedClassList) { URI classUri = this.whichClass(clazz); if (classUri != null) { URI classpath = ClasspathHelper.getParent(classUri, clazz); usedClasspathSet.add(classpath); } } return usedClasspathSet; }
/** * Here we use the loaded packages to calculate the classpath. For each * loaded package we will look from which jar file or directory this package * is loaded. * * @return the found classpath as string array * @since 27-Jul-2009 */ protected String[] getClasspathFromPackages() { Set<URI> packageURIs = new LinkedHashSet<>(); Package[] packages = this.getLoadedPackageArray(); for (int i = 0; i < packages.length; i++) { String resource = Converter.toResource(packages[i]); URI uri = ResourcepathDigger.whichResource(resource, this.classLoader); if (uri != null) { URI path = ClasspathHelper.getParent(uri, resource); packageURIs.add(path); } } return getClasspathFromPackages(packageURIs); }
/** * Here we use the loaded packages to calculate the classpath. For each * loaded package we will look from which jar file or directory this * package is loaded. * * @return the found classpath as string array * @since 27-Jul-2009 */ protected String[] getClasspathFromPackages() { Set<URI> packageURIs = new LinkedHashSet<URI>(); Package[] packages = this.getLoadedPackageArray(); for (int i = 0; i < packages.length; i++) { String resource = Converter.toResource(packages[i]); URI uri = whichResource(resource, this.classLoader); if (uri != null) { URI path = ClasspathHelper.getParent(uri, resource); packageURIs.add(path); } } return getClasspathFromPackages(packageURIs); }