From adfef6d3d8a06011b2670cfc9128c13f1767a602 Mon Sep 17 00:00:00 2001 From: Jason Porter Date: Mon, 27 Jun 2022 14:31:40 -0600 Subject: [PATCH] Fixes #95 Allowing files to start with "assembly" and have "assembly" be the first part of an id. Signed-off-by: Jason Porter --- .../asciidoc/extraction/Extractor.java | 2 +- .../asciidoc/extraction/model/Assembly.java | 5 +++++ .../cli/CornerCaseExtractionRunnerTest.java | 15 +++++++++++++++ .../asciidoc/cli/ExtractionRunnerTest.java | 4 ++-- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/lightguard/documentation/asciidoc/extraction/Extractor.java b/src/main/java/io/github/lightguard/documentation/asciidoc/extraction/Extractor.java index b932ebd..740adb1 100644 --- a/src/main/java/io/github/lightguard/documentation/asciidoc/extraction/Extractor.java +++ b/src/main/java/io/github/lightguard/documentation/asciidoc/extraction/Extractor.java @@ -69,7 +69,7 @@ public int process() { for (File file : walker.getAdocFiles()) { // We only want to process chap files, others should be moved to modules. - if (!file.getName().startsWith("chap-")) { + if (!file.getName().startsWith("chap-") && !file.getName().startsWith("assembly-")) { try { this.logger.fine("Copying non chap- file '" + file + "' to modules directory"); Path modulesDir = Files.createDirectories(targetDirPath.resolve("modules")); diff --git a/src/main/java/io/github/lightguard/documentation/asciidoc/extraction/model/Assembly.java b/src/main/java/io/github/lightguard/documentation/asciidoc/extraction/model/Assembly.java index a2c2cdc..21f05ec 100644 --- a/src/main/java/io/github/lightguard/documentation/asciidoc/extraction/model/Assembly.java +++ b/src/main/java/io/github/lightguard/documentation/asciidoc/extraction/model/Assembly.java @@ -39,6 +39,11 @@ public Assembly(Document doc, List lines, StringBuilder processedBody) { this.id = this.id.replaceAll("chap-", ""); } + // remove "assembly-" if it is found + if (this.id.contains("assembly-")) { + this.id = this.id.replaceAll("assembly-", ""); + } + if (this.id.contains("{context}")) { this.idWithoutContext = this.id.substring(0, this.id.lastIndexOf("{context}") - 1); } else { diff --git a/src/test/java/io/github/lightguard/documentation/asciidoc/cli/CornerCaseExtractionRunnerTest.java b/src/test/java/io/github/lightguard/documentation/asciidoc/cli/CornerCaseExtractionRunnerTest.java index 452a4ed..d4b1351 100644 --- a/src/test/java/io/github/lightguard/documentation/asciidoc/cli/CornerCaseExtractionRunnerTest.java +++ b/src/test/java/io/github/lightguard/documentation/asciidoc/cli/CornerCaseExtractionRunnerTest.java @@ -176,4 +176,19 @@ public void additionalResources81Test() throws Exception { assertThat(Files.lines(assemblyFile)).contains("* {URL_PROCESS_SERVICES}[_{PROCESS_SERVICES}_]"); assertThat(Files.lines(assemblyFile)).contains("* {URL_CONFIGURING_KOGITO}[_{CONFIGURING_KOGITO}_]"); } + + @Test + public void assemblyInsteadOfChap95Test() throws Exception { + this.executeRunner("docs/issue-95", false); + + assertThat(assembliesDir.toFile().exists()).isTrue(); + assertThat(assembliesDir.toFile().listFiles(pathname -> pathname.getName().contains(".adoc"))).hasSize(1); + + var assemblyFile = assembliesDir.resolve("assembly-kogito-using-dmn-models.adoc"); + assertThat(Files.lines(assemblyFile)).contains("[id='assembly-kogito-using-dmn-models']"); + + modulesDir = modulesDir.resolve("dmn"); + assertThat(modulesDir.toFile().exists()).isTrue(); + assertThat(modulesDir.toFile().listFiles(pathname -> pathname.getName().contains(".adoc"))).hasSizeGreaterThanOrEqualTo(1); + } } diff --git a/src/test/java/io/github/lightguard/documentation/asciidoc/cli/ExtractionRunnerTest.java b/src/test/java/io/github/lightguard/documentation/asciidoc/cli/ExtractionRunnerTest.java index c6968d6..55b26b3 100644 --- a/src/test/java/io/github/lightguard/documentation/asciidoc/cli/ExtractionRunnerTest.java +++ b/src/test/java/io/github/lightguard/documentation/asciidoc/cli/ExtractionRunnerTest.java @@ -40,7 +40,7 @@ void testFileContentsSourceBlock() throws Exception { var assembliesDir = new File(this.outputDirectory, "assemblies"); assertThat(assembliesDir.listFiles(new AsciidocFileFilter())).hasSize(1); final var assemblyFile = Objects.requireNonNull(assembliesDir.listFiles(new AsciidocFileFilter()))[0]; - assertThat(assemblyFile.getName()).isEqualTo("assembly-assembly-one.adoc"); + assertThat(assemblyFile.getName()).isEqualTo("assembly-one.adoc"); } @Test @@ -301,7 +301,7 @@ public void testImagesdirInOutput() throws Exception { new CommandLine(new ExtractionRunner()).execute(options); var chap = outputDirectory.toPath().resolve("assemblies") - .resolve("assembly-assembly-one.adoc"); + .resolve("assembly-one.adoc"); var module = outputDirectory.toPath().resolve("modules").resolve("content-test").resolve("con-module-two.adoc"); assertThat(Files.readAllLines(chap).get(2)).isEqualTo(":imagesdir: _images");