Hi Could you add this to the wiki, perhaps on the plugin page? An example of how to use it would also be very useful.
http://gradle.codehaus.org/Plugins thanks, Philip On Wed, Sep 22, 2010 at 10:32 AM, Adam Murdoch <[email protected]> wrote: > > On 20/09/2010, at 12:52 AM, Paul Speed wrote: > > Quiet list lately, but... > > I tried moving this class (and some other things) into its own xslt.gradle > file so I could: > apply from:'../gradle-plugins/xslt.gradle' > > Unfortunately, I don't know the magic incantations necessary to get the Xslt > task class visible to my main build.gradle so that I can declare my own > tasks. I always get a "project property Xslt does not exist error" and if I > try to reference the class directly for debugging (or to import it) I get an > actual class not found error. > > > Currently, classes defined in a script are not visible outside that script. > And so you can only use a task class within the script where it is defined. > This is something we want to fix. > A simple workaround is to set the task class as a project property in the > script: > project.Xslt = Xslt.class > class Xslt extends DefaultTask {... } > Then you should be able to do something like this in other scripts: > task transform(type: Xslt) { ... } > > I'd rather not have to cut-paste this snippet everywhere I need it but I'm > feeling out of my depth. > > Thanks in advance for any help or redirection. > -Paul > > Paul Speed wrote: > > I poked around and couldn't find any good examples of trying to make a task > to do simple XSLT on some source files. (Specifically, I was trying to get > an HTML view of checkstyle's report because the XML makes my head hurt...) > > Maybe there is something already built into gradle that I missed but anyway, > creating my own XSLT task wasn't 'too' bad. > > I ended up cobbling from some of the gradle build files, specifically the > docbook to HTML task and here's what I came up with: > > import javax.xml.transform.TransformerFactory > > import javax.xml.transform.stream.StreamResult > > import javax.xml.transform.stream.StreamSource > > class Xslt extends SourceTask { > > �...@outputfile @Optional > > File destFile > > �...@outputdirectory @Optional > > File destDir > > �...@inputfile > > File stylesheetFile > > �...@taskaction > > def transform() { > > if (!((destFile != null) ^ (destDir != null))) { > > throw new InvalidUserDataException("Must specify output file or dir.") > > } > > def factory = TransformerFactory.newInstance() > > def transformer = factory.newTransformer( > > new StreamSource(stylesheetFile)) > > source.visit { FileVisitDetails fvd -> > > if (fvd.isDirectory()) { > > return > > } > > File d = destFile; > > if( d == null ) > > d = new File( destDir, fvd.file.name ) > > transformer.transform(new StreamSource(fvd.file), > > new StreamResult(d)) > > } > > } > > } > > It seems to work for my limited use-cases but I'm totally open to criticism. > Still a little new to groovy so some of the semantics might be off. > > Maybe someone else finds it useful? Seems like this (or something similar) > would be a good task to have built in. > > -Paul > > --------------------------------------------------------------------- > > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > > > -- > Adam Murdoch > Gradle Developer > http://www.gradle.org > CTO, Gradle Inc. - Gradle Training, Support, Consulting > http://www.gradle.biz > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
