From 8da2da8aed75f05caac19c8b9747041bfd249807 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Tue, 7 Sep 2021 11:55:05 +0100 Subject: [PATCH] Update checkstyle to prevent using var expect for new instance creation. --- checkstyle.xml | 5 ++ .../net/fabricmc/loom/LoomGradlePlugin.java | 2 +- .../nesting/NestedDependencyProvider.java | 3 +- .../configuration/CompileConfiguration.java | 48 ++++++++++--------- .../JarManifestConfiguration.java | 5 +- .../loom/configuration/MavenPublication.java | 3 +- .../providers/MinecraftProviderImpl.java | 2 +- .../mappings/LayeredMappingSpecBuilder.java | 2 +- 8 files changed, 40 insertions(+), 30 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index 9176f4e..e884485 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -158,5 +158,10 @@ + + + + + \ No newline at end of file diff --git a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java index bf52650..df3fe00 100644 --- a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java +++ b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java @@ -78,7 +78,7 @@ public class LoomGradlePlugin implements BootstrappedPlugin { project.apply(ImmutableMap.of("plugin", "idea")); // Setup extensions, minecraft wraps loom - var extension = project.getExtensions().create(LoomGradleExtensionAPI.class, "loom", LoomGradleExtensionImpl.class, project, LoomFiles.create(project)); + LoomGradleExtensionAPI extension = project.getExtensions().create(LoomGradleExtensionAPI.class, "loom", LoomGradleExtensionImpl.class, project, LoomFiles.create(project)); project.getExtensions().create(LoomGradleExtensionAPI.class, "minecraft", MinecraftGradleExtension.class, extension); project.getExtensions().create("fabricApi", FabricApiExtension.class, project); diff --git a/src/main/java/net/fabricmc/loom/build/nesting/NestedDependencyProvider.java b/src/main/java/net/fabricmc/loom/build/nesting/NestedDependencyProvider.java index 0ba7b5a..b211ad7 100644 --- a/src/main/java/net/fabricmc/loom/build/nesting/NestedDependencyProvider.java +++ b/src/main/java/net/fabricmc/loom/build/nesting/NestedDependencyProvider.java @@ -43,6 +43,7 @@ import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; import org.gradle.api.artifacts.DependencySet; import org.gradle.api.artifacts.ProjectDependency; +import org.gradle.api.artifacts.ResolvedArtifact; import org.gradle.api.artifacts.ResolvedConfiguration; import org.gradle.api.artifacts.ResolvedDependency; import org.gradle.api.tasks.bundling.AbstractArchiveTask; @@ -133,7 +134,7 @@ public final class NestedDependencyProvider implements NestedJarProvider { continue; } - for (var artifact : dependency.getModuleArtifacts()) { + for (ResolvedArtifact artifact : dependency.getModuleArtifacts()) { fileList.add(new DependencyInfo<>( dependency, new ResolvedDependencyMetaExtractor(), diff --git a/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java index 81f8bf4..6fc6439 100644 --- a/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java +++ b/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java @@ -139,29 +139,8 @@ public final class CompileConfiguration { MixinExtension mixin = LoomGradleExtension.get(project).getMixin(); - if (!mixin.getUseLegacyMixinAp().get()) { - return; - } - - mixin.init(); - - // Disable some things used by log4j via the mixin AP that prevent it from being garbage collected - System.setProperty("log4j2.disable.jmx", "true"); - System.setProperty("log4j.shutdownHookEnabled", "false"); - System.setProperty("log4j.skipJansi", "true"); - - project.getLogger().info("Configuring compiler arguments for Java"); - - new JavaApInvoker(project).configureMixin(); - - if (project.getPluginManager().hasPlugin("scala")) { - project.getLogger().info("Configuring compiler arguments for Scala"); - new ScalaApInvoker(project).configureMixin(); - } - - if (project.getPluginManager().hasPlugin("org.jetbrains.kotlin.kapt")) { - project.getLogger().info("Configuring compiler arguments for Kapt plugin"); - new KaptApInvoker(project).configureMixin(); + if (mixin.getUseLegacyMixinAp().get()) { + setupMixinAp(project, mixin); } }); @@ -171,6 +150,29 @@ public final class CompileConfiguration { } } + private static void setupMixinAp(Project project, MixinExtension mixin) { + mixin.init(); + + // Disable some things used by log4j via the mixin AP that prevent it from being garbage collected + System.setProperty("log4j2.disable.jmx", "true"); + System.setProperty("log4j.shutdownHookEnabled", "false"); + System.setProperty("log4j.skipJansi", "true"); + + project.getLogger().info("Configuring compiler arguments for Java"); + + new JavaApInvoker(project).configureMixin(); + + if (project.getPluginManager().hasPlugin("scala")) { + project.getLogger().info("Configuring compiler arguments for Scala"); + new ScalaApInvoker(project).configureMixin(); + } + + if (project.getPluginManager().hasPlugin("org.jetbrains.kotlin.kapt")) { + project.getLogger().info("Configuring compiler arguments for Kapt plugin"); + new KaptApInvoker(project).configureMixin(); + } + } + private static void extendsFrom(String a, String b, Project project) { project.getConfigurations().getByName(a, configuration -> configuration.extendsFrom(project.getConfigurations().getByName(b))); } diff --git a/src/main/java/net/fabricmc/loom/configuration/JarManifestConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/JarManifestConfiguration.java index 5048a0f..eeeb4d2 100644 --- a/src/main/java/net/fabricmc/loom/configuration/JarManifestConfiguration.java +++ b/src/main/java/net/fabricmc/loom/configuration/JarManifestConfiguration.java @@ -29,6 +29,7 @@ import java.util.jar.Attributes; import java.util.jar.Manifest; import org.gradle.api.Project; +import org.gradle.api.artifacts.Dependency; import org.gradle.util.GradleVersion; import net.fabricmc.loom.LoomGradleExtension; @@ -46,7 +47,7 @@ public final record JarManifestConfiguration(Project project) { LoomGradleExtension extension = LoomGradleExtension.get(project); Attributes attributes = manifest.getMainAttributes(); - var tinyRemapperVersion = Optional.ofNullable(TinyRemapper.class.getPackage().getImplementationVersion()); + Optional tinyRemapperVersion = Optional.ofNullable(TinyRemapper.class.getPackage().getImplementationVersion()); attributes.putValue("Fabric-Gradle-Version", GradleVersion.current().getVersion()); attributes.putValue("Fabric-Loom-Version", LoomGradlePlugin.LOOM_VERSION); @@ -63,7 +64,7 @@ public final record JarManifestConfiguration(Project project) { private void addMixinVersion(Attributes attributes) { // Not super ideal that this uses the mod compile classpath, should prob look into making this not a thing at somepoint - var dependency = project.getConfigurations().getByName(Constants.Configurations.LOADER_DEPENDENCIES) + Optional dependency = project.getConfigurations().getByName(Constants.Configurations.LOADER_DEPENDENCIES) .getDependencies() .stream() .filter(dep -> "sponge-mixin".equals(dep.getName())) diff --git a/src/main/java/net/fabricmc/loom/configuration/MavenPublication.java b/src/main/java/net/fabricmc/loom/configuration/MavenPublication.java index 682f6ad..d49d0b7 100644 --- a/src/main/java/net/fabricmc/loom/configuration/MavenPublication.java +++ b/src/main/java/net/fabricmc/loom/configuration/MavenPublication.java @@ -44,6 +44,7 @@ import org.gradle.api.publish.Publication; import org.gradle.api.publish.PublishingExtension; import net.fabricmc.loom.LoomGradleExtension; +import net.fabricmc.loom.util.DeprecationHelper; import net.fabricmc.loom.util.GroovyXmlUtil; public final class MavenPublication { @@ -94,7 +95,7 @@ public final class MavenPublication { if (hasSoftwareComponent(publication) || EXCLUDED_PUBLICATIONS.contains(publication)) { continue; } else if (!reportedDeprecation.get()) { - var deprecationHelper = LoomGradleExtension.get(project).getDeprecationHelper(); + DeprecationHelper deprecationHelper = LoomGradleExtension.get(project).getDeprecationHelper(); deprecationHelper.warn("Loom is applying dependency data manually to publications instead of using a software component (from(components[\"java\"])). This is deprecated and will be removed in Loom 0.12."); reportedDeprecation.set(true); } diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/MinecraftProviderImpl.java b/src/main/java/net/fabricmc/loom/configuration/providers/MinecraftProviderImpl.java index 4ab5837..6ac479b 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/MinecraftProviderImpl.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/MinecraftProviderImpl.java @@ -206,7 +206,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra String expVersionManifest = Files.asCharSource(experimentalVersionsJson, StandardCharsets.UTF_8).read(); ManifestVersion expManifest = LoomGradlePlugin.OBJECT_MAPPER.readValue(expVersionManifest, ManifestVersion.class); - var result = expManifest.versions().stream().filter(versions -> versions.id.equalsIgnoreCase(minecraftVersion)).findFirst(); + Optional result = expManifest.versions().stream().filter(versions -> versions.id.equalsIgnoreCase(minecraftVersion)).findFirst(); if (result.isPresent()) { getProject().getLogger().lifecycle("Using fallback experimental version {}", minecraftVersion); diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpecBuilder.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpecBuilder.java index eae2066..f61b882 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpecBuilder.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpecBuilder.java @@ -48,7 +48,7 @@ public class LayeredMappingSpecBuilder { } public LayeredMappingSpecBuilder parchment(String mavenNotation, Action action) { - var builder = ParchmentMappingsSpecBuilder.builder(mavenNotation); + ParchmentMappingsSpecBuilder builder = ParchmentMappingsSpecBuilder.builder(mavenNotation); action.execute(builder); layers.add(builder.build()); return this;