Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ public void modifyVariables(
variables.setVariable(ProjectsUtil.VARIABLE_PROJECT_HOME, realValue);
}

// Project variables can be used in environment configuration file paths.
//
applyProjectVariables(variables);

// Apply the described variables from the various configuration files in the given order...
//
for (String configurationFile : configurationFiles) {
Expand Down Expand Up @@ -314,6 +318,12 @@ public void modifyVariables(
String realValue = variables.resolve(dataSetsCsvFolder);
variables.setVariable(ProjectsUtil.VARIABLE_HOP_DATASETS_FOLDER, realValue);
}
// Keep project variables as the final values when a configuration file defines the same name.
//
applyProjectVariables(variables);
}

private void applyProjectVariables(IVariables variables) {
for (DescribedVariable variable : getDescribedVariables()) {
if (variable.getName() != null) {
variables.setVariable(variable.getName(), variable.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.apache.hop.core.config.DescribedVariablesConfigFile;
import org.apache.hop.core.logging.HopLogStore;
import org.apache.hop.core.variables.DescribedVariable;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.core.variables.Variables;
import org.apache.hop.projects.config.ProjectsConfig;
Expand Down Expand Up @@ -200,6 +203,37 @@ public void testParentProjectVariablesImmediateParentOnly() throws Exception {
assertEquals(childHome.toString(), variables.getVariable(ProjectsUtil.VARIABLE_PROJECT_HOME));
}

@Test
public void testProjectVariableResolvesEnvironmentConfigurationFilePath() throws Exception {
HopLogStore.init();
tempRoot = Files.createTempDirectory("hop-project-environment-variable");
Path projectHome = tempRoot.resolve("project");
Path configFolder = projectHome.resolve("config");
Files.createDirectories(configFolder);

Path environmentFile = configFolder.resolve("environment.json");
DescribedVariablesConfigFile configFile =
new DescribedVariablesConfigFile(environmentFile.toString());
configFile.setDescribedVariable(new DescribedVariable("ENVIRONMENT_VALUE", "loaded", ""));
configFile.saveToFile();

ProjectConfig projectConfig =
new ProjectConfig(
"project", projectHome.toString(), ProjectsConfig.DEFAULT_PROJECT_CONFIG_FILENAME);
Project project = new Project();
project
.getDescribedVariables()
.add(
new DescribedVariable(
"CONFIG_HOME", "${" + ProjectsUtil.VARIABLE_PROJECT_HOME + "}/config", ""));

IVariables variables = new Variables();
project.modifyVariables(
variables, projectConfig, java.util.List.of("${CONFIG_HOME}/environment.json"), "dev");

assertEquals("loaded", variables.getVariable("ENVIRONMENT_VALUE"));
}

@Test
public void testParentProjectFoldersSerialization() throws Exception {
File tempFile = Files.createTempFile("project-config-parent-folders", ".json").toFile();
Expand Down
Loading