Skip to content

Commit 4d0f258

Browse files
authored
Build: Fix fetchAsfProjectName and make the publishing extension more flexible (#1442)
The added flexibility is intended to be ported to the multiple project in the polaris-tools repository. (Follow up of #1384)
1 parent 358d207 commit 4d0f258

File tree

4 files changed

+79
-17
lines changed

4 files changed

+79
-17
lines changed

build-logic/src/main/kotlin/publishing/PublishingHelperExtension.kt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,48 @@ abstract class PublishingHelperExtension
3636
@Inject
3737
constructor(objectFactory: ObjectFactory, project: Project) {
3838
// the following are only relevant on the root project
39-
val asfProjectName = objectFactory.property<String>().convention(project.name)
39+
40+
/**
41+
* Lowercase ASF project ID, as present in keys in the JSON docs describing the projects (for
42+
* example in `https://whimsy.apache.org/public/public_ldap_projects.json`).
43+
*/
44+
val asfProjectId = objectFactory.property<String>().convention(project.name)
45+
46+
/** Used to override the full project name, for example `Apache Polaris`. */
4047
val overrideName = objectFactory.property<String>()
48+
/** Used to override the project description as it appears in published Maven poms. */
4149
val overrideDescription = objectFactory.property<String>()
50+
/** Used to override the project URL as it appears in published Maven poms. */
51+
val overrideProjectUrl = objectFactory.property<String>()
52+
/**
53+
* Used to override the name of the GitHub repo in the apache organization. Defaults to the
54+
* project ID.
55+
*/
56+
val githubRepositoryName = objectFactory.property<String>()
57+
/**
58+
* Used to override the project's SCM as it appears in published Maven poms. Default is derived
59+
* from `githubRepoName`.
60+
*/
61+
val overrideScm = objectFactory.property<String>()
62+
/** Used to override the project's issue management URL as it appears in published Maven poms. */
63+
val overrideIssueManagement = objectFactory.property<String>()
64+
/** Prefix for the tag published for non-SNAPSHOT versions in the Maven poms. */
65+
val overrideTagPrefix = objectFactory.property<String>()
66+
67+
/** The published distributables, including the source tarball, base file name. */
4268
val baseName =
4369
objectFactory
4470
.property<String>()
45-
.convention(project.provider { "apache-${asfProjectName.get()}-${project.version}" })
71+
.convention(project.provider { "apache-${asfProjectId.get()}-${project.version}" })
72+
4673
val distributionDir =
4774
objectFactory.directoryProperty().convention(project.layout.buildDirectory.dir("distributions"))
4875
val sourceTarball =
4976
objectFactory
5077
.fileProperty()
5178
.convention(project.provider { distributionDir.get().file("${baseName.get()}.tar.gz") })
5279

80+
/** List of mailing-lists. */
5381
val mailingLists = objectFactory.listProperty(String::class.java).convention(emptyList())
5482

5583
fun distributionFile(ext: String): File =

build-logic/src/main/kotlin/publishing/configurePom.kt

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import groovy.util.Node
2323
import org.gradle.api.Project
2424
import org.gradle.api.Task
2525
import org.gradle.api.artifacts.component.ModuleComponentSelector
26+
import org.gradle.api.provider.Provider
2627
import org.gradle.api.publish.maven.MavenPom
2728
import org.gradle.api.publish.maven.MavenPublication
2829
import org.gradle.internal.extensions.stdlib.capitalized
@@ -73,7 +74,7 @@ internal fun configurePom(project: Project, mavenPublication: MavenPublication,
7374

7475
task.doFirst {
7576
mavenPom.run {
76-
val asfName = e.asfProjectName.get()
77+
val asfName = e.asfProjectId.get()
7778
val projectPeople = fetchProjectPeople(asfName)
7879

7980
organization {
@@ -98,21 +99,35 @@ internal fun configurePom(project: Project, mavenPublication: MavenPublication,
9899
}
99100
}
100101

102+
val githubRepoName: Provider<String> = e.githubRepositoryName.orElse(asfName)
103+
val codeRepo: Provider<String> =
104+
e.overrideScm.orElse(
105+
githubRepoName
106+
.map { r -> "https://github.com/apache/$r" }
107+
.orElse(projectPeople.repository)
108+
)
109+
101110
scm {
102-
val codeRepo: String = projectPeople.repository
103-
connection.set("scm:git:$codeRepo")
104-
developerConnection.set("scm:git:$codeRepo")
105-
url.set("$codeRepo/tree/main")
111+
val codeRepoString: String = codeRepo.get()
112+
connection.set("scm:git:$codeRepoString")
113+
developerConnection.set("scm:git:$codeRepoString")
114+
url.set("$codeRepoString/tree/main")
106115
val version = project.version.toString()
107116
if (!version.endsWith("-SNAPSHOT")) {
108-
tag.set("apache-polaris-$version")
117+
val tagPrefix: String =
118+
e.overrideTagPrefix.orElse("apache-${projectPeople.apacheId}").get()
119+
tag.set("$tagPrefix-$version")
109120
}
110121
}
111-
issueManagement { url.set(projectPeople.bugDatabase) }
122+
issueManagement {
123+
val issuesUrl: Provider<String> =
124+
codeRepo.map { r -> "$r/issues" }.orElse(projectPeople.bugDatabase)
125+
url.set(e.overrideIssueManagement.orElse(issuesUrl))
126+
}
112127

113-
name.set(e.overrideName.orElse(projectPeople.name))
128+
name.set(e.overrideName.orElse("Apache ${projectPeople.name}"))
114129
description.set(e.overrideDescription.orElse(projectPeople.description))
115-
url.set(projectPeople.website)
130+
url.set(e.overrideProjectUrl.orElse(projectPeople.website))
116131
inceptionYear.set(projectPeople.inceptionYear.toString())
117132

118133
developers {
@@ -127,7 +142,7 @@ internal fun configurePom(project: Project, mavenPublication: MavenPublication,
127142
}
128143
}
129144

130-
addContributorsToPom(mavenPom, asfName, "Apache ${projectPeople.name}")
145+
addContributorsToPom(mavenPom, githubRepoName.get(), "Apache ${projectPeople.name}")
131146
}
132147
}
133148
}

build-logic/src/main/kotlin/publishing/rootProject.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ internal fun configureOnRootProject(project: Project) =
9696

9797
doFirst {
9898
val e = project.extensions.getByType(PublishingHelperExtension::class.java)
99-
val asfName = e.asfProjectName.get()
99+
val asfName = e.asfProjectId.get()
100100

101101
val gitInfo = MemoizedGitInfo.gitInfo(rootProject)
102102
val gitCommitId = gitInfo["Apache-Polaris-Build-Git-Head"]
@@ -132,7 +132,8 @@ internal fun configureOnRootProject(project: Project) =
132132
"NO STAGING REPOSITORY (no build service) !!"
133133
}
134134

135-
val asfProjectName = "Apache Polaris"
135+
val asfProjectName =
136+
e.overrideName.orElse(project.provider { "Apache ${fetchAsfProjectName(asfName)}" }).get()
136137

137138
val versionNoRc = version.toString().replace("-rc-?[0-9]+".toRegex(), "")
138139

build-logic/src/main/kotlin/publishing/util.kt

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ internal fun <T : Any> parseJson(url: String): T {
7979
}
8080
}
8181

82-
// TODO: this function doesn't work because name attribute doesn't exist on
83-
// public_ldap_projects.json
82+
/** Retrieves the project name, for example `Polaris` using the lower-case project ID. */
8483
internal fun fetchAsfProjectName(apacheId: String): String {
8584
val projectsAll: Map<String, Map<String, Any>> =
8685
parseJson("https://whimsy.apache.org/public/public_ldap_projects.json")
@@ -90,7 +89,25 @@ internal fun fetchAsfProjectName(apacheId: String): String {
9089
?: throw IllegalArgumentException(
9190
"No project '$apacheId' found in https://whimsy.apache.org/public/public_ldap_projects.json"
9291
)
93-
return project["name"] as String
92+
val isPodlingCurrent = project.containsKey("podling") && project["podling"] == "current"
93+
if (isPodlingCurrent) {
94+
val podlingsAll: Map<String, Map<String, Any>> =
95+
parseJson("https://whimsy.apache.org/public/public_podlings.json")
96+
val podlings = unsafeCast<Map<String, Map<String, Any>>>(podlingsAll["podling"])
97+
val podling =
98+
podlings[apacheId]
99+
?: throw IllegalArgumentException(
100+
"No podling '$apacheId' found in https://whimsy.apache.org/public/public_podlings.json"
101+
)
102+
return podling["name"] as String
103+
} else {
104+
// top-level-project
105+
val committeesAll: Map<String, Map<String, Any>> =
106+
parseJson("https://whimsy.apache.org/public/committee-info.json")
107+
val committees = unsafeCast<Map<String, Map<String, Any>>>(committeesAll["committees"])
108+
val committee = unsafeCast<Map<String, Any>>(committees[apacheId])
109+
return committee["display_name"] as String
110+
}
94111
}
95112

96113
internal fun fetchProjectPeople(apacheId: String): ProjectPeople {
@@ -146,6 +163,7 @@ internal fun fetchProjectPeople(apacheId: String): ProjectPeople {
146163
val mentors = unsafeCast(podling["mentors"]) as List<String>
147164
mentors.forEach { member -> peopleProjectRoles[member]!!.add("Mentor") }
148165
} else {
166+
// top-level-project
149167
val tlpPrj: Map<String, Any> =
150168
parseJson("https://projects.apache.org/json/projects/$apacheId.json")
151169
website = tlpPrj["homepage"] as String

0 commit comments

Comments
 (0)