Dev Note Gradle Groovy

DEV-NOTES|Gradle: Reading Eclipses codeformatter xml file

This little code snippet transforms the code formatter XML description file into a properties structure which could be applied to the JDT properties later on.

def initializeFormatter() {
  def formatterDefinitions = new XmlSlurper.parse("$rootDir/misc/codeformatter.xml")
  assert formatterDefinitions instanceof GPathResult

  def Properties props = new Properties()

  formatterDefinitions.'**'.findAll{ node ->
    node.name() == 'setting'
  }*.each { n ->
    props.put(n.@id.text(), n.@value.text()

  return props