From 1ce49962fee89602f9a497853e1fa3f45d0aa361 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Tue, 13 Feb 2024 12:31:02 -0600 Subject: [PATCH 1/4] Ensure create server updates plugin config xml after copying config files --- .../tools/maven/applications/DeployMojo.java | 1 - .../tools/maven/server/PluginConfigSupport.java | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java index faace6f06..a8c48d9fb 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java @@ -72,7 +72,6 @@ private void doDeploy() throws IOException, MojoExecutionException, TransformerE // update target server configuration copyConfigFiles(); - exportParametersToXml(); boolean installDependencies = false; boolean installProject = false; diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java index c23253872..f20666fd3 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java @@ -98,6 +98,20 @@ protected String getDeployPackages() { return deployPackages; } + /** + * @throws IOException + * @throws MojoExecutionException + */ + @Override + protected void copyConfigFiles() throws IOException, MojoExecutionException { + try { + super.copyConfigFiles(); + exportParametersToXml(); + } catch (IOException | ParserConfigurationException | TransformerException e) { + throw new MojoExecutionException("Error copying configuration files to Liberty server directory.", e); + } + } + /* * Export plugin configuration parameters to * target/liberty-plugin-config.xml From 18e76a0bfc5e751e89487d3bfebecbe5efa993f2 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Tue, 13 Feb 2024 14:42:49 -0600 Subject: [PATCH 2/4] Fix testcase for additional log message --- liberty-maven-plugin/pom.xml | 2 +- .../wasdev/wlp/test/servlet/it/ServerConfigPropertiesTest.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/liberty-maven-plugin/pom.xml b/liberty-maven-plugin/pom.xml index c6c919883..0947fa0f3 100644 --- a/liberty-maven-plugin/pom.xml +++ b/liberty-maven-plugin/pom.xml @@ -182,7 +182,7 @@ true -Dfile.encoding=UTF-8 - cleanTest + diff --git a/liberty-maven-plugin/src/it/server-config-props-it/src/test/java/net/wasdev/wlp/test/servlet/it/ServerConfigPropertiesTest.java b/liberty-maven-plugin/src/it/server-config-props-it/src/test/java/net/wasdev/wlp/test/servlet/it/ServerConfigPropertiesTest.java index f07f9715f..df1c49f0b 100644 --- a/liberty-maven-plugin/src/it/server-config-props-it/src/test/java/net/wasdev/wlp/test/servlet/it/ServerConfigPropertiesTest.java +++ b/liberty-maven-plugin/src/it/server-config-props-it/src/test/java/net/wasdev/wlp/test/servlet/it/ServerConfigPropertiesTest.java @@ -130,8 +130,7 @@ public void checkMessagesLogForIncludes() throws Exception { //Check app name/appsDir resolved correctly during create, deploy, and start Assert.assertTrue("Found duplicate application message in console output", duplicateMatches.size() == 0); - Assert.assertEquals("appsDirMessage size: " + appDirMatches.size(), 1, appDirMatches.size()); - Assert.assertTrue("Did not find appsDirectory message in console output", appDirMatches.size() == 1); + Assert.assertEquals("appsDirMessage size: " + appDirMatches.size(), 3, appDirMatches.size()); // once for each goal Assert.assertTrue("Did not find app install message in console output", appInstalledMatches.size() == 1); String appMessage = appInstalledMatches.get(0); From 570031642f4a72b3c116c829f8fabaf773e500d2 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Thu, 15 Feb 2024 11:57:58 -0600 Subject: [PATCH 3/4] clean up, comments --- liberty-maven-plugin/pom.xml | 2 +- .../wlp/test/servlet/it/ServerConfigPropertiesTest.java | 2 +- .../java/io/openliberty/tools/maven/server/DevMojo.java | 7 ++++++- .../tools/maven/server/PluginConfigSupport.java | 2 ++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/liberty-maven-plugin/pom.xml b/liberty-maven-plugin/pom.xml index 0947fa0f3..c6c919883 100644 --- a/liberty-maven-plugin/pom.xml +++ b/liberty-maven-plugin/pom.xml @@ -182,7 +182,7 @@ true -Dfile.encoding=UTF-8 - + cleanTest diff --git a/liberty-maven-plugin/src/it/server-config-props-it/src/test/java/net/wasdev/wlp/test/servlet/it/ServerConfigPropertiesTest.java b/liberty-maven-plugin/src/it/server-config-props-it/src/test/java/net/wasdev/wlp/test/servlet/it/ServerConfigPropertiesTest.java index df1c49f0b..7400b82ca 100644 --- a/liberty-maven-plugin/src/it/server-config-props-it/src/test/java/net/wasdev/wlp/test/servlet/it/ServerConfigPropertiesTest.java +++ b/liberty-maven-plugin/src/it/server-config-props-it/src/test/java/net/wasdev/wlp/test/servlet/it/ServerConfigPropertiesTest.java @@ -130,7 +130,7 @@ public void checkMessagesLogForIncludes() throws Exception { //Check app name/appsDir resolved correctly during create, deploy, and start Assert.assertTrue("Found duplicate application message in console output", duplicateMatches.size() == 0); - Assert.assertEquals("appsDirMessage size: " + appDirMatches.size(), 3, appDirMatches.size()); // once for each goal + Assert.assertEquals("appsDirMessage size: " + appDirMatches.size(), 3, appDirMatches.size()); // once for each goal - create, deploy and start Assert.assertTrue("Did not find app install message in console output", appInstalledMatches.size() == 1); String appMessage = appInstalledMatches.get(0); diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java index 45e5a15d4..3e958ce8e 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java @@ -1992,7 +1992,12 @@ protected void runLibertyMojoCreate() throws MojoExecutionException { if (installDirectory != null) { try { File installDirectoryCanonicalFile = installDirectory.getCanonicalFile(); - // Quick check to see if a Liberty installation exists at the installDirectory + // Quick check to see if a Liberty installation exists at the installDirectory CLK999 + // Do not mark this as a non-new installation if the installDirectory is different than + // the previous one listed in liberty-plugin-config.xml? But the only way it already exists + // and is different is if it is an external installation, which should then be managed outside + // of the plugin goals as far as feature installation goes. So perhaps we leave it be, but + // print a log message to indicate we detected a change in install directory location? File file = new File(installDirectoryCanonicalFile, "lib/ws-launch.jar"); if (file.exists()) { this.isNewInstallation = false; diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java index f20666fd3..4471d4cf8 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java @@ -99,6 +99,8 @@ protected String getDeployPackages() { } /** + * Overriding this method to add the export of the parameters to the xml file. This method will get called for the + * following goals: create, deploy, run and dev * @throws IOException * @throws MojoExecutionException */ From 4df8eaf59c36536e4d5940720995a177bbbb13c2 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Thu, 15 Feb 2024 16:35:47 -0600 Subject: [PATCH 4/4] Exclude server related info on initial write of plugin config xml when server does not exist yet --- .../maven/server/PluginConfigSupport.java | 144 ++++++++++-------- 1 file changed, 82 insertions(+), 62 deletions(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java index 4471d4cf8..1b4c88ce4 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java @@ -82,7 +82,7 @@ public abstract class PluginConfigSupport extends StartDebugMojoSupport { @Override protected void installServerAssembly() throws MojoExecutionException { try { - File f = exportParametersToXml(); + File f = exportParametersToXml(false); super.installServerAssembly(); this.buildContext.refresh(f); this.buildContext.refresh(installDirectory); @@ -119,76 +119,35 @@ protected void copyConfigFiles() throws IOException, MojoExecutionException { * target/liberty-plugin-config.xml */ protected File exportParametersToXml() throws IOException, ParserConfigurationException, TransformerException { - PluginConfigXmlDocument configDocument = PluginConfigXmlDocument.newInstance("liberty-plugin-config"); + return exportParametersToXml(true); + } - List profiles = project.getActiveProfiles(); - configDocument.createActiveBuildProfilesElement("activeBuildProfiles", profiles); + /* + * Export plugin configuration parameters to + * target/liberty-plugin-config.xml + */ + protected File exportParametersToXml(boolean includeServerInfo) throws IOException, ParserConfigurationException, TransformerException { + PluginConfigXmlDocument configDocument = PluginConfigXmlDocument.newInstance("liberty-plugin-config"); + // install related info (common parameters) configDocument.createElement("installDirectory", installDirectory); - configDocument.createElement("serverDirectory", serverDirectory); - configDocument.createElement("userDirectory", userDirectory); - configDocument.createElement("serverOutputDirectory", new File(outputDirectory, serverName)); - configDocument.createElement("serverName", serverName); - configDocument.createElement("configDirectory", configDirectory); - - File configFile = findConfigFile("server.xml", serverXmlFile); - if (configFile != null) { - configDocument.createElement("configFile", configFile); - } - - if (combinedBootstrapProperties != null) { - configDocument.createElement("bootstrapProperties", combinedBootstrapProperties); - } else if (bootstrapProperties != null) { - if (bootstrapPropertiesResolved == null) { - bootstrapPropertiesResolved = handleLatePropertyResolution(bootstrapProperties); - } - configDocument.createElement("bootstrapProperties", bootstrapPropertiesResolved); - } else { - configFile = findConfigFile("bootstrap.properties", bootstrapPropertiesFile); - if (configFile != null) { - configDocument.createElement("bootstrapPropertiesFile", configFile); - } - } - - if (combinedJvmOptions != null) { - configDocument.createElement("jvmOptions", combinedJvmOptions); - } else if (jvmOptions != null) { - if (jvmOptionsResolved == null) { - jvmOptionsResolved = handleLatePropertyResolution(jvmOptions); - } - List uniqueOptions = getUniqueValues(jvmOptionsResolved); - configDocument.createElement("jvmOptions", uniqueOptions); - } else { - configFile = findConfigFile("jvm.options", jvmOptionsFile); - if (configFile != null) { - configDocument.createElement("jvmOptionsFile", configFile); - } - } - - // Only write the serverEnvFile path if it was not overridden by liberty.env.{var} Maven properties. - if (envMavenProps.isEmpty()) { - configFile = findConfigFile("server.env", serverEnvFile); - if (configFile != null) { - configDocument.createElement("serverEnv", configFile); - } - } - - if (isConfigCopied()) { - configDocument.createElement("appsDirectory", getAppsDirectory()); - } - - configDocument.createElement("looseApplication", looseApplication); - configDocument.createElement("stripVersion", stripVersion); - configDocument.createElement("installAppPackages", getDeployPackages()); - configDocument.createElement("applicationFilename", getApplicationFilename()); configDocument.createElement("assemblyArtifact", assemblyArtifact); configDocument.createElement("assemblyArchive", assemblyArchive); configDocument.createElement("assemblyInstallDirectory", assemblyInstallDirectory); configDocument.createElement("refresh", refresh); configDocument.createElement("install", install); - configDocument.createElement("installAppsConfigDropins", - ApplicationXmlDocument.getApplicationXmlFile(serverDirectory)); + // even though these are related to the server, they are specified in the common parameters for the install + // and are initialized in the BasicSupport.init() method. + configDocument.createElement("serverDirectory", serverDirectory); + configDocument.createElement("userDirectory", userDirectory); + configDocument.createElement("serverOutputDirectory", new File(outputDirectory, serverName)); + configDocument.createElement("serverName", serverName); + + // project related info + List profiles = project.getActiveProfiles(); + configDocument.createActiveBuildProfilesElement("activeBuildProfiles", profiles); + configDocument.createElement("projectType", project.getPackaging()); if (project.getParent() != null && !project.getParent().getModules().isEmpty()) { configDocument.createElement("aggregatorParentId", project.getParent().getArtifactId()); @@ -209,6 +168,67 @@ protected File exportParametersToXml() throws IOException, ParserConfigurationEx // include warSourceDirectory for liberty-assembly project with source configDocument.createElement("warSourceDirectory", getLibertyAssemblyWarSourceDirectory(project)); + if (includeServerInfo) { + // include all info related specifically to the server (commmon server parameters) + configDocument.createElement("configDirectory", configDirectory); + + File configFile = findConfigFile("server.xml", serverXmlFile); + if (configFile != null) { + configDocument.createElement("configFile", configFile); + } + + if (combinedBootstrapProperties != null) { + configDocument.createElement("bootstrapProperties", combinedBootstrapProperties); + } else if (bootstrapProperties != null) { + if (bootstrapPropertiesResolved == null) { + bootstrapPropertiesResolved = handleLatePropertyResolution(bootstrapProperties); + } + configDocument.createElement("bootstrapProperties", bootstrapPropertiesResolved); + } else { + configFile = findConfigFile("bootstrap.properties", bootstrapPropertiesFile); + if (configFile != null) { + configDocument.createElement("bootstrapPropertiesFile", configFile); + } + } + + if (combinedJvmOptions != null) { + configDocument.createElement("jvmOptions", combinedJvmOptions); + } else if (jvmOptions != null) { + if (jvmOptionsResolved == null) { + jvmOptionsResolved = handleLatePropertyResolution(jvmOptions); + } + List uniqueOptions = getUniqueValues(jvmOptionsResolved); + configDocument.createElement("jvmOptions", uniqueOptions); + } else { + configFile = findConfigFile("jvm.options", jvmOptionsFile); + if (configFile != null) { + configDocument.createElement("jvmOptionsFile", configFile); + } + } + + // Only write the serverEnvFile path if it was not overridden by liberty.env.{var} Maven properties. + if (envMavenProps.isEmpty()) { + configFile = findConfigFile("server.env", serverEnvFile); + if (configFile != null) { + configDocument.createElement("serverEnv", configFile); + } + } + + // include info related to apps + if (isConfigCopied()) { + configDocument.createElement("appsDirectory", getAppsDirectory()); + } + + configDocument.createElement("looseApplication", looseApplication); + configDocument.createElement("stripVersion", stripVersion); + configDocument.createElement("installAppPackages", getDeployPackages()); + configDocument.createElement("applicationFilename", getApplicationFilename()); + + + configDocument.createElement("installAppsConfigDropins", + ApplicationXmlDocument.getApplicationXmlFile(serverDirectory)); + } + // write XML document to file File f = new File(project.getBuild().getDirectory() + File.separator + PLUGIN_CONFIG_XML); configDocument.writeXMLDocument(f);