Skip to content

Commit 5e6377f

Browse files
authored
GH-945 Fix relocation updates. Support BOM dependency. Improve resolving dependencies (#946)
* Fix relocation updates * More fixes * Run dependency scanner in parallel * Close ExecutorService
1 parent 47a44b7 commit 5e6377f

18 files changed

+311
-393
lines changed

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ object Versions {
1212
const val GIT_CHECK = "1.0.0"
1313

1414
const val PAPERLIB = "1.0.8"
15-
const val ADVENTURE_PLATFORM = "4.3.4"
16-
const val ADVENTURE_TEXT_MINIMESSAGE = "4.19.0"
17-
const val ADVENTURE_PLATFORM_FACET = "4.3.4"
15+
const val ADVENTURE_TEXT_MINIMESSAGE = "4.21.0"
16+
const val ADVENTURE_PLATFORM = "4.4.0"
1817
const val CDN_CONFIGS = "1.14.6"
1918

2019
const val MARIA_DB = "3.5.2"

buildSrc/src/main/kotlin/eternalcode-java-test.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies {
1515

1616
testImplementation("org.mockito:mockito-core:${Versions.MOCKITO_CORE}")
1717
testImplementation("net.kyori:adventure-platform-bukkit:${Versions.ADVENTURE_PLATFORM}")
18-
testImplementation("net.kyori:adventure-platform-facet:${Versions.ADVENTURE_PLATFORM_FACET}")
18+
testImplementation("net.kyori:adventure-platform-facet:${Versions.ADVENTURE_PLATFORM}")
1919
testImplementation("net.kyori:adventure-text-minimessage:${Versions.ADVENTURE_TEXT_MINIMESSAGE}")
2020
}
2121

eternalcore-core/build.gradle.kts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,14 @@ dependencies {
2222
compileOnly("org.projectlombok:lombok:${Versions.LOMBOK}")
2323
annotationProcessor("org.projectlombok:lombok:${Versions.LOMBOK}")
2424

25-
// GitCheck
26-
implementation("com.eternalcode:gitcheck:${Versions.GIT_CHECK}")
27-
28-
implementation("net.kyori:adventure-platform-bukkit:${Versions.ADVENTURE_PLATFORM}")
29-
implementation("net.kyori:adventure-text-minimessage:${Versions.ADVENTURE_TEXT_MINIMESSAGE}")
30-
3125
testImplementation("com.eternalcode:eternalcode-commons-bukkit:${Versions.ETERNALCODE_COMMONS}")
3226
}
3327

3428
eternalShadow {
3529
// Paper and Adventure libraries
3630
library("io.papermc:paperlib:${Versions.PAPERLIB}")
31+
library("net.kyori:adventure-text-minimessage:${Versions.ADVENTURE_TEXT_MINIMESSAGE}")
32+
library("net.kyori:adventure-platform-bukkit:${Versions.ADVENTURE_PLATFORM}")
3733
libraryRelocate(
3834
"io.papermc.lib",
3935
"net.kyori",
@@ -53,11 +49,13 @@ eternalShadow {
5349
"com.eternalcode.multification",
5450
)
5551

56-
// EternalCode Commons
52+
// EternalCode Commons & GitCheck
5753
library("com.eternalcode:eternalcode-commons-bukkit:${Versions.ETERNALCODE_COMMONS}")
5854
library("com.eternalcode:eternalcode-commons-adventure:${Versions.ETERNALCODE_COMMONS}")
55+
library("com.eternalcode:gitcheck:${Versions.GIT_CHECK}")
5956
libraryRelocate(
6057
"com.eternalcode.commons",
58+
"com.eternalcode.gitcheck",
6159
)
6260

6361
// database
@@ -72,7 +70,7 @@ eternalShadow {
7270
"com.j256.ormlite",
7371
"org.mariadb.jdbc",
7472
"org.postgresql",
75-
"com.h2database",
73+
"com.h2",
7674
)
7775

7876
// command framework & skull library

eternalcore-plugin/build.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ eternalShadowCompiler {
2626
exclude(
2727
"META-INF/**",
2828
)
29-
30-
// dependsOn(":eternalcore-core:test")
31-
// dependsOn(":eternalcore-core:checkstyleMain")
3229
}
3330
}
3431

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/EternalCoreLoader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public void onEnable() {
1717

1818
this.dependencyLoader = new DependencyLoaderImpl(this.getLogger(), this.getDataFolder(), EternalCoreLoaderConstants.repositories());
1919
this.dependencyLoader.load(
20-
new IsolatedClassAccessorLoader(pluginLoader),
21-
EternalCoreLoaderConstants.dependencies(),
22-
EternalCoreLoaderConstants.relocations()
20+
new IsolatedClassAccessorLoader(pluginLoader),
21+
EternalCoreLoaderConstants.dependencies(),
22+
EternalCoreLoaderConstants.relocations()
2323
);
2424

2525
this.eternalCore = EternalCoreWrapper.create(pluginLoader);

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/EternalCoreLoaderConstants.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ public static List<Relocation> relocations() {
5555

5656
private static List<Relocation> createRelocations() {
5757
return Arrays.stream(RELOCATIONS_HOLDER.split("\\|"))
58-
.map(rawRelocation -> Relocation.builder()
59-
.pattern(rawRelocation)
60-
.relocatedPattern(RELOCATION_PREFIX + rawRelocation)
61-
.build()
62-
)
58+
.map(rawRelocation -> new Relocation(rawRelocation, RELOCATION_PREFIX + rawRelocation))
6359
.toList();
6460
}
6561

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/Dependency.java

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,59 +11,53 @@ public class Dependency {
1111

1212
private static final Pattern VERSION_PATTERN = Pattern.compile("(?<major>[0-9]+)\\.(?<minor>[0-9]+)\\.?(?<patch>[0-9]?)(-(?<label>[-+.a-zA-Z0-9]+))?");
1313

14-
private static final String JAR_MAVEN_FORMAT = "%s/%s/%s/%s/%s-%s.jar";
15-
private static final String JAR_MAVEN_FORMAT_WITH_CLASSIFIER = "%s/%s/%s/%s/%s-%s-%s.jar";
16-
private static final String POM_XML_FORMAT = "%s/%s/%s/%s/%s-%s.pom";
14+
private static final String PATH_FORMAT = "%s/%s/%s/%s/%s";
15+
private static final String JAR_MAVEN_FORMAT = "%s-%s.jar";
16+
private static final String JAR_MAVEN_FORMAT_WITH_CLASSIFIER = "%s-%s-%s.jar";
17+
private static final String POM_XML_FORMAT = "%s-%s.pom";
1718

1819
private final String groupId;
1920
private final String artifactId;
2021
private final String version;
22+
private final boolean isBom;
2123

2224
private Dependency(String groupId, String artifactId, String version) {
25+
this(groupId, artifactId, version, false);
26+
}
27+
28+
private Dependency(String groupId, String artifactId, String version, boolean isBom) {
2329
this.groupId = groupId;
2430
this.artifactId = artifactId;
2531
this.version = version;
32+
this.isBom = isBom;
2633
}
2734

28-
public ResourceLocator toMavenJar(Repository repository, String classifier) {
29-
String url = String.format(
30-
JAR_MAVEN_FORMAT_WITH_CLASSIFIER,
31-
repository.url(),
32-
this.groupId.replace(".", "/"),
33-
this.artifactId,
34-
this.version,
35-
this.artifactId,
36-
this.version,
37-
classifier
38-
);
39-
40-
return ResourceLocator.fromString(url);
35+
public boolean isBom() {
36+
return this.isBom;
4137
}
4238

4339
public ResourceLocator toMavenJar(Repository repository) {
44-
String url = String.format(JAR_MAVEN_FORMAT,
45-
repository.url(),
46-
this.groupId.replace(".", "/"),
47-
this.artifactId,
48-
this.version,
49-
this.artifactId,
50-
this.version
51-
);
40+
return toResource(repository, JAR_MAVEN_FORMAT.formatted(this.artifactId, this.version));
41+
}
5242

53-
return ResourceLocator.fromString(url);
43+
public ResourceLocator toMavenJar(Repository repository, String classifier) {
44+
return toResource(repository, JAR_MAVEN_FORMAT_WITH_CLASSIFIER.formatted(this.artifactId, this.version, classifier));
5445
}
5546

5647
public ResourceLocator toPomXml(Repository repository) {
57-
String url = String.format(POM_XML_FORMAT,
48+
return toResource(repository, POM_XML_FORMAT.formatted(this.artifactId, this.version));
49+
}
50+
51+
public ResourceLocator toResource(Repository repository, String fileName) {
52+
String url = String.format(PATH_FORMAT,
5853
repository.url(),
5954
this.groupId.replace(".", "/"),
6055
this.artifactId,
6156
this.version,
62-
this.artifactId,
63-
this.version
57+
fileName
6458
);
6559

66-
return ResourceLocator.fromString(url);
60+
return ResourceLocator.from(url);
6761
}
6862

6963
public String getGroupId() {
@@ -86,22 +80,22 @@ public boolean isNewerThan(Dependency dependency) {
8680
int thisMajor = this.getMajorVersion();
8781
int dependencyMajor = dependency.getMajorVersion();
8882

89-
if (thisMajor > dependencyMajor) {
90-
return true;
83+
if (thisMajor != dependencyMajor) {
84+
return thisMajor > dependencyMajor;
9185
}
9286

9387
int thisMinor = this.getMinorVersion();
9488
int dependencyMinor = dependency.getMinorVersion();
9589

96-
if (thisMinor > dependencyMinor) {
97-
return true;
90+
if (thisMinor != dependencyMinor) {
91+
return thisMinor > dependencyMinor;
9892
}
9993

10094
int thisPatch = this.getPatchVersion();
10195
int dependencyPatch = dependency.getPatchVersion();
10296

103-
if (thisPatch > dependencyPatch) {
104-
return true;
97+
if (thisPatch != dependencyPatch) {
98+
return thisPatch > dependencyPatch;
10599
}
106100

107101
return false;
@@ -167,12 +161,19 @@ public static Dependency of(String groupId, String artifactId, String version) {
167161
if (version.contains("${")) {
168162
throw new IllegalArgumentException("Version contains a property placeholder: " + version);
169163
}
170-
171164
return new Dependency(rewriteEscaping(groupId), rewriteEscaping(artifactId), rewriteEscaping(version));
172165
}
173166

174167
private static String rewriteEscaping(String value) {
175168
return value.replace("{}", ".");
176169
}
177170

171+
public Dependency asNotBom() {
172+
return new Dependency(this.groupId, this.artifactId, this.version, false);
173+
}
174+
175+
public Dependency asBom() {
176+
return new Dependency(this.groupId, this.artifactId, this.version, true);
177+
}
178+
178179
}
Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
11
package com.eternalcode.core.loader.dependency;
22

33
import java.util.Collection;
4-
import java.util.Collections;
54
import java.util.LinkedHashMap;
65

76
public class DependencyCollector {
87

98
private final LinkedHashMap<String, Dependency> fullScannedDependencies = new LinkedHashMap<>();
109

11-
public boolean hasScannedDependency(Dependency dependency) {
12-
return this.fullScannedDependencies.containsKey(dependency.getGroupArtifactId());
10+
public synchronized boolean hasScannedDependency(Dependency dependency) {
11+
Dependency scanned = this.fullScannedDependencies.get(dependency.getGroupArtifactId());
12+
if (scanned == null) {
13+
return false;
14+
}
15+
16+
if (scanned.isBom() && !dependency.isBom()) {
17+
return false;
18+
}
19+
20+
return scanned.getVersion().equals(dependency.getVersion()) || scanned.isNewerThan(dependency);
1321
}
1422

15-
public void addScannedDependency(Dependency dependency) {
23+
public synchronized Dependency addScannedDependency(Dependency dependency) {
1624
Dependency current = this.fullScannedDependencies.get(dependency.getGroupArtifactId());
1725

1826
if (current == null) {
1927
this.fullScannedDependencies.put(dependency.getGroupArtifactId(), dependency);
20-
return;
28+
return dependency;
2129
}
2230

23-
if (dependency.isNewerThan(current)) {
24-
this.fullScannedDependencies.put(dependency.getGroupArtifactId(), dependency);
31+
if (!current.isBom() || !dependency.isBom()) {
32+
current = current.asNotBom();
33+
dependency = dependency.asNotBom();
2534
}
35+
36+
Dependency resolved = dependency.isNewerThan(current) ? dependency : current;
37+
this.fullScannedDependencies.put(dependency.getGroupArtifactId(), resolved);
38+
return resolved;
2639
}
2740

2841
public void addScannedDependencies(Collection<Dependency> dependencies) {
@@ -31,8 +44,10 @@ public void addScannedDependencies(Collection<Dependency> dependencies) {
3144
}
3245
}
3346

34-
public Collection<Dependency> getScannedDependencies() {
35-
return Collections.unmodifiableCollection(this.fullScannedDependencies.values());
47+
public synchronized Collection<Dependency> getScannedDependencies() {
48+
return this.fullScannedDependencies.values().stream()
49+
.filter(dependency -> !dependency.isBom())
50+
.toList();
3651
}
3752

3853
}

eternalcore-plugin/src/main/java/com/eternalcode/core/loader/dependency/DependencyLoader.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
import com.eternalcode.core.loader.classloader.IsolatedClassLoader;
44
import com.eternalcode.core.loader.relocation.Relocation;
55

6-
import java.net.URL;
76
import java.util.List;
87

98
public interface DependencyLoader extends AutoCloseable {
109

1110
DependencyLoadResult load(List<Dependency> dependencies, List<Relocation> relocations);
1211

13-
DependencyLoadResult load(ClassLoader pattern, List<Dependency> dependencies, List<Relocation> relocations, URL... urls);
14-
1512
DependencyLoadResult load(IsolatedClassLoader loader, List<Dependency> dependencies, List<Relocation> relocations);
1613

1714
@Override

0 commit comments

Comments
 (0)