Update checkstyle to prevent using var expect for new instance creation.

dev/0.11
modmuss50 2021-09-07 11:55:05 +01:00
parent 5837f95ff8
commit 8da2da8aed
8 changed files with 40 additions and 30 deletions

View File

@ -158,5 +158,10 @@
<module name="AtclauseOrder"> <module name="AtclauseOrder">
<property name="tagOrder" value="@param,@return,@throws,@deprecated"/> <property name="tagOrder" value="@param,@return,@throws,@deprecated"/>
</module> </module>
<!-- Prevent var for all cases other than new instance creation -->
<module name="MatchXpath">
<property name="query" value="//VARIABLE_DEF[./TYPE/IDENT[@text='var'] and not(./ASSIGN/EXPR/LITERAL_NEW)]"/>
</module>
</module> </module>
</module> </module>

View File

@ -78,7 +78,7 @@ public class LoomGradlePlugin implements BootstrappedPlugin {
project.apply(ImmutableMap.of("plugin", "idea")); project.apply(ImmutableMap.of("plugin", "idea"));
// Setup extensions, minecraft wraps loom // 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(LoomGradleExtensionAPI.class, "minecraft", MinecraftGradleExtension.class, extension);
project.getExtensions().create("fabricApi", FabricApiExtension.class, project); project.getExtensions().create("fabricApi", FabricApiExtension.class, project);

View File

@ -43,6 +43,7 @@ import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency; import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.DependencySet; import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.artifacts.ProjectDependency; import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.artifacts.ResolvedArtifact;
import org.gradle.api.artifacts.ResolvedConfiguration; import org.gradle.api.artifacts.ResolvedConfiguration;
import org.gradle.api.artifacts.ResolvedDependency; import org.gradle.api.artifacts.ResolvedDependency;
import org.gradle.api.tasks.bundling.AbstractArchiveTask; import org.gradle.api.tasks.bundling.AbstractArchiveTask;
@ -133,7 +134,7 @@ public final class NestedDependencyProvider implements NestedJarProvider {
continue; continue;
} }
for (var artifact : dependency.getModuleArtifacts()) { for (ResolvedArtifact artifact : dependency.getModuleArtifacts()) {
fileList.add(new DependencyInfo<>( fileList.add(new DependencyInfo<>(
dependency, dependency,
new ResolvedDependencyMetaExtractor(), new ResolvedDependencyMetaExtractor(),

View File

@ -139,29 +139,8 @@ public final class CompileConfiguration {
MixinExtension mixin = LoomGradleExtension.get(project).getMixin(); MixinExtension mixin = LoomGradleExtension.get(project).getMixin();
if (!mixin.getUseLegacyMixinAp().get()) { if (mixin.getUseLegacyMixinAp().get()) {
return; setupMixinAp(project, 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();
} }
}); });
@ -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) { private static void extendsFrom(String a, String b, Project project) {
project.getConfigurations().getByName(a, configuration -> configuration.extendsFrom(project.getConfigurations().getByName(b))); project.getConfigurations().getByName(a, configuration -> configuration.extendsFrom(project.getConfigurations().getByName(b)));
} }

View File

@ -29,6 +29,7 @@ import java.util.jar.Attributes;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.artifacts.Dependency;
import org.gradle.util.GradleVersion; import org.gradle.util.GradleVersion;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
@ -46,7 +47,7 @@ public final record JarManifestConfiguration(Project project) {
LoomGradleExtension extension = LoomGradleExtension.get(project); LoomGradleExtension extension = LoomGradleExtension.get(project);
Attributes attributes = manifest.getMainAttributes(); Attributes attributes = manifest.getMainAttributes();
var tinyRemapperVersion = Optional.ofNullable(TinyRemapper.class.getPackage().getImplementationVersion()); Optional<String> tinyRemapperVersion = Optional.ofNullable(TinyRemapper.class.getPackage().getImplementationVersion());
attributes.putValue("Fabric-Gradle-Version", GradleVersion.current().getVersion()); attributes.putValue("Fabric-Gradle-Version", GradleVersion.current().getVersion());
attributes.putValue("Fabric-Loom-Version", LoomGradlePlugin.LOOM_VERSION); attributes.putValue("Fabric-Loom-Version", LoomGradlePlugin.LOOM_VERSION);
@ -63,7 +64,7 @@ public final record JarManifestConfiguration(Project project) {
private void addMixinVersion(Attributes attributes) { 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 // 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> dependency = project.getConfigurations().getByName(Constants.Configurations.LOADER_DEPENDENCIES)
.getDependencies() .getDependencies()
.stream() .stream()
.filter(dep -> "sponge-mixin".equals(dep.getName())) .filter(dep -> "sponge-mixin".equals(dep.getName()))

View File

@ -44,6 +44,7 @@ import org.gradle.api.publish.Publication;
import org.gradle.api.publish.PublishingExtension; import org.gradle.api.publish.PublishingExtension;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.DeprecationHelper;
import net.fabricmc.loom.util.GroovyXmlUtil; import net.fabricmc.loom.util.GroovyXmlUtil;
public final class MavenPublication { public final class MavenPublication {
@ -94,7 +95,7 @@ public final class MavenPublication {
if (hasSoftwareComponent(publication) || EXCLUDED_PUBLICATIONS.contains(publication)) { if (hasSoftwareComponent(publication) || EXCLUDED_PUBLICATIONS.contains(publication)) {
continue; continue;
} else if (!reportedDeprecation.get()) { } 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."); 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); reportedDeprecation.set(true);
} }

View File

@ -206,7 +206,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
String expVersionManifest = Files.asCharSource(experimentalVersionsJson, StandardCharsets.UTF_8).read(); String expVersionManifest = Files.asCharSource(experimentalVersionsJson, StandardCharsets.UTF_8).read();
ManifestVersion expManifest = LoomGradlePlugin.OBJECT_MAPPER.readValue(expVersionManifest, ManifestVersion.class); ManifestVersion expManifest = LoomGradlePlugin.OBJECT_MAPPER.readValue(expVersionManifest, ManifestVersion.class);
var result = expManifest.versions().stream().filter(versions -> versions.id.equalsIgnoreCase(minecraftVersion)).findFirst(); Optional<ManifestVersion.Versions> result = expManifest.versions().stream().filter(versions -> versions.id.equalsIgnoreCase(minecraftVersion)).findFirst();
if (result.isPresent()) { if (result.isPresent()) {
getProject().getLogger().lifecycle("Using fallback experimental version {}", minecraftVersion); getProject().getLogger().lifecycle("Using fallback experimental version {}", minecraftVersion);

View File

@ -48,7 +48,7 @@ public class LayeredMappingSpecBuilder {
} }
public LayeredMappingSpecBuilder parchment(String mavenNotation, Action<ParchmentMappingsSpecBuilder> action) { public LayeredMappingSpecBuilder parchment(String mavenNotation, Action<ParchmentMappingsSpecBuilder> action) {
var builder = ParchmentMappingsSpecBuilder.builder(mavenNotation); ParchmentMappingsSpecBuilder builder = ParchmentMappingsSpecBuilder.builder(mavenNotation);
action.execute(builder); action.execute(builder);
layers.add(builder.build()); layers.add(builder.build());
return this; return this;