Skip to content

Commit

Permalink
Fix changelog merge conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Feb 9, 2022
2 parents 6889321 + 0a44147 commit e4d025b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ This document is intended for Spotless developers.
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).

## [Unreleased]
# Add full support for git worktrees ([#1119](https://github.com/diffplug/spotless/pull/1119))
### Changed
* Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)).

## [2.22.1] - 2022-02-01
### Changed
Expand Down
34 changes: 26 additions & 8 deletions lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class KtfmtStep {
// prevent direct instantiation
private KtfmtStep() {}

private static final String DEFAULT_VERSION = "0.30";
private static final String DEFAULT_VERSION = "0.31";
static final String NAME = "ktfmt";
static final String PACKAGE = "com.facebook";
static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:";
Expand Down Expand Up @@ -120,18 +120,16 @@ static final class State implements Serializable {

FormatterFunc createFormat() throws Exception {
ClassLoader classLoader = jarState.getClassLoader();
Class<?> formatterClazz = classLoader.loadClass(pkg + ".ktfmt.FormatterKt");
return input -> {
try {
if (style == DEFAULT) {
Method formatterMethod = formatterClazz.getMethod(FORMATTER_METHOD, String.class);
return (String) formatterMethod.invoke(formatterClazz, input);
Method formatterMethod = getFormatterClazz(classLoader).getMethod(FORMATTER_METHOD, String.class);
return (String) formatterMethod.invoke(getFormatterClazz(classLoader), input);
} else {
Class<?> formattingOptionsClazz = classLoader.loadClass(pkg + ".ktfmt.FormattingOptions");
Method formatterMethod = formatterClazz.getMethod(FORMATTER_METHOD, formattingOptionsClazz,
Method formatterMethod = getFormatterClazz(classLoader).getMethod(FORMATTER_METHOD, getFormattingOptionsClazz(classLoader),
String.class);
Object formattingOptions = getCustomFormattingOptions(classLoader, style);
return (String) formatterMethod.invoke(formatterClazz, formattingOptions, input);
return (String) formatterMethod.invoke(getFormatterClazz(classLoader), formattingOptions, input);
}
} catch (InvocationTargetException e) {
throw ThrowingEx.unwrapCause(e);
Expand All @@ -146,7 +144,7 @@ private Object getCustomFormattingOptions(ClassLoader classLoader, Style style)

try {
// ktfmt v0.19 and later
return classLoader.loadClass(pkg + ".ktfmt.FormatterKt").getField(style.getFormat()).get(null);
return getFormatterClazz(classLoader).getField(style.getFormat()).get(null);
} catch (NoSuchFieldException ignored) {}

// fallback to old, pre-0.19 ktfmt interface.
Expand All @@ -159,5 +157,25 @@ private Object getCustomFormattingOptions(ClassLoader classLoader, Style style)
throw new IllegalStateException("Versions pre-0.19 can only use Default and Dropbox styles");
}
}

private Class<?> getFormatterClazz(ClassLoader classLoader) throws Exception {
Class<?> formatterClazz;
if (BadSemver.version(version) >= BadSemver.version(0, 31)) {
formatterClazz = classLoader.loadClass(pkg + ".ktfmt.format.Formatter");
} else {
formatterClazz = classLoader.loadClass(pkg + ".ktfmt.FormatterKt");
}
return formatterClazz;
}

private Class<?> getFormattingOptionsClazz(ClassLoader classLoader) throws Exception {
Class<?> formattingOptionsClazz;
if (BadSemver.version(version) >= BadSemver.version(0, 31)) {
formattingOptionsClazz = classLoader.loadClass(pkg + ".ktfmt.format.FormattingOptions");
} else {
formattingOptionsClazz = classLoader.loadClass(pkg + ".ktfmt.FormattingOptions");
}
return formattingOptionsClazz;
}
}
}
3 changes: 2 additions & 1 deletion plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).

## [Unreleased]
# Add full support for git worktrees ([#1119](https://github.com/diffplug/spotless/pull/1119))
### Changed
* Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)).

## [6.2.1] - 2022-02-01
### Changed
Expand Down
3 changes: 2 additions & 1 deletion plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).

## [Unreleased]
# Add full support for git worktrees ([#1119](https://github.com/diffplug/spotless/pull/1119))
### Changed
* Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)).

## [2.20.1] - 2022-02-01
* Bump default versions of formatters ([#1095](https://github.com/diffplug/spotless/pull/1095)).
Expand Down

0 comments on commit e4d025b

Please sign in to comment.