Skip to content

Instantly share code, notes, and snippets.

@renatoathaydes
Created June 16, 2016 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renatoathaydes/1570da8e46944f420022004109de99a1 to your computer and use it in GitHub Desktop.
Save renatoathaydes/1570da8e46944f420022004109de99a1 to your computer and use it in GitHub Desktop.
Adds src/test/groovy as test sources to all projects under the current directory
import groovy.io.FileType
import groovy.util.slurpersupport.GPathResult
import groovy.xml.XmlUtil
def intellijFileVisitor = { File intellijFile ->
def groovyDir = new File(intellijFile.parentFile, 'src/test/groovy')
if (groovyDir.isDirectory() && groovyDir.list()?.size() > 0) {
def module = new XmlSlurper().parse(intellijFile)
GPathResult sources = module.component.content.sourceFolder
def groovySources = sources.any { it.@url == 'file://$MODULE_DIR$/src/test/groovy' }
if (groovySources) {
println "${intellijFile.parentFile} is setup correctly"
} else {
println "Groovy tests are not marked as such in ${intellijFile.parentFile}. Fixing it."
module.component.content.appendNode {
sourceFolder(url: 'file://$MODULE_DIR$/src/test/groovy', isTestSource: true)
}
try {
intellijFile.withWriter { writer ->
XmlUtil.serialize(module, writer)
}
println "Fixed!"
} catch (e) {
println "Could not fix ${intellijFile}: $e"
}
}
}
}
new File('.').traverse(type: FileType.FILES, nameFilter: ~/.*\.iml/, visit: intellijFileVisitor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment