This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch quick-fix/source-editor-maven-properties in repository https://gitbox.apache.org/repos/asf/camel.git
commit e73ce6ad9a3e6db408669fde2b31b2b02df82901 Author: Claus Ibsen <[email protected]> AuthorDate: Thu Oct 1 15:17:31 2026 +0200 chore: camel-jbang - source editor reads property placeholders from src/main/resources of a Maven project Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../jbang/core/commands/tui/SourceEditAssist.java | 56 ++++++++++++---------- .../commands/tui/SourceEditorProjectInfoTest.java | 14 ++++++ 2 files changed, 46 insertions(+), 24 deletions(-) diff --git a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceEditAssist.java b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceEditAssist.java index 682d4cb50998..34e1b800e9c6 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceEditAssist.java +++ b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceEditAssist.java @@ -1438,30 +1438,18 @@ final class SourceEditAssist { } List<AutocompletePopup.CompletionItem> items = new ArrayList<>(); - try (var stream = java.nio.file.Files.list(rootDir)) { - stream.filter(p -> p.getFileName().toString().endsWith(".properties")) - .forEach(p -> { - try { - for (String line : java.nio.file.Files.readAllLines(p)) { - String trimmed = line.trim(); - if (trimmed.isEmpty() || trimmed.startsWith("#") || trimmed.startsWith("!")) { - continue; - } - int eq = trimmed.indexOf('='); - if (eq > 0) { - String key = trimmed.substring(0, eq).trim(); - String value = trimmed.substring(eq + 1).trim(); - items.add(new AutocompletePopup.CompletionItem( - "{{" + key + "}}", value, "placeholder", - null, false, null, p.getFileName().toString())); - } - } - } catch (IOException e) { - // skip unreadable files - } - }); - } catch (IOException e) { - return List.of(); + // a Maven or Gradle project keeps its properties in src/main/resources, a camel run folder next to the routes + for (Path dir : List.of(rootDir, rootDir.resolve("src/main/resources"))) { + if (!java.nio.file.Files.isDirectory(dir)) { + continue; + } + try (var stream = java.nio.file.Files.list(dir)) { + stream.filter(p -> p.getFileName().toString().endsWith(".properties")) + .sorted() + .forEach(p -> addPlaceholders(p, rootDir.relativize(p).toString(), items)); + } catch (IOException e) { + // skip an unreadable folder + } } items.sort(Comparator.comparing(AutocompletePopup.CompletionItem::key, String.CASE_INSENSITIVE_ORDER)); @@ -1471,6 +1459,26 @@ final class SourceEditAssist { return items; } + private static void addPlaceholders(Path file, String source, List<AutocompletePopup.CompletionItem> items) { + try { + for (String line : java.nio.file.Files.readAllLines(file)) { + String trimmed = line.trim(); + if (trimmed.isEmpty() || trimmed.startsWith("#") || trimmed.startsWith("!")) { + continue; + } + int eq = trimmed.indexOf('='); + if (eq > 0) { + String key = trimmed.substring(0, eq).trim(); + String value = trimmed.substring(eq + 1).trim(); + items.add(new AutocompletePopup.CompletionItem( + "{{" + key + "}}", value, "placeholder", null, false, null, source)); + } + } + } catch (IOException e) { + // skip unreadable files + } + } + private static final Pattern PLACEHOLDER = Pattern.compile("\\{\\{([^}:]+?)(?::([^}]*))?\\}\\}"); diff --git a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceEditorProjectInfoTest.java b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceEditorProjectInfoTest.java index 8dd034cf3d80..bc9d3224205b 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceEditorProjectInfoTest.java +++ b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceEditorProjectInfoTest.java @@ -90,6 +90,20 @@ class SourceEditorProjectInfoTest { assertThat(assist.placeholderDocs("from(\"timer:orders\")")).isEmpty(); } + @Test + void thePlaceholdersOfAMavenProjectComeFromItsResources() throws Exception { + Files.writeString(dir.resolve("pom.xml"), "<project/>\n"); + Path resources = Files.createDirectories(dir.resolve("src/main/resources")); + Files.writeString(resources.resolve("application.properties"), "timer.period=1s\n"); + SourceEditAssist assist = new SourceEditAssist( + new MonitorContext(new AtomicReference<>(List.of()), new AtomicReference<>(List.of()))); + assist.setRootDir(dir); + + assertThat(assist.placeholderDocs("from(\"timer:foo?period={{timer.period}}\")")) + .extracting(SourceViewer.DocEntry::text) + .containsExactly("{{timer.period}} = 1s (src/main/resources/application.properties)"); + } + @Test void theBeansARouteRefersToAreFound() throws Exception { Files.writeString(dir.resolve("OrderService.java"), """
