diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/SpaInstaller.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/SpaInstaller.java index 8efed9a5..a937840d 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/SpaInstaller.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/SpaInstaller.java @@ -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; @@ -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. @@ -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" : ""; @@ -217,5 +217,20 @@ private static void writeJSONObject(File file, Map 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 { + distroHelper.wizard.showMessage("Removing existing frontend directory: " + targetDir); + FileUtils.deleteDirectory(targetDir); + } + catch (IOException e) { + throw new MojoExecutionException("Unable to delete existing " + BUILD_TARGET_DIR + " directory", e); + } + } + distroHelper.wizard.showMessage("Creating new frontend directory: " + targetDir); + targetDir.mkdirs(); + return targetDir; + } }