From f9ffa53ce87814db9fa4309f5127444ee9e93b2a Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 29 Jun 2020 21:51:14 -0700 Subject: [PATCH 01/13] Remove all deprecated code from SpotlessCache. --- lib/src/main/java/com/diffplug/spotless/SpotlessCache.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/SpotlessCache.java b/lib/src/main/java/com/diffplug/spotless/SpotlessCache.java index d984107e74..30b0ccae14 100644 --- a/lib/src/main/java/com/diffplug/spotless/SpotlessCache.java +++ b/lib/src/main/java/com/diffplug/spotless/SpotlessCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -77,11 +77,8 @@ static SpotlessCache instance() { /** * Closes all cached classloaders. - * - * @deprecated because it is [dangerous](https://github.com/diffplug/spotless/issues/243#issuecomment-564323856), replacement is {@link #clearOnce(Object)}. */ - @Deprecated - public static void clear() { + private static void clear() { List toDelete; synchronized (instance) { toDelete = new ArrayList<>(instance.cache.values()); From a1072e18d464f4ba2e96fbd5a48a3bc55e8a5934 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 29 Jun 2020 21:53:58 -0700 Subject: [PATCH 02/13] Remove deprecated methods from Provisioner. --- .../java/com/diffplug/spotless/Provisioner.java | 15 +-------------- .../com/diffplug/spotless/ProvisionerTest.java | 14 +------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Provisioner.java b/lib/src/main/java/com/diffplug/spotless/Provisioner.java index cb39e7f993..259cac5a7c 100644 --- a/lib/src/main/java/com/diffplug/spotless/Provisioner.java +++ b/lib/src/main/java/com/diffplug/spotless/Provisioner.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,19 +25,6 @@ * Spotless' dependencies minimal. */ public interface Provisioner { - - /** Method interface has been extended to {@link Provisioner#provisionWithTransitives(boolean, Collection)}. */ - @Deprecated - public default Set provisionWithDependencies(Collection mavenCoordinates) { - return provisionWithTransitives(true, mavenCoordinates); - } - - /** Method interface has been extended to {@link Provisioner#provisionWithTransitives(boolean, String...)}. */ - @Deprecated - public default Set provisionWithDependencies(String... mavenCoordinates) { - return provisionWithDependencies(Arrays.asList(mavenCoordinates)); - } - /** * Given a set of Maven coordinates, returns a set of jars which include all * of the specified coordinates and optionally their transitive dependencies. diff --git a/testlib/src/test/java/com/diffplug/spotless/ProvisionerTest.java b/testlib/src/test/java/com/diffplug/spotless/ProvisionerTest.java index adc26b5318..a8e437d74b 100644 --- a/testlib/src/test/java/com/diffplug/spotless/ProvisionerTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/ProvisionerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,18 +23,6 @@ import org.junit.Test; public class ProvisionerTest { - @Test - @Deprecated - public void testManipulationDeprecated() { - Provisioner provisioner = (withTransitives, deps) -> deps.stream().map(File::new).collect(Collectors.toSet()); - Assertions.assertThat(provisioner.provisionWithDependencies("a")) - .containsExactlyInAnyOrder(new File("a")); - Assertions.assertThat(provisioner.provisionWithDependencies("a", "a")) - .containsExactlyInAnyOrder(new File("a")); - Assertions.assertThat(provisioner.provisionWithDependencies(Arrays.asList("a", "a"))) - .containsExactlyInAnyOrder(new File("a")); - } - @Test public void testManipulation() { Provisioner provisioner = (withTransitives, deps) -> deps.stream().map(File::new).collect(Collectors.toSet()); From a0f399c85394eb04c83a72398cb87f36dff90808 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 29 Jun 2020 21:55:22 -0700 Subject: [PATCH 03/13] Remove deprecated methods from the npm steps. --- .../diffplug/spotless/npm/PrettierFormatterStep.java | 5 ----- .../com/diffplug/spotless/npm/TsFmtFormatterStep.java | 10 ---------- 2 files changed, 15 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 72722a5a9a..b181fca796 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -49,11 +49,6 @@ public static final Map defaultDevDependenciesWithPrettier(Strin return Collections.singletonMap("prettier", version); } - @Deprecated - public static FormatterStep create(Provisioner provisioner, File buildDir, @Nullable File npm, PrettierConfig prettierConfig) { - return create(defaultDevDependencies(), provisioner, buildDir, npm, prettierConfig); - } - public static FormatterStep create(Map devDependencies, Provisioner provisioner, File buildDir, @Nullable File npm, PrettierConfig prettierConfig) { requireNonNull(devDependencies); requireNonNull(provisioner); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java index e815ea1f63..2245cd0b05 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java @@ -39,11 +39,6 @@ public class TsFmtFormatterStep { public static final String NAME = "tsfmt-format"; - @Deprecated - public static FormatterStep create(Provisioner provisioner, File buildDir, @Nullable File npm, File baseDir, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map inlineTsFmtSettings) { - return create(defaultDevDependencies(), provisioner, buildDir, npm, configFile, inlineTsFmtSettings); - } - public static FormatterStep create(Map versions, Provisioner provisioner, File buildDir, @Nullable File npm, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map inlineTsFmtSettings) { requireNonNull(provisioner); requireNonNull(buildDir); @@ -75,11 +70,6 @@ public static class State extends NpmFormatterStepStateBase implements Serializa @Nullable private final TypedTsFmtConfigFile configFile; - @Deprecated - public State(String stepName, File buildDir, @Nullable File npm, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map inlineTsFmtSettings) throws IOException { - this(stepName, defaultDevDependencies(), buildDir, npm, configFile, inlineTsFmtSettings); - } - public State(String stepName, Map versions, File buildDir, @Nullable File npm, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map inlineTsFmtSettings) throws IOException { super(stepName, new NpmConfig( From fe2daaa68b6e202f017b3147c3dffb936983da21 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 29 Jun 2020 21:56:30 -0700 Subject: [PATCH 04/13] Add missing serialVersionUID for the npm steps. --- .../diffplug/spotless/npm/NpmFormatterStepStateBase.java | 2 ++ lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java | 2 ++ .../java/com/diffplug/spotless/npm/SimpleRestClient.java | 6 ++++++ 3 files changed, 10 insertions(+) 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 ae03c7582b..01d3204af7 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -181,6 +181,8 @@ public void close() throws Exception { } protected static class ServerStartException extends RuntimeException { + private static final long serialVersionUID = -8803977379866483002L; + public ServerStartException(Throwable cause) { super(cause); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index 33e68a27f2..e1bf8c8673 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -79,6 +79,8 @@ private String commandLine(String... args) { } static class NpmProcessException extends RuntimeException { + private static final long serialVersionUID = 6424331316676759525L; + public NpmProcessException(String message) { super(message); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.java b/lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.java index 5958135d09..876828bb40 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.java @@ -93,6 +93,8 @@ private String readInputStream(InputStream inputStream) throws IOException { } static abstract class SimpleRestException extends RuntimeException { + private static final long serialVersionUID = -8260821395756603787L; + public SimpleRestException() {} public SimpleRestException(Throwable cause) { @@ -101,6 +103,8 @@ public SimpleRestException(Throwable cause) { } static class SimpleRestResponseException extends SimpleRestException { + private static final long serialVersionUID = -7637152299410053401L; + private final int statusCode; private final String responseMessage; @@ -135,6 +139,8 @@ public String getMessage() { } static class SimpleRestIOException extends SimpleRestException { + private static final long serialVersionUID = -7909757660531122308L; + public SimpleRestIOException(Throwable cause) { super(cause); } From 2e4131f44572a367f202e57377323fcbcf739132 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 29 Jun 2020 21:57:31 -0700 Subject: [PATCH 05/13] Remove deprecated methods from ImportOrderStep. --- .../spotless/java/ImportOrderStep.java | 25 +------------------ .../gradle/spotless/JavaExtension.java | 2 +- 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java b/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java index bdff61d2f8..f08ea42b5c 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,29 +67,6 @@ private FormatterStep createFrom(Supplier> importOrder) { State::toFormatter); } - /** Method interface has been changed to - * {@link ImportOrderStep#createFromOrder(String...)}.*/ - @Deprecated - public static FormatterStep createFromOrder(List importOrder) { - // defensive copying and null checking - List importOrderCopy = requireElementsNonNull(new ArrayList<>(importOrder)); - return forJava().createFrom(() -> importOrderCopy); - } - - /** Static method has been replaced by instance method - * {@link ImportOrderStep#createFrom(String...)}.*/ - @Deprecated - public static FormatterStep createFromOrder(String... importOrder) { - return forJava().createFrom(importOrder); - } - - /** Static method has been replaced by instance method - * {@link ImportOrderStep#createFrom(File)}.*/ - @Deprecated - public static FormatterStep createFromFile(File importsFile) { - return forJava().createFrom(importsFile); - } - private static List getImportOrder(File importsFile) { try (Stream lines = Files.lines(importsFile.toPath())) { return lines.filter(line -> !line.startsWith("#")) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index 51d13fa923..c8f1f65e4d 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -67,7 +67,7 @@ public void importOrder(List importOrder) { "'importOrder([x, y, z])' is deprecated.", "Use 'importOrder x, y, z' instead.", "For details see https://github.com/diffplug/spotless/tree/main/plugin-gradle#applying-to-java-source")); - addStep(ImportOrderStep.createFromOrder(importOrder)); + importOrder(importOrder.toArray(new String[0])); } public void importOrder(String... importOrder) { From db6df585d2af757748c453399d2ab291925d0ab7 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 29 Jun 2020 21:57:48 -0700 Subject: [PATCH 06/13] Remove PaddedCellBulk. --- .../com/diffplug/spotless/PaddedCellBulk.java | 232 ------------------ 1 file changed, 232 deletions(-) delete mode 100644 lib/src/main/java/com/diffplug/spotless/PaddedCellBulk.java diff --git a/lib/src/main/java/com/diffplug/spotless/PaddedCellBulk.java b/lib/src/main/java/com/diffplug/spotless/PaddedCellBulk.java deleted file mode 100644 index 5b6e289503..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/PaddedCellBulk.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright 2016-2020 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless; - -import java.io.File; -import java.io.IOException; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Locale; -import java.util.Objects; -import java.util.logging.Level; -import java.util.logging.Logger; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -/** COMPLETELY DEPRECATED, use {@link PaddedCell#calculateDirtyState(Formatter, File)} instead. */ -@Deprecated -public final class PaddedCellBulk { - private static final Logger logger = Logger.getLogger(PaddedCellBulk.class.getName()); - - /** - * Returns true if the formatter is misbehaving for any of the given files. - * - * If, after 500ms of searching, none are found that misbehave, it gives the - * formatter the benefit of the doubt and returns false. The real point of this - * check is to handle the case that a user just called spotlessApply, but spotlessCheck - * is still failing. In that case, all of the problemFiles are guaranteed to - * be misbehaving, so this time limit doesn't hurt correctness. - * - * If you call this method after every failed spotlessCheck, it can help you - * tell the user about a misbehaving rule and alert her to how to enable - * paddedCell mode, with minimal effort. - */ - @Deprecated - public static boolean anyMisbehave(Formatter formatter, List problemFiles) { - return anyMisbehave(formatter, problemFiles, 500); - } - - /** Same as {@link #anyMisbehave(Formatter, List)} but with a customizable timeout. */ - @Deprecated - public static boolean anyMisbehave(Formatter formatter, List problemFiles, long timeoutMs) { - Objects.requireNonNull(formatter, "formatter"); - Objects.requireNonNull(problemFiles, "problemFiles"); - long start = System.currentTimeMillis(); - for (File problem : problemFiles) { - PaddedCell padded = PaddedCell.check(formatter, problem); - if (padded.misbehaved()) { - return true; - } - if (timeoutMs > 0 && System.currentTimeMillis() - start > timeoutMs) { - return false; - } - } - return false; - } - - /** - * Performs a full check using PaddedCell logic on the given files with the given formatter. - * If any are found which do not conform to the PaddedCell, a description of the error will - * be written to the diagnose dir. - * - * @param rootDir The root directory, used to determine the relative paths of the problemFiles. - * @param diagnoseDir Directory where problems are described (based on the relative paths determined based on rootDir). - * @param formatter The formatter to apply. - * @param problemFiles The files with which we have a problem. - * @return A list of files which are failing because of paddedCell problems, but could be fixed. (specifically, the files for which spotlessApply would be effective) - */ - @SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") - @Deprecated - public static List check(File rootDir, File diagnoseDir, Formatter formatter, List problemFiles) throws IOException { - Objects.requireNonNull(rootDir, "rootDir"); - Objects.requireNonNull(diagnoseDir, "diagnoseDir"); - Objects.requireNonNull(formatter, "formatter"); - Objects.requireNonNull(problemFiles, "problemFiles"); - - // "fake" Formatter which can use the already-computed result of a PaddedCell as - FakeStep paddedCellStep = new FakeStep(); - try (Formatter paddedFormatter = Formatter.builder() - .lineEndingsPolicy(formatter.getLineEndingsPolicy()) - .encoding(formatter.getEncoding()) - .rootDir(formatter.getRootDir()) - .steps(Collections.singletonList(paddedCellStep)) - .exceptionPolicy(formatter.getExceptionPolicy()) - .build()) { - - // empty out the diagnose folder - Path rootPath = rootDir.toPath(); - Path diagnosePath = diagnoseDir.toPath(); - cleanDir(diagnosePath); - - List stillFailing = new ArrayList<>(); - for (File problemFile : problemFiles) { - logger.fine("Running padded cell check on " + problemFile); - PaddedCell padded = PaddedCell.check(formatter, problemFile); - if (!padded.misbehaved()) { - logger.fine(" well-behaved."); - } else { - // the file is misbehaved, so we'll write all its steps to DIAGNOSE_DIR - Path relative = rootPath.relativize(problemFile.toPath()); - Path diagnoseFile = diagnosePath.resolve(relative); - for (int i = 0; i < padded.steps().size(); ++i) { - Path path = Paths.get(diagnoseFile + "." + padded.type().name().toLowerCase(Locale.ROOT) + i); - Files.createDirectories(path.getParent()); - String version = padded.steps().get(i); - Files.write(path, version.getBytes(formatter.getEncoding())); - } - // dump the type of the misbehavior to console - logger.fine(" " + relative + " " + padded.userMessage()); - } - - if (!padded.isResolvable()) { - // if it's not resolvable, then there's - // no point killing the build over it - } else { - // if the input is resolvable, we'll use that to try again at - // determining if it's clean - paddedCellStep.set(problemFile, padded.canonical()); - if (!paddedFormatter.isClean(problemFile)) { - stillFailing.add(problemFile); - } - } - } - return stillFailing; - } - } - - /** Helper for check(). */ - @SuppressWarnings("serial") - @SuppressFBWarnings("SE_NO_SERIALVERSIONID") - static class FakeStep implements FormatterStep { - private File file; - private String formatted; - - void set(File file, String formatted) { - this.file = file; - this.formatted = formatted; - } - - @Override - public String format(String raw, File file) throws Exception { - if (file.equals(this.file)) { - this.file = null; - return Objects.requireNonNull(formatted); - } else { - throw new IllegalArgumentException("Must call set() before each call to format."); - } - } - - @Override - public String getName() { - return "Padded cell result"; - } - } - - /** Performs the typical spotlessApply, but with PaddedCell handling of misbehaving FormatterSteps. */ - @Deprecated - public static void apply(Formatter formatter, File file) throws IOException { - applyAnyChanged(formatter, file); - } - - /** Performs the typical spotlessApply, but with PaddedCell handling of misbehaving FormatterSteps. */ - @Deprecated - public static boolean applyAnyChanged(Formatter formatter, File file) throws IOException { - PaddedCell.DirtyState dirtyState = PaddedCell.calculateDirtyState(formatter, file); - if (dirtyState.isClean() || dirtyState.didNotConverge()) { - return false; - } else { - dirtyState.writeCanonicalTo(file); - return true; - } - } - - /** Does whatever it takes to turn this path into an empty folder. */ - private static void cleanDir(Path folder) throws IOException { - if (Files.exists(folder)) { - if (Files.isDirectory(folder)) { - Files.walkFileTree(folder, FOLDER_CLEANING_VISITOR); - } else { - Files.delete(folder); - } - } - Files.createDirectories(folder); - } - - private static final SimpleFileVisitor FOLDER_CLEANING_VISITOR = new SimpleFileVisitor() { - @Override - public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { - Files.delete(file); - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFileFailed(final Path file, final IOException e) { - return handleException(e); - } - - private FileVisitResult handleException(final IOException e) { - logger.log(Level.SEVERE, e.getMessage(), e); - return FileVisitResult.TERMINATE; - } - - @Override - public FileVisitResult postVisitDirectory(final Path dir, final IOException e) - throws IOException { - if (e != null) { - return handleException(e); - } - Files.delete(dir); - return FileVisitResult.CONTINUE; - } - }; -} From 20aedab44ebea6dbc5b9e78a2e422f9c1a23129d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 29 Jun 2020 21:58:01 -0700 Subject: [PATCH 07/13] Remove deprecated methods from FileSignature. --- .../com/diffplug/spotless/FileSignature.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/FileSignature.java b/lib/src/main/java/com/diffplug/spotless/FileSignature.java index 546a36287c..63546df04e 100644 --- a/lib/src/main/java/com/diffplug/spotless/FileSignature.java +++ b/lib/src/main/java/com/diffplug/spotless/FileSignature.java @@ -47,22 +47,6 @@ public final class FileSignature implements Serializable { private final transient List files; private final Sig[] signatures; - /** Method has been renamed to {@link FileSignature#signAsSet}. - * In case no sorting and removal of duplicates is required, - * use {@link FileSignature#signAsList} instead.*/ - @Deprecated - public static FileSignature from(File... files) throws IOException { - return from(Arrays.asList(files)); - } - - /** Method has been renamed to {@link FileSignature#signAsSet}. - * In case no sorting and removal of duplicates is required, - * use {@link FileSignature#signAsList} instead.*/ - @Deprecated - public static FileSignature from(Iterable files) throws IOException { - return signAsSet(files); - } - /** Creates file signature whereas order of the files remains unchanged. */ public static FileSignature signAsList(File... files) throws IOException { return signAsList(Arrays.asList(files)); From 9c7755be4e140c31169cc869bbe334ae840e825b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 29 Jun 2020 22:02:50 -0700 Subject: [PATCH 08/13] Removed deprecated parts of JarState, which allows us to improve the implementation. --- .../java/com/diffplug/spotless/JarState.java | 27 +++---------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/JarState.java b/lib/src/main/java/com/diffplug/spotless/JarState.java index 15f009be30..1a60c6fbc1 100644 --- a/lib/src/main/java/com/diffplug/spotless/JarState.java +++ b/lib/src/main/java/com/diffplug/spotless/JarState.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 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 java.io.Serializable; import java.net.URI; import java.net.URL; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.NoSuchElementException; @@ -29,8 +28,6 @@ import java.util.TreeSet; import java.util.stream.Collectors; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - /** * Grabs a jar and its dependencies from maven, * and makes it easy to access the collection in @@ -43,27 +40,11 @@ public final class JarState implements Serializable { private static final long serialVersionUID = 1L; private final Set mavenCoordinates; - @SuppressWarnings("unused") private final FileSignature fileSignature; - /* - * Transient because not needed to uniquely identify a JarState instance, and also because - * Gradle only needs this class to be Serializable so it can compare JarState instances for - * incremental builds. - */ - @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") - private final transient Set jars; - - @Deprecated // internal - public JarState(String mavenCoordinate, FileSignature fileSignature, Set jars) { - this(Arrays.asList(mavenCoordinate), fileSignature, jars); - } - - @Deprecated // internal - public JarState(Collection mavenCoordinates, FileSignature fileSignature, Set jars) { + private JarState(Collection mavenCoordinates, FileSignature fileSignature) { this.mavenCoordinates = new TreeSet(mavenCoordinates); this.fileSignature = fileSignature; - this.jars = jars; } /** Provisions the given maven coordinate and its transitive dependencies. */ @@ -89,11 +70,11 @@ private static JarState provisionWithTransitives(boolean withTransitives, Collec throw new NoSuchElementException("Resolved to an empty result: " + mavenCoordinates.stream().collect(Collectors.joining(", "))); } FileSignature fileSignature = FileSignature.signAsSet(jars); - return new JarState(mavenCoordinates, fileSignature, jars); + return new JarState(mavenCoordinates, fileSignature); } URL[] jarUrls() { - return jars.stream().map(File::toURI).map(ThrowingEx.wrap(URI::toURL)).toArray(URL[]::new); + return fileSignature.files().stream().map(File::toURI).map(ThrowingEx.wrap(URI::toURL)).toArray(URL[]::new); } /** From 542dce7891a14c25b75b52b5dd55a450c1fbbc4c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 29 Jun 2020 22:05:28 -0700 Subject: [PATCH 09/13] Remove deprecated methods from DiffMessageFormatter. --- .../spotless/extra/integration/DiffMessageFormatter.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java index d2d86ff7db..8db5ebeb24 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,12 +57,6 @@ public Builder runToFix(String runToFix) { return this; } - @Deprecated - public Builder isPaddedCell(boolean isPaddedCell) { - System.err.println("PaddedCell is now always on, and cannot be turned off."); - return this; - } - public Builder formatter(Formatter formatter) { this.formatter = Objects.requireNonNull(formatter); return this; From 7bc4ceaeeea0f41de54d6c09e1e6f2f8355412db Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 29 Jun 2020 22:06:55 -0700 Subject: [PATCH 10/13] Removed the deprecated methods from GrEclipseFormatterStep. --- .../extra/groovy/GrEclipseFormatterStep.java | 19 +--- .../DeprecatedGrEclipseFormatterStepTest.java | 90 ------------------- 2 files changed, 1 insertion(+), 108 deletions(-) delete mode 100644 lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/DeprecatedGrEclipseFormatterStepTest.java diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java index 19c0f1d3f1..96664e6475 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,11 @@ */ package com.diffplug.spotless.extra.groovy; -import java.io.File; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Properties; import com.diffplug.spotless.FormatterFunc; -import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.extra.EclipseBasedStepBuilder; import com.diffplug.spotless.extra.EclipseBasedStepBuilder.State; @@ -38,21 +36,6 @@ private GrEclipseFormatterStep() {} private static final String DEFAULT_VERSION = "4.13.0"; private static final String FORMATTER_METHOD = "format"; - /** Creates a formatter step using the default version for the given settings file. */ - @Deprecated - public static FormatterStep create(Iterable settingsFiles, Provisioner provisioner) { - return create(defaultVersion(), settingsFiles, provisioner); - } - - /** Creates a formatter step for the given version and settings file. */ - @Deprecated - public static FormatterStep create(String version, Iterable settingsFiles, Provisioner provisioner) { - EclipseBasedStepBuilder builder = createBuilder(provisioner); - builder.setVersion(version); - builder.setPreferences(settingsFiles); - return builder.build(); - } - public static String defaultVersion() { return DEFAULT_VERSION; } diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/DeprecatedGrEclipseFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/DeprecatedGrEclipseFormatterStepTest.java deleted file mode 100644 index 1021edb503..0000000000 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/DeprecatedGrEclipseFormatterStepTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2016 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.extra.groovy; - -import java.io.File; -import java.io.IOException; -import java.util.List; - -import org.junit.Test; - -import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.Provisioner; -import com.diffplug.spotless.ResourceHarness; -import com.diffplug.spotless.SerializableEqualityTester; -import com.diffplug.spotless.StepHarness; -import com.diffplug.spotless.TestProvisioner; - -@Deprecated -public class DeprecatedGrEclipseFormatterStepTest extends ResourceHarness { - - private static final String RESOURCE_PATH = "groovy/greclipse/format/"; - private static final String CONFIG_FILE = RESOURCE_PATH + "greclipse.properties"; - private static final String DEPRECATED_VERSION = "4.6.3"; - - //String is hard-coded in the GrEclipseFormatter - private static final String FORMATTER_FILENAME_REPALCEMENT = "Hello.groovy"; - - private static Provisioner provisioner() { - return TestProvisioner.mavenCentral(); - } - - @Test - public void nominal() throws Throwable { - List config = createTestFiles(CONFIG_FILE); - StepHarness.forStep(GrEclipseFormatterStep.create(DEPRECATED_VERSION, config, provisioner())) - .testResource(RESOURCE_PATH + "unformatted.test", RESOURCE_PATH + "formatted.test"); - } - - @Test - public void formatterException() throws Throwable { - List config = createTestFiles(CONFIG_FILE); - StepHarness.forStep(GrEclipseFormatterStep.create(DEPRECATED_VERSION, config, provisioner())) - .testException(RESOURCE_PATH + "exception.test", assertion -> { - assertion.isInstanceOf(IllegalArgumentException.class); - assertion.hasMessageContaining(FORMATTER_FILENAME_REPALCEMENT); - }); - } - - @Test - public void configurationException() throws Throwable { - String configFileName = "greclipse.exception"; - List config = createTestFiles(RESOURCE_PATH + configFileName); - StepHarness.forStep(GrEclipseFormatterStep.create(DEPRECATED_VERSION, config, provisioner())) - .testException(RESOURCE_PATH + "unformatted.test", assertion -> { - assertion.isInstanceOf(IllegalArgumentException.class); - assertion.hasMessageContaining(configFileName); - }); - } - - @Test - public void equality() throws IOException { - List configFile = createTestFiles(CONFIG_FILE); - new SerializableEqualityTester() { - - @Override - protected void setupTest(API api) { - api.areDifferentThan(); - } - - @Override - protected FormatterStep create() { - return GrEclipseFormatterStep.create(DEPRECATED_VERSION, configFile, provisioner()); - } - }.testEquals(); - } - -} From 5783c278746ea30f33e6950b932c8186af4f3a63 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 29 Jun 2020 22:09:06 -0700 Subject: [PATCH 11/13] Removed the deprecated EclipseFormatterStep --- .../extra/java/EclipseFormatterStep.java | 73 ------------------ .../extra/java/EclipseFormatterStepTest.java | 77 ------------------- .../gradle/spotless/JavaExtension.java | 4 +- 3 files changed, 1 insertion(+), 153 deletions(-) delete mode 100644 lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseFormatterStep.java delete mode 100644 lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseFormatterStepTest.java diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseFormatterStep.java deleted file mode 100644 index df5cf64313..0000000000 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseFormatterStep.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2016 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.extra.java; - -import java.io.File; -import java.util.Collections; -import java.util.Objects; - -import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.Provisioner; -import com.diffplug.spotless.extra.EclipseBasedStepBuilder; - -/** - * Formatter step which calls out to the Eclipse formatter. - * This class is deprecated. Use {@link EclipseJdtFormatterStep} instead. - */ -@Deprecated -public final class EclipseFormatterStep { - // prevent direct instantiation - private EclipseFormatterStep() {} - - private static final String DEFAULT_VERSION = "4.7.2"; - - /** Creates a formatter step for the given version and settings file. - * Formatter steps based on property configuration should support zero (default configuration) - * to many files. Use {@link #create(Iterable, Provisioner)} instead.*/ - @Deprecated - public static FormatterStep create(File settingsFile, Provisioner provisioner) { - return create(Collections.singletonList(settingsFile), provisioner); - } - - /** Creates a formatter step for the given version and settings file. */ - public static FormatterStep create(Iterable settingsFiles, Provisioner provisioner) { - return create(defaultVersion(), settingsFiles, provisioner); - } - - /** Creates a formatter step for the given version and settings file. - * Formatter steps based on property configuration should support zero (default configuration) - * to many files. Use {@link #create(String, Iterable, Provisioner)} instead.*/ - @Deprecated - public static FormatterStep create(String version, File settingsFile, Provisioner provisioner) { - return create(version, Collections.singletonList(settingsFile), provisioner); - } - - /** Creates a formatter step for the given version and settings files. */ - public static FormatterStep create(String version, Iterable settingsFiles, Provisioner provisioner) { - Objects.requireNonNull(version, "version"); - Objects.requireNonNull(settingsFiles, "settingsFiles"); - Objects.requireNonNull(provisioner, "provisioner"); - EclipseBasedStepBuilder builder = EclipseJdtFormatterStep.createBuilder(provisioner); - builder.setPreferences(settingsFiles); - builder.setVersion(DEFAULT_VERSION); - return builder.build(); - } - - public static String defaultVersion() { - return DEFAULT_VERSION; - } - -} diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseFormatterStepTest.java deleted file mode 100644 index cef7e3889a..0000000000 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseFormatterStepTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2016 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.extra.java; - -import java.io.File; -import java.io.IOException; -import java.util.List; - -import org.junit.Test; - -import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.ResourceHarness; -import com.diffplug.spotless.SerializableEqualityTester; -import com.diffplug.spotless.StepHarness; -import com.diffplug.spotless.TestProvisioner; - -@Deprecated -public class EclipseFormatterStepTest extends ResourceHarness { - @Test - public void loadPropertiesSettings() throws Throwable { - List eclipseFormatFile = createTestFiles("java/eclipse/formatter.properties"); - StepHarness.forStep(EclipseFormatterStep.create(eclipseFormatFile, TestProvisioner.mavenCentral())) - .testResource("java/eclipse/JavaCodeUnformatted.test", "java/eclipse/JavaCodeFormatted.test"); - } - - @Test - public void loadXmlSettings() throws Throwable { - List eclipseFormatFile = createTestFiles("java/eclipse/formatter.xml"); - StepHarness.forStep(EclipseFormatterStep.create(eclipseFormatFile, TestProvisioner.mavenCentral())) - .testResource("java/eclipse/JavaCodeUnformatted.test", "java/eclipse/JavaCodeFormatted.test"); - } - - @Test - public void longLiteralProblem() throws Throwable { - String folder = "java/eclipse/long_literals/"; - List eclipseFormatFile = createTestFiles(folder + "spotless.eclipseformat.xml"); - StepHarness.forStep(EclipseFormatterStep.create(eclipseFormatFile, TestProvisioner.mavenCentral())) - .testResourceUnaffected(folder + "Example1.test") - .testResourceUnaffected(folder + "Example2.test"); - } - - @Test - public void equality() throws IOException { - List xmlFile = createTestFiles("java/eclipse/formatter.xml"); - List propFile = createTestFiles("java/eclipse/formatter.properties"); - new SerializableEqualityTester() { - List settingsFiles; - - @Override - protected void setupTest(API api) { - settingsFiles = xmlFile; - api.areDifferentThan(); - - settingsFiles = propFile; - api.areDifferentThan(); - } - - @Override - protected FormatterStep create() { - return EclipseFormatterStep.create(settingsFiles, TestProvisioner.mavenCentral()); - } - }.testEquals(); - } -} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index c8f1f65e4d..e81074eb2a 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -29,14 +29,12 @@ import com.diffplug.common.base.StringPrinter; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.extra.EclipseBasedStepBuilder; -import com.diffplug.spotless.extra.java.EclipseFormatterStep; import com.diffplug.spotless.extra.java.EclipseJdtFormatterStep; import com.diffplug.spotless.generic.LicenseHeaderStep; import com.diffplug.spotless.java.GoogleJavaFormatStep; import com.diffplug.spotless.java.ImportOrderStep; import com.diffplug.spotless.java.RemoveUnusedImportsStep; -@SuppressWarnings("deprecation") public class JavaExtension extends FormatExtension implements HasBuiltinDelimiterForLicense { static final String NAME = "java"; @@ -82,7 +80,7 @@ public void importOrderFile(Object importOrderFile) { /** Use {@link #eclipse()} instead */ @Deprecated public void eclipseFormatFile(Object eclipseFormatFile) { - eclipseFormatFile(EclipseFormatterStep.defaultVersion(), eclipseFormatFile); + eclipseFormatFile(EclipseJdtFormatterStep.defaultVersion(), eclipseFormatFile); } /** Use {@link #eclipse(String)} instead */ From acb6b8549338ad8aefda936e6b2350266c86300b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 29 Jun 2020 22:19:41 -0700 Subject: [PATCH 12/13] Update changelog. --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index b04f1913e0..4515786d3f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * This change allows the maven plugin to cache classloaders across subprojects when loading config resources from the classpath (fixes [#559](https://github.com/diffplug/spotless/issues/559)). * This change also allows the gradle plugin to work with the remote buildcache (fixes [#280](https://github.com/diffplug/spotless/issues/280)). * **BREAKING** Heavy refactor of the `LicenseHeaderStep` public API. Doesn't change internal behavior, but makes implementation of the gradle and maven plugins much easier. ([#628](https://github.com/diffplug/spotless/pull/628)) +* **BREAKING** Removed all deprecated methods and classes. + * [#629](https://github.com/diffplug/spotless/pull/629) removes the code which wasn't being used in plugin-gradle or plugin-maven. ## [1.34.1] - 2020-06-17 ### Changed From 5e3c41cc571b4c9f3aa4e4d11fbc2d3a463d71d1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 29 Jun 2020 22:35:43 -0700 Subject: [PATCH 13/13] Removed the deprecated parts of EclipseWtpFormatterStep which were unused in the plugins. --- .../extra/wtp/EclipseWtpFormatterStep.java | 29 +------------------ 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java index 045fcc3038..fe45e846d7 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,33 +65,6 @@ public static EclipseBasedStepBuilder createCssBuilder(Provisioner provisioner) return new EclipseBasedStepBuilder(NAME, " - css", provisioner, state -> applyWithoutFile("EclipseCssFormatterStepImpl", state)); } - /** - * Provides default configuration for HTML formatter. - * Method is deprecated. Use {@link EclipseWtpFormatterStep#createBuilder(Provisioner)} instead. - */ - @Deprecated - public static EclipseBasedStepBuilder createHtmlBuilder(Provisioner provisioner) { - return HTML.createBuilder(provisioner); - } - - /** - * Provides default configuration for Java Script formatter. - * Method is deprecated. Use {@link EclipseWtpFormatterStep#createBuilder(Provisioner)} instead. - */ - @Deprecated - public static EclipseBasedStepBuilder createJsBuilder(Provisioner provisioner) { - return JS.createBuilder(provisioner); - } - - /** - * Provides default configuration for JSON formatter. - * Method is deprecated. Use {@link EclipseWtpFormatterStep#createBuilder(Provisioner)} instead. - */ - @Deprecated - public static EclipseBasedStepBuilder createJsonBuilder(Provisioner provisioner) { - return JSON.createBuilder(provisioner); - } - /** * Provides default configuration for XML formatter. * Method is deprecated. Use {@link EclipseWtpFormatterStep#createBuilder(Provisioner)} instead.