Skip to content

Commit

Permalink
Reverted changes regarding OS temp directory
Browse files Browse the repository at this point in the history
  • Loading branch information
nravilla committed Sep 23, 2024
1 parent c5e8d41 commit 2e8af3f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -84,6 +79,19 @@ public static List<File> 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);
Expand Down

0 comments on commit 2e8af3f

Please sign in to comment.