public UrlClazzLoader(String name, String details, URL[] urls) { super(name, details, true); for (URL url : urls) { if (url != null) { addClasspathEntry(new ClasspathEntry(this, url.toString())); } } } }
/** * 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; }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final JarPair other = (JarPair) obj; if (this.jar1.equals(other.jar1) && this.jar2.equals(other.jar2) || this.jar1.equals(other.jar2) && this.jar2.equals(other.jar1)) { return true; } return false; }
protected void addClasspathEntry(ClasspathEntry newEntry) { classpathEntries.add(newEntry); if (newEntry.isJar()) { List<ClasspathEntry> manifestClasspath = newEntry.findManifestClasspathEntries(); for (ClasspathEntry manifestEntry : manifestClasspath) { addClasspathEntry(manifestEntry); } } }
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; }
List<ClasspathEntry> manifestClasspathEntries = new ArrayList<>(); if (isJar()) { JarInputStream jarStream; try { jarStream = new JarInputStream(new URL(getUrl()).openStream()); Manifest manifest = jarStream.getManifest(); if (manifest != null) { for (String jarPath : jarPaths) { logger.debug("Manifest jar path: " + jarPath); manifestClasspathEntries.add(new ClasspathEntry(classLoader, jarPath));
@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)); } }
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 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"); } } }
listener.onEntryScanStart(entry); allResourceVersions.addAll(entry.getResourceVersions()); if (listener != null) { listener.onEntryScanEnd(entry);
List<ClasspathEntry> manifestClasspathEntries = new ArrayList<>(); if (isJar()) { JarInputStream jarStream; try { jarStream = new JarInputStream(new URL(getUrl()).openStream()); Manifest manifest = jarStream.getManifest(); if (manifest != null) { for (String jarPath : jarPaths) { logger.debug("Manifest jar path: " + jarPath); manifestClasspathEntries.add(new ClasspathEntry(classLoader, jarPath));
@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)); } } });
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 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 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"); } } }
protected void addClasspathEntry(ClasspathEntry newEntry) { classpathEntries.add(newEntry); if (newEntry.isJar()) { List<ClasspathEntry> manifestClasspath = newEntry.findManifestClasspathEntries(); for (ClasspathEntry manifestEntry : manifestClasspath) { addClasspathEntry(manifestEntry); } } }
listener.onEntryScanStart(entry); allResourceVersions.addAll(entry.getResourceVersions()); if (listener != null) { listener.onEntryScanEnd(entry);
/** * 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; }
@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; } });
public UrlClazzLoader(String name, String details, URL[] urls) { super(name, details, true); for (URL url : urls) { if (url != null) { addClasspathEntry(new ClasspathEntry(this, url.toString())); } } } }