gradle / gradle-jdocbook

A Gradle plugin for jdocbook
13 stars 14 forks source link

Issues locating resources #8

Closed erichschroeter closed 12 years ago

erichschroeter commented 12 years ago

I have a docbook project setup similar to the hibernate project (I've been using it as an example to get up and running with this plugin). My build.gradle is as follows:

buildscript {
  repositories {
    mavenCentral()
    mavenLocal()
    mavenRepo name: 'jboss', url: 'http://repository.jboss.org/nexus/content/groups/public/'
  }
  dependencies { classpath group: 'org.jboss.jdocbook', name:'gradle-jdocbook', version: '1.1.3' }
}

apply plugin: 'jdocbook'

jdocbook {
  masterLanguage = 'en-US'

  format('html_single') {
    finalName = 'index.html'
    stylesheet = 'classpath:/xslt/org/hibernate/jdocbook/xslt/xhtml-single.xsl'
  }

  manual {
    masterSourceDocumentName = 'manual.xml'
  }
}

However, I am getting errors when running the buildDocs task where resources cannot be located:

$ gradle :documentation:buildDocs
> Building > :documentation:stageStyles_manual > Resolving dependencies ':docume
:documentation:stageStyles_manual UP-TO-DATE
:documentation:renderDocBook_manual_en-US_html_single
Extending script classloader with the jdocbookStyles dependencies
rendering Book(manual) en-US/html_single
> Building > :documentation:renderDocBook_manual_en-US_html_single > Resolving d

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':documentation:renderDocBook_manual_en-US_html_single'.
> could not locate resource [classpath:/xslt/org/hibernate/jdocbook/xslt/xhtml-single.xsl]

BUILD FAILED

The xhtml-single.xsl file is located in src/main/style/xslt/org/hibernate/jdocbook/xslt/ but it still is not found. I tried just commenting out the classpath, and it appears jdocbook looks for a default stylesheet at /html/docbook.xsl. So, I tried placing a dummy docbook.xsl file in the following places within the project, but no matter where I put it, it was not located:

I've tried looking at the plugin code, but I'm fairly new to Groovy and Gradle, so I don't have much confidence in evaluating it. How are resources located in the jdocbook plugin? Do I have to put resources in a special place?

sebersole commented 12 years ago

You probably want to use this as a starting point instead: https://github.com/pressgang/docbook5-poc

Look at the staging stuff.

erichschroeter commented 12 years ago

So, I cloned the docbook5-poc project and executed the buildDocs task and it was successfully built. I then:

  1. changed my build.gradle file to only use the default book config (which is what the docbook5-poc uses)
  2. changed the stylesheet value to stylesheet = 'classpath:/xslt/org/jboss/pressgang/xhtml-single.xsl'
  3. copied the files in src/main/style to my project

and my project built successfully. The problem with the resources comes in as soon as I try to use multiple book configs.

I want to have at least 2 configs, one for manual and another for devguide. However, I keep getting the resource error mentioned above. Do you have any good examples of multi-book config projects? I'm following the same pattern as that of the multilbooks.gradle sample; is it out-dated?

ari commented 12 years ago

I'm stumped by this one too. You can't point the stylesheet to "${project.path}/stylesheets/something.xsl" because project isn't defined in the context of the jdocbook plugin.

ari commented 12 years ago

Ah, found it.

final URL transformationStylesheet = componentRegistry.getEnvironment().getResourceDelegate().requireResource( formatPlan.getStylesheetResource() );

which turns out to require syntax like this:

stylesheet = "file:stylesheets/pdf.xsl"

Steve, can I suggest you add this syntax to the example files to save someone else several hours of going in circles. Thanks for the great plugin.

sebersole commented 12 years ago

We probably could (should?) expose 'project' as a scripting variable inside our closure. That's a separate feature request to me. Feel free to make that if you think it is worthwhile.

As far as the URL syntax, you don't have to use the file: scheme... The code also understands a classpath: scheme. Again, you have to understand that all these "resources" get staged. You can name them relative to the staging dir using this classpath: URL scheme.

ari commented 12 years ago

Since I have multiple docbook documents, the stylesheets aren't inside the src directory for each, so classpath wasn't getting me anywhere. I keep a common set of stylesheets at the top level.

Anyway, file: is working for me. Just took some time to figure it out. Thanks.

Now onto my next problems:

Perhaps the docbook xsl is different to the maven plugin I was previously using. At the very least I can see it is XSL version 1 and not version 2.