diff --git a/gradle/error-prone.gradle b/gradle/error-prone.gradle index 8b73fdbe4e..9660b961db 100644 --- a/gradle/error-prone.gradle +++ b/gradle/error-prone.gradle @@ -23,11 +23,6 @@ tasks.withType(JavaCompile).configureEach { 'NonStaticImport', 'Slf4jLoggerDeclaration', // logger -> log 'StaticImport', - // critical, finds lots of bugs... unused configs and stuff. - 'Unused', - 'UnusedMethod', - 'UnusedParameters', - 'UnusedVariable', ) error( 'AmbiguousJsonCreator', @@ -52,11 +47,19 @@ tasks.withType(JavaCompile).configureEach { 'SelfAssignment', 'StringJoin', 'StringJoining', + 'Unused', + 'UnusedMethod', + 'UnusedParameters', + 'UnusedVariable' ) // fixme bug: this only happens when the file is dirty! // up2date checking (caching) must consider file changes, as file is currently corrupt! // fix SelfTest.java:L22 ForbidGradleInternal(import org.gradle.api.internal.project.ProjectInternal;) +// errorproneArgs.add('-XepExcludedPaths:.*/SelfTest.java|.*/EclipseJdtFormatterStepTeeeest.java|.*/JvmTest.java') errorproneArgs.add('-XepExcludedPaths:.*/SelfTest.java') + // bug https://github.com/google/error-prone/issues/5289 + errorproneArgs.add('-XepExcludedPaths:.*/EclipseJdtFormatterStepTest.java') + errorproneArgs.add('-XepExcludedPaths:.*/JvmTest.java') if (!getenv().containsKey('CI') && getenv('IN_PLACE')?.toBoolean()) { errorproneArgs.addAll( '-XepPatchLocation:IN_PLACE', @@ -86,7 +89,10 @@ tasks.withType(JavaCompile).configureEach { 'Slf4jLogStatement,' + 'StringJoin,' + 'StringJoining,' + - 'TimeZoneUsage,' + 'TimeZoneUsage,' + + 'UnusedMethod,' + + 'UnusedParameters,' + + 'UnusedVariable,' ) } } diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStepTest.java index 811f811ee0..39bc61e062 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStepTest.java @@ -15,8 +15,6 @@ */ package com.diffplug.spotless.extra.cpp; -import java.util.stream.Stream; - import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -36,7 +34,4 @@ void formatWithVersion(String version) throws Exception { "#include ;\nint main(int argc, char *argv[]) {\n}\n"); } - private static Stream formatWithVersion() { - return Stream.of("11.0", "11.6", EclipseCdtFormatterStep.defaultVersion()); - } } diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java index 6b00c0e794..4e86b38ce2 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java @@ -15,8 +15,6 @@ */ package com.diffplug.spotless.extra.groovy; -import java.util.stream.Stream; - import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -24,8 +22,6 @@ import com.diffplug.spotless.extra.eclipse.EquoResourceHarness; public class GrEclipseFormatterStepTest extends EquoResourceHarness { - private static final String INPUT = "class F{ def m(){} }"; - private static final String EXPECTED = "class F{\n\tdef m(){}\n}"; public GrEclipseFormatterStepTest() { super(GrEclipseFormatterStep.createBuilder(TestProvisioner.mavenCentral())); @@ -38,7 +34,4 @@ void formatWithVersion(String version) throws Exception { "class F{ def m(){} }", "class F{\n\tdef m(){}\n}"); } - private static Stream formatWithVersion() { - return Stream.of("4.18", GrEclipseFormatterStep.defaultVersion()); - } } diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java index ea0001d517..350736d9c4 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java @@ -22,7 +22,6 @@ import java.nio.file.Files; import java.util.Properties; import java.util.function.Consumer; -import java.util.stream.Stream; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -52,10 +51,6 @@ void formatWithVersion(String version) throws Exception { harnessFor(version).test("someFilename", unformatted, formatted); } - private static Stream formatWithVersion() { - return Stream.of(JVM_SUPPORT.getRecommendedFormatterVersion(), EclipseWtpFormatterStep.defaultVersion()); - } - /** * Check that configuration change is supported by all WTP formatters. * Some of the formatters only support static workspace configuration. diff --git a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java index 7e515cd62d..3a66969a0b 100644 --- a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java @@ -27,9 +27,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3; import com.pinterest.ktlint.rule.engine.api.Code; import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults; @@ -55,8 +52,6 @@ public class KtLintCompat0Dot49Dot0Adapter implements KtLintCompatAdapter { - private static final Logger LOGGER = LoggerFactory.getLogger(KtLintCompat0Dot49Dot0Adapter.class); - private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; static { diff --git a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java index 437b9579bd..66d21beeb8 100644 --- a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java @@ -25,9 +25,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3; import com.pinterest.ktlint.rule.engine.api.Code; import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults; @@ -55,8 +52,6 @@ public class KtLintCompat0Dot50Dot0Adapter implements KtLintCompatAdapter { - private static final Logger LOGGER = LoggerFactory.getLogger(KtLintCompat0Dot50Dot0Adapter.class); - private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; static { diff --git a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java index 8bf029a59a..29d4e10b20 100644 --- a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java +++ b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java @@ -24,9 +24,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3; import com.pinterest.ktlint.rule.engine.api.Code; import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults; @@ -54,8 +51,6 @@ public class KtLintCompat1Dot0Dot0Adapter implements KtLintCompatAdapter { - private static final Logger LOGGER = LoggerFactory.getLogger(KtLintCompat1Dot0Dot0Adapter.class); - private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; static { diff --git a/lib/src/gherkin/java/com/diffplug/spotless/glue/gherkin/GherkinUtilsFormatterFunc.java b/lib/src/gherkin/java/com/diffplug/spotless/glue/gherkin/GherkinUtilsFormatterFunc.java index 4b79347b29..1702099241 100644 --- a/lib/src/gherkin/java/com/diffplug/spotless/glue/gherkin/GherkinUtilsFormatterFunc.java +++ b/lib/src/gherkin/java/com/diffplug/spotless/glue/gherkin/GherkinUtilsFormatterFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 DiffPlug + * Copyright 2023-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,9 +15,6 @@ */ package com.diffplug.spotless.glue.gherkin; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.gherkin.GherkinUtilsConfig; @@ -30,12 +27,9 @@ import io.cucumber.messages.types.SourceMediaType; public class GherkinUtilsFormatterFunc implements FormatterFunc { - private static final Logger LOGGER = LoggerFactory.getLogger(GherkinUtilsFormatterFunc.class); - - private final GherkinUtilsConfig gherkinSimpleConfig; public GherkinUtilsFormatterFunc(GherkinUtilsConfig gherkinSimpleConfig) { - this.gherkinSimpleConfig = gherkinSimpleConfig; + } // Follows https://github.com/cucumber/gherkin-utils/blob/main/java/src/test/java/io/cucumber/gherkin/utils/pretty/PrettyTest.java diff --git a/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatRemoveUnusedImporterFormatterFunc.java b/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatRemoveUnusedImporterFormatterFunc.java index de21a18795..611fcce95f 100644 --- a/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatRemoveUnusedImporterFormatterFunc.java +++ b/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatRemoveUnusedImporterFormatterFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 DiffPlug + * Copyright 2023-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,6 @@ */ package com.diffplug.spotless.glue.java; -import java.util.Objects; - import javax.annotation.Nonnull; import com.google.googlejavaformat.java.RemoveUnusedImports; @@ -25,11 +23,8 @@ public class GoogleJavaFormatRemoveUnusedImporterFormatterFunc implements FormatterFunc { - @Nonnull - private final String version; - public GoogleJavaFormatRemoveUnusedImporterFormatterFunc(@Nonnull String version) { - this.version = Objects.requireNonNull(version); + } @Override diff --git a/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java b/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java index 33a4e4c12e..b9ec259593 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/ReplaceRegexStep.java @@ -44,7 +44,7 @@ public static FormatterStep lint(String name, String regex, String lintDetail) { Objects.requireNonNull(regex, "regex"); Objects.requireNonNull(lintDetail, "lintDetail"); return FormatterStep.createLazy(name, - () -> new LintState(Pattern.compile(regex, Pattern.UNIX_LINES | Pattern.MULTILINE), name, lintDetail), + () -> new LintState(Pattern.compile(regex, Pattern.UNIX_LINES | Pattern.MULTILINE), lintDetail), LintState::toLinter); } @@ -68,12 +68,12 @@ private static final class LintState implements Serializable { private static final long serialVersionUID = 1L; private final Pattern regex; - private final String ruleId; + private final String lintDetail; - LintState(Pattern regex, String ruleId, String lintDetail) { + LintState(Pattern regex, String lintDetail) { this.regex = regex; - this.ruleId = ruleId; + this.lintDetail = lintDetail; } diff --git a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java index f51e0356d0..4904dfdb35 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java @@ -40,17 +40,16 @@ public final class PalantirJavaFormatStep implements Serializable { private final JarState.Promised jarState; /** Version of the formatter jar. */ private final String formatterVersion; - private final String style; + /** Whether to format Java docs. */ private final boolean formatJavadoc; private PalantirJavaFormatStep(JarState.Promised jarState, String formatterVersion, - String style, boolean formatJavadoc) { this.jarState = jarState; this.formatterVersion = formatterVersion; - this.style = style; + this.formatJavadoc = formatJavadoc; } @@ -76,13 +75,12 @@ public static FormatterStep create(String version, String style, Provisioner pro * Creates a step which formats everything - code, import order, unused imports, and Java docs. And with the given * format style. */ - public static FormatterStep create(String version, String style, boolean formatJavadoc, Provisioner provisioner) { + public static FormatterStep create(String version, String ignored, boolean formatJavadoc, Provisioner provisioner) { Objects.requireNonNull(version, "version"); - Objects.requireNonNull(style, "style"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.create(NAME, - new PalantirJavaFormatStep(JarState.promise(() -> JarState.from(MAVEN_COORDINATE + version, provisioner)), version, style, formatJavadoc), + new PalantirJavaFormatStep(JarState.promise(() -> JarState.from(MAVEN_COORDINATE + version, provisioner)), version, formatJavadoc), PalantirJavaFormatStep::equalityState, State::createFormat); } @@ -103,7 +101,7 @@ public static boolean defaultFormatJavadoc() { } private State equalityState() { - return new State(jarState.get(), formatterVersion, style, formatJavadoc); + return new State(jarState.get(), formatterVersion, formatJavadoc); } private static final class State implements Serializable { @@ -111,14 +109,14 @@ private static final class State implements Serializable { private static final long serialVersionUID = 1L; private final JarState jarState; - private final String formatterVersion; + private final String style; private final boolean formatJavadoc; - State(JarState jarState, String formatterVersion, String style, boolean formatJavadoc) { + State(JarState jarState, String style, boolean formatJavadoc) { ModuleHelper.doOpenInternalPackagesIfRequired(); this.jarState = jarState; - this.formatterVersion = formatterVersion; + this.style = style; this.formatJavadoc = formatJavadoc; } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 7fc8f2033b..230e64a8f7 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -41,18 +41,15 @@ abstract class NpmFormatterStepStateBase implements Serializable { private static final Logger LOGGER = LoggerFactory.getLogger(NpmFormatterStepStateBase.class); - private static final TimedLogger TIMED_LOGGER = TimedLogger.forLogger(LOGGER); - @Serial private static final long serialVersionUID = 1460749955865959948L; - private final String stepName; private final NpmConfig npmConfig; public final NpmFormatterStepLocations locations; protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, NpmFormatterStepLocations locations) throws IOException { - this.stepName = requireNonNull(stepName); + this.npmConfig = requireNonNull(npmConfig); this.locations = locations; } diff --git a/lib/src/main/java/com/diffplug/spotless/rdf/RdfFormatterFunc.java b/lib/src/main/java/com/diffplug/spotless/rdf/RdfFormatterFunc.java index da3960b8f6..d9f6c0ea0d 100644 --- a/lib/src/main/java/com/diffplug/spotless/rdf/RdfFormatterFunc.java +++ b/lib/src/main/java/com/diffplug/spotless/rdf/RdfFormatterFunc.java @@ -64,13 +64,13 @@ public String apply(String rawUnix, File file) throws Exception { return formatTurtle(rawUnix, file, reflectionHelper); } if (TRIG_EXTENSIONS.contains(extension)) { - return formatTrig(rawUnix, file); + return formatTrig(); } if (NTRIPLES_EXTENSIONS.contains(extension)) { - return formatNTriples(rawUnix, file); + return formatNTriples(); } if (NQUADS_EXTENSIONS.contains(extension)) { - return formatNQuads(rawUnix, file); + return formatNQuads(); } throw new IllegalArgumentException("Cannot handle file with extension %s".formatted(extension)); } catch (InvocationTargetException e) { @@ -80,15 +80,15 @@ public String apply(String rawUnix, File file) throws Exception { } } - private String formatNQuads(String rawUnix, File file) { + private String formatNQuads() { throw new UnsupportedOperationException("NQUADS formatting not supported yet"); } - private String formatNTriples(String rawUnix, File file) { + private String formatNTriples() { throw new UnsupportedOperationException("NTRIPLES formatting not supported yet"); } - private String formatTrig(String rawUnix, File file) { + private String formatTrig() { throw new UnsupportedOperationException("TRIG formatting not supported yet"); } diff --git a/lib/src/main/java/com/diffplug/spotless/rdf/ReflectionHelper.java b/lib/src/main/java/com/diffplug/spotless/rdf/ReflectionHelper.java index 061062434f..9a7e11b0ec 100644 --- a/lib/src/main/java/com/diffplug/spotless/rdf/ReflectionHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/rdf/ReflectionHelper.java @@ -16,7 +16,6 @@ package com.diffplug.spotless.rdf; import java.io.File; -import java.io.StringWriter; import java.lang.invoke.MethodHandles; import java.lang.reflect.Field; import java.lang.reflect.InvocationHandler; @@ -46,19 +45,16 @@ class ReflectionHelper { private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private final RdfFormatterStep.State state; private final ClassLoader classLoader; - private final Class JenaRdfDataMgrClass; private final Class JenaRdfParserClass; private final Class JenaRdfParserBuilderClass; private final Class JenaErrorHandlerClass; private final Class JenaModelClass; private final Class JenaStmtIteratorClass; - private final Class JenaStatementClass; private final Class JenaRDFNodeClass; private final Class JenaResourceClass; private final Class JenaPropertyClass; private final Class JenaModelFactoryClass; private final Class JenaLangClass; - private final Class JenaRDFFormatClass; private final Class JenaGraphClass; private final Class JenaTriple; private final Class TurtleFormatFormattingStyleClass; @@ -69,21 +65,15 @@ class ReflectionHelper { private final Method graphStream; private final Method graphFindTriple; private final Method contains; - private final Method getSubject; - private final Method getPredicate; - private final Method getObject; - private final Method isAnon; private final Method getGraph; private final Method tripleGetObject; - private Object turtleFormatter; private final Object jenaModelInstance; public ReflectionHelper(RdfFormatterStep.State state) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { this.state = state; this.classLoader = state.getJarState().getClassLoader(); - this.JenaRdfDataMgrClass = classLoader.loadClass("org.apache.jena.riot.RDFDataMgr"); this.JenaRdfParserClass = classLoader.loadClass("org.apache.jena.riot.RDFParser"); this.JenaRdfParserBuilderClass = classLoader.loadClass("org.apache.jena.riot.RDFParserBuilder"); this.JenaErrorHandlerClass = classLoader.loadClass("org.apache.jena.riot.system.ErrorHandler"); @@ -92,20 +82,14 @@ public ReflectionHelper(RdfFormatterStep.State state) this.JenaRDFNodeClass = classLoader.loadClass("org.apache.jena.rdf.model.RDFNode"); this.JenaResourceClass = classLoader.loadClass("org.apache.jena.rdf.model.Resource"); this.JenaPropertyClass = classLoader.loadClass("org.apache.jena.rdf.model.Property"); - this.JenaStatementClass = classLoader.loadClass("org.apache.jena.rdf.model.Statement"); this.JenaModelFactoryClass = classLoader.loadClass("org.apache.jena.rdf.model.ModelFactory"); this.JenaLangClass = classLoader.loadClass("org.apache.jena.riot.Lang"); - this.JenaRDFFormatClass = classLoader.loadClass("org.apache.jena.riot.RDFFormat"); this.TurtleFormatFormatterClass = classLoader.loadClass("de.atextor.turtle.formatter.TurtleFormatter"); this.TurtleFormatFormattingStyleClass = classLoader.loadClass("de.atextor.turtle.formatter.FormattingStyle"); Class[] innerClasses = TurtleFormatFormattingStyleClass.getDeclaredClasses(); this.TurtleFormatFormattingStyleBuilderClass = Arrays.stream(innerClasses) .filter(c -> "FormattingStyleBuilder".equals(c.getSimpleName())).findFirst().orElseThrow(); this.TurtleFormatKnownPrefix = Arrays.stream(innerClasses).filter(c -> "KnownPrefix".equals(c.getSimpleName())).findFirst().orElseThrow(); - this.getSubject = JenaStatementClass.getMethod("getSubject"); - this.getPredicate = JenaStatementClass.getMethod("getPredicate"); - this.getObject = JenaStatementClass.getMethod("getObject"); - this.isAnon = JenaRDFNodeClass.getMethod("isAnon"); this.getGraph = JenaModelClass.getMethod("getGraph"); this.JenaGraphClass = classLoader.loadClass("org.apache.jena.graph.Graph"); this.JenaTriple = classLoader.loadClass("org.apache.jena.graph.Triple"); @@ -129,44 +113,12 @@ public Object getErrorHandler(File file) { new Class[]{JenaErrorHandlerClass}, new DynamicErrorInvocationHandler(file)); } - public Object listModelStatements(Object modelBefore) - throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Method listStatements = JenaModelClass.getMethod("listStatements"); - return listStatements.invoke(modelBefore); - } - - public boolean hasNext(Object statementIterator) - throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { - Method hasNext = JenaStmtIteratorClass.getMethod("hasNext"); - return (boolean) hasNext.invoke(statementIterator); - } - public Object next(Object statementIterator) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { Method hasNext = JenaStmtIteratorClass.getMethod("next"); return hasNext.invoke(statementIterator); } - public boolean containsBlankNode(Object statement) - throws InvocationTargetException, IllegalAccessException { - Object subject = getSubject.invoke(statement); - if ((boolean) isAnon.invoke(subject)) { - return true; - } - Object predicate = getPredicate.invoke(statement); - if ((boolean) isAnon.invoke(predicate)) { - return true; - } - Object object = getObject.invoke(statement); - return (boolean) isAnon.invoke(object); - } - - public boolean containsStatement(Object model, Object statement) - throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Method contains = JenaModelClass.getMethod("contains", JenaStatementClass); - return (boolean) contains.invoke(model, statement); - } - public boolean graphContainsSameTerm(Object graph, Object triple) throws InvocationTargetException, IllegalAccessException { boolean found = (boolean) contains.invoke(graph, triple); if (!found) { @@ -241,30 +193,6 @@ public Stream streamGraph(Object graph) throws InvocationTargetException } - public String formatWithJena(Object model, Object rdfFormat) - throws NoSuchMethodException, NoSuchFieldException, InvocationTargetException, IllegalAccessException { - StringWriter sw = new StringWriter(); - JenaRdfDataMgrClass - .getMethod("write", StringWriter.class, JenaModelClass, JenaRDFFormatClass) - .invoke(JenaRdfDataMgrClass, sw, model, rdfFormat); - return sw.toString(); - } - - public String formatWithTurtleFormatter(Object model) - throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException { - Object formatter = getTurtleFormatter(); - return (String) TurtleFormatFormatterClass.getMethod("apply", JenaModelClass).invoke(formatter, model); - } - - private synchronized Object getTurtleFormatter() - throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException { - if (this.turtleFormatter == null) { - Object style = newTurtleFormatterStyle(); - this.turtleFormatter = newTurtleFormatter(style); - } - return this.turtleFormatter; - } - private Object newTurtleFormatterStyle() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { Object builder = TurtleFormatFormattingStyleClass.getMethod("builder").invoke(TurtleFormatFormatterClass); for (String optionName : state.getTurtleFormatterStyle().keySet()) { @@ -465,10 +393,6 @@ private Method getBuilderMethod(String optionName) { return method; } - public Object getRDFFormat(String rdfFormat) throws NoSuchFieldException, IllegalAccessException { - return JenaRDFFormatClass.getDeclaredField(rdfFormat).get(JenaRDFFormatClass); - } - public Object parseToModel(String rawUnix, File file, Object lang) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Object model = getModel(); @@ -489,56 +413,4 @@ public long modelSize(Object model) throws InvocationTargetException, IllegalAcc return (long) size.invoke(model); } - private static class SortedModelInvocationHandler implements InvocationHandler { - private final ReflectionHelper reflectionHelper; - private final Object jenaModel; - - public SortedModelInvocationHandler(ReflectionHelper reflectionHelper, Object jenaModel) { - this.reflectionHelper = reflectionHelper; - this.jenaModel = jenaModel; - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - if ("listSubjects".equals(method.getName()) && method.getParameterCount() == 0) { - Object resIterator = method.invoke(jenaModel); - List resources = new ArrayList<>(); - while (hasNext(resIterator)) { - resources.add(next(resIterator)); - } - resources.sort(Comparator.comparing(x -> { - try { - return (String) x.getClass().getMethod("getURI").invoke(x); - } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { - throw new RuntimeException(e); - } - }).thenComparing(x -> { - Object anonId; - try { - anonId = x.getClass().getMethod("getAnonId").invoke(x); - } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { - throw new RuntimeException(e); - } - if (anonId != null) { - return anonId.toString(); - } - return null; - })); - return reflectionHelper.classLoader.loadClass("org.apache.jena.rdf.model.impl.ResIteratorImpl") - .getConstructor( - Iterator.class, Object.class) - .newInstance(resources.iterator(), null); - } - return method.invoke(jenaModel); - } - - boolean hasNext(Object it) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - return (boolean) it.getClass().getMethod("hasNext").invoke(it); - } - - Object next(Object it) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - return it.getClass().getMethod("next").invoke(it); - } - - } } diff --git a/lib/src/test/java/com/diffplug/spotless/npm/TimedLoggerTest.java b/lib/src/test/java/com/diffplug/spotless/npm/TimedLoggerTest.java index 132afe362e..7aa9a3e995 100644 --- a/lib/src/test/java/com/diffplug/spotless/npm/TimedLoggerTest.java +++ b/lib/src/test/java/com/diffplug/spotless/npm/TimedLoggerTest.java @@ -234,14 +234,6 @@ public TestLoggingEvent(Level level, Marker marker, String msg, Object[] argumen this.throwable = throwable; } - public Level level() { - return level; - } - - public Marker marker() { - return marker; - } - public String msg() { return msg; } @@ -250,10 +242,6 @@ public Object[] arguments() { return arguments; } - public Throwable throwable() { - return throwable; - } - @Override public String toString() { return String.format( diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index b8260e3b9c..053b4a2e18 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -30,8 +30,6 @@ import org.gradle.api.attributes.Category; import org.gradle.api.attributes.java.TargetJvmEnvironment; import org.gradle.api.initialization.dsl.ScriptHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.diffplug.common.base.Unhandled; import com.diffplug.common.collect.ImmutableList; @@ -142,8 +140,6 @@ private static Provisioner forConfigurationContainer(Project project, Configurat }; } - private static final Logger LOGGER = LoggerFactory.getLogger(GradleProvisioner.class); - /** Models a request to the provisioner. */ private static class Request { final boolean withTransitives; diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index f986d83717..640b4493c4 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -24,7 +24,6 @@ class KotlinExtensionTest extends GradleIntegrationHarness { private static final String HEADER = "// License Header"; - private static final String HEADER_WITH_YEAR = "// License Header $YEAR"; @Test void integrationDiktat() throws IOException { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/MultipleTargetsTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/MultipleTargetsTest.java index 7efb772ffd..7f1329e763 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/MultipleTargetsTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/MultipleTargetsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ import java.io.IOException; import java.util.List; -import org.gradle.testkit.runner.BuildResult; import org.junit.jupiter.api.Test; import com.diffplug.common.collect.Lists; @@ -88,8 +87,6 @@ private void runTest(String targets) throws IOException { initContent(TARGET_FILES, "A"); initContent(NON_TARGET_FILES, "A"); - BuildResult result = gradleRunner().withArguments("spotlessApply").build(); - checkContent(TARGET_FILES, "a"); checkContent(NON_TARGET_FILES, "A"); } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTest.java index ae0986f996..c42692fe2d 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SelfTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,7 @@ private static void runTaskManually() throws Exception { }); project.getBuildscript().getRepositories().mavenCentral(); SpotlessTaskImpl onlyTask = project.getTasks().stream() - .filter(task -> task instanceof SpotlessTaskImpl) + .filter(SpotlessTaskImpl.class::isInstance) .map(task -> (SpotlessTaskImpl) task) .collect(MoreCollectors.singleOrEmpty()).get(); Tasks.execute(onlyTask); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/IdeHookTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/IdeHookTest.java index 452efd4a26..e8030d68ed 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/IdeHookTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/IdeHookTest.java @@ -29,7 +29,7 @@ class IdeHookTest extends MavenIntegrationHarness { private String error; private File dirty; private File clean; - private File diverge; + private File outofbounds; @BeforeEach diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java index d738e17dac..38e6c0a1b4 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import com.diffplug.spotless.ProcessRunner; import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.maven.MavenIntegrationHarness; import com.diffplug.spotless.npm.EslintFormatterStep; @@ -50,7 +49,6 @@ void eslintConfigFile() throws Exception { setFile(".eslintrc.js").toResource("npm/eslint/javascript/custom_rules/.eslintrc.js"); setFile(TEST_FILE_PATH).toResource("npm/eslint/javascript/custom_rules/javascript-es6.dirty"); - ProcessRunner.Result result = mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(TEST_FILE_PATH).sameAsResource("npm/eslint/javascript/custom_rules/javascript-es6.clean"); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index 4c2f05532c..3158b93a72 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 DiffPlug + * Copyright 2023-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,10 @@ package com.diffplug.spotless.maven.json; import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.diffplug.spotless.maven.MavenIntegrationHarness; public class JsonTest extends MavenIntegrationHarness { - private static final Logger LOGGER = LoggerFactory.getLogger(JsonTest.class); @Test public void testFormatJson_WithSimple_defaultConfig_sortByKeys() throws Exception { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java index abba35e72c..b8fda271e6 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ private String prepareRun(String kind, String suffix) throws IOException { } private ProcessRunner.Result runExpectingError(String kind, String suffix) throws IOException, InterruptedException { - String path = prepareRun(kind, suffix); + return mavenRunner().withArguments("spotless:apply").runHasError(); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index 6af4d09ce9..0d5891cec4 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 DiffPlug + * Copyright 2023-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,10 @@ package com.diffplug.spotless.maven.yaml; import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.diffplug.spotless.maven.MavenIntegrationHarness; public class YamlTest extends MavenIntegrationHarness { - private static final Logger LOGGER = LoggerFactory.getLogger(YamlTest.class); @Test public void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws Exception { diff --git a/settings.gradle b/settings.gradle index 7c6a7f9873..5c5c30f758 100644 --- a/settings.gradle +++ b/settings.gradle @@ -27,12 +27,12 @@ dependencyResolutionManagement { } } -if (System.env['CI'] != null) { +if (getenv('CI') != null) { // use the remote buildcache on all CI builds buildCache { def cred = { - if (System.env[it] != null) { - return System.env[it] + if (getenv(it) != null) { + return getenv(it) } else { return System.getProperty(it) } diff --git a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java index 746ea5d46a..a44d1375dc 100644 --- a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java @@ -50,7 +50,7 @@ void supportAdd() { @ParameterizedTest(name = "{index} {1}") @MethodSource - void supportAddFailsFor(Consumer> configuration, String nameNotUsed) { + void supportAddFailsFor(Consumer> configuration, String ignored) { assertThrows(IllegalArgumentException.class, () -> configuration.accept(testSupport)); } diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index da00e37d35..22152b83df 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2024 DiffPlug + * Copyright 2016-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,6 @@ class EslintJavascriptFormattingStepTest extends NpmFormatterStepCommonTests { void formattingUsingRulesetsFile(String ruleSetName) throws Exception { String filedir = "npm/eslint/javascript/" + ruleSetName + "/"; - String testDir = "formatting_ruleset_" + ruleSetName.replace('/', '_') + "/"; // File testDirFile = newFolder(testDir); final File eslintRc = createTestFile(filedir + ".eslintrc.js");