gradle task which works with files -


i trying write task works files, based on gradle-watch-plugin. (though not now. supposed run when start threadwatch task presume)

however don't how pass , passed filenames inside task.

apply plugin: 'java' apply plugin: 'application' apply plugin: 'groovy' apply plugin: 'com.bluepapa32.watch'  watch {     rules {         files filetree(dir: '/src/main/resources', include: '*.xls')         tasks 'validaterules'     } }  ....  dependencies {     compile "org.codehaus.groovy:groovy-all:2.0.5"      compile ("org.drools:drools-core:${droolsversion}")     compile ("org.drools:drools-compiler:${droolsversion}")     compile ("org.drools:drools-decisiontables:${droolsversion}") }  import org.drools.builder.* import org.drools.io.resourcefactory  task validaterules(type: defaulttask) {      ext.rulevalidator = {          xls_file_name ->             try {                 def tconfig = knowledgebuilderfactory.newdecisiontableconfiguration().with {                     tconfig.inputtype = decisiontableinputtype.xls                     def builder = knowledgebuilderfactory.newknowledgebuilder().with {                         builder.add(                             resourcefactory.newinputstreamresource(new fileinputstream(xls_file_name)),                             resourcetype.dtable,                             tconfig                         )                         if (builder.haserrors()) {                             println 'invalid ${xls_file_name} rule table!'                         }                     }                     table.add rfactory                 }             } catch (exc) {                 println exc.getmessage()             }     }      dolast {         rulevalidator()     } }  task watchthread() << {     thread.start {         project.tasks.watch.execute()     } } 

according gradle watch plugin need define watch configuration needed task , file list.

however did not described how task should , how pass parameters there -> created task, based on defaulttask , needs acquire file list.

however don't know there because don't understand how watch plugin passing there. @ all.

firstly, since gradle 2.5 there continuous build mode (-t on command-line), means can forego use of watch plugin in cases. should consider upgrading build @ least 2.5 if possible.

now code itself, there couple of things can better.

[1] seem have mixed task configuration task action.

task validaterules << {     // given assuming single xls file can     // (it throw exception if there more one)     def xls_file_name = inputs.files.singlefile      // ... rest of code inside try block can follow here     // (i not catch exception, rather let gradle handle it) } 

[2] configure custom task act upon change in inputs

validaterules {   inputs.files filetree(dir: '/src/main/resources', include: '*.xls') } 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -