From 3a1f1d03072cb7b376a6aed37a7e16a2a1e4ddc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Tue, 10 Oct 2023 17:22:54 +0200 Subject: [PATCH] Ignore files starting with "_" when indexing guides --- src/main/java/io/quarkus/search/app/entity/Guide.java | 11 +++++++++-- .../io/quarkus/search/app/fetching/QuarkusIO.java | 5 ++++- .../search/app/fetching/FetchingServiceTest.java | 7 ++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/quarkus/search/app/entity/Guide.java b/src/main/java/io/quarkus/search/app/entity/Guide.java index 8e37bc7a..e4606065 100644 --- a/src/main/java/io/quarkus/search/app/entity/Guide.java +++ b/src/main/java/io/quarkus/search/app/entity/Guide.java @@ -1,7 +1,5 @@ package io.quarkus.search.app.entity; -import io.quarkus.search.app.hibernate.AnalysisConfigurer; -import io.quarkus.search.app.hibernate.PathWrapper; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; @@ -13,6 +11,9 @@ import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; import org.hibernate.search.mapper.pojo.mapping.definition.annotation.KeywordField; +import io.quarkus.search.app.hibernate.AnalysisConfigurer; +import io.quarkus.search.app.hibernate.PathWrapper; + @Entity @Indexed public class Guide { @@ -41,4 +42,10 @@ public class Guide { // Using PathWrapper because of https://hibernate.atlassian.net/browse/HSEARCH-4988 public PathWrapper fullContentPath; + @Override + public String toString() { + return "Guide{" + + "relativePath='" + relativePath + '\'' + + '}'; + } } diff --git a/src/main/java/io/quarkus/search/app/fetching/QuarkusIO.java b/src/main/java/io/quarkus/search/app/fetching/QuarkusIO.java index 6a61e7c0..992f748b 100644 --- a/src/main/java/io/quarkus/search/app/fetching/QuarkusIO.java +++ b/src/main/java/io/quarkus/search/app/fetching/QuarkusIO.java @@ -27,7 +27,10 @@ public void close() throws Exception { public Stream guides() throws IOException { return Files.list(directory.path().resolve("_guides")) - .filter(path -> FilenameUtils.isExtension(path.getFileName().toString(), "adoc")) + .filter(path -> { + String filename = path.getFileName().toString(); + return !filename.startsWith("_") && FilenameUtils.isExtension(filename, "adoc"); + }) .map(this::parseGuide); } diff --git a/src/test/java/io/quarkus/search/app/fetching/FetchingServiceTest.java b/src/test/java/io/quarkus/search/app/fetching/FetchingServiceTest.java index 5dbc84af..af3db618 100644 --- a/src/test/java/io/quarkus/search/app/fetching/FetchingServiceTest.java +++ b/src/test/java/io/quarkus/search/app/fetching/FetchingServiceTest.java @@ -102,8 +102,11 @@ class LocalDirectoryTest extends AbstractTest { @BeforeAll static void initLocalRepo() throws IOException { Path guideToFetch = sourceDir.resolve("_guides/" + FETCHED_GUIDE_NAME + ".adoc"); + Path adocToIgnore = sourceDir.resolve("_guides/_attributes.adoc"); PathUtils.createParentDirectories(guideToFetch); Files.writeString(guideToFetch, FETCHED_GUIDE_CONTENT); + PathUtils.createParentDirectories(adocToIgnore); + Files.writeString(adocToIgnore, "ignored"); } } @@ -121,10 +124,12 @@ class GitTest extends AbstractTest { @BeforeAll static void initOrigin() throws IOException, GitAPIException { Path guideToFetch = sourceRepoDir.resolve("_guides/" + FETCHED_GUIDE_NAME + ".adoc"); + Path adocToIgnore = sourceRepoDir.resolve("_guides/_attributes.adoc"); try (Git git = Git.init().setDirectory(sourceRepoDir.toFile()).call()) { PathUtils.createParentDirectories(guideToFetch); - Files.writeString(guideToFetch, "initial"); + PathUtils.createParentDirectories(adocToIgnore); + Files.writeString(adocToIgnore, "ignored"); git.add().addFilepattern(".").call(); git.commit().setMessage("First commit").call();