Skip to content

Instantly share code, notes, and snippets.

@marcgeld
Created June 26, 2017 09:03
Show Gist options
  • Save marcgeld/91b36e083a9aa036bb709f0a56138be6 to your computer and use it in GitHub Desktop.
Save marcgeld/91b36e083a9aa036bb709f0a56138be6 to your computer and use it in GitHub Desktop.
Compare jar-file versions in two folders
#!/usr/bin/env groovy
import groovy.io.FileType
def printelnerr = System.err.&println
def appName = this.getClass().getName()
def cli = new CliBuilder( usage:"${appName} --basedir <path_to_dir> --intersectdir <path_to_dir> " )
cli.with {
b( longOpt: 'basedir', 'path to directory with jars (Original)', args: 1, required: true )
i( longOpt: 'intersectdir', 'path to directory with jars (Compare)', args: 1, required: true )
h( longOpt: 'help', 'Print help', required: false )
}
def options = cli.parse(args)
if (!options) {
return
}
if (options.h) {
cli.usage()
}
File baseDir = new File(options.b)
File intersectDir = new File(options.i)
println " baseDir ${baseDir}"
println "intersectDir ${intersectDir}"
// Base jars
baseJarFileList = []
baseDir.eachFileRecurse( FileType.FILES ) {
if( it.name.endsWith( '.jar' ) ) {
baseJarFileList << it
}
}
// Other jars
intersectJarFileList = []
intersectDir.eachFileRecurse( FileType.FILES ) {
if( it.name.endsWith( '.jar' ) ) {
intersectJarFileList << it
}
}
def baseList = baseJarFileList.collect { file -> file.getName() }
def intersectList = intersectJarFileList.collect { file -> file.getName() }
// Regex for sequence of hyphens (dash), digits etc.
def versionChanged = ( intersectList - baseList ).collect { it.replaceAll(/-[\d\.-]*\.jar/, "") }
versionChanged.each { name ->
//println name
oldName = baseList.find { it =~ /^${name}*/ }
newName = intersectList.find { it =~ /^${name}*/ }
if ( oldName == null )
oldName = "N/A"
if ( newName == null )
newName = ""
println "${oldName} -> ${newName}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment