Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Pil0tXia committed Apr 12, 2024
1 parent 41c9d22 commit 3e999f7
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,14 @@ cyclonedxBom {

// TODO depend 'dist' on 'generateDistLicense'
tasks.register('generateDistLicense') {
dependsOn('cyclonedxBom')
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 = new File('tools/third-party-licenses/LICENSE')
def licensesDir = new File('tools/third-party-licenses/licenses/java/')
if (licensesDir.exists()) {
Expand All @@ -231,12 +234,10 @@ tasks.register('generateDistLicense') {
licensesDir.mkdirs()
}

def projectLicenseText = file('LICENSE').text
def distLicenseText = projectLicenseText + "\n=======================================================================\n" +
"This distribution contains the following third-party:\n\n"

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) {
Expand All @@ -257,7 +258,6 @@ tasks.register('generateDistLicense') {
}
}
}

thirdPartyArtifacts.sort { a, b ->
def nameComparison = a.name <=> b.name
if (nameComparison == 0) {
Expand All @@ -266,14 +266,19 @@ tasks.register('generateDistLicense') {
return nameComparison
}
}

def distLicenseText = projectLicenseText + "\n=======================================================================\n" +
"This distribution contains the following third-party:\n\n"
thirdPartyArtifacts.each { artifact ->
// Write licenses
def artifactLicenseFile = new File(licensesDir, "${artifact.license}.txt")
if (artifact.licenseContent != null) {
artifactLicenseFile.text = artifact.licenseContent
} else {
artifactLicenseFile.text = "No license content provided by the artifact."
}

// Assemble LICENSE
distLicenseText += "${artifact.name} ${artifact.version} licensed under '${artifact.license}'. For details see: licenses/${artifact.license}.txt\n"
}
distLicenseFile.text = distLicenseText
Expand All @@ -282,16 +287,19 @@ tasks.register('generateDistLicense') {

// TODO depend 'dist' on 'generateDistNotice'
tasks.register('generateDistNotice') {
dependsOn('generateLicenseReport')
dependsOn('generateLicenseReport') // Task from 'com.github.jk1.dependency-license-report' plugin
doLast {
def reportsDir = new File('build/reports/dependency-license')
// Inputs
def reportsDir = new File('build/reports/dependency-license/')
def projectNoticeText = file('NOTICE').text

// Outputs
def distNoticeFile = new File('tools/third-party-licenses/NOTICE')

def distNoticeText = projectNoticeText
reportsDir.eachDir { dir ->
dir.eachFileRecurse (groovy.io.FileType.FILES) { file ->
// Find NOTICE files
if (file.name.length() >= 6 && file.name.substring(0, 6).equalsIgnoreCase("NOTICE")) {
def artifactName = dir.name.replace(".jar", "")
distNoticeText += "\n=======================================================================\n\n" +
Expand Down

0 comments on commit 3e999f7

Please sign in to comment.