bharos commented on code in PR #13257:
URL: https://github.com/apache/gravitino/pull/13257#discussion_r4065120606


##########
build.gradle.kts:
##########
@@ -72,6 +81,230 @@ val sharedTestEnvironmentLock = 
gradle.sharedServices.registerIfAbsent(
   maxParallelUsages.set(1)
 }
 
+/** Packages the legal documents for one Maven artifact, retaining dependency 
provenance. */
+@CacheableTask
+abstract class GenerateJarLegalFiles : DefaultTask() {
+  companion object {
+    private const val LICENSE_INVENTORY = "\nBundled component licensing:\n"
+    private const val NOTICE_INVENTORY = "\nBundled component notices:\n"
+    private val noticeFileName = 
Regex("(?i)([A-Za-z0-9_]+-)*NOTICES?([.-].*)?")
+    private val legalFileName = Regex(
+      
"(?i)([A-Za-z0-9_]+-)*(LICENSE|LICENCE|NOTICES?|COPYING|COPYRIGHT)(-[A-Za-z0-9_-]+)?(\\.(txt|md|markdown|adoc))?"
+    )
+
+    /** Selects legal resources without mistaking SDK models such as 
license-manager.json for licenses. */
+    fun isLegalResource(path: String): Boolean =
+      path == "about.html" || path.startsWith("about_files/") ||
+        path.startsWith("licenses/") || path.startsWith("license/") ||
+        path.startsWith("META-INF/licenses/") || 
path.startsWith("META-INF/license/") ||
+        path.startsWith("META-INF/licenses-binary/") ||
+        legalFileName.matches(path.substringAfterLast('/'))
+  }
+
+  @get:Internal
+  abstract val templates: DirectoryProperty
+
+  @get:InputFiles
+  @get:PathSensitive(PathSensitivity.RELATIVE)
+  val templateFiles: FileTree
+    get() = templates.get().asFileTree
+
+  @get:Input
+  abstract val sourceNotices: ListProperty<String>
+
+  @get:InputFiles
+  @get:PathSensitive(PathSensitivity.NONE)
+  abstract val dependencyJars: ConfigurableFileCollection
+
+  @get:Input
+  abstract val dependencyIds: MapProperty<String, String>
+
+  @get:Input
+  abstract val excludedGroups: SetProperty<String>
+
+  @get:InputFiles
+  @get:PathSensitive(PathSensitivity.RELATIVE)
+  abstract val javadocFiles: ConfigurableFileCollection
+
+  @get:OutputFile
+  abstract val outputArchive: RegularFileProperty
+
+  init {
+    sourceNotices.convention(emptyList())
+    dependencyIds.convention(emptyMap())
+    excludedGroups.convention(emptySet())
+  }
+
+  @TaskAction
+  fun generate() {
+    val directory = templates.get().asFile
+    val ids = dependencyIds.get()
+    val excluded = excludedGroups.get()
+    // ByteBuffer compares byte contents, so identical documents are retained 
only once.
+    val documents = sortedMapOf<String, LinkedHashSet<ByteBuffer>>()
+    fun add(path: String, bytes: ByteArray) {
+      require(!path.startsWith('/') && path.split('/').none { it == ".." }) {
+        "Invalid legal resource path: $path"
+      }
+      val group = path.removePrefix("META-INF/licenses/").substringBefore('/')
+      if (path.startsWith("META-INF/licenses/") && group in excluded) return
+      documents.getOrPut(path) { linkedSetOf() }.add(ByteBuffer.wrap(bytes))
+    }
+    val overrides = mutableMapOf<String, String>()
+    directory.resolve("dependencies.txt").readLines()
+      .filter { it.isNotBlank() && !it.startsWith('#') }
+      .forEach { line ->
+        val fields = line.split('=', limit = 2)
+        require(fields.size == 2) { "Invalid Maven legal supplement: $line" }
+        require(overrides.put(fields[0], fields[1]) == null) { "Duplicate 
Maven legal supplement: ${fields[0]}" }
+      }
+    fun supplement(id: String): String {
+      val parts = id.split('/')
+      val coordinate = "${parts[0]}:${parts[1]}"
+      val selected = overrides["$coordinate:${parts[2]}"] ?: 
overrides[coordinate]
+      require(selected != null || overrides.keys.none { 
it.startsWith("$coordinate:") }) {
+        "Unaudited Maven legal supplement version: $coordinate:${parts[2]}. 
Review dependencies.txt and upstream legal documents."

Review Comment:
   Done—the error now includes the full Gradle task path alongside the 
dependency coordinate and version.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to