You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2020/12/06 12:14:49 UTC

[groovy] 01/02: lazily evaluate artifactory.properties file (thanks Cédric)

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit e6f2ce3869dd9a6148d5fb4e9d8dccbd380f9ba3
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun Dec 6 22:14:03 2020 +1000

    lazily evaluate artifactory.properties file (thanks Cédric)
---
 .../groovy/gradle/SharedConfiguration.groovy       | 26 +++++++++++++---------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/buildSrc/src/main/groovy/org/apache/groovy/gradle/SharedConfiguration.groovy b/buildSrc/src/main/groovy/org/apache/groovy/gradle/SharedConfiguration.groovy
index 419f68c..87bac51 100644
--- a/buildSrc/src/main/groovy/org/apache/groovy/gradle/SharedConfiguration.groovy
+++ b/buildSrc/src/main/groovy/org/apache/groovy/gradle/SharedConfiguration.groovy
@@ -18,7 +18,6 @@
  */
 package org.apache.groovy.gradle
 
-
 import groovy.transform.CompileStatic
 import org.gradle.StartParameter
 import org.gradle.api.execution.TaskExecutionGraph
@@ -100,16 +99,7 @@ class SharedConfiguration {
         final Provider<String> repoKey
 
         Artifactory(ProjectLayout layout, ProviderFactory providers, Logger logger) {
-            // try to read artifactory.properties
-            Directory base = layout.projectDirectory
-            RegularFile artifactoryFile = base.file('artifactory.properties')
-            while (!artifactoryFile.asFile.exists()) {
-                base = base.dir('..')
-                if (!base) break
-                artifactoryFile = base.file('artifactory.properties')
-            }
-
-            def artifactoryProperties = providers.fileContents(artifactoryFile).asText.forUseAtConfigurationTime().map {
+            def artifactoryProperties = providers.fileContents(artifactoryFile(providers, layout)).asText.forUseAtConfigurationTime().map {
                 def props = new Properties()
                 props.load(new StringReader(it))
                 props
@@ -121,6 +111,20 @@ class SharedConfiguration {
             logger.lifecycle "ArtifactoryUser user: ${username.getOrElse("not defined")}"
         }
 
+        private Provider<RegularFile> artifactoryFile(ProviderFactory providers, ProjectLayout layout) {
+            providers.provider {
+                // try to read artifactory.properties
+                Directory base = layout.projectDirectory
+                RegularFile artifactoryFile = base.file('artifactory.properties')
+                while (!artifactoryFile.asFile.exists()) {
+                    base = base.dir('..')
+                    if (!base) break
+                    artifactoryFile = base.file('artifactory.properties')
+                }
+                artifactoryFile
+            }
+        }
+
         private Provider<String> provider(ProviderFactory providers, Provider<Properties> properties, String propertyName, String gradlePropertyName, String envVarName) {
             return providers.gradleProperty(gradlePropertyName).forUseAtConfigurationTime()
                     .orElse(providers.environmentVariable(envVarName).forUseAtConfigurationTime())