hansva commented on code in PR #9289:
URL: https://github.com/apache/hop/pull/9289#discussion_r4491060258
##########
plugins/misc/projects/src/main/java/org/apache/hop/projects/project/ManageProjectsOptionPlugin.java:
##########
@@ -387,16 +387,19 @@ private void createProject(ILogChannel log,
ProjectsConfig config, IVariables va
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();
}
+
+ config.addProjectConfig(projectConfig);
Review Comment:
**Should fix:** moving the home-folder check up fixes the issue's example,
but `loadProject`, `verifyProjectsChain` and `saveToFile` still run after the
project is registered and saved here. If one of them fails, the project stays
registered with no config file.
Example: `--project-create --project=x --project-home=<existing folder>
--project-parent=x` prints "Project 'x' was created", then fails with "Parent
project 'x' can not be the same as the project itself". `--projects-list` then
shows `x : null`.
Suggestion: wrap everything after `saveConfig()` in a try/catch that undoes
the registration and rethrows:
```java
try {
// loadProject ... saveToFile as now
} catch (Exception e) {
config.removeProjectConfig(projectName);
ProjectsConfigSingleton.saveConfig();
throw e;
}
```
Moving the registration to the end is riskier, because `verifyProjectsChain`
looks parents up in the registered config. A test for the `--project-parent=x`
case would cover it, like
`createWithAMissingHomeFolderDoesNotRegisterTheProject`.
##########
plugins/misc/projects/src/main/java/org/apache/hop/projects/environment/ManageEnvironmentsOptionPlugin.java:
##########
@@ -243,24 +243,33 @@ private void createEnvironment(
+ 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.modifyVariables(variables, projectConfig, new ArrayList<>(),
environmentName);
Review Comment:
**Nit:** `ProjectsUtil.enableProject` below calls `modifyVariables` again
with the real configuration files. The result is the same, but a broken parent
project now logs its error twice. That's fine to leave; a short comment here
would explain why the first call is needed (for `'${PROJECT_HOME}'` in the
configuration file paths).
--
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]