Skip to content

Commit

Permalink
Merge pull request #2952 from wkclz/patch-1
Browse files Browse the repository at this point in the history
#2241 fix bug: when running with a fat jar, need to read entries with openConnection
  • Loading branch information
k8s-ci-robot authored Jan 8, 2024
2 parents f8f6ca6 + f69bd5e commit 65b3f8f
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 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 @@ -22,6 +22,7 @@
import java.io.File;

import java.io.IOException;
import java.net.JarURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLDecoder;
Expand Down Expand Up @@ -485,14 +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");
jarFileName = jarFileName.substring(5, jarFileName.indexOf("!"));
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 = new JarFile(jarFileName)) {
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 65b3f8f

Please sign in to comment.