java - Can we use one wsimport task for multiple wsdl's in gradle without repeating the similar code? -


i writing gradle task wsimport generate web service artifacts. task wrote working fine , shown below.

task wsimport {     ext.destdir = file('gen')     dolast {         ant {             sourcesets.main.output.classesdir.mkdirs()             destdir.mkdirs()             taskdef(name: 'wsimport',                     classname: 'com.sun.tools.ws.ant.wsimport',                     classpath: 'c:/users/sbhattar/git/java_commons/common/java/lib/jaxws-2.2.6/jaxws-tools.jar'             )             wsimport(keep: true,                     destdir: sourcesets.main.output.classesdir,                     sourcedestdir: destdir,                     extension: "true",                     verbose: "false",                     quiet: "false",                     xnocompile: "true",                  wsdl:"http://spapen2w1.shashwat.com.planservice_4_0.wsdl") {                 xjcarg(value: "-xautonameresolution")             }         }     } } 

but since need generate artifacts multiple wsdl's pass array of wsdl paths on wsdl parameter. source code ant.taskdef uses parse wsdl. have tried passing array of wsdl thinking since arguments[0] object , since array instance of string might work did not. appreciated me eliminate code repeatition. new groovy/gradle.

public void execute(antbuilder ant, object... arguments) {     def wsdl = arguments[0]     def extension = arguments[1]     def destinationdir = arguments[2]     def classpath = arguments[3]     def episodes = arguments[4]      log.info("parsing wsdl '{}' destination directory of '{}'",          wsdl, destinationdir)      ant.taskdef (name : 'wsimport',          classname: 'com.sun.tools.ws.ant.wsimport',          classpath: classpath)      def params = [               wsdl            : wsdl.path,               verbose         : extension.verbose,               sourcedestdir   : destinationdir.path,               keep            : extension.keep,               wsdllocation    : extension.wsdllocation,               xnocompile      : extension.xnocompile,               fork            : extension.fork,               xdebug          : extension.xdebug,               target          : extension.target,               xadditionalheaders : extension.xadditionalheaders     ] 

one way eliminate repetition create list, wsdlpaths, , iterate on it. simple example:

task wsimport {     dolast {         def wsdlpaths = ["path1", "path2", "path3"]          wsdlpaths.each { wsdlpath ->             ant {                 // replace current code appropriate                 echo(message: "path ${wsdlpath}")             }         }     } } 

here merely use ant.echo should able substitute current code (with slight edits appropriate).


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -