diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractServerTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractServerTask.groovy index a9602a91..5fbedf11 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractServerTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractServerTask.groovy @@ -890,6 +890,7 @@ abstract class AbstractServerTask extends AbstractLibertyTask { if (serverEnvPath == null && server.serverEnvFile == null) { // Do a special case merge but ONLY if there is no server.env file present in configDirectory or specified with serverEnvFile envPropsToWrite = mergeSpecialPropsFromInstallServerEnvIfAbsent(envFile, configuredProps) + logger.warn("The default " + envFile.getCanonicalPath() + " file is overwritten by inlined configuration.") } else if (serverEnvPath != null) { logger.warn("The " + serverEnvPath + " file is overwritten by inlined configuration.") } @@ -911,8 +912,6 @@ abstract class AbstractServerTask extends AbstractLibertyTask { */ private Properties mergeSpecialPropsFromInstallServerEnvIfAbsent(File envFile, Properties envProps) throws IOException { - String[] specialProps = { "keystore_password" } - // Make a copy to avoid side effects Properties mergedProps = new Properties() mergedProps.putAll(envProps) @@ -920,10 +919,9 @@ abstract class AbstractServerTask extends AbstractLibertyTask { // From install (target) dir Properties serverEnvProps = convertServerEnvToProperties(envFile) - for (String propertyName : specialProps) { - if (serverEnvProps.containsKey(propertyName)) { - mergedProps.putIfAbsent(propertyName,serverEnvProps.get(propertyName)) - } + String propertyName = "keystore_password" + if (serverEnvProps.containsKey(propertyName)) { + mergedProps.putIfAbsent(propertyName,serverEnvProps.get(propertyName)) } return mergedProps diff --git a/src/test/groovy/io/openliberty/tools/gradle/TestCreateWithInlineProperties.groovy b/src/test/groovy/io/openliberty/tools/gradle/TestCreateWithInlineProperties.groovy index 883ea56f..455c7f6f 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/TestCreateWithInlineProperties.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/TestCreateWithInlineProperties.groovy @@ -72,11 +72,15 @@ public class TestCreateWithInlineProperties extends AbstractIntegrationTest{ prop = new Properties(); prop.load( input2 ); - assert prop.size() == 2 : "expected 2 properties in server.env file but found "+prop.size() + assert prop.size() == 3 : "expected 3 properties in server.env file but found "+prop.size() String value2 = prop.getProperty("some.env.var"); - assert value2 != null && value2.equals("someValue") : "property not found in server.env file" + assert value2 != null && value2.equals("someValue") : "some.env.var property not found in server.env file" value2 = prop.getProperty("another.env.var"); - assert value2 != null && value2.equals("anotherValue") : "property not found in server.env file" + assert value2 != null && value2.equals("anotherValue") : "another.env.var property not found in server.env file" + // if no server.env file is specified in configuration and mergeServerEnv is not set to true, + // the keystore_password is still preserved when present in the default server.env file and not specified in a property + value2 = prop.getProperty("keystore_password"); + assert value2 != null : "keystore_password property not found in server.env file" assert libertyConfigVarOverridesFile.text.contains("name=\"someVar\"") : "configDropins/overrides/liberty-plugin-variable-config.xml does not contain expected variable: "+libertyConfigVarOverridesFile.text assert libertyConfigVarOverridesFile.text.contains("value=\"someValue\"") : "configDropins/overrides/liberty-plugin-variable-config.xml does not contain expected variable: "+libertyConfigVarOverridesFile.text diff --git a/src/test/groovy/io/openliberty/tools/gradle/TestServerEnvKeystorePasswordPreserve.groovy b/src/test/groovy/io/openliberty/tools/gradle/TestServerEnvKeystorePasswordPreserve.groovy deleted file mode 100644 index 7059015b..00000000 --- a/src/test/groovy/io/openliberty/tools/gradle/TestServerEnvKeystorePasswordPreserve.groovy +++ /dev/null @@ -1,93 +0,0 @@ -package io.openliberty.tools.gradle - -import org.junit.AfterClass -import org.junit.BeforeClass -import org.junit.Test - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathFactory; - -import java.io.BufferedReader; -import java.io.FileReader; - - -import org.junit.BeforeClass -import org.junit.FixMethodOrder -import org.junit.Test -import org.junit.runners.MethodSorters -import org.junit.Assert; -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; -import org.w3c.dom.Node; -import org.w3c.dom.Element; - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -class TestServerEnvKeystorePasswordPreserve extends AbstractIntegrationTest { - static File resourceDir = new File("build/resources/test/sample.servlet") - static File buildDir = new File(integTestDir, "/test-server-env-keystore-password-preserve") - static String buildFilename = "testServerEnvKeystorePasswordPreserve.gradle" - - @BeforeClass - public static void setup() { - createDir(buildDir) - createTestProject(buildDir, resourceDir, buildFilename) - runTasks(buildDir, 'libertyCreate') - } - - @Test - public void check_for_server_env() { - assert new File('build/testBuilds/test-server-env-keystore-password-preserve/build/wlp/usr/servers/LibertyProjectServer/server.env').exists() : 'server.env not found!' - } - - /* - # envProps in build.gradle - env = ['TEST_PROP_2':'white', 'CONFIG_SERVER_ENV_PROPS':'TEST'] - - # default server.env - keystore_password=sfKRrA1ioLdtIFQC9bEfkua - - # Final server.env - # Generated by liberty-gradle-plugin - keystore_password=sfKRrA1ioLdtIFQC9bEfkua - CONFIG_SERVER_ENV_PROPS=TEST - TEST_PROP_2=white - */ - @Test - public void check_server_env_contents() { - File serverEnv = new File("build/testBuilds/test-server-env-keystore-password-preserve/build/wlp/usr/servers/LibertyProjectServer/server.env") - FileInputStream input = new FileInputStream(serverEnv) - - Map serverEnvContents = new HashMap(); - - BufferedReader bf = new BufferedReader(new FileReader(serverEnv)) - String line = bf.readLine(); - boolean commentFound = false - while(line != null) { - //ignore comment lines - if(!line.startsWith("#")) { - String[] keyValuePair = line.split("="); - String key = keyValuePair[0]; - String value = keyValuePair[1]; - - serverEnvContents.put(key,value); - } else { - commentFound = true - Assert.assertTrue("File should have been generated by liberty-gradle-plugin", line.contains("liberty-gradle-plugin")); - } - line = bf.readLine(); - } - Assert.assertTrue("Expected generated by liberty-gradle-plugin comment not found", commentFound); - - // The contents of the default server.env can change over time. - // Only the keystore_password should be preserved at this time. Ensure that no additional lines are in the "merged" server.env file. - Assert.assertEquals("Number of env properties should be 3, but is "+serverEnvContents.size(), serverEnvContents.size(), 3) - Assert.assertTrue("keystore_password mapping found", serverEnvContents.containsKey("keystore_password")) - Assert.assertTrue("CONFIG_SERVER_ENV_PROPS=TEST", serverEnvContents.get("CONFIG_SERVER_ENV_PROPS").equals("TEST")) - Assert.assertTrue("TEST_PROP_2=white", serverEnvContents.get("TEST_PROP_2").equals("white")) - - } - -} \ No newline at end of file diff --git a/src/test/resources/sample.servlet/testServerEnvKeystorePasswordPreserve.gradle b/src/test/resources/sample.servlet/testServerEnvKeystorePasswordPreserve.gradle deleted file mode 100644 index 5987ae0a..00000000 --- a/src/test/resources/sample.servlet/testServerEnvKeystorePasswordPreserve.gradle +++ /dev/null @@ -1,92 +0,0 @@ -/* - This test checks whether the application was successfully installed without the version number in the package - when deploy is called and stripVersion is set to true. -*/ -group = 'liberty.gradle' -version = '1' - -buildscript { - repositories { - mavenLocal() - mavenCentral() - maven { - name = 'Sonatype Nexus Snapshots' - url = 'https://oss.sonatype.org/content/repositories/snapshots/' - } - } - dependencies { - classpath "io.openliberty.tools:liberty-gradle-plugin:$lgpVersion" - } -} - -apply plugin: 'war' -apply plugin: 'liberty' - -sourceCompatibility = 1.7 -targetCompatibility = 1.7 - -compileJava.options.encoding = 'UTF-8' - -ext { - // Liberty server properties - wlpServerName = 'LibertyProjectServer' - serverDirectory = "${project.buildDir}/wlp/usr/servers/${wlpServerName}" - testServerHttpPort = 9080 - testServerHttpsPort = 9443 - - // This is set in the ibm-web-ext.xml file - warContext = 'myLibertyApp' - -} - -liberty { - server{ - serverXmlFile = file("src/main/liberty/config/server-apps-test.xml") - name = wlpServerName - deploy { - apps = [war] - copyLibsDirectory = file("${project.buildDir}/libs") - } - mergeServerEnv = true - env = ['TEST_PROP_2':'white', 'CONFIG_SERVER_ENV_PROPS':'TEST'] - } -} - -repositories { - mavenCentral() -} - -dependencies { - testImplementation 'junit:junit:4.13.1' - providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0' - implementation 'org.apache.commons:commons-text:1.1' - libertyRuntime group: runtimeGroup, name: kernelArtifactId, version: runtimeVersion -} - -test { - println 'inside the test block' - reports.html.outputLocation = file("$buildDir/reports/unit") - reports.junitXml.outputLocation = file("$buildDir/test-results/unit") - exclude '**/it/**' -} - -task integrationTest(type: Test) { - group 'Verification' - description 'Runs the integration tests.' - reports.html.outputLocation = file("$buildDir/reports/it") - reports.junitXml.outputLocation = file("$buildDir/test-results/it") - include '**/it/**' - exclude '**/unit/**' - - systemProperties = ['liberty.test.port': testServerHttpPort, 'war.name': warContext] -} - -task printMessageAboutRunningServer { - doLast { - println "The server is now running at http://localhost:${testServerHttpPort}/${warContext}" - println "To stop the server run 'gradle libertyStop'" - } -} - -deploy.dependsOn 'war' -libertyStart.finalizedBy 'printMessageAboutRunningServer'