You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LicenseReader.groovy 738B

1234567891011121314151617181920212223242526272829
  1. package org.sonar.build
  2. import groovy.json.JsonOutput
  3. import groovy.json.JsonSlurper
  4. class LicenseReader extends FilterReader {
  5. LicenseReader(Reader fileReader) {
  6. super(build(fileReader))
  7. }
  8. private static Reader build(Reader fileReader) {
  9. def json = new JsonSlurper().parse(fileReader)
  10. json.dependencies.each { dependency ->
  11. if (dependency.licenses.size() > 1) {
  12. def idx = dependency.licenses.findIndexOf { it.name == "Elastic License 2.0" }
  13. if (idx >= 0) {
  14. dependency.licenses = [dependency.licenses[idx]]
  15. }
  16. }
  17. }
  18. json.dependencies.sort { it.name }
  19. def jsonText = JsonOutput.toJson(json)
  20. return new StringReader(JsonOutput.prettyPrint(jsonText))
  21. }
  22. }