Skip to content

Commit 267d74a

Browse files
committed
Fixes asciidoctor#1230. Add test to make sure Asciidoctor version is returned when using --version
1 parent 989cf99 commit 267d74a

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

asciidoctorj-cli/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,4 @@ jar {
2828
'Automatic-Module-Name': 'org.asciidoctor.asciidoctorj.cli'
2929
)
3030
}
31-
metaInf { from "$buildDir/version-info/" }
3231
}

asciidoctorj-cli/src/main/java/org/asciidoctor/cli/jruby/AsciidoctorInvoker.java

-3
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ public int invoke(String... parameters) throws IOException {
9090

9191
private String getAsciidoctorJVersion() {
9292
InputStream in = getClass().getResourceAsStream("/META-INF/asciidoctorj-version.properties");
93-
if (in == null) {
94-
return "N/A";
95-
}
9693
Properties versionProps = new Properties();
9794
try {
9895
versionProps.load(in);

asciidoctorj-cli/src/test/java/org/asciidoctor/cli/WhenAsciidoctorIsCalledUsingCli.java

+18
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.io.File;
1616
import java.io.IOException;
1717
import java.io.PrintStream;
18+
import java.nio.charset.StandardCharsets;
1819

1920
import static org.assertj.core.api.Assertions.catchThrowable;
2021
import static org.hamcrest.CoreMatchers.is;
@@ -274,6 +275,23 @@ void should_convert_to_subdirectories(@ClasspathResource("relative/sub/test.adoc
274275
expectedFile.delete();
275276
}
276277

278+
@Test
279+
void should_print_version() throws IOException {
280+
PrintStream previousSystemOut = System.out;
281+
try (ByteArrayOutputStream out = new ByteArrayOutputStream();
282+
PrintStream sysout = new PrintStream(out)){
283+
System.setOut(sysout);
284+
new AsciidoctorInvoker().invoke("--version");
285+
String result = out.toString(StandardCharsets.UTF_8);
286+
Assertions.assertThat(result)
287+
// Needs to be updated when version changes
288+
.contains("2.0.20");
289+
} finally {
290+
System.setOut(previousSystemOut);
291+
}
292+
}
293+
294+
277295
private ByteArrayOutputStream redirectStdout() {
278296
ByteArrayOutputStream output = new ByteArrayOutputStream();
279297
System.setOut(new PrintStream(output));

asciidoctorj-core/build.gradle

+17-15
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ javadoc {
8686
source(project(':asciidoctorj-api').sourceSets.main.allJava)
8787
}
8888

89+
task createVersionFile {
90+
inputs.property('version.asciidoctor', asciidoctorGemVersion)
91+
inputs.property('version.asciidoctorj', project.version)
92+
outputs.dir("${buildDir}/version-info")
93+
94+
doLast {
95+
file("${buildDir}/version-info/asciidoctorj-version.properties", ).text = """
96+
version.asciidoctorj: ${project.version}
97+
version.asciidoctor: $asciidoctorGemVersion
98+
"""
99+
}
100+
}
101+
102+
89103
jar {
90104
bnd(
91105
('Bundle-Name'): 'asciidoctorj',
@@ -96,24 +110,12 @@ jar {
96110
'Automatic-Module-Name': 'org.asciidoctor.asciidoctorj'
97111
)
98112
}
99-
metaInf { from "$buildDir/version-info/" }
113+
metaInf {
114+
from createVersionFile
115+
}
100116
}
101117

102118
test {
103119
useJUnitPlatform()
104120
}
105121

106-
task createVersionFile {
107-
inputs.property('version.asciidoctor', asciidoctorGemVersion)
108-
inputs.property('version.asciidoctorj', project.version)
109-
outputs.dir("$buildDir/version-info")
110-
111-
doLast {
112-
file("$buildDir/version-info/asciidoctorj-version.properties").text = """
113-
version.asciidoctorj: ${project.version}
114-
version.asciidoctor: $asciidoctorGemVersion
115-
"""
116-
}
117-
}
118-
119-
jar.dependsOn createVersionFile

0 commit comments

Comments
 (0)