|
| 1 | +/* |
| 2 | + * Copyright 2020-2021 DiffPlug |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.diffplug.gradle.spotless; |
| 17 | + |
| 18 | +import java.io.IOException; |
| 19 | + |
| 20 | +import org.gradle.testkit.runner.BuildResult; |
| 21 | +import org.gradle.testkit.runner.GradleRunner; |
| 22 | +import org.junit.jupiter.api.Test; |
| 23 | + |
| 24 | +public class ConfigurationCacheDaemonLocalTest extends GradleIntegrationHarness { |
| 25 | + @Override |
| 26 | + protected GradleRunner gradleRunner() throws IOException { |
| 27 | + setFile("gradle.properties").toContent("org.gradle.unsafe.configuration-cache=true"); |
| 28 | + return super.gradleRunner().withGradleVersion(GradleVersionSupport.CONFIGURATION_CACHE.version); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void gjf() throws IOException { |
| 33 | + setFile("build.gradle").toLines( |
| 34 | + "plugins {", |
| 35 | + " id 'com.diffplug.spotless-setup'", |
| 36 | + " id 'com.diffplug.spotless'", |
| 37 | + "}", |
| 38 | + "repositories { mavenCentral() }", |
| 39 | + "spotlessSetup {", |
| 40 | + " enableConfigCacheDaemonLocal = true", |
| 41 | + "}", |
| 42 | + "spotless {", |
| 43 | + " java {", |
| 44 | + " target file('test.java')", |
| 45 | + " googleJavaFormat('1.2')", |
| 46 | + " }", |
| 47 | + "}"); |
| 48 | + |
| 49 | + // first run works |
| 50 | + setFile("test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test"); |
| 51 | + gradleRunner().withArguments("spotlessApply").build(); |
| 52 | + assertFile("test.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test"); |
| 53 | + |
| 54 | + // and it keeps working! |
| 55 | + gradleRunner().withArguments("spotlessApply", "--stacktrace").build(); |
| 56 | + gradleRunner().withArguments("spotlessApply").build(); |
| 57 | + gradleRunner().withArguments("spotlessApply").build(); |
| 58 | + |
| 59 | + setFile("test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test"); |
| 60 | + gradleRunner().withArguments("spotlessCheck").buildAndFail(); |
| 61 | + gradleRunner().withArguments("spotlessApply").build(); |
| 62 | + assertFile("test.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test"); |
| 63 | + |
| 64 | + BuildResult failure = gradleRunner().withDebug(true).withArguments("spotlessApply", "--stacktrace").buildAndFail(); |
| 65 | + failure.getOutput().contains("Spotless daemon-local cache is stale. Regenerate the cache with\n" + |
| 66 | + " rm -rf .gradle/configuration-cache\n" + |
| 67 | + "For more information see #123\n"); |
| 68 | + } |
| 69 | +} |
0 commit comments