Skip to content

Add support for configuration cache #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Goomph releases

## [Unreleased]
### Added
- 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))

## [3.31.0] - 2021-07-23
### Added
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ Below is an index of Goomph's capabilities, along with links to the javadoc wher

* Used to power the infrastructure above.

#### Other

* [`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.

<!---freshmark /javadoc -->

## Acknowledgements
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spotless {
}

String VER_DURIAN = '1.2.0'
String VER_DURIAN_SWT = '3.4.0'
String VER_DURIAN_SWT = '3.5.0'
String VER_BNDLIB = '5.3.0'
String OLDEST_SUPPORTED_GRADLE = '5.1'
String VER_P2_BOOTSTRAP = '4.13.0'
Expand All @@ -42,8 +42,8 @@ dependencies {
// OSGi
implementation "biz.aQute.bnd:biz.aQute.bndlib:${VER_BNDLIB}"
// testing
testImplementation "junit:junit:4.13"
testImplementation "org.assertj:assertj-core:3.14.0"
testImplementation "junit:junit:4.13.2"
testImplementation "org.assertj:assertj-core:3.20.2"
}

configurations.compileClasspath {
Expand Down
7 changes: 7 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ plugin_list=\
eclipseResourceFilters \
equinoxLaunch \
oomphIde \
platformSpecificBuild \
p2AsMaven \
osgiBndManifest \
swtNativeDeps
Expand Down Expand Up @@ -63,6 +64,12 @@ plugin_oomphIde_name=Goomph oomphIde
plugin_oomphIde_desc=Downloads and sets up any Eclipse-based IDE.
plugin_oomphIde_tags=eclipse ide p2AsMaven

plugin_platformSpecificBuild_id=com.diffplug.configuration-cache-for-platform-specific-build
plugin_platformSpecificBuild_impl=com.diffplug.gradle.swt.PlatformSpecificBuildPlugin
plugin_platformSpecificBuild_name=Goomph configuration-cache friendly platform specific build
plugin_platformSpecificBuild_desc=Allows `OS.getNative()` and `OS.getRunning()` to work with configuration cache
plugin_platformSpecificBuild_tags=configuration-cache platform-specific

plugin_p2AsMaven_id=com.diffplug.p2.asmaven
plugin_p2AsMaven_impl=com.diffplug.gradle.p2.AsMavenPlugin
plugin_p2AsMaven_name=Goomph p2AsMaven
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.gradle.swt;


import com.diffplug.common.swt.os.OS;
import org.gradle.api.Plugin;
import org.gradle.api.initialization.Settings;

/**
* In order to detect the underlying operating system and architecture, it is necessary to
* to read various system properties and environment variables, which breaks the Gradle configuration cache.
* But, if you apply `com.diffplug.configuration-cache-for-platform-specific-build` in your `settings.gradle`,
* then you can call {@link OS#getRunning()} and {@link OS#getNative()} and behind the scenes it will use
* <a href="https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:requirements:undeclared_sys_prop_read">
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.gradle.swt;


import com.diffplug.gradle.GradleIntegrationTest;
import java.io.IOException;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.Ignore;
import org.junit.Test;

public class PlatformSpecificBuildPluginTest extends GradleIntegrationTest {
protected GradleRunner gradleRunner() {
return super.gradleRunner().withGradleVersion("7.2");
}

private GradleRunner breakConfigCache() throws IOException {
write("gradle.properties", "org.gradle.unsafe.configuration-cache=true");
write("build.gradle",
"plugins {",
" id 'java'",
" id 'com.diffplug.eclipse.mavencentral'",
"}",
"repositories { mavenCentral() }",
"eclipseMavenCentral {",
" release '4.20.0', {",
" implementation 'org.eclipse.swt'",
" implementation 'org.eclipse.jface'",
" implementation \"org.eclipse.swt.${com.diffplug.common.swt.os.SwtPlatform.getRunning()}\"",
" useNativesForRunningPlatform()",
" }",
"}");
write("src/main/java/pkg/Demo.java",
"package pkg;",
"public class Demo {}");
return gradleRunner().withArguments("jar");
}

@Test
@Ignore // fails in real project, but not unit test, not sure why
public void configurationCacheBroken() throws IOException {
breakConfigCache().buildAndFail();
}

@Test
public void configurationCacheWorks() throws IOException {
write("settings.gradle",
"plugins {",
" id 'com.diffplug.configuration-cache-for-platform-specific-build'",
"}");
breakConfigCache().build();
}
}