eerohele / saxon-gradle

A Gradle plugin for running XSLT transformations with Saxon
MIT License
16 stars 6 forks source link

Use resolved filename to parse the stylesheet #22

Open ndw opened 3 years ago

ndw commented 3 years ago

I noticed the following bug this morning. When I load a Gradle file in IntelliJ, I see warnings like this one:

Failed to parse: /Users/ndw/Projects/docbook/xslTNG/tools/copy-xspec.xsl
  /tools/copy-xspec.xsl (No such file or directory)

The gradle script contains a SaxonXsltTask that identifies the stylesheet like this:

      stylesheet "tools/copy-xspec.xsl"

I believe the warning is from stylesheet():

    @SuppressWarnings('CatchException')
    void stylesheet(Object stylesheet) {
        this.options.stylesheet = project.file(stylesheet)
        if (this.options.stylesheet.exists()) {
            try {
                this.xslt = this.xmlSlurper
                        .parse(stylesheet)
                        .declareNamespace(xsl: XSLT_NAMESPACE)
            } catch (Exception ex) {
                logger.warn("Failed to parse: ${this.options.stylesheet}")
                logger.warn("  ${ex.getMessage()}")
            }
        }
    }

I haven't run this through the debugger, but it appears that project.file(stylesheet) returns an absolute filename correctly, but when .parse() is called, stylesheet is passed instead of this.options.stylesheet. I'm not sure why that's getting the filename wrong. Maybe something about how IntelliJ configures Gradle?

But it looks like passing this.options.stylesheet would work more consistently.

eerohele commented 3 years ago

Thanks! I'll take a look.