diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java index 49c3ef02..e40e44c4 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java @@ -326,7 +326,8 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro setConfigFolder(configDir, distroProperties, distroArtifact); ContentHelper.downloadAndMoveContentBackendConfig(web, distroProperties, moduleInstaller, wizard); spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); - + ContentHelper.deleteTempContentFolder(web); + File owasDir = new File(web, "owa"); owasDir.mkdir(); downloadOWAs(targetDirectory, distroProperties, owasDir); diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index 2db239b3..07951f8e 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -65,7 +65,8 @@ public class Setup extends AbstractServerTask { private static final String NO_DEBUGGING_DEFAULT_ANSWER = "no debugging"; - private static final int DEFAULT_PORT = 8080; + private static final int DEFAULT_PORT = 8080; + /** * DB Driver type @@ -280,10 +281,11 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE distroHelper.parseContentProperties(distroProperties); moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper); setConfigFolder(server, distroProperties); - ContentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties, moduleInstaller, wizard); + ContentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties, moduleInstaller, wizard); if (spaInstaller != null) { spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); } + ContentHelper.deleteTempContentFolder(server.getServerDirectory()); installOWAs(server, distroProperties); } else { moduleInstaller.installDefaultModules(server); @@ -344,8 +346,8 @@ private void downloadOWAs(File targetDirectory, DistroProperties distroPropertie owaHelper.downloadOwa(owasDir, owa, moduleInstaller); } } - } - + } + /** * Sets the configuration folder for the specified server using the provided distro properties. * diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java index f2073169..f0602793 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java @@ -3,7 +3,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Collection; @@ -23,19 +22,15 @@ public class ContentHelper { public static final String FRONTEND_CONFIG_FOLDER = File.separator + "configs" + File.separator + "frontend_config"; public static final String BACKEND_CONFIG_FOLDER = "configs" + File.separator + "backend_config"; - public static void downloadContent(File serverDirectory, Artifact contentArtifact, ModuleInstaller moduleInstaller, - File targetDir) throws MojoExecutionException { - try { - String artifactId = contentArtifact.getArtifactId(); - //create a artifact folder under temp_content - File sourceDir = Files.createTempDirectory(TEMP_CONTENT_FOLDER + artifactId).toFile(); - - moduleInstaller.installAndUnpackModule(contentArtifact, sourceDir.getAbsolutePath()); - moveBackendConfig(artifactId, sourceDir, targetDir); - } - catch (Exception e) { - throw new MojoExecutionException("Error creating temp_content: " + e.getMessage(), e); - } + public static void downloadContent(File serverDirectory, Artifact contentArtifact, ModuleInstaller moduleInstaller, File targetDir) throws MojoExecutionException { + + String artifactId = contentArtifact.getArtifactId(); + //create a artifact folder under temp_content + File sourceDir = new File(serverDirectory, TEMP_CONTENT_FOLDER + File.separator + artifactId); + sourceDir.mkdirs(); + + moduleInstaller.installAndUnpackModule(contentArtifact, sourceDir.getAbsolutePath()); + moveBackendConfig(artifactId, sourceDir, targetDir); } private static void moveBackendConfig(String artifactId, File sourceDir, File targetDir) throws MojoExecutionException { @@ -84,6 +79,19 @@ public static List getContentFrontendConfigFiles(DistroProperties distroPr return contentConfigFiles; } + public static void deleteTempContentFolder(File serverDirectory) throws MojoExecutionException { + File tempContentDir = new File(serverDirectory, TEMP_CONTENT_FOLDER); + try { + if (tempContentDir.exists()) { + FileUtils.deleteDirectory(tempContentDir); + } + } + catch (IOException e) { + throw new MojoExecutionException("Failed to delete temporary content folder at: " + + tempContentDir.getAbsolutePath() + " due to: " + e.getMessage(), e); + } + } + public static void downloadAndMoveContentBackendConfig(File serverDirectory, DistroProperties distroProperties, ModuleInstaller moduleInstaller, Wizard wizard) throws MojoExecutionException { if (distroProperties != null) { File targetDir = new File(serverDirectory, SDKConstants.OPENMRS_SERVER_CONFIGURATION);