Skip to content

Commit

Permalink
v3.17.1 release (^.^)YYa!!
Browse files Browse the repository at this point in the history
  • Loading branch information
yangfuhai committed Nov 25, 2022
1 parent 7775717 commit 9261674
Showing 1 changed file with 28 additions and 43 deletions.
71 changes: 28 additions & 43 deletions src/main/java/io/jboot/utils/ClassScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,22 @@
*/
package io.jboot.utils;

import io.jboot.app.config.JbootConfigManager;

import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.function.Predicate;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarInputStream;
import java.util.stream.Collectors;

import io.jboot.app.config.JbootConfigManager;

public class ClassScanner {

private static final Set<Class<?>> appClassesCache = new HashSet<>();
Expand All @@ -45,7 +41,7 @@ public class ClassScanner {
public static final Set<String> scanClasses = new HashSet<>();
public static final Set<String> excludeClasses = new HashSet<>();
// dev模式打开扫描信息打印
private static boolean printScannerInfoEnable = JbootConfigManager.me().isDevMode();
private static boolean printScannerInfoEnable = false;

public static boolean isPrintScannerInfoEnable() {
return printScannerInfoEnable;
Expand Down Expand Up @@ -627,51 +623,44 @@ private static void addClassesFromJar(String jarPath) {
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry jarEntry = entries.nextElement();
if (jarEntry.isDirectory()) {
String entryName = jarEntry.getName();
String entryName = jarEntry.getName();
if (jarEntry.isDirectory() && entryName.startsWith("BOOT-INF/classes/")) {

if (isPrintScannerInfoEnable()) {
System.out.println("Jboot Scan entryName: " + entryName);
}

if (entryName.startsWith("BOOT-INF/classes/")) {
if (entryName.endsWith(".class")) {
String className = entryName.replace("/", ".").substring(0, entryName.length() - 6);
addClass(classForName(className));
}
}
}
else {
String entryName = jarEntry.getName();
if (entryName.endsWith(".class")) {
String className = entryName.replace("/", ".").substring(0, entryName.length() - 6);
addClass(classForName(className));
}
else if (entryName.startsWith("BOOT-INF/lib/") && entryName.endsWith(".jar")) {
} else {
if (entryName.endsWith(".class")) {
String className = entryName.replace("/", ".").substring(0, entryName.length() - 6);
addClass(classForName(className));
} else if (entryName.startsWith("BOOT-INF/lib/") && entryName.endsWith(".jar")) {
if (!isIncludeJar(entryName)) {
continue;
}

if (isPrintScannerInfoEnable()) {
System.out.println("Jboot Scan Jar: " + entryName);
}
JarInputStream jarIS = new JarInputStream(jarFile
.getInputStream(jarEntry));

JarEntry innerEntry = jarIS.getNextJarEntry();
while (innerEntry != null) {
if (!innerEntry.isDirectory()) {
String nestedEntryName = innerEntry.getName();
if (nestedEntryName.endsWith(".class")) {
String className = nestedEntryName.replace("/", ".").substring(0, nestedEntryName.length() - 6);
addClass(classForName(className));

try (JarInputStream jarStream = new JarInputStream(jarFile
.getInputStream(jarEntry));){
JarEntry innerEntry = jarStream.getNextJarEntry();
while (innerEntry != null) {
if (!innerEntry.isDirectory()) {
String nestedEntryName = innerEntry.getName();
if (nestedEntryName.endsWith(".class")) {
String className = nestedEntryName.replace("/", ".").substring(0, nestedEntryName.length() - 6);
addClass(classForName(className));
}
}
innerEntry = jarStream.getNextJarEntry();
}
innerEntry = jarIS.getNextJarEntry();
}
if (jarIS != null) {
jarIS.close();
}
// addClassesFromJar(nestedJarPath);
}
}
}
Expand All @@ -686,10 +675,6 @@ else if (entryName.startsWith("BOOT-INF/lib/") && entryName.endsWith(".jar")) {
}
}

// public static void main(String[] args) {
// String filePath = "D:\\test\\springbootest.jar";
// addClassesFromJar(filePath);
// }

private static void addClassesFromClassPath(String classPath) {

Expand Down Expand Up @@ -748,8 +733,8 @@ private static void findClassPathsAndJarsByClassloader(Set<String> jarPaths, Set
}

if (!path.toLowerCase().endsWith(".jar")) {
if(path.toLowerCase().endsWith("!/") || path.toLowerCase().endsWith("!")) { }
else{
if (path.toLowerCase().endsWith("!/") || path.toLowerCase().endsWith("!")) {
} else {
classPaths.add(new File(path).getCanonicalPath().replace('\\', '/'));
}
} else {
Expand Down Expand Up @@ -788,8 +773,8 @@ private static void findClassPathsAndJarsByClassPath(Set<String> jarPaths, Set<S
}
try {
if (!path.toLowerCase().endsWith(".jar") && !jarPaths.contains(path)) {
if (path.toLowerCase().endsWith("!/") || path.toLowerCase().endsWith("!")) {}
else{
if (path.toLowerCase().endsWith("!/") || path.toLowerCase().endsWith("!")) {
} else {
classPaths.add(new File(path).getCanonicalPath().replace('\\', '/'));
}
} else {
Expand Down

0 comments on commit 9261674

Please sign in to comment.