diff --git a/asciidoctorj-cli/build.gradle b/asciidoctorj-cli/build.gradle index 2b6cc96d4..ace3fc1fa 100644 --- a/asciidoctorj-cli/build.gradle +++ b/asciidoctorj-cli/build.gradle @@ -28,5 +28,4 @@ jar { 'Automatic-Module-Name': 'org.asciidoctor.asciidoctorj.cli' ) } - metaInf { from "$buildDir/version-info/" } } diff --git a/asciidoctorj-cli/src/main/java/org/asciidoctor/cli/jruby/AsciidoctorInvoker.java b/asciidoctorj-cli/src/main/java/org/asciidoctor/cli/jruby/AsciidoctorInvoker.java index ec29d4f29..59254c83e 100644 --- a/asciidoctorj-cli/src/main/java/org/asciidoctor/cli/jruby/AsciidoctorInvoker.java +++ b/asciidoctorj-cli/src/main/java/org/asciidoctor/cli/jruby/AsciidoctorInvoker.java @@ -90,9 +90,6 @@ public int invoke(String... parameters) throws IOException { 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); diff --git a/asciidoctorj-cli/src/test/java/org/asciidoctor/cli/WhenAsciidoctorIsCalledUsingCli.java b/asciidoctorj-cli/src/test/java/org/asciidoctor/cli/WhenAsciidoctorIsCalledUsingCli.java index 64415a30e..da93d9929 100644 --- a/asciidoctorj-cli/src/test/java/org/asciidoctor/cli/WhenAsciidoctorIsCalledUsingCli.java +++ b/asciidoctorj-cli/src/test/java/org/asciidoctor/cli/WhenAsciidoctorIsCalledUsingCli.java @@ -15,6 +15,7 @@ import java.io.File; import java.io.IOException; import java.io.PrintStream; +import java.nio.charset.StandardCharsets; import static org.assertj.core.api.Assertions.catchThrowable; import static org.hamcrest.CoreMatchers.is; @@ -274,6 +275,23 @@ void should_convert_to_subdirectories(@ClasspathResource("relative/sub/test.adoc expectedFile.delete(); } + @Test + void should_print_version() throws IOException { + PrintStream previousSystemOut = System.out; + try (ByteArrayOutputStream out = new ByteArrayOutputStream(); + PrintStream sysout = new PrintStream(out)){ + System.setOut(sysout); + new AsciidoctorInvoker().invoke("--version"); + String result = out.toString(StandardCharsets.UTF_8); + Assertions.assertThat(result) + // Needs to be updated when version changes + .contains("2.0.20"); + } finally { + System.setOut(previousSystemOut); + } + } + + private ByteArrayOutputStream redirectStdout() { ByteArrayOutputStream output = new ByteArrayOutputStream(); System.setOut(new PrintStream(output)); diff --git a/asciidoctorj-core/build.gradle b/asciidoctorj-core/build.gradle index 0c5697de7..ed1403e80 100644 --- a/asciidoctorj-core/build.gradle +++ b/asciidoctorj-core/build.gradle @@ -86,6 +86,20 @@ javadoc { source(project(':asciidoctorj-api').sourceSets.main.allJava) } +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 { bnd( ('Bundle-Name'): 'asciidoctorj', @@ -96,24 +110,12 @@ jar { 'Automatic-Module-Name': 'org.asciidoctor.asciidoctorj' ) } - metaInf { from "$buildDir/version-info/" } + metaInf { + from createVersionFile + } } test { useJUnitPlatform() } -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