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

SDK-345 - Spa Installer does not remove previously deployed frontend … #304

Merged
merged 5 commits into from
Nov 11, 2024
Merged
Changes from 3 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 @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.io.MoreFiles;
import com.google.common.io.RecursiveDeleteOption;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.openmrs.maven.plugins.model.DistroProperties;
Expand Down Expand Up @@ -56,15 +57,15 @@ public SpaInstaller(DistroHelper distroHelper, NodeHelper nodeHelper) {
* @param distroProperties Non-null
* @throws MojoExecutionException
*/
public void installFromDistroProperties(File appDataDir, DistroProperties distroProperties)
throws MojoExecutionException {

public void installFromDistroProperties(File appDataDir, DistroProperties distroProperties) throws MojoExecutionException {
installFromDistroProperties(appDataDir, distroProperties, false, null);
}

public void installFromDistroProperties(File appDataDir, DistroProperties distroProperties, boolean ignorePeerDependencies, Boolean overrideReuseNodeCache)
throws MojoExecutionException {

File buildTargetDir = prepareTargetDirectory(appDataDir);

// We find all the lines in distro properties beginning with `spa` and convert these
// into a JSON structure. This is passed to the frontend build tool.
// If no SPA elements are present in the distro properties, the SPA is not installed.
Expand Down Expand Up @@ -93,7 +94,6 @@ public void installFromDistroProperties(File appDataDir, DistroProperties distro
Properties sdkProperties = getSdkProperties();
boolean reuseNodeCache = (overrideReuseNodeCache != null) ? overrideReuseNodeCache : Boolean.parseBoolean(sdkProperties.getProperty("reuseNodeCache"));
nodeHelper.installNodeAndNpm(nodeVersion, npmVersion, reuseNodeCache);
File buildTargetDir = new File(appDataDir, BUILD_TARGET_DIR);

String program = "openmrs@" + coreVersion;
String legacyPeerDeps = ignorePeerDependencies ? "--legacy-peer-deps" : "";
Expand Down Expand Up @@ -217,5 +217,18 @@ private static void writeJSONObject(File file, Map<String, Object> jsonObject) t
"Exception while writing JSON to \"" + file.getAbsolutePath() + "\" " + e.getMessage(), e);
}
}


private File prepareTargetDirectory(File appDataDir) throws MojoExecutionException {
File targetDir = new File(appDataDir, BUILD_TARGET_DIR);
if (targetDir.exists()) {
try {
FileUtils.deleteDirectory(targetDir);
}
catch (IOException e) {
throw new MojoExecutionException("Unable to delete existing " + BUILD_TARGET_DIR + " directory", e);
}
}
targetDir.mkdirs();
return targetDir;
}
}
Loading