-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
O3-3640: SDK to use any content packages specified in distribution pr…
…operties (#288)
- Loading branch information
Showing
5 changed files
with
141 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.openmrs.maven.plugins.utility; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.openmrs.maven.plugins.model.Artifact; | ||
import org.openmrs.maven.plugins.model.DistroProperties; | ||
|
||
/** | ||
* This class is downloads and moves content backend config to respective configuration folders | ||
*/ | ||
public class ContentHelper { | ||
|
||
public static final String FRONTEND_CONFIG_FOLDER = Paths.get("configs", "frontend_config").toString(); | ||
public static final String BACKEND_CONFIG_FOLDER = Paths.get("configs", "backend_config").toString(); | ||
|
||
public static void downloadContent(Artifact contentArtifact, ModuleInstaller moduleInstaller, File targetDir) throws MojoExecutionException { | ||
String artifactId = contentArtifact.getArtifactId(); | ||
// create a temporary artifact folder | ||
File sourceDir; | ||
try { | ||
sourceDir = Files.createTempDirectory("openmrs-sdk-" + artifactId + "-").toFile(); | ||
} catch (IOException e) { | ||
throw new MojoExecutionException("Exception while trying to create temporary directory", e); | ||
} | ||
|
||
moduleInstaller.installAndUnpackModule(contentArtifact, sourceDir.getAbsolutePath()); | ||
moveBackendConfig(artifactId, sourceDir, targetDir); | ||
|
||
FileUtils.deleteQuietly(sourceDir); | ||
} | ||
|
||
private static void moveBackendConfig(String artifactId, File sourceDir, File targetDir) throws MojoExecutionException { | ||
try { | ||
File backendConfigFiles = sourceDir.toPath().resolve(BACKEND_CONFIG_FOLDER).toFile(); | ||
Path targetPath = targetDir.toPath().toAbsolutePath(); | ||
|
||
if (backendConfigFiles.exists()) { | ||
File[] configDirectories = backendConfigFiles.listFiles(File::isDirectory); | ||
if (configDirectories != null) { | ||
for (File config : configDirectories) { | ||
Path destDir = targetPath.resolve(config.getName()).resolve(artifactId); | ||
Files.createDirectories(destDir); | ||
|
||
//copy config files to the matching configuration folder | ||
FileUtils.copyDirectory(config, destDir.toFile()); | ||
} | ||
} | ||
} | ||
} | ||
catch (IOException e) { | ||
throw new MojoExecutionException("Error copying backend configuration: " + 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); | ||
List<Artifact> contents = distroProperties.getContentArtifacts(); | ||
|
||
if (contents != null) { | ||
for (Artifact content : contents) { | ||
wizard.showMessage("Downloading Content: " + content + "\n"); | ||
ContentHelper.downloadContent(content, moduleInstaller, targetDir); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters