Skip to content
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

Use modern API to get property values #2007

Closed
wants to merge 3 commits into from
Closed
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
23 changes: 13 additions & 10 deletions gradle/build-scans.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
File acceptFile = new File(gradle.gradleUserHomeDir, "build-scans/spotless/gradle-scans-license-agree.txt")
acceptFile.parentFile.mkdirs()
def env = System.getenv()
boolean isCI = env.CI || env.TRAVIS
boolean hasAccepted = isCI || env.SPOTLESS_GRADLE_SCANS_ACCEPT=='yes' || acceptFile.exists() && acceptFile.text.trim() == 'yes'
boolean hasRefused = env.SPOTLESS_GRADLE_SCANS_ACCEPT=='no' || acceptFile.exists() && acceptFile.text.trim() == 'no'

def env(String key) {
return providers.environmentVariable(key).orNull
}
boolean isCI = env('CI') != null
boolean hasAccepted = isCI || env('SPOTLESS_GRADLE_SCANS_ACCEPT') =='yes' || acceptFile.exists() && acceptFile.text.trim() == 'yes'
boolean hasRefused = env('SPOTLESS_GRADLE_SCANS_ACCEPT') =='no' || acceptFile.exists() && acceptFile.text.trim() == 'no'

buildScan {
if (hasAccepted) {
termsOfServiceAgree = 'yes'
} else if (!hasRefused) {
gradle.buildFinished {
println """
This build uses Gradle Build Scans to gather statistics, share information about
This build uses Gradle Build Scans to gather statistics, share information about
failures, environmental issues, dependencies resolved during the build and more.
Build scans will be published after each build, if you accept the terms of
Build scans will be published after each build, if you accept the terms of
service, and in particular the privacy policy.

Please read
https://gradle.com/terms-of-service
Please read

https://gradle.com/terms-of-service
https://gradle.com/legal/privacy

and then:
Expand All @@ -32,7 +35,7 @@ and then:

echo 'no' >> ${acceptFile}

And we'll not bother you again. Note that build scans are only made public if
And we'll not bother you again. Note that build scans are only made public if
you share the URL at the end of the build.
"""
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/changelog.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if (project == rootProject) {
if (isPlugin) {
// make sure there aren't any unreleased changes in lib
if (!rootProject.spotlessChangelog.parsedChangelog.noUnreleasedChanges()) {
if (!("true".equals(rootProject.findProperty('ignoreUnreleasedLib')))) {
if (!("true" == rootProject.providers.gradleProperty('ignoreUnreleasedLib').orNull)) {
throw new IllegalArgumentException(
"You're going to publish ${changelogPushTasks[0]}, but there are unreleased features in lib!\n" +
"You should run :changelogPush first! Else you'll be missing out on:\n" +
Expand Down
14 changes: 8 additions & 6 deletions gradle/java-publish.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import java.nio.charset.StandardCharsets
def env(String key) {
return providers.environmentVariable(key).orNull
}

def decode64(String varName) {
String envValue = System.env[varName]
String envValue = env(varName)
if (envValue == null) {
return ""
} else {
Expand All @@ -11,7 +13,7 @@ def decode64(String varName) {

if (project.parent == null) {
group = 'com.diffplug.spotless'
def pass = System.env['ORG_GRADLE_PROJECT_nexus_pass64']
def pass = env('ORG_GRADLE_PROJECT_nexus_pass64')
if (pass != null) {
pass = pass.decodeBase64()
}
Expand All @@ -22,7 +24,7 @@ if (project.parent == null) {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
username = System.env['ORG_GRADLE_PROJECT_nexus_user']
username = env('ORG_GRADLE_PROJECT_nexus_user')
password = decode64('ORG_GRADLE_PROJECT_nexus_pass64')
}
}
Expand Down Expand Up @@ -169,14 +171,14 @@ model {
}
}

if (System.env['JITPACK'] == 'true' || version.endsWith('-SNAPSHOT')) {
if (env('JITPACK') == 'true' || version.endsWith('-SNAPSHOT')) {
signing {
setRequired(false)
}
} else {
signing {
String gpg_key = decode64('ORG_GRADLE_PROJECT_gpg_key64')
useInMemoryPgpKeys(gpg_key, System.env['ORG_GRADLE_PROJECT_gpg_passphrase'])
useInMemoryPgpKeys(gpg_key, env('ORG_GRADLE_PROJECT_gpg_passphrase'))
sign(publishing.publications)
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/special-tests.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def special = [
'Shfmt'
]

boolean isCiServer = System.getenv().containsKey("CI")
boolean isCiServer = providers.environmentVariable("CI").isPresent()
tasks.withType(Test).configureEach {
if (isCiServer) {
retry {
Expand Down
5 changes: 3 additions & 2 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).

## [Unreleased]
* Support for `gofmt` ([#2001](https://github.com/diffplug/spotless/pull/2001))

### Added
* Support for `gofmt` ([#2001](https://github.com/diffplug/spotless/pull/2001))
* Maven / Gradle - Support for formatting Java Docs for the Palantir formatter ([#2009](https://github.com/diffplug/spotless/pull/2009))
### Changes
* Bump min Gradle requirement from `6.1.1` to `6.2`. ([#2007](https://github.com/diffplug/spotless/pull/2007))

## [6.24.0] - 2024-01-15
### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 DiffPlug
* Copyright 2016-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -558,8 +558,8 @@ public LicenseHeaderConfig updateYearWithLatest(boolean updateYearWithLatest) {

FormatterStep createStep() {
return builder.withYearModeLazy(() -> {
if ("true".equals(spotless.project
.findProperty(LicenseHeaderStep.FLAG_SET_LICENSE_HEADER_YEARS_FROM_GIT_HISTORY()))) {
if ("true".equals(spotless.project.getProviders()
.gradleProperty(LicenseHeaderStep.FLAG_SET_LICENSE_HEADER_YEARS_FROM_GIT_HISTORY()).getOrNull())) {
return YearMode.SET_FROM_GIT;
} else {
boolean updateYear = updateYearWithLatest == null ? getRatchetFrom() != null : updateYearWithLatest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,7 +34,7 @@ private static void dumpIsClean() {
}

static void performHook(SpotlessTaskImpl spotlessTask) {
String path = (String) spotlessTask.getProject().property(PROPERTY);
String path = spotlessTask.getProject().getProviders().gradleProperty(PROPERTY).get();
File file = new File(path);
if (!file.isAbsolute()) {
System.err.println("Argument passed to " + PROPERTY + " must be an absolute path");
Expand All @@ -50,7 +50,7 @@ static void performHook(SpotlessTaskImpl spotlessTask) {
}
}
byte[] bytes;
if (spotlessTask.getProject().hasProperty(USE_STD_IN)) {
if (spotlessTask.getProject().getProviders().gradleProperty(USE_STD_IN).isPresent()) {
bytes = ByteStreams.toByteArray(System.in);
} else {
bytes = Files.readAllBytes(file.toPath());
Expand All @@ -63,7 +63,7 @@ static void performHook(SpotlessTaskImpl spotlessTask) {
System.err.println("Run 'spotlessDiagnose' for details https://github.com/diffplug/spotless/blob/main/PADDEDCELL.md");
} else {
System.err.println("IS DIRTY");
if (spotlessTask.getProject().hasProperty(USE_STD_OUT)) {
if (spotlessTask.getProject().getProviders().gradleProperty(USE_STD_OUT).isPresent()) {
dirty.writeCanonicalTo(System.out);
} else {
dirty.writeCanonicalTo(file);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2022 DiffPlug
* Copyright 2016-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,7 +48,7 @@ public SpotlessExtensionImpl(Project project) {

@Override
protected void createFormatTasks(String name, FormatExtension formatExtension) {
boolean isIdeHook = project.hasProperty(IdeHook.PROPERTY);
boolean isIdeHook = project.getProviders().gradleProperty(IdeHook.PROPERTY).isPresent();
TaskContainer tasks = project.getTasks();

// create the SpotlessTask
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 DiffPlug
* Copyright 2016-2024 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 @@ -26,7 +26,7 @@

public class SpotlessPlugin implements Plugin<Project> {
static final String SPOTLESS_MODERN = "spotlessModern";
static final String VER_GRADLE_min = "6.1.1";
static final String VER_GRADLE_min = "6.2";
static final String VER_GRADLE_javaPluginExtension = "7.1";
private static final int MINIMUM_JRE = 11;

Expand All @@ -41,7 +41,7 @@ public void apply(Project project) {
+ "https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation");
}
// if -PspotlessModern=true, then use the modern stuff instead of the legacy stuff
if (project.hasProperty(SPOTLESS_MODERN)) {
if (project.getProviders().gradleProperty(SPOTLESS_MODERN).isPresent()) {
project.getLogger().warn("'spotlessModern' has no effect as of Spotless 5.0, recommend removing it.");
}
// make sure there's a `clean` and a `check`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ prettierConfig['printWidth'] = 20
prettierConfig['parser'] = 'typescript'

// the executable names
def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'
def nodeExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/node.exe' : '/bin/node'
def npmExec = providers.systemProperty('os.name').get().toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'
def nodeExec = providers.systemProperty('os.name').get().toLowerCase().contains('windows') ? '/node.exe' : '/bin/node'

spotless {
format 'mytypescript', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ prettierConfig['printWidth'] = 20
prettierConfig['parser'] = 'typescript'

// the executable name
def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'
def npmExec = providers.systemProperty('os.name').get().toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'

spotless {
typescript {
Expand Down
14 changes: 9 additions & 5 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ dependencyResolutionManagement {
}
}

if (System.env['CI'] != null) {
def env(String key) {
return providers.environmentVariable(key).orNull
}

if (env('CI') != null) {
// use the remote buildcache on all CI builds
buildCache {
def cred = {
if (System.env[it] != null) {
return System.env[it]
if (env(it) != null) {
return env(it)
} else {
return System.getProperty(it)
return providers.systemProperty(it)
}
}
remote(HttpBuildCache) {
Expand Down Expand Up @@ -92,6 +96,6 @@ def getStartProperty(java.lang.String name) {
return userProperties.get(name)
}

if (System.getenv('SPOTLESS_EXCLUDE_MAVEN') != 'true' && getStartProperty('SPOTLESS_EXCLUDE_MAVEN') != 'true') {
if (env('SPOTLESS_EXCLUDE_MAVEN') != 'true' && getStartProperty('SPOTLESS_EXCLUDE_MAVEN') != 'true') {
include 'plugin-maven' // maven-specific glue code
}
Loading