asciidoctor / asciidoctor-gradle-plugin

A Gradle plugin that uses Asciidoctor via JRuby to process AsciiDoc source files within the project.
https://asciidoctor.github.io/asciidoctor-gradle-plugin/
Apache License 2.0
285 stars 120 forks source link

[BUG] Missing lang in `includedir` value for PDF. It is different than for html #556

Closed ieugen closed 4 years ago

ieugen commented 4 years ago

Hi,

I have my CV written in asciidoc and I want to build it with gradle and this gradle plugin. I've noticed that the includedir value when generating PDF does not contain the lang attribute

My build file is here https://github.com/ieugen/ieugen.ro/blob/gradle-build/cv/build.gradle

plugins {
  id 'org.asciidoctor.jvm.convert' version '3.1.0'
  id 'org.asciidoctor.jvm.pdf' version '3.1.0'
}
asciidoctor {
  languages 'en', 'ro'
  sources {
      include 'index.adoc'
  }
}
asciidoctorj {
  modules {
      pdf {
        version '1.5.3'
      }
  }
  attributesForLang 'en',
    langName : 'English',
    'published-cv' : 'https://ieugen.ro/cv/en'

  attributesForLang 'ro',
    langName : 'Română',
    'published-cv' : 'https://ieugen.ro/cv/ro'
}

asciidoctorPdf { }

Running the command: ./gradlew clean asciidoctor asciidoctorPdf builds the HTML files ok but PDF's are with error:

> Task :cv:asciidoctorPdf
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/home/ieugen/.gradle/wrapper/dists/gradle-6.5-bin/6nifqtx7604sqp1q6g8wikw7p/gradle-6.5/lib/groovy-all-1.3-2.5.11.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
iun. 29, 2020 4:33:43 P.M. uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/reader.rb preprocess_include_directive
SEVERE: index.adoc: line 36: include file not found: /home/ieugen/proiecte/ieugen.ro/cv/src/docs/asciidoc/{lang}/professional-experience/2016-02-administrator-at-netdava/index.adoc
include file not found: /home/ieugen/proiecte/ieugen.ro/cv/src/docs/asciidoc/{lang}/professional-experience/2016-02-administrator-at-netdava/index.adoc :: index.adoc :: /home/ieugen/proiecte/ieugen.ro/cv//home/ieugen/proiecte/ieugen.ro/cv/src/docs/asciidoc/en/professional-experience/index.adoc:36 (uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/reader.rb:preprocess_include_directive)
iun. 29, 2020 4:33:44 P.M. uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/reader.rb preprocess_include_directive
SEVERE: index.adoc: line 39: include file not found: /home/ieugen/proiecte/ieugen.ro/cv/src/docs/asciidoc/{lang}/professional-experience/2012-06-self-employed-at-pfa/index.adoc
include file not found: /home/ieugen/proiecte/ieugen.ro/cv/src/docs/asciidoc/{lang}/professional-experience/2012-06-self-employed-at-pfa/index.adoc :: index.adoc :: /home/ieugen/proiecte/ieugen.ro/cv//home/ieugen/proiecte/ieugen.ro/cv/src/docs/asciidoc/en/professional-experience/index.adoc:39 (uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/reader.rb:preprocess_include_directive)
iun. 29, 2020 4:33:44 P.M. uri:classloader:/gems/asciidoctor-2.0.10/lib/asciidoctor/reader.rb preprocess_include_directive
ieugen commented 4 years ago

index.pdf

ysb33r commented 4 years ago

I'll try to have a look on the weekend.

ieugen commented 4 years ago

Thank you. I tried ifdef but failed. lang is null apparently.

ieugen commented 4 years ago

Hi, any update on this?

ieugen commented 4 years ago

Hi, Have you started on this? I can't wait for this bug anymore so I'm willing to take a shot at it. I would need some guidance so feel free to give some hints. I'll make a PR once I have something. I think a org.asciidoctor.gradle.jvm.MultiLanguageFunctionalSpec would be nice for pdf as well.

ieugen commented 4 years ago

I think the cause of the bug is because asciidoctor {} block that configures the languages is part of the org.asciidoctor.jvm.convert plugin which does HTML conversion.

https://asciidoctor.github.io/asciidoctor-gradle-plugin/development-3.x/user-guide/#_the_new_asciidoctorj_plugin

I think the languages 'en', 'ro' should be set inside the base plugin since they are a cross cutting concern.

@ysb33r : Could you please confirm? If this is the case I might be able to find a workaround by setting the options/attributes in the base / pdf plugin.

Also a bug fix in this case would be to move the locale code in the base plugin. WDYT?

ieugen commented 4 years ago

It seems I fixed the problem by adding the languages to PDF plugin as well:

asciidoctorPdf {
  languages 'en', 'ro'
}

So this means that this is not a bug, just a miss-understanding on my part. I expected the languages to be inherited from the convert plugin but that did not happen since all plugins inherit from base plugin.

I do think the language could/should be available in the base since all plugins will use something like this but I'm no expert on asciidoctor and this is just a week opinion.

ysb33r commented 4 years ago

Hi, Have you started on this? I can't wait for this bug anymore so I'm willing to take a shot at it. I would need some guidance so feel free to give some hints. I'll make a PR once I have something. I think a org.asciidoctor.gradle.jvm.MultiLanguageFunctionalSpec would be nice for pdf as well.

Have a go at it. We would like to do a 3.3.0 release at soiem stage and it would be good if this is part of it.

It seems I fixed the problem by adding the languages to PDF plugin as well:

asciidoctorPdf {
  languages 'en', 'ro'
}

So this means that this is not a bug, just a miss-understanding on my part. I expected the languages to be inherited from the convert plugin but that did not happen since all plugins inherit from base plugin.

I do think the language could/should be available in the base since all plugins will use something like this but I'm no expert on asciidoctor and this is just a week opinion.

From experience in using this I am also leaning over to the capability of defining it once for all tasks (as and when needed). The only way for this would be to add the functionliaty to both the asciidoctorj and asciidoctorjs extensions and then let the base tasks query the task extension for the values. This is nto a trivial fix, but it is not difficult either.

I have not looked at his code for a while, but it should be do-able as long as it the test refactoring is done first before actually changing the functionality.

ieugen commented 4 years ago

After giving it some thought I think the solution is ok as it is right now. Also by having it like this you get to choose a different set of languages for HTML and PDF. If you need the same list, I think you can use a def langs = [ 'ro ', 'es', 'en' ] and assign that. Moving it in the base plugin in this case will make the plugins more coupled. Inheritance is the root of all evil :). I'm closing this.