Skip to content

Commit a4063ed

Browse files
authored
Add support for configuration cache (#153)
2 parents 6511522 + be82b2b commit a4063ed

File tree

6 files changed

+120
-3
lines changed

6 files changed

+120
-3
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Goomph releases
22

33
## [Unreleased]
4+
### Added
5+
- New plugin `com.diffplug.configuration-cache-for-platform-specific-build` which makes the `OS.getNative()` and `SwtPlatform.xxx` methods work without breaking the Gradle configuration cache. ([#153](https://github.com/diffplug/goomph/pull/153))
46

57
## [3.31.0] - 2021-07-23
68
### Added

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ Below is an index of Goomph's capabilities, along with links to the javadoc wher
108108

109109
* Used to power the infrastructure above.
110110

111+
#### Other
112+
113+
* [`com.diffplug.configuration-cache-for-platform-specific-build`](https://javadoc.io/doc/com.diffplug.gradle/goomph/3.31.0/com/diffplug/gradle/swt/PlatformSpecificBuildPlugin.html) allows you to use `OS.getNative()` and `OS.getRunning()` in your gradle build without breaking the configuration cache.
114+
111115
<!---freshmark /javadoc -->
112116

113117
## Acknowledgements

build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ spotless {
2424
}
2525

2626
String VER_DURIAN = '1.2.0'
27-
String VER_DURIAN_SWT = '3.4.0'
27+
String VER_DURIAN_SWT = '3.5.0'
2828
String VER_BNDLIB = '5.3.0'
2929
String OLDEST_SUPPORTED_GRADLE = '5.1'
3030
String VER_P2_BOOTSTRAP = '4.13.0'
@@ -42,8 +42,8 @@ dependencies {
4242
// OSGi
4343
implementation "biz.aQute.bnd:biz.aQute.bndlib:${VER_BNDLIB}"
4444
// testing
45-
testImplementation "junit:junit:4.13"
46-
testImplementation "org.assertj:assertj-core:3.14.0"
45+
testImplementation "junit:junit:4.13.2"
46+
testImplementation "org.assertj:assertj-core:3.20.2"
4747
}
4848

4949
configurations.compileClasspath {

gradle.properties

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ plugin_list=\
1414
eclipseResourceFilters \
1515
equinoxLaunch \
1616
oomphIde \
17+
platformSpecificBuild \
1718
p2AsMaven \
1819
osgiBndManifest \
1920
swtNativeDeps
@@ -63,6 +64,12 @@ plugin_oomphIde_name=Goomph oomphIde
6364
plugin_oomphIde_desc=Downloads and sets up any Eclipse-based IDE.
6465
plugin_oomphIde_tags=eclipse ide p2AsMaven
6566

67+
plugin_platformSpecificBuild_id=com.diffplug.configuration-cache-for-platform-specific-build
68+
plugin_platformSpecificBuild_impl=com.diffplug.gradle.swt.PlatformSpecificBuildPlugin
69+
plugin_platformSpecificBuild_name=Goomph configuration-cache friendly platform specific build
70+
plugin_platformSpecificBuild_desc=Allows `OS.getNative()` and `OS.getRunning()` to work with configuration cache
71+
plugin_platformSpecificBuild_tags=configuration-cache platform-specific
72+
6673
plugin_p2AsMaven_id=com.diffplug.p2.asmaven
6774
plugin_p2AsMaven_impl=com.diffplug.gradle.p2.AsMavenPlugin
6875
plugin_p2AsMaven_name=Goomph p2AsMaven
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (C) 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+
* https://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.swt;
17+
18+
19+
import com.diffplug.common.swt.os.OS;
20+
import org.gradle.api.Plugin;
21+
import org.gradle.api.initialization.Settings;
22+
23+
/**
24+
* In order to detect the underlying operating system and architecture, it is necessary to
25+
* to read various system properties and environment variables, which breaks the Gradle configuration cache.
26+
* But, if you apply `com.diffplug.configuration-cache-for-platform-specific-build` in your `settings.gradle`,
27+
* then you can call {@link OS#getRunning()} and {@link OS#getNative()} and behind the scenes it will use
28+
* <a href="https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:requirements:undeclared_sys_prop_read">
29+
* the appropriate APIs</a> which don't break the configuration cache.
30+
*/
31+
public class PlatformSpecificBuildPlugin implements Plugin<Settings> {
32+
@Override
33+
public void apply(Settings settings) {
34+
OS.detectPlatform(
35+
systemProp -> settings.getProviders().systemProperty(systemProp).forUseAtConfigurationTime().get(),
36+
envVar -> settings.getProviders().environmentVariable(envVar).forUseAtConfigurationTime().get());
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (C) 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+
* https://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.swt;
17+
18+
19+
import com.diffplug.gradle.GradleIntegrationTest;
20+
import java.io.IOException;
21+
import org.gradle.testkit.runner.GradleRunner;
22+
import org.junit.Ignore;
23+
import org.junit.Test;
24+
25+
public class PlatformSpecificBuildPluginTest extends GradleIntegrationTest {
26+
protected GradleRunner gradleRunner() {
27+
return super.gradleRunner().withGradleVersion("7.2");
28+
}
29+
30+
private GradleRunner breakConfigCache() throws IOException {
31+
write("gradle.properties", "org.gradle.unsafe.configuration-cache=true");
32+
write("build.gradle",
33+
"plugins {",
34+
" id 'java'",
35+
" id 'com.diffplug.eclipse.mavencentral'",
36+
"}",
37+
"repositories { mavenCentral() }",
38+
"eclipseMavenCentral {",
39+
" release '4.20.0', {",
40+
" implementation 'org.eclipse.swt'",
41+
" implementation 'org.eclipse.jface'",
42+
" implementation \"org.eclipse.swt.${com.diffplug.common.swt.os.SwtPlatform.getRunning()}\"",
43+
" useNativesForRunningPlatform()",
44+
" }",
45+
"}");
46+
write("src/main/java/pkg/Demo.java",
47+
"package pkg;",
48+
"public class Demo {}");
49+
return gradleRunner().withArguments("jar");
50+
}
51+
52+
@Test
53+
@Ignore // fails in real project, but not unit test, not sure why
54+
public void configurationCacheBroken() throws IOException {
55+
breakConfigCache().buildAndFail();
56+
}
57+
58+
@Test
59+
public void configurationCacheWorks() throws IOException {
60+
write("settings.gradle",
61+
"plugins {",
62+
" id 'com.diffplug.configuration-cache-for-platform-specific-build'",
63+
"}");
64+
breakConfigCache().build();
65+
}
66+
}

0 commit comments

Comments
 (0)