Skip to content

Commit 519cfff

Browse files
committed
add classlist file of jdk11
jsse packages now listed in classlist file. fix #406
1 parent c23338b commit 519cfff

File tree

2 files changed

+95
-56
lines changed

2 files changed

+95
-56
lines changed

libs/javavi/src/main/java/kg/ash/javavi/searchers/ClasspathCollector.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public class ClasspathCollector {
1717
public static final Logger logger = LogManager.getLogger();
1818

1919
private ByExtensionVisitor finder = new ByExtensionVisitor(
20-
Arrays.asList("*.jar", "*.JAR", "*.zip", "*.ZIP", "*.class", "*.jmod"));
20+
Arrays.asList("*.jar", "*.JAR", "*.zip", "*.ZIP", "*.class",
21+
"*.jmod", "classlist"));
2122

2223
private String pSep = File.pathSeparator;
2324

@@ -34,19 +35,22 @@ public List<String> collectClassPath() {
3435
result.addAll(addPathFromDir(System.getProperty("java.home")));
3536

3637
String classPath = System.getProperty("java.class.path");
37-
Stream.of(classPath.split(pSep)).filter(p -> p.length() >= 4).forEach(path -> {
38-
String ext = path.substring(path.length() - 4).toLowerCase();
39-
if (ext.endsWith(".jar") || ext.endsWith(".zip")) {
40-
result.add(path);
41-
} else {
42-
result.addAll(addPathFromDir(path));
43-
}
38+
Stream.of(classPath.split(pSep))
39+
.filter(p -> p.length() >= 4).forEach(path -> {
40+
String ext = path.substring(path.length() - 4)
41+
.toLowerCase();
42+
if (ext.endsWith(".jar") || ext.endsWith(".zip")) {
43+
result.add(path);
44+
} else {
45+
result.addAll(addPathFromDir(path));
46+
}
4447
});
4548

4649
return result;
4750
}
4851

4952
private List<String> addPathFromDir(String dirpath) {
53+
logger.info(dirpath);
5054
List<String> result = new ArrayList<>();
5155
File dir = new File(dirpath);
5256
if (dir.isDirectory()) {

libs/javavi/src/main/java/kg/ash/javavi/searchers/ClasspathPackageSearcher.java

Lines changed: 83 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package kg.ash.javavi.searchers;
22

3-
import kg.ash.javavi.apache.logging.log4j.LogManager;
4-
import kg.ash.javavi.apache.logging.log4j.Logger;
5-
63
import java.io.File;
4+
import java.io.IOException;
5+
import java.nio.file.Files;
6+
import java.nio.file.Paths;
77
import java.util.ArrayList;
88
import java.util.Enumeration;
99
import java.util.List;
1010
import java.util.Optional;
11+
import java.util.stream.Stream;
1112
import java.util.zip.ZipFile;
1213

14+
import kg.ash.javavi.apache.logging.log4j.LogManager;
15+
import kg.ash.javavi.apache.logging.log4j.Logger;
16+
1317
public class ClasspathPackageSearcher implements PackageSeacherIFace {
1418

1519
public static final Logger logger = LogManager.getLogger();
@@ -18,56 +22,85 @@ public List<PackageEntry> loadEntries() {
1822
List<PackageEntry> result = new ArrayList<>();
1923

2024
List<String> knownPaths = new ArrayList<>();
21-
new ClasspathCollector().collectClassPath().stream().forEach(filePath -> {
22-
if (filePath.toLowerCase().endsWith(".class")) {
23-
String path = filePath.substring(0, filePath.length() - 6).replaceAll("/", ".");
24-
String newPath = path.substring(0, path.lastIndexOf("."));
25-
String fileName = path.substring(path.lastIndexOf(".") + 1, path.length());
26-
Optional<PackageEntry> kp = knownPaths.parallelStream()
27-
.filter(s -> newPath.endsWith(s))
28-
.findFirst()
29-
.map(p -> p + File.separator + fileName + ".class")
30-
.map(p -> new PackageEntry(p, JavaClassMap.SOURCETYPE_CLASSPATH, filePath,
31-
PackageEntry.FILETYPE_CLASS));
32-
if (kp.isPresent()) {
33-
result.add(kp.get());
34-
return;
35-
}
25+
new ClasspathCollector().collectClassPath()
26+
.stream()
27+
.forEach(filePath -> {
28+
if (filePath.toLowerCase().endsWith(".class")) {
29+
String path = filePath.substring(
30+
0, filePath.length() - 6)
31+
.replaceAll("/", ".");
32+
String newPath = path.substring(
33+
0, path.lastIndexOf("."));
34+
String fileName = path.substring(
35+
path.lastIndexOf(".") + 1, path.length());
36+
Optional<PackageEntry> kp = knownPaths.parallelStream()
37+
.filter(s -> newPath.endsWith(s))
38+
.findFirst()
39+
.map(p -> p + File.separator + fileName + ".class")
40+
.map(p -> new PackageEntry(
41+
p,
42+
JavaClassMap.SOURCETYPE_CLASSPATH,
43+
filePath,
44+
PackageEntry.FILETYPE_CLASS));
45+
if (kp.isPresent()) {
46+
result.add(kp.get());
47+
return;
48+
}
3649

37-
String[] split = path.split("\\.");
38-
int j = split.length - 2;
39-
while (j > 0) {
40-
path = "";
41-
for (int i = j; i <= split.length - 2; i++) {
42-
path += split[i] + ".";
50+
String[] split = path.split("\\.");
51+
int j = split.length - 2;
52+
while (j > 0) {
53+
path = "";
54+
for (int i = j; i <= split.length - 2; i++) {
55+
path += split[i] + ".";
56+
}
57+
String pkg = getPackageByFile(path + fileName);
58+
if (pkg != null) {
59+
result.add(
60+
new PackageEntry(
61+
pkg + File.separator +
62+
fileName + ".class",
63+
JavaClassMap.SOURCETYPE_CLASSPATH,
64+
filePath,
65+
PackageEntry.FILETYPE_CLASS));
66+
knownPaths.add(pkg);
67+
break;
68+
} else {
69+
j--;
70+
}
4371
}
44-
String pkg = getPackageByFile(path + fileName);
45-
if (pkg != null) {
46-
result.add(new PackageEntry(pkg + File.separator + fileName + ".class",
47-
JavaClassMap.SOURCETYPE_CLASSPATH, filePath,
48-
PackageEntry.FILETYPE_CLASS));
49-
knownPaths.add(pkg);
50-
break;
51-
} else {
52-
j--;
72+
} else if (filePath.endsWith("classlist")) {
73+
try (Stream<String> stream =
74+
Files.lines(Paths.get(filePath))) {
75+
stream.forEach(l -> {
76+
result.add(
77+
new PackageEntry(l + ".class",
78+
JavaClassMap.SOURCETYPE_CLASSPATH,
79+
filePath));
80+
});
81+
} catch (IOException ex) {
82+
logger.warn("error read classlist file", ex);
5383
}
54-
}
55-
} else {
56-
try {
57-
for (Enumeration entries = new ZipFile(filePath).entries();
58-
entries.hasMoreElements(); ) {
59-
String entry = entries.nextElement().toString();
60-
if (filePath.endsWith(".jmod") && entry.startsWith("classes/")) {
61-
entry = entry.substring(8);
84+
} else {
85+
try {
86+
for (Enumeration entries =
87+
new ZipFile(filePath).entries();
88+
entries.hasMoreElements(); ) {
89+
String entry = entries.nextElement().toString();
90+
if (filePath.endsWith(".jmod")
91+
&& entry.startsWith("classes/")) {
92+
entry = entry.substring(8);
93+
}
94+
result.add(
95+
new PackageEntry(entry,
96+
JavaClassMap.SOURCETYPE_CLASSPATH,
97+
filePath));
6298
}
63-
result.add(
64-
new PackageEntry(entry, JavaClassMap.SOURCETYPE_CLASSPATH, filePath));
99+
} catch (Exception e) {
100+
logger.error(e, e);
65101
}
66-
} catch (Exception e) {
67-
logger.error(e, e);
68102
}
69-
}
70-
});
103+
});
71104

72105
return result;
73106
}
@@ -76,7 +109,9 @@ private String getPackageByFile(String path) {
76109
try {
77110
Class clazz = Class.forName(path);
78111
return clazz.getPackage().getName();
79-
} catch (ExceptionInInitializerError | ClassNotFoundException | NoClassDefFoundError ex) {
112+
} catch (ExceptionInInitializerError |
113+
ClassNotFoundException |
114+
NoClassDefFoundError ex) {
80115
return null;
81116
}
82117
}

0 commit comments

Comments
 (0)