]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15485 handle Elastic license and prettify json
authorZipeng WU <zipeng.wu@sonarsource.com>
Mon, 25 Oct 2021 11:33:30 +0000 (13:33 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 26 Oct 2021 20:03:36 +0000 (20:03 +0000)
sonar-application/build.gradle

index 578835e42da9907c8d725f46d225c94ba318b2d8..2a70c75b0a41efb0b95dff4e0ebb013bc2becb7a 100644 (file)
@@ -1,3 +1,5 @@
+import groovy.json.JsonOutput
+import groovy.json.JsonSlurper
 import org.apache.tools.ant.filters.ReplaceTokens
 
 plugins {
@@ -104,6 +106,20 @@ task zip(type: Zip, dependsOn: [configurations.compileClasspath, tasks.downloadL
   into("${archiveDir}/") {
     from(tasks.downloadLicenses.outputs) {
       include 'dependency-license.json'
+      eachFile { jsonFile ->
+        def json = new JsonSlurper().parse(jsonFile.file)
+        json.dependencies.each { dependency ->
+          if (dependency.licenses.size() > 1) {
+            def idx = dependency.licenses.findIndexOf { it.name == "Elastic License 2.0" }
+            if (idx >= 0) {
+              dependency.licenses = [dependency.licenses[idx]]
+            }
+          }
+        }
+        json.dependencies.sort { it.name }
+        def jsonText = JsonOutput.toJson(json)
+        jsonFile.file.text = JsonOutput.prettyPrint(jsonText)
+      }
     }
     from(file('src/main/assembly')) {
       exclude 'conf/sonar.properties'
@@ -178,7 +194,7 @@ task zip(type: Zip, dependsOn: [configurations.compileClasspath, tasks.downloadL
             'sqversion': version
     ])
   }
-  
+
   into("${archiveDir}/elasticsearch/") {
     from file('src/main/assembly/elasticsearch-patch')
       include 'bin/elasticsearch'