Skip to content

Commit

Permalink
function to download and skipLicenses property
Browse files Browse the repository at this point in the history
  • Loading branch information
vcarluer committed Jun 27, 2023
1 parent e2e5a77 commit f3166a4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
42 changes: 25 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,26 @@ var licenseReportDir = "$projectDir/doc/licenses"

val configBuildDir = "$buildDir/config"
mkdir(configBuildDir)
val normalizerLocalPath = "$configBuildDir/license-normalizer-bundle.json"
val fn = file(normalizerLocalPath); uri("https://raw.githubusercontent.com/Cosmo-Tech/cosmotech-license/main/config/license-normalizer-bundle.json").toURL().openStream().use { it.copyTo(
FileOutputStream(fn)
) }
val allowedPath = "$configBuildDir/allowed-licenses.json"
val fa = file(allowedPath); uri("https://raw.githubusercontent.com/Cosmo-Tech/cosmotech-license/main/config/allowed-licenses.json").toURL().openStream().use { it.copyTo(
FileOutputStream(fa)
) }

fun downloadLicenseConfigFile(name: String): String {
val localPath = "$configBuildDir/$name"
val f = file(localPath)
f.delete()
uri("https://raw.githubusercontent.com/Cosmo-Tech/cosmotech-license/main/config/$name").toURL().openStream().use { it.copyTo(
FileOutputStream(f)
) }
return localPath
}

val licenseNormalizerPath = downloadLicenseConfigFile("license-normalizer-bundle.json")
val licenseAllowedPath = downloadLicenseConfigFile("allowed-licenses.json")
val licenseEmptyPath = downloadLicenseConfigFile("empty-dependencies-resume.json")

licenseReport {
outputDir = licenseReportDir
allowedLicensesFile = file(allowedPath)
allowedLicensesFile = file(licenseAllowedPath)
renderers = arrayOf<ReportRenderer>(InventoryHtmlReportRenderer("index.html"), JsonReportRenderer("report.json"))
filters = arrayOf<LicenseBundleNormalizer>(LicenseBundleNormalizer(normalizerLocalPath, true))
filters = arrayOf<LicenseBundleNormalizer>(LicenseBundleNormalizer(licenseNormalizerPath, true))
}

allprojects {
Expand Down Expand Up @@ -540,25 +546,27 @@ tasks.register<CheckLicenseTask>("validateLicense") {

tasks.withType<KotlinCompile> {
// Run licensing tasks before compiling
dependsOn("generateLicenseDoc")
if (project.properties["skipLicenses"] != "true") {
dependsOn("generateLicenseDoc")
}
}

tasks.register("displayLicensesNotAllowed") {
val notAllowedFile = file(buildString {
append(licenseReportDir)
append("/dependencies-without-allowed-license.json")
})
val dependenciesEmptyResumeTemplate = file(buildString {
append(licenseReportDir)
append("/empty-dependencies-resume.json")
})
val dependenciesEmptyResumeTemplate = file(licenseEmptyPath)
if (notAllowedFile.readText() != dependenciesEmptyResumeTemplate.readText()) {
println("Licenses not allowed:")
println(notAllowedFile.readText())
println("Please review licenses and add new license check rules in https://github.com/Cosmo-Tech/cosmotech-license")
}
}

gradle.buildFinished {
val displayTask = tasks.getByName("displayLicensesNotAllowed")
displayTask.run {}
if (project.properties["skipLicenses"] != "true") {
val displayTask = tasks.getByName("displayLicensesNotAllowed")
displayTask.run {}
}
}
5 changes: 0 additions & 5 deletions doc/licenses/empty-dependencies-resume.json

This file was deleted.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ org.gradle.parallel=true

org.gradle.jvmargs=-Xmx2g

detekt.ignoreFailures=false
detekt.ignoreFailures=false

0 comments on commit f3166a4

Please sign in to comment.