Skip to content

Commit

Permalink
Fix #218 - ImportOrderStep.createFromFile is now lazy. (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Feb 10, 2019
1 parent 220b374 commit b7032ee
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -52,17 +53,17 @@ private ImportOrderStep(String lineFormat) {
public FormatterStep createFrom(String... importOrder) {
// defensive copying and null checking
List<String> 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<String> importOrder) {
private FormatterStep createFrom(Supplier<List<String>> importOrder) {
return FormatterStep.createLazy("importOrder",
() -> new State(importOrder, lineFormat),
() -> new State(importOrder.get(), lineFormat),
State::toFormatter);
}

Expand All @@ -71,8 +72,8 @@ private FormatterStep createFrom(List<String> importOrder) {
@Deprecated
public static FormatterStep createFromOrder(List<String> importOrder) {
// defensive copying and null checking
importOrder = requireElementsNonNull(new ArrayList<>(importOrder));
return forJava().createFrom(importOrder);
List<String> importOrderCopy = requireElementsNonNull(new ArrayList<>(importOrder));
return forJava().createFrom(() -> importOrderCopy);
}

/** Static method has been replaced by instance method
Expand Down
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
1 change: 1 addition & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
* `<importOrder><file>somefile</file></importOrder>` 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))

Expand Down

0 comments on commit b7032ee

Please sign in to comment.