aboutsummaryrefslogtreecommitdiffstats
path: root/buildSrc/src/main/groovy/org.sonar.build/LicenseReader.groovy
blob: cb611e90497e98f1ae5951b2d4a055b3445dbecc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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))
  }
}