diff --git a/CHANGES.md b/CHANGES.md index 143d84f42c..9f0e4eab75 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,7 @@ You might be looking for: * CSS and XML extensions are discontinued ([#325](https://github.com/diffplug/spotless/pull/325)). * Updated default google-java-format from 1.5 to 1.7 ([#335](https://github.com/diffplug/spotless/issues/335)). +* `ImportOrderStep.createFromFile` is now lazy ([#218](https://github.com/diffplug/spotless/issues/218)). ### Version 1.17.0 - October 30th 2018 (javadoc [lib](https://diffplug.github.io/spotless/javadoc/spotless-lib/1.17.0/) [lib-extra](https://diffplug.github.io/spotless/javadoc/spotless-lib-extra/1.17.0/), artifact [lib]([jcenter](https://bintray.com/diffplug/opensource/spotless-lib), [lib-extra]([jcenter](https://bintray.com/diffplug/opensource/spotless-lib-extra))) 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 9bbf2f7151..bdff61d2f8 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -52,17 +53,17 @@ private ImportOrderStep(String lineFormat) { public FormatterStep createFrom(String... importOrder) { // defensive copying and null checking List importOrderList = requireElementsNonNull(Arrays.asList(importOrder)); - return createFrom(importOrderList); + return createFrom(() -> importOrderList); } public FormatterStep createFrom(File importsFile) { Objects.requireNonNull(importsFile); - return createFrom(getImportOrder(importsFile)); + return createFrom(() -> getImportOrder(importsFile)); } - private FormatterStep createFrom(List importOrder) { + private FormatterStep createFrom(Supplier> importOrder) { return FormatterStep.createLazy("importOrder", - () -> new State(importOrder, lineFormat), + () -> new State(importOrder.get(), lineFormat), State::toFormatter); } @@ -71,8 +72,8 @@ private FormatterStep createFrom(List importOrder) { @Deprecated public static FormatterStep createFromOrder(List importOrder) { // defensive copying and null checking - importOrder = requireElementsNonNull(new ArrayList<>(importOrder)); - return forJava().createFrom(importOrder); + List importOrderCopy = requireElementsNonNull(new ArrayList<>(importOrder)); + return forJava().createFrom(() -> importOrderCopy); } /** Static method has been replaced by instance method diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 463fc3bdd8..cb9c701792 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -6,6 +6,7 @@ * Improved configuration times for large projects (thanks to @oehme for finding [#348](https://github.com/diffplug/spotless/pull/348)). * Updated default google-java-format from 1.5 to 1.7 ([#335](https://github.com/diffplug/spotless/issues/335)). * Replacing a step no longer triggers early evaluation ([#219](https://github.com/diffplug/spotless/issues/219)). +* `importOrderFile(Object file)` for java and groovy is now lazy ([#218](https://github.com/diffplug/spotless/issues/218)). ### Version 3.17.0 - December 13th 2018 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-plugin-gradle/3.17.0/), [jcenter](https://bintray.com/diffplug/opensource/spotless-plugin-gradle/3.17.0)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index ff16945d10..3f72b74383 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,6 +4,7 @@ * Provided eclipse-wtp formatters as part of custom source format element. ([#325](https://github.com/diffplug/spotless/pull/325)). This change obsoletes the CSS and XML source elements. * Updated default google-java-format from 1.5 to 1.7 ([#335](https://github.com/diffplug/spotless/issues/335)). +* `somefile` is now lazy ([#218](https://github.com/diffplug/spotless/issues/218)). ### Version 1.17.0 - December 13th 2018 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-maven-plugin/1.17.0/), [jcenter](https://bintray.com/diffplug/opensource/spotless-maven-plugin/1.17.0))