Skip to content

Commit

Permalink
Fix configuration cache issues (#214 fixes #211)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Dec 8, 2023
2 parents 4220dbf + f89c5c9 commit ba9297c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## [Unreleased]
### Added
- Eclipse `4.30.0` aka `2023-12` ([new and noteworthy](https://eclipse.dev/eclipse/news/4.30/))
- 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))
### Fixed
- `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))

## [3.43.0] - 2023-09-28
### Added
Expand Down
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spotless {
}

String VER_DURIAN = '1.2.0'
String VER_DURIAN_SWT = '3.6.1'
String VER_DURIAN_SWT = '4.3.0'
String VER_BNDLIB = '6.3.1'
String OLDEST_SUPPORTED_GRADLE = '5.1'
String VER_P2_BOOTSTRAP = '4.13.0'
Expand All @@ -40,15 +40,15 @@ dependencies {
implementation "com.diffplug.durian:durian-collect:${VER_DURIAN}"
implementation "com.diffplug.durian:durian-io:${VER_DURIAN}"
implementation "com.diffplug.durian:durian-swt.os:${VER_DURIAN_SWT}"
implementation "commons-io:commons-io:2.11.0"
implementation "com.diffplug.spotless:spotless-lib:2.28.0"
implementation "com.squareup.okhttp3:okhttp:4.10.0"
implementation "com.squareup.okio:okio:3.2.0"
implementation "commons-io:commons-io:2.15.1"
implementation "com.diffplug.spotless:spotless-lib:2.34.0"
implementation "com.squareup.okhttp3:okhttp:4.12.0"
implementation "com.squareup.okio:okio:3.6.0"
// OSGi
implementation "biz.aQute.bnd:biz.aQute.bndlib:${VER_BNDLIB}"
// testing
testImplementation "junit:junit:4.13.2"
testImplementation "org.assertj:assertj-core:3.23.1"
testImplementation "org.assertj:assertj-core:3.24.2"
}

configurations.compileClasspath {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 DiffPlug
* Copyright (C) 2021-2023 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 @@ -15,10 +15,12 @@
*/
package com.diffplug.gradle.swt;


import com.diffplug.common.swt.os.OS;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.gradle.api.Plugin;
import org.gradle.api.initialization.Settings;
import org.gradle.api.provider.Provider;

/**
* In order to detect the underlying operating system and architecture, it is necessary to
Expand All @@ -29,10 +31,41 @@
* the appropriate APIs</a> which don't break the configuration cache.
*/
public class PlatformSpecificBuildPlugin implements Plugin<Settings> {

@Override
public void apply(Settings settings) {
OS.detectPlatform(
systemProp -> settings.getProviders().systemProperty(systemProp).forUseAtConfigurationTime().get(),
envVar -> settings.getProviders().environmentVariable(envVar).forUseAtConfigurationTime().get());
systemProp -> get(settings, settings.getProviders().systemProperty(systemProp)),
envVar -> get(settings, settings.getProviders().environmentVariable(envVar)),
cmds -> get(settings, settings.getProviders().exec(e -> {
e.commandLine(cmds.toArray());
}).getStandardOutput().getAsText()));
}

private <T> T get(Settings settings, Provider<T> provider) {
if (badSemver(settings.getGradle().getGradleVersion()) >= badSemver(STOP_FORUSE_AT_CONFIGURATION_TIME)) {
return provider.get();
} else {
return provider.forUseAtConfigurationTime().get();
}
}

static final String STOP_FORUSE_AT_CONFIGURATION_TIME = "7.4";

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

private static int badSemver(String input) {
Matcher matcher = BAD_SEMVER.matcher(input);
if (!matcher.find() || matcher.start() != 0) {
throw new IllegalArgumentException("Version must start with " + BAD_SEMVER.pattern());
}
String major = matcher.group(1);
String minor = matcher.group(2);
return badSemver(Integer.parseInt(major), Integer.parseInt(minor));
}

/** Ambiguous after 2147.483647.blah-blah */
private static int badSemver(int major, int minor) {
return major * 1_000_000 + minor;
}
}

0 comments on commit ba9297c

Please sign in to comment.