From 6a7771140d7b35b2050e06fba830456182754aa6 Mon Sep 17 00:00:00 2001 From: Robert Panzer Date: Mon, 20 Nov 2023 17:45:20 +0100 Subject: [PATCH] CLI should set :mkdirs option by default (#1241) --- CHANGELOG.adoc | 4 ++++ .../jruby/cli/AsciidoctorInvoker.java | 2 ++ .../cli/WhenAsciidoctorIsCalledUsingCli.java | 18 ++++++++++++++++++ .../src/test/resources/relative/sub/test.adoc | 5 +++++ 4 files changed, 29 insertions(+) create mode 100644 asciidoctorj-core/src/test/resources/relative/sub/test.adoc diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 3e07a7ba9..2486784d5 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -17,6 +17,10 @@ Improvement:: * Upgrade to JRuby 9.4.3.0 (#1235) (@headius) +Bug Fixes:: + +* CLI should set :mkdirs option by default (#1241) (@mojavelinux) + == 2.5.10 (2023-06-04) Improvement:: diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/AsciidoctorInvoker.java b/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/AsciidoctorInvoker.java index 5e834a9b4..a7780894b 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/AsciidoctorInvoker.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/AsciidoctorInvoker.java @@ -160,6 +160,8 @@ private void convertInput(Asciidoctor asciidoctor, Options options, List i return; } + options.setMkDirs(true); + findInvalidInputFile(inputFiles) .ifPresent(inputFile -> { System.err.println("asciidoctor: FAILED: input file(s) '" diff --git a/asciidoctorj-core/src/test/java/org/asciidoctor/jruby/cli/WhenAsciidoctorIsCalledUsingCli.java b/asciidoctorj-core/src/test/java/org/asciidoctor/jruby/cli/WhenAsciidoctorIsCalledUsingCli.java index 464aab346..3c6584433 100644 --- a/asciidoctorj-core/src/test/java/org/asciidoctor/jruby/cli/WhenAsciidoctorIsCalledUsingCli.java +++ b/asciidoctorj-core/src/test/java/org/asciidoctor/jruby/cli/WhenAsciidoctorIsCalledUsingCli.java @@ -20,6 +20,8 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.core.StringStartsWith.startsWith; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; @RunWith(Arquillian.class) public class WhenAsciidoctorIsCalledUsingCli { @@ -277,6 +279,22 @@ public void with_absolute_path_file_should_be_rendered() { expectedFile.delete(); } + @Test + public void should_convert_to_subdirectories() throws IOException { + + File inputFile = classpath.getResource("relative/sub/test.adoc"); + File srcDir = inputFile.getParentFile().getParentFile(); // points to relative/ + File toDir = new File(temporaryFolder.getRoot(), getClass().getSimpleName()); + File expectedFile = new File(toDir, "test.html"); + assertFalse(toDir.exists()); + + new AsciidoctorInvoker().invoke("-R", srcDir.getPath(), "-D", toDir.getPath(), srcDir.getAbsolutePath() + "/**/*.adoc"); + // Note that the subdirectory /sub is ignored, other than what asciidoctor does with it. + + assertTrue(expectedFile.exists()); + expectedFile.delete(); + } + private ByteArrayOutputStream redirectStdout() { ByteArrayOutputStream output = new ByteArrayOutputStream(); System.setOut(new PrintStream(output)); diff --git a/asciidoctorj-core/src/test/resources/relative/sub/test.adoc b/asciidoctorj-core/src/test/resources/relative/sub/test.adoc new file mode 100644 index 000000000..a6821e0ca --- /dev/null +++ b/asciidoctorj-core/src/test/resources/relative/sub/test.adoc @@ -0,0 +1,5 @@ += Test + + == Test + + Test \ No newline at end of file