Skip to content

Commit 28425df

Browse files
authored
Merge pull request #416 from nsutcliffe/master
New maven coordinates for 2.0.0 release of Scalafmt
2 parents dbf857a + 34bb05b commit 28425df

File tree

8 files changed

+78
-2
lines changed

8 files changed

+78
-2
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ You might be looking for:
77

88
### 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/))
99

10+
* Added new maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415))
11+
1012
### 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)))
1113

1214
* Fixes incorrect M2 cache directory path handling of Eclipse based formatters ([#401](https://github.com/diffplug/spotless/issues/401))

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}}
8989
- 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.
9090
- Thanks to [Konstantin Lutovich](https://github.com/lutovich) for [implementing the maven plugin](https://github.com/diffplug/spotless/pull/188).
9191
- Thanks to [Joan Goyeau](https://github.com/joan38) for [fixing scalafmt integration](https://github.com/diffplug/spotless/pull/260).
92+
- Thanks to [Nick Sutcliffe](https://github.com/nsutcliffe) for [fixing scalafmt post-2.0](https://github.com/diffplug/spotless/pull/416).
9293
- Thanks to [Baptiste Mesta](https://github.com/baptistemesta) for
9394
- 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.
9495
- making license headers date-aware [#179](https://github.com/diffplug/spotless/pull/179)

lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.nio.file.Files;
2424
import java.util.Collections;
2525
import java.util.Objects;
26+
import java.util.regex.Matcher;
27+
import java.util.regex.Pattern;
2628

2729
import javax.annotation.Nullable;
2830

@@ -37,9 +39,11 @@ public class ScalaFmtStep {
3739
// prevent direct instantiation
3840
private ScalaFmtStep() {}
3941

42+
private static final Pattern VERSION_PRE_2_0 = Pattern.compile("[10]\\.(\\d+)\\.\\d+");
4043
private static final String DEFAULT_VERSION = "1.1.0";
4144
static final String NAME = "scalafmt";
42-
static final String MAVEN_COORDINATE = "com.geirsson:scalafmt-core_2.11:";
45+
static final String MAVEN_COORDINATE_PRE_2_0 = "com.geirsson:scalafmt-core_2.11:";
46+
static final String MAVEN_COORDINATE = "org.scalameta:scalafmt-core_2.11:";
4347

4448
public static FormatterStep create(Provisioner provisioner) {
4549
return create(defaultVersion(), provisioner, null);
@@ -64,7 +68,15 @@ static final class State implements Serializable {
6468
final FileSignature configSignature;
6569

6670
State(String version, Provisioner provisioner, @Nullable File configFile) throws IOException {
67-
this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner);
71+
String mavenCoordinate;
72+
Matcher versionMatcher = VERSION_PRE_2_0.matcher(version);
73+
if (versionMatcher.matches()) {
74+
mavenCoordinate = MAVEN_COORDINATE_PRE_2_0;
75+
} else {
76+
mavenCoordinate = MAVEN_COORDINATE;
77+
}
78+
79+
this.jarState = JarState.from(mavenCoordinate + version, provisioner);
6880
this.configSignature = FileSignature.signAsList(configFile == null ? Collections.emptySet() : Collections.singleton(configFile));
6981
}
7082

plugin-gradle/CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### 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/))
44

5+
* Added new maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415))
6+
57
### 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))
68

79
* Fixes incorrect M2 cache directory path handling of Eclipse based formatters ([#401](https://github.com/diffplug/spotless/issues/401))

plugin-maven/CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### 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/))
44

5+
* Added new maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415))
6+
57
### 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))
68

79
* Fixes incorrect M2 cache directory path handling of Eclipse based formatters ([#401](https://github.com/diffplug/spotless/issues/401))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@foobar("annot", {
2+
val x = 2
3+
val y = 2 // y=2
4+
x + y
5+
})
6+
object a extends b with c {
7+
def foo[T: Int#Double#Triple, R <% String](
8+
@annot1
9+
x: Int @annot2 = 2,
10+
y: Int = 3
11+
): Int = {
12+
"match" match {
13+
case 1 | 2 =>
14+
3
15+
case <A>2</A> => 2
16+
}
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@foobar("annot", {
2+
val x = 2
3+
val y = 2 // y=2
4+
x + y
5+
})
6+
object a
7+
extends b
8+
with c {
9+
def foo[
10+
T: Int#Double#Triple,
11+
R <% String
12+
](
13+
@annot1
14+
x: Int @annot2 =
15+
2,
16+
y: Int = 3
17+
): Int = {
18+
"match" match {
19+
case 1 | 2 =>
20+
3
21+
case <A>2</A> =>
22+
2
23+
}
24+
}
25+
}

testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java

+14
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ public void behaviorCustomConfig() throws Exception {
4141
.testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf");
4242
}
4343

44+
@Test
45+
public void behaviorDefaultConfigVersion_2_0_0() throws Exception {
46+
FormatterStep step = ScalaFmtStep.create("2.0.0", TestProvisioner.mavenCentral(), null);
47+
StepHarness.forStep(step)
48+
.testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basicPost2.0.0.clean");
49+
}
50+
51+
@Test
52+
public void behaviorCustomConfigVersion_2_0_0() throws Exception {
53+
FormatterStep step = ScalaFmtStep.create("2.0.0", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf"));
54+
StepHarness.forStep(step)
55+
.testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basicPost2.0.0.cleanWithCustomConf");
56+
}
57+
4458
@Test
4559
public void equality() throws Exception {
4660
new SerializableEqualityTester() {

0 commit comments

Comments
 (0)