Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Optional<String>> artifactIdCacheMap = new ConcurrentHashMap<>();

static File searchPomProperties(File dirOrFile) {
Expand Down Expand Up @@ -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)) {
Copy link
Collaborator

@lvjing2 lvjing2 Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 先确认下 jar_unpack 路径产生的时机是什么?
  2. 单独对 jar_unpack 逻辑定制处理是否合理?
  3. 这个路径文件,不去clean prefix、suffix,但后面的 parseArtifactId 逻辑还会执行,会有什么不同?为何不直接返回。
  4. 函数里对 IOException 做过处理,对 File must exist 异常也可以做下处理。
image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

master代码里面似乎之前针对这里做过一些处理,针对.jar 为结尾的jarLocation做的处理

上述问题发生时机为安装biz的时候,默认会选择unpack,从unpack中加载资源,2.1 之前没有问题,3.x中新增了截图中的逻辑,但是unpakc的路径 是jar_unpack_XX ,导致找资源失败,从而导致安装biz模块失败,这里是加载biz模块的逻辑,失败了再做其他处理也没什么意义,可以看看master中 有
if (jarLocation.contains(JAR_SUFFIX)) { jarLocation = jarLocation.substring(0, jarLocation.lastIndexOf(JAR_SUFFIX) + JAR_SUFFIX.length()); }

 这样的逻辑是否合理

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

master代码里面似乎之前针对这里做过一些处理,针对.jar 为结尾的jarLocation做的处理

上述问题发生时机为安装biz的时候,默认会选择unpack,从unpack中加载资源,2.1 之前没有问题,3.x中新增了截图中的逻辑,但是unpakc的路径 是jar_unpack_XX ,导致找资源失败,从而导致安装biz模块失败,这里是加载biz模块的逻辑,失败了再做其他处理也没什么意义,可以看看master中 有
if (jarLocation.contains(JAR_SUFFIX)) { jarLocation = jarLocation.substring(0, jarLocation.lastIndexOf(JAR_SUFFIX) + JAR_SUFFIX.length()); }

 这样的逻辑是否合理

// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading