Skip to content

Commit 2b249b4

Browse files
authored
Merge branch 'main' into feat/gson-support
2 parents 0da1a1a + 7331070 commit 2b249b4

File tree

13 files changed

+62
-42
lines changed

13 files changed

+62
-42
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1313
### Added
1414
* Added support for JSON formatting based on [Gson](https://github.com/google/gson) ([#1125](https://github.com/diffplug/spotless/pull/1125)).
1515

16+
### Changed
17+
18+
* Use SLF4J for logging ([#1116](https://github.com/diffplug/spotless/issues/1116))
19+
1620
## [2.22.2] - 2022-02-09
1721
### Changed
1822
* Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)).

gradle/javadoc/java8/package-list

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ java.util.concurrent.atomic
5555
java.util.concurrent.locks
5656
java.util.function
5757
java.util.jar
58-
java.util.logging
5958
java.util.prefs
6059
java.util.regex
6160
java.util.spi

lib/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ for (glue in NEEDS_GLUE) {
2121
}
2222

2323
dependencies {
24+
compileOnly 'org.slf4j:slf4j-api:1.7.35'
2425
// zero runtime reqs is a hard requirements for spotless-lib
2526
// if you need a dep, put it in lib-extra
2627
testImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT"
@@ -29,6 +30,7 @@ dependencies {
2930

3031
// used for pom sorting
3132
sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0'
33+
sortPomCompileOnly 'org.slf4j:slf4j-api:1.7.35'
3234

3335
palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0'
3436

lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 DiffPlug
2+
* Copyright 2021-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
1919
import java.util.Collections;
2020
import java.util.List;
2121
import java.util.Map;
22-
import java.util.logging.Logger;
2322

2423
import com.pinterest.ktlint.core.KtLint;
2524
import com.pinterest.ktlint.core.KtLint.Params;
@@ -33,7 +32,6 @@
3332
import kotlin.jvm.functions.Function2;
3433

3534
public class KtlintFormatterFunc implements FormatterFunc.NeedsFile {
36-
private static final Logger logger = Logger.getLogger(KtlintFormatterFunc.class.getName());
3735

3836
private final List<RuleSet> rulesets;
3937
private final Map<String, String> userData;

lib/src/main/java/com/diffplug/spotless/FormatExceptionPolicyLegacy.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,13 +15,13 @@
1515
*/
1616
package com.diffplug.spotless;
1717

18-
import java.util.logging.Level;
19-
import java.util.logging.Logger;
18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
2020

2121
class FormatExceptionPolicyLegacy extends NoLambda.EqualityBasedOnSerialization implements FormatExceptionPolicy {
2222
private static final long serialVersionUID = 1L;
2323

24-
private static final Logger logger = Logger.getLogger(Formatter.class.getName());
24+
private static final Logger logger = LoggerFactory.getLogger(Formatter.class);
2525

2626
@Override
2727
public void handleError(Throwable e, FormatterStep step, String relativePath) {
@@ -34,10 +34,10 @@ public void handleError(Throwable e, FormatterStep step, String relativePath) {
3434
}
3535

3636
static void error(Throwable e, FormatterStep step, String relativePath) {
37-
logger.log(Level.SEVERE, "Step '" + step.getName() + "' found problem in '" + relativePath + "':\n" + e.getMessage(), e);
37+
logger.error("Step '{}' found problem in '{}':\n{}", step.getName(), relativePath, e.getMessage(), e);
3838
}
3939

4040
static void warning(Throwable e, FormatterStep step, String relativePath) {
41-
logger.log(Level.WARNING, "Unable to apply step '" + step.getName() + "' to '" + relativePath + "'", e);
41+
logger.warn("Unable to apply step '{}' to '{}'", step.getName(), relativePath, e);
4242
}
4343
}

lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,9 @@
2424
import java.util.Objects;
2525
import java.util.TreeMap;
2626
import java.util.function.Consumer;
27-
import java.util.logging.Logger;
27+
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
2830

2931
import com.diffplug.spotless.FormatterFunc;
3032
import com.diffplug.spotless.FormatterStep;
@@ -78,8 +80,8 @@ private static class State implements Serializable {
7880
}
7981

8082
FormatterFunc createFormat() throws Exception {
81-
Logger logger = Logger.getLogger(FreshMarkStep.class.getName());
82-
Consumer<String> loggingStream = logger::warning;
83+
Logger logger = LoggerFactory.getLogger(FreshMarkStep.class);
84+
Consumer<String> loggingStream = logger::warn;
8385

8486
ClassLoader classLoader = jarState.getClassLoader();
8587

lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,9 @@
2727
import java.util.Map.Entry;
2828
import java.util.concurrent.TimeUnit;
2929
import java.util.concurrent.TimeoutException;
30-
import java.util.logging.Logger;
30+
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
3133

3234
import com.diffplug.spotless.FileSignature;
3335
import com.diffplug.spotless.FormatterFunc;
@@ -36,7 +38,7 @@
3638

3739
abstract class NpmFormatterStepStateBase implements Serializable {
3840

39-
private static final Logger logger = Logger.getLogger(NpmFormatterStepStateBase.class.getName());
41+
private static final Logger logger = LoggerFactory.getLogger(NpmFormatterStepStateBase.class);
4042

4143
private static final long serialVersionUID = 1460749955865959948L;
4244

@@ -166,13 +168,15 @@ public String getBaseUrl() {
166168
@Override
167169
public void close() throws Exception {
168170
try {
169-
logger.fine("Closing npm server in directory <" + serverPortFile.getParent() + "> and port <" + serverPort + ">");
171+
logger.trace("Closing npm server in directory <{}> and port <{}>",
172+
serverPortFile.getParent(), serverPort);
173+
170174
if (server.isAlive()) {
171175
boolean ended = server.waitFor(5, TimeUnit.SECONDS);
172176
if (!ended) {
173-
logger.info("Force-Closing npm server in directory <" + serverPortFile.getParent() + "> and port <" + serverPort + ">");
177+
logger.info("Force-Closing npm server in directory <{}> and port <{}>", serverPortFile.getParent(), serverPort);
174178
server.destroyForcibly().waitFor();
175-
logger.fine("Force-Closing npm server in directory <" + serverPortFile.getParent() + "> and port <" + serverPort + "> -- Finished");
179+
logger.trace("Force-Closing npm server in directory <{}> and port <{}> -- Finished", serverPortFile.getParent(), serverPort);
176180
}
177181
}
178182
} finally {

lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,11 +23,12 @@
2323
import java.util.Collections;
2424
import java.util.Map;
2525
import java.util.TreeMap;
26-
import java.util.logging.Level;
27-
import java.util.logging.Logger;
2826

2927
import javax.annotation.Nonnull;
3028

29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
31+
3132
import com.diffplug.spotless.FormatterFunc;
3233
import com.diffplug.spotless.FormatterFunc.Closeable;
3334
import com.diffplug.spotless.FormatterStep;
@@ -36,7 +37,7 @@
3637

3738
public class PrettierFormatterStep {
3839

39-
private static final Logger logger = Logger.getLogger(PrettierFormatterStep.class.getName());
40+
private static final Logger logger = LoggerFactory.getLogger(PrettierFormatterStep.class);
4041

4142
public static final String NAME = "prettier-format";
4243

@@ -95,7 +96,7 @@ private void endServer(PrettierRestService restService, ServerProcessInfo restSe
9596
try {
9697
restService.shutdown();
9798
} catch (Throwable t) {
98-
logger.log(Level.INFO, "Failed to request shutdown of rest service via api. Trying via process.", t);
99+
logger.info("Failed to request shutdown of rest service via api. Trying via process.", t);
99100
}
100101
restServer.close();
101102
}

lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,12 +21,13 @@
2121
import java.io.IOException;
2222
import java.io.Serializable;
2323
import java.util.*;
24-
import java.util.logging.Level;
25-
import java.util.logging.Logger;
2624

2725
import javax.annotation.Nonnull;
2826
import javax.annotation.Nullable;
2927

28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
30+
3031
import com.diffplug.spotless.FormatterFunc;
3132
import com.diffplug.spotless.FormatterFunc.Closeable;
3233
import com.diffplug.spotless.FormatterStep;
@@ -35,7 +36,7 @@
3536

3637
public class TsFmtFormatterStep {
3738

38-
private static final Logger logger = Logger.getLogger(TsFmtFormatterStep.class.getName());
39+
private static final Logger logger = LoggerFactory.getLogger(TsFmtFormatterStep.class);
3940

4041
public static final String NAME = "tsfmt-format";
4142

@@ -115,7 +116,7 @@ private void endServer(TsFmtRestService restService, ServerProcessInfo restServe
115116
try {
116117
restService.shutdown();
117118
} catch (Throwable t) {
118-
logger.log(Level.INFO, "Failed to request shutdown of rest service via api. Trying via process.", t);
119+
logger.info("Failed to request shutdown of rest service via api. Trying via process.", t);
119120
}
120121
restServer.close();
121122
}

lib/src/sortPom/java/com/diffplug/spotless/glue/pom/SortPomFormatterFunc.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 DiffPlug
2+
* Copyright 2021-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,9 +18,10 @@
1818
import java.io.File;
1919
import java.io.FileInputStream;
2020
import java.io.FileOutputStream;
21-
import java.util.logging.Logger;
2221

2322
import org.apache.commons.io.IOUtils;
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
2425

2526
import com.diffplug.spotless.FormatterFunc;
2627
import com.diffplug.spotless.pom.SortPomCfg;
@@ -30,7 +31,7 @@
3031
import sortpom.parameter.PluginParameters;
3132

3233
public class SortPomFormatterFunc implements FormatterFunc {
33-
private static final Logger logger = Logger.getLogger(SortPomFormatterFunc.class.getName());
34+
private static final Logger logger = LoggerFactory.getLogger(SortPomFormatterFunc.class);
3435
private final SortPomCfg cfg;
3536

3637
public SortPomFormatterFunc(SortPomCfg cfg) {
@@ -61,7 +62,7 @@ public String apply(String input) throws Exception {
6162
private static class MySortPomLogger implements SortPomLogger {
6263
@Override
6364
public void warn(String content) {
64-
logger.warning(content);
65+
logger.warn(content);
6566
}
6667

6768
@Override
@@ -71,7 +72,7 @@ public void info(String content) {
7172

7273
@Override
7374
public void error(String content) {
74-
logger.severe(content);
75+
logger.error(content);
7576
}
7677
}
7778
}

plugin-gradle/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
66
### Added
77
* Added support for JSON formatting based on [Gson](https://github.com/google/gson) ([#1125](https://github.com/diffplug/spotless/pull/1125)).
88

9+
### Changed
10+
11+
* Use SLF4J for logging ([#1116](https://github.com/diffplug/spotless/issues/1116))
12+
913
## [6.2.2] - 2022-02-09
1014
### Changed
1115
* Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)).

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,8 +20,6 @@
2020
import java.util.HashMap;
2121
import java.util.Map;
2222
import java.util.Set;
23-
import java.util.logging.Level;
24-
import java.util.logging.Logger;
2523

2624
import org.gradle.api.GradleException;
2725
import org.gradle.api.Project;
@@ -30,6 +28,8 @@
3028
import org.gradle.api.artifacts.dsl.DependencyHandler;
3129
import org.gradle.api.attributes.Bundling;
3230
import org.gradle.api.initialization.dsl.ScriptHandler;
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
3333

3434
import com.diffplug.common.base.Unhandled;
3535
import com.diffplug.common.collect.ImmutableList;
@@ -127,17 +127,17 @@ private static Provisioner forConfigurationContainer(Project project, Configurat
127127
if (!projName.isEmpty()) {
128128
projName = projName + "/";
129129
}
130-
logger.log(
131-
Level.SEVERE,
132-
"You need to add a repository containing the '" + mavenCoords + "' artifact in '" + projName + "build.gradle'.\n" +
130+
logger.error(
131+
"You need to add a repository containing the '{}' artifact in '{}build.gradle'.\n" +
133132
"E.g.: 'repositories { mavenCentral() }'",
133+
mavenCoords, projName,
134134
e);
135135
throw e;
136136
}
137137
};
138138
}
139139

140-
private static final Logger logger = Logger.getLogger(GradleProvisioner.class.getName());
140+
private static final Logger logger = LoggerFactory.getLogger(GradleProvisioner.class);
141141

142142
/** Models a request to the provisioner. */
143143
private static class Request {

plugin-maven/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
44

55
## [Unreleased]
66

7+
### Changed
8+
9+
* Use SLF4J for logging ([#1116](https://github.com/diffplug/spotless/issues/1116))
10+
711
## [2.20.2] - 2022-02-09
812
### Changed
913
* Bump default ktfmt `0.30` -> `0.31` ([#1118](https://github.com/diffplug/spotless/pull/1118)).

0 commit comments

Comments
 (0)