Pil0tXia commented on code in PR #4831:
URL: https://github.com/apache/eventmesh/pull/4831#discussion_r1568523894


##########
build.gradle:
##########
@@ -212,6 +212,107 @@ task printProjects() {
     })
 }
 
+cyclonedxBom {
+    includeConfigs = ["runtimeClasspath"]
+}
+
+// TODO depend 'dist' on 'generateDistLicense'
+tasks.register('generateDistLicense') {
+    dependsOn('cyclonedxBom') // Task from 'org.cyclonedx.bom' plugin
+    doLast {
+        // Inputs
+        def bomFile = file('build/reports/bom.json')
+        def bom = new JsonSlurper().parseText(bomFile.text)
+        def projectLicenseText = file('LICENSE').text
+
+        // Outputs
+        def distLicenseFile = file('tools/dist-license/LICENSE')
+        def licensesDir = file('tools/dist-license/licenses/java/')
+        if (licensesDir.exists()) {
+            licensesDir.eachFile { it.delete() }
+        } else {
+            licensesDir.mkdirs()
+        }
+
+        List<Map<String, String>> thirdPartyArtifacts = new 
ArrayList<Map<String, String>>()
+        // Parse BOM
+        bom.components.each { component ->
+            // Exclude project modules
+            if (!component.group.startsWith('org.apache.eventmesh')) {
+                component.licenses.each { artifactLicense ->
+                    if (artifactLicense.license != null) {
+                        Map<String, String> artifact = new HashMap<String, 
String>()
+                        artifact.put("name", component.name)
+                        artifact.put("version", component.version)
+                        if (artifactLicense.license.id != null) {
+                            artifact.put("license", artifactLicense.license.id)
+                            if (artifactLicense.license.text != null) {
+                                artifact.put("licenseContent", new 
String(artifactLicense.license.text.content.decodeBase64()))
+                            }
+                        } else {
+                            artifact.put("license", 
artifactLicense.license.name)
+                            artifact.put("licenseContent", 
artifactLicense.license.url)
+                        }
+                        thirdPartyArtifacts.add(artifact)
+                    }
+                }
+            }
+        }
+        thirdPartyArtifacts.sort { a, b ->
+            def nameComparison = a.name <=> b.name
+            if (nameComparison == 0) {
+                return a.version <=> b.version
+            } else {
+                return nameComparison
+            }
+        }
+
+        def distLicenseText = projectLicenseText + 
"\n=======================================================================\n" +
+                "This distribution contains the following third-party:\n\n"
+        thirdPartyArtifacts.each { artifact ->
+            // Write licenses
+            def artifactLicenseFilename = artifact.license.replaceAll("/", 
"-") + ".txt"
+            def artifactLicenseFile = new File(licensesDir, 
artifactLicenseFilename)
+            if (artifact.licenseContent != null) {
+                artifactLicenseFile.text = artifact.licenseContent
+            } else {
+                artifactLicenseFile.text = "No license content provided by the 
artifact."

Review Comment:
   There are too many allowed licenses, and even this way we still can't detect 
all license variants of all third-party artifacts. So I chose to deny licenses 
in https://github.com/apache/eventmesh/pull/4827.



##########
build.gradle:
##########
@@ -212,6 +212,107 @@ task printProjects() {
     })
 }
 
+cyclonedxBom {
+    includeConfigs = ["runtimeClasspath"]
+}
+
+// TODO depend 'dist' on 'generateDistLicense'
+tasks.register('generateDistLicense') {
+    dependsOn('cyclonedxBom') // Task from 'org.cyclonedx.bom' plugin
+    doLast {
+        // Inputs
+        def bomFile = file('build/reports/bom.json')
+        def bom = new JsonSlurper().parseText(bomFile.text)
+        def projectLicenseText = file('LICENSE').text
+
+        // Outputs
+        def distLicenseFile = file('tools/dist-license/LICENSE')
+        def licensesDir = file('tools/dist-license/licenses/java/')
+        if (licensesDir.exists()) {
+            licensesDir.eachFile { it.delete() }
+        } else {
+            licensesDir.mkdirs()
+        }
+
+        List<Map<String, String>> thirdPartyArtifacts = new 
ArrayList<Map<String, String>>()
+        // Parse BOM
+        bom.components.each { component ->
+            // Exclude project modules
+            if (!component.group.startsWith('org.apache.eventmesh')) {
+                component.licenses.each { artifactLicense ->
+                    if (artifactLicense.license != null) {
+                        Map<String, String> artifact = new HashMap<String, 
String>()
+                        artifact.put("name", component.name)
+                        artifact.put("version", component.version)
+                        if (artifactLicense.license.id != null) {
+                            artifact.put("license", artifactLicense.license.id)
+                            if (artifactLicense.license.text != null) {
+                                artifact.put("licenseContent", new 
String(artifactLicense.license.text.content.decodeBase64()))
+                            }
+                        } else {
+                            artifact.put("license", 
artifactLicense.license.name)
+                            artifact.put("licenseContent", 
artifactLicense.license.url)
+                        }
+                        thirdPartyArtifacts.add(artifact)
+                    }
+                }
+            }
+        }
+        thirdPartyArtifacts.sort { a, b ->
+            def nameComparison = a.name <=> b.name
+            if (nameComparison == 0) {
+                return a.version <=> b.version
+            } else {
+                return nameComparison
+            }
+        }
+
+        def distLicenseText = projectLicenseText + 
"\n=======================================================================\n" +
+                "This distribution contains the following third-party:\n\n"
+        thirdPartyArtifacts.each { artifact ->
+            // Write licenses
+            def artifactLicenseFilename = artifact.license.replaceAll("/", 
"-") + ".txt"
+            def artifactLicenseFile = new File(licensesDir, 
artifactLicenseFilename)
+            if (artifact.licenseContent != null) {
+                artifactLicenseFile.text = artifact.licenseContent
+            } else {
+                artifactLicenseFile.text = "No license content provided by the 
artifact."

Review Comment:
   There are too many allowed licenses, and even this way we still can't detect 
all license variants of third-party artifacts. So I chose to deny licenses in 
https://github.com/apache/eventmesh/pull/4827.



-- 
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: issues-unsubscr...@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@eventmesh.apache.org
For additional commands, e-mail: issues-h...@eventmesh.apache.org

Reply via email to