Skip to content

Commit e8ea341

Browse files
authored
Replace org:immutables with JDK records (#209)
* Replace org:immutables with JDK records * Preserve libraries order to improve reproducibility
1 parent cf38523 commit e8ea341

32 files changed

+223
-695
lines changed

build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ plugins {
1212
alias(libs.plugins.gradlePluginPublish)
1313
alias(libs.plugins.indra.publishing.gradlePlugin)
1414
alias(libs.plugins.blossom)
15-
alias(libs.plugins.eclipseApt)
1615
}
1716

1817
group = "org.spongepowered"
@@ -55,9 +54,6 @@ dependencies {
5554
implementation(libs.gson)
5655

5756
compileOnlyApi(libs.checkerQual)
58-
annotationProcessor(libs.immutables.value)
59-
compileOnlyApi(variantOf(libs.immutables.value) { classifier("annotations") })
60-
api(libs.immutables.gson)
6157

6258
// IDE support
6359
implementation(libs.ideaExt)

gradle/libs.versions.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ asm = "9.9.1"
77
checker = "3.52.1"
88
vineFlower = "1.11.2"
99
ideaExt = "1.3"
10-
immutables = "2.10.1"
1110
indra = "4.0.0"
1211
junit = "5.14.1"
1312
mergeTool = "1.2.3"
@@ -25,8 +24,6 @@ asm-util = { module = "org.ow2.asm:asm-util", version.ref = "asm" }
2524
vineFlower = { module = "org.vineflower:vineflower", version.ref = "vineFlower" }
2625
gson = { module = "com.google.code.gson:gson", version = "2.13.2" }
2726
ideaExt = { module = "gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext", version.ref = "ideaExt" }
28-
immutables-value = { module = "org.immutables:value", version.ref = "immutables" }
29-
immutables-gson = { module = "org.immutables:gson", version.ref = "immutables" }
3027
junit-api = { module = "org.junit.jupiter:junit-jupiter-api" }
3128
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
3229
junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine" }
@@ -37,7 +34,6 @@ mammoth = { module = "net.kyori:mammoth", version.ref = "mammoth" }
3734

3835
[plugins]
3936
blossom = { id = "net.kyori.blossom", version = "2.2.0" }
40-
eclipseApt = { id = "com.diffplug.eclipse.apt", version = "4.4.1" }
4137
gradlePluginPublish = { id = "com.gradle.plugin-publish", version = "2.0.0" }
4238
ideaExt = { id = "org.jetbrains.gradle.plugin.idea-ext", version.ref = "ideaExt" }
4339
indra = { id = "net.kyori.indra", version.ref = "indra" }

src/main/java/org/spongepowered/gradle/vanilla/internal/Constants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ private Configurations() {
171171
* Extra dependencies that are injected into the project.
172172
*/
173173
public static final Set<GroupArtifactVersion> INJECTED_DEPENDENCIES = Set.of(
174-
GroupArtifactVersion.of("com.google.code.findbugs", "jsr305", "3.0.2"),
175-
GroupArtifactVersion.of("org.jetbrains", "annotations", "23.0.0") // 1.18+ only technically
174+
new GroupArtifactVersion("com.google.code.findbugs", "jsr305", "3.0.2"),
175+
new GroupArtifactVersion("org.jetbrains", "annotations", "23.0.0") // 1.18+ only technically
176176
);
177177

178178
private Constants() {

src/main/java/org/spongepowered/gradle/vanilla/internal/bundler/BundleElement.java

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,51 +24,15 @@
2424
*/
2525
package org.spongepowered.gradle.vanilla.internal.bundler;
2626

27-
import org.immutables.value.Value;
28-
2927
/**
3028
* A single entry in a bundle.
3129
*
3230
* <p>In bundle format version {@code 1.0}, these elements are declared as
3331
* rows of tab-separated values.</p>
32+
*
33+
* @param sha256 The expected SHA-265 hash of the file in the jar.
34+
* @param id The maven coordinates corresponding to this artifact.
35+
* @param path The path of the index entry in the jar.
3436
*/
35-
@Value.Immutable
36-
public interface BundleElement {
37-
38-
/**
39-
* Create a new bundle element.
40-
*
41-
* @param sha256 the sha-265 hash
42-
* @param id the ID of the bundle element
43-
* @param path the path in the jar
44-
* @return a new element
45-
*/
46-
static BundleElement of(final String sha256, final String id, final String path) {
47-
return new BundleElementImpl(sha256, id, path);
48-
}
49-
50-
/**
51-
* The expected hash of the file in the jar.
52-
*
53-
* @return SHA-265 hash string
54-
*/
55-
@Value.Parameter
56-
String sha256();
57-
58-
/**
59-
* The maven coordinates corresponding to this artifact.
60-
*
61-
* @return the maven coordinates
62-
*/
63-
@Value.Parameter
64-
String id();
65-
66-
/**
67-
* The path of the index entry in the jar.
68-
*
69-
* @return the path relative to the jar
70-
*/
71-
@Value.Parameter
72-
String path();
73-
37+
public record BundleElement(String sha256, String id, String path) {
7438
}

src/main/java/org/spongepowered/gradle/vanilla/internal/bundler/BundlerMetadata.java

Lines changed: 14 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,28 @@
2525
package org.spongepowered.gradle.vanilla.internal.bundler;
2626

2727
import org.checkerframework.checker.nullness.qual.Nullable;
28-
import org.immutables.value.Value;
2928

3029
import java.io.BufferedReader;
3130
import java.io.IOException;
3231
import java.io.InputStreamReader;
3332
import java.nio.charset.StandardCharsets;
3433
import java.nio.file.Path;
35-
import java.util.Collections;
34+
import java.util.List;
3635
import java.util.Optional;
37-
import java.util.Set;
3836
import java.util.jar.JarEntry;
3937
import java.util.jar.JarFile;
4038
import java.util.jar.Manifest;
41-
import java.util.stream.Collectors;
4239
import java.util.stream.Stream;
4340

44-
@Value.Immutable
45-
public abstract class BundlerMetadata {
41+
/**
42+
* The bundler metadata.
43+
*
44+
* @param version The bundler format used by this jar.
45+
* @param libraries Libraries packed in the jar as dependencies for the server.
46+
* @param server A bundle element describing the server itself.
47+
* @param mainClass The main class to execute.
48+
*/
49+
public record BundlerMetadata(FormatVersion version, List<BundleElement> libraries, BundleElement server, @Nullable String mainClass) {
4650

4751
private static final String MAIN_CLASS = "META-INF/main-class";
4852

@@ -94,9 +98,9 @@ public static Optional<BundlerMetadata> read(final JarFile file) throws IOExcept
9498
}
9599

96100
// libraries list
97-
final Set<BundleElement> libraries;
101+
final List<BundleElement> libraries;
98102
try (final Stream<BundleElement> elements = BundlerMetadata.readIndex(file, "libraries")) {
99-
libraries = Collections.unmodifiableSet(elements.collect(Collectors.toSet()));
103+
libraries = elements.toList();
100104
}
101105

102106
// main class
@@ -110,11 +114,7 @@ public static Optional<BundlerMetadata> read(final JarFile file) throws IOExcept
110114
mainClass = read.readLine();
111115
}
112116

113-
return Optional.of(BundlerMetadata.of(parsed, libraries, serverJar, mainClass));
114-
}
115-
116-
public static BundlerMetadata of(final FormatVersion version, final Set<BundleElement> libraries, final BundleElement server, final @Nullable String mainClass) {
117-
return new BundlerMetadataImpl(version, libraries, server, mainClass);
117+
return Optional.of(new BundlerMetadata(parsed, libraries, serverJar, mainClass));
118118
}
119119

120120
private static Stream<BundleElement> readIndex(final JarFile jar, final String index) throws IOException {
@@ -126,7 +126,7 @@ private static Stream<BundleElement> readIndex(final JarFile jar, final String i
126126
final BufferedReader reader = new BufferedReader(new InputStreamReader(jar.getInputStream(entry), StandardCharsets.UTF_8));
127127
return reader.lines()
128128
.map(x -> x.split("\t"))
129-
.map(line -> BundleElement.of(line[0], line[1], "META-INF/" + index + "/" + line[2]))
129+
.map(line -> new BundleElement(line[0], line[1], "META-INF/" + index + "/" + line[2]))
130130
.onClose(() -> {
131131
try {
132132
reader.close();
@@ -135,40 +135,4 @@ private static Stream<BundleElement> readIndex(final JarFile jar, final String i
135135
}
136136
});
137137
}
138-
139-
/**
140-
* The bundler format used by this jar.
141-
*
142-
* <p>While VanillaGradle only knows about versions that existed at the time
143-
* of its release, we will attempt to read future versions as well.</p>
144-
*
145-
* @return the format version
146-
*/
147-
@Value.Parameter
148-
public abstract FormatVersion version();
149-
150-
/**
151-
* Libraries packed in the jar as dependencies for the server.
152-
*
153-
* @return the library elements
154-
*/
155-
@Value.Parameter
156-
public abstract Set<BundleElement> libraries();
157-
158-
/**
159-
* Get a bundle element describing the server itself.
160-
*
161-
* @return an index entry describing the server
162-
*/
163-
@Value.Parameter
164-
public abstract BundleElement server();
165-
166-
/**
167-
* The main class to execute.
168-
*
169-
* @return the main class
170-
*/
171-
@Value.Parameter
172-
public abstract @Nullable String mainClass();
173-
174138
}

src/main/java/org/spongepowered/gradle/vanilla/internal/bundler/FormatVersion.java

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@
2424
*/
2525
package org.spongepowered.gradle.vanilla.internal.bundler;
2626

27-
import org.immutables.value.Value;
28-
2927
/**
3028
* A version of the Minecraft bundler metadata format.
29+
*
30+
* @param major Major version. Indicates incompatible changes.
31+
* @param minor Minor version. Indicates additions and other compatible changes.
3132
*/
32-
@Value.Immutable(builder = false)
33-
public interface FormatVersion extends Comparable<FormatVersion> {
33+
public record FormatVersion(int major, int minor) implements Comparable<FormatVersion> {
3434

3535
/**
3636
* An attribute in the manifest of bundler jars containing a format version.
3737
*
3838
* @see #parse(String)
3939
*/
40-
String MANIFEST_ATTRIBUTE = "Bundler-Format";
40+
public static final String MANIFEST_ATTRIBUTE = "Bundler-Format";
4141

4242
/**
4343
* Parse the manifest attribute version.
@@ -52,52 +52,25 @@ static FormatVersion parse(final String attribute) {
5252
if (split.length < 2) {
5353
throw new IllegalArgumentException("Invalid version " + attribute);
5454
}
55-
return FormatVersion.of(
55+
return new FormatVersion(
5656
Integer.parseInt(split[0]),
5757
Integer.parseInt(split[1])
5858
);
5959
}
6060

61-
/**
62-
* Create a format version directly.
63-
*
64-
* @param major the major version
65-
* @param minor the minor version
66-
* @return a new format version object
67-
*/
68-
static FormatVersion of(final int major, final int minor) {
69-
return new FormatVersionImpl(major, minor);
70-
}
71-
72-
/**
73-
* Major version. Indicates incompatible changes.
74-
*
75-
* @return the major version
76-
*/
77-
@Value.Parameter
78-
int major();
79-
80-
/**
81-
* Minor version. Indicates additions and other compatible changes.
82-
*
83-
* @return the minor version
84-
*/
85-
@Value.Parameter
86-
int minor();
87-
8861
/**
8962
* Whether a version of {@code other} can interpret data in this format version.
9063
*
9164
* @param other the compared version
9265
* @return whether other is compatible with this version's data
9366
*/
94-
default boolean compatibleWith(final FormatVersion other) {
67+
public boolean compatibleWith(final FormatVersion other) {
9568
return other.major() == this.major()
9669
&& other.minor() >= this.minor();
9770
}
9871

9972
@Override
100-
default int compareTo(final FormatVersion other) {
73+
public int compareTo(final FormatVersion other) {
10174
if (this.major() != other.major()) {
10275
return Integer.compare(this.major(), other.major());
10376
} else {

src/main/java/org/spongepowered/gradle/vanilla/internal/bundler/package-info.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/main/java/org/spongepowered/gradle/vanilla/internal/model/Argument.java

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.google.gson.stream.JsonReader;
3333
import com.google.gson.stream.JsonToken;
3434
import com.google.gson.stream.JsonWriter;
35-
import org.immutables.value.Value;
3635
import org.spongepowered.gradle.vanilla.internal.model.rule.RuleDeclaration;
3736

3837
import java.io.IOException;
@@ -42,32 +41,13 @@
4241

4342
import javax.annotation.Nullable;
4443

45-
@Value.Immutable
46-
public interface Argument {
44+
public record Argument(List<String> value, RuleDeclaration rules) {
4745

48-
static Argument of(final List<String> value) {
49-
return new ArgumentImpl(value, RuleDeclaration.empty());
46+
public Argument(final List<String> value) {
47+
this(value, RuleDeclaration.empty());
5048
}
5149

52-
static Argument of(final List<String> value, final RuleDeclaration rules) {
53-
return new ArgumentImpl(value, rules);
54-
}
55-
56-
/**
57-
* The argument value.
58-
*
59-
* @return the value of the argument
60-
*/
61-
@Value.Parameter
62-
List<String> value();
63-
64-
@Value.Default
65-
@Value.Parameter
66-
default RuleDeclaration rules() {
67-
return RuleDeclaration.empty();
68-
}
69-
70-
final class ArgumentTypeAdapter extends TypeAdapter<Argument> {
50+
public static final class ArgumentTypeAdapter extends TypeAdapter<Argument> {
7151
private static final String VALUE = "value";
7252
private static final String RULES = "rules";
7353
private final TypeAdapter<RuleDeclaration> declaration;
@@ -85,7 +65,7 @@ public void write(final JsonWriter out, final Argument value) {
8565
public Argument read(final JsonReader in) throws IOException {
8666
switch (in.peek()) {
8767
case STRING: // literal argument
88-
return new ArgumentImpl(Collections.singletonList(in.nextString()), RuleDeclaration.empty());
68+
return new Argument(Collections.singletonList(in.nextString()));
8969
case BEGIN_OBJECT: // argument with a rule
9070
@Nullable List<String> value = null;
9171
RuleDeclaration declaration = RuleDeclaration.empty();
@@ -116,7 +96,7 @@ public Argument read(final JsonReader in) throws IOException {
11696
if (value == null) {
11797
throw new JsonSyntaxException("Exited argument declaration without finding argument values");
11898
}
119-
return new ArgumentImpl(value, declaration);
99+
return new Argument(value, declaration);
120100
default:
121101
throw new JsonSyntaxException("Expected either a literal argument or a rule, but got " + in.peek() + " at " + in.getPath());
122102

0 commit comments

Comments
 (0)