Skip to content

Commit

Permalink
Remove JvmLocalCache now that everything is round-trippable on its …
Browse files Browse the repository at this point in the history
…own (#2088)
  • Loading branch information
nedtwigg committed Apr 7, 2024
2 parents f7346d5 + 53d0399 commit 7262511
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 150 deletions.
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Fixed
* Full no-asterisk support for configuration cache ([#2088](https://github.com/diffplug/spotless/pull/2088) closes [#1274](https://github.com/diffplug/spotless/issues/1274) and [#987](https://github.com/diffplug/spotless/issues/987)).
* Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990))
* Correctly provide EditorConfig property types for Ktlint ([#2052](https://github.com/diffplug/spotless/issues/2052))
* Fixed memory leak introduced in 6.21.0 ([#2067](https://github.com/diffplug/spotless/issues/2067))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public LineEnding getLineEndings() {
}

public void setLineEndings(LineEnding lineEndings) {
if (lineEndings == LineEnding.GIT_ATTRIBUTES) {
throw new IllegalArgumentException("GIT_ATTRIBUTES not supported in Gradle, use GIT_ATTRIBUTES_FAST_ALLSAME instead. See https://github.com/diffplug/spotless/issues/1274 for more details.");
}
this.lineEndings = requireNonNull(lineEndings);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 DiffPlug
* Copyright 2020-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,7 +37,6 @@
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.work.Incremental;

import com.diffplug.gradle.spotless.JvmLocalCache.LiveCache;
import com.diffplug.spotless.FormatExceptionPolicy;
import com.diffplug.spotless.FormatExceptionPolicyStrict;
import com.diffplug.spotless.Formatter;
Expand All @@ -49,10 +48,6 @@ public abstract class SpotlessTask extends DefaultTask {
@Internal
abstract Property<SpotlessTaskService> getTaskService();

protected <T> LiveCache<T> createLive(String keyName) {
return JvmLocalCache.createLive(this, keyName);
}

// set by SpotlessExtension, but possibly overridden by FormatExtension
protected String encoding = "UTF-8";

Expand All @@ -65,15 +60,15 @@ public void setEncoding(String encoding) {
this.encoding = Objects.requireNonNull(encoding);
}

protected final LiveCache<Provider<LineEnding.Policy>> lineEndingsPolicy = createLive("lineEndingsPolicy");
protected Provider<LineEnding.Policy> lineEndingsPolicy = null;

@Input
public Provider<LineEnding.Policy> getLineEndingsPolicy() {
return lineEndingsPolicy.get();
return lineEndingsPolicy;
}

public void setLineEndingsPolicy(Provider<LineEnding.Policy> lineEndingsPolicy) {
this.lineEndingsPolicy.set(lineEndingsPolicy);
this.lineEndingsPolicy = lineEndingsPolicy;
}

/** The sha of the tree at repository root, used for determining if an individual *file* is clean according to git. */
Expand Down Expand Up @@ -155,22 +150,17 @@ public File getOutputDirectory() {
return outputDirectory;
}

protected final LiveCache<List<FormatterStep>> steps = createLive("steps");
{
steps.set(new ArrayList<FormatterStep>());
}
protected final List<FormatterStep> steps = new ArrayList<>();

@Input
public List<FormatterStep> getSteps() {
return Collections.unmodifiableList(steps.get());
return Collections.unmodifiableList(steps);
}

public void setSteps(List<FormatterStep> steps) {
this.steps.set(PluginGradlePreconditions.requireElementsNonNull(steps));
}

public boolean addStep(FormatterStep step) {
return this.steps.get().add(Objects.requireNonNull(step));
PluginGradlePreconditions.requireElementsNonNull(steps);
this.steps.clear();
this.steps.addAll(steps);
}

/** Returns the name of this format. */
Expand All @@ -186,10 +176,10 @@ String formatName() {
Formatter buildFormatter() {
return Formatter.builder()
.name(formatName())
.lineEndingsPolicy(lineEndingsPolicy.get().get())
.lineEndingsPolicy(getLineEndingsPolicy().get())
.encoding(Charset.forName(encoding))
.rootDir(getProjectDir().get().getAsFile().toPath())
.steps(steps.get())
.steps(steps)
.exceptionPolicy(exceptionPolicy)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ void failureWhenExeNotFound() throws Exception {
var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail();
assertThat(spotlessApply.getOutput()).contains("Build failed with an exception");
assertFile("biome_test.js").sameAsResource("biome/js/fileBefore.js");
assertThat(spotlessApply.getOutput()).contains("Could not create task ':spotlessMybiomeApply'");
assertThat(spotlessApply.getOutput()).contains("Execution failed for task ':spotlessMybiome'");
assertThat(spotlessApply.getOutput()).contains("Biome executable does not exist");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 DiffPlug
* Copyright 2020-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,11 +17,8 @@

import java.io.IOException;

import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;

public class ConfigurationCacheTest extends GradleIntegrationHarness {
@Override
Expand Down Expand Up @@ -65,8 +62,7 @@ public void helpConfiguresIfTasksAreCreated() throws IOException {
}

@Test
@EnabledForJreRange(max = JRE.JAVA_20)
public void jvmLocalCache() throws IOException {
public void multipleRuns() throws IOException {
setFile("build.gradle").toLines(
"plugins {",
" id 'com.diffplug.spotless'",
Expand All @@ -93,14 +89,5 @@ public void jvmLocalCache() throws IOException {
gradleRunner().withArguments("spotlessCheck").buildAndFail();
gradleRunner().withArguments("spotlessApply").build();
assertFile("test.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test");

// the withDebug forces it to start a new deamon, but only in Gradle 8.3 and older
// starting with Gradle 8.5 this doesn't work anymore
// and we need Gradle 8.5 for Java 21
// so we can't test this on Java 21 for now
BuildResult failure = gradleRunner().withDebug(true).withArguments("spotlessApply", "--stacktrace").buildAndFail();
failure.getOutput().contains("Spotless daemon-local cache is stale. Regenerate the cache with\n" +
" rm -rf .gradle/configuration-cache\n" +
"For more information see #123\n");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 DiffPlug
* Copyright 2016-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -151,10 +151,10 @@ void customRunToFixMessage() throws Exception {
@Test
void whitespaceProblem() throws Exception {
Bundle spotless = create(setFile("testFile").toContent("A \nB\t\nC \n"));
spotless.task.addStep(FormatterStep.createNeverUpToDate("trimTrailing", input -> {
spotless.task.setSteps(List.of(FormatterStep.createNeverUpToDate("trimTrailing", input -> {
Pattern pattern = Pattern.compile("[ \t]+$", Pattern.UNIX_LINES | Pattern.MULTILINE);
return pattern.matcher(input).replaceAll("");
}));
})));
assertCheckFailure(spotless,
" testFile",
" @@ -1,3 +1,3 @@",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 DiffPlug
* Copyright 2016-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@

import java.io.File;
import java.util.Collections;
import java.util.List;

import org.gradle.api.Project;
import org.gradle.api.services.BuildServiceParameters;
Expand Down Expand Up @@ -61,7 +62,7 @@ void testStep() throws Exception {
File outputFile = new File(spotlessTask.getOutputDirectory(), "testFile");
spotlessTask.setTarget(Collections.singleton(testFile));

spotlessTask.addStep(FormatterStep.createNeverUpToDate("double-p", content -> content.replace("pp", "p")));
spotlessTask.setSteps(List.of(FormatterStep.createNeverUpToDate("double-p", content -> content.replace("pp", "p"))));
Tasks.execute(spotlessTask);

assertFile(outputFile).hasContent("aple");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 DiffPlug
* Copyright 2016-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.gradle.api.Project;
import org.gradle.api.provider.Provider;
Expand Down Expand Up @@ -65,7 +66,7 @@ public BuildServiceParameters.None getParameters() {
private SpotlessTaskImpl createFormatTask(String name, FormatterStep step) {
SpotlessTaskImpl task = project.getTasks().create("spotless" + SpotlessPlugin.capitalize(name), SpotlessTaskImpl.class);
task.init(taskService);
task.addStep(step);
task.setSteps(List.of(step));
task.setLineEndingsPolicy(project.provider(LineEnding.UNIX::createPolicy));
task.setTarget(Collections.singletonList(file));
return task;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 DiffPlug
* Copyright 2023-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -310,7 +310,7 @@ void failureWhenExeNotFound() throws Exception {
var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail();
assertThat(spotlessApply.getOutput()).contains("Build failed with an exception");
assertFile("rome_test.js").sameAsResource("rome/js/fileBefore.js");
assertThat(spotlessApply.getOutput()).contains("Could not create task ':spotlessMyromeApply'");
assertThat(spotlessApply.getOutput()).contains("Execution failed for task ':spotlessMyrome'");
assertThat(spotlessApply.getOutput()).contains("Biome executable does not exist");
}

Expand Down

0 comments on commit 7262511

Please sign in to comment.