diff --git a/sofa-ark-parent/core-impl/archive/src/main/java/com/alipay/sofa/ark/loader/jar/JarUtils.java b/sofa-ark-parent/core-impl/archive/src/main/java/com/alipay/sofa/ark/loader/jar/JarUtils.java index 1eadfcf01..589edb505 100644 --- a/sofa-ark-parent/core-impl/archive/src/main/java/com/alipay/sofa/ark/loader/jar/JarUtils.java +++ b/sofa-ark-parent/core-impl/archive/src/main/java/com/alipay/sofa/ark/loader/jar/JarUtils.java @@ -60,6 +60,8 @@ public class JarUtils { public static final String JAR_SUFFIX = ".jar"; + public static final String JAR_UNPACK = ".jar-unpack/"; + private static final Map> artifactIdCacheMap = new ConcurrentHashMap<>(); static File searchPomProperties(File dirOrFile) { @@ -152,11 +154,14 @@ public static String parseArtifactId(String jarLocation) { // 9. if is ark plugin, then return null to set declared default // clean the jar location prefix and suffix - if (jarLocation.contains(JAR_SUFFIX)) { - jarLocation = jarLocation.substring(0, jarLocation.lastIndexOf(JAR_SUFFIX) + JAR_SUFFIX.length()); - } - if (jarLocation.startsWith("file:")) { - jarLocation = jarLocation.substring("file:".length()); + if (!jarLocation.endsWith(JAR_UNPACK)) { + // clean the jar location prefix and suffix + if (jarLocation.contains(JAR_SUFFIX)) { + jarLocation = jarLocation.substring(0, jarLocation.lastIndexOf(JAR_SUFFIX) + JAR_SUFFIX.length()); + } + if (jarLocation.startsWith("file:")) { + jarLocation = jarLocation.substring("file:".length()); + } } // modify the path to suit WindowsOS diff --git a/sofa-ark-parent/core-impl/archive/src/test/java/com/alipay/sofa/ark/loader/test/jar/JarUtilsTest.java b/sofa-ark-parent/core-impl/archive/src/test/java/com/alipay/sofa/ark/loader/test/jar/JarUtilsTest.java index d618e0587..680ac74ef 100644 --- a/sofa-ark-parent/core-impl/archive/src/test/java/com/alipay/sofa/ark/loader/test/jar/JarUtilsTest.java +++ b/sofa-ark-parent/core-impl/archive/src/test/java/com/alipay/sofa/ark/loader/test/jar/JarUtilsTest.java @@ -194,4 +194,12 @@ public void testParseArtifactIdFromJarInJarInJarMore() { + "!/BOOT-INF/lib/example-client-2.0.0.jar!/BOOT-INF/lib/example-client-3.0.0.jar!/"); assertEquals("example-client", artifactId1); } + + @Test + public void testParseArtifactIdFromPackJar() { + URL resourceUrl = JarUtilsTest.class.getResource("/biz-1.0.0-ark-biz.jar-unpack"); + String filePath = resourceUrl.getFile() + "/"; + String artifactId1 = parseArtifactId(filePath); + assertEquals("sofa-ark-archive", artifactId1); + } }