Skip to content

Commit faa56fc

Browse files
committed
Rename spotlessOut to spotlessClean, to differentiate it from the coming spotlessLint.
1 parent 8f43b2f commit faa56fc

File tree

8 files changed

+49
-54
lines changed

8 files changed

+49
-54
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 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.
@@ -29,11 +29,11 @@ public abstract class SpotlessApply extends SpotlessTaskService.ClientTask {
2929
@TaskAction
3030
public void performAction() {
3131
getTaskService().get().registerApplyAlreadyRan(this);
32-
ConfigurableFileTree files = getConfigCacheWorkaround().fileTree().from(getSpotlessOutDirectory().get());
33-
if (files.isEmpty()) {
32+
ConfigurableFileTree cleanFiles = getConfigCacheWorkaround().fileTree().from(getSpotlessCleanDirectory().get());
33+
if (cleanFiles.isEmpty()) {
3434
getState().setDidWork(sourceDidWork());
3535
} else {
36-
files.visit(new FileVisitor() {
36+
cleanFiles.visit(new FileVisitor() {
3737
@Override
3838
public void visitDir(FileVisitDetails fileVisitDetails) {
3939

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

Lines changed: 5 additions & 5 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.
@@ -54,15 +54,15 @@ public void performAction() throws IOException {
5454
}
5555

5656
private void performAction(boolean isTest) throws IOException {
57-
ConfigurableFileTree files = getConfigCacheWorkaround().fileTree().from(getSpotlessOutDirectory().get());
58-
if (files.isEmpty()) {
57+
ConfigurableFileTree cleanFiles = getConfigCacheWorkaround().fileTree().from(getSpotlessCleanDirectory().get());
58+
if (cleanFiles.isEmpty()) {
5959
getState().setDidWork(sourceDidWork());
6060
} else if (!isTest && applyHasRun()) {
6161
// if our matching apply has already run, then we don't need to do anything
6262
getState().setDidWork(false);
6363
} else {
6464
List<File> problemFiles = new ArrayList<>();
65-
files.visit(new FileVisitor() {
65+
cleanFiles.visit(new FileVisitor() {
6666
@Override
6767
public void visitDir(FileVisitDetails fileVisitDetails) {
6868

@@ -105,7 +105,7 @@ public void visitFile(FileVisitDetails fileVisitDetails) {
105105
.runToFix(getRunToFixMessage().get())
106106
.formatterFolder(
107107
getProjectDir().get().getAsFile().toPath(),
108-
getSpotlessOutDirectory().get().toPath(),
108+
getSpotlessCleanDirectory().get().toPath(),
109109
getEncoding().get())
110110
.problemFiles(problemFiles)
111111
.getMessage());

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ public void setTarget(Iterable<File> target) {
149149
}
150150
}
151151

152-
protected File outputDirectory = new File(getProject().getLayout().getBuildDirectory().getAsFile().get(),
153-
"spotless/" + getName());
152+
protected File cleanDirectory = new File(getProject().getLayout().getBuildDirectory().getAsFile().get(),
153+
"spotless-clean/" + getName());
154154

155155
@OutputDirectory
156-
public File getOutputDirectory() {
157-
return outputDirectory;
156+
public File getCleanDirectory() {
157+
return cleanDirectory;
158158
}
159159

160160
private final ConfigurationCacheHackList stepsInternalRoundtrip = ConfigurationCacheHackList.forRoundtrip();

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

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,37 @@ public void performAction(InputChanges inputs) throws Exception {
7474

7575
if (!inputs.isIncremental()) {
7676
getLogger().info("Not incremental: removing prior outputs");
77-
getFs().delete(d -> d.delete(outputDirectory));
78-
Files.createDirectories(outputDirectory.toPath());
77+
getFs().delete(d -> d.delete(cleanDirectory));
78+
Files.createDirectories(cleanDirectory.toPath());
7979
}
8080

8181
try (Formatter formatter = buildFormatter()) {
8282
GitRatchetGradle ratchet = getRatchet();
8383
for (FileChange fileChange : inputs.getFileChanges(target)) {
8484
File input = fileChange.getFile();
85+
String subpath = FormatExtension.relativize(getProjectDir().getAsFile().get(), input);
86+
if (subpath == null) {
87+
throw new IllegalArgumentException(StringPrinter.buildString(printer -> {
88+
printer.println("Spotless error! All target files must be within the project dir.");
89+
printer.println(" project dir: " + getProjectDir().getAsFile().get().getAbsolutePath());
90+
printer.println(" target: " + input.getAbsolutePath());
91+
}));
92+
}
8593
if (fileChange.getChangeType() == ChangeType.REMOVED) {
86-
deletePreviousResults(input);
94+
deletePreviousResults(cleanDirectory, subpath);
8795
} else {
8896
if (input.isFile()) {
89-
processInputFile(ratchet, formatter, input);
97+
processInputFile(ratchet, formatter, input, subpath);
9098
}
9199
}
92100
}
93101
}
94102
}
95103

96104
@VisibleForTesting
97-
void processInputFile(@Nullable GitRatchet ratchet, Formatter formatter, File input) throws IOException {
98-
File output = getOutputFileWithBaseDir(input, outputDirectory);
99-
getLogger().debug("Applying format to {} and writing to {}", input, output);
105+
void processInputFile(@Nullable GitRatchet ratchet, Formatter formatter, File input, String subpath) throws IOException {
106+
File cleanFile = new File(cleanDirectory, subpath);
107+
getLogger().debug("Applying format to {} and writing to {}", input, cleanFile);
100108
LintState lintState;
101109
if (ratchet != null && ratchet.isClean(getProjectDir().get().getAsFile(), getRootTreeSha(), input)) {
102110
lintState = LintState.clean();
@@ -109,20 +117,20 @@ void processInputFile(@Nullable GitRatchet ratchet, Formatter formatter, File in
109117
}
110118
if (lintState.getDirtyState().isClean()) {
111119
// Remove previous output if it exists
112-
Files.deleteIfExists(output.toPath());
120+
Files.deleteIfExists(cleanFile.toPath());
113121
} else if (lintState.getDirtyState().didNotConverge()) {
114122
getLogger().warn("Skipping '{}' because it does not converge. Run {@code spotlessDiagnose} to understand why", input);
115123
} else {
116-
Path parentDir = output.toPath().getParent();
124+
Path parentDir = cleanFile.toPath().getParent();
117125
if (parentDir == null) {
118-
throw new IllegalStateException("Every file has a parent folder. But not: " + output);
126+
throw new IllegalStateException("Every file has a parent folder. But not: " + cleanFile);
119127
}
120128
Files.createDirectories(parentDir);
121129
// Need to copy the original file to the tmp location just to remember the file attributes
122-
Files.copy(input.toPath(), output.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES);
130+
Files.copy(input.toPath(), cleanFile.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES);
123131

124-
getLogger().info(String.format("Writing clean file: %s", output));
125-
lintState.getDirtyState().writeCanonicalTo(output);
132+
getLogger().info(String.format("Writing clean file: %s", cleanFile));
133+
lintState.getDirtyState().writeCanonicalTo(cleanFile);
126134
}
127135
if (lintState.isHasLints()) {
128136
var lints = lintState.getLints(formatter);
@@ -131,25 +139,12 @@ void processInputFile(@Nullable GitRatchet ratchet, Formatter formatter, File in
131139
}
132140
}
133141

134-
private void deletePreviousResults(File input) throws IOException {
135-
File output = getOutputFileWithBaseDir(input, outputDirectory);
142+
private void deletePreviousResults(File baseDir, String subpath) throws IOException {
143+
File output = new File(baseDir, subpath);
136144
if (output.isDirectory()) {
137145
getFs().delete(d -> d.delete(output));
138146
} else {
139147
Files.deleteIfExists(output.toPath());
140148
}
141149
}
142-
143-
private File getOutputFileWithBaseDir(File input, File baseDir) {
144-
File projectDir = getProjectDir().get().getAsFile();
145-
String outputFileName = FormatExtension.relativize(projectDir, input);
146-
if (outputFileName == null) {
147-
throw new IllegalArgumentException(StringPrinter.buildString(printer -> {
148-
printer.println("Spotless error! All target files must be within the project dir.");
149-
printer.println(" project dir: " + projectDir.getAbsolutePath());
150-
printer.println(" target: " + input.getAbsolutePath());
151-
}));
152-
}
153-
return new File(baseDir, outputFileName);
154-
}
155150
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 DiffPlug
2+
* Copyright 2021-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.
@@ -104,7 +104,7 @@ static void usesServiceTolerateTestFailure(DefaultTask task, Provider<SpotlessTa
104104

105105
static abstract class ClientTask extends DefaultTask {
106106
@Internal
107-
abstract Property<File> getSpotlessOutDirectory();
107+
abstract Property<File> getSpotlessCleanDirectory();
108108

109109
@Internal
110110
abstract Property<SpotlessTaskService> getTaskService();
@@ -117,7 +117,7 @@ static abstract class ClientTask extends DefaultTask {
117117

118118
void init(SpotlessTaskImpl impl) {
119119
usesServiceTolerateTestFailure(this, impl.getTaskServiceProvider());
120-
getSpotlessOutDirectory().set(impl.getOutputDirectory());
120+
getSpotlessCleanDirectory().set(impl.getCleanDirectory());
121121
getTaskService().set(impl.getTaskService());
122122
getProjectDir().set(impl.getProjectDir());
123123
}

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public BuildServiceParameters.None getParameters() {
4848
@Test
4949
void testLineEndings() throws Exception {
5050
File testFile = setFile("testFile").toContent("\r\n");
51-
File outputFile = new File(spotlessTask.getOutputDirectory(), "testFile");
51+
File outputFile = new File(spotlessTask.getCleanDirectory(), "testFile");
5252

5353
spotlessTask.setTarget(Collections.singleton(testFile));
5454
Tasks.execute(spotlessTask);
@@ -59,7 +59,7 @@ void testLineEndings() throws Exception {
5959
@Test
6060
void testStep() throws Exception {
6161
File testFile = setFile("testFile").toContent("apple");
62-
File outputFile = new File(spotlessTask.getOutputDirectory(), "testFile");
62+
File outputFile = new File(spotlessTask.getCleanDirectory(), "testFile");
6363
spotlessTask.setTarget(Collections.singleton(testFile));
6464

6565
spotlessTask.setSteps(List.of(ReplaceStep.create("double-p", "pp", "p")));

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public BuildServiceParameters.None getParameters() {
4949
}
5050
});
5151
File file;
52-
File outputFile;
52+
File cleanFile;
5353
SpotlessTaskImpl source;
5454
SpotlessCheck check;
5555
SpotlessApply apply;
@@ -61,7 +61,7 @@ public BuildServiceParameters.None getParameters() {
6161
source = createFormatTask(name, step);
6262
check = createCheckTask(name, source);
6363
apply = createApplyTask(name, source);
64-
outputFile = new File(source.getOutputDirectory() + "/src", file.getName());
64+
cleanFile = new File(source.getCleanDirectory() + "/src", file.getName());
6565
}
6666

6767
private SpotlessTaskImpl createFormatTask(String name, FormatterStep step) {
@@ -143,10 +143,10 @@ void paddedCellFormat() throws Exception {
143143
converge.format();
144144
diverge.format();
145145

146-
assertFile(wellbehaved.outputFile).hasContent("42"); // cycle -> first element in cycle
147-
assertFile(cycle.outputFile).hasContent("A"); // cycle -> first element in cycle
148-
assertFile(converge.outputFile).hasContent(""); // converge -> converges
149-
assertThat(diverge.outputFile).doesNotExist(); // diverge -> no change
146+
assertFile(wellbehaved.cleanFile).hasContent("42"); // cycle -> first element in cycle
147+
assertFile(cycle.cleanFile).hasContent("A"); // cycle -> first element in cycle
148+
assertFile(converge.cleanFile).hasContent(""); // converge -> converges
149+
assertThat(diverge.cleanFile).doesNotExist(); // diverge -> no change
150150
}
151151

152152
@Test

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java

Lines changed: 2 additions & 2 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.
@@ -41,6 +41,6 @@ public void testThrowsMessageContainsFilename() throws Exception {
4141
File input = Paths.get("unitTests", "projectDir", "someInput").toFile();
4242
Formatter formatter = Mockito.mock(Formatter.class);
4343

44-
Assertions.assertThatThrownBy(() -> task.processInputFile(null, formatter, input)).hasMessageContaining(input.toString());
44+
Assertions.assertThatThrownBy(() -> task.processInputFile(null, formatter, input, "someInput")).hasMessageContaining(input.toString());
4545
}
4646
}

0 commit comments

Comments
 (0)