From 170406728f878cc6da12fb14f87110f9aff7237e Mon Sep 17 00:00:00 2001 From: Joan Goyeau Date: Sat, 7 Jul 2018 11:55:15 +0200 Subject: [PATCH] Use guaranteed binary and source compatibility between releases of Scalafmt --- .../diffplug/spotless/scala/ScalaFmtStep.java | 23 ++++--------------- 1 file changed, 5 insertions(+), 18 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 6a856f3ec1..4079192b7a 100644 --- a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java @@ -90,29 +90,16 @@ FormatterFunc createFormat() throws Exception { } else { File file = configSignature.getOnlyFile(); - Class optionCls = classLoader.loadClass("scala.Option"); - Class configCls = classLoader.loadClass("org.scalafmt.config.Config"); + Class configCls = classLoader.loadClass("org.scalafmt.Scalafmt"); Object either; - try { - // scalafmt >= v0.7.0-RC1 - Method fromHocon = configCls.getMethod("fromHoconString", String.class, optionCls); - Object fromHoconEmptyPath = configCls.getMethod("fromHoconString$default$2").invoke(null); + Method fromHocon = configCls.getMethod("fromHoconString", String.class); - String configStr = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); + String configStr = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); - Object configured = fromHocon.invoke(null, configStr, fromHoconEmptyPath); - either = invokeNoArg(configured, "toEither"); - } catch (NoSuchMethodException e) { - // In case of a NoSuchMethodException try old configuration API - // scalafmt <= v0.6.8 - Method fromHocon = configCls.getMethod("fromHocon", String.class, optionCls); - Object fromHoconEmptyPath = configCls.getMethod("fromHocon$default$2").invoke(null); - - String configStr = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); - either = fromHocon.invoke(null, configStr, fromHoconEmptyPath); - } + Object configured = fromHocon.invoke(null, configStr); + either = invokeNoArg(configured, "toEither"); config = invokeNoArg(invokeNoArg(either, "right"), "get"); }