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

Fixes #942. When an Asciidoctor instance is created with a classloade… #943

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[

== Unreleased

Bug Fixes::

* When creating an AsciidoctorJ instance with classloader parameter, extensions are not discovered (@ahus1) (#942)

== 2.4.0 (2020-07-19)

Improvement::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ public ConverterRegistryExecutor(AsciidoctorJRuby asciidoctor) {
}

public void registerAllConverters() {
registerAllConverters(Thread.currentThread().getContextClassLoader());
}

public void registerAllConverters(ClassLoader classloader) {
ServiceLoader<ConverterRegistry> converterRegistryServiceLoader = ServiceLoader
.load(ConverterRegistry.class);
.load(ConverterRegistry.class, classloader);

for (ConverterRegistry converterRegistry : converterRegistryServiceLoader) {
converterRegistry.register(asciidoctor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ public ExtensionRegistryExecutor(AsciidoctorJRuby asciidoctor) {
}

public void registerAllExtensions() {
registerAllExtensions(Thread.currentThread().getContextClassLoader());
}

public void registerAllExtensions(ClassLoader classloader) {
ServiceLoader<ExtensionRegistry> extensionRegistryServiceLoader = ServiceLoader
.load(ExtensionRegistry.class);
.load(ExtensionRegistry.class, classloader);

for (ExtensionRegistry extensionRegistry : extensionRegistryServiceLoader) {
extensionRegistry.register(asciidoctor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ public static JRubyAsciidoctor create(List<String> loadPaths) {
}

public static JRubyAsciidoctor create(ClassLoader classloader) {
return processRegistrations(createJRubyAsciidoctorInstance(null, new ArrayList<>(), classloader));
return processRegistrations(
createJRubyAsciidoctorInstance(null, new ArrayList<>(), classloader),
classloader);
}

public static JRubyAsciidoctor create(ClassLoader classloader, String gemPath) {
return processRegistrations(createJRubyAsciidoctorInstance(Collections.singletonMap(GEM_PATH, gemPath), new ArrayList<>(), classloader));
return processRegistrations(
createJRubyAsciidoctorInstance(Collections.singletonMap(GEM_PATH, gemPath), new ArrayList<>(), classloader),
classloader);
}

public static JRubyAsciidoctor create(List<String> loadPaths, String gemPath) {
Expand All @@ -96,22 +100,49 @@ private static JRubyAsciidoctor processRegistrations(JRubyAsciidoctor asciidocto
return asciidoctor;
}

private static JRubyAsciidoctor processRegistrations(JRubyAsciidoctor asciidoctor, ClassLoader classloader) {
registerExtensions(asciidoctor, classloader);
registerConverters(asciidoctor, classloader);
registerSyntaxHighlighters(asciidoctor, classloader);
registerLogHandlers(asciidoctor, classloader);

JavaLogger.install(asciidoctor.getRubyRuntime(), asciidoctor);

return asciidoctor;
}

private static void registerConverters(AsciidoctorJRuby asciidoctor) {
new ConverterRegistryExecutor(asciidoctor).registerAllConverters();
}

private static void registerConverters(AsciidoctorJRuby asciidoctor, ClassLoader classloader) {
new ConverterRegistryExecutor(asciidoctor).registerAllConverters(classloader);
}

private static void registerExtensions(AsciidoctorJRuby asciidoctor) {
new ExtensionRegistryExecutor(asciidoctor).registerAllExtensions();
}

private static void registerExtensions(AsciidoctorJRuby asciidoctor, ClassLoader classloader) {
new ExtensionRegistryExecutor(asciidoctor).registerAllExtensions(classloader);
}

private static void registerSyntaxHighlighters(AsciidoctorJRuby asciidoctor) {
new SyntaxHighlighterRegistryExecutor(asciidoctor).registerAllSyntaxHighlighter();
}

private static void registerSyntaxHighlighters(AsciidoctorJRuby asciidoctor, ClassLoader classloader) {
new SyntaxHighlighterRegistryExecutor(asciidoctor).registerAllSyntaxHighlighter(classloader);
}

private static void registerLogHandlers(AsciidoctorJRuby asciidoctor) {
new LogHandlerRegistryExecutor(asciidoctor).registerAllLogHandlers();
}

private static void registerLogHandlers(AsciidoctorJRuby asciidoctor, ClassLoader classloader) {
new LogHandlerRegistryExecutor(asciidoctor).registerAllLogHandlers(classloader);
}

private static JRubyAsciidoctor createJRubyAsciidoctorInstance(Map<String, String> environmentVars, List<String> loadPaths, ClassLoader classloader) {
Ruby rubyRuntime = createRubyRuntime(environmentVars, loadPaths, classloader);
return new JRubyAsciidoctor(rubyRuntime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.util.ServiceLoader;

public class LogHandlerRegistryExecutor {
private static ServiceLoader<LogHandler> logHandlerServiceLoader = ServiceLoader
.load(LogHandler.class);

private AsciidoctorJRuby asciidoctor;

Expand All @@ -16,6 +14,13 @@ public LogHandlerRegistryExecutor(AsciidoctorJRuby asciidoctor) {
}

public void registerAllLogHandlers() {
registerAllLogHandlers(Thread.currentThread().getContextClassLoader());
}

public void registerAllLogHandlers(ClassLoader classloader) {
ServiceLoader<LogHandler> logHandlerServiceLoader = ServiceLoader
.load(LogHandler.class, classloader);

for (LogHandler logHandler: logHandlerServiceLoader) {
asciidoctor.registerLogHandler(logHandler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ public SyntaxHighlighterRegistryExecutor(AsciidoctorJRuby asciidoctor) {
}

public void registerAllSyntaxHighlighter() {
registerAllSyntaxHighlighter(Thread.currentThread().getContextClassLoader());
}

public void registerAllSyntaxHighlighter(ClassLoader classLoader) {
ServiceLoader<SyntaxHighlighterRegistry> serviceLoader = ServiceLoader
.load(SyntaxHighlighterRegistry.class);
.load(SyntaxHighlighterRegistry.class, classLoader);

for (SyntaxHighlighterRegistry extensionRegistry : serviceLoader) {
extensionRegistry.register(asciidoctor);
}
Expand Down