Skip to content

Commit 727f7b2

Browse files
committed
Merge remote-tracking branch 'upstream/api-12' into loofah/api-12
2 parents f8c6cb5 + 21bc1ef commit 727f7b2

File tree

124 files changed

+2478
-2667
lines changed

Some content is hidden

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

124 files changed

+2478
-2667
lines changed

.github/workflows/common-run-build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ jobs:
6565
uses: "actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3" # v4.3.1
6666
with:
6767
name: SpongeVanilla installer libraries
68-
path: "${{ github.workspace }}/vanilla/build/resources/installer/libraries.json"
68+
path: "${{ github.workspace }}/vanilla/build/resources/installer/sponge-libraries.json"

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Build #
22
#########
3-
MANIFEST.MF
43
dependency-reduced-pom.xml
54

65
# Compiled #

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

+47-96
Original file line numberDiff line numberDiff line change
@@ -50,39 +50,25 @@
5050
import java.nio.file.Files;
5151
import java.security.MessageDigest;
5252
import java.security.NoSuchAlgorithmException;
53+
import java.util.Collections;
5354
import java.util.Comparator;
5455
import java.util.HashSet;
5556
import java.util.List;
5657
import java.util.Map;
57-
import java.util.Objects;
5858
import java.util.Set;
5959
import java.util.TreeMap;
6060
import java.util.stream.Collectors;
6161

6262
public abstract class OutputDependenciesToJson extends DefaultTask {
6363

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

6766
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
6867

6968
/**
7069
* A single dependency.
7170
*/
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-
71+
record DependencyDescriptor(String group, String module, String version, String sha512) implements Comparable<DependencyDescriptor> {
8672
@Override
8773
public int compareTo(final DependencyDescriptor that) {
8874
final int group = this.group.compareTo(that.group);
@@ -97,35 +83,6 @@ public int compareTo(final DependencyDescriptor that) {
9783

9884
return this.version.compareTo(that.version);
9985
}
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-
}
12986
}
13087

13188
/**
@@ -134,14 +91,7 @@ public String toString() {
13491
* <p>At runtime, transitive dependencies won't be traversed, so this needs to
13592
* include direct + transitive depends.</p>
13693
*/
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-
}
94+
record DependencyManifest(Map<String, List<DependencyDescriptor>> dependencies) {}
14595

14696
/**
14797
* Configuration to gather dependency artifacts from.
@@ -162,10 +112,10 @@ public final void dependencies(final String key, final NamedDomainObjectProvider
162112

163113
@Input
164114
@Optional
165-
protected abstract SetProperty<ModuleComponentIdentifier> getExcludedDependenciesBuildInput();
115+
protected abstract SetProperty<ModuleComponentIdentifier> getExcludedDependencyIdentifiers();
166116

167-
public final void excludedDependencies(final NamedDomainObjectProvider<Configuration> config) {
168-
this.getExcludedDependencies().set(config.flatMap(conf -> conf.getIncoming().getArtifacts().getResolvedArtifacts()));
117+
public final void excludeDependencies(final NamedDomainObjectProvider<Configuration> config) {
118+
this.getExcludedDependencies().addAll(config.flatMap(conf -> conf.getIncoming().getArtifacts().getResolvedArtifacts()));
169119
}
170120

171121
/**
@@ -179,25 +129,21 @@ public final void excludedDependencies(final NamedDomainObjectProvider<Configura
179129

180130
public OutputDependenciesToJson() {
181131
this.getAllowedClassifiers().add("");
182-
this.getExcludedDependenciesBuildInput().set(this.getExcludedDependencies().map(deps -> {
183-
return deps.stream()
184-
.map(res -> res.getId().getComponentIdentifier())
185-
.filter(res -> res instanceof ModuleComponentIdentifier)
186-
.map(res -> (ModuleComponentIdentifier) res)
187-
.collect(Collectors.toSet());
132+
this.getExcludedDependencyIdentifiers().set(this.getExcludedDependencies().map(artifacts -> {
133+
final Set<ModuleComponentIdentifier> ids = new HashSet<>();
134+
for (final ResolvedArtifactResult artifact : artifacts) {
135+
final ComponentIdentifier id = artifact.getId().getComponentIdentifier();
136+
if (id instanceof ModuleComponentIdentifier) {
137+
ids.add((ModuleComponentIdentifier) id);
138+
}
139+
}
140+
return ids;
188141
}));
189142
}
190143

191144
@TaskAction
192145
public void generateDependenciesJson() {
193-
final Set<ModuleComponentIdentifier> excludedDeps = new HashSet<>();
194-
if (this.getExcludedDependencies().isPresent()) {
195-
for (final ResolvedArtifactResult result : this.getExcludedDependencies().get()) {
196-
if (result.getId().getComponentIdentifier() instanceof ModuleComponentIdentifier) {
197-
excludedDeps.add((ModuleComponentIdentifier) result.getId().getComponentIdentifier());
198-
}
199-
}
200-
}
146+
final Set<ModuleComponentIdentifier> excludedDeps = this.getExcludedDependencyIdentifiers().getOrElse(Collections.emptySet());
201147

202148
final Map<String, ConfigurationHolder> inputConfigs = this.getDependencies().get();
203149
final Map<String, List<DependencyDescriptor>> dependenciesMap = new TreeMap<>();
@@ -225,63 +171,68 @@ private List<DependencyDescriptor> configToDescriptor(final Set<ResolvedArtifact
225171
.map(dependency -> {
226172
final ModuleComponentIdentifier id = (ModuleComponentIdentifier) dependency.getId().getComponentIdentifier();
227173

228-
// Get file input stream for reading the file content
229-
final String md5hash;
174+
final MessageDigest digest;
175+
try {
176+
digest = MessageDigest.getInstance("SHA-512");
177+
} catch (final NoSuchAlgorithmException e) {
178+
throw new GradleException("Failed to find digest algorithm", e);
179+
}
180+
230181
try (final InputStream in = Files.newInputStream(dependency.getFile().toPath())) {
231-
final MessageDigest hasher = MessageDigest.getInstance("MD5");
232182
final byte[] buf = new byte[4096];
233183
int read;
234184
while ((read = in.read(buf)) != -1) {
235-
hasher.update(buf, 0, read);
185+
digest.update(buf, 0, read);
236186
}
237-
238-
md5hash = OutputDependenciesToJson.toHexString(hasher.digest());
239-
} catch (final IOException | NoSuchAlgorithmException ex) {
240-
throw new GradleException("Failed to create hash for " + dependency, ex);
187+
} catch (final IOException e) {
188+
throw new GradleException("Failed to digest file for " + dependency, e);
241189
}
242190

243-
// create descriptor
244191
return new DependencyDescriptor(
245192
id.getGroup(),
246193
id.getModule(),
247194
id.getVersion(),
248-
md5hash
195+
OutputDependenciesToJson.toHexString(digest.digest())
249196
);
250197
})
251198
.sorted(Comparator.naturalOrder()) // sort dependencies for stable output
252199
.collect(Collectors.toList());
253200
}
254201

255202
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];
203+
final char[] chars = new char[bytes.length << 1];
204+
int i = 0;
205+
for (final byte b : bytes) {
206+
chars[i++] = OutputDependenciesToJson.hexChars[(b >> 4) & 15];
207+
chars[i++] = OutputDependenciesToJson.hexChars[b & 15];
261208
}
262-
return new String(hexChars);
209+
return new String(chars);
263210
}
264211

265212
public static class ConfigurationHolder {
266-
private final Provider<Set<ResolvedArtifactResult>> configuration;
213+
private final Provider<Set<ResolvedArtifactResult>> artifacts;
267214

268215
public ConfigurationHolder(final Configuration configuration) {
269-
this.configuration = configuration.getIncoming().getArtifacts().getResolvedArtifacts();
216+
this.artifacts = configuration.getIncoming().getArtifacts().getResolvedArtifacts();
270217
}
271218

272219
@Input
273220
public Provider<Set<String>> getIds() {
274-
return this.getArtifacts().map(set -> set.stream()
275-
.map(art -> art.getId().getComponentIdentifier())
276-
.filter(id -> id instanceof ModuleComponentIdentifier)
277-
.map(art -> art.getDisplayName())
278-
.collect(Collectors.toSet()));
221+
return this.artifacts.map(set -> {
222+
final Set<String> ids = new HashSet<>();
223+
for (final ResolvedArtifactResult artifact : set) {
224+
final ComponentIdentifier id = artifact.getId().getComponentIdentifier();
225+
if (id instanceof ModuleComponentIdentifier) {
226+
ids.add(id.getDisplayName());
227+
}
228+
}
229+
return ids;
230+
});
279231
}
280232

281233
@Internal
282234
public Provider<Set<ResolvedArtifactResult>> getArtifacts() {
283-
return this.configuration;
235+
return this.artifacts;
284236
}
285237
}
286-
287238
}

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

+10-12
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,16 @@ public void copyModulesExcludingProvided(final Configuration source, final Confi
9393
}
9494
}
9595

96-
public void applyNamedDependencyOnOutput(final Project originProject, final SourceSet sourceAdding, final SourceSet targetSource, final Project implProject, final String dependencyConfigName) {
97-
implProject.getLogger().lifecycle(
98-
"[{}] Adding {}({}) to {}({}).{}",
99-
implProject.getName(),
100-
originProject.getPath(),
101-
sourceAdding.getName(),
102-
implProject.getPath(),
103-
targetSource.getName(),
104-
dependencyConfigName
105-
);
106-
107-
implProject.getDependencies().add(dependencyConfigName, sourceAdding.getOutput());
96+
public void addDependencyToRuntimeOnly(final SourceSet source, final SourceSet target) {
97+
this.addDependencyTo(source, target.getRuntimeOnlyConfigurationName());
98+
}
99+
100+
public void addDependencyToImplementation(final SourceSet source, final SourceSet target) {
101+
this.addDependencyTo(source, target.getImplementationConfigurationName());
102+
}
103+
104+
public void addDependencyTo(final SourceSet source, final String targetConfig) {
105+
this.project.getDependencies().add(targetConfig, source.getOutput());
108106
}
109107

110108
public String generateImplementationVersionString(final String apiVersion, final String minecraftVersion, final String implRecommendedVersion) {

build.gradle.kts

+18-27
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,33 @@ val mixinsConfig by configurations.register("mixins") {
5757
val main by sourceSets
5858

5959
val applaunch by sourceSets.registering {
60-
spongeImpl.applyNamedDependencyOnOutput(project, this, main, project, main.implementationConfigurationName)
60+
spongeImpl.addDependencyToImplementation(this, main)
6161

6262
configurations.named(implementationConfigurationName) {
6363
extendsFrom(applaunchConfig)
6464
}
6565
}
6666
val launch by sourceSets.registering {
67-
spongeImpl.applyNamedDependencyOnOutput(project, applaunch.get(), this, project, this.implementationConfigurationName)
68-
spongeImpl.applyNamedDependencyOnOutput(project, this, main, project, main.implementationConfigurationName)
67+
spongeImpl.addDependencyToImplementation(applaunch.get(), this)
68+
spongeImpl.addDependencyToImplementation(this, main)
6969

7070
configurations.named(implementationConfigurationName) {
7171
extendsFrom(launchConfig)
7272
}
7373
}
7474
val accessors by sourceSets.registering {
75-
spongeImpl.applyNamedDependencyOnOutput(project, launch.get(), this, project, this.implementationConfigurationName)
76-
spongeImpl.applyNamedDependencyOnOutput(project, this, main, project, main.implementationConfigurationName)
75+
spongeImpl.addDependencyToImplementation(launch.get(), this)
76+
spongeImpl.addDependencyToImplementation(this, main)
7777

7878
configurations.named(implementationConfigurationName) {
7979
extendsFrom(accessorsConfig)
8080
}
8181
}
8282
val mixins by sourceSets.registering {
83-
spongeImpl.applyNamedDependencyOnOutput(project, launch.get(), this, project, this.implementationConfigurationName)
84-
spongeImpl.applyNamedDependencyOnOutput(project, applaunch.get(), this, project, this.implementationConfigurationName)
85-
spongeImpl.applyNamedDependencyOnOutput(project, accessors.get(), this, project, this.implementationConfigurationName)
86-
spongeImpl.applyNamedDependencyOnOutput(project, main, this, project, this.implementationConfigurationName)
83+
spongeImpl.addDependencyToImplementation(launch.get(), this)
84+
spongeImpl.addDependencyToImplementation(applaunch.get(), this)
85+
spongeImpl.addDependencyToImplementation(accessors.get(), this)
86+
spongeImpl.addDependencyToImplementation(main, this)
8787

8888
configurations.named(implementationConfigurationName) {
8989
extendsFrom(mixinsConfig)
@@ -122,6 +122,7 @@ dependencies {
122122
exclude(group = "org.apache.commons", module = "commons-lang3")
123123
}
124124
launchConfig(libs.mixin)
125+
launchConfig(libs.mixinextras.common)
125126
launchConfig(apiLibs.checkerQual)
126127
launchConfig(libs.guava) {
127128
exclude(group = "com.google.code.findbugs", module = "jsr305") // We don't want to use jsr305, use checkerframework
@@ -176,24 +177,6 @@ dependencies {
176177
}
177178
}
178179

179-
indraSpotlessLicenser {
180-
licenseHeaderFile(rootProject.file("HEADER.txt"))
181-
182-
property("name", "Sponge")
183-
property("organization", organization)
184-
property("url", projectUrl)
185-
}
186-
187-
idea {
188-
if (project != null) {
189-
(project as ExtensionAware).extensions["settings"].run {
190-
(this as ExtensionAware).extensions.getByType(org.jetbrains.gradle.ext.TaskTriggersConfig::class).run {
191-
afterSync(":modlauncher-transformers:build")
192-
}
193-
}
194-
}
195-
}
196-
197180
allprojects {
198181
configurations.configureEach {
199182
resolutionStrategy.dependencySubstitution {
@@ -284,6 +267,14 @@ allprojects {
284267
}
285268
}
286269

270+
indraSpotlessLicenser {
271+
licenseHeaderFile(rootProject.file("HEADER.txt"))
272+
273+
property("name", "Sponge")
274+
property("organization", organization)
275+
property("url", projectUrl)
276+
}
277+
287278
val spongeSnapshotRepo: String? by project
288279
val spongeReleaseRepo: String? by project
289280
tasks {

0 commit comments

Comments
 (0)