]> source.dussan.org Git - sonarqube.git/commitdiff
Optimize gradle build to use the incremental build feature
authorOlaf Śnieżek <osniezek@gradle.com>
Thu, 17 Nov 2022 11:53:52 +0000 (12:53 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 14 Feb 2023 20:02:48 +0000 (20:02 +0000)
buildSrc/src/main/groovy/org.sonar.build/LicenseReader.groovy [new file with mode: 0644]
sonar-application/build.gradle

diff --git a/buildSrc/src/main/groovy/org.sonar.build/LicenseReader.groovy b/buildSrc/src/main/groovy/org.sonar.build/LicenseReader.groovy
new file mode 100644 (file)
index 0000000..cb611e9
--- /dev/null
@@ -0,0 +1,29 @@
+package org.sonar.build
+
+import groovy.json.JsonOutput
+import groovy.json.JsonSlurper
+
+class LicenseReader extends FilterReader {
+
+  LicenseReader(Reader fileReader) {
+    super(build(fileReader))
+  }
+
+  private static Reader build(Reader fileReader) {
+    def json = new JsonSlurper().parse(fileReader)
+
+    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)
+    return new StringReader(JsonOutput.prettyPrint(jsonText))
+  }
+}
index d6da1f90227a380d40f56637fb919bb73e4a6b37..54e2ac87de79bc3d477b5fd6af6c8f9404efaf0c 100644 (file)
@@ -1,6 +1,5 @@
-import groovy.json.JsonOutput
-import groovy.json.JsonSlurper
 import org.apache.tools.ant.filters.ReplaceTokens
+import org.sonar.build.LicenseReader
 
 plugins {
   id "com.github.hierynomus.license-report"
@@ -133,20 +132,7 @@ task zip(type: Zip, dependsOn: [configurations.compileClasspath, downloadElastic
     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)
-        }
+        filter(LicenseReader)
       }
     }
   }
@@ -275,7 +261,11 @@ task zip(type: Zip, dependsOn: [configurations.compileClasspath, downloadElastic
   }
   // Create the empty dir (plugins) required by elasticsearch
   into("${archiveDir}/elasticsearch/") {
-    from "$buildDir/elasticsearch"
+    // Create the empty dir required by elasticsearch
+    from {
+      new File(buildDir, 'elasticsearch/plugins').mkdirs()
+      "$buildDir/elasticsearch"
+    }
   }
   into("${archiveDir}/lib/extensions/") {
     from configurations.bundledPlugin
@@ -315,10 +305,7 @@ task zip(type: Zip, dependsOn: [configurations.compileClasspath, downloadElastic
     from configurations.shutdowner
   }
 }
-// Create the empty dir required by elasticsearch
-zip.doFirst {
-  new File(buildDir, 'elasticsearch/plugins').mkdirs()
-}
+
 // Check the size of the archive
 zip.doLast {
   def minLength = 320000000