Skip to content

Instantly share code, notes, and snippets.

@VadimKirilchuk
Created July 25, 2013 10:46
Show Gist options
  • Save VadimKirilchuk/6078634 to your computer and use it in GitHub Desktop.
Save VadimKirilchuk/6078634 to your computer and use it in GitHub Desktop.
Outputs difference between two java property files. Using just diff is not enough because properties can have different order, duplicated or commented,
if (this.args.length < 2) { throw new IllegalArgumentException("Please, give path to baseline properties and path to other properties")}
def excludeList = [/log4j\./]
File baseline = this.args[0] as File
File other = this.args[1] as File
Properties baselineProps = new Properties()
baseline.withInputStream { stream -> baselineProps.load(stream) }
Properties otherProps = new Properties()
other.withInputStream { stream -> otherProps.load(stream) }
baselineProps.each { key, value ->
if (excludeList.find { key =~ it }) { return }
def otherValue = otherProps.get(key)
if (!otherProps.containsKey(key)) {
println "- ${key}=${value}"
} else if (otherValue != value) {
println "! ${key}=[${value} | ${otherValue}]"
}
}
otherProps.each { key, value ->
if (excludeList.find { key =~ it }) { return }
if (!baselineProps.containsKey(key)) {
println "+ ${key}=${value}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment