This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new 6495a3a7a4 hop-conf no longer re-saves unrelated settings or prints
misleading m… (#9289)
6495a3a7a4 is described below
commit 6495a3a7a4d44eb157bb97cdcd529c239af4b93a
Author: Bart Maertens <[email protected]>
AuthorDate: Thu Nov 12 08:59:52 2026 +0100
hop-conf no longer re-saves unrelated settings or prints misleading m…
(#9289)
* hop-conf no longer re-saves unrelated settings or prints misleading
messages, fixes #9007
* Roll back --project-create when a later step fails, #9007
* Roll back --environment-create on failure, skip unresolved config file
paths, #9007
---
core/src/main/java/org/apache/hop/core/Const.java | 7 +-
.../java/org/apache/hop/config/HopConfigBase.java | 36 ++++-
.../org/apache/hop/config/HopConfigBaseTest.java | 158 +++++++++++++++++++++
.../org/apache/hop/lint/LinterConfigPlugin.java | 7 +-
.../ManageEnvironmentsOptionPlugin.java | 50 +++++--
.../project/ManageProjectsOptionPlugin.java | 69 +++++----
.../ManageEnvironmentsOptionPluginTest.java | 98 +++++++++++++
.../project/ManageProjectsOptionPluginTest.java | 119 ++++++++++++++++
.../config/ExplorerPerspectiveConfigPlugin.java | 4 +-
.../hopgui/search/config/SearchConfigPlugin.java | 4 +-
.../ExplorerPerspectiveConfigPluginTest.java | 106 ++++++++++++++
.../search/config/SearchConfigPluginTest.java | 107 ++++++++++++++
12 files changed, 713 insertions(+), 52 deletions(-)
diff --git a/core/src/main/java/org/apache/hop/core/Const.java
b/core/src/main/java/org/apache/hop/core/Const.java
index b39521670f..c5b9cf61a0 100644
--- a/core/src/main/java/org/apache/hop/core/Const.java
+++ b/core/src/main/java/org/apache/hop/core/Const.java
@@ -138,13 +138,10 @@ public class Const {
System.getProperty("HOP_AUDIT_FOLDER"),
System.getProperty("user.dir") + File.separator + "audit");
- /*
- The name of the history folder in which the Hop local audit manager saves
data
- */
+ /** The folder that holds the Hop configuration file hop-config.json */
@Variable(
scope = VariableScope.SYSTEM,
- description =
- "The name of the history folder in which the Hop local audit manager
saves data.")
+ description = "The folder that holds the Hop configuration file
hop-config.json.")
public static final String HOP_CONFIG_FOLDER =
NVL(
System.getProperty("HOP_CONFIG_FOLDER"),
diff --git a/engine/src/main/java/org/apache/hop/config/HopConfigBase.java
b/engine/src/main/java/org/apache/hop/config/HopConfigBase.java
index d0026ad6e6..5784f39fbb 100644
--- a/engine/src/main/java/org/apache/hop/config/HopConfigBase.java
+++ b/engine/src/main/java/org/apache/hop/config/HopConfigBase.java
@@ -80,16 +80,46 @@ public abstract class HopConfigBase implements Runnable,
IHasHopMetadataProvider
private boolean handleConfigMixinsOptions(LogChannel log) throws
HopException {
boolean actionTaken = false;
+ CommandLine.ParseResult parseResult = cmd.getParseResult();
+ Map<String, CommandLine.Model.CommandSpec> mixinSpecs =
cmd.getCommandSpec().mixins();
Map<String, Object> mixins = cmd.getMixins();
- for (String key : mixins.keySet()) {
- Object mixin = mixins.get(key);
- if (mixin instanceof IConfigOptions configOptions) {
+ for (Map.Entry<String, Object> entry : mixins.entrySet()) {
+ // Only hand a plugin its options when at least one of them was given.
Plugins that load
+ // their current settings when they are created would otherwise save
them again, and report
+ // a change, on every unrelated hop-conf command.
+ //
+ if (entry.getValue() instanceof IConfigOptions configOptions
+ && hasMatchedOption(parseResult, mixinSpecs.get(entry.getKey()))) {
actionTaken = configOptions.handleOption(log, this, variables) ||
actionTaken;
}
}
return actionTaken;
}
+ /**
+ * @param parseResult the parsed command line, null if it isn't known
+ * @param mixinSpec the specification of a config plugin mixed into the
command
+ * @return true if any option or positional parameter of the mixin was given
on the command line,
+ * or if that can't be determined
+ */
+ static boolean hasMatchedOption(
+ CommandLine.ParseResult parseResult, CommandLine.Model.CommandSpec
mixinSpec) {
+ if (parseResult == null || mixinSpec == null) {
+ return true;
+ }
+ for (CommandLine.Model.OptionSpec option : mixinSpec.options()) {
+ if (parseResult.hasMatchedOption(option)) {
+ return true;
+ }
+ }
+ for (CommandLine.Model.PositionalParamSpec positional :
mixinSpec.positionalParameters()) {
+ if (parseResult.hasMatchedPositional(positional)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
protected LogLevel determineLogLevel() {
return LogLevel.lookupCode(variables.resolve(level));
}
diff --git a/engine/src/test/java/org/apache/hop/config/HopConfigBaseTest.java
b/engine/src/test/java/org/apache/hop/config/HopConfigBaseTest.java
new file mode 100644
index 0000000000..e00fef7768
--- /dev/null
+++ b/engine/src/test/java/org/apache/hop/config/HopConfigBaseTest.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.config;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.hop.core.config.plugin.IConfigOptions;
+import org.apache.hop.core.logging.ILogChannel;
+import org.apache.hop.core.variables.IVariables;
+import org.apache.hop.metadata.api.IHasHopMetadataProvider;
+import org.junit.jupiter.api.Test;
+import picocli.CommandLine;
+
+/** hop-conf only hands a config plugin its options when one of them was given
(#9007). */
+class HopConfigBaseTest {
+
+ @Test
+ void onlyPluginsWithAGivenOptionAreHandled() {
+ TestConfig config = new TestConfig();
+ CommandLine cmd = new CommandLine(config);
+ FirstOptions first = new FirstOptions();
+ SecondOptions second = new SecondOptions();
+ cmd.addMixin("first", first);
+ cmd.addMixin("second", second);
+ config.setCmd(cmd);
+
+ cmd.parseArgs("--first=value");
+ config.run();
+
+ assertEquals(1, first.calls);
+ assertEquals(0, second.calls);
+ }
+
+ @Test
+ void noPluginIsHandledWithoutOptions() {
+ TestConfig config = new TestConfig();
+ CommandLine cmd = new CommandLine(config);
+ FirstOptions first = new FirstOptions();
+ cmd.addMixin("first", first);
+ config.setCmd(cmd);
+
+ cmd.parseArgs("--level=Basic");
+ config.run();
+
+ assertEquals(0, first.calls);
+ }
+
+ @Test
+ void optionsOfTheConfSubcommandAreMatched() {
+ // 'hop conf ...' parses from the root command: the subcommand keeps its
own parse result.
+ //
+ CommandLine root = new CommandLine(new RootCommand());
+ TestConfig config = new TestConfig();
+ CommandLine sub = new CommandLine(config);
+ root.addSubcommand("conf", sub);
+ FirstOptions first = new FirstOptions();
+ SecondOptions second = new SecondOptions();
+ sub.addMixin("first", first);
+ sub.addMixin("second", second);
+ config.setCmd(sub);
+
+ root.parseArgs("conf", "--second");
+ config.run();
+
+ assertEquals(0, first.calls);
+ assertEquals(1, second.calls);
+ }
+
+ @Test
+ void pluginsWithAGivenPositionalParameterAreHandled() {
+ TestConfig config = new TestConfig();
+ CommandLine cmd = new CommandLine(config);
+ FirstOptions first = new FirstOptions();
+ PositionalOptions positional = new PositionalOptions();
+ cmd.addMixin("first", first);
+ cmd.addMixin("positional", positional);
+ config.setCmd(cmd);
+
+ cmd.parseArgs("value");
+ config.run();
+
+ assertEquals(0, first.calls);
+ assertEquals(1, positional.calls);
+ }
+
+ @Test
+ void unknownParseResultKeepsHandlingEveryPlugin() {
+ assertTrue(HopConfigBase.hasMatchedOption(null, null));
+ CommandLine cmd = new CommandLine(new FirstOptions());
+ CommandLine.ParseResult parseResult = cmd.parseArgs();
+ assertFalse(HopConfigBase.hasMatchedOption(parseResult,
cmd.getCommandSpec()));
+ }
+
+ @CommandLine.Command
+ static class RootCommand {}
+
+ @CommandLine.Command
+ static class TestConfig extends HopConfigBase {}
+
+ static class FirstOptions implements IConfigOptions {
+ @CommandLine.Option(names = "--first")
+ String first;
+
+ int calls;
+
+ @Override
+ public boolean handleOption(
+ ILogChannel log, IHasHopMetadataProvider hasHopMetadataProvider,
IVariables variables) {
+ calls++;
+ return true;
+ }
+ }
+
+ static class PositionalOptions implements IConfigOptions {
+ @CommandLine.Parameters(arity = "0..1")
+ String value;
+
+ int calls;
+
+ @Override
+ public boolean handleOption(
+ ILogChannel log, IHasHopMetadataProvider hasHopMetadataProvider,
IVariables variables) {
+ calls++;
+ return true;
+ }
+ }
+
+ static class SecondOptions implements IConfigOptions {
+ @CommandLine.Option(names = "--second")
+ boolean second;
+
+ int calls;
+
+ @Override
+ public boolean handleOption(
+ ILogChannel log, IHasHopMetadataProvider hasHopMetadataProvider,
IVariables variables) {
+ calls++;
+ return true;
+ }
+ }
+}
diff --git
a/plugins/misc/lint/src/main/java/org/apache/hop/lint/LinterConfigPlugin.java
b/plugins/misc/lint/src/main/java/org/apache/hop/lint/LinterConfigPlugin.java
index 194304ac2a..83eb369e77 100644
---
a/plugins/misc/lint/src/main/java/org/apache/hop/lint/LinterConfigPlugin.java
+++
b/plugins/misc/lint/src/main/java/org/apache/hop/lint/LinterConfigPlugin.java
@@ -420,11 +420,8 @@ public class LinterConfigPlugin implements IConfigOptions,
IGuiPluginCompositeWi
}
/**
- * Called by the configuration perspective when the user applies changes,
and by {@code hop conf}
- * for every registered config plugin whether or not it was given any
options.
- *
- * <p>Because {@code hop conf} calls this unconditionally, doing anything
when nothing was set
- * would rewrite the linter settings on every unrelated {@code hop conf}
command.
+ * Called by {@code hop conf} when at least one of the linter options was
given. The fields hold
+ * the stored settings for the options that weren't, so those are saved
unchanged.
*/
@Override
public boolean handleOption(
diff --git
a/plugins/misc/projects/src/main/java/org/apache/hop/projects/environment/ManageEnvironmentsOptionPlugin.java
b/plugins/misc/projects/src/main/java/org/apache/hop/projects/environment/ManageEnvironmentsOptionPlugin.java
index c32fa4d6d4..2564ef939a 100644
---
a/plugins/misc/projects/src/main/java/org/apache/hop/projects/environment/ManageEnvironmentsOptionPlugin.java
+++
b/plugins/misc/projects/src/main/java/org/apache/hop/projects/environment/ManageEnvironmentsOptionPlugin.java
@@ -17,6 +17,7 @@
package org.apache.hop.projects.environment;
+import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
@@ -212,7 +213,6 @@ public class ManageEnvironmentsOptionPlugin implements
IConfigOptions {
}
enableProject(log, environment, variables, hasHopMetadataProvider, config);
- validateConfigFiles(log, variables, environment);
}
private void createEnvironment(
@@ -233,34 +233,58 @@ public class ManageEnvironmentsOptionPlugin implements
IConfigOptions {
updateEnvironmentDetails(environment, variables);
- config.addEnvironment(environment);
- ProjectsConfigSingleton.saveConfig();
+ try {
+ config.addEnvironment(environment);
+ ProjectsConfigSingleton.saveConfig();
+
+ enableProject(log, environment, variables, hasHopMetadataProvider,
config);
+ } catch (Exception e) {
+ // Don't leave a registered environment behind: a retry would fail with
"already exists".
+ //
+ try {
+ config.removeEnvironment(environmentName);
+ ProjectsConfigSingleton.saveConfig();
+ } catch (Exception rollbackException) {
+ e.addSuppressed(rollbackException);
+ }
+ throw e;
+ }
log.logBasic(
CONST_ENVIRONMENT
+ environmentName
+ "' was created in Hop configuration file "
+ HopConfig.getInstance().getConfigFilename());
-
- enableProject(log, environment, variables, hasHopMetadataProvider, config);
-
- validateConfigFiles(log, variables, environment);
logEnvironmentDetails(log, environment);
}
+ /**
+ * Create the environment's missing configuration files, then enable its
project with them.
+ *
+ * <p>The project variables are applied before the files are created, since
a configuration file
+ * path can refer to them (for example '${PROJECT_HOME}'). Enabling the
project reads the files,
+ * so they have to exist by then.
+ */
private void enableProject(
ILogChannel log,
LifecycleEnvironment environment,
IVariables variables,
IHasHopMetadataProvider hasHopMetadataProvider,
ProjectsConfig config)
- throws HopException {
+ throws Exception {
ProjectConfig projectConfig =
config.findProjectConfig(environment.getProjectName());
if (projectConfig == null) {
log.logBasic(
"Warning: referenced project '" + environment.getProjectName() + "'
doesn't exist");
+ validateConfigFiles(log, variables, environment);
} else {
Project project = projectConfig.loadProject(variables);
+ // Project variables only, so '${PROJECT_HOME}' in the configuration
file paths resolves.
+ // enableProject() below applies them again, together with the
configuration files.
+ //
+ project.modifyVariables(variables, projectConfig, new ArrayList<>(),
environmentName);
+
+ validateConfigFiles(log, variables, environment);
// Change variables, metadata, ... for the project
//
@@ -282,6 +306,16 @@ public class ManageEnvironmentsOptionPlugin implements
IConfigOptions {
}
for (String environmentConfigFilename :
environment.getConfigurationFiles()) {
String realEnvConfFilename =
variables.resolve(environmentConfigFilename);
+ // For example '${PROJECT_HOME}' when the project doesn't exist:
creating the file would
+ // create a folder literally called '${PROJECT_HOME}'.
+ //
+ if (StringUtil.containsVariableToken(realEnvConfFilename)) {
+ log.logBasic(
+ "Warning: environment configuration file '"
+ + realEnvConfFilename
+ + "' was not created, it refers to a variable that isn't set");
+ continue;
+ }
DescribedVariablesConfigFile variablesConfigFile =
new DescribedVariablesConfigFile(realEnvConfFilename);
// Create the config file if it doesn't exist
diff --git
a/plugins/misc/projects/src/main/java/org/apache/hop/projects/project/ManageProjectsOptionPlugin.java
b/plugins/misc/projects/src/main/java/org/apache/hop/projects/project/ManageProjectsOptionPlugin.java
index f4b4c9527d..ea8dde5038 100644
---
a/plugins/misc/projects/src/main/java/org/apache/hop/projects/project/ManageProjectsOptionPlugin.java
+++
b/plugins/misc/projects/src/main/java/org/apache/hop/projects/project/ManageProjectsOptionPlugin.java
@@ -201,7 +201,7 @@ public class ManageProjectsOptionPlugin implements
IConfigOptions {
}
return changed;
} catch (Exception e) {
- throw new HopException("Error handling environment configuration
options", e);
+ throw new HopException("Error handling project configuration options",
e);
}
}
@@ -265,7 +265,7 @@ public class ManageProjectsOptionPlugin implements
IConfigOptions {
config.removeProjectConfig(projectName);
ProjectsConfigSingleton.saveConfig();
- log.logBasic(CONST_PROJECT + projectName + " was removed from the
configuration");
+ log.logBasic(CONST_PROJECT + projectName + "' was removed from the
configuration");
}
private void modifyProject(ILogChannel log, ProjectsConfig config,
IVariables variables)
@@ -387,39 +387,54 @@ public class ManageProjectsOptionPlugin implements
IConfigOptions {
new ProjectConfig(
projectName, projectHome, Const.NVL(projectConfigFile,
defaultProjectConfigFilename));
- config.addProjectConfig(projectConfig);
- ProjectsConfigSingleton.saveConfig();
-
- log.logBasic(CONST_PROJECT + projectName + "' was created for home folder
: " + projectHome);
-
+ // This fails when the home folder doesn't exist: do it before the project
is registered.
+ //
String configFilename =
projectConfig.getActualProjectConfigFilename(variables);
boolean configFileExisted = false;
try (FileObject configFile = HopVfs.getFileObject(configFilename)) {
configFileExisted = configFile.exists();
}
- Project project = projectConfig.loadProject(variables);
- // Keep an existing parent from a pre-existing project-config.json (Docker
- // --project-keep-config-file). Only fall back to the standard parent when
none is set.
- // --project-parent still wins via modifyProjectSettings below.
- //
- if (StringUtils.isEmpty(project.getParentProjectName())) {
-
project.setParentProjectName(config.findRegisteredStandardParentProject());
- }
- // A brand-new config file starts from the project name. An existing file
keeps its id,
- // including none, so a 2.19.0 project is not switched on to execution
filtering.
- if (!configFileExisted && StringUtils.isEmpty(project.getProjectId())) {
- project.setProjectId(projectName);
- }
- modifyProjectSettings(project);
- // Check to see if there's not a loop in the project parent hierarchy
- //
- project.verifyProjectsChain(projectName, variables);
+ Project project;
+ try {
+ config.addProjectConfig(projectConfig);
+ ProjectsConfigSingleton.saveConfig();
- // Always save, even if it's an empty file
- //
- project.saveToFile(projectKeepConfigFile);
+ project = projectConfig.loadProject(variables);
+ // Keep an existing parent from a pre-existing project-config.json
(Docker
+ // --project-keep-config-file). Only fall back to the standard parent
when none is set.
+ // --project-parent still wins via modifyProjectSettings below.
+ //
+ if (StringUtils.isEmpty(project.getParentProjectName())) {
+
project.setParentProjectName(config.findRegisteredStandardParentProject());
+ }
+ // A brand-new config file starts from the project name. An existing
file keeps its id,
+ // including none, so a 2.19.0 project is not switched on to execution
filtering.
+ if (!configFileExisted && StringUtils.isEmpty(project.getProjectId())) {
+ project.setProjectId(projectName);
+ }
+ modifyProjectSettings(project);
+
+ // Check to see if there's not a loop in the project parent hierarchy
+ //
+ project.verifyProjectsChain(projectName, variables);
+
+ // Always save, even if it's an empty file
+ //
+ project.saveToFile(projectKeepConfigFile);
+ } catch (Exception e) {
+ // Don't leave a registered project without a configuration file behind.
+ //
+ try {
+ config.removeProjectConfig(projectName);
+ ProjectsConfigSingleton.saveConfig();
+ } catch (Exception rollbackException) {
+ e.addSuppressed(rollbackException);
+ }
+ throw e;
+ }
+ log.logBasic(CONST_PROJECT + projectName + "' was created for home folder
: " + projectHome);
log.logBasic(
"Configuration file for project '"
+ projectName
diff --git
a/plugins/misc/projects/src/test/java/org/apache/hop/projects/environment/ManageEnvironmentsOptionPluginTest.java
b/plugins/misc/projects/src/test/java/org/apache/hop/projects/environment/ManageEnvironmentsOptionPluginTest.java
index 2995ac7ac3..e725006439 100644
---
a/plugins/misc/projects/src/test/java/org/apache/hop/projects/environment/ManageEnvironmentsOptionPluginTest.java
+++
b/plugins/misc/projects/src/test/java/org/apache/hop/projects/environment/ManageEnvironmentsOptionPluginTest.java
@@ -18,19 +18,24 @@
package org.apache.hop.projects.environment;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.ArrayList;
import java.util.List;
import org.apache.hop.core.config.HopConfig;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.logging.HopLogStore;
+import org.apache.hop.core.logging.IHopLoggingEventListener;
import org.apache.hop.core.logging.LogChannel;
+import org.apache.hop.core.logging.LogLevel;
import org.apache.hop.core.variables.Variables;
import org.apache.hop.projects.config.ProjectsConfigSingleton;
+import org.apache.hop.projects.project.ProjectConfig;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -122,4 +127,97 @@ class ManageEnvironmentsOptionPluginTest {
HopConfig.setInMemoryMode(false);
}
}
+
+ @Test
+ void createEnvironmentCreatesAMissingConfigFileBeforeReadingIt() throws
Exception {
+ // #9007: the file was read, and an error logged, before it was created
+ //
+ Files.writeString(tempDir.resolve("project-config.json"), "{}");
+ String projectName = "issue-9007-project-" + System.nanoTime();
+ String name = "issue-9007-" + System.nanoTime();
+ List<String> errors = new ArrayList<>();
+ IHopLoggingEventListener listener =
+ event -> {
+ if (event.getLevel() == LogLevel.ERROR) {
+ errors.add(String.valueOf(event.getMessage()));
+ }
+ };
+ HopConfig.setInMemoryMode(true);
+ HopLogStore.getAppender().addLoggingEventListener(listener);
+ try {
+ ProjectsConfigSingleton.getConfig()
+ .addProjectConfig(
+ new ProjectConfig(projectName, tempDir.toString(),
"project-config.json"));
+
+ ManageEnvironmentsOptionPlugin plugin = new
ManageEnvironmentsOptionPlugin();
+ new CommandLine(plugin)
+ .parseArgs(
+ "--environment-create",
+ "--environment=" + name,
+ "--environment-project=" + projectName,
+ "--environment-config-files=${PROJECT_HOME}/dev-config.json");
+
+ assertTrue(plugin.handleOption(LogChannel.GENERAL, null, new
Variables()));
+
+ assertTrue(Files.exists(tempDir.resolve("dev-config.json")));
+ assertFalse(
+ errors.stream().anyMatch(message -> message.contains("does not
exist")),
+ errors.toString());
+ } finally {
+ HopLogStore.getAppender().removeLoggingEventListener(listener);
+ ProjectsConfigSingleton.getConfig().removeEnvironment(name);
+ ProjectsConfigSingleton.getConfig().removeProjectConfig(projectName);
+ HopConfig.setInMemoryMode(false);
+ }
+ }
+
+ @Test
+ void createThatFailsAfterRegisteringRollsTheEnvironmentBack() throws
Exception {
+ // A regular file where the configuration file's folder should be:
creating it fails.
+ //
+ Files.writeString(tempDir.resolve("blocker"), "not a folder");
+ String name = "issue-9007-rollback-" + System.nanoTime();
+ HopConfig.setInMemoryMode(true);
+ try {
+ ManageEnvironmentsOptionPlugin plugin = new
ManageEnvironmentsOptionPlugin();
+ new CommandLine(plugin)
+ .parseArgs(
+ "--environment-create",
+ "--environment=" + name,
+ "--environment-project=missing-project",
+ "--environment-config-files=" +
tempDir.resolve("blocker").resolve("dev.json"));
+
+ assertThrows(
+ HopException.class, () -> plugin.handleOption(LogChannel.GENERAL,
null, new Variables()));
+ assertNull(ProjectsConfigSingleton.getConfig().findEnvironment(name));
+ } finally {
+ ProjectsConfigSingleton.getConfig().removeEnvironment(name);
+ HopConfig.setInMemoryMode(false);
+ }
+ }
+
+ @Test
+ void createDoesNotCreateAConfigFileWithAnUnresolvedVariable() throws
Exception {
+ String name = "issue-9007-unresolved-" + System.nanoTime();
+ HopConfig.setInMemoryMode(true);
+ try {
+ ManageEnvironmentsOptionPlugin plugin = new
ManageEnvironmentsOptionPlugin();
+ new CommandLine(plugin)
+ .parseArgs(
+ "--environment-create",
+ "--environment=" + name,
+ "--environment-project=missing-project",
+ "--environment-config-files=" + tempDir +
"/${ISSUE_9007_UNSET}/dev.json");
+
+ assertTrue(plugin.handleOption(LogChannel.GENERAL, null, new
Variables()));
+
+ assertFalse(Files.exists(tempDir.resolve("${ISSUE_9007_UNSET}")));
+ assertEquals(
+ List.of(tempDir + "/${ISSUE_9007_UNSET}/dev.json"),
+
ProjectsConfigSingleton.getConfig().findEnvironment(name).getConfigurationFiles());
+ } finally {
+ ProjectsConfigSingleton.getConfig().removeEnvironment(name);
+ HopConfig.setInMemoryMode(false);
+ }
+ }
}
diff --git
a/plugins/misc/projects/src/test/java/org/apache/hop/projects/project/ManageProjectsOptionPluginTest.java
b/plugins/misc/projects/src/test/java/org/apache/hop/projects/project/ManageProjectsOptionPluginTest.java
new file mode 100644
index 0000000000..1360e8db5e
--- /dev/null
+++
b/plugins/misc/projects/src/test/java/org/apache/hop/projects/project/ManageProjectsOptionPluginTest.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.projects.project;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.CALLS_REAL_METHODS;
+import static org.mockito.Mockito.mockStatic;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import org.apache.hop.core.config.HopConfig;
+import org.apache.hop.core.exception.HopException;
+import org.apache.hop.core.logging.HopLogStore;
+import org.apache.hop.core.logging.LogChannel;
+import org.apache.hop.core.variables.Variables;
+import org.apache.hop.projects.config.ProjectsConfigSingleton;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.mockito.MockedStatic;
+import picocli.CommandLine;
+
+class ManageProjectsOptionPluginTest {
+
+ @TempDir Path tempDir;
+
+ @BeforeAll
+ static void beforeAll() {
+ HopLogStore.init();
+ }
+
+ @Test
+ void createWithAMissingHomeFolderDoesNotRegisterTheProject() {
+ String name = "issue-9007-" + System.nanoTime();
+ Path missingHome = tempDir.resolve("missing");
+ HopConfig.setInMemoryMode(true);
+ try {
+ ManageProjectsOptionPlugin plugin = new ManageProjectsOptionPlugin();
+ new CommandLine(plugin)
+ .parseArgs("--project-create", "--project=" + name,
"--project-home=" + missingHome);
+
+ HopException exception =
+ assertThrows(
+ HopException.class,
+ () -> plugin.handleOption(LogChannel.GENERAL, null, new
Variables()));
+ assertTrue(exception.getCause().getMessage().contains("does not exist"));
+ assertNull(ProjectsConfigSingleton.getConfig().findProjectConfig(name));
+ } finally {
+ ProjectsConfigSingleton.getConfig().removeProjectConfig(name);
+ HopConfig.setInMemoryMode(false);
+ }
+ }
+
+ @Test
+ void createThatFailsAfterRegisteringRollsTheProjectBack() {
+ String name = "issue-9007-parent-" + System.nanoTime();
+ HopConfig.setInMemoryMode(true);
+ try {
+ ManageProjectsOptionPlugin plugin = new ManageProjectsOptionPlugin();
+ new CommandLine(plugin)
+ .parseArgs(
+ "--project-create",
+ "--project=" + name,
+ "--project-home=" + tempDir,
+ "--project-parent=" + name);
+
+ HopException exception =
+ assertThrows(
+ HopException.class,
+ () -> plugin.handleOption(LogChannel.GENERAL, null, new
Variables()));
+ assertTrue(exception.getCause().getMessage().contains("can not be the
same"));
+ assertNull(ProjectsConfigSingleton.getConfig().findProjectConfig(name));
+ assertFalse(Files.exists(tempDir.resolve("project-config.json")));
+ } finally {
+ ProjectsConfigSingleton.getConfig().removeProjectConfig(name);
+ HopConfig.setInMemoryMode(false);
+ }
+ }
+
+ @Test
+ void createThatCannotSaveTheHopConfigDoesNotKeepTheProject() {
+ String name = "issue-9007-save-" + System.nanoTime();
+ HopConfig.setInMemoryMode(true);
+ try (MockedStatic<ProjectsConfigSingleton> singleton =
+ mockStatic(ProjectsConfigSingleton.class, CALLS_REAL_METHODS)) {
+ singleton
+ .when(ProjectsConfigSingleton::saveConfig)
+ .thenThrow(new HopException("hop-config.json is not writable"));
+ ManageProjectsOptionPlugin plugin = new ManageProjectsOptionPlugin();
+ new CommandLine(plugin)
+ .parseArgs("--project-create", "--project=" + name,
"--project-home=" + tempDir);
+
+ assertThrows(
+ HopException.class, () -> plugin.handleOption(LogChannel.GENERAL,
null, new Variables()));
+ assertNull(ProjectsConfigSingleton.getConfig().findProjectConfig(name));
+ } finally {
+ ProjectsConfigSingleton.getConfig().removeProjectConfig(name);
+ HopConfig.setInMemoryMode(false);
+ }
+ }
+}
diff --git
a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/config/ExplorerPerspectiveConfigPlugin.java
b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/config/ExplorerPerspectiveConfigPlugin.java
index b1a6206c3e..4f3aa7cde3 100644
---
a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/config/ExplorerPerspectiveConfigPlugin.java
+++
b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/config/ExplorerPerspectiveConfigPlugin.java
@@ -96,7 +96,7 @@ public class ExplorerPerspectiveConfigPlugin
@CommandLine.Option(
names = {"-exv", "--explorer-file-explorer-visible-by-default"},
description = "Show the file explorer panel by default in the explorer
perspective")
- private Boolean fileExplorerVisibleByDefault = true;
+ private Boolean fileExplorerVisibleByDefault;
@GuiWidgetElement(
id = WIDGET_ID_OPEN_HELP_FILES,
@@ -126,7 +126,7 @@ public class ExplorerPerspectiveConfigPlugin
@CommandLine.Option(
names = {"-exafs", "--explorer-active-file-selection"},
description = "Automatically select the active tab file in the file
explorer tree")
- private Boolean activeFileSelection = true;
+ private Boolean activeFileSelection;
@GuiWidgetElement(
id = WIDGET_ID_MAX_UNDO,
diff --git
a/ui/src/main/java/org/apache/hop/ui/hopgui/search/config/SearchConfigPlugin.java
b/ui/src/main/java/org/apache/hop/ui/hopgui/search/config/SearchConfigPlugin.java
index 5aebf7f43b..470fe947e9 100644
---
a/ui/src/main/java/org/apache/hop/ui/hopgui/search/config/SearchConfigPlugin.java
+++
b/ui/src/main/java/org/apache/hop/ui/hopgui/search/config/SearchConfigPlugin.java
@@ -120,7 +120,7 @@ public class SearchConfigPlugin implements IConfigOptions,
IGuiPluginCompositeWi
names = {"-sit", "--search-include-project-text-files"},
description = "Include project text files (CSV, JSON, …) in Hop GUI
content search",
negatable = true)
- private Boolean includeProjectTextFiles = true;
+ private Boolean includeProjectTextFiles;
@GuiWidgetElement(
id = WIDGET_ID_SEARCH_AS_YOU_TYPE,
@@ -132,7 +132,7 @@ public class SearchConfigPlugin implements IConfigOptions,
IGuiPluginCompositeWi
names = {"-sat", "--search-as-you-type"},
description = "Run Hop GUI search while typing (debounced)",
negatable = true)
- private Boolean searchAsYouType = true;
+ private Boolean searchAsYouType;
@GuiWidgetElement(
id = WIDGET_ID_DEBOUNCE_MS,
diff --git
a/ui/src/test/java/org/apache/hop/ui/hopgui/perspective/explorer/config/ExplorerPerspectiveConfigPluginTest.java
b/ui/src/test/java/org/apache/hop/ui/hopgui/perspective/explorer/config/ExplorerPerspectiveConfigPluginTest.java
new file mode 100644
index 0000000000..4fb636d951
--- /dev/null
+++
b/ui/src/test/java/org/apache/hop/ui/hopgui/perspective/explorer/config/ExplorerPerspectiveConfigPluginTest.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.ui.hopgui.perspective.explorer.config;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.hop.core.config.HopConfig;
+import org.apache.hop.core.logging.HopLogStore;
+import org.apache.hop.core.logging.LogChannel;
+import org.apache.hop.core.variables.Variables;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import picocli.CommandLine;
+
+/** The explorer checkboxes are only changed by hop-conf when their option is
given (#9007). */
+class ExplorerPerspectiveConfigPluginTest {
+
+ private String originalLazyLoadingDepth;
+ private Boolean originalVisibleByDefault;
+ private Boolean originalActiveFileSelection;
+
+ @BeforeAll
+ static void beforeAll() {
+ HopLogStore.init();
+ }
+
+ @BeforeEach
+ void inMemory() {
+ HopConfig.setInMemoryMode(true);
+ ExplorerPerspectiveConfig config =
ExplorerPerspectiveConfigSingleton.getConfig();
+ originalLazyLoadingDepth = config.getLazyLoadingDepth();
+ originalVisibleByDefault = config.getFileExplorerVisibleByDefault();
+ originalActiveFileSelection = config.getActiveFileSelection();
+ }
+
+ @AfterEach
+ void restore() {
+ ExplorerPerspectiveConfig config =
ExplorerPerspectiveConfigSingleton.getConfig();
+ config.setLazyLoadingDepth(originalLazyLoadingDepth);
+ config.setFileExplorerVisibleByDefault(originalVisibleByDefault);
+ config.setActiveFileSelection(originalActiveFileSelection);
+ HopConfig.setInMemoryMode(false);
+ }
+
+ @Test
+ void otherOptionKeepsTheCheckboxSettings() throws Exception {
+ ExplorerPerspectiveConfig config =
ExplorerPerspectiveConfigSingleton.getConfig();
+ config.setFileExplorerVisibleByDefault(false);
+ config.setActiveFileSelection(false);
+
+ assertTrue(handle("--explorer-lazy-loading-initial-depth=2"));
+
+ assertEquals("2", config.getLazyLoadingDepth());
+ assertFalse(config.getFileExplorerVisibleByDefault());
+ assertFalse(config.getActiveFileSelection());
+ }
+
+ @Test
+ void flagsWithoutAValueEnable() throws Exception {
+ ExplorerPerspectiveConfig config =
ExplorerPerspectiveConfigSingleton.getConfig();
+ config.setFileExplorerVisibleByDefault(false);
+ config.setActiveFileSelection(false);
+
+ assertTrue(handle("-exv", "-exafs"));
+
+ assertTrue(config.getFileExplorerVisibleByDefault());
+ assertTrue(config.getActiveFileSelection());
+ }
+
+ @Test
+ void flagsWithFalseDisable() throws Exception {
+ ExplorerPerspectiveConfig config =
ExplorerPerspectiveConfigSingleton.getConfig();
+ config.setFileExplorerVisibleByDefault(true);
+ config.setActiveFileSelection(true);
+
+ assertTrue(handle("-exv=false", "-exafs=false"));
+
+ assertFalse(config.getFileExplorerVisibleByDefault());
+ assertFalse(config.getActiveFileSelection());
+ }
+
+ private static boolean handle(String... args) throws Exception {
+ ExplorerPerspectiveConfigPlugin plugin = new
ExplorerPerspectiveConfigPlugin();
+ new CommandLine(plugin).parseArgs(args);
+ return plugin.handleOption(LogChannel.GENERAL, null, new Variables());
+ }
+}
diff --git
a/ui/src/test/java/org/apache/hop/ui/hopgui/search/config/SearchConfigPluginTest.java
b/ui/src/test/java/org/apache/hop/ui/hopgui/search/config/SearchConfigPluginTest.java
new file mode 100644
index 0000000000..1a2d113d4b
--- /dev/null
+++
b/ui/src/test/java/org/apache/hop/ui/hopgui/search/config/SearchConfigPluginTest.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.ui.hopgui.search.config;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.hop.core.config.HopConfig;
+import org.apache.hop.core.logging.HopLogStore;
+import org.apache.hop.core.logging.LogChannel;
+import org.apache.hop.core.variables.Variables;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import picocli.CommandLine;
+
+/** The search checkboxes are only changed by hop-conf when their option is
given (#9007). */
+class SearchConfigPluginTest {
+
+ private Boolean originalSearchAsYouType;
+ private Boolean originalIncludeProjectTextFiles;
+ private String originalMaxResults;
+
+ @BeforeAll
+ static void beforeAll() {
+ HopLogStore.init();
+ }
+
+ @BeforeEach
+ void inMemory() {
+ HopConfig.setInMemoryMode(true);
+ SearchConfig config = SearchConfigSingleton.getConfig();
+ originalSearchAsYouType = config.getSearchAsYouType();
+ originalIncludeProjectTextFiles = config.getIncludeProjectTextFiles();
+ originalMaxResults = config.getMaxResults();
+ }
+
+ @AfterEach
+ void restore() {
+ SearchConfig config = SearchConfigSingleton.getConfig();
+ config.setSearchAsYouType(originalSearchAsYouType);
+ config.setIncludeProjectTextFiles(originalIncludeProjectTextFiles);
+ config.setMaxResults(originalMaxResults);
+ HopConfig.setInMemoryMode(false);
+ }
+
+ @Test
+ void checkboxOptionsAreUnsetUnlessGiven() {
+ SearchConfigPlugin plugin = parse("--search-max-results=10");
+ assertNull(plugin.getSearchAsYouType());
+ assertNull(plugin.getIncludeProjectTextFiles());
+ }
+
+ @Test
+ void negatedOptionsDisable() {
+ SearchConfigPlugin plugin =
+ parse("--no-search-as-you-type",
"--no-search-include-project-text-files");
+ assertFalse(plugin.getSearchAsYouType());
+ assertFalse(plugin.getIncludeProjectTextFiles());
+ }
+
+ @Test
+ void optionsEnable() {
+ SearchConfigPlugin plugin =
+ parse("--search-as-you-type", "--search-include-project-text-files");
+ assertTrue(plugin.getSearchAsYouType());
+ assertTrue(plugin.getIncludeProjectTextFiles());
+ }
+
+ @Test
+ void otherOptionKeepsTheCheckboxSettings() throws Exception {
+ SearchConfig config = SearchConfigSingleton.getConfig();
+ config.setSearchAsYouType(false);
+ config.setIncludeProjectTextFiles(false);
+
+ SearchConfigPlugin plugin = parse("--search-max-results=10");
+ assertTrue(plugin.handleOption(LogChannel.GENERAL, null, new Variables()));
+
+ assertEquals("10", config.getMaxResults());
+ assertFalse(config.getSearchAsYouType());
+ assertFalse(config.getIncludeProjectTextFiles());
+ }
+
+ private static SearchConfigPlugin parse(String... args) {
+ SearchConfigPlugin plugin = new SearchConfigPlugin();
+ new CommandLine(plugin).parseArgs(args);
+ return plugin;
+ }
+}