@Override public void onEntryScanEnd(ClasspathEntry entry) { String filePath = entry.getUrl().toString(); Matcher matcher = JAR_NAME.matcher(filePath); if (matcher.matches()) { updateStatus("Finished processing jar " + matcher.group(1)); } } });
@Override public void onEntryScanStart(ClasspathEntry entry) { String filePath = entry.getUrl().toString(); Matcher matcher = JAR_NAME.matcher(filePath); if (matcher.matches()) { updateStatus("Processing jar " + matcher.group(1)); } }
@Override public FileVisitResult visitFile(Path classpathResourceFile, BasicFileAttributes attrs) throws IOException { String resourceName = classpathResourceFile.toString(); logger.debug(getUrl() + " -" + resourceName); ClasspathResourceVersion classFileVersion = new ClasspathResourceVersion(ClasspathEntry.this, resourceName, attrs.size()); resourceVersions.add(classFileVersion); return CONTINUE; } });
@Override public FileVisitResult visitFile(Path classpathResourceFile, BasicFileAttributes attrs) throws IOException { String resourceName = classpathResourceFile.toString(); logger.debug(getUrl() + " -" + resourceName); ClasspathResourceVersion classFileVersion = new ClasspathResourceVersion(ClasspathEntry.this, resourceName, attrs.size()); resourceVersions.add(classFileVersion); return CONTINUE; } });
/** * The contents of a jar are only loaded if accessed the first time. * */ public List<ClasspathResourceVersion> getResourceVersions() throws URISyntaxException, IOException { if (!lazyLoadDone) { if (isClassFolder()) { logger.debug("\nScanning class folder: " + getUrl()); URI uri = new URI(getUrl()); Path start = Paths.get(uri); scanClasspathEntry(start); } else if (isJar()) { logger.debug("\nScanning jar: " + getUrl()); URI uri = new URI("jar:" + getUrl()); try (FileSystem jarFS = FileSystems.newFileSystem(uri, new HashMap<String, String>())) { Path zipInJarPath = jarFS.getPath("/"); scanClasspathEntry(zipInJarPath); } catch (Exception exc) { logger.debug("Could not scan jar: " + getUrl() + " - reason:" + exc.getMessage()); } } lazyLoadDone = true; } return resourceVersions; }
/** * The contents of a jar are only loaded if accessed the first time. * */ public List<ClasspathResourceVersion> getResourceVersions() throws URISyntaxException, IOException { if (!lazyLoadDone) { if (isClassFolder()) { logger.debug("\nScanning class folder: " + getUrl()); URI uri = new URI(getUrl()); Path start = Paths.get(uri); scanClasspathEntry(start); } else if (isJar()) { logger.debug("\nScanning jar: " + getUrl()); URI uri = new URI("jar:" + getUrl()); try (FileSystem jarFS = FileSystems.newFileSystem(uri, new HashMap<String, String>())) { Path zipInJarPath = jarFS.getPath("/"); scanClasspathEntry(zipInJarPath); } catch (Exception exc) { logger.debug("Could not scan jar: " + getUrl() + " - reason:" + exc.getMessage()); } } lazyLoadDone = true; } return resourceVersions; }
JarInputStream jarStream; try { jarStream = new JarInputStream(new URL(getUrl()).openStream()); Manifest manifest = jarStream.getManifest(); if (manifest != null) {
public JHades findClass(Class clazz) { if (clazz == null) { throw new IllegalArgumentException("Class name cannot be null."); } System.out.println(">> jHades searchClass >> Searching for class: " + clazz.getCanonicalName() + "\n"); ClasspathResource foundClass = scanner.findClass(clazz); for (ClasspathResourceVersion version : foundClass.getResourceFileVersions()) { System.out.println(version.getClasspathEntry().getUrl() + foundClass.getName() + " size = " + version.getFileSize()); } endCommand(foundClass != null); return this; }
public JHades findClass(Class clazz) { if (clazz == null) { throw new IllegalArgumentException("Class name cannot be null."); } System.out.println(">> jHades searchClass >> Searching for class: " + clazz.getCanonicalName() + "\n"); ClasspathResource foundClass = scanner.findClass(clazz); for (ClasspathResourceVersion version : foundClass.getResourceFileVersions()) { System.out.println(version.getClasspathEntry().getUrl() + foundClass.getName() + " size = " + version.getFileSize()); } endCommand(foundClass != null); return this; }
JarInputStream jarStream; try { jarStream = new JarInputStream(new URL(getUrl()).openStream()); Manifest manifest = jarStream.getManifest(); if (manifest != null) {
boolean found = false; for (ClasspathEntry classpathEntry : allClasspathEntries) { if (classpathEntry.getUrl().contains(pathEntry)) { found = true; break;
public JHades printClasspath() { System.out.println("\n>> jHades printClasspath >> Printing all class folder and jars on the classpath:\n"); List<ClasspathEntry> classpathEntries = scanner.findAllClasspathEntries(); ClazzLoader clazzLoader = null; for (ClasspathEntry entry : classpathEntries) { if (entry.getClassLoader() != null && !entry.getClassLoader().equals(clazzLoader)) { System.out.println(); // line break between class loaders clazzLoader = entry.getClassLoader(); } System.out.println(entry.getClassLoaderName() + " - " + entry.getUrl()); } endCommand(classpathEntries.size() > 0); return this; }
boolean found = false; for (ClasspathEntry classpathEntry : allClasspathEntries) { if (classpathEntry.getUrl().contains(pathEntry)) { found = true; break;
public JHades printClasspath() { System.out.println("\n>> jHades printClasspath >> Printing all class folder and jars on the classpath:\n"); List<ClasspathEntry> classpathEntries = scanner.findAllClasspathEntries(); ClazzLoader clazzLoader = null; for (ClasspathEntry entry : classpathEntries) { if (entry.getClassLoader() != null && !entry.getClassLoader().equals(clazzLoader)) { System.out.println(); // line break between class loaders clazzLoader = entry.getClassLoader(); } System.out.println(entry.getClassLoaderName() + " - " + entry.getUrl()); } endCommand(classpathEntries.size() > 0); return this; }
public void print() { System.out.println("\n>> jHades multipleClassVersionsReport >> Duplicate classpath resources report: \n"); ClasspathResources.sortByNumberOfVersionsDesc(resourcesWithDuplicates); for (ClasspathResource resource : resourcesWithDuplicates) { if (!resourcesToExclude.contains(resource.getName())) { System.out.println(resource.getName() + " has " + resource.getResourceFileVersions().size() + " versions on these classpath locations:\n"); for (ClasspathResourceVersion resourceFileVersion : resource.getResourceFileVersions()) { String classLoaderName = resourceFileVersion.getClasspathEntry().getClassLoaderName(); System.out.println(" " + (classLoaderName != null ? classLoaderName : "") + " - " + urlFormatter.formatUrl(resourceFileVersion.getClasspathEntry().getUrl()) + " - class file size = " + resourceFileVersion.getFileSize()); } System.out.println(); } } if (resourcesWithDuplicates.isEmpty()) { System.out.println("No duplicates where found.\n"); } } }
public void print() { System.out.println("\n>> jHades multipleClassVersionsReport >> Duplicate classpath resources report: \n"); ClasspathResources.sortByNumberOfVersionsDesc(resourcesWithDuplicates); for (ClasspathResource resource : resourcesWithDuplicates) { if (!resourcesToExclude.contains(resource.getName())) { System.out.println(resource.getName() + " has " + resource.getResourceFileVersions().size() + " versions on these classpath locations:\n"); for (ClasspathResourceVersion resourceFileVersion : resource.getResourceFileVersions()) { String classLoaderName = resourceFileVersion.getClasspathEntry().getClassLoaderName(); System.out.println(" " + (classLoaderName != null ? classLoaderName : "") + " - " + urlFormatter.formatUrl(resourceFileVersion.getClasspathEntry().getUrl()) + " - class file size = " + resourceFileVersion.getFileSize()); } System.out.println(); } } if (resourcesWithDuplicates.isEmpty()) { System.out.println("No duplicates where found.\n"); } } }
public JHades overlappingJarsReport() { System.out.println("\n>> jHades - scanning classpath for overlapping jars: \n"); List<JarPair> jarOverlapReportLines = scanner.findOverlappingJars(); for (JarPair jarOverlapReportLine : jarOverlapReportLines) { String reportLine = jarOverlapReportLine.getJar1().getUrl() + " overlaps with \n" + jarOverlapReportLine.getJar2().getUrl() + " - total overlapping classes: " + jarOverlapReportLine.getDupClassesTotal() + " - "; if (jarOverlapReportLine.getJar1().getClassLoader().equals(jarOverlapReportLine.getJar2().getClassLoader())) { reportLine += "same classloader ! This is an ERROR!\n"; } else { reportLine += "different classloaders.\n"; } System.out.println(reportLine); } endCommand(jarOverlapReportLines.size() > 0); return this; }
public JHades overlappingJarsReport() { System.out.println("\n>> jHades - scanning classpath for overlapping jars: \n"); List<JarPair> jarOverlapReportLines = scanner.findOverlappingJars(); for (JarPair jarOverlapReportLine : jarOverlapReportLines) { String reportLine = jarOverlapReportLine.getJar1().getUrl() + " overlaps with \n" + jarOverlapReportLine.getJar2().getUrl() + " - total overlapping classes: " + jarOverlapReportLine.getDupClassesTotal() + " - "; if (jarOverlapReportLine.getJar1().getClassLoader().equals(jarOverlapReportLine.getJar2().getClassLoader())) { reportLine += "same classloader ! This is an ERROR!\n"; } else { reportLine += "different classloaders.\n"; } System.out.println(reportLine); } endCommand(jarOverlapReportLines.size() > 0); return this; }
String reportLine = getJarName(jarOverlapReportLine.getJar1().getUrl()) + " overlaps with " + getJarName(jarOverlapReportLine.getJar2().getUrl()) + " - total overlapping classes: " + jarOverlapReportLine.getDupClassesTotal(); System.out.println(reportLine); System.out.println(match.getName() + "\n"); for (ClasspathResourceVersion version : match.getResourceFileVersions()) { System.out.println(" " + version.getClasspathEntry().getUrl());