From 4258850039380d74b3e05d6b76f657d2bb1a5a48 Mon Sep 17 00:00:00 2001
From: Pawel Pasterz <pawel.pasterz@gmail.com>
Date: Wed, 6 Jan 2021 09:20:56 +0100
Subject: [PATCH] Change gradle file

---
 build.gradle.kts                              |  7 +++++
 .../flank/common/config/FlankProperties.kt    | 29 ++++++++++++-------
 flank-scripts/build.gradle.kts                |  1 -
 .../scripts/config/FlankScriptsConfigs.kt     | 22 --------------
 .../kotlin/flank/scripts/github/GithubApi.kt  |  2 +-
 .../flank/scripts/integration/IssueList.kt    |  2 +-
 .../scripts/integration/PrepareMessage.kt     |  2 +-
 .../scripts/integration/WorkflowSummary.kt    |  2 +-
 .../release/updatebugsnag/UpdateBugSnag.kt    |  2 +-
 .../apiclient/UpdateApiJsonCommand.kt         |  2 +-
 .../firebase/sdk/CheckForSDKUpdateCommand.kt  |  2 +-
 .../scripts/shell/firebase/sdk/CommitList.kt  |  2 +-
 .../scripts/shell/firebase/sdk/Extensions.kt  |  2 +-
 .../shell/firebase/sdk/LastSDKUpdateRun.kt    |  2 +-
 .../shell/firebase/sdk/OpenedUpdates.kt       |  2 +-
 .../testartifacts/core/TestArtifactsRepo.kt   |  2 +-
 .../kotlin/flank/scripts/zenhub/ZenHubAPI.kt  |  2 +-
 17 files changed, 39 insertions(+), 46 deletions(-)
 delete mode 100644 flank-scripts/src/main/kotlin/flank/scripts/config/FlankScriptsConfigs.kt

diff --git a/build.gradle.kts b/build.gradle.kts
index 5f73346022..d2013ea7f6 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -30,6 +30,13 @@ tasks {
 
 subprojects {
     apply(plugin = Plugins.KTLINT_GRADLE_PLUGIN)
+    afterEvaluate {
+        if (tasks.findByName("test") != null) {
+            tasks.test {
+                systemProperty("useDefaultProperties", "")
+            }
+        }
+    }
 }
 
 repositories {
diff --git a/common/src/main/kotlin/flank/common/config/FlankProperties.kt b/common/src/main/kotlin/flank/common/config/FlankProperties.kt
index c2bb4dae14..996c96d039 100644
--- a/common/src/main/kotlin/flank/common/config/FlankProperties.kt
+++ b/common/src/main/kotlin/flank/common/config/FlankProperties.kt
@@ -5,14 +5,14 @@ import flank.common.isCI
 import java.nio.file.Paths
 import java.util.Properties
 
-const val ZENHUB_REPO_ID = "zenhub.repo-id"
-const val FLANK_REPO = "repo.flank"
-const val GCLOUD_REPO = "repo.gcloud_cli"
-const val ARTIFACTS_REPO = "repo.test-artifacts"
-const val IT_WORKFLOW_FILE = "integration.workflow-filename"
-const val IT_USER = "integration.issue-poster"
-const val SDK_WORKFLOW = "sdk-check.workflow-filename"
-const val SDK_USER = "sdk-check.issue-poster"
+private const val ZENHUB_REPO_ID = "zenhub.repo-id"
+private const val FLANK_REPO = "repo.flank"
+private const val GCLOUD_REPO = "repo.gcloud_cli"
+private const val ARTIFACTS_REPO = "repo.test-artifacts"
+private const val IT_WORKFLOW_FILE = "integration.workflow-filename"
+private const val IT_USER = "integration.issue-poster"
+private const val SDK_WORKFLOW = "sdk-check.workflow-filename"
+private const val SDK_USER = "sdk-check.issue-poster"
 
 private val defaults = Properties().apply {
     setProperty(ZENHUB_REPO_ID, "84221974")
@@ -34,10 +34,19 @@ class SafeProperties(defaults: Properties) : Properties(defaults) {
 // default properties should be used in CI and during tests
 private fun shouldUseDefaults() = isCI() || isTest()
 
-private fun isTest() = System.getProperty("testScript") != null
+private fun isTest() = System.getProperty("useDefaultProperties") != null
 
-val flankProjectProperties = SafeProperties(defaults).also { prop ->
+private val props = SafeProperties(defaults).also { prop ->
     with(Paths.get("$flankCommonRootPathString/flank-debug.properties").toFile()) {
         if (exists()) prop.load(inputStream())
     }
 }
+
+val zenhubRepositoryID = Integer.parseInt(props[ZENHUB_REPO_ID])
+val flankRepository = props[FLANK_REPO]
+val flankGcloudCLIRepository = props[GCLOUD_REPO]
+val flankTestArtifactsRepository = props[ARTIFACTS_REPO]
+val integrationOpenedIssueUser = props[IT_USER]
+val updatesOpenedUser = props[SDK_USER]
+val fullSuiteWorkflowFilename = props[IT_WORKFLOW_FILE]
+val updateDependenciesWorkflowFilename = props[SDK_WORKFLOW]
diff --git a/flank-scripts/build.gradle.kts b/flank-scripts/build.gradle.kts
index 3d4abd075c..9b6912c9af 100644
--- a/flank-scripts/build.gradle.kts
+++ b/flank-scripts/build.gradle.kts
@@ -99,7 +99,6 @@ publishing {
 tasks.test {
     maxHeapSize = "2048m"
     minHeapSize = "512m"
-    systemProperty("testScript", "")
 }
 
 repositories {
diff --git a/flank-scripts/src/main/kotlin/flank/scripts/config/FlankScriptsConfigs.kt b/flank-scripts/src/main/kotlin/flank/scripts/config/FlankScriptsConfigs.kt
deleted file mode 100644
index 182286795b..0000000000
--- a/flank-scripts/src/main/kotlin/flank/scripts/config/FlankScriptsConfigs.kt
+++ /dev/null
@@ -1,22 +0,0 @@
-package flank.scripts.config
-
-import flank.common.config.ARTIFACTS_REPO
-import flank.common.config.FLANK_REPO
-import flank.common.config.GCLOUD_REPO
-import flank.common.config.IT_USER
-import flank.common.config.IT_WORKFLOW_FILE
-import flank.common.config.SDK_USER
-import flank.common.config.SDK_WORKFLOW
-import flank.common.config.ZENHUB_REPO_ID
-import flank.common.config.flankProjectProperties
-
-private val props = flankProjectProperties
-
-val zenhubRepositoryID = Integer.parseInt(props[ZENHUB_REPO_ID])
-val flankRepository = props[FLANK_REPO]
-val flankGcloudCLIRepository = props[GCLOUD_REPO]
-val flankTestArtifactsRepository = props[ARTIFACTS_REPO]
-val integrationOpenedIssueUser = props[IT_USER]
-val updatesOpenedUser = props[SDK_USER]
-val fullSuiteWorkflowFilename = props[IT_WORKFLOW_FILE]
-val updateDependenciesWorkflowFilename = props[SDK_WORKFLOW]
diff --git a/flank-scripts/src/main/kotlin/flank/scripts/github/GithubApi.kt b/flank-scripts/src/main/kotlin/flank/scripts/github/GithubApi.kt
index fb4f236c75..833e55de34 100644
--- a/flank-scripts/src/main/kotlin/flank/scripts/github/GithubApi.kt
+++ b/flank-scripts/src/main/kotlin/flank/scripts/github/GithubApi.kt
@@ -14,9 +14,9 @@ import com.jcabi.github.Release
 import com.jcabi.github.Releases
 import com.jcabi.github.Repo
 import com.jcabi.github.RtGithub
+import flank.common.config.flankRepository
 import flank.scripts.ci.releasenotes.GitHubRelease
 import flank.scripts.ci.releasenotes.GithubReleaseDeserializable
-import flank.scripts.config.flankRepository
 import flank.scripts.exceptions.mapClientErrorToGithubException
 import flank.scripts.github.objects.GitHubCommit
 import flank.scripts.github.objects.GitHubCommitListDeserializer
diff --git a/flank-scripts/src/main/kotlin/flank/scripts/integration/IssueList.kt b/flank-scripts/src/main/kotlin/flank/scripts/integration/IssueList.kt
index 90e1282108..be5f1b8003 100644
--- a/flank-scripts/src/main/kotlin/flank/scripts/integration/IssueList.kt
+++ b/flank-scripts/src/main/kotlin/flank/scripts/integration/IssueList.kt
@@ -2,7 +2,7 @@ package flank.scripts.integration
 
 import com.github.kittinunf.result.getOrElse
 import com.github.kittinunf.result.onError
-import flank.scripts.config.integrationOpenedIssueUser
+import flank.common.config.integrationOpenedIssueUser
 import flank.scripts.github.getGitHubIssueList
 
 suspend fun checkForOpenedITIssues(token: String): Int? = getGitHubIssueList(
diff --git a/flank-scripts/src/main/kotlin/flank/scripts/integration/PrepareMessage.kt b/flank-scripts/src/main/kotlin/flank/scripts/integration/PrepareMessage.kt
index a787387134..d76f0aefc1 100644
--- a/flank-scripts/src/main/kotlin/flank/scripts/integration/PrepareMessage.kt
+++ b/flank-scripts/src/main/kotlin/flank/scripts/integration/PrepareMessage.kt
@@ -1,6 +1,6 @@
 package flank.scripts.integration
 
-import flank.scripts.config.flankRepository
+import flank.common.config.flankRepository
 import flank.scripts.github.objects.GithubPullRequest
 import java.time.Instant
 import java.time.LocalDateTime
diff --git a/flank-scripts/src/main/kotlin/flank/scripts/integration/WorkflowSummary.kt b/flank-scripts/src/main/kotlin/flank/scripts/integration/WorkflowSummary.kt
index fdbe80a379..7350ea4be0 100644
--- a/flank-scripts/src/main/kotlin/flank/scripts/integration/WorkflowSummary.kt
+++ b/flank-scripts/src/main/kotlin/flank/scripts/integration/WorkflowSummary.kt
@@ -1,6 +1,6 @@
 package flank.scripts.integration
 
-import flank.scripts.config.fullSuiteWorkflowFilename
+import flank.common.config.fullSuiteWorkflowFilename
 import flank.scripts.github.commons.getLastWorkflowRunDate
 
 suspend fun getLastITWorkflowRunDate(token: String) = getLastWorkflowRunDate(
diff --git a/flank-scripts/src/main/kotlin/flank/scripts/release/updatebugsnag/UpdateBugSnag.kt b/flank-scripts/src/main/kotlin/flank/scripts/release/updatebugsnag/UpdateBugSnag.kt
index 903529a3f1..49ebbab51d 100644
--- a/flank-scripts/src/main/kotlin/flank/scripts/release/updatebugsnag/UpdateBugSnag.kt
+++ b/flank-scripts/src/main/kotlin/flank/scripts/release/updatebugsnag/UpdateBugSnag.kt
@@ -3,7 +3,7 @@ package flank.scripts.release.updatebugsnag
 import com.github.kittinunf.fuel.Fuel
 import com.github.kittinunf.fuel.core.extensions.jsonBody
 import com.github.kittinunf.fuel.coroutines.awaitResult
-import flank.scripts.config.flankRepository
+import flank.common.config.flankRepository
 import flank.scripts.exceptions.mapClientError
 import flank.scripts.exceptions.toBugsnagException
 import flank.scripts.utils.toJson
diff --git a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/apiclient/UpdateApiJsonCommand.kt b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/apiclient/UpdateApiJsonCommand.kt
index 0a24f68781..bce2aff3c9 100644
--- a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/apiclient/UpdateApiJsonCommand.kt
+++ b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/apiclient/UpdateApiJsonCommand.kt
@@ -1,9 +1,9 @@
 package flank.scripts.shell.firebase.apiclient
 
 import com.github.ajalt.clikt.core.CliktCommand
+import flank.common.config.flankGcloudCLIRepository
 import flank.common.currentPath
 import flank.common.downloadFile
-import flank.scripts.config.flankGcloudCLIRepository
 import flank.scripts.utils.downloadSortJsonIfNeeded
 import flank.scripts.utils.runCommand
 import java.nio.file.Paths
diff --git a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/CheckForSDKUpdateCommand.kt b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/CheckForSDKUpdateCommand.kt
index 239845b3fd..2c81f4bf84 100644
--- a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/CheckForSDKUpdateCommand.kt
+++ b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/CheckForSDKUpdateCommand.kt
@@ -4,9 +4,9 @@ import com.github.ajalt.clikt.core.CliktCommand
 import com.github.ajalt.clikt.parameters.options.option
 import com.github.ajalt.clikt.parameters.options.required
 import com.github.kittinunf.fuel.Fuel
+import flank.common.config.flankGcloudCLIRepository
 import flank.common.currentPath
 import flank.common.downloadFile
-import flank.scripts.config.flankGcloudCLIRepository
 import flank.scripts.utils.parseToVersion
 import kotlinx.coroutines.runBlocking
 import java.nio.file.Paths
diff --git a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/CommitList.kt b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/CommitList.kt
index 18474b6fab..cf3b666a06 100644
--- a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/CommitList.kt
+++ b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/CommitList.kt
@@ -1,6 +1,6 @@
 package flank.scripts.shell.firebase.sdk
 
-import flank.scripts.config.flankGcloudCLIRepository
+import flank.common.config.flankGcloudCLIRepository
 import flank.scripts.github.getGitHubCommitList
 import flank.scripts.github.objects.GitHubCommit
 import java.time.Instant
diff --git a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/Extensions.kt b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/Extensions.kt
index f3deb12f9a..70ad8115b7 100644
--- a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/Extensions.kt
+++ b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/Extensions.kt
@@ -2,8 +2,8 @@ package flank.scripts.shell.firebase.sdk
 
 import com.github.kittinunf.result.Result
 import com.github.kittinunf.result.onError
+import flank.common.config.zenhubRepositoryID
 import flank.common.newLine
-import flank.scripts.config.zenhubRepositoryID
 import flank.scripts.github.objects.GitHubCreateIssueRequest
 import flank.scripts.github.objects.GitHubCreateIssueResponse
 import flank.scripts.github.objects.GitHubUpdateIssueRequest
diff --git a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/LastSDKUpdateRun.kt b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/LastSDKUpdateRun.kt
index 188aa6283b..ad5f5b31fc 100644
--- a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/LastSDKUpdateRun.kt
+++ b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/LastSDKUpdateRun.kt
@@ -1,6 +1,6 @@
 package flank.scripts.shell.firebase.sdk
 
-import flank.scripts.config.updateDependenciesWorkflowFilename
+import flank.common.config.updateDependenciesWorkflowFilename
 import flank.scripts.github.commons.getLastWorkflowRunDate
 
 suspend fun getLastSDKUpdateRunDate(token: String) = getLastWorkflowRunDate(
diff --git a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/OpenedUpdates.kt b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/OpenedUpdates.kt
index ba10601d21..290bc21574 100644
--- a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/OpenedUpdates.kt
+++ b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/sdk/OpenedUpdates.kt
@@ -2,7 +2,7 @@ package flank.scripts.shell.firebase.sdk
 
 import com.github.kittinunf.result.getOrElse
 import com.github.kittinunf.result.onError
-import flank.scripts.config.updatesOpenedUser
+import flank.common.config.updatesOpenedUser
 import flank.scripts.github.getGitHubIssueList
 
 suspend fun checkForOpenedUpdates(token: String) = getGitHubIssueList(
diff --git a/flank-scripts/src/main/kotlin/flank/scripts/testartifacts/core/TestArtifactsRepo.kt b/flank-scripts/src/main/kotlin/flank/scripts/testartifacts/core/TestArtifactsRepo.kt
index 049e175e5d..f9c2da896c 100644
--- a/flank-scripts/src/main/kotlin/flank/scripts/testartifacts/core/TestArtifactsRepo.kt
+++ b/flank-scripts/src/main/kotlin/flank/scripts/testartifacts/core/TestArtifactsRepo.kt
@@ -1,7 +1,7 @@
 package flank.scripts.testartifacts.core
 
 import com.jcabi.github.Repo
-import flank.scripts.config.flankTestArtifactsRepository
+import flank.common.config.flankTestArtifactsRepository
 import flank.scripts.github.githubRepo
 import flank.scripts.utils.getEnv
 
diff --git a/flank-scripts/src/main/kotlin/flank/scripts/zenhub/ZenHubAPI.kt b/flank-scripts/src/main/kotlin/flank/scripts/zenhub/ZenHubAPI.kt
index cbf79b666d..2e5a4faff6 100644
--- a/flank-scripts/src/main/kotlin/flank/scripts/zenhub/ZenHubAPI.kt
+++ b/flank-scripts/src/main/kotlin/flank/scripts/zenhub/ZenHubAPI.kt
@@ -7,7 +7,7 @@ import com.github.kittinunf.fuel.coroutines.awaitStringResult
 import com.github.kittinunf.result.getOrNull
 import com.github.kittinunf.result.onError
 import com.github.kittinunf.result.success
-import flank.scripts.config.zenhubRepositoryID
+import flank.common.config.zenhubRepositoryID
 import flank.scripts.utils.toJson
 import flank.scripts.zenhub.objects.ConvertToEpicRequest
 import flank.scripts.zenhub.objects.UpdateEpicRequest