From ca205b77ccc1255e16bf1def573e85b6881b645f Mon Sep 17 00:00:00 2001 From: Nick Sutcliffe Date: Mon, 8 Jul 2019 15:54:14 +0100 Subject: [PATCH 1/7] New maven coordinates for 2.0.0 release of Scalafmt --- .../java/com/diffplug/spotless/scala/ScalaFmtStep.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java index 05244cda4a..a912ca3ba2 100644 --- a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java @@ -39,7 +39,8 @@ private ScalaFmtStep() {} private static final String DEFAULT_VERSION = "1.1.0"; static final String NAME = "scalafmt"; - static final String MAVEN_COORDINATE = "com.geirsson:scalafmt-core_2.11:"; + static final String MAVEN_COORDINATE_PRE_2 = "com.geirsson:scalafmt-core_2.11:"; + static final String MAVEN_COORDINATE = "org.scalameta:scalafmt-core_2.11:"; public static FormatterStep create(Provisioner provisioner) { return create(defaultVersion(), provisioner, null); @@ -64,7 +65,11 @@ static final class State implements Serializable { final FileSignature configSignature; State(String version, Provisioner provisioner, @Nullable File configFile) throws IOException { - this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner); + String MAVEN_COORDINATE_FOR_VERSION; + if (Integer.parseInt(version.substring(0,1)) < 2) MAVEN_COORDINATE_FOR_VERSION = MAVEN_COORDINATE_PRE_2; + else MAVEN_COORDINATE_FOR_VERSION = MAVEN_COORDINATE; + + this.jarState = JarState.from(MAVEN_COORDINATE_FOR_VERSION + version, provisioner); this.configSignature = FileSignature.signAsList(configFile == null ? Collections.emptySet() : Collections.singleton(configFile)); } From 23dd9f3d0711ecd4e3fffea574ffd325572b1372 Mon Sep 17 00:00:00 2001 From: Nick Sutcliffe Date: Mon, 8 Jul 2019 16:30:19 +0100 Subject: [PATCH 2/7] Updating CHANGES.md --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 300be39a38..63d3092f4b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,8 @@ You might be looking for: ### Version 1.24.0-SNAPSHOT - TBD (javadoc [lib](https://diffplug.github.io/spotless/javadoc/spotless-lib/snapshot/) [lib-extra](https://diffplug.github.io/spotless/javadoc/spotless-lib-extra/snapshot/), [snapshot repo](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/)) +* Added new maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415)) + ### Version 1.23.1 - June 17th 2018 (javadoc [lib](https://diffplug.github.io/spotless/javadoc/spotless-lib/1.23.1/) [lib-extra](https://diffplug.github.io/spotless/javadoc/spotless-lib-extra/1.23.1/), artifact [lib]([jcenter](https://bintray.com/diffplug/opensource/spotless-lib), [lib-extra]([jcenter](https://bintray.com/diffplug/opensource/spotless-lib-extra))) * Fixes incorrect M2 cache directory path handling of Eclipse based formatters ([#401](https://github.com/diffplug/spotless/issues/401)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 45a75a1d23..d37a38badc 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -2,6 +2,8 @@ ### Version 3.24.0-SNAPSHOT - TBD ([javadoc](https://diffplug.github.io/spotless/javadoc/snapshot/), [snapshot](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/spotless-plugin-gradle/)) +* Added new maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415)) + ### Version 3.23.1 - June 17th 2019 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-plugin-gradle/3.23.1/), [jcenter](https://bintray.com/diffplug/opensource/spotless-plugin-gradle/3.23.1)) * Fixes incorrect M2 cache directory path handling of Eclipse based formatters ([#401](https://github.com/diffplug/spotless/issues/401)) From 81a89b5fc0bd23943710b067788afe42af1c4665 Mon Sep 17 00:00:00 2001 From: Nick Sutcliffe Date: Mon, 8 Jul 2019 18:48:09 +0100 Subject: [PATCH 3/7] Regex to match version, tidying code --- .../diffplug/spotless/scala/ScalaFmtStep.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java index a912ca3ba2..f6bdc6caa0 100644 --- a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java @@ -23,6 +23,8 @@ import java.nio.file.Files; import java.util.Collections; import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.annotation.Nullable; @@ -37,9 +39,10 @@ public class ScalaFmtStep { // prevent direct instantiation private ScalaFmtStep() {} + private static final Pattern VERSION_PRE_2_0 = Pattern.compile("[10]\\.(\\d+)\\.\\d+"); private static final String DEFAULT_VERSION = "1.1.0"; static final String NAME = "scalafmt"; - static final String MAVEN_COORDINATE_PRE_2 = "com.geirsson:scalafmt-core_2.11:"; + static final String MAVEN_COORDINATE_PRE_2_0 = "com.geirsson:scalafmt-core_2.11:"; static final String MAVEN_COORDINATE = "org.scalameta:scalafmt-core_2.11:"; public static FormatterStep create(Provisioner provisioner) { @@ -65,11 +68,15 @@ static final class State implements Serializable { final FileSignature configSignature; State(String version, Provisioner provisioner, @Nullable File configFile) throws IOException { - String MAVEN_COORDINATE_FOR_VERSION; - if (Integer.parseInt(version.substring(0,1)) < 2) MAVEN_COORDINATE_FOR_VERSION = MAVEN_COORDINATE_PRE_2; - else MAVEN_COORDINATE_FOR_VERSION = MAVEN_COORDINATE; + String mavenCoordinate; + Matcher versionMatcher = VERSION_PRE_2_0.matcher(version); + if (versionMatcher.matches()) { + mavenCoordinate = MAVEN_COORDINATE_PRE_2_0; + } else { + mavenCoordinate = MAVEN_COORDINATE; + } - this.jarState = JarState.from(MAVEN_COORDINATE_FOR_VERSION + version, provisioner); + this.jarState = JarState.from(mavenCoordinate + version, provisioner); this.configSignature = FileSignature.signAsList(configFile == null ? Collections.emptySet() : Collections.singleton(configFile)); } From 501bfddd98edfe6fd9ab43bfc9ac9d66e1d58ae4 Mon Sep 17 00:00:00 2001 From: Nick Sutcliffe Date: Mon, 8 Jul 2019 18:50:41 +0100 Subject: [PATCH 4/7] Adding changes to plugin-maven/CHANGES.md --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index c3bfe0b5c2..3892dfff45 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -2,6 +2,8 @@ ### Version 1.24.0-SNAPSHOT - TBD ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-maven-plugin/snapshot/), [snapshot](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/spotless-maven-plugin/)) +* Added new maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415)) + ### Version 1.23.1 - June 17th 2019 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-maven-plugin/1.23.1/), [jcenter](https://bintray.com/diffplug/opensource/spotless-maven-plugin/1.23.1)) * Fixes incorrect M2 cache directory path handling of Eclipse based formatters ([#401](https://github.com/diffplug/spotless/issues/401)) From 305fc450f1959df525e127c7045a09c8c6adb8a7 Mon Sep 17 00:00:00 2001 From: Nick Sutcliffe Date: Mon, 8 Jul 2019 22:13:51 +0100 Subject: [PATCH 5/7] Adding Scalafmt 2.0.0 tests --- .../diffplug/spotless/scala/ScalaFmtStepTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java index 21b4372f70..31e18cd2d8 100644 --- a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java @@ -41,6 +41,20 @@ public void behaviorCustomConfig() throws Exception { .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf"); } + @Test + public void behaviorDefaultConfigVersion_2_0_0() throws Exception { + FormatterStep step = ScalaFmtStep.create("2.0.0", TestProvisioner.mavenCentral(), null); + StepHarness.forStep(step) + .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.clean"); + } + + @Test + public void behaviorCustomConfigVersion_2_0_0() throws Exception { + FormatterStep step = ScalaFmtStep.create("2.0.0", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf")); + StepHarness.forStep(step) + .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf"); + } + @Test public void equality() throws Exception { new SerializableEqualityTester() { From 95516c8dad02909a163b2cb81761970ea045dd58 Mon Sep 17 00:00:00 2001 From: Nick Sutcliffe Date: Mon, 8 Jul 2019 22:55:47 +0100 Subject: [PATCH 6/7] Updating test data for 2.0.0 due to new defaults align.openParenDefnSite --- .../scala/scalafmt/basicPost2.0.0.clean | 18 +++++++++++++ .../basicPost2.0.0.cleanWithCustomConf | 25 +++++++++++++++++++ .../spotless/scala/ScalaFmtStepTest.java | 4 +-- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 testlib/src/main/resources/scala/scalafmt/basicPost2.0.0.clean create mode 100644 testlib/src/main/resources/scala/scalafmt/basicPost2.0.0.cleanWithCustomConf diff --git a/testlib/src/main/resources/scala/scalafmt/basicPost2.0.0.clean b/testlib/src/main/resources/scala/scalafmt/basicPost2.0.0.clean new file mode 100644 index 0000000000..b838dfea65 --- /dev/null +++ b/testlib/src/main/resources/scala/scalafmt/basicPost2.0.0.clean @@ -0,0 +1,18 @@ +@foobar("annot", { + val x = 2 + val y = 2 // y=2 + x + y +}) +object a extends b with c { + def foo[T: Int#Double#Triple, R <% String]( + @annot1 + x: Int @annot2 = 2, + y: Int = 3 + ): Int = { + "match" match { + case 1 | 2 => + 3 + case 2 => 2 + } + } +} diff --git a/testlib/src/main/resources/scala/scalafmt/basicPost2.0.0.cleanWithCustomConf b/testlib/src/main/resources/scala/scalafmt/basicPost2.0.0.cleanWithCustomConf new file mode 100644 index 0000000000..fc8267fb75 --- /dev/null +++ b/testlib/src/main/resources/scala/scalafmt/basicPost2.0.0.cleanWithCustomConf @@ -0,0 +1,25 @@ +@foobar("annot", { + val x = 2 + val y = 2 // y=2 + x + y +}) +object a + extends b + with c { + def foo[ + T: Int#Double#Triple, + R <% String + ]( + @annot1 + x: Int @annot2 = + 2, + y: Int = 3 + ): Int = { + "match" match { + case 1 | 2 => + 3 + case 2 => + 2 + } + } +} diff --git a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java index 31e18cd2d8..e91eeb175e 100644 --- a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java @@ -45,14 +45,14 @@ public void behaviorCustomConfig() throws Exception { public void behaviorDefaultConfigVersion_2_0_0() throws Exception { FormatterStep step = ScalaFmtStep.create("2.0.0", TestProvisioner.mavenCentral(), null); StepHarness.forStep(step) - .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.clean"); + .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basicPost2.0.0.clean"); } @Test public void behaviorCustomConfigVersion_2_0_0() throws Exception { FormatterStep step = ScalaFmtStep.create("2.0.0", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf")); StepHarness.forStep(step) - .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf"); + .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basicPost2.0.0.cleanWithCustomConf"); } @Test From 34bb05b9ed30eff7f8a18cdf1dd59707f4572168 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 8 Jul 2019 15:04:27 -0700 Subject: [PATCH 7/7] Add Nick Sutcliffe to the credits. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e7287e99cf..7e669c3a2e 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} - Thanks to [Frank Vennemeyer](https://github.com/fvgh) for [Groovy support via greclipse](https://github.com/diffplug/spotless/issues/13), [C++ support via CDT](https://github.com/diffplug/spotless/issues/232), [XML support via WTP](https://github.com/diffplug/spotless/pull/241) and a huge body of work with other eclipse-based formatters. - Thanks to [Konstantin Lutovich](https://github.com/lutovich) for [implementing the maven plugin](https://github.com/diffplug/spotless/pull/188). - Thanks to [Joan Goyeau](https://github.com/joan38) for [fixing scalafmt integration](https://github.com/diffplug/spotless/pull/260). +- Thanks to [Nick Sutcliffe](https://github.com/nsutcliffe) for [fixing scalafmt post-2.0](https://github.com/diffplug/spotless/pull/416). - Thanks to [Baptiste Mesta](https://github.com/baptistemesta) for - porting the DBeaver formatter to Spotless, and thanks to [DBeaver](https://dbeaver.jkiss.org/) and [its authors](https://github.com/serge-rider/dbeaver/graphs/contributors) for their excellent SQL formatter. - making license headers date-aware [#179](https://github.com/diffplug/spotless/pull/179)