diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 23112cec6..b7f1d74d7 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -29,7 +29,6 @@ Improvement:: Bug Fixes:: -* Fix CLI target file location for source files relative to source dir (#1135) (@AlexCzar) * -s CLI option should be changed to -e to align with Asciidoctor (#1237) (@mojavelinux) === Compatible changes @@ -60,6 +59,7 @@ Bug Fixes:: * Cell nodes do not inherit from StructuralNode (#1086) (@rahmanusta) * Avoid throwing an exception when using AsciidoctorJ CLI and reading input from stdin (#1105) (@AlexCzar) * Remove destinationDir Option from API (use toDir instead) (#853, #941) (@abelsromero) +* Fix CLI target file location for source files relative to source dir (#1135) (@AlexCzar) * Fix ConcurrentModificationException when converting to stream concurrently (#1158) (@rocketraman) * 'UnsupportedOperationException' when passing immutable Map as options to 'createPhraseNode' (#1221) (@abelsromero) @@ -73,6 +73,7 @@ Build Improvement:: * Set JUnit5 as default test engine (#1186) (@abelsromero) * Removed pollutedTest Gradle task using junit-pioneer (#1193) (@abelsromero) * Ignore 'docs/**' changes in CI (#1225) (@abelsromero) +* Add test for ensuring that asciidoctor version is available in CLI (#1230) (@abelsromero) Documentation:: 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..14129a03a 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,27 @@ 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); + String expected = System.getProperty("org.asciidoctor.asciidoctorj-test.version.asciidoctorj"); + Assertions.assertThat(expected) + .as("Bad test setup, could not determine expected Asciidoctor version") + .isNotEmpty(); + expected = expected.replace("-SNAPSHOT", ""); + Assertions.assertThat(result) + .contains(expected); + } 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 diff --git a/build.gradle b/build.gradle index b2c52b067..e0af18d8d 100644 --- a/build.gradle +++ b/build.gradle @@ -200,6 +200,7 @@ subprojects { // Allow junit-pioneer environment manipulation on Windows + Java17+ jvmArgs = ['--add-opens', 'java.base/java.lang=ALL-UNNAMED'] } + systemProperty 'org.asciidoctor.asciidoctorj-test.version.asciidoctorj', asciidoctorGemVersion } }