@@ -37,7 +37,7 @@ public class ScalaFmtStep {
37
37
// prevent direct instantiation
38
38
private ScalaFmtStep () {}
39
39
40
- private static final String DEFAULT_VERSION = "0.5.7 " ;
40
+ private static final String DEFAULT_VERSION = "1.1.0 " ;
41
41
static final String NAME = "scalafmt" ;
42
42
static final String MAVEN_COORDINATE = "com.geirsson:scalafmt-core_2.11:" ;
43
43
@@ -92,11 +92,28 @@ FormatterFunc createFormat() throws Exception {
92
92
93
93
Class <?> optionCls = classLoader .loadClass ("scala.Option" );
94
94
Class <?> configCls = classLoader .loadClass ("org.scalafmt.config.Config" );
95
- Method fromHocon = configCls .getMethod ("fromHocon" , String .class , optionCls );
96
- Object fromHoconEmptyPath = configCls .getMethod ("fromHocon$default$2" ).invoke (null );
97
95
98
- String configStr = new String (Files .readAllBytes (file .toPath ()), StandardCharsets .UTF_8 );
99
- Object either = fromHocon .invoke (null , configStr , fromHoconEmptyPath );
96
+ Object either ;
97
+
98
+ 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 );
102
+
103
+ String configStr = new String (Files .readAllBytes (file .toPath ()), StandardCharsets .UTF_8 );
104
+
105
+ Object configured = fromHocon .invoke (null , configStr , fromHoconEmptyPath );
106
+ either = invokeNoArg (configured , "toEither" );
107
+ } 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 );
112
+
113
+ String configStr = new String (Files .readAllBytes (file .toPath ()), StandardCharsets .UTF_8 );
114
+ either = fromHocon .invoke (null , configStr , fromHoconEmptyPath );
115
+ }
116
+
100
117
config = invokeNoArg (invokeNoArg (either , "right" ), "get" );
101
118
}
102
119
return input -> {
0 commit comments