diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index a75cbbe39e..1d3a5cc081 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,9 +3,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Added `wildcardsLast` option for Java `importOrder` ([#956](https://github.com/diffplug/spotless/pull/956)) ## [2.16.0] - 2021-10-02 - ### Added * Added support for JBDI bind list params in sql formatter ([#955](https://github.com/diffplug/spotless/pull/955)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 4d19b5a600..08e475eeed 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -179,6 +179,7 @@ any other maven phase (i.e. compile) then it can be configured as below; + false java,javax,org,com,com.diffplug, diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java index 9ff62a1ee2..8476b83733 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * Copyright 2016-2021 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,17 +31,20 @@ public class ImportOrder implements FormatterStepFactory { @Parameter private String order; + @Parameter + private boolean wildcardsLast = false; + @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { if (file != null ^ order != null) { if (file != null) { File importsFile = config.getFileLocator().locateFile(file); - return ImportOrderStep.forJava().createFrom(importsFile); + return ImportOrderStep.forJava().createFrom(wildcardsLast, importsFile); } else { - return ImportOrderStep.forJava().createFrom(order.split(",", -1)); + return ImportOrderStep.forJava().createFrom(wildcardsLast, order.split(",", -1)); } } else if (file == null && order == null) { - return ImportOrderStep.forJava().createFrom(); + return ImportOrderStep.forJava().createFrom(wildcardsLast); } else { throw new IllegalArgumentException("Must specify exactly one of 'file' or 'order'."); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/ImportOrderTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/ImportOrderTest.java index d34aa68d59..2eef48083e 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/ImportOrderTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/ImportOrderTest.java @@ -45,6 +45,15 @@ void standard() throws Exception { runTest("java/importsorter/JavaCodeSortedImportsDefault.test"); } + @Test + void wildcardsLast() throws Exception { + writePomWithJavaSteps( + "", + " true", + ""); + runTest("java/importsorter/JavaCodeSortedImportsWildcardsLast.test"); + } + private void runTest() throws Exception { runTest("java/importsorter/JavaCodeSortedImports.test"); }