Skip to content

Commit

Permalink
Add auto-formatting of Java code with Immaculate
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Jan 1, 2025
1 parent 9163863 commit e25712b
Show file tree
Hide file tree
Showing 81 changed files with 593 additions and 804 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import groovy.transform.TupleConstructor
plugins {
id 'java-gradle-plugin'
id 'maven-publish'
id 'net.neoforged.gradleutils' version '3.0.0'
id 'net.neoforged.gradleutils'
id 'com.gradle.plugin-publish' version '1.2.1'
id 'com.gradleup.shadow' version '8.3.0'
}
Expand Down
11 changes: 10 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@

plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.9.0'
id 'net.neoforged.gradleutils' version '4.0.0' apply false
id 'dev.lukebemish.immaculate' version '0.1.6' apply false
}

rootProject.name = 'moddev-gradle'

gradle.lifecycle.beforeProject { project ->
project.plugins.withId("java") {
apply plugin: 'dev.lukebemish.immaculate'
apply plugin: 'net.neoforged.gradleutils.immaculate'
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package net.neoforged.moddevgradle.boot;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.plugins.PluginAware;
import org.gradle.util.GradleVersion;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* This is just a trampoline to perform the Java and Gradle version check, and is compiled for Java 8 in the real Jar.
*/
Expand All @@ -32,7 +31,7 @@ public final void apply(T target) {

if (GradleVersion.current().compareTo(MIN_GRADLE_VERSION) < 0) {
throw new GradleException("To use the NeoForge plugin, please use at least " + MIN_GRADLE_VERSION
+ ". You are currently using " + GradleVersion.current() + ".");
+ ". You are currently using " + GradleVersion.current() + ".");
}

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package net.neoforged.moddevgradle.legacyforge.dsl;

import javax.inject.Inject;
import net.neoforged.moddevgradle.dsl.DataFileCollection;
import net.neoforged.moddevgradle.dsl.ModDevExtension;
import net.neoforged.moddevgradle.legacyforge.internal.LegacyForgeModDevPlugin;
import org.gradle.api.Action;
import org.gradle.api.Project;

import javax.inject.Inject;

/**
* This is the top-level {@code legacyForge} extension, used to configure the moddev plugin.
*/
Expand All @@ -16,8 +15,8 @@ public abstract class LegacyForgeExtension extends ModDevExtension {

@Inject
public LegacyForgeExtension(Project project,
DataFileCollection accessTransformers,
DataFileCollection interfaceInjectionData) {
DataFileCollection accessTransformers,
DataFileCollection interfaceInjectionData) {
super(project, accessTransformers, interfaceInjectionData);
this.project = project;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package net.neoforged.moddevgradle.legacyforge.dsl;

import java.util.HashSet;
import java.util.Set;
import javax.inject.Inject;
import net.neoforged.moddevgradle.internal.utils.ExtensionUtils;
import org.gradle.api.Project;
import org.gradle.api.tasks.SourceSet;
import org.jetbrains.annotations.Nullable;

import javax.inject.Inject;
import java.util.HashSet;
import java.util.Set;

public abstract class LegacyForgeModdingSettings {
@Nullable
private String neoForgeVersion;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package net.neoforged.moddevgradle.legacyforge.dsl;

import java.util.List;
import javax.inject.Inject;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.process.CommandLineArgumentProvider;

import javax.inject.Inject;
import java.util.List;

abstract class MixinCompilerArgs implements CommandLineArgumentProvider {
@Inject
public MixinCompilerArgs() {
}
public MixinCompilerArgs() {}

@OutputFile
protected abstract RegularFileProperty getOutMappings();
Expand All @@ -36,7 +34,6 @@ public Iterable<String> asArguments() {
"-AoutRefMapFile=" + getRefmap().get().getAsFile().getAbsolutePath(),
"-AmappingTypes=tsrg",
"-ApluginVersion=0.7", // Not sure what this is used for, but MixinGradle gives it to the AP. Latest as of time of writing
"-AdefaultObfuscationEnv=searge"
);
"-AdefaultObfuscationEnv=searge");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.neoforged.moddevgradle.legacyforge.dsl;

import javax.inject.Inject;
import org.gradle.api.Project;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.RegularFile;
Expand All @@ -9,17 +10,15 @@
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.jvm.tasks.Jar;

import javax.inject.Inject;

public abstract class MixinExtension {
private final Project project;
private final Provider<RegularFile> officialToSrg;
private final ConfigurableFileCollection extraMappingFiles;

@Inject
public MixinExtension(Project project,
Provider<RegularFile> officialToSrg,
ConfigurableFileCollection extraMappingFiles) {
Provider<RegularFile> officialToSrg,
ConfigurableFileCollection extraMappingFiles) {
this.project = project;
this.officialToSrg = officialToSrg;
this.extraMappingFiles = extraMappingFiles;
Expand Down Expand Up @@ -54,4 +53,3 @@ public Provider<RegularFile> add(SourceSet sourceSet, String refmap) {
return refMapFile;
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package net.neoforged.moddevgradle.legacyforge.dsl;

import java.util.List;
import java.util.Objects;
import javax.inject.Inject;
import net.neoforged.moddevgradle.legacyforge.internal.MinecraftMappings;
import net.neoforged.moddevgradle.legacyforge.tasks.RemapJar;
import net.neoforged.moddevgradle.legacyforge.tasks.RemapOperation;
Expand All @@ -23,10 +26,6 @@
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
import org.jetbrains.annotations.ApiStatus;

import javax.inject.Inject;
import java.util.List;
import java.util.Objects;

public abstract class ObfuscationExtension {
private final Project project;
private final Configuration autoRenamingToolRuntime;
Expand All @@ -35,9 +34,9 @@ public abstract class ObfuscationExtension {

@Inject
public ObfuscationExtension(Project project,
Configuration autoRenamingToolRuntime,
Configuration installerToolsRuntime,
FileCollection extraMixinMappings) {
Configuration autoRenamingToolRuntime,
Configuration installerToolsRuntime,
FileCollection extraMixinMappings) {
this.project = project;
this.autoRenamingToolRuntime = autoRenamingToolRuntime;
this.installerToolsRuntime = installerToolsRuntime;
Expand Down Expand Up @@ -79,13 +78,12 @@ public void configureSrgToNamedOperation(RemapOperation operation) {
/**
* Create a reobfuscation task.
*
* @param jar the jar task to reobfuscate
* @param sourceSet the source set whose classpath to use when remapping inherited methods
* @param jar the jar task to reobfuscate
* @param sourceSet the source set whose classpath to use when remapping inherited methods
* @return a provider of the created task
*/
public TaskProvider<RemapJar> reobfuscate(TaskProvider<? extends AbstractArchiveTask> jar, SourceSet sourceSet) {
return reobfuscate(jar, sourceSet, ignored -> {
});
return reobfuscate(jar, sourceSet, ignored -> {});
}

/**
Expand All @@ -97,8 +95,8 @@ public TaskProvider<RemapJar> reobfuscate(TaskProvider<? extends AbstractArchive
* @return a provider of the created task
*/
public TaskProvider<RemapJar> reobfuscate(TaskProvider<? extends AbstractArchiveTask> jar,
SourceSet sourceSet,
Action<RemapJar> configureTask) {
SourceSet sourceSet,
Action<RemapJar> configureTask) {
var reobf = project.getTasks().register("reobf" + StringUtils.capitalize(jar.getName()), RemapJar.class, task -> {
task.getInput().set(jar.flatMap(AbstractArchiveTask::getArchiveFile));
task.getDestinationDirectory().convention(task.getProject().getLayout().getBuildDirectory().dir("libs"));
Expand Down Expand Up @@ -139,8 +137,7 @@ public TaskProvider<RemapJar> reobfuscate(TaskProvider<? extends AbstractArchive

// Publish the reobf configuration instead of the original one to Maven
java.withVariantsFromConfiguration(config, ConfigurationVariantDetails::skip);
java.addVariantsFromConfiguration(reobfConfig, spec -> {
});
java.addVariantsFromConfiguration(reobfConfig, spec -> {});
}

return reobf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.List;
import javax.inject.Inject;
import org.gradle.api.Action;
import org.gradle.api.artifacts.CacheableRule;
import org.gradle.api.artifacts.ComponentMetadataContext;
Expand All @@ -14,9 +16,6 @@
import org.gradle.api.attributes.Usage;
import org.gradle.api.model.ObjectFactory;

import javax.inject.Inject;
import java.util.List;

@CacheableRule
class LegacyForgeMetadataTransform extends LegacyMetadataTransform {
@Inject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package net.neoforged.moddevgradle.legacyforge.internal;

import java.net.URI;
import java.util.stream.Stream;
import net.neoforged.minecraftdependencies.MinecraftDependenciesPlugin;
import net.neoforged.moddevgradle.internal.ArtifactNamingStrategy;
import net.neoforged.moddevgradle.internal.Branding;
import net.neoforged.moddevgradle.internal.DataFileCollections;
import net.neoforged.moddevgradle.internal.ModdingDependencies;
import net.neoforged.moddevgradle.internal.jarjar.JarJarPlugin;
import net.neoforged.moddevgradle.internal.ModDevArtifactsWorkflow;
import net.neoforged.moddevgradle.internal.ModDevRunWorkflow;
import net.neoforged.moddevgradle.internal.ModdingDependencies;
import net.neoforged.moddevgradle.internal.RepositoriesPlugin;
import net.neoforged.moddevgradle.internal.jarjar.JarJarPlugin;
import net.neoforged.moddevgradle.internal.utils.ExtensionUtils;
import net.neoforged.moddevgradle.internal.utils.VersionCapabilitiesInternal;
import net.neoforged.moddevgradle.legacyforge.dsl.LegacyForgeExtension;
Expand All @@ -30,9 +32,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.util.stream.Stream;

@ApiStatus.Internal
public class LegacyForgeModDevPlugin implements Plugin<Project> {
private static final Logger LOG = LoggerFactory.getLogger(LegacyForgeModDevPlugin.class);
Expand Down Expand Up @@ -102,8 +101,7 @@ public void apply(Project project) {
LegacyForgeExtension.class,
project,
dataFileCollections.accessTransformers().extension(),
dataFileCollections.interfaceInjectionData().extension()
);
dataFileCollections.interfaceInjectionData().extension());
}

public void enable(Project project, LegacyForgeModdingSettings settings, LegacyForgeExtension extension) {
Expand Down Expand Up @@ -151,15 +149,13 @@ public void enable(Project project, LegacyForgeModdingSettings settings, LegacyF
artifactNamingStrategy,
configurations.getByName(DataFileCollections.CONFIGURATION_ACCESS_TRANSFORMERS),
configurations.getByName(DataFileCollections.CONFIGURATION_INTERFACE_INJECTION_DATA),
versionCapabilities
);
versionCapabilities);

var runs = ModDevRunWorkflow.create(
project,
Branding.MDG,
artifacts,
extension.getRuns()
);
extension.getRuns());

// Configure the mixin and obfuscation extensions
var mixin = ExtensionUtils.getExtension(project, MIXIN_EXTENSION, MixinExtension.class);
Expand All @@ -185,8 +181,7 @@ public void enable(Project project, LegacyForgeModdingSettings settings, LegacyF

var reobfJar = obf.reobfuscate(
project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class),
project.getExtensions().getByType(SourceSetContainer.class).getByName(SourceSet.MAIN_SOURCE_SET_NAME)
);
project.getExtensions().getByType(SourceSetContainer.class).getByName(SourceSet.MAIN_SOURCE_SET_NAME));

project.getTasks().named("assemble", assemble -> assemble.dependsOn(reobfJar));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.jar.JarInputStream;
import org.gradle.api.GradleException;
import org.gradle.api.artifacts.ComponentMetadataContext;
import org.gradle.api.artifacts.ComponentMetadataRule;
import org.gradle.api.artifacts.repositories.RepositoryResourceAccessor;
import org.gradle.api.model.ObjectFactory;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.jar.JarInputStream;

abstract class LegacyMetadataTransform implements ComponentMetadataRule {
protected final ObjectFactory objects;
private final RepositoryResourceAccessor repositoryResourceAccessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import javax.inject.Inject;
import org.gradle.api.Action;
import org.gradle.api.artifacts.CacheableRule;
import org.gradle.api.artifacts.ComponentMetadataContext;
Expand All @@ -11,8 +12,6 @@
import org.gradle.api.attributes.java.TargetJvmVersion;
import org.gradle.api.model.ObjectFactory;

import javax.inject.Inject;

/**
* Given an implicit Metadata object by Gradle (which results from reading in a pom.xml from Maven for MCP data,
* which is basically empty), we build metadata that is equivalent to NeoForms Gradle module metadata.
Expand Down Expand Up @@ -64,8 +63,7 @@ protected void adaptWithConfig(ComponentMetadataContext context, JsonObject conf
});
});

dependencies(context, "mcpRuntimeElements", javaTarget, Usage.JAVA_RUNTIME, deps -> {
});
dependencies(context, "mcpRuntimeElements", javaTarget, Usage.JAVA_RUNTIME, deps -> {});

dependencies(context, "mcpApiElements", javaTarget, Usage.JAVA_API, dependencies -> {
var libraries = config.getAsJsonObject("libraries").getAsJsonArray("joined");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package net.neoforged.moddevgradle.legacyforge.internal;

import java.util.Locale;
import org.gradle.api.Named;
import org.gradle.api.attributes.Attribute;
import org.jetbrains.annotations.ApiStatus;

import java.util.Locale;

@ApiStatus.Internal
public enum MinecraftMappings implements Named {
NAMED,
Expand Down
Loading

0 comments on commit e25712b

Please sign in to comment.