GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [improve][build] Add Dependabot configuration and an updateBinaryLice… · apache/pulsar@017cc73

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github
    • dependabot.yml
  • ARCHITECTURE.md
  • CONTRIBUTING.md
  • build-logic/conventions/src
    • main/kotlin
      • BinaryLicenseSupport.kt
      • CheckBinaryLicenseTask.kt
      • UpdateBinaryLicenseTask.kt
      • pulsar.binary-license-check-conventions.gradle.kts
    • test/kotlin
      • BinaryLicenseSupportTest.kt
  • build.gradle.kts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/dependabot.yml‎

Copy file name to clipboard
+73Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
# Patch updates only for the Gradle build: minor and major upgrades of the versions in
21+
# gradle/libs.versions.toml are made deliberately, because they can affect compatibility
22+
# and the release notes of Pulsar.
23+
#
24+
# A Gradle update usually changes the jars that the binary distributions bundle, which fails
25+
# checkBinaryLicense in CI. A committer updates the pull request with:
26+
# ./gradlew updateBinaryLicense && ./gradlew checkBinaryLicense
27+
# and pushes the LICENSE/NOTICE changes to the Dependabot branch.
28+
#
29+
# The commit message prefixes end with a space, so that Dependabot does not add a colon
30+
# after them and the pull request titles match the [type][scope] format that
31+
# .github/workflows/ci-semantic-pull-request.yml checks.
32+
#
33+
# An update of gradle/actions can only run after its commit is in
34+
# https://github.com/apache/infrastructure-actions/blob/main/approved_patterns.yml
35+
36+
version: 2
37+
updates:
38+
- package-ecosystem: gradle
39+
directory: "/"
40+
schedule:
41+
interval: daily
42+
cooldown:
43+
default-days: 7
44+
open-pull-requests-limit: 10
45+
commit-message:
46+
prefix: "[improve][build] "
47+
ignore:
48+
- dependency-name: "*"
49+
update-types:
50+
- version-update:semver-major
51+
- version-update:semver-minor
52+
groups:
53+
# OpenTelemetry releases each *-alpha artifact together with its stable line, at the same
54+
# version plus "-alpha" (opentelemetry and opentelemetry-alpha, and
55+
# opentelemetry-instrumentation and opentelemetry-instrumentation-alpha in
56+
# gradle/libs.versions.toml). Updating them in one pull request keeps the versions in sync;
57+
# the root build.gradle.kts fails when they differ.
58+
opentelemetry:
59+
patterns:
60+
- "io.opentelemetry:*"
61+
- "io.opentelemetry.instrumentation:*"
62+
63+
# The composite actions in .github/actions also reference actions
64+
- package-ecosystem: github-actions
65+
directories:
66+
- "/"
67+
- "/.github/actions/*"
68+
schedule:
69+
interval: weekly
70+
cooldown:
71+
default-days: 7
72+
commit-message:
73+
prefix: "[improve][ci] "
Collapse file

‎ARCHITECTURE.md‎

Copy file name to clipboardExpand all lines: ARCHITECTURE.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ When editing `build-logic/`, `settings.gradle.kts`, a module `build.gradle.kts`,
166166
would be unresolvable from Maven Central. A module is published only when it applies
167167
`pulsar.public-java-library-conventions`.
168168
- **After a dependency change**, run `./gradlew checkBinaryLicense` and update the distribution
169-
`LICENSE`/`NOTICE`; justify any genuinely new dependency (see
169+
`LICENSE`/`NOTICE` (`./gradlew updateBinaryLicense` updates the versions of the jars they reference); justify any genuinely new dependency (see
170170
[`CODING.md` → Dependencies](CODING.md#dependencies)).
171171
- **Follow the [Gradle best practices](https://docs.gradle.org/current/userguide/best_practices_index.html)**
172172
— AI agents should read the
Collapse file

‎CONTRIBUTING.md‎

Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+2Lines changed: 2 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ Gradle's build-JDK requirement. Use `-PtestJavaVersion=17` as well to run ordina
8282

8383
# Verify bundled-dependency LICENSE/NOTICE coverage (after changing a runtime dependency)
8484
./gradlew checkBinaryLicense
85+
# Update the jar versions in the distribution LICENSE/NOTICE files after a dependency upgrade
86+
./gradlew updateBinaryLicense
8587

8688
# Start a standalone Pulsar service (broker + bookie + metadata in one JVM)
8789
bin/pulsar standalone
Collapse file

‎build-logic/conventions/src/main/kotlin/BinaryLicenseSupport.kt‎

Copy file name to clipboard
+175Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import org.gradle.api.GradleException
21+
import org.gradle.api.file.ArchiveOperations
22+
import java.io.File
23+
24+
/** The jars bundled in a binary distribution tarball and the LICENSE and NOTICE it ships. */
25+
internal class BinaryDistributionContents(
26+
val bundledJars: Set<String>,
27+
val license: String,
28+
val notice: String,
29+
)
30+
31+
/**
32+
* The rules shared by [CheckBinaryLicenseTask] and [UpdateBinaryLicenseTask], so that the update
33+
* task produces exactly what the check task accepts.
34+
*/
35+
internal object BinaryLicenseSupport {
36+
private val licenseEntryRegex = Regex("^[^/]+/LICENSE$")
37+
private val noticeEntryRegex = Regex("^[^/]+/NOTICE$")
38+
private val nameExclusionSubstrings = listOf(
39+
"pulsar-client",
40+
"pulsar-cli-utils",
41+
"pulsar-common",
42+
"pulsar-http-client-api",
43+
"pulsar-package",
44+
"pulsar-tls-factory-api",
45+
"pulsar-websocket",
46+
)
47+
48+
/** The NOTICE reference that does not need to be bundled. */
49+
const val NOTICE_EXEMPT_JAR = "checker-qual.jar"
50+
51+
private val jarReferenceRegex = Regex(""".* (.*\.jar).*""")
52+
private const val JAR_NAME_CHARS = "A-Za-z0-9_.+-"
53+
private val digitRunRegex = Regex("""\d+""")
54+
55+
fun readDistribution(archiveOperations: ArchiveOperations, tarFile: File): BinaryDistributionContents {
56+
val bundledJars = sortedSetOf<String>()
57+
var licenseContent: String? = null
58+
var noticeContent: String? = null
59+
60+
archiveOperations.tarTree(tarFile).visit {
61+
if (isDirectory) return@visit
62+
val path = relativePath.pathString
63+
when {
64+
path.endsWith(".jar") -> {
65+
val inExcludedDir = path.contains("/examples/") || path.contains("/instances/")
66+
val nameExcluded = nameExclusionSubstrings.any { name.contains(it) }
67+
if (!inExcludedDir && !nameExcluded) {
68+
bundledJars.add(name)
69+
}
70+
}
71+
licenseEntryRegex.matches(path) -> licenseContent = file.readText()
72+
noticeEntryRegex.matches(path) -> noticeContent = file.readText()
73+
}
74+
}
75+
76+
return BinaryDistributionContents(
77+
bundledJars,
78+
licenseContent
79+
?: throw GradleException("Could not find a top-level LICENSE entry in ${tarFile.name}"),
80+
noticeContent
81+
?: throw GradleException("Could not find a top-level NOTICE entry in ${tarFile.name}"),
82+
)
83+
}
84+
85+
/** The jar referenced on each line of a LICENSE or NOTICE text: the last one on the line. */
86+
fun extractJarReferences(content: String): List<String> =
87+
content.lines().mapNotNull { line -> jarReferenceRegex.matchEntire(line)?.groupValues?.get(1) }
88+
89+
/** Whether LICENSE has to mention [jar]; the Pulsar jars themselves need no entry. */
90+
fun needsLicenseEntry(jar: String): Boolean = !jar.contains("org.apache.pulsar")
91+
92+
/**
93+
* Whether a LICENSE or NOTICE reference matches a bundled jar. A reference may contain
94+
* wildcards like "org.rocksdb.*.jar", so it is treated as a regex, matching the legacy bash
95+
* `grep -q $J` semantics.
96+
*/
97+
fun isBundled(reference: String, bundledJars: Collection<String>): Boolean {
98+
val pattern = Regex(reference)
99+
return bundledJars.any { pattern.containsMatchIn(it) }
100+
}
101+
102+
/** Replaces each whole-word occurrence of a key of [renames] in [content] with its value. */
103+
fun replaceJarNames(content: String, renames: Map<String, String>): String =
104+
renames.entries.fold(content) { text, (from, to) ->
105+
Regex("(?<![$JAR_NAME_CHARS])${Regex.escape(from)}(?![$JAR_NAME_CHARS])")
106+
.replace(text, Regex.escapeReplacement(to))
107+
}
108+
109+
/**
110+
* Pairs each [stale] reference, which no longer matches a bundled jar, with the jar in
111+
* [candidates] that is the same artifact at another version.
112+
*
113+
* A candidate is the same artifact when both names share a prefix that ends with "-" and is
114+
* followed by a digit in both, as in "netty-codec-" + "4.2.20.Final.jar". Of these, the
115+
* candidate whose remainder has the same shape, with each run of digits treated as equal, is
116+
* chosen, which keeps classifiers apart: "...-4.2.21.Final-linux-x86_64.jar" replaces
117+
* "...-4.2.20.Final-linux-x86_64.jar" and not "...-4.2.20.Final-linux-aarch_64.jar". When no
118+
* candidate has the same shape, as when "1.80.jar" becomes "1.80.1.jar", a single candidate
119+
* is still taken. Anything else is left for a human to resolve.
120+
*/
121+
fun matchVersionChanges(stale: Collection<String>, candidates: Collection<String>): JarVersionMatches {
122+
val chosen = mutableMapOf<String, String>()
123+
val ambiguous = mutableMapOf<String, List<String>>()
124+
val unmatched = mutableListOf<String>()
125+
126+
for (reference in stale) {
127+
val sameArtifact = candidates.mapNotNull { jar ->
128+
versionStart(reference, jar)?.let { start -> jar to start }
129+
}
130+
val sameShape = sameArtifact.filter { (jar, start) ->
131+
shape(reference.substring(start)) == shape(jar.substring(start))
132+
}
133+
val match = sameShape.singleOrNull() ?: if (sameShape.isEmpty()) sameArtifact.singleOrNull() else null
134+
when {
135+
match != null -> chosen[reference] = match.first
136+
sameArtifact.isEmpty() -> unmatched.add(reference)
137+
else -> ambiguous[reference] = (sameShape.ifEmpty { sameArtifact }).map { it.first }
138+
}
139+
}
140+
141+
// A jar can replace only one reference; when several claim it, a human has to decide.
142+
val claimedTwice = chosen.values.groupingBy { it }.eachCount().filterValues { it > 1 }.keys
143+
val renames = chosen.filterValues { it !in claimedTwice }
144+
chosen.filterValues { it in claimedTwice }.forEach { (reference, jar) -> ambiguous[reference] = listOf(jar) }
145+
146+
return JarVersionMatches(renames, ambiguous, unmatched)
147+
}
148+
149+
/**
150+
* The length of the longest shared prefix of [a] and [b] that ends with "-" and is followed
151+
* by a digit in both, or null when there is none.
152+
*/
153+
private fun versionStart(a: String, b: String): Int? {
154+
if (a == b) return null
155+
val common = a.commonPrefixWith(b).length
156+
for (i in common downTo 1) {
157+
if (a[i - 1] == '-' && i < a.length && i < b.length && a[i].isDigit() && b[i].isDigit()) {
158+
return i
159+
}
160+
}
161+
return null
162+
}
163+
164+
private fun shape(versionAndRest: String): String = digitRunRegex.replace(versionAndRest, "#")
165+
}
166+
167+
/**
168+
* The result of [BinaryLicenseSupport.matchVersionChanges]: the [renames] to apply, the
169+
* references with several possible replacements, and the references that match no candidate.
170+
*/
171+
internal data class JarVersionMatches(
172+
val renames: Map<String, String>,
173+
val ambiguous: Map<String, List<String>>,
174+
val unmatched: List<String>,
175+
)

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.