christophd commented on code in PR #29578:
URL: https://github.com/apache/camel/pull/29578#discussion_r4537289520
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/PluginHelper.java:
##########
@@ -86,6 +88,49 @@ private PluginHelper() {
// prevent instantiation of utility class
}
+ public static Path getCustomPluginConfigPath() {
+ return getCustomPluginConfigPath(null);
+ }
+
+ /**
+ * Resolves the path to the plugin configuration file. Checks, in order:
+ * <ol>
+ * <li>A path set programmatically via method argument</li>
+ * <li>The {@value #PLUGIN_CONFIG_ENV} environment variable</li>
+ * <li>The default {@value #PLUGIN_CONFIG} in the user home directory</li>
+ * </ol>
+ */
+ public static Path getCustomPluginConfigPath(Path configPath) {
+ return resolvePluginConfigPath(configPath,
System.getenv(PLUGIN_CONFIG_ENV));
+ }
+
+ static Path resolvePluginConfigPath(Path configPath, String envValue) {
+ Path pluginConfigPath;
+ if (configPath != null) {
+ pluginConfigPath = configPath;
+ } else {
+ if (envValue != null && !envValue.isBlank()) {
+ try {
+ pluginConfigPath = Path.of(envValue);
+ } catch (java.nio.file.InvalidPathException e) {
+ throw new IllegalStateException(
+ "Invalid path in " + PLUGIN_CONFIG_ENV + "
environment variable: " + envValue, e);
+ }
+ } else {
+ return CommandLineHelper.getHomeDir().resolve(PLUGIN_CONFIG);
+ }
+ }
+
+ if (Files.isDirectory(pluginConfigPath)) {
+ return pluginConfigPath.resolve(PLUGIN_CONFIG);
+ }
+ Path fileName = pluginConfigPath.getFileName();
+ if (fileName != null &&
fileName.toString().toLowerCase().endsWith(".json")) {
+ return pluginConfigPath;
+ }
+ return pluginConfigPath.resolve(PLUGIN_CONFIG);
Review Comment:
_Claude Code on behalf of christophd_
Fixed in 15a31bd. An existing regular file is now accepted regardless of
extension (`Files.isRegularFile()` check runs before the suffix check). The
`toLowerCase()` uses `Locale.ROOT`, and a comment documents the remaining
fallback: a non-existing path without `.json` suffix is treated as a directory,
created on first save. Tests added for all three cases. The docs now describe
this behavior too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]