Skip to content

Commit

Permalink
Merge pull request #114 from tmarzeion/SDK-177
Browse files Browse the repository at this point in the history
SDK-177 - Bundle modules in war
  • Loading branch information
rkorytkowski authored Nov 22, 2016
2 parents 61c78eb + bbb33b6 commit 05318b4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
import java.util.List;
import java.util.Properties;
import java.util.UUID;
import java.util.zip.ZipFile;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.openmrs.maven.plugins.SdkMatchers.hasModuleVersion;
import static org.openmrs.maven.plugins.SdkMatchers.hasModuleVersionInDisstro;
import static org.openmrs.maven.plugins.SdkMatchers.hasPlatformVersion;
Expand Down Expand Up @@ -196,6 +198,12 @@ public void assertFileNotPresent(String path){
verifier.assertFileNotPresent(testDirectory.getAbsolutePath() + File.separator + path);
}

public void assertZipEntryPresent(String path, String zipEntryName) throws Exception {
File file = new File(testDirectory.getAbsolutePath(), path);
ZipFile zipFile = new ZipFile(file);
assertNotNull(zipFile.getEntry(zipEntryName));
}

/**
* check whether build ended with success
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.openmrs.maven.plugins;

import net.lingala.zip4j.core.ZipFile;
import org.junit.Test;

import java.io.File;
Expand All @@ -23,4 +22,27 @@ public void testBuildDistro() throws Exception {
assertFilePresent("openmrs.war");
assertSuccess();
}

@Test
public void testBundledBuildDistro() throws Exception {
addTaskParam("distro", "referenceapplication:2.3.1");
addTaskParam("dir", "referenceapplication-2.3.1");
addTaskParam("bundled", "true");
executeTask("build-distro");

testDirectory = new File(testDirectory, "referenceapplication-2.3.1");
assertFilePresent("Dockerfile");
assertFilePresent("docker-compose.yml");
assertFilePresent("setenv.sh");
assertFilePresent("startup.sh");
assertFilePresent("wait-for-it.sh");
assertFilePresent("openmrs.war");

assertFileNotPresent("modules");
assertFileNotPresent("WEB-INF");

assertZipEntryPresent("openmrs.war", "WEB-INF/bundledModules");

assertSuccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class BuildDistro extends AbstractTask {

public static final String DB_DUMP_PATH = "dbdump" + File.separator + "dump.sql";

public static final String WAR_FILE_MODULES_DIRECTORY_NAME = "bundledModules";

/**
* @parameter expression="${distro}"
*/
Expand All @@ -56,6 +58,11 @@ public class BuildDistro extends AbstractTask {
*/
private String dbSql;

/**
* @parameter expression="${bundled}" default-value="false"
*/
private boolean bundled;

@Override
public void executeTask() throws MojoExecutionException, MojoFailureException {
File buildDirectory = getBuildDirectory();
Expand Down Expand Up @@ -158,7 +165,27 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro
moduleInstaller.installModules(distroProperties.getWarArtifacts(), targetDirectory.getAbsolutePath());
renameWebApp(targetDirectory);

moduleInstaller.installModules(distroProperties.getModuleArtifacts(), targetDirectory.getAbsolutePath()+File.separator+"modules");
if (bundled) {
try {
ZipFile warfile = new ZipFile(new File(targetDirectory, OPENMRS_WAR));
File tempDir = new File(targetDirectory, "WEB-INF");
moduleInstaller.installModules(distroProperties.getModuleArtifacts(),
new File(tempDir, WAR_FILE_MODULES_DIRECTORY_NAME).getAbsolutePath());
ZipParameters parameters = new ZipParameters();
warfile.addFolder(tempDir, parameters);
try {
FileUtils.deleteDirectory(tempDir);
} catch (IOException e) {
throw new RuntimeException("Failed to remove " + tempDir.getName() + " file", e);
}
} catch (ZipException e) {
throw new RuntimeException("Failed to bundle modules into *.war file", e);
}
}
else {
moduleInstaller.installModules(distroProperties.getModuleArtifacts(),
new File(targetDirectory, "modules").getAbsolutePath());
}

wizard.showMessage("Creating Docker Compose configuration...\n");
String distroName = adjustImageName(distroProperties.getName());
Expand Down

0 comments on commit 05318b4

Please sign in to comment.