Skip to content

Commit 04733e4

Browse files
committed
chore: update from api-13 changes
2 parents c0c06c8 + 1fff094 commit 04733e4

File tree

59 files changed

+1116
-1992
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1116
-1992
lines changed

.github/workflows/check-spotless.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ jobs:
1111
uses: SpongePowered/.github/.github/workflows/shared-check-spotless.yaml@master
1212
with:
1313
runtime_version: 21
14-
extra_gradle_params: "-Pprojects=vanilla,forge,neoforge,testplugins"
14+
extra_gradle_params: "-Pprojects=vanilla,neoforge,testplugins"
1515
secrets: inherit

build-logic/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
indra {
77
javaVersions {
88
strictVersions(false) // it's just buildscript, no need for anything fancy
9+
target(17)
910
}
1011
}
1112

build-logic/src/main/java/org/spongepowered/gradle/impl/OutputDependenciesToJson.java

+21-71
Original file line numberDiff line numberDiff line change
@@ -54,35 +54,20 @@
5454
import java.util.HashSet;
5555
import java.util.List;
5656
import java.util.Map;
57-
import java.util.Objects;
5857
import java.util.Set;
5958
import java.util.TreeMap;
6059
import java.util.stream.Collectors;
6160

6261
public abstract class OutputDependenciesToJson extends DefaultTask {
6362

64-
// From http://stackoverflow.com/questions/9655181/convert-from-byte-array-to-hex-string-in-java
65-
private static final char[] hexArray = "0123456789abcdef".toCharArray();
63+
private static final char[] hexChars = "0123456789abcdef".toCharArray();
6664

6765
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
6866

6967
/**
7068
* A single dependency.
7169
*/
72-
static final class DependencyDescriptor implements Comparable<DependencyDescriptor> {
73-
74-
final String group;
75-
final String module;
76-
final String version;
77-
final String md5;
78-
79-
DependencyDescriptor(final String group, final String module, final String version, final String md5) {
80-
this.group = group;
81-
this.module = module;
82-
this.version = version;
83-
this.md5 = md5;
84-
}
85-
70+
record DependencyDescriptor(String group, String module, String version, String sha512) implements Comparable<DependencyDescriptor> {
8671
@Override
8772
public int compareTo(final DependencyDescriptor that) {
8873
final int group = this.group.compareTo(that.group);
@@ -97,35 +82,6 @@ public int compareTo(final DependencyDescriptor that) {
9782

9883
return this.version.compareTo(that.version);
9984
}
100-
101-
@Override
102-
public boolean equals(final Object other) {
103-
if (this == other) {
104-
return true;
105-
}
106-
if (other == null || this.getClass() != other.getClass()) {
107-
return false;
108-
}
109-
final DependencyDescriptor that = (DependencyDescriptor) other;
110-
return Objects.equals(this.group, that.group)
111-
&& Objects.equals(this.module, that.module)
112-
&& Objects.equals(this.version, that.version);
113-
}
114-
115-
@Override
116-
public int hashCode() {
117-
return Objects.hash(this.group, this.module, this.version);
118-
}
119-
120-
@Override
121-
public String toString() {
122-
return "DependencyDescriptor{" +
123-
"group='" + this.group + '\'' +
124-
", module='" + this.module + '\'' +
125-
", version='" + this.version + '\'' +
126-
", md5='" + this.md5 + '\'' +
127-
'}';
128-
}
12985
}
13086

13187
/**
@@ -134,14 +90,7 @@ public String toString() {
13490
* <p>At runtime, transitive dependencies won't be traversed, so this needs to
13591
* include direct + transitive depends.</p>
13692
*/
137-
static final class DependencyManifest {
138-
139-
final Map<String, List<DependencyDescriptor>> dependencies;
140-
141-
DependencyManifest(final Map<String, List<DependencyDescriptor>> dependencies) {
142-
this.dependencies = dependencies;
143-
}
144-
}
93+
record DependencyManifest(Map<String, List<DependencyDescriptor>> dependencies) {}
14594

14695
/**
14796
* Configuration to gather dependency artifacts from.
@@ -225,41 +174,42 @@ private List<DependencyDescriptor> configToDescriptor(final Set<ResolvedArtifact
225174
.map(dependency -> {
226175
final ModuleComponentIdentifier id = (ModuleComponentIdentifier) dependency.getId().getComponentIdentifier();
227176

228-
// Get file input stream for reading the file content
229-
final String md5hash;
177+
final MessageDigest digest;
178+
try {
179+
digest = MessageDigest.getInstance("SHA-512");
180+
} catch (final NoSuchAlgorithmException e) {
181+
throw new GradleException("Failed to find digest algorithm", e);
182+
}
183+
230184
try (final InputStream in = Files.newInputStream(dependency.getFile().toPath())) {
231-
final MessageDigest hasher = MessageDigest.getInstance("MD5");
232185
final byte[] buf = new byte[4096];
233186
int read;
234187
while ((read = in.read(buf)) != -1) {
235-
hasher.update(buf, 0, read);
188+
digest.update(buf, 0, read);
236189
}
237-
238-
md5hash = OutputDependenciesToJson.toHexString(hasher.digest());
239-
} catch (final IOException | NoSuchAlgorithmException ex) {
240-
throw new GradleException("Failed to create hash for " + dependency, ex);
190+
} catch (final IOException e) {
191+
throw new GradleException("Failed to digest file for " + dependency, e);
241192
}
242193

243-
// create descriptor
244194
return new DependencyDescriptor(
245195
id.getGroup(),
246196
id.getModule(),
247197
id.getVersion(),
248-
md5hash
198+
OutputDependenciesToJson.toHexString(digest.digest())
249199
);
250200
})
251201
.sorted(Comparator.naturalOrder()) // sort dependencies for stable output
252202
.collect(Collectors.toList());
253203
}
254204

255205
public static String toHexString(final byte[] bytes) {
256-
final char[] hexChars = new char[bytes.length * 2];
257-
for (int j = 0; j < bytes.length; j++) {
258-
final int v = bytes[j] & 0xFF;
259-
hexChars[j * 2] = OutputDependenciesToJson.hexArray[v >>> 4];
260-
hexChars[j * 2 + 1] = OutputDependenciesToJson.hexArray[v & 0x0F];
206+
final char[] chars = new char[bytes.length << 1];
207+
int i = 0;
208+
for (final byte b : bytes) {
209+
chars[i++] = OutputDependenciesToJson.hexChars[(b >> 4) & 15];
210+
chars[i++] = OutputDependenciesToJson.hexChars[b & 15];
261211
}
262-
return new String(hexChars);
212+
return new String(chars);
263213
}
264214

265215
public static class ConfigurationHolder {
@@ -274,7 +224,7 @@ public Provider<Set<String>> getIds() {
274224
return this.getArtifacts().map(set -> set.stream()
275225
.map(art -> art.getId().getComponentIdentifier())
276226
.filter(id -> id instanceof ModuleComponentIdentifier)
277-
.map(art -> art.getDisplayName())
227+
.map(ComponentIdentifier::getDisplayName)
278228
.collect(Collectors.toSet()));
279229
}
280230

build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ idea {
189189
(project as ExtensionAware).extensions["settings"].run {
190190
(this as ExtensionAware).extensions.getByType(org.jetbrains.gradle.ext.TaskTriggersConfig::class).run {
191191
afterSync(":modlauncher-transformers:build")
192+
afterSync(":library-manager:build")
192193
}
193194
}
194195
}

forge/build.gradle.kts

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ plugins {
1818
}
1919

2020
val commonProject = parent!!
21-
val transformersProject = parent!!.project(":modlauncher-transformers")
21+
val transformersProject = commonProject.project(":modlauncher-transformers")
22+
val libraryManagerProject = commonProject.project(":library-manager")
2223
val testPluginsProject: Project? = rootProject.subprojects.find { "testplugins" == it.name }
2324

2425
val apiVersion: String by project
@@ -211,6 +212,7 @@ dependencies {
211212
service(project(transformersProject.path)) {
212213
exclude(group = "cpw.mods", module = "modlauncher")
213214
}
215+
service(project(libraryManagerProject.path))
214216
service(platform(apiLibs.configurate.bom))
215217
service(apiLibs.configurate.core) {
216218
exclude(group = "org.checkerframework", module = "checker-qual")
@@ -232,6 +234,7 @@ dependencies {
232234

233235
val serviceShadedLibraries = serviceShadedLibrariesConfig.name
234236
serviceShadedLibraries(project(transformersProject.path)) { isTransitive = false }
237+
serviceShadedLibraries(project(libraryManagerProject.path)) { isTransitive = false }
235238

236239
val gameShadedLibraries = gameShadedLibrariesConfig.name
237240
gameShadedLibraries("org.spongepowered:spongeapi:$apiVersion") { isTransitive = false }

forge/src/applaunch/java/org/spongepowered/forge/applaunch/loading/moddiscovery/SpongeForgeDependencyLocator.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
import net.minecraftforge.forgespi.locating.IModLocator;
3434
import org.apache.logging.log4j.LogManager;
3535
import org.apache.logging.log4j.Logger;
36-
import org.spongepowered.forge.applaunch.loading.moddiscovery.library.LibraryManager;
36+
import org.spongepowered.forge.applaunch.loading.moddiscovery.library.Log4JLogger;
3737
import org.spongepowered.forge.applaunch.transformation.SpongeForgeTransformationService;
38+
import org.spongepowered.libs.LibraryManager;
3839

3940
import java.nio.file.Path;
4041
import java.util.ArrayList;
@@ -60,8 +61,8 @@ public List<IModFile> scanMods(Iterable<IModFile> loadedMods) {
6061
}
6162
this.libraryManager.finishedProcessing();
6263

63-
for (final LibraryManager.Library library : this.libraryManager.getAll().values()) {
64-
final Path path = library.getFile();
64+
for (final LibraryManager.Library library : this.libraryManager.getAll("main")) {
65+
final Path path = library.file();
6566
SpongeForgeDependencyLocator.LOGGER.debug("Proposing jar {} as a game library", path);
6667

6768
final IModLocator.ModFileOrException fileOrException = createMod(path);
@@ -89,6 +90,7 @@ public String name() {
8990
public void initArguments(final Map<String, ?> arguments) {
9091
final Environment env = Launcher.INSTANCE.environment();
9192
this.libraryManager = new LibraryManager(
93+
new Log4JLogger(LogManager.getLogger(LibraryManager.class)),
9294
env.getProperty(SpongeForgeTransformationService.Keys.CHECK_LIBRARY_HASHES.get()).orElse(true),
9395
env.getProperty(SpongeForgeTransformationService.Keys.LIBRARIES_DIRECTORY.get())
9496
.orElseThrow(() -> new IllegalStateException("no libraries available")),

0 commit comments

Comments
 (0)