Skip to content

Commit 4c23f57

Browse files
committed
Remove transients from NpmFormatterStepStateBase by embedding NpmPathResolver and making it serializable.
1 parent e37a567 commit 4c23f57

File tree

6 files changed

+22
-43
lines changed

6 files changed

+22
-43
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2024 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.
@@ -102,8 +102,7 @@ private static class State extends NpmFormatterStepStateBase implements Serializ
102102
projectDir,
103103
buildDir,
104104
cacheDir,
105-
npmPathResolver::resolveNpmExecutable,
106-
npmPathResolver::resolveNodeExecutable));
105+
npmPathResolver));
107106
this.origEslintConfig = requireNonNull(eslintConfig.verify());
108107
this.eslintConfigInUse = eslintConfig;
109108
}
Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 DiffPlug
2+
* Copyright 2023-2024 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,36 +19,23 @@
1919

2020
import java.io.File;
2121
import java.io.Serializable;
22-
import java.util.function.Supplier;
2322

2423
import javax.annotation.Nonnull;
2524

26-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
27-
2825
class NpmFormatterStepLocations implements Serializable {
2926

3027
private static final long serialVersionUID = -1055408537924029969L;
31-
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
32-
private final transient File projectDir;
33-
34-
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
35-
private final transient File buildDir;
36-
37-
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
38-
private final transient File cacheDir;
39-
40-
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
41-
private final transient Supplier<File> npmExecutable;
4228

43-
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
44-
private final transient Supplier<File> nodeExecutable;
29+
private final File projectDir;
30+
private final File buildDir;
31+
private final File cacheDir;
32+
private final NpmPathResolver resolver;
4533

46-
public NpmFormatterStepLocations(@Nonnull File projectDir, @Nonnull File buildDir, File cacheDir, @Nonnull Supplier<File> npmExecutable, @Nonnull Supplier<File> nodeExecutable) {
34+
public NpmFormatterStepLocations(@Nonnull File projectDir, @Nonnull File buildDir, File cacheDir, @Nonnull NpmPathResolver resolver) {
4735
this.projectDir = requireNonNull(projectDir);
4836
this.buildDir = requireNonNull(buildDir);
4937
this.cacheDir = cacheDir;
50-
this.npmExecutable = requireNonNull(npmExecutable);
51-
this.nodeExecutable = requireNonNull(nodeExecutable);
38+
this.resolver = requireNonNull(resolver);
5239
}
5340

5441
public File projectDir() {
@@ -64,10 +51,10 @@ public File cacheDir() {
6451
}
6552

6653
public File npmExecutable() {
67-
return npmExecutable.get();
54+
return resolver.resolveNpmExecutable();
6855
}
6956

7057
public File nodeExecutable() {
71-
return nodeExecutable.get();
58+
return resolver.resolveNodeExecutable();
7259
}
7360
}

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2024 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.
@@ -35,8 +35,6 @@
3535
import com.diffplug.spotless.ProcessRunner.LongRunningProcess;
3636
import com.diffplug.spotless.ThrowingEx;
3737

38-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
39-
4038
abstract class NpmFormatterStepStateBase implements Serializable {
4139

4240
private static final Logger logger = LoggerFactory.getLogger(NpmFormatterStepStateBase.class);
@@ -45,15 +43,11 @@ abstract class NpmFormatterStepStateBase implements Serializable {
4543

4644
private static final long serialVersionUID = 1460749955865959948L;
4745

48-
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
49-
protected final transient NodeServerLayout nodeServerLayout;
50-
51-
public final NpmFormatterStepLocations locations;
52-
53-
private final NpmConfig npmConfig;
54-
5546
private final String stepName;
47+
private final NpmConfig npmConfig;
5648

49+
public final NpmFormatterStepLocations locations;
50+
protected final transient NodeServerLayout nodeServerLayout;
5751
private final transient NodeServeApp nodeServeApp;
5852

5953
protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, NpmFormatterStepLocations locations) throws IOException {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 DiffPlug
2+
* Copyright 2020-2024 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.
@@ -16,10 +16,11 @@
1616
package com.diffplug.spotless.npm;
1717

1818
import java.io.File;
19+
import java.io.Serializable;
1920
import java.util.List;
2021
import java.util.Optional;
2122

22-
public class NpmPathResolver {
23+
public class NpmPathResolver implements Serializable {
2324

2425
private final File explicitNpmExecutable;
2526

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2024 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.
@@ -79,8 +79,7 @@ private static class State extends NpmFormatterStepStateBase implements Serializ
7979
projectDir,
8080
buildDir,
8181
cacheDir,
82-
npmPathResolver::resolveNpmExecutable,
83-
npmPathResolver::resolveNodeExecutable));
82+
npmPathResolver));
8483
this.prettierConfig = requireNonNull(prettierConfig);
8584
}
8685

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2024 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.
@@ -83,8 +83,7 @@ public State(String stepName, Map<String, String> versions, File projectDir, Fil
8383
projectDir,
8484
buildDir,
8585
cacheDir,
86-
npmPathResolver::resolveNpmExecutable,
87-
npmPathResolver::resolveNodeExecutable));
86+
npmPathResolver));
8887
this.buildDir = requireNonNull(buildDir);
8988
this.configFile = configFile;
9089
this.inlineTsFmtSettings = inlineTsFmtSettings == null ? new TreeMap<>() : new TreeMap<>(inlineTsFmtSettings);

0 commit comments

Comments
 (0)