Skip to content

Commit 4cbb787

Browse files
joan38nedtwigg
authored andcommitted
Use guaranteed binary and source compatibility between releases of Scalafmt (#260)
* Use guaranteed binary and source compatibility between releases of Scalafmt * Update CHANGE.md
1 parent bef05d1 commit 4cbb787

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -92,34 +92,34 @@ FormatterFunc createFormat() throws Exception {
9292

9393
Class<?> optionCls = classLoader.loadClass("scala.Option");
9494
Class<?> configCls = classLoader.loadClass("org.scalafmt.config.Config");
95+
Class<?> scalafmtCls = classLoader.loadClass("org.scalafmt.Scalafmt");
9596

9697
Object either;
9798

9899
try {
99-
// scalafmt >= v0.7.0-RC1
100-
Method fromHocon = configCls.getMethod("fromHoconString", String.class, optionCls);
101-
Object fromHoconEmptyPath = configCls.getMethod("fromHoconString$default$2").invoke(null);
100+
// scalafmt >= 1.6.0
101+
Method parseHoconConfig = scalafmtCls.getMethod("parseHoconConfig", String.class);
102102

103103
String configStr = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
104104

105-
Object configured = fromHocon.invoke(null, configStr, fromHoconEmptyPath);
105+
Object configured = parseHoconConfig.invoke(null, configStr);
106106
either = invokeNoArg(configured, "toEither");
107107
} catch (NoSuchMethodException e) {
108-
// In case of a NoSuchMethodException try old configuration API
109-
// scalafmt <= v0.6.8
110-
Method fromHocon = configCls.getMethod("fromHocon", String.class, optionCls);
111-
Object fromHoconEmptyPath = configCls.getMethod("fromHocon$default$2").invoke(null);
108+
// scalafmt >= v0.7.0-RC1 && scalafmt < 1.6.0
109+
Method fromHocon = configCls.getMethod("fromHoconString", String.class, optionCls);
110+
Object fromHoconEmptyPath = configCls.getMethod("fromHoconString$default$2").invoke(null);
112111

113112
String configStr = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
114-
either = fromHocon.invoke(null, configStr, fromHoconEmptyPath);
113+
114+
Object configured = fromHocon.invoke(null, configStr, fromHoconEmptyPath);
115+
either = invokeNoArg(configured, "toEither");
115116
}
116117

117118
config = invokeNoArg(invokeNoArg(either, "right"), "get");
118119
}
119120
return input -> {
120121
Object resultInsideFormatted = formatMethod.invoke(null, input, config, emptyRange);
121-
String result = (String) formattedGet.invoke(resultInsideFormatted);
122-
return result;
122+
return (String) formattedGet.invoke(resultInsideFormatted);
123123
};
124124
}
125125
}

plugin-gradle/CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Updated default groovy-eclipse from 4.6.3 to 4.8.0 ([#244](https://github.com/diffplug/spotless/pull/244)). New version allows to ignore internal formatter errors/warnings.
66
* Updated default eclipse-jdt from 4.7.2 to 4.7.3a ([#263](https://github.com/diffplug/spotless/issues/263)). New version fixes a bug preventing Java code formatting within JavaDoc comments ([#191](https://github.com/diffplug/spotless/issues/191)).
77
* Eclipse formatter versions decoupled from Spotless formatter step implementations to allow independent updates of M2 based Eclipse dependencies. ([#253](https://github.com/diffplug/spotless/pull/253))
8+
* Use guaranteed binary and source compatibility between releases of Scalafmt. ([#260](https://github.com/diffplug/spotless/pull/260))
89

910
### Version 3.13.0 - June 1st 2018 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-plugin-gradle/3.13.0/), [jcenter](https://bintray.com/diffplug/opensource/spotless-plugin-gradle/3.13.0))
1011

0 commit comments

Comments
 (0)