diff --git a/build.gradle b/build.gradle index b6026b2..53793a1 100644 --- a/build.gradle +++ b/build.gradle @@ -19,8 +19,7 @@ version = gitversion.tagOffset println "Version: $version" -// TODO [Mavenizer] Update to Java 25 once ForgeGradle and ForgeDev target Gradle 9.1.0 -java.toolchain.languageVersion = JavaLanguageVersion.of(21) +java.toolchain.languageVersion = JavaLanguageVersion.of(25) dependencies { compileOnly libs.nulls diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 9bbc975..f8e1ee3 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradlew b/gradlew index faf9300..adff685 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -114,7 +114,6 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -172,7 +171,6 @@ fi # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) JAVACMD=$( cygpath --unix "$JAVACMD" ) @@ -212,8 +210,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" # Stop when "xargs" is not available. diff --git a/gradlew.bat b/gradlew.bat index 9d21a21..c4bdd3a 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -70,11 +70,10 @@ goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell diff --git a/settings.gradle b/settings.gradle index 767da1c..f601175 100644 --- a/settings.gradle +++ b/settings.gradle @@ -20,17 +20,17 @@ gradle.beforeProject { Project project -> //formatter:off dependencyResolutionManagement.versionCatalogs.register('libs') { plugin 'licenser', 'net.minecraftforge.licenser' version '1.2.0' - plugin 'gradleutils', 'net.minecraftforge.gradleutils' version '3.3.18' - plugin 'gitversion', 'net.minecraftforge.gitversion' version '3.1.1' - plugin 'changelog', 'net.minecraftforge.changelog' version '3.1.2' + plugin 'gradleutils', 'net.minecraftforge.gradleutils' version '3.3.21' + plugin 'gitversion', 'net.minecraftforge.gitversion' version '3.1.6' + plugin 'changelog', 'net.minecraftforge.changelog' version '3.1.3' plugin 'shadow', 'com.gradleup.shadow' version '9.2.2' // Static Analysis - library 'nulls', 'org.jetbrains', 'annotations' version '26.0.2' + library 'nulls', 'org.jetbrains', 'annotations' version '26.0.2-1' library 'gson', 'com.google.code.gson', 'gson' version '2.10.1' library 'jopt', 'net.sf.jopt-simple', 'jopt-simple' version '6.0-alpha-3' - library 'jver', 'net.minecraftforge', 'java-provisioner' version '1.0.10' + library 'jver', 'net.minecraftforge', 'java-provisioner' version '2.0.0' library 'srgutils', 'net.minecraftforge', 'srgutils' version '0.5.14' library 'diff', 'io.codechicken', 'DiffPatch' version '2.0.0.36' // Fuzzy patching @@ -38,11 +38,12 @@ dependencyResolutionManagement.versionCatalogs.register('libs') { library 'commonsio', 'commons-io', 'commons-io' version '2.18.0' // Utilities - library 'utils-download', 'net.minecraftforge', 'download-utils' version '0.3.1' - library 'utils-files', 'net.minecraftforge', 'file-utils' version '0.3.1' - library 'utils-hash', 'net.minecraftforge', 'hash-utils' version '0.1.9' - library 'utils-data', 'net.minecraftforge', 'json-data-utils' version '0.2.3' - library 'utils-logging', 'net.minecraftforge', 'log-utils' version '0.3.1' - bundle 'utils', ['utils-download', 'utils-files', 'utils-hash', 'utils-data', 'utils-logging'] + library 'utils-download', 'net.minecraftforge', 'download-utils' version '0.4.0' + library 'utils-files', 'net.minecraftforge', 'file-utils' version '0.3.2' + library 'utils-hash', 'net.minecraftforge', 'hash-utils' version '0.1.12' + library 'utils-data', 'net.minecraftforge', 'json-data-utils' version '0.4.0' + library 'utils-logging', 'net.minecraftforge', 'log-utils' version '0.5.0' + library 'utils-os', 'net.minecraftforge', 'os-utils' version '0.1.0' + bundle 'utils', ['utils-download', 'utils-files', 'utils-hash', 'utils-data', 'utils-logging', 'utils-os'] } //formatter:on diff --git a/src/main/java/net/minecraftforge/mcmaven/cli/MCPDataTask.java b/src/main/java/net/minecraftforge/mcmaven/cli/MCPDataTask.java index 32c9a3c..c2859cf 100644 --- a/src/main/java/net/minecraftforge/mcmaven/cli/MCPDataTask.java +++ b/src/main/java/net/minecraftforge/mcmaven/cli/MCPDataTask.java @@ -20,7 +20,9 @@ import net.minecraftforge.srgutils.IMappingFile.IField; import net.minecraftforge.srgutils.IMappingFile.IMethod; import net.minecraftforge.srgutils.IMappingFile.IParameter; -import net.minecraftforge.util.logging.Log; +import net.minecraftforge.util.logging.Logger; + +import static net.minecraftforge.mcmaven.impl.Mavenizer.LOGGER; // TODO [Mavenizer][MCPDataTask] This is a copy of FG6's ExtractMCPData task. // its not the best, but I dont want to re-wrok INSTALLER_TOOLS to put the tsrg in the mappings zip @@ -28,14 +30,14 @@ public class MCPDataTask { public static void run(String[] args) throws Exception { int ret = runI(args); if (ret != 0) { - Log.release(); + LOGGER.release(); //System.exit(ret); } } private static int runI(String[] args) throws Exception { // TODO [MCMavenizer] Make this into a --log [level] option - Log.enabled = Log.Level.INFO; + LOGGER.setEnabled(Logger.Level.INFO); var parser = new OptionParser(); parser.allowsUnrecognizedOptions(); @@ -87,7 +89,7 @@ private static int runI(String[] args) throws Exception { var options = parser.parse(args); if (options.has(helpO)) { - parser.printHelpOn(Log.INFO); + parser.printHelpOn(LOGGER.getInfo()); return -1; } @@ -103,7 +105,7 @@ private static int runI(String[] args) throws Exception { null; if (artifact == null) { - Log.error("Missing mcp --version or --artifact"); + LOGGER.error("Missing mcp --version or --artifact"); return -2; } @@ -118,19 +120,19 @@ else if (options.has(parchmentO)) var key = options.valueOf(keyO); if (key == null) { - Log.error("Missing --key option"); + LOGGER.error("Missing --key option"); return -3; } var repo = new MCPConfigRepo(new Cache(cacheRoot, jdkCacheRoot)); - Log.info(" Output: " + output.getAbsolutePath()); - Log.info(" Cache: " + cacheRoot.getAbsolutePath()); - Log.info(" JDK Cache: " + jdkCacheRoot.getAbsolutePath()); - Log.info(" Artifact: " + artifact); - Log.info(" Key: " + key); + LOGGER.info(" Output: " + output.getAbsolutePath()); + LOGGER.info(" Cache: " + cacheRoot.getAbsolutePath()); + LOGGER.info(" JDK Cache: " + jdkCacheRoot.getAbsolutePath()); + LOGGER.info(" Artifact: " + artifact); + LOGGER.info(" Key: " + key); if (mappings != null) - Log.info(" Mappings: " + mappings); - Log.info(); + LOGGER.info(" Mappings: " + mappings); + LOGGER.info(); var mcp = repo.get(artifact); var side = mcp.getSide("joined"); @@ -141,14 +143,14 @@ else if (options.has(parchmentO)) path = "config/static_methods.txt"; if (path == null) { - Log.error("Could not find data entry for '%s'".formatted(key)); + LOGGER.error("Could not find data entry for '%s'".formatted(key)); return -4; } try (ZipFile zip = new ZipFile(mcp.getData())) { var entry = zip.getEntry(path); if (entry == null) { - Log.error("Invalid config zip, missing file: " + path); + LOGGER.error("Invalid config zip, missing file: " + path); return -5; } diff --git a/src/main/java/net/minecraftforge/mcmaven/cli/MCPTask.java b/src/main/java/net/minecraftforge/mcmaven/cli/MCPTask.java index 6051101..a033a3e 100644 --- a/src/main/java/net/minecraftforge/mcmaven/cli/MCPTask.java +++ b/src/main/java/net/minecraftforge/mcmaven/cli/MCPTask.java @@ -24,14 +24,16 @@ import net.minecraftforge.util.data.json.JsonData; import net.minecraftforge.util.hash.HashFunction; import net.minecraftforge.util.hash.HashStore; -import net.minecraftforge.util.logging.Log; +import static net.minecraftforge.mcmaven.impl.Mavenizer.LOGGER; + +import net.minecraftforge.util.logging.Logger; import org.jetbrains.annotations.Nullable; // TODO [Mavenizer][MCPTask] Cleanup. Works well but is a mess. public class MCPTask { public static void run(String[] args) throws Exception { // TODO [MCMavenizer] Make this into a --log [level] option - Log.enabled = Log.Level.INFO; + LOGGER.setEnabled(Logger.Level.INFO); var parser = new OptionParser(); parser.allowsUnrecognizedOptions(); @@ -100,8 +102,8 @@ public static void run(String[] args) throws Exception { var options = parser.parse(args); if (options.has(helpO)) { - parser.printHelpOn(Log.INFO); - Log.release(); + parser.printHelpOn(LOGGER.getInfo()); + LOGGER.release(); return; } @@ -122,24 +124,24 @@ public static void run(String[] args) throws Exception { var sas = options.has(sasO) ? options.valueOf(sasO) : null; if (artifact == null) { - Log.error("Missing mcp --version or --artifact"); - Log.release(); + LOGGER.error("Missing mcp --version or --artifact"); + LOGGER.release(); return; } var repo = new MCPConfigRepo(new Cache(cacheRoot, jdkCacheRoot)); - Log.info(" Output: " + output.getAbsolutePath()); - Log.info(" Cache: " + cacheRoot.getAbsolutePath()); - Log.info(" JDK Cache: " + jdkCacheRoot.getAbsolutePath()); - Log.info(" Artifact: " + artifact); - Log.info(" Pipeline: " + pipeline); + LOGGER.info(" Output: " + output.getAbsolutePath()); + LOGGER.info(" Cache: " + cacheRoot.getAbsolutePath()); + LOGGER.info(" JDK Cache: " + jdkCacheRoot.getAbsolutePath()); + LOGGER.info(" Artifact: " + artifact); + LOGGER.info(" Pipeline: " + pipeline); if (options.has(rawO)) { - Log.info(" Raw Names: " + (options.has(seargeO) ? "Searge" : "Notch")); + LOGGER.info(" Raw Names: " + (options.has(seargeO) ? "Searge" : "Notch")); } else { - Log.info(" Access: " + (ats == null ? null : ats.getAbsolutePath())); - Log.info(" SAS: " + (sas == null ? null : sas.getAbsolutePath())); + LOGGER.info(" Access: " + (ats == null ? null : ats.getAbsolutePath())); + LOGGER.info(" SAS: " + (sas == null ? null : sas.getAbsolutePath())); } - Log.info(); + LOGGER.info(); var mcp = repo.get(artifact); var side = mcp.getSide(pipeline); @@ -152,13 +154,13 @@ public static void run(String[] args) throws Exception { Task rawTask = searge ? side.getTasks().getSrgJar() : side.getTasks().getRawJar(); File raw; - Log.info("Creating Raw Jar"); - var indent = Log.push(); + LOGGER.info("Creating Raw Jar"); + var indent = LOGGER.push(); try { raw = rawTask.execute(); cache.add("raw", raw); } finally { - Log.pop(indent); + LOGGER.pop(indent); } if (!output.exists() || !cache.isSame()) { @@ -198,12 +200,12 @@ public static void run(String[] args) throws Exception { File sources = null; { - Log.info("Creating MCP Source Jar"); - var indent = Log.push(); + LOGGER.info("Creating MCP Source Jar"); + var indent = LOGGER.push(); try { sources = sourcesTask.execute(); } finally { - Log.pop(indent); + LOGGER.pop(indent); } } @@ -211,8 +213,8 @@ public static void run(String[] args) throws Exception { .add("sources", sources); if (options.has(mappingsO)) { - Log.info("Renaming MCP Source Jar"); - var indent = Log.push(); + LOGGER.info("Renaming MCP Source Jar"); + var indent = LOGGER.push(); try { var mappings = options.has(parchmentO) ? new ParchmentMappings(options.valueOf(parchmentO)) @@ -221,7 +223,7 @@ public static void run(String[] args) throws Exception { var renameTask = new RenameTask(side.getBuildFolder(), pipeline, side, sourcesTask, mappings, false); sources = renameTask.execute(); } finally { - Log.pop(indent); + LOGGER.pop(indent); } cache.add("renamed", sources); @@ -242,14 +244,14 @@ public static void run(String[] args) throws Exception { // TODO [Mavenizer][Extra MCPTask Files] do this better private static void writeFiles(MCPTaskFactory mcpTaskFactory, File output) { var files = new MCPSetupFiles(); - files.versionManifest = mcpTaskFactory.findStep("downloadManifest").execute(); - files.versionJson = mcpTaskFactory.findStep("downloadJson").execute(); - files.clientRaw = mcpTaskFactory.findStep("downloadClient").execute(); - files.serverRaw = mcpTaskFactory.findStep("downloadServer").execute(); - files.serverExtracted = mcpTaskFactory.findStep("extractServer").execute(); - files.clientMappings = mcpTaskFactory.findStep("downloadClientMappings").execute(); - files.serverMappings = mcpTaskFactory.findStep("downloadServerMappings").execute(); - files.librariesList = mcpTaskFactory.findStep("listLibraries").execute(); + files.versionManifest = mcpTaskFactory.findStep("downloadManifest").execute().getAbsolutePath(); + files.versionJson = mcpTaskFactory.findStep("downloadJson").execute().getAbsolutePath(); + files.clientRaw = mcpTaskFactory.findStep("downloadClient").execute().getAbsolutePath(); + files.serverRaw = mcpTaskFactory.findStep("downloadServer").execute().getAbsolutePath(); + files.serverExtracted = mcpTaskFactory.findStep("extractServer").execute().getAbsolutePath(); + files.clientMappings = mcpTaskFactory.downloadClientMappings().execute().getAbsolutePath(); + files.serverMappings = mcpTaskFactory.downloadServerMappings().execute().getAbsolutePath(); + files.librariesList = mcpTaskFactory.findStep("listLibraries").execute().getAbsolutePath(); try { JsonData.toJson(files, output); diff --git a/src/main/java/net/minecraftforge/mcmaven/cli/Main.java b/src/main/java/net/minecraftforge/mcmaven/cli/Main.java index 92a2a1d..d089e45 100644 --- a/src/main/java/net/minecraftforge/mcmaven/cli/Main.java +++ b/src/main/java/net/minecraftforge/mcmaven/cli/Main.java @@ -6,7 +6,7 @@ import joptsimple.OptionParser; import joptsimple.OptionSpecBuilder; -import net.minecraftforge.util.logging.Log; +import static net.minecraftforge.mcmaven.impl.Mavenizer.LOGGER; import java.time.Duration; import java.util.ArrayList; @@ -16,22 +16,22 @@ public class Main { public static void main(String[] args) throws Exception { var start = System.nanoTime(); try { - Log.capture(); - Log.info(JarVersionInfo.of(DISPLAY_NAME, Main.class).implementation()); + LOGGER.capture(); + LOGGER.info(JarVersionInfo.of(DISPLAY_NAME, Main.class).implementation()); run(args); } catch (Throwable e) { - Log.release(); + LOGGER.release(); throw e; } var time = Duration.ofNanos(System.nanoTime() - start); - if (Log.isCapturing()) { - Log.drop(); - Log.INFO.print("Minecraft Maven is up-to-date"); + if (LOGGER.isCapturing()) { + LOGGER.drop(); + LOGGER.getInfo().print("Minecraft Maven is up-to-date"); } else { - Log.INFO.print("Minecraft Maven has finished"); + LOGGER.getInfo().print("Minecraft Maven has finished"); } - Log.INFO.println(String.format(", took %d:%02d.%03d", time.toMinutesPart(), time.toSecondsPart(), time.toMillisPart())); + LOGGER.getInfo().printf(", took %d:%02d.%03d%n", time.toMinutesPart(), time.toSecondsPart(), time.toMillisPart()); } private static void run(String[] args) throws Exception { @@ -59,7 +59,7 @@ private static void run(String[] args) throws Exception { } } - parser.printHelpOn(Log.INFO); - Log.release(); + parser.printHelpOn(LOGGER.getInfo()); + LOGGER.release(); } } diff --git a/src/main/java/net/minecraftforge/mcmaven/cli/MavenTask.java b/src/main/java/net/minecraftforge/mcmaven/cli/MavenTask.java index 884eb52..df425b5 100644 --- a/src/main/java/net/minecraftforge/mcmaven/cli/MavenTask.java +++ b/src/main/java/net/minecraftforge/mcmaven/cli/MavenTask.java @@ -10,18 +10,20 @@ import joptsimple.OptionParser; import joptsimple.OptionSpecBuilder; -import net.minecraftforge.mcmaven.impl.GlobalOptions; +import net.minecraftforge.mcmaven.impl.Mavenizer; import net.minecraftforge.mcmaven.impl.MinecraftMaven; import net.minecraftforge.mcmaven.impl.mappings.Mappings; import net.minecraftforge.mcmaven.impl.mappings.ParchmentMappings; import net.minecraftforge.mcmaven.impl.util.Artifact; import net.minecraftforge.mcmaven.impl.util.Constants; -import net.minecraftforge.util.logging.Log; +import net.minecraftforge.util.logging.Logger; + +import static net.minecraftforge.mcmaven.impl.Mavenizer.LOGGER; class MavenTask { static void run(String[] args) throws Exception { // TODO [MCMavenizer] Make this into a --log [level] option - Log.enabled = Log.Level.INFO; + LOGGER.setEnabled(Logger.Level.INFO); var parser = new OptionParser(); parser.allowsUnrecognizedOptions(); @@ -111,16 +113,16 @@ static void run(String[] args) throws Exception { var options = parser.parse(args); if (options.has(helpO)) { - parser.printHelpOn(Log.INFO); - Log.release(); + parser.printHelpOn(LOGGER.getInfo()); + LOGGER.release(); return; } // global options if (options.has(offlineO)) - GlobalOptions.setOffline(); + Mavenizer.setOffline(); if (options.has(cacheOnlyO)) - GlobalOptions.setCacheOnly(); + Mavenizer.setCacheOnly(); var output = options.valueOf(outputO); var cache = options.valueOf(cacheO); diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/GlobalOptions.java b/src/main/java/net/minecraftforge/mcmaven/impl/Mavenizer.java similarity index 79% rename from src/main/java/net/minecraftforge/mcmaven/impl/GlobalOptions.java rename to src/main/java/net/minecraftforge/mcmaven/impl/Mavenizer.java index a518cc8..5c4d994 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/GlobalOptions.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/Mavenizer.java @@ -4,9 +4,11 @@ */ package net.minecraftforge.mcmaven.impl; -import net.minecraftforge.util.logging.Log; +import net.minecraftforge.util.logging.Logger; + +public final class Mavenizer { + public static final Logger LOGGER = Logger.create(); -public final class GlobalOptions { private static boolean offline = false; private static boolean cacheOnly = false; @@ -37,10 +39,11 @@ public static void assertNotCacheOnly() { if (cacheOnly) { throw new IllegalArgumentException("Cache is out of date! Please run without --cache-only"); } else if (!cacheMiss) { + LOGGER.warn("Cache miss!", new Exception("Cache miss!")); cacheMiss = true; - Log.release(); + LOGGER.release(); } } - private GlobalOptions() { } + private Mavenizer() { } } diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/MinecraftMaven.java b/src/main/java/net/minecraftforge/mcmaven/impl/MinecraftMaven.java index d66ff06..0259c52 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/MinecraftMaven.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/MinecraftMaven.java @@ -17,7 +17,7 @@ import net.minecraftforge.util.data.json.JsonData; import net.minecraftforge.util.hash.HashStore; import net.minecraftforge.util.hash.HashUtils; -import net.minecraftforge.util.logging.Log; +import static net.minecraftforge.mcmaven.impl.Mavenizer.LOGGER; import java.io.File; import java.util.ArrayList; @@ -37,22 +37,22 @@ public MinecraftMaven(File output, File cacheRoot, File jdkCacheRoot, Mappings m } public MinecraftMaven { - Log.info(" Output: " + output.getAbsolutePath()); - Log.info(" Cache: " + cache.root().getAbsolutePath()); - Log.info(" JDK Cache: " + cache.jdks().root().getAbsolutePath()); - Log.info(" Offline: " + GlobalOptions.isOffline()); - Log.info(" Cache Only: " + GlobalOptions.isCacheOnly()); - Log.info(" Mappings: " + mappings); + LOGGER.info(" Output: " + output.getAbsolutePath()); + LOGGER.info(" Cache: " + cache.root().getAbsolutePath()); + LOGGER.info(" JDK Cache: " + cache.jdks().root().getAbsolutePath()); + LOGGER.info(" Offline: " + Mavenizer.isOffline()); + LOGGER.info(" Cache Only: " + Mavenizer.isCacheOnly()); + LOGGER.info(" Mappings: " + mappings); if (!foreignRepositories.isEmpty()) - Log.info(" Foreign Repos: [" + String.join(", ", foreignRepositories.values()) + ']'); - Log.info(" GradleVariantHack: " + globalAuxiliaryVariants); - Log.info(); + LOGGER.info(" Foreign Repos: [" + String.join(", ", foreignRepositories.values()) + ']'); + LOGGER.info(" GradleVariantHack: " + globalAuxiliaryVariants); + LOGGER.info(); } public void run(Artifact artifact) { var module = artifact.getGroup() + ':' + artifact.getName(); var version = artifact.getVersion(); - Log.info("Processing Minecraft dependency: %s:%s".formatted(module, version)); + LOGGER.info("Processing Minecraft dependency: %s:%s".formatted(module, version)); var mcprepo = new MCPConfigRepo(this.cache); if (Constants.FORGE_GROUP.equals(artifact.getGroup()) && Constants.FORGE_NAME.equals(artifact.getName())) { diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/cache/JDKCache.java b/src/main/java/net/minecraftforge/mcmaven/impl/cache/JDKCache.java index c896f9e..e74f25b 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/cache/JDKCache.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/cache/JDKCache.java @@ -12,20 +12,21 @@ import java.util.List; import java.util.Map; -import net.minecraftforge.java_provisioner.api.IJavaInstall; -import net.minecraftforge.java_provisioner.api.IJavaLocator; -import net.minecraftforge.mcmaven.impl.GlobalOptions; -import net.minecraftforge.util.logging.Log; -import net.minecraftforge.util.logging.Log.Level; +import net.minecraftforge.java_provisioner.api.JavaInstall; +import net.minecraftforge.java_provisioner.api.JavaLocator; +import net.minecraftforge.java_provisioner.api.JavaProvisioner; +import net.minecraftforge.mcmaven.impl.Mavenizer; +import net.minecraftforge.util.logging.Logger; -import org.jetbrains.annotations.Nullable; +import static net.minecraftforge.mcmaven.impl.Mavenizer.LOGGER; /** Represents the JDK cache for this tool. */ public final class JDKCache { private boolean attemptedLocate = false; + private final List attemptedLocateErrors = new ArrayList<>(); private final File root; private final Map jdks = new HashMap<>(); - private final IJavaLocator disco; + private final JavaProvisioner disco; /** * Initializes the JDK cache with the given cache directory. @@ -34,7 +35,7 @@ public final class JDKCache { */ public JDKCache(File cache) { this.root = cache; - this.disco = IJavaLocator.disco(cache, GlobalOptions.isOffline()); + this.disco = JavaLocator.disco(cache, Mavenizer.isOffline()); } public File root() { @@ -48,7 +49,7 @@ public File root() { * @param version The version to get * @return The JDK, or {@code null} if it could not be found or downloaded */ - public @Nullable File get(int version) { + public File get(int version) throws Exception { if (!attemptedLocate) attemptLocate(); @@ -57,26 +58,19 @@ public File root() { if (ret != null) return ret; try { - var downloaded = disco.provision(version); // Implementation detail, we only download jdks, so no need to check here - if (downloaded == null) { - Log.error("Failed to find JDK for " + version); - for (var line : disco.logOutput()) - Log.error(" " + line); - return null; - } - ret = downloaded.home(); + ret = disco.provision(version).home(); // Implementation detail, we only download jdks, so no need to check here } catch (Exception e) { - Log.error("Failed to provision JDK " + version); - e.printStackTrace(Log.getLog(Level.ERROR)); - return null; + LOGGER.error("Failed to provision JDK " + version); + e.printStackTrace(LOGGER.getLog(Logger.Level.ERROR)); + throw e; } // not sure how this would ever hit. but just in case... var old = jdks.putIfAbsent(version, ret); if (old != null) { - Log.error("JDKCache: Downloaded JDK " + version + " is replacing an existing download! It was probably downloaded by another thread."); - Log.error("JDKCache: Old JDK: " + old); - // TODO Throw exception here + LOGGER.error("JDKCache: Downloaded JDK " + version + " is replacing an existing download! It was probably downloaded by another thread."); + LOGGER.error("JDKCache: Old JDK: " + old); + // TODO [Mavenizer][Provisioner] Properly account for parallel Mavenizer instances } return ret; @@ -86,16 +80,19 @@ private void attemptLocate() { if (attemptedLocate) return; attemptedLocate = true; - List locators = new ArrayList<>(); - locators.add(IJavaLocator.home()); - locators.add(IJavaLocator.gradle()); + List locators = new ArrayList<>(); + locators.add(JavaLocator.home()); + locators.add(JavaLocator.gradle()); locators.add(this.disco); - List installs = new ArrayList<>(); + List installs = new ArrayList<>(); - for (IJavaLocator locator : locators) { - List found = locator.findAll(); - installs.addAll(found); + for (JavaLocator locator : locators) { + try { + installs.addAll(locator.findAll()); + } catch (Exception e) { + attemptedLocateErrors.add(e); + } } // Remove duplicates @@ -103,7 +100,7 @@ private void attemptLocate() { installs.removeIf(install -> !seen.add(install.home())); Collections.sort(installs); - for (IJavaInstall install : installs) { + for (JavaInstall install : installs) { if (!install.isJdk() || install.majorVersion() <= 0) continue; this.jdks.putIfAbsent(install.majorVersion(), install.home()); diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/cache/MavenCache.java b/src/main/java/net/minecraftforge/mcmaven/impl/cache/MavenCache.java index 938872f..5dd7980 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/cache/MavenCache.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/cache/MavenCache.java @@ -4,13 +4,13 @@ */ package net.minecraftforge.mcmaven.impl.cache; -import net.minecraftforge.mcmaven.impl.GlobalOptions; +import net.minecraftforge.mcmaven.impl.Mavenizer; import net.minecraftforge.mcmaven.impl.util.Artifact; import net.minecraftforge.util.download.DownloadUtils; import net.minecraftforge.util.hash.HashFunction; import net.minecraftforge.mcmaven.impl.util.Util; import net.minecraftforge.util.hash.HashUtils; -import net.minecraftforge.util.logging.Log; +import static net.minecraftforge.mcmaven.impl.Mavenizer.LOGGER; import org.jetbrains.annotations.ApiStatus; import org.w3c.dom.Document; import org.w3c.dom.NodeList; @@ -23,7 +23,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -213,18 +212,18 @@ protected File download(boolean changing, String path) throws IOException { if (!invalidHash && changing) { for (var func : knownHashes) { - if (GlobalOptions.isOffline()) continue; + if (Mavenizer.isOffline()) continue; - var rhash = DownloadUtils.tryDownloadString(true, repo + path + '.' + func.extension()); + var rhash = DownloadUtils.tryDownloadString(repo + path + '.' + func.extension()); if (rhash == null) continue; try { var chash = func.hash(target); if (!chash.equals(rhash)) { - Log.error("Outdated cached file: " + target.getAbsolutePath()); - Log.error("Expected: " + rhash); - Log.error("Actual: " + chash); + LOGGER.error("Outdated cached file: " + target.getAbsolutePath()); + LOGGER.error("Expected: " + rhash); + LOGGER.error("Actual: " + chash); invalidHash = true; } } catch (IOException e) { @@ -239,12 +238,12 @@ protected File download(boolean changing, String path) throws IOException { if (!invalidHash) return target; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); target.delete(); } - GlobalOptions.assertNotCacheOnly(); - GlobalOptions.assertOnline(); + Mavenizer.assertNotCacheOnly(); + Mavenizer.assertOnline(); downloadFile(target, path); HashUtils.updateHash(target, knownHashes); return target; diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/cache/MinecraftMavenCache.java b/src/main/java/net/minecraftforge/mcmaven/impl/cache/MinecraftMavenCache.java index 28abfc6..d5bcc7e 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/cache/MinecraftMavenCache.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/cache/MinecraftMavenCache.java @@ -14,6 +14,7 @@ import net.minecraftforge.util.file.FileUtils; import net.minecraftforge.util.hash.HashFunction; import net.minecraftforge.mcmaven.impl.util.Util; +import net.minecraftforge.util.os.OS; /** Represents the Minecraft maven cache for this tool. */ public final class MinecraftMavenCache extends MavenCache { @@ -22,7 +23,7 @@ public final class MinecraftMavenCache extends MavenCache { HashFunction.SHA1 }; - private static final File LOCAL_MCLIBS = new File(MCJsonUtils.getMCDir(), "libraries"); + private static final File LOCAL_MCLIBS = new File(MCJsonUtils.getMCDir(OS.current()), "libraries"); /** * Initializes a new maven cache with the given cache directory. diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/data/MCPSetupFiles.java b/src/main/java/net/minecraftforge/mcmaven/impl/data/MCPSetupFiles.java index acb692c..39ebcbf 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/data/MCPSetupFiles.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/data/MCPSetupFiles.java @@ -4,16 +4,14 @@ */ package net.minecraftforge.mcmaven.impl.data; -import java.io.File; - public class MCPSetupFiles { - public File versionManifest; - public File versionJson; - public File clientRaw; - public File clientMappings; - public File serverRaw; - public File serverExtracted; - public File serverMappings; - public File librariesList; - public File joinedSrgMappings; + public String versionManifest; + public String versionJson; + public String clientRaw; + public String clientMappings; + public String serverRaw; + public String serverExtracted; + public String serverMappings; + public String librariesList; + public String joinedSrgMappings; } diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/mappings/Mappings.java b/src/main/java/net/minecraftforge/mcmaven/impl/mappings/Mappings.java index 4293c2d..3dac9ea 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/mappings/Mappings.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/mappings/Mappings.java @@ -13,7 +13,7 @@ import java.util.Map; import java.util.zip.ZipFile; -import net.minecraftforge.mcmaven.impl.GlobalOptions; +import net.minecraftforge.mcmaven.impl.Mavenizer; import net.minecraftforge.mcmaven.impl.repo.mcpconfig.MCPSide; import net.minecraftforge.mcmaven.impl.util.Artifact; import net.minecraftforge.mcmaven.impl.util.Constants; @@ -151,7 +151,7 @@ private File getMappings(MCPSide side, Task srgMappings, Task clientTask, Task s if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); var args = List.of( "--task", @@ -166,9 +166,12 @@ private File getMappings(MCPSide side, Task srgMappings, Task clientTask, Task s output.getAbsolutePath() ); - var jdk = side.getMCP().getCache().jdks().get(Constants.INSTALLER_TOOLS_JAVA_VERSION); - if (jdk == null) - throw new IllegalStateException("Failed to find JDK for version " + Constants.INSTALLER_TOOLS_JAVA_VERSION); + File jdk; + try { + jdk = side.getMCP().getCache().jdks().get(Constants.INSTALLER_TOOLS_JAVA_VERSION); + } catch (Exception e) { + throw new IllegalStateException("Failed to find JDK for version " + Constants.INSTALLER_TOOLS_JAVA_VERSION, e); + } var ret = ProcessUtils.runJar(jdk, log.getParentFile(), log, tool, Collections.emptyList(), args); if (ret.exitCode != 0) diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/repo/Repo.java b/src/main/java/net/minecraftforge/mcmaven/impl/repo/Repo.java index db5826f..e8068ad 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/repo/Repo.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/repo/Repo.java @@ -4,7 +4,7 @@ */ package net.minecraftforge.mcmaven.impl.repo; -import net.minecraftforge.mcmaven.impl.GlobalOptions; +import net.minecraftforge.mcmaven.impl.Mavenizer; import net.minecraftforge.mcmaven.impl.cache.Cache; import net.minecraftforge.mcmaven.impl.data.GradleModule; import net.minecraftforge.mcmaven.impl.mappings.Mappings; @@ -17,17 +17,21 @@ import net.minecraftforge.util.data.json.JsonData; import net.minecraftforge.util.file.FileUtils; import net.minecraftforge.util.hash.HashStore; -import net.minecraftforge.util.logging.Log; +import static net.minecraftforge.mcmaven.impl.Mavenizer.LOGGER; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.EnumSet; import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.function.Consumer; import java.util.function.Supplier; +import java.util.stream.Collectors; import org.jetbrains.annotations.Nullable; @@ -73,6 +77,13 @@ protected Supplier sourceVariant(Mappings mappings) { }; } + protected Supplier metadataVariant() { + return () -> new GradleModule.Variant[] { + GradleModule.Variant.of("metadata") + .attribute("org.gradle.usage", "metadata") + }; + } + protected static Task variantTask(Task parent, Supplier supplier) { return Task.named(parent.name() + "[variants]", Task.deps(parent), () -> { var variants = supplier.get(); @@ -105,15 +116,23 @@ protected GradleModule.Variant[] classVariants(Mappings mappings, MCPSide side, var natives = new HashMap>(); for (var artifact : side.getMCLibraries()) { - var variant = GradleAttributes.OperatingSystemFamily.from(artifact.getOs()); - if (variant == null) + var osVariants = EnumSet.noneOf(GradleAttributes.OperatingSystemFamily.class); + for (var os : artifact.getOs()) { + var variant = GradleAttributes.OperatingSystemFamily.from(os); + if (variant != null) + osVariants.add(variant); + } + + if (osVariants.isEmpty()) { all.add(artifact); - else - natives.computeIfAbsent(variant, k -> new ArrayList<>()).add(artifact); + } else { + for (var variant : osVariants) { + natives.computeIfAbsent(variant, k -> new ArrayList<>()).add(artifact); + } + } } - for (var artifact : side.getMCPConfigLibraries()) - all.add(artifact); + all.addAll(side.getMCPConfigLibraries()); for (var extra : extraDeps) { if (extra != null) @@ -164,7 +183,7 @@ protected static Task simplePom(File build, Artifact artifact) { if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); var builder = new POMBuilder(artifact.getGroup(), artifact.getName(), artifact.getVersion()); @@ -201,14 +220,14 @@ public File get() { return this.task.execute(); try { - Log.info(this.message); - Log.push(); + LOGGER.info(this.message); + LOGGER.push(); return this.task.execute(); } finally { if (this.variants != null) this.variants.execute(); - Log.pop(); + LOGGER.pop(); } } diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/repo/forge/ForgeRepo.java b/src/main/java/net/minecraftforge/mcmaven/impl/repo/forge/ForgeRepo.java index 4d66079..8c6549c 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/repo/forge/ForgeRepo.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/repo/forge/ForgeRepo.java @@ -15,14 +15,14 @@ import net.minecraftforge.mcmaven.impl.util.Artifact; import net.minecraftforge.mcmaven.impl.util.ComparableVersion; import net.minecraftforge.mcmaven.impl.util.Constants; -import net.minecraftforge.mcmaven.impl.GlobalOptions; +import net.minecraftforge.mcmaven.impl.Mavenizer; import net.minecraftforge.mcmaven.impl.util.POMBuilder; import net.minecraftforge.mcmaven.impl.util.Task; import net.minecraftforge.mcmaven.impl.util.Util; import net.minecraftforge.util.data.json.JsonData; import net.minecraftforge.util.file.FileUtils; import net.minecraftforge.util.hash.HashStore; -import net.minecraftforge.util.logging.Log; +import static net.minecraftforge.mcmaven.impl.Mavenizer.LOGGER; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; @@ -72,8 +72,8 @@ public List process(Artifact artifact, Mappings mappings) { throw new IllegalArgumentException("Unknown or unsupported module: " + module); var fg = FGVersion.fromForge(version); - Log.info("Processing Minecraft Forge (userdev): " + version); - var indent = Log.push(); + LOGGER.info("Processing Minecraft Forge (userdev): " + version); + var indent = LOGGER.push(); try { if (fg == null) throw new IllegalArgumentException("Python version unsupported!"); @@ -87,7 +87,7 @@ public List process(Artifact artifact, Mappings mappings) { throw new IllegalArgumentException("Forge version %s is not supported yet".formatted(version)); } finally { - Log.pop(indent); + LOGGER.pop(indent); } } @@ -145,7 +145,7 @@ private List processV3(String version, Mappings mappings) { var sources = pending("Sources", sourcesTask, name.withClassifier("sources"), true, sourceVariant(mappings)); var classes = pending("Classes", classesTask, name, false, () -> classVariants(mappings, patcher, extraCoords, mappingCoords)); - var metadata = pending("Metadata", metadata(build, patcher), name.withClassifier("metadata").withExtension("zip"), false); + var metadata = pending("Metadata", metadata(build, patcher), name.withClassifier("metadata").withExtension("zip"), false, metadataVariant()); var pom = pending("Maven POM", pom(build, patcher, version, extraCoords, mappingCoords), name.withExtension("pom"), false); @@ -174,13 +174,14 @@ private static Task metadata(File build, Patcher patcher) { var cache = HashStore .fromFile(output) - .add("data", patcher.getDataHash()) .add(versionJson) + .add(versionProperties) + .add("data", patcher.getDataHash()) .addKnown("version", "1"); if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); try { FileUtils.ensureParent(output); @@ -232,7 +233,7 @@ private static Task pom(File build, Patcher patcher, String version, Artifact cl if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); var builder = new POMBuilder("net.minecraftforge", "forge", version).preferGradleModule().dependencies(dependencies -> { if (clientExtra != null) diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/repo/forge/InjectTask.java b/src/main/java/net/minecraftforge/mcmaven/impl/repo/forge/InjectTask.java index a8afbc6..d24548c 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/repo/forge/InjectTask.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/repo/forge/InjectTask.java @@ -4,7 +4,7 @@ */ package net.minecraftforge.mcmaven.impl.repo.forge; -import net.minecraftforge.mcmaven.impl.GlobalOptions; +import net.minecraftforge.mcmaven.impl.Mavenizer; import net.minecraftforge.mcmaven.impl.cache.Cache; import net.minecraftforge.mcmaven.impl.mappings.Mappings; import net.minecraftforge.mcmaven.impl.util.Artifact; @@ -16,8 +16,6 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Set; -import java.util.function.Supplier; /** * Takes a jar containing compiled class files, and injects extra data/resources from a patcher into it. @@ -79,12 +77,13 @@ private File injectDataImpl(Task inputTask, File outputJar) { if (outputJar.exists() && cache.isSame()) return outputJar; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); cache.clear().add("recompiled", recompiledJar); try { - var jars = new ArrayList(); - jars.addAll(universals); + var jars = new ArrayList<>(universals); + universals.forEach(cache::add); + jars.add(recompiledJar); FileUtils.mergeJars(outputJar, true, (file, name) -> file == recompiledJar || !name.endsWith(".class"), jars.toArray(File[]::new)); diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/repo/forge/Patcher.java b/src/main/java/net/minecraftforge/mcmaven/impl/repo/forge/Patcher.java index 3a7eb58..4c52d80 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/repo/forge/Patcher.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/repo/forge/Patcher.java @@ -13,7 +13,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Stack; import java.util.function.Consumer; import java.util.function.Predicate; @@ -27,7 +26,7 @@ import io.codechicken.diffpatch.util.Input.MultiInput; import io.codechicken.diffpatch.util.Output.MultiOutput; import io.codechicken.diffpatch.util.archiver.ArchiveFormat; -import net.minecraftforge.mcmaven.impl.GlobalOptions; +import net.minecraftforge.mcmaven.impl.Mavenizer; import net.minecraftforge.mcmaven.impl.cache.Cache; import net.minecraftforge.mcmaven.impl.cache.MavenCache; import net.minecraftforge.mcmaven.impl.repo.mcpconfig.MCP; @@ -42,7 +41,7 @@ import net.minecraftforge.mcmaven.impl.util.ProcessUtils; import net.minecraftforge.mcmaven.impl.util.Task; import net.minecraftforge.mcmaven.impl.util.Util; -import net.minecraftforge.util.logging.Log; +import static net.minecraftforge.mcmaven.impl.Mavenizer.LOGGER; import org.jetbrains.annotations.Nullable; // TODO: [MCMavenizer] This class needs to be split off into some sort of abstract class so that other patching processes can be implemented. @@ -336,7 +335,7 @@ private File extractJoinedFiles(String filename, List files) { if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); if (output.exists()) output.delete(); @@ -384,7 +383,7 @@ private File extractSingleTask(String key, String value) { if (target.exists() && cache.isSame()) return target; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); try (var zip = new ZipFile(this.data)) { var entry = zip.getEntry(value); @@ -421,7 +420,7 @@ public static File modifyAccess(File globalBase, Task inputTask, File cfg, Cache if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); var args = List.of( "--inJar", input.getAbsolutePath(), @@ -429,9 +428,12 @@ public static File modifyAccess(File globalBase, Task inputTask, File cfg, Cache "--outJar", output.getAbsolutePath() ); - var jdk = dlCache.jdks().get(Constants.ACCESS_TRANSFORMER_JAVA_VERSION); - if (jdk == null) - throw new IllegalStateException("Failed to find JDK for version " + Constants.ACCESS_TRANSFORMER_JAVA_VERSION); + File jdk; + try { + jdk = dlCache.jdks().get(Constants.ACCESS_TRANSFORMER_JAVA_VERSION); + } catch (Exception e) { + throw new IllegalStateException("Failed to find JDK for version " + Constants.ACCESS_TRANSFORMER_JAVA_VERSION, e); + } var ret = ProcessUtils.runJar(jdk, globalBase, log, tool, Collections.emptyList(), args); if (ret.exitCode != 0) @@ -454,7 +456,7 @@ public static File stripSides(File globalBase, Task inputTask, File cfg, Cache d if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); var args = new ArrayList(); args.add("--strip"); @@ -465,9 +467,12 @@ public static File stripSides(File globalBase, Task inputTask, File cfg, Cache d args.add("--output"); args.add(output.getAbsolutePath()); - var jdk = dlCache.jdks().get(Constants.SIDE_STRIPPER_JAVA_VERSION); - if (jdk == null) - throw new IllegalStateException("Failed to find JDK for version " + Constants.SIDE_STRIPPER_JAVA_VERSION); + File jdk; + try { + jdk = dlCache.jdks().get(Constants.SIDE_STRIPPER_JAVA_VERSION); + } catch (Exception e) { + throw new IllegalStateException("Failed to find JDK for version " + Constants.SIDE_STRIPPER_JAVA_VERSION, e); + } var ret = ProcessUtils.runJar(jdk, globalBase, log, tool, Collections.emptyList(), args); if (ret.exitCode != 0) @@ -528,7 +533,7 @@ private File postProcess(Task inputTask, PatcherConfig.V2.DataFunction data, Fil if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); var args = new ArrayList(); for (var arg : data.getArgs()) @@ -536,10 +541,12 @@ private File postProcess(Task inputTask, PatcherConfig.V2.DataFunction data, Fil int java_version = data.getJavaVersion(this.getMCP().getConfig()); var jdks = this.getMCP().getCache().jdks(); - var jdk = jdks.get(java_version); - if (jdk == null) - throw new IllegalStateException("Failed to find JDK for version " + java_version); - + File jdk; + try { + jdk = jdks.get(java_version); + } catch (Exception e) { + throw new IllegalStateException("Failed to find JDK for version " + java_version, e); + } var ret = ProcessUtils.runJar(jdk, log.getParentFile(), log, tool, data.getJvmArgs(), args); if (ret.exitCode != 0) @@ -568,10 +575,10 @@ private File patch(Task inputTask, File output, File rejects) { if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); var builder = PatchOperation.builder() - .logTo(Log::error) + .logTo(LOGGER::error) .baseInput(MultiInput.archive(ArchiveFormat.ZIP, input.toPath())) .patchesInput(MultiInput.archive(ArchiveFormat.ZIP, this.data.toPath())) .patchedOutput(MultiOutput.archive(ArchiveFormat.ZIP, output.toPath())) @@ -592,9 +599,9 @@ private File patch(Task inputTask, File output, File rejects) { boolean success = result.exit == 0; if (!success) { if (result.summary != null) - result.summary.print(Log.ERROR, true); + result.summary.print(LOGGER.getError(), true); else - Log.error("Failed to apply patches, no summary available"); + LOGGER.error("Failed to apply patches, no summary available"); throw except("Failed to apply patches, rejects saved to: " + rejects.getAbsolutePath()); } @@ -628,7 +635,7 @@ private File injectSourcesImpl(Task inputTask, File output) { if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); try { FileUtils.mergeJars(output, false, diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MCPConfigRepo.java b/src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MCPConfigRepo.java index 044baed..6bbdeac 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MCPConfigRepo.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MCPConfigRepo.java @@ -4,7 +4,7 @@ */ package net.minecraftforge.mcmaven.impl.repo.mcpconfig; -import net.minecraftforge.mcmaven.impl.GlobalOptions; +import net.minecraftforge.mcmaven.impl.Mavenizer; import net.minecraftforge.mcmaven.impl.repo.Repo; import net.minecraftforge.mcmaven.impl.tasks.RecompileTask; import net.minecraftforge.mcmaven.impl.tasks.RenameTask; @@ -123,7 +123,7 @@ public List process(Artifact artifact, Mappings mappings) { var sources = pending("Sources", sourcesTask, name.withClassifier("sources"), true, sourceVariant(mappings)); var classes = pending("Classes", classesTask, name, false, () -> classVariants(mappings, mcpSide)); - var metadata = pending("Metadata", metadata(build, mcpSide), name.withClassifier("metadata").withExtension("zip"), false); + var metadata = pending("Metadata", metadata(build, mcpSide), name.withClassifier("metadata").withExtension("zip"), false, metadataVariant()); var pom = pending("Maven POM", pom(build, side, mcpSide, version), name.withExtension("pom"), false); pending.addAll(List.of( @@ -168,7 +168,7 @@ private static Task mergeExtra(File build, String side, Task recompiled, Task ex if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); try { FileUtils.mergeJars(output, true, extraF, recompiledF); @@ -183,7 +183,7 @@ private static Task mergeExtra(File build, String side, Task recompiled, Task ex private static Task metadata(File build, MCPSide side) { var minecraftTasks = side.getMCP().getMinecraftTasks(); - return Task.named("metadata[forge]", Task.deps(minecraftTasks.versionJson), () -> { + return Task.named("metadata[" + side + ']', Task.deps(minecraftTasks.versionJson), () -> { var output = new File(build, "metadata.zip"); // metadata @@ -201,7 +201,7 @@ private static Task metadata(File build, MCPSide side) { if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); try { FileUtils.ensureParent(output); @@ -240,7 +240,7 @@ private static Task pom(File build, String side, MCPSide mcpSide, String version if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); var builder = new POMBuilder("net.minecraft", side, version).preferGradleModule().dependencies(dependencies -> { mcpSide.forAllLibraries(dependencies::add, Artifact::hasNoOs); @@ -265,7 +265,7 @@ private static Task pomExtra(File build, String side, String version) { if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); var builder = new POMBuilder("net.minecraft", side, version); diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MCPTaskFactory.java b/src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MCPTaskFactory.java index 842f72a..e9126b0 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MCPTaskFactory.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MCPTaskFactory.java @@ -23,7 +23,6 @@ import java.util.Set; import java.util.TreeSet; import java.util.function.BiPredicate; -import java.util.function.Supplier; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.jar.JarInputStream; @@ -41,11 +40,10 @@ import io.codechicken.diffpatch.util.Input.MultiInput; import io.codechicken.diffpatch.util.Output.MultiOutput; import io.codechicken.diffpatch.util.archiver.ArchiveFormat; -import net.minecraftforge.mcmaven.impl.GlobalOptions; +import net.minecraftforge.mcmaven.impl.Mavenizer; import net.minecraftforge.mcmaven.impl.cache.MavenCache; import net.minecraftforge.mcmaven.impl.util.Artifact; import net.minecraftforge.mcmaven.impl.util.Constants; -import net.minecraftforge.util.data.OS; import net.minecraftforge.util.data.json.JsonData; import net.minecraftforge.util.data.json.MCPConfig; import net.minecraftforge.util.file.FileUtils; @@ -54,8 +52,7 @@ import net.minecraftforge.mcmaven.impl.util.Task; import net.minecraftforge.mcmaven.impl.util.Util; import net.minecraftforge.srgutils.IMappingFile; -import net.minecraftforge.util.logging.Log; -import org.jetbrains.annotations.NotNull; +import static net.minecraftforge.mcmaven.impl.Mavenizer.LOGGER; import org.jetbrains.annotations.Nullable; // TODO [MCMavenizer][Documentation] Document @@ -245,7 +242,7 @@ public Task findStep(String name) { var ret = this.tasks.get(name); if (ret == null) - throw except("Unknown task `" + name + "`"); + throw except("Unknown task `" + name + '`'); return ret; } @@ -281,7 +278,7 @@ private File extractSingle(String key, String value) { if (target.exists() && cache.isSame()) return target; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); try (var zip = new ZipFile(getData())) { var entry = zip.getEntry(value); @@ -328,7 +325,7 @@ private File extractFolder(String key, String value) { FileUtils.ensureParent(target); if (!target.exists() || !same) { - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); try (var os = new FileOutputStream(target)) { zip.getInputStream(e).transferTo(os); } @@ -380,8 +377,8 @@ private Task createTask(Map step) { if (spec >= 2) { switch (type) { - case "downloadClientMappings": return mc.versionFile("client_mappings", "txt"); - case "downloadServerMappings": return mc.versionFile("server_mappings", "txt"); + case "downloadClientMappings": return downloadClientMappings(); + case "downloadServerMappings": return downloadServerMappings(); } } @@ -393,6 +390,14 @@ private Task createTask(Map step) { return execute(name, step, custom); } + public Task downloadClientMappings() { + return this.side.getMCP().getMinecraftTasks().versionFile("client_mappings", "txt"); + } + + public Task downloadServerMappings() { + return this.side.getMCP().getMinecraftTasks().versionFile("server_mappings", "txt"); + } + private Task strip(String name, Map step) { var whitelist = "whitelist".equalsIgnoreCase(step.getOrDefault("mode", "whitelist")); var output = new File(this.build, name + ".jar").getAbsoluteFile(); @@ -414,7 +419,7 @@ private File strip(Task inputTask, boolean whitelist, File output) { if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); if (output.exists()) output.delete(); @@ -467,7 +472,7 @@ private File inject(Task inputTask, Task injectTask, File packages, File output) if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); if (output.exists()) output.delete(); @@ -542,10 +547,10 @@ private File patch(Task inputTask, Task patchesTask, File output, File rejects) if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); var builder = PatchOperation.builder() - .logTo(Log::error) + .logTo(LOGGER::error) .baseInput(MultiInput.archive(ArchiveFormat.ZIP, input.toPath())) .patchesInput(MultiInput.folder(patches.toPath())) .patchedOutput(MultiOutput.archive(ArchiveFormat.ZIP, output.toPath())) @@ -565,9 +570,9 @@ private File patch(Task inputTask, Task patchesTask, File output, File rejects) boolean success = result.exit == 0; if (!success) { if (result.summary != null) - result.summary.print(Log.ERROR, true); + result.summary.print(LOGGER.getError(), true); else - Log.error("Failed to apply patches, no summary available"); + LOGGER.error("Failed to apply patches, no summary available"); throw except("Failed to apply patches, Rejects saved to: " + rejects.getAbsolutePath()); } @@ -600,11 +605,17 @@ private File listLibraries(Task jsonTask, File output) { cache.addKnown(lib.coord, lib.dl.sha1); if (output.exists() && libsVarCache.exists() && cache.isSame()) { - this.libraries = JsonData.>fromJson(libsVarCache, new TypeToken<>() { }).stream().map(Lib.Cached::resolve).toList(); - return output; + try { + this.libraries = JsonData.>fromJson(libsVarCache, new TypeToken<>() { }).stream().map(Lib.Cached::resolve).toList(); + return output; + } catch (Exception e) { + LOGGER.error("Failed to load cached libraries, regenerating..."); + LOGGER.error("Cached file: " + libsVarCache.getAbsolutePath()); + e.printStackTrace(LOGGER.getError()); + } } - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); cache.clear().add(jsonF); var buf = new StringBuilder(20_000); @@ -618,9 +629,7 @@ private File listLibraries(Task jsonTask, File output) { buf.append("-e=").append(target.getAbsolutePath()).append('\n'); - var artifact = Artifact.from(lib.coord); - if (lib.os != null && lib.os != OS.UNKNOWN) - artifact = artifact.withOS(lib.os); + var artifact = Artifact.from(lib.coord).withOS(lib.os); downloadedLibs.add(new Lib(artifact, target)); cache.add(lib.coord, target); @@ -714,7 +723,7 @@ public int compareTo(LibLine o) { if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); cache.clear().add(bundle); var buf = new StringBuilder(); @@ -776,7 +785,7 @@ private File getExtra(Task prestripTask, Task mappingsTask) { if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); try { var whitelist = IMappingFile @@ -841,13 +850,16 @@ private File execute(List jvmArgs, List runArgs, MCPConfig if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); int java_version = func.getJavaVersion(this.side.getMCP().getConfig()); var jdks = this.side.getMCP().getCache().jdks(); - var jdk = jdks.get(java_version); - if (jdk == null) - throw new IllegalStateException("Failed to find JDK for version " + java_version); + File jdk; + try { + jdk = jdks.get(java_version); + } catch (Exception e) { + throw new IllegalStateException("Failed to find JDK for version " + java_version, e); + } var ret = ProcessUtils.runJar(jdk, log.getParentFile(), log, tool, jvm, run); if (ret.exitCode != 0) diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MinecraftTasks.java b/src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MinecraftTasks.java index d01ba0d..ed0b179 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MinecraftTasks.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MinecraftTasks.java @@ -9,7 +9,7 @@ import java.util.HashMap; import java.util.Map; -import net.minecraftforge.mcmaven.impl.GlobalOptions; +import net.minecraftforge.mcmaven.impl.Mavenizer; import net.minecraftforge.mcmaven.impl.util.Constants; import net.minecraftforge.mcmaven.impl.util.Util; import net.minecraftforge.util.data.json.JsonData; @@ -40,10 +40,10 @@ public class MinecraftTasks { private File downloadLauncherManifest() { var target = new File(this.cache, "launcher_manifest.json"); - if (!target.exists() || (!GlobalOptions.isCacheOnly() && target.lastModified() < System.currentTimeMillis() - Constants.CACHE_TIMEOUT)) { + if (!target.exists() || (!Mavenizer.isCacheOnly() && target.lastModified() < System.currentTimeMillis() - Constants.CACHE_TIMEOUT)) { try { - GlobalOptions.assertNotCacheOnly(); - GlobalOptions.assertOnline(); + Mavenizer.assertNotCacheOnly(); + Mavenizer.assertOnline(); DownloadUtils.downloadFile(target, Constants.LAUNCHER_MANIFEST); } catch (IOException e) { Util.sneak(e); @@ -63,8 +63,8 @@ private File downloadVersionJson() { if (target.exists() && cache.isSame()) return target; - GlobalOptions.assertNotCacheOnly(); - GlobalOptions.assertOnline(); + Mavenizer.assertNotCacheOnly(); + Mavenizer.assertOnline(); var manifest = JsonData.launcherManifest(manifestF); var url = manifest.getUrl(this.version); @@ -72,7 +72,7 @@ private File downloadVersionJson() { throw new IllegalStateException("Failed to find url for " + this.version + " version.json"); try { - DownloadUtils.downloadFile(false, target, url.toExternalForm()); + DownloadUtils.downloadFile(target, url.toExternalForm()); } catch (IOException e) { throw new IllegalStateException("Failed to download " + url, e); } @@ -99,8 +99,8 @@ private File downloadVersionFile(String key, String ext) { if (target.exists() && cache.isSame()) return target; - GlobalOptions.assertNotCacheOnly(); - GlobalOptions.assertOnline(); + Mavenizer.assertNotCacheOnly(); + Mavenizer.assertOnline(); var manifest = JsonData.minecraftVersion(manifestF); var dl = manifest.getDownload(key); diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/tasks/MCPNames.java b/src/main/java/net/minecraftforge/mcmaven/impl/tasks/MCPNames.java index 9fb3a2b..6982d39 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/tasks/MCPNames.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/tasks/MCPNames.java @@ -6,7 +6,7 @@ import de.siegmar.fastcsv.reader.CsvReader; import net.minecraftforge.util.hash.HashFunction; -import net.minecraftforge.util.logging.Log; +import static net.minecraftforge.mcmaven.impl.Mavenizer.LOGGER; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.tuple.Pair; import org.jetbrains.annotations.Nullable; @@ -215,7 +215,7 @@ private boolean injectJavadoc(List lines, String line, String _package, if (len == value.getRight()) { innerClasses.pop(); } else if (len < value.getRight()) { - Log.error("Failed to properly track class blocks around class " + value.getLeft() + ":" + (lines.size() + 1)); + LOGGER.error("Failed to properly track class blocks around class " + value.getLeft() + ":" + (lines.size() + 1)); return false; } } diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/tasks/RecompileTask.java b/src/main/java/net/minecraftforge/mcmaven/impl/tasks/RecompileTask.java index 7394dd4..fd58b56 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/tasks/RecompileTask.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/tasks/RecompileTask.java @@ -4,7 +4,7 @@ */ package net.minecraftforge.mcmaven.impl.tasks; -import net.minecraftforge.mcmaven.impl.GlobalOptions; +import net.minecraftforge.mcmaven.impl.Mavenizer; import net.minecraftforge.mcmaven.impl.mappings.Mappings; import net.minecraftforge.mcmaven.impl.repo.mcpconfig.MCP; import net.minecraftforge.mcmaven.impl.util.Artifact; @@ -14,7 +14,6 @@ import java.io.File; import java.util.List; -import java.util.Set; import java.util.function.Supplier; /** @@ -72,11 +71,13 @@ private File recompileSourcesImpl(Task inputTask, File outputJar) { if (outputJar.exists() && cache.isSame()) return outputJar; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); - var jdk = this.mcp.getCache().jdks().get(javaTarget); - if (jdk == null) { - throw new IllegalStateException("JDK not found: " + javaTarget); + File jdk; + try { + jdk = this.mcp.getCache().jdks().get(javaTarget); + } catch (Exception e) { + throw new IllegalStateException("JDK not found: " + javaTarget, e); } ProcessUtils.recompileJar(jdk, this.classpath.get(), sourcesJar, outputJar, this.build); diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/tasks/RenameTask.java b/src/main/java/net/minecraftforge/mcmaven/impl/tasks/RenameTask.java index e22a4bb..b2534e7 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/tasks/RenameTask.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/tasks/RenameTask.java @@ -4,7 +4,7 @@ */ package net.minecraftforge.mcmaven.impl.tasks; -import net.minecraftforge.mcmaven.impl.GlobalOptions; +import net.minecraftforge.mcmaven.impl.Mavenizer; import net.minecraftforge.mcmaven.impl.mappings.Mappings; import net.minecraftforge.mcmaven.impl.repo.mcpconfig.MCPSide; import net.minecraftforge.util.file.FileUtils; @@ -90,7 +90,7 @@ private static File remapSourcesImpl(Task inputTask, Task mappingsTask, File out if (output.exists() && cache.isSame()) return output; - GlobalOptions.assertNotCacheOnly(); + Mavenizer.assertNotCacheOnly(); try { var names = MCPNames.load(mappings); diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/util/Arch.java b/src/main/java/net/minecraftforge/mcmaven/impl/util/Arch.java deleted file mode 100644 index a56139f..0000000 --- a/src/main/java/net/minecraftforge/mcmaven/impl/util/Arch.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) Forge Development LLC and contributors - * SPDX-License-Identifier: LGPL-2.1-only - */ -package net.minecraftforge.mcmaven.impl.util; - -// TODO Always warn on unknown OS - -import java.util.Locale; - -/** - * Enum representing the operating system. - */ -public enum Arch { - X86 ("x86", "i386", "i686"), - X86_64 ("x86_64", "x64", "amd64"), - ARM ("arm", "aarch32", "aarch_32"), - ARM64 ("arm64", "aarch64", "aarch_64"), - UNKNOWN("unknown"); - - private static final Arch[] $values = values(); - /** The operating system that this tool is being run on. */ - public static final Arch CURRENT = getCurrent(); - - private final String key; - private final String[] names; - - Arch(String... names) { - this.key = names[0]; - this.names = names; - } - - /** - * The primary name, and enum key, of the operating system. - * - * @return The primary name - */ - public String key() { - return this.key; - } - - /** - * Returns the OS enum for the given key. - * - * @param key The key to search for - * @return The OS enum, or null if not found - */ - public static Arch byKey(String key) { - for (Arch value : $values) { - if (value.key.equals(key)) - return value; - } - - return UNKNOWN; - } - - public static Arch byName(String name) { - for (Arch value : $values) { - for (String n : value.names) { - if (n.equals(name)) - return value; - } - } - - return UNKNOWN; - } - - private static Arch getCurrent() { - String prop = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH); - for (Arch os : $values) { - for (String key : os.names) { - if (prop.contains(key)) return os; - } - } - - return UNKNOWN; - } -} diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/util/Artifact.java b/src/main/java/net/minecraftforge/mcmaven/impl/util/Artifact.java index 86d1abe..802932b 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/util/Artifact.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/util/Artifact.java @@ -4,12 +4,14 @@ */ package net.minecraftforge.mcmaven.impl.util; -import net.minecraftforge.util.data.OS; +import net.minecraftforge.util.os.OS; +import net.minecraftforge.util.os.Arch; import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.Serial; import java.io.Serializable; +import java.util.EnumSet; import java.util.Locale; import java.util.Objects; import java.util.regex.Pattern; @@ -27,7 +29,7 @@ public class Artifact implements Comparable, Serializable { private final @Nullable String version; private final @Nullable String classifier; private final String ext; - private final OS os; + private final EnumSet os; private final Arch arch; // Cached after building the first time we're asked @@ -106,7 +108,7 @@ private Artifact(String descriptor) { this.version = pts.length > 2 ? pts[2] : null; this.classifier = pts.length > 3 ? pts[3] : null; - this.os = this.classifier != null ? findOS(this.classifier) : OS.UNKNOWN; + this.os = this.classifier != null ? findOS(this.classifier) : EnumSet.noneOf(OS.class); this.arch = this.classifier != null ? findArch(this.classifier) : Arch.UNKNOWN; } @@ -116,21 +118,31 @@ private Artifact(String group, String name, String version, @Nullable String cla this.version = version; this.classifier = classifier; this.ext = Objects.requireNonNullElse(ext, "jar"); - this.os = os == OS.UNKNOWN && classifier != null ? findOS(classifier) : os; + this.os = classifier != null ? findOS(classifier) : os == OS.UNKNOWN ? EnumSet.noneOf(OS.class) : EnumSet.of(os); this.arch = arch == Arch.UNKNOWN && classifier != null ? findArch(classifier) : arch; } - private static OS findOS(String classifier) { + private Artifact(String group, String name, String version, @Nullable String classifier, @Nullable String ext, EnumSet os, Arch arch) { + this.group = group; + this.name = name; + this.version = version; + this.classifier = classifier; + this.ext = Objects.requireNonNullElse(ext, "jar"); + this.os = os; + this.arch = arch == Arch.UNKNOWN && classifier != null ? findArch(classifier) : arch; + } + + private static EnumSet findOS(String classifier) { for (var s : classifier.split("-")) { if (s.isBlank()) continue; var osCandidate = OS.byName(s); if (osCandidate != OS.UNKNOWN) { - return osCandidate; + return EnumSet.of(osCandidate); } } - return OS.UNKNOWN; + return EnumSet.noneOf(OS.class); } private static Arch findArch(String classifier) { @@ -216,12 +228,12 @@ public String getExtension() { } /** @return The os of this artifact (defaults to {@link OS#UNKNOWN}) */ - public OS getOs() { + public EnumSet getOs() { return os; } public boolean hasNoOs() { - return this.os == OS.UNKNOWN; + return this.os.isEmpty(); } /** @return The arch of this artifact (defaults to {@link Arch#UNKNOWN}) */ @@ -274,6 +286,10 @@ public Artifact withOS(OS os) { return new Artifact(group, name, version, classifier, ext, os, arch); } + public Artifact withOS(EnumSet os) { + return new Artifact(group, name, version, classifier, ext, os, arch); + } + public Artifact withArch(Arch arch) { return new Artifact(group, name, version, classifier, ext, os, arch); } diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/util/GradleAttributes.java b/src/main/java/net/minecraftforge/mcmaven/impl/util/GradleAttributes.java index fddd405..53cea58 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/util/GradleAttributes.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/util/GradleAttributes.java @@ -5,7 +5,7 @@ package net.minecraftforge.mcmaven.impl.util; import net.minecraftforge.mcmaven.impl.data.GradleModule; -import net.minecraftforge.util.data.OS; +import net.minecraftforge.util.os.OS; import org.jetbrains.annotations.Nullable; import java.util.Locale; @@ -24,12 +24,13 @@ public String getValue() { return this.name().toLowerCase(Locale.ROOT); } - public static @Nullable OperatingSystemFamily from(OS os) { + public static @Nullable OperatingSystemFamily from(@Nullable OS os) { return switch (os) { case WINDOWS -> WINDOWS; case MACOS -> MACOS; - case LINUX, ALPINE, MUSL -> LINUX; - case null, default -> null; + case null -> null; + case UNKNOWN -> null; + default -> LINUX; }; } } diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/util/ProcessUtils.java b/src/main/java/net/minecraftforge/mcmaven/impl/util/ProcessUtils.java index ab1c448..864a4a5 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/util/ProcessUtils.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/util/ProcessUtils.java @@ -4,9 +4,9 @@ */ package net.minecraftforge.mcmaven.impl.util; -import net.minecraftforge.java_provisioner.util.OS; +import net.minecraftforge.util.os.OS; import net.minecraftforge.util.file.FileUtils; -import net.minecraftforge.util.logging.Log; +import static net.minecraftforge.mcmaven.impl.Mavenizer.LOGGER; import org.apache.commons.io.IOUtils; import java.io.BufferedReader; @@ -114,7 +114,7 @@ public static int runCommand(Consumer lines, String... args) { * @return The exit code of the process */ public static int runCommand(File workDir, Consumer lines, String... args) { - Log.debug("Running Command: " + String.join(" ", args)); + LOGGER.debug("Running Command: " + String.join(" ", args)); Process process; try { @@ -189,9 +189,9 @@ public static Result runJar(File javaHome, File workDir, File logFile, File tool classpath += File.pathSeparator + classes.getAbsolutePath(); var main = getMainClass(tool); - var launcher = new File(javaHome, "bin/java" + OS.CURRENT.exe()); + var launcher = new File(javaHome, "bin/java" + OS.current().exe()); Consumer lines = line -> { - Log.quiet(line); + LOGGER.quiet(line); log.println(line); }; lines.accept("Java: " + launcher.getAbsolutePath()); @@ -284,10 +284,10 @@ public static File recompileJar(File javaHome, List classpath, File source var process = ProcessUtils.runJavac(javaHome, workDir, new File(outputJar.getAbsolutePath() + ".log"), args); if (process.exitCode != 0) { - Log.error("Javac failed to execute! Exit code " + process.exitCode); - Log.error("--- BEGIN JAVAC LOG ---"); - process.lines.forEach(Log::error); - Log.error("--- END JAVAC LOG ---"); + LOGGER.error("Javac failed to execute! Exit code " + process.exitCode); + LOGGER.error("--- BEGIN JAVAC LOG ---"); + process.lines.forEach(LOGGER::error); + LOGGER.error("--- END JAVAC LOG ---"); throw new RuntimeException("Javac failed to execute! Exit code " + process.exitCode); } @@ -335,9 +335,9 @@ private static Result runJavac(File javaHome, File workDir, File logFile, List lines = line -> { - Log.quiet(line); + LOGGER.quiet(line); log.println(line); }; lines.accept("Java Compiler: " + launcher.getAbsolutePath()); diff --git a/src/main/java/net/minecraftforge/mcmaven/impl/util/Task.java b/src/main/java/net/minecraftforge/mcmaven/impl/util/Task.java index b868dcf..ec2b25f 100644 --- a/src/main/java/net/minecraftforge/mcmaven/impl/util/Task.java +++ b/src/main/java/net/minecraftforge/mcmaven/impl/util/Task.java @@ -4,7 +4,7 @@ */ package net.minecraftforge.mcmaven.impl.util; -import net.minecraftforge.util.logging.Log; +import static net.minecraftforge.mcmaven.impl.Mavenizer.LOGGER; import java.io.File; import java.time.Duration; @@ -103,19 +103,19 @@ public File execute() { } } - Log.info(name); - var indent = Log.push(); + LOGGER.info(name); + var indent = LOGGER.push(); var start = System.nanoTime(); try { this.file = supplier.call(); var time = Duration.ofNanos(System.nanoTime() - start); - Log.debug(String.format("-> took %d:%02d.%03d", time.toMinutesPart(), time.toSecondsPart(), time.toMillisPart())); - Log.debug("-> " + this.file.getAbsolutePath()); + LOGGER.debug(String.format("-> took %d:%02d.%03d", time.toMinutesPart(), time.toSecondsPart(), time.toMillisPart())); + LOGGER.debug("-> " + this.file.getAbsolutePath()); } catch (Exception e) { throw new RuntimeException("Failed to execute task `%s`".formatted(this.name()), e); } finally { - Log.pop(indent); + LOGGER.pop(indent); } }