Skip to content

Commit f202378

Browse files
committed
[6.0.10][publish] fix persistent-container & update env
1 parent 473e24e commit f202378

File tree

27 files changed

+428
-501
lines changed

27 files changed

+428
-501
lines changed

build.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ subprojects {
2727

2828
dependencies {
2929
compileOnly(kotlin("stdlib"))
30-
compileOnly(kotlin("reflect"))
3130
}
3231

3332
java {

common/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dependencies {
44
implementation("org.ow2.asm:asm:9.4")
55
implementation("org.ow2.asm:asm-util:9.4")
66
implementation("org.ow2.asm:asm-commons:9.4")
7-
implementation("me.lucko:jar-relocator:1.5")
7+
implementation("com.github.bkm016:jar-relocator:1.7-R2")
88
implementation("org.tabooproject.reflex:reflex:1.0.19")
99
implementation("org.tabooproject.reflex:analyser:1.0.19")
1010
}
@@ -16,7 +16,7 @@ tasks {
1616
include(dependency("org.ow2.asm:asm:9.4"))
1717
include(dependency("org.ow2.asm:asm-util:9.4"))
1818
include(dependency("org.ow2.asm:asm-commons:9.4"))
19-
include(dependency("me.lucko:jar-relocator:1.5"))
19+
include(dependency("com.github.bkm016:jar-relocator:1.7-R2"))
2020
include(dependency("org.tabooproject.reflex:reflex:1.0.19"))
2121
include(dependency("org.tabooproject.reflex:analyser:1.0.19"))
2222
}

common/src/main/java/taboolib/common/env/AbstractXmlParser.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@ protected static String find(String name, Element node) throws ParseException {
7575
*
7676
* @param name The name of the node to search for
7777
* @param node The node to search inside of
78-
* @param def The default value, or <code>null</code> if the value is
79-
* required
80-
* @return The text content of the node it found, or <code>def</code> if the
81-
* node is not found
78+
* @param def The default value, or <code>null</code> if the value is required
79+
* @return The text content of the node it found, or <code>def</code> if the node is not found
8280
* @throws ParseException If the node cannot be found and there is no default value
8381
* @since 1.0.0
8482
*/

common/src/main/java/taboolib/common/env/ClassAppender.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
* @since 2020-04-12 22:39
1919
*/
2020
public class ClassAppender {
21+
2122
static MethodHandles.Lookup lookup;
2223
static Unsafe unsafe;
23-
2424

2525
static {
2626
try {
@@ -81,7 +81,6 @@ else if (loader.getClass().getName().equals("net.minecraft.launchwrapper.LaunchC
8181
} catch (Throwable t) {
8282
t.printStackTrace();
8383
}
84-
8584
return null;
8685
}
8786

common/src/main/java/taboolib/common/env/Dependency.java

+98-84
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package taboolib.common.env;
22

3+
import org.jetbrains.annotations.Nullable;
34
import org.w3c.dom.Element;
45

56
import java.io.File;
7+
import java.io.IOException;
8+
import java.net.MalformedURLException;
9+
import java.net.URL;
610
import java.text.ParseException;
11+
import java.util.Collection;
712
import java.util.Objects;
813

914
/**
@@ -16,121 +21,110 @@
1621
public class Dependency extends AbstractXmlParser {
1722

1823
/**
19-
* A placeholder string for when the version has not been specified
20-
*
21-
* @since 1.0.0
24+
* 当版本尚未指定时的占位符字符串
2225
*/
2326
private static final String LATEST_VERSION = "latest";
2427

2528
/**
26-
* The ID of the group for this dependency
27-
*
28-
* @since 1.0.0
29+
* 此依赖项的组 ID
2930
*/
3031
private final String groupId;
3132

3233
/**
33-
* The ID of the artifact for this dependency
34-
*
35-
* @since 1.0.0
34+
* 此依赖项的工件 ID
3635
*/
3736
private final String artifactId;
37+
3838
/**
39-
* The scope of the dependency
40-
*
41-
* @since 1.0.0
39+
* 依赖项的范围
4240
*/
4341
private final DependencyScope scope;
42+
4443
/**
45-
* The version of the artifact to download, or
46-
* {@link Dependency#LATEST_VERSION} if it is not specified in the pom
47-
*
48-
* @since 1.0.0
44+
* 要下载的版本,或者如果在 pom 中没有指定依赖项的最新版本,则设置依赖项的最新版本
4945
*/
5046
private String version;
5147

52-
/**
53-
* Creates a new dependency
54-
*
55-
* @param groupId The group ID
56-
* @param artifactId The artifact ID
57-
* @param version The version to download
58-
* @param scope The scope
59-
* @since 1.0.0
60-
*/
6148
public Dependency(String groupId, String artifactId, String version, DependencyScope scope) {
6249
this.groupId = groupId;
6350
this.artifactId = artifactId;
6451
this.version = version.contains("$") || version.contains("[") || version.contains("(") ? LATEST_VERSION : version;
6552
this.scope = scope;
6653
}
6754

68-
/**
69-
* Creates a new dependency from the specified element in the pom
70-
*
71-
* @param node The element to create the dependency from
72-
* @throws ParseException If the xml could not be parsed
73-
* @since 1.0.0
74-
*/
7555
public Dependency(Element node) throws ParseException {
7656
this(find("groupId", node), find("artifactId", node), find("version", node, LATEST_VERSION), DependencyScope.valueOf(find("scope", node, "runtime").toUpperCase()));
7757
}
7858

7959
/**
80-
* Gets the ID of the group for this dependency
81-
*
82-
* @return The group ID
83-
* @since 1.0.0
60+
* 获取依赖的下载地址
8461
*/
85-
public String getGroupId() {
86-
return groupId;
62+
public URL getURL(Repository repo, String ext) throws MalformedURLException {
63+
String name = String.format("%s-%s.%s", getArtifactId(), getVersion(), ext);
64+
return new URL(String.format("%s/%s/%s/%s/%s", repo.getUrl(), getGroupId().replace('.', '/'), getArtifactId(), getVersion(), name));
8765
}
8866

8967
/**
90-
* Gets the ID of the artifact for this dependency
91-
*
92-
* @return The artifact ID
93-
* @since 1.0.0
68+
* 检查依赖项的版本
69+
* 如果版本尚未指定,则尝试从仓库中获取最新版本
9470
*/
95-
public String getArtifactId() {
96-
return artifactId;
97-
}
98-
99-
/**
100-
* Gets the version of the artifact to download
101-
*
102-
* @return The version, or <code>null</code> if the latest version should be
103-
* downloaded and the latest version has not been determined yet
104-
* @since 1.0.0
105-
*/
106-
public String getVersion() {
107-
return version.equals(LATEST_VERSION) ? null : version;
71+
public void checkVersion(Collection<Repository> repositories, File baseDir) throws IOException {
72+
if (getVersion() == null) {
73+
// 获取本地最新版本
74+
DependencyVersion installedLatestVersion = getInstalledLatestVersion(baseDir);
75+
// 是否检查更新
76+
boolean checkUpdate = false;
77+
// 本地版本不存在
78+
if (installedLatestVersion == null) {
79+
checkUpdate = true;
80+
}
81+
// 2022/3/31
82+
// HikariCP 引用的 slf4j 为 latest 版本,因此每次开服都会尝试从仓库中获取最新版本
83+
else if (VersionChecker.isOutdated()) {
84+
checkUpdate = true;
85+
VersionChecker.updateCheckTime();
86+
}
87+
IOException e = null;
88+
if (checkUpdate) {
89+
// 尝试从仓库中获取最新版本
90+
for (Repository repo : repositories) {
91+
try {
92+
repo.getLatestVersion(this);
93+
e = null;
94+
break;
95+
} catch (IOException ex) {
96+
e = new IOException(String.format("Unable to find latest version of %s", this), ex);
97+
}
98+
}
99+
if (e != null) {
100+
throw e;
101+
}
102+
} else {
103+
setVersion(installedLatestVersion.toString());
104+
}
105+
}
108106
}
109107

110108
/**
111-
* Sets the latest version of this dependency
112-
*
113-
* @param version The latest version
114-
* @throws IllegalStateException If this dependency has a specific version already
115-
* @since 1.0.0
109+
* Get the latest version of this artifact that are currently
110+
* downloaded on this computer
116111
*/
117-
public void setVersion(String version) {
118-
if (!this.version.equals(LATEST_VERSION)) {
119-
throw new IllegalStateException("Version is already resolved");
120-
} else if (version.equals(LATEST_VERSION)) {
121-
throw new IllegalArgumentException("Cannot set version to the latest");
122-
} else {
123-
this.version = version;
112+
@Nullable
113+
public DependencyVersion getInstalledLatestVersion(File baseDir) {
114+
DependencyVersion max = null;
115+
for (DependencyVersion ver : getInstalledVersions(baseDir)) {
116+
if (max == null || ver.compareTo(max) > 0) {
117+
max = ver;
118+
}
124119
}
120+
return max;
125121
}
126122

127123
/**
128-
* Gets a list of all of the versions of this artifact that are currently
124+
* Gets a list of all the versions of this artifact that are currently
129125
* downloaded on this computer
130126
*
131-
* @param dir The directory to store downloaded artifacts in
132127
* @return An array of the versions that are already downloaded
133-
* @since 1.0.0
134128
*/
135129
public DependencyVersion[] getInstalledVersions(File dir) {
136130
for (String part : getGroupId().split("\\.")) {
@@ -148,26 +142,17 @@ public DependencyVersion[] getInstalledVersions(File dir) {
148142
return versions;
149143
}
150144

151-
/**
152-
* Gets the scope of this dependency
153-
*
154-
* @return The scope
155-
* @since 1.0.0
156-
*/
157-
public DependencyScope getScope() {
158-
return scope;
159-
}
160-
161145
/**
162146
* Gets the file that the downloaded artifact should be stored in
163147
*
164148
* @param dir The directory to store downloaded artifacts in
165-
* @param ext The file extension to download (should be either
166-
* <code>"jar"</code> or <code>"pom"</code>
149+
* @param ext The file extension to download (should be either <code>"jar"</code> or <code>"pom"</code>)
167150
* @return The file to download into
168-
* @since 1.0.0
169151
*/
170-
public File getFile(File dir, String ext) {
152+
public File findFile(File dir, String ext) {
153+
if (getVersion() == null) {
154+
throw new IllegalStateException("Version is not resolved: " + this);
155+
}
171156
for (String part : getGroupId().split("\\.")) {
172157
dir = new File(dir, part);
173158
}
@@ -177,6 +162,35 @@ public File getFile(File dir, String ext) {
177162
return dir;
178163
}
179164

165+
/**
166+
* Sets the version of this dependency
167+
*/
168+
public void setVersion(String version) {
169+
if (!this.version.equals(LATEST_VERSION)) {
170+
throw new IllegalStateException("Version is already resolved");
171+
} else if (version.equals(LATEST_VERSION)) {
172+
throw new IllegalArgumentException("Cannot set version to the latest");
173+
} else {
174+
this.version = version;
175+
}
176+
}
177+
178+
public String getGroupId() {
179+
return groupId;
180+
}
181+
182+
public String getArtifactId() {
183+
return artifactId;
184+
}
185+
186+
public String getVersion() {
187+
return version.equals(LATEST_VERSION) ? null : version;
188+
}
189+
190+
public DependencyScope getScope() {
191+
return scope;
192+
}
193+
180194
@Override
181195
public String toString() {
182196
return String.format("%s:%s:%s", groupId, artifactId, version);

0 commit comments

Comments
 (0)