Skip to content

Instantly share code, notes, and snippets.

@indare
Created August 3, 2012 07:49
Show Gist options
  • Save indare/3245546 to your computer and use it in GitHub Desktop.
Save indare/3245546 to your computer and use it in GitHub Desktop.
ClassNotFountになったぞ・・・('A`)
package info.indare.hogehoge.fuga
import info.indare.hogehoge.Pugya
class Fuga extends Pugya{
def moto(){
println this.getClass().getName()
}
}
class HogeMaster {
public static void main(args){
def srcPath = System.getProperty("user.dir") + File.separator + "src" + File.separator
def dir = System.getProperty("user.dir") + File.separator + "src" + File.separator
List<Class<?>> testClasses = new ArrayList<Class<?>>()
def testRootDir = "info.indare.hogehoge".split(/\./).inject(dir) { prev, next ->
prev.toString() + File.separator + next
}
new File(testRootDir.toString()).eachFileRecurse {
if (it.isFile()){
println(it)
def classfile = it.absolutePath.replace(srcPath,"").replace(File.separator,".").replace(".groovy","")
println(classfile)
testClasses.push(getClassForName(classfile))
}
}
testClasses.each{
it.newInstance().moto()
}
}
@SuppressWarnings("unchecked")
public static <T> Class<T> getClassForName(String className) {
try {
return (Class<T>) Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}
package info.indare.hogehoge.piyo
import info.indare.hogehoge.Pugya
class Piyo extends Pugya{
def moto(){
println this.getClass().getName()
}
}
package info.indare.hogehoge
class Pugya {
def moto(){
println this.getClass().getName()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment