Skip to content

Commit

Permalink
the packageURL is startWith 'file:' when client is a file in target (…
Browse files Browse the repository at this point in the history
…unit test)
  • Loading branch information
wkclz committed Jan 3, 2024
1 parent de71d98 commit f69bd5e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions util/src/main/java/io/kubernetes/client/util/ModelMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -486,17 +486,26 @@ private static List<String> getClassNamesFromPackage(ClassLoader classLoader, St

private static void processJarPackage(URL packageURL, String packageName, String pkg, ArrayList<String> names) throws IOException {
String jarFileName = URLDecoder.decode(packageURL.getFile(), "UTF-8");
if (!jarFileName.startsWith("jar:") && !jarFileName.startsWith("nested:")) {
JarFile jf = null;
// jar: client in repository; nested: client in a fat jar
if (jarFileName.startsWith("jar:") || jarFileName.startsWith("nested:")) {
jf = ((JarURLConnection) packageURL.openConnection()).getJarFile();
}
// file: client is a file in target (unit test)
if (jarFileName.startsWith("file:") ) {
jarFileName = jarFileName.substring(5, jarFileName.indexOf("!"));
jf = new JarFile(jarFileName);
}
if (jf == null) {
logger.error("Loading classes from jar with error packageURL: {}", jarFileName);
return;
}
logger.info("Loading classes from jar {}", jarFileName);
try (JarFile jf = ((JarURLConnection) packageURL.openConnection()).getJarFile()) {
Enumeration<JarEntry> jarEntries = jf.entries();
while (jarEntries.hasMoreElements()) {
processJarEntry(jarEntries.nextElement(), packageName, pkg, names);
}
Enumeration<JarEntry> jarEntries = jf.entries();
while (jarEntries.hasMoreElements()) {
processJarEntry(jarEntries.nextElement(), packageName, pkg, names);
}
jf.close();
}

private static void processJarEntry(JarEntry jarEntry, String packageName, String pkg, ArrayList<String> names) {
Expand Down

0 comments on commit f69bd5e

Please sign in to comment.