Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure create server updates plugin config xml after copying config files #1792

Merged
merged 4 commits into from
Feb 16, 2024
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 @@ -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 - create, deploy and start
Assert.assertTrue("Did not find app install message in console output", appInstalledMatches.size() == 1);

String appMessage = appInstalledMatches.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ private void doDeploy() throws IOException, MojoExecutionException, TransformerE

// update target server configuration
copyConfigFiles();
exportParametersToXml();

boolean installDependencies = false;
boolean installProject = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -98,81 +98,56 @@ protected String getDeployPackages() {
return deployPackages;
}

/**
* 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
*/
@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
*/
protected File exportParametersToXml() throws IOException, ParserConfigurationException, TransformerException {
PluginConfigXmlDocument configDocument = PluginConfigXmlDocument.newInstance("liberty-plugin-config");
return exportParametersToXml(true);
}

List<Profile> 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<String> 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<Profile> 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());
Expand All @@ -193,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<String> 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);
Expand Down
Loading