Skip to content

Commit b3bb015

Browse files
committed
JSON Data Utils targets Java 8 (for SlimeLauncher)
1 parent 53f3319 commit b3bb015

File tree

7 files changed

+37
-22
lines changed

7 files changed

+37
-22
lines changed

file-utils/src/main/java/net/minecraftforge/util/file/FileUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package net.minecraftforge.util.file;
66

77
import net.minecraftforge.srgutils.IMappingFile;
8-
import net.minecraftforge.util.logging.SimpleLogger;
98
import org.apache.commons.io.IOUtils;
109

1110
import java.io.ByteArrayOutputStream;

json-data-utils/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies {
1616
}
1717

1818
java {
19-
toolchain.languageVersion = JavaLanguageVersion.of(17)
19+
toolchain.languageVersion = JavaLanguageVersion.of(8)
2020
withSourcesJar()
2121
}
2222

json-data-utils/src/main/java/net/minecraftforge/util/data/DownloadUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.net.URL;
2525
import java.net.URLConnection;
2626
import java.nio.charset.StandardCharsets;
27+
import java.nio.file.FileSystemException;
2728
import java.nio.file.Files;
2829
import java.nio.file.StandardCopyOption;
2930

@@ -149,7 +150,7 @@ private static URLConnection getConnection(String address) {
149150
out.write(buf, 0, n);
150151
}
151152

152-
return out.toString(StandardCharsets.UTF_8);
153+
return out.toString(StandardCharsets.UTF_8.name());
153154
}
154155
}
155156
} catch (IOException e) {
@@ -182,8 +183,8 @@ public static boolean downloadFile(File target, String url) {
182183
}
183184

184185
private static void ensureParent(File path) {
185-
var parent = path.getAbsoluteFile().getParentFile();
186-
if (parent != null && !parent.exists())
187-
parent.mkdirs();
186+
File parent = path.getAbsoluteFile().getParentFile();
187+
if (parent != null && !parent.exists() && !parent.mkdirs())
188+
throw new IllegalStateException("Cannot create parent directory for " + path);
188189
}
189190
}

json-data-utils/src/main/java/net/minecraftforge/util/data/MCJsonUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public class MCJsonUtils {
1414
* @return The Minecraft directory
1515
*/
1616
public static File getMCDir() {
17-
var userHomeDir = System.getProperty("user.home", ".");
18-
var mcDir = ".minecraft";
17+
String userHomeDir = System.getProperty("user.home", ".");
18+
String mcDir = ".minecraft";
1919
if (OS.CURRENT == OS.WINDOWS && System.getenv("APPDATA") != null)
2020
return new File(System.getenv("APPDATA"), mcDir);
2121
else if (OS.CURRENT == OS.MACOS)

json-data-utils/src/main/java/net/minecraftforge/util/data/json/JsonData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static MinecraftVersion minecraftVersion(byte[] data) {
4444
}
4545

4646
private static <T> T fromJson(File file, Class<T> classOfT) throws JsonSyntaxException, JsonIOException {
47-
try (var stream = new FileInputStream(file)) {
47+
try (FileInputStream stream = new FileInputStream(file)) {
4848
return fromJson(stream, classOfT);
4949
} catch (IOException e) {
5050
throw new JsonIOException(e);
@@ -64,7 +64,7 @@ public static String toJson(Object src) {
6464
return GSON.toJson(src);
6565
}
6666
public static void toJson(Object src, File file) throws IOException {
67-
try (var writer = new FileWriter(file)) {
67+
try (FileWriter writer = new FileWriter(file)) {
6868
GSON.toJson(src, writer);
6969
}
7070
}

json-data-utils/src/main/java/net/minecraftforge/util/data/json/LauncherManifest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static class VersionInfo {
2424
public URL getUrl(String version) {
2525
if (version == null || versions == null)
2626
return null;
27-
for (var info : versions)
27+
for (VersionInfo info : versions)
2828
if (version.equals(info.id))
2929
return info.url;
3030
return null;

json-data-utils/src/main/java/net/minecraftforge/util/data/json/MinecraftVersion.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public class MinecraftVersion {
2323
public Library[] libraries;
2424

2525
public List<Lib> getLibs() {
26-
var libs = new ArrayList<Lib>();
26+
List<Lib> libs = new ArrayList<>();
2727

28-
for (var lib : this.libraries) {
28+
for (Library lib : this.libraries) {
2929
if (lib.rules != null && lib.rules.size() != 1)
30-
throw new UnsupportedOperationException("Rules were found, but wasn't precisely one??? Rules: %s".formatted(String.valueOf(lib.rules)));
30+
throw new UnsupportedOperationException("Rules were found, but wasn't precisely one??? Rules: " + lib.rules);
3131

32-
var os = lib.rules == null ? null : lib.rules.get(0).os.toOS();
32+
OS os = lib.rules == null ? null : lib.rules.get(0).os.toOS();
3333
libs.add(new Lib(lib.name, lib.downloads.artifact, os));
3434
if (lib.downloads.classifiers != null)
3535
lib.downloads.classifiers.forEach((k, v) -> libs.add(new Lib(lib.name + ':' + k, v, os)));
@@ -38,9 +38,20 @@ public List<Lib> getLibs() {
3838
return libs;
3939
}
4040

41-
public record Lib(String coord, LibraryDownload dl, @Nullable OS os) {}
41+
public static final class Lib {
42+
public final String coord;
43+
public final LibraryDownload dl;
44+
public final OS os;
45+
46+
public Lib(String coord, LibraryDownload dl, OS os) {
47+
this.coord = coord;
48+
this.dl = dl;
49+
this.os = os;
50+
}
51+
}
4252

4353
// TODO: [MCMaven][MinecraftVersion] Add function to filter libraries based on current operating systems
54+
4455
/** Represents a library that is required by a minecraft version. */
4556
public static class Library {
4657
/** The artifact coordinates of the library. */
@@ -84,12 +95,16 @@ public static class OS {
8495
public String name;
8596

8697
public net.minecraftforge.util.data.OS toOS() {
87-
return switch (name) {
88-
case "windows" -> net.minecraftforge.util.data.OS.WINDOWS;
89-
case "linux" -> net.minecraftforge.util.data.OS.LINUX;
90-
case "osx" -> net.minecraftforge.util.data.OS.MACOS;
91-
default -> net.minecraftforge.util.data.OS.UNKNOWN;
92-
};
98+
switch (this.name) {
99+
case "windows":
100+
return net.minecraftforge.util.data.OS.WINDOWS;
101+
case "linux":
102+
return net.minecraftforge.util.data.OS.LINUX;
103+
case "osx":
104+
return net.minecraftforge.util.data.OS.MACOS;
105+
default:
106+
return net.minecraftforge.util.data.OS.UNKNOWN;
107+
}
93108
}
94109
}
95110
}

0 commit comments

Comments
 (0)