the idea rather simple, want access project classes in build script directly.
i first tried:
apply plugin: 'java' tasks.create(name: 'randomtask', type: sourcetask) { source.each { println } } and sadly got 0 files.
then decided give compilejava try:
apply plugin: 'java' compilejava { source.each { println } } and while indeed did list of files compiled it's not need. want class objects of files.
so example if had com.example.someclass, i'd expect class<com.example.someclass> use reflections on classes.
here's non-working example of i'd like:
apply plugin: 'java' tasks.create(name: 'randomtask', type: somemagicaltype) { umlbuilder builder = umlbuilder.builder() classes.each { clazz -> clazz.methods.each { method -> builder.addmethod(method) } } builder.build().writetofile(file('out/application.uml')) } p.s.: i'm using gradle 2.5 , java 8
i had little play trying classes in project , instantiating them. managed get, it's not pretty raw job of getting class object
task allmethods(dependson: classes) << { def ncl = new groovyclassloader() ncl.addclasspath("${sourcesets.main.output.classesdir}") configurations.compile.each { ncl.addclasspath(it.path) } def ctree = filetree(dir: sourcesets.main.output.classesdir) def cfiles = ctree.matching { include '**/*.class' exclude '**/*$*.class' } cfiles.each { f -> def c = f.path - (sourcesets.main.output.classesdir.path + "/") def cname = c.replaceall('/', '\\.') - ".class" def cz = class.forname(cname, false, ncl) cz.methods.each { println } } } it creates new class loader, adds default output classes dir, , dependency classes compile configuration, builds list of files classesdir, converts them path string in format 'a.b.yourclass', , loads in , dumps out methods on classes.
you can add own logic attributes methods need, should going.
Comments
Post a Comment