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

Detect install config changes during dev mode #1796

Merged
merged 3 commits into from
Feb 22, 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 @@ -589,12 +589,25 @@ private boolean dependencyEquals(Dependency dep1, Dependency dep2) {
return true;
}

private static final String LIBERTY_RUNTIME_PROP = "liberty.runtime.";
private static final String LIBERTY_BOOTSTRAP_PROP = "liberty.bootstrap.";
private static final String LIBERTY_JVM_PROP = "liberty.jvm.";
private static final String LIBERTY_ENV_PROP = "liberty.env.";
private static final String LIBERTY_VAR_PROP = "liberty.var.";
private static final String LIBERTY_DEFAULT_VAR_PROP = "liberty.defaultVar.";

private boolean hasInstallationPropChanged(MavenProject project, MavenProject backupProject) {
Properties projProp = project.getProperties();
Properties backupProjProp = backupProject.getProperties();

if (!Objects.equals(getPropertiesWithKeyPrefix(projProp, LIBERTY_RUNTIME_PROP),
getPropertiesWithKeyPrefix(backupProjProp, LIBERTY_RUNTIME_PROP))) {
return true;
}

return false;
}

private boolean hasServerPropertyChanged(MavenProject project, MavenProject backupProject) {
Properties projProp = project.getProperties();
Properties backupProjProp = backupProject.getProperties();
Expand Down Expand Up @@ -651,6 +664,39 @@ private boolean restartForLibertyMojoConfigChanged(Xpp3Dom config, Xpp3Dom oldCo
return false;
}

private boolean hasInstallationConfigChanged(Xpp3Dom config, Xpp3Dom oldConfig) {
if (!Objects.equals(config.getChild("installDirectory"), oldConfig.getChild("installDirectory"))) {
return true;
} else if (!Objects.equals(config.getChild("runtimeArchive"), oldConfig.getChild("runtimeArchive"))) {
return true;
} else if (!Objects.equals(config.getChild("runtimeArtifact"), oldConfig.getChild("runtimeArtifact"))) {
return true;
} else if (!Objects.equals(config.getChild("assemblyArchive"), oldConfig.getChild("assemblyArchive"))) {
return true;
} else if (!Objects.equals(config.getChild("assemblyArtifact"), oldConfig.getChild("assemblyArtifact"))) {
return true;
} else if (!Objects.equals(config.getChild("libertyRuntimeGroupId"), oldConfig.getChild("libertyRuntimeGroupId"))) {
return true;
} else if (!Objects.equals(config.getChild("libertyRuntimeArtifactId"), oldConfig.getChild("libertyRuntimeArtifactId"))) {
return true;
} else if (!Objects.equals(config.getChild("libertyRuntimeVersion"), oldConfig.getChild("libertyRuntimeVersion"))) {
return true;
} else if (!Objects.equals(config.getChild("serverName"), oldConfig.getChild("serverName"))) {
return true;
} else if (!Objects.equals(config.getChild("userDirectory"), oldConfig.getChild("userDirectory"))) {
return true;
} else if (!Objects.equals(config.getChild("outputDirectory"), oldConfig.getChild("outputDirectory"))) {
return true;
} else if (!Objects.equals(config.getChild("runtimeInstallDirectory"), oldConfig.getChild("runtimeInstallDirectory"))) {
return true;
} else if (!Objects.equals(config.getChild("assemblyInstallDirectory"), oldConfig.getChild("assemblyInstallDirectory"))) {
return true;
} else if (!Objects.equals(config.getChild("install"), oldConfig.getChild("install"))) {
return true;
}
return false;
}

@Override
public boolean updateArtifactPaths(ProjectModule projectModule, boolean redeployCheck, boolean generateFeatures, ThreadPoolExecutor executor)
throws PluginExecutionException {
Expand Down Expand Up @@ -913,6 +959,7 @@ public boolean recompileBuildFile(File buildFile, Set<String> compileArtifactPat
// - liberty.* properties in project properties section
// - changes in liberty plugin configuration in the build plugin section
// - project dependencies changes
boolean reinstallLiberty = false; // if this gets set to true, need to throw PluginExecutionException so user can run 'clean'
cherylking marked this conversation as resolved.
Show resolved Hide resolved
boolean restartServer = false;
boolean createServer = false;
boolean installFeature = false;
Expand Down Expand Up @@ -949,6 +996,11 @@ public boolean recompileBuildFile(File buildFile, Set<String> compileArtifactPat
}

// Monitoring liberty properties in the pom.xml
if (hasInstallationPropChanged(project, backupProject)) {
// Note that a change in installation config values requires a restart of dev mode.
reinstallLiberty = true;
getLog().error("A change in Liberty runtime installation configuration requires a restart of dev mode. Stopping dev mode.");
}
if (hasServerPropertyChanged(project, backupProject)) {
restartServer = true;
}
Expand All @@ -967,6 +1019,11 @@ public boolean recompileBuildFile(File buildFile, Set<String> compileArtifactPat
if (restartForLibertyMojoConfigChanged(config, oldConfig)) {
restartServer = true;
}
if (hasInstallationConfigChanged(config, oldConfig)) {
// Note that a change in installation config values requires a restart of dev mode.
reinstallLiberty = true;
getLog().error("A change in Liberty runtime installation configuration requires a restart of dev mode. Stopping dev mode.");
}
}
}
config = ExecuteMojoUtil.getPluginGoalConfig(libertyPlugin, "install-feature", getLog());
Expand Down Expand Up @@ -1054,7 +1111,12 @@ public boolean recompileBuildFile(File buildFile, Set<String> compileArtifactPat
getLog().warn("Change detected in the set of resource directories, since dev mode was first launched. Adding/deleting a resource directory has no change on the set of directories monitored by dev mode. Changing the watch list will require a dev mode restart");
}

if (restartServer) {
if (reinstallLiberty) {
project = backupProject;
session.setCurrentProject(backupProject);
util.stopServer();
throw new PluginExecutionException("A change in Liberty runtime installation configuration requires a restart of dev mode. Please run the 'dev' goal again for the change to take effect.");
} else if (restartServer) {
// - stop Server
// - create server or runBoostMojo
// - install feature
Expand All @@ -1077,7 +1139,7 @@ public boolean recompileBuildFile(File buildFile, Set<String> compileArtifactPat
runLibertyMojoInstallFeature(null, null, super.getContainerName());
}
}
if (!(restartServer || createServer || redeployApp || installFeature || runBoostPackage)) {
if (!(reinstallLiberty || restartServer || createServer || redeployApp || installFeature || runBoostPackage)) {
// pom.xml is changed but not affecting liberty:dev mode. return true with the
// updated project set in the session
getLog().debug("changes in the pom.xml are not monitored by dev mode");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ protected File exportParametersToXml(boolean includeServerInfo) throws IOExcepti

// install related info (common parameters)
configDocument.createElement("installDirectory", installDirectory);
configDocument.createElement("assemblyArtifact", assemblyArtifact);
configDocument.createElement("assemblyArchive", assemblyArchive);
configDocument.createElement("assemblyInstallDirectory", assemblyInstallDirectory);
if (installType != InstallType.ALREADY_EXISTS) {
configDocument.createElement("assemblyArtifact", assemblyArtifact);
configDocument.createElement("assemblyArchive", assemblyArchive);
configDocument.createElement("assemblyInstallDirectory", assemblyInstallDirectory);
}
configDocument.createElement("refresh", refresh);
configDocument.createElement("install", install);

Expand Down
Loading