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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 0 additions & 4 deletions
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' } }
Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 7 deletions
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()))
Lines changed: 4 additions & 9 deletions
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

Lines changed: 3 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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;
Lines changed: 2 additions & 2 deletions
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);

0 commit comments

Comments
 (0)