Fixes Print version of AsciidoctorJ when calling asciidoctorj --version
MODIFY
asciidoctorj-core/build.gradle
asciidoctorj-core/build.gradle
@@ -56,6 +56,7 @@ jar {
'com.beust.jcommander;resolution:=optional',
'*'
}
+ metaInf { from "$buildDir/version-info/" }
}
test {
@@ -64,6 +65,20 @@ test {
}
}
+task createVersionFile {
+ inputs.property('version.asciidoctor', asciidoctorGemVersion)
+ inputs.property('version.asciidoctorj', project.version)
+ outputs.dir("$buildDir/version-info")
+
+ doLast {
+ file("$buildDir/version-info/asciidoctorj-version.properties").text = """
+version.asciidoctorj: ${project.version}
+version.asciidoctor: $asciidoctorGemVersion
+"""
+ }
+}
+jar.dependsOn createVersionFile
+
task pollutedTest(type: Test) {
useJUnit {
includeCategories 'org.asciidoctor.categories.Polluted'

MODIFY
asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/AsciidoctorInvoker.java
asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/AsciidoctorInvoker.java
package org.asciidoctor.jruby.cli;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.Scanner;
import org.asciidoctor.Asciidoctor;
@@ -36,7 +39,7 @@ public class AsciidoctorInvoker {
JRubyAsciidoctor asciidoctor = buildAsciidoctorJInstance(asciidoctorCliOptions);
if (asciidoctorCliOptions.isVersion()) {
- System.out.println("AsciidoctorJRuby " + asciidoctor.asciidoctorVersion() + " [http://asciidoctor.org]");
+ System.out.println("AsciidoctorJRuby " + getAsciidoctorJVersion() + " (Asciidoctor " + asciidoctor.asciidoctorVersion() + ") [https://asciidoctor.org]");
Object rubyVersionString = JRubyRuntimeContext.get(asciidoctor).evalScriptlet("\"#{JRUBY_VERSION} (#{RUBY_VERSION})\"");
System.out.println("Runtime Environment: jruby " + rubyVersionString);
return;
@@ -80,6 +83,21 @@ public class AsciidoctorInvoker {
}
}
+ private String getAsciidoctorJVersion() {
+ InputStream in = getClass().getResourceAsStream("/META-INF/asciidoctorj-version.properties");
+ if (in == null) {
+ return "N/A";
+ }
+ Properties versionProps = new Properties();
+ try {
+ versionProps.load(in);
+ return versionProps.getProperty("version.asciidoctorj");
+ } catch (IOException e) {
+ return "N/A";
+ }
+
+ }
+
private void setTimingsMode(Asciidoctor asciidoctor, AsciidoctorCliOptions asciidoctorCliOptions, Options options) {
if (asciidoctorCliOptions.isTimings()) {
options.setOption("timings",

Fixes #791. Print version of AsciidoctorJ when calling asciidoctorj --version