New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image lookup does not work if both pdf-themesdir
and pdf-theme
are set to distinct uri:classloader:
paths
#2383
Comments
More about my use-case: In my code, I'd like to read all of the theme, images, and fonts from resources in a JAR. In the theme file, I'd like to use paths that are relative to the respective resource path. This works fine with fonts, where I set |
I don't have time to work on this right now. If you can see where in the code the logic needs to be changed and are willing to work on it with tests, I'll do my best to guide you through the steps of getting a PR submitted and merged. |
Thanks for the reply @mojavelinux. Unfortunately, my Ruby is rusty at best. And after searching for uses of "pdf-fontsdir" (to see how it's handled there) and |
This is the right project. There are things that need to be done (or at least not done) to support loading resources from the classpath. And there are several tests to verify that this functionality works in Asciidoctor PDF. See
It's possible you have found a case not covered by those tests. But, like I said, I don't have time right now to track it down. If you're not willing or able to debug the scenario, then no change will happen anytime in the near future. |
That's because the relevant logic should be in JRuby itself. |
I think the mistake you've made is that you are using Here's an example (expressed as CLI options even though you can also pass them using the Java API):
JRuby will then look for the theme at: uri:classloader:/templates/asciidoc/name-theme.yml. Note that the -theme.yml suffix is not required when specifying the name of the theme. |
Note that if pdf-themesdir is set, it must be everything except the basename of the theme file. It's not possible to specify part of the directory in pdf-themesdir and part of it in pdf-theme. |
Yeah, sorry, I was mixing up "classpath" with "classloader" in my comments, but in my comments only. As you can see from the error message, in my actual code I was using "classloader":
|
Thanks for clarifying. What I can tell you is that this definitely works. First, I have tests in Asciidoctor PDF to prove it. I have also tested it with the Maven plugin examples and it works there too. That's really all I can do unless you can provide a demo of a case when it is not working. I can't fix code that is already behaving as expected. |
FYI, here is the work-around that I'm currently applying:
|
That's fair. IIRC, strictly speaking the issues was not about |
What I can tell is is that the lookup of images definitely works in this case. If it does not, then there's something else going on with your environment. We have tests in Asciidoctor PDF that run on Linux and Windows to prove that it's absolutely supported regardless of whether you use pdf-theme or pdf-themesdir. |
If you prefer to set the pdf-theme directly because it works better for your environment, that's fine. But please don't state that Asciidoctor PDF doesn't support using pdf-themesdir with Btw, I'm happy to be proven wrong, but you actually have to demonstrate the failure in an isolated environment that I can actually debug. |
It's not exactly a minimal example, but this change triggers the behavior I'm seeing, and running our PdfTemplateReporterFunTest then fails with
Before going deeper into this, let's check if my expectations are correct. Given:
I'd expect that |
uri:classpath:
syntax also for pdf-themesdir
pdf-themesdir
if the latter start with uri:classloader:
There's the problem right there. The reason it works when you specify |
Thanks for clarifying, that wasn't obvious to me from reading the docs. Would it make sense to fail early then, with a dedicated error message if
Is this by design, or would it make sense to relax the entanglement between |
This behavior is by design. I'd be open to a docs update to clarify the
requirement. We're not making any more design changes to Asciidoctor PDF.
|
pdf-themesdir
if the latter start with uri:classloader:
pdf-themesdir
and pdf-theme
are set to distinct uri:classloader:
paths
Ok, I gave it a new try:
Is that supposed to work? As I'm still getting
Interestingly, it also doesn't work if I just set |
I wonder whether asciidoctor/asciidoctor#3929 is related, as it indeed seems like "uri:classloader:/pdf-theme/ort.png" is being treated as a relative path as it gets appended to "C:/Users/SEBAST~1/AppData/Local/Temp/ort-PdfTemplateReporter-asciidoc662513518992088845/" (and yes, I am running on JRuby). |
No, it's not related. It's not relevant for this case.
I assure the test case you are specifying works and is tested. If you want
any movement on this issue, I need an isolated and reproducible test case
in code. Otherwise, I have to assume there is a problem with your setup or
the version of JRuby you're using.
|
Aside from sharing a sample project that isolates your scenario, the only thing I can advise is to join the project chat at https://chat.asciidoctor.org to see if someone else can help you figure out why it doesn't work in your environment. I'm beyond frustrated at this point that the response I keep getting is "sorry, it doesn't work" with no additional details when I've proven time and again that this case does work. I just don't have time to keep posting the same point over and over again on this issue. |
Of course. I'm a maintainer myself and I know how annoying bad issue reports can be. I'm just trying to understand where to start in the mix of my expectations of how things are supposed to work (after reading the docs), Ruby, JRuby, Asciidoctor, Asciidoctor-PDF, etc.
Which might very well be.
Please don't be frustrated, and don't take my "sorry, it doesn't work" (for me) as equals to blaming you. I really don't. I'm still just trying to understand in which area providing more detail is most meaningful (see above).
That's understandable. Let's settle this issue for good until I've managed to isolate it. In any case, thanks for your responses so far. |
I did some more digging and this turns out to be incorrect. It is possible to use a directory other than the directory in which the theme file is located. (When using the classloader, the paths must not exit the classloader, but that probably goes without saying). I've updated the docs to include a more detailed explanation of how paths are resolved: https://docs.asciidoctor.org/pdf-converter/latest/theme/apply-theme/#theme-and-font-directories And, to be clear, I've tested this manually (in addition to the automated tests) with Asciidoctor PDF on CRuby, Asciidoctor PDF on JRuby, AsciidoctorJ PDF with the Maven plugin, and AsciidoctorJ PDF using the asciidoctorj bin script (installed via SDKman). In all cases, it works exactly as I have described it in the documentation. |
Ok, so after some lengthy debugging session I finally found the root cause of my issue that I'd like to share. It's caused by an implicit update of the JRuby version used by AsciidoctorJ:
As you can see, JRuby 9.3.8.0 gets updated to version 9.4.2.0 by Gradle (due to version 9.4.2.0 already being used by other code in the same project). This is what triggers
Here is an example project that demonstrates the issue. Sorry @mojavelinux for the noise after all, and thanks a lot for bearing with me. |
Thanks for conducting that research and sharing your findings. This looks like it boils down to a regression in JRuby, perhaps even specific to Windows. I wonder if it would be possible to go one step further and trigger it using JRuby itself, without Asciidoctor involved. |
I can actually confirm it to happen on Linux, too.
Would you have any hint how to do that? Like triggering a resource lookup that's supposed to be relative to another resource directory? Alternatively, any hints how to try with an AsciidoctorJ pre-release, as that seems to have been upgraded to JRuby 9.4.1.0? |
It should be as simple as calling |
I'm very frustrated with JRuby that this regression was allowed to happen. I just can't see how this bug made it through the test suite and into a release. |
Out of curiosity, I ran the Asciidoctor PDF test suite using JRuby 9.4.2.0. I can confirm that even our tests fail. So either JRuby has a good reason for changing this behavior (and we have to rethink our assumptions), or it's a bug in JRuby. |
Thanks for checking. It's somewhat relieving to not be alone 😉
I wasn't able to find a hint about such a behavior change in JRuby's release notes. So I'll probably file a bug with JRuby and see what the responses are. |
I found the exact change. Consider the following Ruby script: require 'pathname'
p (::Pathname.new 'uri:classloader:/pdf-themes/logo.png').absolute?
if File.respond_to? :absolute_path?
p File.absolute_path? 'uri:classloader:/pdf-themes/logo.png'
end Here are the results with different versions of JRuby:
What happened is that JRuby 9.4.2.0 implemented That means we can't rely on it. I can put in a workaround in the meantime, but this really strikes me as a bug in JRuby. I don't see why these two return values should be different. |
I just learned that JRuby 9.4.2.0 also gets the result wrong for a URL. Consider this code:
That should be I'm quickly losing faith in the JRuby test suite if it gets this kind of stuff wrong. |
Are you going to report it, or should I? (I guess you have more creds in that community than me, so I'd appreciate if you did.) |
I don't have time to track this down right now. But I am trying to get a patch into Asciidoctor PDF to work around it since this has the potential for causing a lot of problems for people upgrading. |
I've created jruby/jruby#7744 to raise awareness with the JRuby folks. |
@mojavelinux in Ruby 3.1 (JRuby 9.4.x) we stopped using our own pathname and started using a standardized gem. Something got lost in transit. The File#absolute_path? is a new method which just followed C Ruby's logic (e.g. I forgot about this value-added part). Opened jruby/jruby#7745 for that. |
Thanks for the insight @enebo! I'm glad to see that you are now tracking this in JRuby. One odd thing I noticed is that |
@mojavelinux I have not stepped through this yet but that is baffling to me too. There are specs to test absolute_path? but because I forgot this should have added our value-added logic for URIs it just calls the most obvious methods (and the normal ruby specs for this pass). When I figure this out we will definitely add tests for this and probably audit what else is calling the methods which made this return true. |
@sschuberth The workaround is included in the 2.3.6 release. I'll probably keep it in the 2.3.x release line, but remove it from main once we can confirm that JRuby handles the logic. |
Asciidoctor(J)-PDF 2.3.6 [1] includes a work-around for a bug in JRuby 9.4 that causes `uri:classloader:` paths to be recognized as absolute paths. Thanks to this work-around the current code can be simplified to avoid extracting image resources. However, as explained at [2] the `pdf-themesdir` "must resolve to the directory that contains the theme yml file". So move both the image and PDF theme file to a "pdf-theme" resource directory to have a conforming resource layout. And instead of setting `pdf-themesdir` explicitly, set it implicitly only by setting `pdf-theme` "because `pdf-themesdir` is then computed to be the directory of that file." [1]: https://github.com/asciidoctor/asciidoctor-pdf/releases/tag/v2.3.6 [2]: asciidoctor/asciidoctor-pdf#2383 (comment) Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
Asciidoctor(J)-PDF 2.3.6 [1] includes a work-around for a bug in JRuby 9.4 that causes `uri:classloader:` paths to be recognized as absolute paths. Thanks to this work-around the current code can be simplified to avoid extracting image resources. However, as explained at [2] the `pdf-themesdir` "must resolve to the directory that contains the theme yml file". So move both the image and PDF theme file to a "pdf-theme" resource directory to have a conforming resource layout. And instead of setting `pdf-themesdir` explicitly, set it implicitly only by setting `pdf-theme` "because `pdf-themesdir` is then computed to be the directory of that file." [1]: https://github.com/asciidoctor/asciidoctor-pdf/releases/tag/v2.3.6 [2]: asciidoctor/asciidoctor-pdf#2383 (comment) Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
Asciidoctor(J)-PDF 2.3.6 [1] includes a work-around for a bug in JRuby 9.4 that causes `uri:classloader:` paths to be recognized as absolute paths. Thanks to this work-around the current code can be simplified to avoid extracting image resources. However, as explained at [2] the `pdf-themesdir` "must resolve to the directory that contains the theme yml file". So move both the image and PDF theme file to a "pdf-theme" resource directory to have a conforming resource layout. And instead of setting `pdf-themesdir` explicitly, set it implicitly only by setting `pdf-theme` "because `pdf-themesdir` is then computed to be the directory of that file." [1]: https://github.com/asciidoctor/asciidoctor-pdf/releases/tag/v2.3.6 [2]: asciidoctor/asciidoctor-pdf#2383 (comment) Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
Can there possibly be some regression @mojavelinux? It seems despite me specifying a
pdf-themesdir
(as auri:classpath
uri:classloader
), thebackground-image
is being prefixed with a local path. This code triggersHmm, or does
pdf-themesdir
(in contrast topdf-fontsdir
) not supporturi:classpath
uri:classloader
? At least it's not explicitly mentioned in the docs.Originally posted by @sschuberth in #1829 (comment)
The text was updated successfully, but these errors were encountered: