Skip to content

Commit f89c5c9

Browse files
committed
Fix com.diffplug.configuration-cache-for-platform-specific-build (#214)
1 parent 6aefbfb commit f89c5c9

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

CHANGES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
## [Unreleased]
44
### Added
5-
- Eclipse `4.30.0` aka `2023-12` ([new and noteworthy](https://eclipse.dev/eclipse/news/4.30/))
5+
- Eclipse `4.30.0` aka `2023-12` ([new and noteworthy](https://eclipse.dev/eclipse/news/4.30/)) ([#213](https://github.com/diffplug/goomph/pull/213))
6+
### Fixed
7+
- `com.diffplug.configuration-cache-for-platform-specific-build` no longer throws Gradle warnings about `uname -a` or about `forUseAtConfigurationTime` being deprecated. ([#214](https://github.com/diffplug/goomph/pull/214))
68

79
## [3.43.0] - 2023-09-28
810
### Added

src/main/java/com/diffplug/gradle/swt/PlatformSpecificBuildPlugin.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2021 DiffPlug
2+
* Copyright (C) 2021-2023 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.
@@ -15,10 +15,12 @@
1515
*/
1616
package com.diffplug.gradle.swt;
1717

18-
1918
import com.diffplug.common.swt.os.OS;
19+
import java.util.regex.Matcher;
20+
import java.util.regex.Pattern;
2021
import org.gradle.api.Plugin;
2122
import org.gradle.api.initialization.Settings;
23+
import org.gradle.api.provider.Provider;
2224

2325
/**
2426
* In order to detect the underlying operating system and architecture, it is necessary to
@@ -29,10 +31,41 @@
2931
* the appropriate APIs</a> which don't break the configuration cache.
3032
*/
3133
public class PlatformSpecificBuildPlugin implements Plugin<Settings> {
34+
3235
@Override
3336
public void apply(Settings settings) {
3437
OS.detectPlatform(
35-
systemProp -> settings.getProviders().systemProperty(systemProp).forUseAtConfigurationTime().get(),
36-
envVar -> settings.getProviders().environmentVariable(envVar).forUseAtConfigurationTime().get());
38+
systemProp -> get(settings, settings.getProviders().systemProperty(systemProp)),
39+
envVar -> get(settings, settings.getProviders().environmentVariable(envVar)),
40+
cmds -> get(settings, settings.getProviders().exec(e -> {
41+
e.commandLine(cmds.toArray());
42+
}).getStandardOutput().getAsText()));
43+
}
44+
45+
private <T> T get(Settings settings, Provider<T> provider) {
46+
if (badSemver(settings.getGradle().getGradleVersion()) >= badSemver(STOP_FORUSE_AT_CONFIGURATION_TIME)) {
47+
return provider.get();
48+
} else {
49+
return provider.forUseAtConfigurationTime().get();
50+
}
51+
}
52+
53+
static final String STOP_FORUSE_AT_CONFIGURATION_TIME = "7.4";
54+
55+
private static final Pattern BAD_SEMVER = Pattern.compile("(\\d+)\\.(\\d+)");
56+
57+
private static int badSemver(String input) {
58+
Matcher matcher = BAD_SEMVER.matcher(input);
59+
if (!matcher.find() || matcher.start() != 0) {
60+
throw new IllegalArgumentException("Version must start with " + BAD_SEMVER.pattern());
61+
}
62+
String major = matcher.group(1);
63+
String minor = matcher.group(2);
64+
return badSemver(Integer.parseInt(major), Integer.parseInt(minor));
65+
}
66+
67+
/** Ambiguous after 2147.483647.blah-blah */
68+
private static int badSemver(int major, int minor) {
69+
return major * 1_000_000 + minor;
3770
}
3871
}

0 commit comments

Comments
 (0)