diff --git a/common/src/main/java/net/neoforged/gradle/common/extensions/subsystems/SubsystemsExtension.java b/common/src/main/java/net/neoforged/gradle/common/extensions/subsystems/SubsystemsExtension.java index 2a2f008a5..4864fafd8 100644 --- a/common/src/main/java/net/neoforged/gradle/common/extensions/subsystems/SubsystemsExtension.java +++ b/common/src/main/java/net/neoforged/gradle/common/extensions/subsystems/SubsystemsExtension.java @@ -1,14 +1,18 @@ package net.neoforged.gradle.common.extensions.subsystems; import net.minecraftforge.gdi.ConfigurableDSLElement; +import net.neoforged.gradle.dsl.common.extensions.subsystems.DecompilerLogLevel; import net.neoforged.gradle.dsl.common.extensions.subsystems.Subsystems; +import org.gradle.api.GradleException; import org.gradle.api.Project; import org.gradle.api.provider.ProviderFactory; import javax.inject.Inject; import java.util.Arrays; +import java.util.Locale; public abstract class SubsystemsExtension implements ConfigurableDSLElement, Subsystems { + private static final String PROPERTY_PREFIX = "neogradle.subsystems."; private final Project project; @Inject @@ -16,10 +20,16 @@ public SubsystemsExtension(Project project) { this.project = project; ProviderFactory providers = project.getProviders(); - getDecompiler().getMaxMemory().convention(providers.gradleProperty("neogradle.subsystems.decompiler.maxMemory")); - getDecompiler().getMaxThreads().convention(providers.gradleProperty("neogradle.subsystems.decompiler.maxThreads").map(Integer::parseUnsignedInt)); - getDecompiler().getLogLevel().convention(providers.gradleProperty("neogradle.subsystems.decompiler.logLevel")); - getDecompiler().getJvmArgs().convention(providers.gradleProperty("neogradle.subsystems.decompiler.jvmArgs").map(s -> Arrays.asList(s.split("\\s+")))); + getDecompiler().getMaxMemory().convention(providers.gradleProperty(PROPERTY_PREFIX + "decompiler.maxMemory")); + getDecompiler().getMaxThreads().convention(providers.gradleProperty(PROPERTY_PREFIX + "decompiler.maxThreads").map(Integer::parseUnsignedInt)); + getDecompiler().getLogLevel().convention(providers.gradleProperty(PROPERTY_PREFIX + "decompiler.logLevel").map(s -> { + try { + return DecompilerLogLevel.valueOf(s.toUpperCase(Locale.ROOT)); + } catch (Exception e) { + throw new GradleException("Unknown DecompilerLogLevel: " + s + ". Available options: " + Arrays.toString(DecompilerLogLevel.values())); + } + })); + getDecompiler().getJvmArgs().convention(providers.gradleProperty(PROPERTY_PREFIX + "decompiler.jvmArgs").map(s -> Arrays.asList(s.split("\\s+")))); } @Override diff --git a/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/extensions/subsystems/Decompiler.groovy b/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/extensions/subsystems/Decompiler.groovy index 41f8c4a72..952630cdc 100644 --- a/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/extensions/subsystems/Decompiler.groovy +++ b/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/extensions/subsystems/Decompiler.groovy @@ -34,12 +34,12 @@ interface Decompiler extends ConfigurableDSLElement { /** * The log-level to use for the decompiler. Supported values: info, debug, warn, error. - * Defaults to info. + * Defaults to {@link DecompilerLogLevel#INFO}. */ @Input @Optional @DSLProperty - Property getLogLevel(); + Property getLogLevel(); /** * Allows additional JVM arguments to be added to the decompiler invocation. diff --git a/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/extensions/subsystems/DecompilerLogLevel.groovy b/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/extensions/subsystems/DecompilerLogLevel.groovy new file mode 100644 index 000000000..9e42283fe --- /dev/null +++ b/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/extensions/subsystems/DecompilerLogLevel.groovy @@ -0,0 +1,8 @@ +package net.neoforged.gradle.dsl.common.extensions.subsystems + +enum DecompilerLogLevel { + TRACE, + INFO, + WARN, + ERROR +} diff --git a/neoform/src/main/java/net/neoforged/gradle/neoform/runtime/extensions/NeoFormRuntimeExtension.java b/neoform/src/main/java/net/neoforged/gradle/neoform/runtime/extensions/NeoFormRuntimeExtension.java index 4b4c06d77..f2d01227f 100644 --- a/neoform/src/main/java/net/neoforged/gradle/neoform/runtime/extensions/NeoFormRuntimeExtension.java +++ b/neoform/src/main/java/net/neoforged/gradle/neoform/runtime/extensions/NeoFormRuntimeExtension.java @@ -13,6 +13,7 @@ import net.neoforged.gradle.dsl.common.extensions.Minecraft; import net.neoforged.gradle.dsl.common.extensions.MinecraftArtifactCache; import net.neoforged.gradle.dsl.common.extensions.subsystems.Decompiler; +import net.neoforged.gradle.dsl.common.extensions.subsystems.DecompilerLogLevel; import net.neoforged.gradle.dsl.common.extensions.subsystems.Subsystems; import net.neoforged.gradle.dsl.common.runtime.naming.TaskBuildingContext; import net.neoforged.gradle.dsl.common.runtime.tasks.Runtime; @@ -38,6 +39,7 @@ import net.neoforged.gradle.neoform.util.NeoFormRuntimeUtils; import net.neoforged.gradle.util.CopyingFileTreeVisitor; import org.apache.commons.lang3.StringUtils; +import org.gradle.api.GradleException; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; @@ -157,7 +159,7 @@ private static TaskProvider createDecompile(NeoFormRuntimeSpe Decompiler settings = spec.getProject().getExtensions().getByType(Subsystems.class).getDecompiler(); String maxMemory = settings.getMaxMemory().getOrElse(defaultMaxMemory); int maxThreads = settings.getMaxThreads().getOrElse(0); - String logLevel = settings.getLogLevel().getOrElse("INFO"); + String logLevel = getDecompilerLogLevelArg(settings.getLogLevel().getOrElse(DecompilerLogLevel.INFO), function.getVersion()); if (settings.getJvmArgs().isPresent()) { jvmArgs.addAll(settings.getJvmArgs().get()); @@ -175,6 +177,21 @@ private static TaskProvider createDecompile(NeoFormRuntimeSpe }); } + private static String getDecompilerLogLevelArg(DecompilerLogLevel logLevel, String version) { + switch (logLevel) { + case TRACE: + return "trace"; + case INFO: + return "info"; + case WARN: + return "warn"; + case ERROR: + return "error"; + default: + throw new GradleException("LogLevel " + logLevel + " not supported by " + version); + } + } + private TaskProvider createExecute(final NeoFormRuntimeSpecification spec, final NeoFormConfigConfigurationSpecV1.Step step, final NeoFormConfigConfigurationSpecV1.Function function) { return spec.getProject().getTasks().register(CommonRuntimeUtils.buildTaskName(spec, step.getName()), Execute.class, task -> { task.getExecutingJar().set(ToolUtilities.resolveTool(task.getProject(), function.getVersion()));