Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ktfmt dropbox style in maven plugin #764

Merged
merged 8 commits into from
Jan 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public static String defaultVersion() {
return DEFAULT_VERSION;
}

public static String defaultStyle() {
return Style.DEFAULT.name();
}

static final class State implements Serializable {
private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 DiffPlug
* Copyright 2016-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -109,7 +109,11 @@ public class KtfmtConfig {
}

public void dropboxStyle() {
style = Style.DROPBOX;
style(Style.DROPBOX);
}

public void style(Style style) {
this.style = style;
replaceStep(createStep());
}

Expand Down
1 change: 1 addition & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Added support for eclipse-cdt 4.18.0.
* Added support for eclipse-jdt 4.18.0.
* Added support for eclipse-wtp 4.18.0.
* Added ability to specify dropbox style for ktfmt `<style>DROPBOX</style>` ([#764](https://github.com/diffplug/spotless/pull/764))
### Changed
* Updated default eclipse-jdt from 4.17.0 to 4.18.0.
* Updated default eclipse-wtp from 4.17.0 to 4.18.0.
Expand Down
3 changes: 2 additions & 1 deletion plugin-maven/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T

```xml
<ktfmt>
<version>0.13</version> <!-- optional -->
<version>0.18</version> <!-- optional -->
<style>DEFAULT</style> <!-- optional, other option is DROPBOX -->
</ktfmt>
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 DiffPlug
* Copyright 2016-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.kotlin.KtfmtStep;
import com.diffplug.spotless.kotlin.KtfmtStep.Style;
import com.diffplug.spotless.maven.FormatterStepConfig;
import com.diffplug.spotless.maven.FormatterStepFactory;

Expand All @@ -27,9 +28,13 @@ public class Ktfmt implements FormatterStepFactory {
@Parameter
private String version;

@Parameter
private String style;

@Override
public FormatterStep newFormatterStep(FormatterStepConfig config) {
String version = this.version != null ? this.version : KtfmtStep.defaultVersion();
return KtfmtStep.create(version, config.getProvisioner());
String style = this.style != null ? this.style : KtfmtStep.defaultStyle();
return KtfmtStep.create(version, config.getProvisioner(), Style.valueOf(style));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 DiffPlug
* Copyright 2016-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,4 +39,16 @@ public void testKtfmt() throws Exception {
assertFile(path1).sameAsResource("kotlin/ktfmt/basic.clean");
assertFile(path2).sameAsResource("kotlin/ktfmt/basic.clean");
}

@Test
public void testKtfmtStyle() throws Exception {
// ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+.
JreVersion.assume11OrGreater();

writePomWithKotlinSteps("<ktfmt><style>DROPBOX</style></ktfmt>");

setFile("src/main/kotlin/main.kt").toResource("kotlin/ktfmt/basic.dirty");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile("src/main/kotlin/main.kt").sameAsResource("kotlin/ktfmt/basic-dropboxstyle.clean");
}
}