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 #1230. Add test to make sure Asciidoctor version is returned wh… #1243

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion asciidoctorj-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ jar {
'Automatic-Module-Name': 'org.asciidoctor.asciidoctorj.cli'
)
}
metaInf { from "$buildDir/version-info/" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
abelsromero marked this conversation as resolved.
Show resolved Hide resolved
.contains("2.0.20");
} finally {
System.setOut(previousSystemOut);
}
}


private ByteArrayOutputStream redirectStdout() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
System.setOut(new PrintStream(output));
Expand Down
32 changes: 17 additions & 15 deletions asciidoctorj-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Loading