christophd commented on code in PR #29578:
URL: https://github.com/apache/camel/pull/29578#discussion_r4535959879
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/PluginHelper.java:
##########
@@ -86,6 +88,37 @@ 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_FILE} in the user home
directory</li>
+ * </ol>
+ */
+ public static Path getCustomPluginConfigPath(Path configPath) {
+ Path pluginConfigPath;
+ if (configPath != null) {
+ pluginConfigPath = configPath;
+ } else {
+ String env = System.getenv(PLUGIN_CONFIG_ENV);
+ if (env != null && !env.isBlank()) {
+ pluginConfigPath = Path.of(env);
Review Comment:
_Claude Code on behalf of christophd_
Fixed. `Path.of(env)` is now wrapped in a try-catch for
`InvalidPathException`, throwing an `IllegalStateException` that names the
`CAMEL_CLI_PLUGIN_CONFIG` variable. Same handling added in
`PluginBaseCommand.pluginConfigPath()` for the `--plugin-config` option.
##########
dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/PluginHelperTest.java:
##########
@@ -395,12 +396,126 @@ void testNoCompatibilityWarningForLegacyEntry() {
assertEquals("", printer.getOutput());
}
+ @Test
+ public void testDefaultPluginConfigPath() {
+ Path expected =
CommandLineHelper.getHomeDir().resolve(PluginHelper.PLUGIN_CONFIG_FILE);
+ assertEquals(expected, PluginHelper.getCustomPluginConfigPath());
+ }
+
+ @Test
+ public void testCustomPluginConfigPath() {
+ Path custom = tempDir.resolve("custom-plugins.json");
+ assertEquals(custom, PluginHelper.getCustomPluginConfigPath(custom));
+ }
+
+ @Test
+ public void testCustomPluginConfigPathAsDirectory() throws Exception {
+ Path customDir = tempDir.resolve("custom-config-dir");
+ Files.createDirectories(customDir);
+ assertEquals(customDir.resolve(PluginHelper.PLUGIN_CONFIG_FILE),
PluginHelper.getCustomPluginConfigPath(customDir));
+ }
+
+ @Test
+ public void testCustomPluginConfigPathReset() {
Review Comment:
_Claude Code on behalf of christophd_
Added. Extracted a package-private `resolvePluginConfigPath(Path configPath,
String envValue)` overload that can be unit-tested directly without touching
the real environment — avoids needing `@SetEnvironmentVariable` and the
surefire `--add-opens` flags.
Four new tests added:
- `testEnvVarPluginConfigPath` — env var as JSON file
- `testEnvVarPluginConfigPathAsDirectory` — env var as directory
- `testExplicitPathTakesPrecedenceOverEnvVar` — explicit path wins over env
var
- `testInvalidEnvVarPathThrowsIllegalState` — invalid path gives a clear
error
--
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]