Created
June 16, 2016 07:05
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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