|
| 1 | +/* |
| 2 | + * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. |
| 3 | + */ |
| 4 | + |
| 5 | +@file:Suppress("DuplicatedCode", "MISSING_DEPENDENCY_CLASS") |
| 6 | + |
| 7 | +import java.util.* |
| 8 | + |
| 9 | +pluginManagement { |
| 10 | + fun logAbsentProperty(name: String): Nothing? { |
| 11 | + logger.info("Property '$name' is not present for repository credentials.") |
| 12 | + |
| 13 | + return null |
| 14 | + } |
| 15 | + |
| 16 | + @Suppress("RemoveRedundantQualifierName") |
| 17 | + fun getLocalProperties(): java.util.Properties { |
| 18 | + return java.util.Properties().apply { |
| 19 | + val propertiesDir = File( |
| 20 | + rootDir.path |
| 21 | + .removeSuffix("/gradle-conventions") |
| 22 | + .removeSuffix("/gradle-conventions-settings") |
| 23 | + .removeSuffix("/ksp-plugin") |
| 24 | + .removeSuffix("/compiler-plugin") |
| 25 | + .removeSuffix("/gradle-plugin") |
| 26 | + ) |
| 27 | + val localFile = File(propertiesDir, "local.properties") |
| 28 | + if (localFile.exists()) { |
| 29 | + localFile.inputStream().use { load(it) } |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + fun getSpaceUsername(): String? { |
| 35 | + val username = "kotlinx.rpc.team.space.username" |
| 36 | + return getLocalProperties()[username] as String? |
| 37 | + ?: settings.providers.gradleProperty(username).orNull |
| 38 | + ?: System.getenv(username)?.ifEmpty { null } |
| 39 | + ?: logAbsentProperty(username) |
| 40 | + } |
| 41 | + |
| 42 | + fun getSpacePassword(): String? { |
| 43 | + val password = "kotlinx.rpc.team.space.password" |
| 44 | + return getLocalProperties()[password] as String? |
| 45 | + ?: settings.providers.gradleProperty(password).orNull |
| 46 | + ?: System.getenv(password)?.ifEmpty { null } |
| 47 | + ?: logAbsentProperty(password) |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Creates a publishing repository targeting Space Packages on jetbrains.team. |
| 52 | + * |
| 53 | + * @param repoName the name of the Space Packages repository |
| 54 | + */ |
| 55 | + fun RepositoryHandler.jbTeamPackages(repoName: String) { |
| 56 | + maven { |
| 57 | + name = repoName.split("-").joinToString("") { it.replaceFirstChar { c -> c.titlecase() } } |
| 58 | + url = uri("https://packages.jetbrains.team/maven/p/krpc/$repoName") |
| 59 | + credentials { |
| 60 | + username = getSpaceUsername() |
| 61 | + password = getSpacePassword() |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + fun RepositoryHandler.buildDeps() = jbTeamPackages(repoName = "build-deps") |
| 67 | + fun RepositoryHandler.buildDepsEap() = jbTeamPackages(repoName = "build-deps-eap") |
| 68 | + |
| 69 | + repositories { |
| 70 | + buildDeps() |
| 71 | + buildDepsEap() |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +gradle.rootProject { |
| 76 | + fun logAbsentProperty(name: String): Nothing? { |
| 77 | + logger.info("Property '$name' is not present for repository credentials.") |
| 78 | + |
| 79 | + return null |
| 80 | + } |
| 81 | + |
| 82 | + fun getLocalProperties(): Properties { |
| 83 | + return Properties().apply { |
| 84 | + val propertiesDir = File( |
| 85 | + rootDir.path |
| 86 | + .removeSuffix("/gradle-conventions") |
| 87 | + .removeSuffix("/gradle-conventions-settings") |
| 88 | + .removeSuffix("/ksp-plugin") |
| 89 | + .removeSuffix("/compiler-plugin") |
| 90 | + .removeSuffix("/gradle-plugin") |
| 91 | + ) |
| 92 | + val localFile = File(propertiesDir, "local.properties") |
| 93 | + if (localFile.exists()) { |
| 94 | + localFile.inputStream().use { load(it) } |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + fun getSpaceUsername(): String? { |
| 100 | + val username = "kotlinx.rpc.team.space.username" |
| 101 | + return getLocalProperties()[username] as String? |
| 102 | + ?: settings.providers.gradleProperty(username).orNull |
| 103 | + ?: System.getenv(username)?.ifEmpty { null } |
| 104 | + ?: logAbsentProperty(username) |
| 105 | + } |
| 106 | + |
| 107 | + fun getSpacePassword(): String? { |
| 108 | + val password = "kotlinx.rpc.team.space.password" |
| 109 | + return getLocalProperties()[password] as String? |
| 110 | + ?: settings.providers.gradleProperty(password).orNull |
| 111 | + ?: System.getenv(password)?.ifEmpty { null } |
| 112 | + ?: logAbsentProperty(password) |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Creates a publishing repository targeting Space Packages on jetbrains.team. |
| 117 | + * |
| 118 | + * @param repoName the name of the Space Packages repository |
| 119 | + */ |
| 120 | + fun RepositoryHandler.jbTeamPackages(repoName: String) { |
| 121 | + maven { |
| 122 | + name = repoName.split("-").joinToString("") { it.replaceFirstChar { c -> c.titlecase() } } |
| 123 | + |
| 124 | + url = uri("https://packages.jetbrains.team/maven/p/krpc/$repoName") |
| 125 | + credentials { |
| 126 | + username = getSpaceUsername() |
| 127 | + password = getSpacePassword() |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + fun RepositoryHandler.buildDeps() = jbTeamPackages(repoName = "build-deps") |
| 133 | + fun RepositoryHandler.buildDepsEap() = jbTeamPackages(repoName = "build-deps-eap") |
| 134 | + |
| 135 | + allprojects { |
| 136 | + buildscript { |
| 137 | + repositories { |
| 138 | + buildDeps() |
| 139 | + buildDepsEap() |
| 140 | + } |
| 141 | + } |
| 142 | + repositories { |
| 143 | + buildDeps() |
| 144 | + buildDepsEap() |
| 145 | + } |
| 146 | + } |
| 147 | +} |
0 commit comments