diff --git a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/SetEnableTechnologiesVariableAction.java b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/SetEnableTechnologiesVariableAction.java index 2900beabc315949c073bffa474f38fbb46482ef6..cc364e8797ed85de66a2434d1a8c7349fe579e22 100644 --- a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/SetEnableTechnologiesVariableAction.java +++ b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/SetEnableTechnologiesVariableAction.java @@ -19,6 +19,11 @@ package ch.systemsx.cisd.openbis.installer.izpack; import static ch.systemsx.cisd.openbis.installer.izpack.SetTechnologyCheckBoxesAction.ENABLED_TECHNOLOGIES_KEY; import java.io.File; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; import com.izforge.izpack.api.data.AutomatedInstallData; import com.izforge.izpack.api.data.PanelActionConfiguration; @@ -68,10 +73,10 @@ public class SetEnableTechnologiesVariableAction implements PanelAction if (isFirstTimeInstallation == false) { File asConfigFile = new File(installDir, Utils.AS_PATH + Utils.SERVICE_PROPERTIES_PATH); - Utils.updateOrAppendProperty(asConfigFile, ENABLED_TECHNOLOGIES_KEY, newTechnologyList); + modifyPropertyEnabledTechnologies(asConfigFile, data); File dssConfigFile = new File(installDir, Utils.DSS_PATH + Utils.SERVICE_PROPERTIES_PATH); - Utils.updateOrAppendProperty(dssConfigFile, ENABLED_TECHNOLOGIES_KEY, newTechnologyList); + modifyPropertyEnabledTechnologies(dssConfigFile, data); } } @@ -89,4 +94,39 @@ public class SetEnableTechnologiesVariableAction implements PanelAction return builder.toString(); } + private void modifyPropertyEnabledTechnologies(File configFile, AutomatedInstallData data) + { + Set<String> allTechnologies = new HashSet<String>(); + CommaSeparatedListBuilder builder = new CommaSeparatedListBuilder(); + for (String technology : GlobalInstallationContext.TECHNOLOGIES) + { + String lowerCasedTechnology = technology.toLowerCase(); + allTechnologies.add(lowerCasedTechnology); + String technologyFlag = data.getVariable(technology); + if (Boolean.TRUE.toString().equalsIgnoreCase(technologyFlag)) + { + builder.append(lowerCasedTechnology); + } + } + Properties properties = Utils.tryToGetProperties(configFile); + if (properties != null) + { + String property = properties.getProperty(ENABLED_TECHNOLOGIES_KEY); + if (StringUtils.isNotBlank(property)) + { + String[] splittedProperty = property.split(","); + for (String term : splittedProperty) + { + String trimmedTerm = term.trim(); + if (allTechnologies.contains(trimmedTerm) == false) + { + builder.append(trimmedTerm); + } + } + } + } + Utils.updateOrAppendProperty(configFile, ENABLED_TECHNOLOGIES_KEY, builder.toString()); + } + + } diff --git a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/Utils.java b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/Utils.java index 67db2c2a8d62d2832e95ffe63d3afd24fe295c17..58143e61c9e967d3f0d82074538670a57896ab1c 100644 --- a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/Utils.java +++ b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/Utils.java @@ -98,12 +98,17 @@ class Utils } private static Properties tryToGetServiceProperties(File installDir, String relativePath) + { + return tryToGetProperties(new File(installDir, relativePath)); + } + + public static Properties tryToGetProperties(File configFile) { Properties properties = new Properties(); FileReader fileReader = null; try { - fileReader = new FileReader(new File(installDir, relativePath)); + fileReader = new FileReader(configFile); properties.load(fileReader); return properties; } catch (Exception ex) diff --git a/installation/sourceTest/java/ch/systemsx/cisd/openbis/installer/izpack/SetEnableTechnologiesVariableActionTest.java b/installation/sourceTest/java/ch/systemsx/cisd/openbis/installer/izpack/SetEnableTechnologiesVariableActionTest.java index c8103b132e4d0aa21e8d2383cef8b89b651de5ee..9c7bc8f010d81f4f00221e7414460853f64876e7 100644 --- a/installation/sourceTest/java/ch/systemsx/cisd/openbis/installer/izpack/SetEnableTechnologiesVariableActionTest.java +++ b/installation/sourceTest/java/ch/systemsx/cisd/openbis/installer/izpack/SetEnableTechnologiesVariableActionTest.java @@ -119,20 +119,39 @@ public class SetEnableTechnologiesVariableActionTest extends AbstractFileSystemT } @Test - public void testUpdateInstallationWithoutCorePluginsFolder() + public void testUpdateInstallationWithOtherEnabledTechnologiesInAs() { FileUtilities.deleteRecursively(corePluginsFolder); FileUtilities.writeToFile(configFile, "abc = 123\n" + ENABLED_TECHNOLOGIES_KEY - + "=proteomics"); + + "=proteomics, my-tech"); Properties variables = new Properties(); variables.setProperty(TECHNOLOGY_PROTEOMICS, "true"); variables.setProperty(TECHNOLOGY_SCREENING, "false"); updateEnabledTechnologyProperties(variables, false); - assertEquals("[abc = 123, " + ENABLED_TECHNOLOGIES_KEY + "=proteomics]", FileUtilities + assertEquals("[abc = 123, " + ENABLED_TECHNOLOGIES_KEY + "=proteomics, my-tech]", + FileUtilities.loadToStringList(configFile).toString()); + assertEquals("[, " + ENABLED_TECHNOLOGIES_KEY + " = proteomics]", FileUtilities + .loadToStringList(dssConfigFile).toString()); + } + + @Test + public void testUpdateInstallationWithOtherEnabledTechnologiesInDss() + { + FileUtilities.writeToFile(configFile, ENABLED_TECHNOLOGIES_KEY + + "=proteomics"); + FileUtilities.writeToFile(dssConfigFile, "abc = 123\n" + ENABLED_TECHNOLOGIES_KEY + + " =my-tech,screening"); + Properties variables = new Properties(); + variables.setProperty(TECHNOLOGY_PROTEOMICS, "true"); + variables.setProperty(TECHNOLOGY_SCREENING, "false"); + + updateEnabledTechnologyProperties(variables, false); + + assertEquals("[" + ENABLED_TECHNOLOGIES_KEY + "=proteomics]", FileUtilities .loadToStringList(configFile).toString()); - assertEquals("[, " + ENABLED_TECHNOLOGIES_KEY + " = proteomics]", + assertEquals("[abc = 123, " + ENABLED_TECHNOLOGIES_KEY + " = proteomics, my-tech]", FileUtilities.loadToStringList(dssConfigFile).toString()); }