Skip to content

Commit

Permalink
Fix forUseAtConfigurationTime warnings from the `BlowdryerSetupPlug…
Browse files Browse the repository at this point in the history
…in`. (#38)
  • Loading branch information
nedtwigg committed Dec 8, 2023
2 parents c6c8056 + 487b69b commit 5ade001
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Remove `Provider.forUseAtConfigurationTime method has been deprecated` warnings in recent versions of Gradle. ([#38](https://github.com/diffplug/blowdryer/pull/38))

## [1.7.0] - 2023-01-28
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.initialization.Settings;
import org.gradle.api.provider.Provider;

/** Gradle settings plugin which configures the source URL and version. */
public class BlowdryerSetupPlugin implements Plugin<Settings> {
static final String MINIMUM_GRADLE = "6.8";
static final String STOP_FORUSE_AT_CONFIGURATION_TIME = "7.4";

private static final Pattern BAD_SEMVER = Pattern.compile("(\\d+)\\.(\\d+)");

Expand All @@ -32,7 +34,11 @@ public void apply(Settings settings) {
if (badSemver(settings.getGradle().getGradleVersion()) < badSemver(MINIMUM_GRADLE)) {
throw new GradleException("Blowdryer requires Gradle " + MINIMUM_GRADLE + " or newer, this was " + settings.getGradle().getGradleVersion());
}
Blowdryer.initTempDir(settings.getProviders().systemProperty("java.io.tmpdir").forUseAtConfigurationTime().get());
Provider<String> tmpDir = settings.getProviders().systemProperty("java.io.tmpdir");
String tmpDirPath = badSemver(settings.getGradle().getGradleVersion()) >= badSemver(STOP_FORUSE_AT_CONFIGURATION_TIME) ? // depends on Gradle version
tmpDir.get() : // Gradle 7.4 and later
tmpDir.forUseAtConfigurationTime().get(); // before Gradle 7.4
Blowdryer.initTempDir(tmpDirPath);
settings.getExtensions().create(BlowdryerSetup.NAME, BlowdryerSetup.class, settings.getRootDir());
}

Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/diffplug/blowdryer/BlowdryerPluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Locale;
import java.util.stream.Collectors;
import org.assertj.core.api.Assertions;
import org.gradle.testkit.runner.BuildResult;
import org.junit.Assume;
import org.junit.Test;

Expand Down Expand Up @@ -377,4 +378,11 @@ public void tooOldError() throws IOException {
Assertions.assertThat(gradleRunner().withGradleVersion("6.7").buildAndFail().getOutput().replace("\r\n", "\n"))
.contains("Blowdryer requires Gradle 6.8 or newer, this was 6.7");
}

@Test
public void deprecationError() throws IOException {
settingsGithub("test/2/a");
BuildResult build = gradleRunner().withGradleVersion("8.5").withArguments("--warning-mode=fail").build();
Assertions.assertThat(build.getOutput()).doesNotContain("Provider.forUseAtConfigurationTime method has been deprecated");
}
}

0 comments on commit 5ade001

Please sign in to comment.