Skip to content

Commit

Permalink
[6.1.0][dev] 统一重定向的转义方式
Browse files Browse the repository at this point in the history
  • Loading branch information
Bkm016 committed Jan 27, 2024
1 parent 8ffd475 commit a758ba4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
15 changes: 6 additions & 9 deletions common-env/src/main/java/taboolib/common/env/RuntimeEnv.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import taboolib.common.ClassAppender;
import taboolib.common.PrimitiveIO;
import taboolib.common.PrimitiveSettings;
import taboolib.common.TabooLib;
import taboolib.common.*;

import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -18,7 +15,7 @@
import java.util.List;
import java.util.zip.ZipFile;

import static taboolib.common.PrimitiveSettings.KOTLINX_VERSION;
import static taboolib.common.PrimitiveSettings.KOTLIN_COROUTINES_VERSION;
import static taboolib.common.PrimitiveSettings.KOTLIN_VERSION;

/**
Expand All @@ -31,7 +28,7 @@
public class RuntimeEnv {

public static final String KOTLIN_ID = "!kotlin".substring(1);
public static final String KOTLINX_ID = "!kotlinx.coroutines".substring(1);
public static final String KOTLIN_COROUTINES_ID = "!kotlinx.coroutines".substring(1);

public static final RuntimeEnv ENV = new RuntimeEnv();

Expand All @@ -49,13 +46,13 @@ static void init() throws Throwable {
}
// 启用 Kotlin 重定向
if (!PrimitiveSettings.SKIP_KOTLIN_RELOCATE) {
rel.add(new JarRelocation(KOTLIN_ID + ".", KOTLIN_ID + KOTLIN_VERSION.replace(".", "") + "."));
rel.add(new JarRelocation(KOTLINX_ID + ".", KOTLINX_ID + KOTLINX_VERSION.replace(".", "") + "."));
rel.add(new JarRelocation(KOTLIN_ID + ".", KOTLIN_ID + PrimitiveLoader.formatVersion(KOTLIN_VERSION) + "."));
rel.add(new JarRelocation(KOTLIN_COROUTINES_ID + ".", KOTLIN_COROUTINES_ID + PrimitiveLoader.formatVersion(KOTLIN_COROUTINES_VERSION) + "."));
}
}
// 加载 Kotlin 环境
if (!KOTLIN_VERSION.equals("null")) ENV.loadDependency("org.jetbrains.kotlin:kotlin-stdlib:" + KOTLIN_VERSION, rel);
if (!KOTLINX_VERSION.equals("null")) ENV.loadDependency("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:" + KOTLINX_VERSION, false, rel);
if (!KOTLIN_COROUTINES_VERSION.equals("null")) ENV.loadDependency("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:" + KOTLIN_COROUTINES_VERSION, false, rel);
}

public void inject(@NotNull Class<?> clazz) throws Throwable {
Expand Down
14 changes: 9 additions & 5 deletions common/src/main/java/taboolib/common/PrimitiveLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ public static void loadFile(File file, boolean isIsolated, boolean isExternal, S
// 在非隔离模式下进行 Kotlin 重定向
if (!IS_ISOLATED_MODE && !SKIP_KOTLIN_RELOCATE) {
String kt = "!kotlin".substring(1);
String ktx = "!kotlinx.coroutines".substring(1);
String kv = KOTLIN_VERSION.replace(".", "");
String kvx = KOTLINX_VERSION.replace(".", "");
String ktc = "!kotlinx.coroutines".substring(1);
String kv = formatVersion(KOTLIN_VERSION);
String kvc = formatVersion(KOTLIN_COROUTINES_VERSION);
rel.add(new Relocation(kt + ".", kt + kv + "."));
rel.add(new Relocation(ktx + ".", ktx + kvx + "."));
rel.add(new Relocation(ktc + ".", ktc + kvc + "."));
}
// 是否重定向
if (!rel.isEmpty()) {
String hash = PrimitiveIO.getHash(file.getName() + Arrays.deepHashCode(relocate) + KOTLIN_VERSION + KOTLINX_VERSION);
String hash = PrimitiveIO.getHash(file.getName() + Arrays.deepHashCode(relocate) + KOTLIN_VERSION + KOTLIN_COROUTINES_VERSION);
jar = new File(getCacheFile(), hash + ".jar");
if ((!jar.exists() && jar.length() == 0) || IS_FORCE_DOWNLOAD_IN_DEV_MODE) {
PrimitiveIO.println("Relocating ...");
Expand Down Expand Up @@ -206,4 +206,8 @@ private static File getLibraryFile() {
}
return file;
}

public static String formatVersion(String str) {
return str.replaceAll("[._-]", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class PrimitiveSettings {
/**
* Kotlinx 版本
*/
public static final String KOTLINX_VERSION = VERSION_PROPERTIES.getProperty("!kotlin-coroutines".substring(1), "1.7.3");
public static final String KOTLIN_COROUTINES_VERSION = VERSION_PROPERTIES.getProperty("!kotlin-coroutines".substring(1), "1.7.3");

/**
* TabooLib 版本
Expand Down

0 comments on commit a758ba4

Please sign in to comment.