Skip to content
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

When creating an AsciidoctorJ instance with classloader parameter, extensions are not discovered #942

Open
ahus1 opened this issue Aug 11, 2020 · 3 comments · May be fixed by #943
Open

Comments

@ahus1
Copy link
Contributor

ahus1 commented Aug 11, 2020

For the AsciiDoc plugin for IntelliJ I create a custom class loader and then call

AsciidoctorJRuby.Factory.create(classloader)

to create an instance. I do this as the list of JARs is determined at runtime.

The expected behavior to me was that all extensions in META-INF should be registered automatically.

But this was not the case.

I found that JRubyAsciidoctor#processRegistrations() doesn't receive the classloader parameter, and neither do its decendants.

A workaround for this: set the thread's classloader like this:

ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
try {
  Thread.currentThread().setContextClassLoader(classloader);
  return AsciidoctorJRuby.Factory.create(classloader);
} finally {
  Thread.currentThread().setContextClassLoader(oldCl);
}

Please advise if this behavior should be changed.

How could a code change look like? Would the classloader be passed down to the ServiceLoader.load() to be passed as a second parameter (currently only one parameter is passed, so the threads default classloader is used)?

@robertpanzer
Copy link
Member

The class loader that you are passing to AsciidoctorJRuby.Factory.create() is currently only used to load the Asciidoctor implementation from that location.

But I agree that it would make sense to also use it for loading extensions, converters, etc.

@robertpanzer
Copy link
Member

I can create a PR for that in the next days.

robertpanzer added a commit to robertpanzer/asciidoctorj that referenced this issue Aug 13, 2020
… classloader parameter, use this classloader also to autoregister extensions, converters, syntax highlighters and loggers.
@ahus1
Copy link
Contributor Author

ahus1 commented Aug 13, 2020

Thank you for looking into this. No hurry necessary as there is a workaround.
I'm happy to test it in my environments once you give me a "ping".

BTW: The AsciiDoc plugin for IntelliJ is about to offer support for user-supplied AsciidoctorJ based extensions in the preview. There might still be some caveats, but the current pre-release offers initial support: asciidoctor/asciidoctor-intellij-plugin#532

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants