Skip to content

Commit 6e07578

Browse files
committed
moving npm based formatters from lib-extra to lib
and adapt dependencies where needed.
1 parent 3d3f304 commit 6e07578

30 files changed

+51
-64
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ lib('java.RemoveUnusedImportsStep') +'{{yes}} | {{yes}}
4545
extra('java.EclipseFormatterStep') +'{{yes}} | {{yes}} | {{no}} |',
4646
lib('kotlin.KtLintStep') +'{{yes}} | {{yes}} | {{no}} |',
4747
lib('markdown.FreshMarkStep') +'{{yes}} | {{no}} | {{no}} |',
48-
extra('npm.PrettierFormatterStep') +'{{yes}} | {{no}} | {{no}} |',
49-
extra('npm.TsFmtFormatterStep') +'{{yes}} | {{no}} | {{no}} |',
48+
lib('npm.PrettierFormatterStep') +'{{yes}} | {{no}} | {{no}} |',
49+
lib('npm.TsFmtFormatterStep') +'{{yes}} | {{no}} | {{no}} |',
5050
lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{no}} |',
5151
lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{no}} | {{no}} |',
5252
'| [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | {{no}} | {{no}} | {{no}} |',
@@ -70,8 +70,8 @@ lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{no}}
7070
| [`java.EclipseFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseFormatterStep.java) | :+1: | :+1: | :white_large_square: |
7171
| [`kotlin.KtLintStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java) | :+1: | :+1: | :white_large_square: |
7272
| [`markdown.FreshMarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java) | :+1: | :white_large_square: | :white_large_square: |
73-
| [`npm.PrettierFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/npm/PrettierFormatterStep.java) | :+1: | :white_large_square: | :white_large_square: |
74-
| [`npm.TsFmtFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/npm/TsFmtFormatterStep.java) | :+1: | :white_large_square: | :white_large_square: |
73+
| [`npm.PrettierFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java) | :+1: | :white_large_square: | :white_large_square: |
74+
| [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :white_large_square: | :white_large_square: |
7575
| [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :white_large_square: |
7676
| [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :white_large_square: | :white_large_square: |
7777
| [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | :white_large_square: | :white_large_square: | :white_large_square: |

lib-extra/build.gradle

-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,3 @@ dependencies {
2323

2424
// we'll hold the core lib to a high standard
2525
spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes)
26-
27-
test { useJUnit { excludeCategories 'com.diffplug.spotless.category.NpmTest' } }
28-
29-
task npmTest(type: Test) { useJUnit { includeCategories 'com.diffplug.spotless.category.NpmTest' } }

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/BlacklistedOptionException.java renamed to lib/src/main/java/com/diffplug/spotless/npm/BlacklistedOptionException.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

1818
class BlacklistedOptionException extends RuntimeException {
1919
private static final long serialVersionUID = -5876348893394153811L;

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/NodeJSWrapper.java renamed to lib/src/main/java/com/diffplug/spotless/npm/NodeJSWrapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

1818
import java.io.File;
1919
import java.util.Map;

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/NpmConfig.java renamed to lib/src/main/java/com/diffplug/spotless/npm/NpmConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

1818
import java.io.Serializable;
1919

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/NpmExecutableResolver.java renamed to lib/src/main/java/com/diffplug/spotless/npm/NpmExecutableResolver.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

18-
import static com.diffplug.spotless.extra.npm.PlatformInfo.OS.WINDOWS;
18+
import static com.diffplug.spotless.npm.PlatformInfo.OS.WINDOWS;
1919

2020
import java.io.File;
21+
import java.util.Arrays;
2122
import java.util.Optional;
2223
import java.util.function.Supplier;
2324
import java.util.stream.Stream;
2425

25-
import com.diffplug.common.base.Splitter;
26-
2726
/**
2827
* Utility class to resolve an npm binary to be used by npm-based steps.
2928
* Tries to find an npm executable in the following order:
@@ -84,9 +83,7 @@ private static Supplier<Optional<File>> pathListFromEnvironment(String environme
8483
return () -> {
8584
String pathList = System.getenv(environmentPathListName);
8685
if (pathList != null) {
87-
return Splitter.on(System.getProperty("path.separator", ":"))
88-
.splitToList(pathList)
89-
.stream()
86+
return Arrays.stream(pathList.split(System.getProperty("path.separator", ":")))
9087
.map(File::new)
9188
.map(dir -> dir.getName().equalsIgnoreCase("node_modules") ? dir.getParentFile() : dir)
9289
.map(dir -> new File(dir, npmExecutableName()))

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/NpmFormatterStepStateBase.java renamed to lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

18-
import static com.diffplug.spotless.extra.npm.NpmExecutableResolver.tryFind;
1918
import static java.util.Objects.requireNonNull;
2019

2120
import java.io.ByteArrayOutputStream;
@@ -29,11 +28,7 @@
2928

3029
import javax.annotation.Nullable;
3130

32-
import com.diffplug.common.base.Errors;
33-
import com.diffplug.spotless.FileSignature;
34-
import com.diffplug.spotless.FormatterFunc;
35-
import com.diffplug.spotless.JarState;
36-
import com.diffplug.spotless.Provisioner;
31+
import com.diffplug.spotless.*;
3732

3833
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3934

@@ -92,7 +87,7 @@ private void runNpmInstall(@Nullable File npm, File npmProjectDir) throws IOExce
9287

9388
private File resolveNpm(@Nullable File npm) {
9489
return Optional.ofNullable(npm)
95-
.orElseGet(() -> tryFind()
90+
.orElseGet(() -> NpmExecutableResolver.tryFind()
9691
.orElseThrow(() -> new IllegalStateException("cannot automatically determine npm executable and none was specifically supplied!")));
9792
}
9893

@@ -118,7 +113,7 @@ protected static String readFileFromClasspath(Class<?> clazz, String name) {
118113
}
119114
return output.toString(StandardCharsets.UTF_8.name());
120115
} catch (IOException e) {
121-
throw Errors.asRuntime(e);
116+
throw ThrowingEx.asRuntime(e);
122117
}
123118
}
124119

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/PlatformInfo.java renamed to lib/src/main/java/com/diffplug/spotless/npm/PlatformInfo.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,19 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

1818
import static java.util.Objects.requireNonNull;
1919

2020
import java.util.Locale;
2121

22-
import com.diffplug.common.base.StandardSystemProperty;
23-
2422
class PlatformInfo {
2523
private PlatformInfo() {
2624
// no instance
2725
}
2826

2927
static OS normalizedOS() {
30-
final String osNameProperty = StandardSystemProperty.OS_NAME.value();
28+
final String osNameProperty = System.getProperty("os.name");
3129
if (osNameProperty == null) {
3230
throw new RuntimeException("No info about OS available, cannot decide which implementation of j2v8 to use");
3331
}
@@ -49,7 +47,7 @@ static String normalizedOSName() {
4947
}
5048

5149
static String normalizedArchName() {
52-
final String osArchProperty = StandardSystemProperty.OS_ARCH.value();
50+
final String osArchProperty = System.getProperty("os.arch");
5351
if (osArchProperty == null) {
5452
throw new RuntimeException("No info about ARCH available, cannot decide which implementation of j2v8 to use");
5553
}

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/PrettierConfig.java renamed to lib/src/main/java/com/diffplug/spotless/npm/PrettierConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

1818
import java.io.File;
1919
import java.io.IOException;

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/PrettierFormatterStep.java renamed to lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

1818
import static java.util.Arrays.asList;
1919
import static java.util.Objects.requireNonNull;
@@ -53,7 +53,7 @@ public static class State extends NpmFormatterStepStateBase implements Serializa
5353
super(stepName,
5454
provisioner,
5555
new NpmConfig(
56-
readFileFromClasspath(PrettierFormatterStep.class, "/com/diffplug/spotless/extra/npm/prettier-package.json"),
56+
readFileFromClasspath(PrettierFormatterStep.class, "/com/diffplug/spotless/npm/prettier-package.json"),
5757
"prettier"),
5858
buildDir,
5959
npm);

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/Reflective.java renamed to lib/src/main/java/com/diffplug/spotless/npm/Reflective.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

1818
import static java.util.Objects.requireNonNull;
1919

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/ReflectiveObjectWrapper.java renamed to lib/src/main/java/com/diffplug/spotless/npm/ReflectiveObjectWrapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

1818
import static java.util.Objects.requireNonNull;
1919

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/SimpleJsonWriter.java renamed to lib/src/main/java/com/diffplug/spotless/npm/SimpleJsonWriter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

1818
import static java.util.Objects.requireNonNull;
1919

@@ -26,7 +26,7 @@
2626
import java.util.Map;
2727
import java.util.stream.Collectors;
2828

29-
import com.diffplug.common.base.Errors;
29+
import com.diffplug.spotless.ThrowingEx;
3030

3131
public class SimpleJsonWriter {
3232

@@ -83,7 +83,7 @@ void toJsonFile(File file) {
8383
try {
8484
Files.write(file.toPath(), toJsonString().getBytes(StandardCharsets.UTF_8));
8585
} catch (IOException e) {
86-
throw Errors.asRuntime(e);
86+
throw ThrowingEx.asRuntime(e);
8787
}
8888
}
8989

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/TsConfigFileType.java renamed to lib/src/main/java/com/diffplug/spotless/npm/TsConfigFileType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

1818
import java.util.Arrays;
1919

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/TsFmtFormatterStep.java renamed to lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

1818
import static java.util.Arrays.asList;
1919
import static java.util.Objects.requireNonNull;
@@ -61,7 +61,7 @@ public State(String stepName, Provisioner provisioner, File buildDir, @Nullable
6161
super(stepName,
6262
provisioner,
6363
new NpmConfig(
64-
readFileFromClasspath(TsFmtFormatterStep.class, "/com/diffplug/spotless/extra/npm/tsfmt-package.json"),
64+
readFileFromClasspath(TsFmtFormatterStep.class, "/com/diffplug/spotless/npm/tsfmt-package.json"),
6565
"typescript-formatter"),
6666
buildDir,
6767
npm);

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/TsFmtResult.java renamed to lib/src/main/java/com/diffplug/spotless/npm/TsFmtResult.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

1818
class TsFmtResult {
1919

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/TypedTsFmtConfigFile.java renamed to lib/src/main/java/com/diffplug/spotless/npm/TypedTsFmtConfigFile.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

1818
import static java.util.Objects.requireNonNull;
1919

@@ -22,8 +22,8 @@
2222
import java.io.Serializable;
2323
import java.util.Locale;
2424

25-
import com.diffplug.common.base.Errors;
2625
import com.diffplug.spotless.FileSignature;
26+
import com.diffplug.spotless.ThrowingEx;
2727

2828
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2929

@@ -45,7 +45,7 @@ public TypedTsFmtConfigFile(TsConfigFileType configFileType, File configFile) {
4545
try {
4646
this.configFileSignature = FileSignature.signAsList(configFile);
4747
} catch (IOException e) {
48-
throw Errors.asRuntime(e);
48+
throw ThrowingEx.asRuntime(e);
4949
}
5050
}
5151

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/V8ArrayWrapper.java renamed to lib/src/main/java/com/diffplug/spotless/npm/V8ArrayWrapper.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
17-
18-
import static com.diffplug.spotless.extra.npm.NodeJSWrapper.V8_VALUE_CLASS;
16+
package com.diffplug.spotless.npm;
1917

2018
public class V8ArrayWrapper extends ReflectiveObjectWrapper {
2119

@@ -30,8 +28,8 @@ public V8ArrayWrapper push(Object object) {
3028
ReflectiveObjectWrapper objectWrapper = (ReflectiveObjectWrapper) object;
3129
object = objectWrapper.wrappedObj();
3230
}
33-
if (reflective().clazz(V8_VALUE_CLASS).isAssignableFrom(object.getClass())) {
34-
invoke("push", reflective().typed(V8_VALUE_CLASS, object));
31+
if (reflective().clazz(NodeJSWrapper.V8_VALUE_CLASS).isAssignableFrom(object.getClass())) {
32+
invoke("push", reflective().typed(NodeJSWrapper.V8_VALUE_CLASS, object));
3533
} else {
3634
invoke("push", object);
3735
}

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/V8FunctionWrapper.java renamed to lib/src/main/java/com/diffplug/spotless/npm/V8FunctionWrapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

1818
import java.lang.reflect.Method;
1919

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/V8ObjectUtilsWrapper.java renamed to lib/src/main/java/com/diffplug/spotless/npm/V8ObjectUtilsWrapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

1818
import static java.util.Objects.requireNonNull;
1919

lib-extra/src/main/java/com/diffplug/spotless/extra/npm/V8ObjectWrapper.java renamed to lib/src/main/java/com/diffplug/spotless/npm/V8ObjectWrapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.diffplug.spotless.extra.npm;
16+
package com.diffplug.spotless.npm;
1717

1818
import java.util.Optional;
1919

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535
import com.diffplug.spotless.LazyForwardingEquality;
3636
import com.diffplug.spotless.LineEnding;
3737
import com.diffplug.spotless.ThrowingEx;
38-
import com.diffplug.spotless.extra.npm.PrettierFormatterStep;
3938
import com.diffplug.spotless.generic.EndWithNewlineStep;
4039
import com.diffplug.spotless.generic.IndentStep;
4140
import com.diffplug.spotless.generic.LicenseHeaderStep;
4241
import com.diffplug.spotless.generic.ReplaceRegexStep;
4342
import com.diffplug.spotless.generic.ReplaceStep;
4443
import com.diffplug.spotless.generic.TrimTrailingWhitespaceStep;
44+
import com.diffplug.spotless.npm.PrettierFormatterStep;
4545

4646
import groovy.lang.Closure;
4747

@@ -471,7 +471,7 @@ FormatterStep createStep() {
471471
GradleProvisioner.fromProject(project),
472472
project.getBuildDir(),
473473
npmFileOrNull(),
474-
new com.diffplug.spotless.extra.npm.PrettierConfig(
474+
new com.diffplug.spotless.npm.PrettierConfig(
475475
this.prettierConfigFile != null ? project.file(this.prettierConfigFile) : null,
476476
this.prettierConfig));
477477
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import org.gradle.api.Project;
2727

2828
import com.diffplug.spotless.FormatterStep;
29-
import com.diffplug.spotless.extra.npm.TsConfigFileType;
30-
import com.diffplug.spotless.extra.npm.TsFmtFormatterStep;
31-
import com.diffplug.spotless.extra.npm.TypedTsFmtConfigFile;
29+
import com.diffplug.spotless.npm.TsConfigFileType;
30+
import com.diffplug.spotless.npm.TsFmtFormatterStep;
31+
import com.diffplug.spotless.npm.TypedTsFmtConfigFile;
3232

3333
public class TypescriptExtension extends FormatExtension {
3434

testlib/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ dependencies {
1515
// we'll hold the testlib to a low standard (prize brevity)
1616
spotbugs { reportLevel = 'high' } // low|medium|high (low = sensitive to even minor mistakes)
1717

18+
test { useJUnit { excludeCategories 'com.diffplug.spotless.category.NpmTest' } }
19+
20+
task npmTest(type: Test) { useJUnit { includeCategories 'com.diffplug.spotless.category.NpmTest' } }

0 commit comments

Comments
 (0)