diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/AbstractSdkIT.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/AbstractSdkIT.java index f964a344..fedff9a3 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/AbstractSdkIT.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/AbstractSdkIT.java @@ -42,6 +42,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.not; import static org.hamcrest.io.FileMatchers.anExistingFileOrDirectory; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.openmrs.maven.plugins.SdkMatchers.hasModuleVersion; @@ -145,12 +146,12 @@ static synchronized int nextCounter() { return counter++; } - public String setupTestServer() throws Exception{ + public String setupTestServer(String distro) throws Exception{ Verifier setupServer = new Verifier(testDirectory.getAbsolutePath()); String serverId = UUID.randomUUID().toString(); try { addTaskParam(setupServer, "openMRSPath", testDirectory.getAbsolutePath()); - addTaskParam(setupServer, "distro", "referenceapplication:2.2"); + addTaskParam(setupServer, "distro", distro); addTaskParam(setupServer, "debug", "1044"); addMockDbSettings(setupServer); @@ -326,14 +327,14 @@ protected void assertServerInstalled(String serverId) { assertFilePresent(serverId, SDKConstants.OPENMRS_SERVER_PROPERTIES); } - protected void assertModulesInstalled(String serverId, String... filenames){ + protected void assertModulesInstalled(String serverId, String... filenames) { Path modulesRoot = testDirectoryPath.resolve(Paths.get(serverId, "modules")); - for(String filename : filenames){ + for(String filename : filenames) { assertPathPresent(modulesRoot.resolve(filename)); } } - protected void assertModulesInstalled(String serverId, DistroProperties distroProperties) { + protected void assertOnlyModulesInstalled(String serverId, DistroProperties distroProperties) { List modules = distroProperties.getModuleArtifacts(); String[] moduleFilenames = new String[modules.size()]; @@ -341,7 +342,13 @@ protected void assertModulesInstalled(String serverId, DistroProperties distroPr moduleFilenames[i] = modules.get(i).getDestFileName(); } - assertModulesInstalled(serverId, moduleFilenames); + Path modulesRoot = testDirectoryPath.resolve(Paths.get(serverId, "modules")); + File[] expectedFiles = modulesRoot.toFile().listFiles(f -> f.getName().endsWith(".omod")); + assertNotNull(expectedFiles); + assertThat(expectedFiles.length, equalTo(moduleFilenames.length)); + for(String filename : moduleFilenames) { + assertPathPresent(modulesRoot.resolve(filename)); + } } protected void addMockDbSettings() { @@ -376,4 +383,18 @@ protected String getAnswers() { answers = StringUtils.removeStart(answers, "["); return answers; } + + protected String getLogContents() throws Exception { + File logFile = new File(testDirectory, "log.txt"); + assertTrue(logFile.exists()); + return FileUtils.readFileToString(logFile, "UTF-8"); + } + + protected void assertLogContains(String message) throws Exception { + assertTrue(getLogContents().contains(message)); + } + + protected void assertLogDoesNotContain(String message) throws Exception { + assertFalse(getLogContents().contains(message)); + } } diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/AddExclusionIT.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/AddExclusionIT.java index e2dce834..da9d783f 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/AddExclusionIT.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/AddExclusionIT.java @@ -1,6 +1,5 @@ package org.openmrs.maven.plugins; -import org.apache.commons.io.FileUtils; import org.junit.Test; import org.openmrs.maven.plugins.model.DistroProperties; import org.openmrs.maven.plugins.utility.PropertiesUtils; @@ -8,7 +7,6 @@ import java.io.File; import java.util.Properties; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -35,7 +33,7 @@ public void shouldAddExclusionIfNoParentDefined() throws Exception { executeExclusionTask(distroFile, "omod.uicommons"); assertNotNull(getDistroProperties()); assertTrue(getDistroProperties().getExclusions().contains("omod.uicommons")); - assertTrue(getLogContents().contains(AddExclusion.WARNING_NO_PARENT_DISTRO)); + assertLogContains(AddExclusion.WARNING_NO_PARENT_DISTRO); } @Test @@ -47,8 +45,8 @@ public void shouldAddExclusionForPropertyContainedInParent() throws Exception { executeExclusionTask(distroFile, "omod.uicommons"); assertNotNull(getDistroProperties()); assertTrue(getDistroProperties().getExclusions().contains("omod.uicommons")); - assertFalse(getLogContents().contains(AddExclusion.WARNING_NO_PARENT_DISTRO)); - assertFalse(getLogContents().contains(AddExclusion.WARNING_PROPERTY_NOT_IN_PARENT)); + assertLogDoesNotContain(AddExclusion.WARNING_NO_PARENT_DISTRO); + assertLogDoesNotContain(AddExclusion.WARNING_PROPERTY_NOT_IN_PARENT); } @Test @@ -60,8 +58,8 @@ public void shouldAddExclusionForPropertyContainedInDistro() throws Exception { executeExclusionTask(distroFile, "omod.uicommons"); assertNotNull(getDistroProperties()); assertTrue(getDistroProperties().getExclusions().contains("omod.uicommons")); - assertFalse(getLogContents().contains(AddExclusion.WARNING_NO_PARENT_DISTRO)); - assertFalse(getLogContents().contains(AddExclusion.WARNING_PROPERTY_NOT_IN_PARENT)); + assertLogDoesNotContain(AddExclusion.WARNING_NO_PARENT_DISTRO); + assertLogDoesNotContain(AddExclusion.WARNING_PROPERTY_NOT_IN_PARENT); } @Test @@ -73,14 +71,8 @@ public void shouldAddExclusionForPropertyNotContainedInParent() throws Exception executeExclusionTask(distroFile, "omod.invalidmodulename"); assertNotNull(getDistroProperties()); assertTrue(getDistroProperties().getExclusions().contains("omod.invalidmodulename")); - assertFalse(getLogContents().contains(AddExclusion.WARNING_NO_PARENT_DISTRO)); - assertTrue(getLogContents().contains(AddExclusion.WARNING_PROPERTY_NOT_IN_PARENT)); - } - - private String getLogContents() throws Exception { - File logFile = new File(testDirectory, "log.txt"); - assertTrue(logFile.exists()); - return FileUtils.readFileToString(logFile, "UTF-8"); + assertLogDoesNotContain(AddExclusion.WARNING_NO_PARENT_DISTRO); + assertLogContains(AddExclusion.WARNING_PROPERTY_NOT_IN_PARENT); } private void executeExclusionTask(File distroFile, String exclusion) throws Exception { diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/BuildIT.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/BuildIT.java index 5aa4e0a2..95e5e8e2 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/BuildIT.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/BuildIT.java @@ -23,7 +23,7 @@ protected void addTestResources() throws Exception { @Override public void setup() throws Exception { super.setup(); - serverId = setupTestServer(); + serverId = setupTestServer("referenceapplication:2.2"); Server server = Server.loadServer(testDirectoryPath.resolve(serverId)); File firstDir = new File(testDirectory, "module1"); File secondDir = new File(testDirectory, "module2"); diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/DeployIT.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/DeployIT.java index 135d2c17..d24953af 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/DeployIT.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/DeployIT.java @@ -21,23 +21,22 @@ public class DeployIT extends AbstractSdkIT { - private static String testServerId; + private String testServerId; @Before @Override public void setup() throws Exception { super.setup(); - testServerId = setupTestServer(); } @Test public void deploy_shouldReplaceWebapp() throws Exception { + testServerId = setupTestServer("referenceapplication:2.2"); + assertFilePresent(testServerId, "openmrs-1.11.2.war"); + assertFileNotPresent(testServerId, "openmrs-1.11.5.war"); addTaskParam("platform", "1.11.5"); - addAnswer(testServerId); - executeTask("deploy"); - assertSuccess(); assertFilePresent(testServerId, "openmrs-1.11.5.war"); assertPlatformUpdated(testServerId, "1.11.5"); @@ -45,14 +44,15 @@ public void deploy_shouldReplaceWebapp() throws Exception { } @Test - public void deploy_shouldReplaceDistroPlatform() throws Exception{ + public void deploy_shouldReplaceDistroPlatform() throws Exception { + testServerId = setupTestServer("referenceapplication:2.2"); + assertFilePresent(testServerId, "openmrs-1.11.2.war"); + assertFileNotPresent(testServerId, "webservices.rest-2.16.omod"); + assertFileNotPresent(testServerId, "openmrs-2.0.2.war"); addTaskParam("platform", "2.0.2"); - addAnswer(testServerId); addAnswer("y"); - executeTask("deploy"); - assertSuccess(); assertFilePresent(testServerId, "openmrs-2.0.2.war"); assertModulesInstalled(testServerId, "webservices.rest-2.16.omod"); @@ -60,21 +60,18 @@ public void deploy_shouldReplaceDistroPlatform() throws Exception{ @Test public void deploy_shouldUpgradeDistroTo2_3_1() throws Exception { - + testServerId = setupTestServer("referenceapplication:2.2"); addAnswer(testServerId); addAnswer("Distribution"); addAnswer("referenceapplication:2.3.1"); addAnswer("y"); - executeTask("deploy"); - assertSuccess(); assertFilePresent(testServerId, "openmrs-1.11.5.war"); Properties properties = PropertiesUtils.loadPropertiesFromResource("openmrs-distro-2.3.1.properties"); DistroProperties distroProperties = new DistroProperties(properties); - assertModulesInstalled(testServerId, distroProperties); + assertOnlyModulesInstalled(testServerId, distroProperties); assertPlatformUpdated(testServerId, "1.11.5"); - Server.setServersPath(testDirectory.getAbsolutePath()); Server server = Server.loadServer(testServerId); assertThat(server, serverHasVersion("2.3.1")); @@ -82,41 +79,60 @@ public void deploy_shouldUpgradeDistroTo2_3_1() throws Exception { @Test public void deploy_shouldDowngradeDistroTo2_1() throws Exception { - + testServerId = setupTestServer("referenceapplication:2.2"); addAnswer(testServerId); addAnswer("Distribution"); addAnswer("referenceapplication:2.1"); addAnswer("y"); - executeTask("deploy"); - assertSuccess(); assertFilePresent(testServerId, "openmrs-1.10.0.war"); Properties properties = PropertiesUtils.loadPropertiesFromResource("openmrs-distro-2.1.properties"); DistroProperties distroProperties = new DistroProperties(properties); - assertModulesInstalled(testServerId, distroProperties); + assertOnlyModulesInstalled(testServerId, distroProperties); assertPlatformUpdated(testServerId, "1.10.0"); - Server.setServersPath(testDirectory.getAbsolutePath()); Server server = Server.loadServer(testServerId); assertThat(server, serverHasVersion("2.1")); } @Test - public void deploy_shouldUpgradeDistroTo3_0_0() throws Exception { + public void deploy_shouldUpgradeDistroTo2_13_0() throws Exception { + testServerId = setupTestServer("referenceapplication:2.3.1"); + addAnswer(testServerId); + addAnswer("Distribution"); + addAnswer("referenceapplication:2.13.0"); + addAnswer("y"); + executeTask("deploy"); + assertSuccess(); + assertFilePresent(testServerId, "openmrs-2.5.9.war"); + Properties properties = PropertiesUtils.loadPropertiesFromResource("integration-test/distributions/referenceapplication-package-2.13.0.properties"); + if ("2.2.6".equals(properties.get("omod.atlas"))) { + properties.setProperty("omod.atlas", "2.2.7"); + } + DistroProperties distroProperties = new DistroProperties(properties); + assertOnlyModulesInstalled(testServerId, distroProperties); + assertPlatformUpdated(testServerId, "2.5.9"); + assertFilePresent(testServerId, "owa"); + assertFilePresent(testServerId, "owa", "SystemAdministration.owa"); + Server.setServersPath(testDirectory.getAbsolutePath()); + Server server = Server.loadServer(testServerId); + assertThat(server, serverHasVersion("2.13.0")); + } + @Test + public void deploy_shouldUpgradeDistroTo3_0_0() throws Exception { + testServerId = setupTestServer("referenceapplication:2.2"); addAnswer(testServerId); addAnswer("Distribution"); addAnswer("referenceapplication:3.0.0"); addAnswer("y"); - executeTask("deploy"); - assertSuccess(); assertFilePresent(testServerId, "openmrs-2.6.7.war"); Properties properties = PropertiesUtils.loadPropertiesFromResource("integration-test/distributions/distro-emr-configuration-3.0.0.properties"); - DistroProperties distroProperties = new DistroProperties(properties); - assertModulesInstalled(testServerId, distroProperties); + + assertNumFilesPresent(24, Paths.get(testServerId, "modules"), null, ".omod"); assertPlatformUpdated(testServerId, "2.6.7"); assertNumFilesPresent(0, Paths.get(testServerId, "owa"), null, null); @@ -125,24 +141,93 @@ public void deploy_shouldUpgradeDistroTo3_0_0() throws Exception { assertFileContains("omod.spa", testServerId, "openmrs-distro.properties"); assertNumFilesPresent(1, Paths.get(testServerId, "modules"), "spa-", ".omod"); - // TODO: Deploy does not currently support installing or updating frontend or config or content. This needs to be ticketed and fixed + assertFilePresent(testServerId, "frontend"); + assertFilePresent(testServerId, "frontend", "index.html"); + assertFilePresent(testServerId, "frontend", "importmap.json"); + + assertFilePresent(testServerId, "configuration"); + assertFilePresent(testServerId, "configuration", "conceptclasses", "conceptclasses-core_data.csv"); Server.setServersPath(testDirectory.getAbsolutePath()); Server server = Server.loadServer(testServerId); assertThat(server, serverHasVersion("3.0.0")); + + assertLogContains("+ Adds frontend spa"); + assertLogContains("+ Adds frontend configuration"); } @Test - public void deploy_shouldUpgradeDistroFromDistroProperties() throws Exception { - includeDistroPropertiesFile(DistroProperties.DISTRO_FILE_NAME); + public void deploy_shouldUpgradeDistroWithConfigPackage() throws Exception { + testServerId = setupTestServer("referenceapplication:2.2"); + includeDistroPropertiesFile("openmrs-distro-configuration.properties"); addAnswer(testServerId); addAnswer("y"); addAnswer("y"); + executeTask("deploy"); + assertSuccess(); + assertFilePresent(testServerId, "configuration", "addresshierarchy", "addressConfiguration-core_demo.xml"); + assertFilePresent(testServerId, "configuration", "addresshierarchy", "addresshierarchy-core_demo.csv"); + assertFilePresent(testServerId, "configuration", "conceptclasses", "conceptclasses-core_data.csv"); + assertFilePresent(testServerId, "configuration", "encountertypes", "encountertypes_core-demo.csv"); + assertLogContains("+ Adds frontend configuration"); + } - assertFilePresent(testServerId, "modules", "appui-1.3.omod"); + @Test + public void deploy_shouldUpgradeDistroWithContentPackage() throws Exception { + testServerId = setupTestServer("referenceapplication:2.2"); + includeDistroPropertiesFile("openmrs-distro-content-package.properties"); + addAnswer(testServerId); + addAnswer("y"); + addAnswer("y"); + executeTask("deploy"); + assertSuccess(); + assertFilePresent(testServerId, "configuration", "conceptclasses", "hiv", "conceptclasses.csv"); + assertFilePresent(testServerId, "configuration", "conceptsources", "hiv", "conceptsources.csv"); + assertFilePresent(testServerId, "configuration", "encountertypes", "hiv", "encountertypes.csv"); + assertLogContains("+ Adds frontend configuration"); + } + @Test + public void deploy_shouldReplaceConfigurationAndContentIfChanged() throws Exception { + testServerId = setupTestServer("referenceapplication:2.2"); + + includeDistroPropertiesFile("openmrs-distro-configuration.properties"); + addAnswer(testServerId); + addAnswer("y"); + addAnswer("y"); + executeTask("deploy"); + assertSuccess(); + assertFilePresent(testServerId, "configuration", "addresshierarchy", "addressConfiguration-core_demo.xml"); + assertFilePresent(testServerId, "configuration", "addresshierarchy", "addresshierarchy-core_demo.csv"); + assertFilePresent(testServerId, "configuration", "conceptclasses", "conceptclasses-core_data.csv"); + assertFilePresent(testServerId, "configuration", "encountertypes", "encountertypes_core-demo.csv"); + assertLogContains("+ Adds frontend configuration"); + + includeDistroPropertiesFile("openmrs-distro-content-package.properties"); + addAnswer(testServerId); + addAnswer("y"); + addAnswer("y"); executeTask("deploy"); + assertSuccess(); + assertFileNotPresent(testServerId, "configuration", "addresshierarchy", "addressConfiguration-core_demo.xml"); + assertFileNotPresent(testServerId, "configuration", "addresshierarchy", "addresshierarchy-core_demo.csv"); + assertFileNotPresent(testServerId, "configuration", "conceptclasses", "conceptclasses-core_data.csv"); + assertFileNotPresent(testServerId, "configuration", "encountertypes", "encountertypes_core-demo.csv"); + assertFilePresent(testServerId, "configuration", "conceptclasses", "hiv", "conceptclasses.csv"); + assertFilePresent(testServerId, "configuration", "conceptsources", "hiv", "conceptsources.csv"); + assertFilePresent(testServerId, "configuration", "encountertypes", "hiv", "encountertypes.csv"); + assertLogContains("^ Updates frontend configuration"); + } + @Test + public void deploy_shouldUpgradeDistroFromDistroProperties() throws Exception { + testServerId = setupTestServer("referenceapplication:2.2"); + includeDistroPropertiesFile(DistroProperties.DISTRO_FILE_NAME); + addAnswer(testServerId); + addAnswer("y"); + addAnswer("y"); + assertFilePresent(testServerId, "modules", "appui-1.3.omod"); + executeTask("deploy"); assertSuccess(); assertFilePresent(testServerId, "openmrs-1.11.5.war"); assertFileNotPresent(testServerId, "modules", "appui-1.3.omod"); @@ -152,15 +237,14 @@ public void deploy_shouldUpgradeDistroFromDistroProperties() throws Exception { @Test public void deploy_shouldInstallModule() throws Exception { + testServerId = setupTestServer("referenceapplication:2.2"); addTaskParam("artifactId", "owa"); addTaskParam("groupId", Artifact.GROUP_MODULE); addTaskParam("version", "1.4"); - addAnswer(testServerId); addAnswer("y"); addAnswer("y"); executeTask("deploy"); - assertSuccess(); assertModulesInstalled(testServerId, "owa-1.4.omod"); assertModuleUpdated(testServerId, "owa", "1.4"); @@ -168,11 +252,11 @@ public void deploy_shouldInstallModule() throws Exception { @Test public void deploy_shouldInstallModuleFromPomInDir() throws Exception { + testServerId = setupTestServer("referenceapplication:2.2"); includePomFile("deployIT", "pom-owa-module.xml"); addAnswer(testServerId); addAnswer("y"); executeTask("deploy"); - assertSuccess(); assertModulesInstalled(testServerId, "owa-1.4.omod"); assertModuleUpdated(testServerId, "owa", "1.4"); @@ -180,13 +264,11 @@ public void deploy_shouldInstallModuleFromPomInDir() throws Exception { @Test public void deploy_shouldInstallOwaAndOwaModule() throws Exception { + testServerId = setupTestServer("referenceapplication:2.2"); addTaskParam("owa", "conceptdictionary:1.0.0"); - addAnswer(testServerId); addAnswer("y"); - executeTask("deploy"); - assertSuccess(); assertFilePresent(testServerId, "owa"); assertFilePresent(testServerId, "owa", "conceptdictionary.owa"); diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/PullIT.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/PullIT.java index 602a0dda..c6859cc1 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/PullIT.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/PullIT.java @@ -25,7 +25,7 @@ public class PullIT extends AbstractSdkIT { @Override public void setup() throws Exception { super.setup(); - serverId = setupTestServer(); + serverId = setupTestServer("referenceapplication:2.2"); cloneGitProject(); verifier = new Verifier(new File(testDirectory, OPENMRS_MODULE_IDGEN).getAbsolutePath()); addTaskParam("openMRSPath", testDirectory.getAbsolutePath()); diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/ResetIT.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/ResetIT.java index 584489c0..ac3c9087 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/ResetIT.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/ResetIT.java @@ -7,7 +7,7 @@ public class ResetIT extends AbstractSdkIT { @Test public void reset_shouldResetExistingServer() throws Exception { // create the server - String serverId = setupTestServer(); + String serverId = setupTestServer("referenceapplication:2.2"); // now reset the server addTaskParam("serverId", serverId); diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/SetupIT.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/SetupIT.java index 7c0432ea..00660f8c 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/SetupIT.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/SetupIT.java @@ -52,7 +52,7 @@ public void setup_shouldInstallRefapp2_3_1() throws Exception{ Properties properties = PropertiesUtils.loadPropertiesFromResource("openmrs-distro-2.3.1.properties"); DistroProperties distroProperties = new DistroProperties(properties); - assertModulesInstalled(serverId, distroProperties); + assertOnlyModulesInstalled(serverId, distroProperties); Server.setServersPath(testDirectory.getAbsolutePath()); Server server = Server.loadServer(serverId); @@ -83,7 +83,7 @@ public void setup_shouldInstallRefapp2_13_0() throws Exception{ assertThat(properties.get("omod.atlas"), equalTo("2.2.6")); properties.put("omod.atlas", "2.2.7"); DistroProperties distroProperties = new DistroProperties(properties); - assertModulesInstalled(serverId, distroProperties); + assertOnlyModulesInstalled(serverId, distroProperties); assertNumFilesPresent(42, Paths.get(serverId, "modules"), null, ".omod"); @@ -114,10 +114,6 @@ public void setup_shouldInstallRefapp3_0_0() throws Exception{ assertFilePresent(serverId, "openmrs-2.6.7.war"); assertFilePresent(serverId, "modules"); - Properties properties = PropertiesUtils.loadPropertiesFromResource("integration-test/distributions/distro-emr-configuration-3.0.0.properties"); - DistroProperties distroProperties = new DistroProperties(properties); - assertModulesInstalled(serverId, distroProperties); - assertNumFilesPresent(24, Paths.get(serverId, "modules"), null, ".omod"); assertNumFilesPresent(0, Paths.get(serverId, "owa"), null, null); diff --git a/integration-tests/src/test/resources/integration-test/openmrs-distro-configuration.properties b/integration-tests/src/test/resources/integration-test/openmrs-distro-configuration.properties new file mode 100644 index 00000000..f234fe40 --- /dev/null +++ b/integration-tests/src/test/resources/integration-test/openmrs-distro-configuration.properties @@ -0,0 +1,6 @@ +name=Config Package Example +version=1.0.0 +war.openmrs=2.6.9 +config.distro-emr-configuration=3.0.0 +config.distro-emr-configuration.groupId=org.openmrs +db.h2.supported=true \ No newline at end of file diff --git a/integration-tests/src/test/resources/integration-test/openmrs-distro-content-package.properties b/integration-tests/src/test/resources/integration-test/openmrs-distro-content-package.properties new file mode 100644 index 00000000..11d3e4b7 --- /dev/null +++ b/integration-tests/src/test/resources/integration-test/openmrs-distro-content-package.properties @@ -0,0 +1,7 @@ +name=Content Package Example +version=1.0.0 +war.openmrs=2.6.9 +content.hiv.groupId=org.openmrs.content +content.hiv.type=zip +content.hiv=1.0.0 +db.h2.supported=true \ No newline at end of file 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 bcfdc891..8eb6a30b 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 @@ -263,6 +263,7 @@ private String buildDistro(File targetDirectory, Distribution distribution) thro wizard.showMessage("Downloading modules...\n"); String distroName = adjustImageName(distroProperties.getName()); + File web = new File(targetDirectory, WEB); web.mkdirs(); @@ -281,11 +282,12 @@ private String buildDistro(File targetDirectory, Distribution distribution) thro downloadOWAs(targetDirectory, distroProperties, owasDir); spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); File frontendDir = new File(tempDir, "frontend"); - if(frontendDir.exists()) { + if (frontendDir.exists()) { frontendDir.renameTo(new File(tempDir, "bundledFrontend")); } - warfile.addFolder(tempDir, new ZipParameters()); + + // TODO: If the bundled war should have config and content, then add those here. try { FileUtils.deleteDirectory(tempDir); } @@ -296,7 +298,8 @@ private String buildDistro(File targetDirectory, Distribution distribution) thro catch (ZipException e) { throw new MojoExecutionException("Failed to bundle modules into *.war file " + e.getMessage(), e); } - } else { + } + else { File modulesDir = new File(web, "modules"); modulesDir.mkdir(); moduleInstaller.installModules(distroProperties.getModuleArtifacts(), modulesDir.getAbsolutePath()); @@ -316,7 +319,6 @@ private String buildDistro(File targetDirectory, Distribution distribution) thro downloadOWAs(targetDirectory, distroProperties, owasDir); } - boolean isAbovePlatform2point0 = isAbovePlatformVersion(new Version(distroProperties.getPlatformVersion()), 2, 0); if(isAbovePlatform2point0) { File openmrsCoreDir = new File(web, "openmrs_core"); @@ -487,8 +489,7 @@ private void copyDbDump(File targetDirectory, InputStream stream) throws MojoExe } } - private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, Artifact distroArtifact) - throws MojoExecutionException { + private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, Artifact distroArtifact) throws MojoExecutionException { InputStream stream = null; if (sqlScriptPath == null) { diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Deploy.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Deploy.java index cdaa459c..55e9fc32 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Deploy.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Deploy.java @@ -9,10 +9,12 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.openmrs.maven.plugins.model.Artifact; +import org.openmrs.maven.plugins.model.Distribution; import org.openmrs.maven.plugins.model.DistroProperties; import org.openmrs.maven.plugins.model.Project; import org.openmrs.maven.plugins.model.Server; import org.openmrs.maven.plugins.model.Version; +import org.openmrs.maven.plugins.utility.DistributionBuilder; import org.openmrs.maven.plugins.utility.SDKConstants; import java.io.File; @@ -128,19 +130,19 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { if ((platform == null && distro == null && owa == null) && artifactId == null) { Artifact artifact = checkCurrentDirectoryForOpenmrsWebappUpdate(server); - DistroProperties distroProperties = checkCurrentDirectoryForDistroProperties(); + Distribution distribution = checkCurrentDirectoryForDistribution(); if (artifact != null) { deployOpenmrsFromDir(server, artifact); - } else if (distroProperties != null) { - serverUpgrader.upgradeToDistro(server, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); + } else if (distribution != null) { + serverUpgrader.upgradeToDistro(server, distribution, ignorePeerDependencies, overrideReuseNodeCache); } else if (checkCurrentDirForModuleProject()) { deployModule(groupId, artifactId, version, server); } else { runInteractiveMode(server, serverUpgrader); } } else if (distro != null) { - DistroProperties distroProperties = distroHelper.resolveDistroPropertiesForStringSpecifier(distro, versionsHelper); - serverUpgrader.upgradeToDistro(server, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); + Distribution distribution = distroHelper.resolveDistributionForStringSpecifier(distro, versionsHelper); + serverUpgrader.upgradeToDistro(server, distribution, ignorePeerDependencies, overrideReuseNodeCache); } else if (platform != null) { deployOpenmrs(server, platform); } else if (owa != null) { @@ -176,8 +178,7 @@ private void runInteractiveMode(Server server, ServerUpgrader upgrader) server.getName(), server.getVersion())); - if (server.getName().equals("Platform") || server.getDistroGroupId() == null - || server.getDistroArtifactId() == null) { + if (server.getName().equals("Platform") || server.getDistroGroupId() == null || server.getDistroArtifactId() == null) { // If its impossible to define distro, prompt refapp distro versions distro = wizard.promptForRefAppVersion(versionsHelper); } else { @@ -186,8 +187,8 @@ private void runInteractiveMode(Server server, ServerUpgrader upgrader) server.getVersion(), server.getName(), versionsHelper); } wizard.showMessage("Deploying distribution: " + distro); - distroProperties = distroHelper.resolveDistroPropertiesForStringSpecifier(distro, versionsHelper); - upgrader.upgradeToDistro(server, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); + Distribution distribution = distroHelper.resolveDistributionForStringSpecifier(distro, versionsHelper); + upgrader.upgradeToDistro(server, distribution, ignorePeerDependencies, overrideReuseNodeCache); break; } case (DEPLOY_PLATFORM_OPTION): { @@ -230,7 +231,7 @@ private void deployOwa(Server server, String name, String version) throws MojoEx } boolean installOwaModule = true; - List serverModules = server.getServerModules(); + List serverModules = server.getModuleArtifacts(); Artifact owaModule = new Artifact("owa-omod", "1.0.0"); for (Artifact module : serverModules) { if (owaModule.getArtifactId().equals(module.getArtifactId())) { @@ -314,10 +315,10 @@ public void deployOpenmrsFromDir(Server server, Artifact artifact) throws MojoEx } } - private void deployOpenmrsPlatform(Server server, Artifact artifact) - throws MojoExecutionException, MojoFailureException { - DistroProperties platformDistroProperties = distroHelper - .downloadDistroProperties(server.getServerDirectory(), artifact); + private void deployOpenmrsPlatform(Server server, Artifact artifact) throws MojoExecutionException { + DistributionBuilder builder = new DistributionBuilder(getMavenEnvironment()); + Distribution distribution = builder.buildFromArtifact(artifact); + DistroProperties platformDistroProperties = distribution.getEffectiveProperties(); DistroProperties serverDistroProperties = server.getDistroProperties(); List warArtifacts = platformDistroProperties.getWarArtifacts(); @@ -326,7 +327,7 @@ private void deployOpenmrsPlatform(Server server, Artifact artifact) serverDistroProperties.setArtifacts(warArtifacts, moduleArtifacts); serverDistroProperties.saveTo(server.getServerDirectory()); ServerUpgrader serverUpgrader = new ServerUpgrader(this); - serverUpgrader.upgradeToDistro(server, serverDistroProperties, ignorePeerDependencies, overrideReuseNodeCache); + serverUpgrader.upgradeToDistro(server, distribution, ignorePeerDependencies, overrideReuseNodeCache); } /** @@ -477,20 +478,25 @@ public Artifact checkCurrentDirectoryForOpenmrsWebappUpdate(Server server) throw return null; } - private DistroProperties checkCurrentDirectoryForDistroProperties() throws MojoExecutionException { - DistroProperties distroProperties = distroHelper.getDistroPropertiesFromDir(); - if (distroProperties != null) { - String message = String.format( - "Would you like to deploy %s %s from the current directory?", - distroProperties.getName(), - distroProperties.getVersion()); - - boolean agree = wizard.promptYesNo(message); - if (agree) { - return distroProperties; + private Distribution checkCurrentDirectoryForDistribution() throws MojoExecutionException { + File distroPropertiesFile = distroHelper.getDistroPropertiesFileFromDir(); + if (distroPropertiesFile != null) { + Distribution distribution = null; + try { + DistributionBuilder builder = new DistributionBuilder(getMavenEnvironment()); + distribution = builder.buildFromFile(distroPropertiesFile); + } + catch (Exception e) { + wizard.showWarning("Found " + distroPropertiesFile.getAbsolutePath() + " but unable to load this into a distribution: " + e.getMessage()); + } + if (distribution != null) { + String message = String.format("Would you like to deploy %s %s from the current directory?", distribution.getName(), distribution.getVersion()); + boolean agree = wizard.promptYesNo(message); + if (agree) { + return distribution; + } } } - return null; } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/ServerUpgrader.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/ServerUpgrader.java index 2fc72783..4766c9a4 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/ServerUpgrader.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/ServerUpgrader.java @@ -3,8 +3,14 @@ import org.apache.commons.io.FileUtils; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.shared.utils.StringUtils; -import org.openmrs.maven.plugins.model.*; -import org.openmrs.maven.plugins.utility.DistroHelper; +import org.openmrs.maven.plugins.model.Artifact; +import org.openmrs.maven.plugins.model.BaseSdkProperties; +import org.openmrs.maven.plugins.model.Distribution; +import org.openmrs.maven.plugins.model.DistroProperties; +import org.openmrs.maven.plugins.model.Server; +import org.openmrs.maven.plugins.model.UpgradeDifferential; +import org.openmrs.maven.plugins.model.Version; +import org.openmrs.maven.plugins.utility.ContentHelper; import org.openmrs.maven.plugins.utility.SDKConstants; import java.io.File; @@ -14,8 +20,8 @@ import java.util.Map; public class ServerUpgrader { - private final AbstractTask parentTask; + private final AbstractTask parentTask; public ServerUpgrader(AbstractTask parentTask) { this.parentTask = parentTask; @@ -34,62 +40,182 @@ public void upgradePlatform(Server server, String version) throws MojoExecutionE parentTask.getLog().info(String.format("Server %s has been successfully upgraded to %s", server.getServerId(), version)); } - public void upgradeToDistro(Server server, DistroProperties distroProperties, boolean ignorePeerDependencies, Boolean overrideReuseNodeCache) throws MojoExecutionException { - UpgradeDifferential upgradeDifferential = DistroHelper.calculateUpdateDifferential(server, distroProperties); - boolean confirmed = parentTask.wizard.promptForConfirmDistroUpgrade(upgradeDifferential, server, distroProperties); - if(confirmed){ - server.saveBackupProperties(); + public void upgradeToDistro(Server server, Distribution distribution, boolean ignorePeerDependencies, Boolean overrideReuseNodeCache) throws MojoExecutionException { + boolean serverExists = server.getPropertiesFile().exists(); + UpgradeDifferential upgradeDifferential = calculateUpdateDifferential(server, distribution); + DistroProperties distroProperties = distribution.getEffectiveProperties(); + if (serverExists) { + boolean confirmed = parentTask.wizard.promptForConfirmDistroUpgrade(upgradeDifferential); + if (!confirmed) { + parentTask.wizard.showMessage("Server upgrade aborted"); + return; + } + } + server.saveBackupProperties(); + server.deleteServerTmpDirectory(); - String modulesDir = server.getServerDirectory().getPath()+File.separator+SDKConstants.OPENMRS_SERVER_MODULES; - if(upgradeDifferential.getPlatformArtifact()!=null){ - server.deleteServerTmpDirectory(); - replaceWebapp(server, upgradeDifferential.getPlatformArtifact().getVersion()); + if (distroProperties.getVersion() != null) { + server.setVersion(distroProperties.getVersion()); + } + + // Upgrade the war + File warFile = server.getWarFile(); + UpgradeDifferential.ArtifactChanges warChanges = upgradeDifferential.getWarChanges(); + if (warChanges.hasChanges() || !warFile.exists()) { + if (warChanges.getNewArtifacts().isEmpty()) { + throw new MojoExecutionException("Deleting openmrs war is not supported"); } - if(!upgradeDifferential.getModulesToAdd().isEmpty()){ - parentTask.moduleInstaller.installModules(upgradeDifferential.getModulesToAdd(), modulesDir); - for(Artifact artifact: upgradeDifferential.getModulesToAdd()){ - server.setModuleProperties(artifact); - } + if (warChanges.getNewArtifacts().size() > 1) { + throw new MojoExecutionException("Only one openmrs war can be configured in a distribution"); } - if(!upgradeDifferential.getModulesToDelete().isEmpty()){ - for(Artifact artifact: upgradeDifferential.getModulesToDelete()){ - File moduleToDelete = new File(modulesDir, artifact.getDestFileName()); - moduleToDelete.delete(); - server.removeModuleProperties(artifact); + replaceWebapp(server, warChanges.getNewArtifacts().get(0).getVersion()); + } + + // Upgrade modules + UpgradeDifferential.ArtifactChanges moduleChanges = upgradeDifferential.getModuleChanges(); + if (moduleChanges.hasChanges()) { + File modulesDir = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_MODULES); + for (Artifact artifact : moduleChanges.getArtifactsToRemove()) { + File moduleToDelete = new File(modulesDir, artifact.getDestFileName()); + if (moduleToDelete.delete()) { + parentTask.wizard.showMessage("Removed module: " + moduleToDelete.getAbsolutePath()); } + server.removeModuleProperties(artifact); + } + parentTask.moduleInstaller.installModules(moduleChanges.getArtifactsToAdd(), modulesDir.getAbsolutePath()); + for (Artifact artifact : moduleChanges.getArtifactsToAdd()) { + server.setModuleProperties(artifact); } - if(!upgradeDifferential.getUpdateOldToNewMap().isEmpty()){ - for(Map.Entry updateEntry : upgradeDifferential.getUpdateOldToNewMap().entrySet()){ - updateModule(server, modulesDir, updateEntry); + } + + // Upgrade owas + UpgradeDifferential.ArtifactChanges owaChanges = upgradeDifferential.getOwaChanges(); + if (owaChanges.hasChanges()) { + File owaDir = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_OWA); + if (owaDir.mkdir()) { + parentTask.wizard.showMessage("Created directory: " + owaDir.getName()); + } + for (Artifact artifact : owaChanges.getArtifactsToRemove()) { + File owaFile = new File(owaDir, artifact.getDestFileName()); + if (owaFile.delete()) { + parentTask.wizard.showMessage("Removed owa file: " + owaFile.getName()); } + File owaExpandedDir = new File(owaDir, artifact.getArtifactId()); + if (owaExpandedDir.exists()) { + try { + FileUtils.deleteDirectory(owaExpandedDir); + parentTask.wizard.showMessage("Removed owa dir: " + owaExpandedDir); + } catch (IOException e) { + throw new MojoExecutionException("Failed to delete directory: " + owaExpandedDir.getAbsolutePath(), e); + } + } + server.removePropertiesForArtifact(BaseSdkProperties.TYPE_OWA, artifact); + } + for (Artifact artifact : owaChanges.getArtifactsToAdd()) { + parentTask.wizard.showMessage("Installing OWA: " + artifact.getArtifactId()); + parentTask.owaHelper.downloadOwa(owaDir, artifact, parentTask.moduleInstaller); + server.addPropertiesForArtifact(BaseSdkProperties.TYPE_OWA, artifact); } - if(!upgradeDifferential.getDowngradeNewToOldMap().isEmpty()){ - for(Map.Entry downgradeEntry : upgradeDifferential.getDowngradeNewToOldMap().entrySet()){ - updateModule(server, modulesDir, downgradeEntry); + } + + // Upgrade spa + UpgradeDifferential.ArtifactChanges spaArtifactChanges = upgradeDifferential.getSpaArtifactChanges(); + UpgradeDifferential.PropertyChanges spaBuildChanges = upgradeDifferential.getSpaBuildChanges(); + boolean updateSpa = spaArtifactChanges.hasChanges() || spaBuildChanges.hasChanges(); + if (updateSpa) { + parentTask.spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); + } + + // Upgrade config and content + UpgradeDifferential.ArtifactChanges configChanges = upgradeDifferential.getConfigChanges(); + UpgradeDifferential.ArtifactChanges contentChanges = upgradeDifferential.getContentChanges(); + + if (configChanges.hasChanges() || contentChanges.hasChanges()) { + + // TODO: This should happen in a higher-level validation stage and this method needs refactoring + parentTask.distroHelper.parseContentProperties(distroProperties); + + File configDir = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_CONFIGURATION); + if (configDir.exists()) { + parentTask.wizard.showMessage("Removing existing configuration and content packages"); + try { + FileUtils.deleteDirectory(configDir); + } + catch (IOException e) { + throw new MojoExecutionException("Unable to delete existing configuration directory", e); } } - parentTask.spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties); - server.setVersion(distroProperties.getVersion()); - server.setName(distroProperties.getName()); - server.getDistroPropertiesFile().delete(); - distroProperties.saveTo(server.getServerDirectory()); - server.deleteBackupProperties(); - deleteDependencyPluginMarker(); - server.saveAndSynchronizeDistro(); - parentTask.getLog().info("Server upgraded successfully"); - } else { - parentTask.wizard.showMessage("Server upgrade aborted"); + if (configChanges.hasChanges()) { + parentTask.configurationInstaller.installToServer(server, distroProperties); + } + + if (contentChanges.hasChanges()) { + ContentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties, parentTask.moduleInstaller, parentTask.wizard); + // TODO: Where is the frontend config installation? + } + } + server.setVersion(distroProperties.getVersion()); + server.setName(distroProperties.getName()); + if (server.getDistroPropertiesFile().delete()) { + parentTask.wizard.showMessage("Removed old distro properties file, and saving new one"); + } + distroProperties.saveTo(server.getServerDirectory()); + server.deleteBackupProperties(); + deleteDependencyPluginMarker(); + server.saveAndSynchronizeDistro(); + parentTask.getLog().info("Server upgraded successfully"); } - private void updateModule(Server server, String modulesDir, Map.Entry updateEntry) throws MojoExecutionException { - File oldModule = new File(modulesDir, updateEntry.getKey().getDestFileName()); - oldModule.delete(); - server.removeModuleProperties(updateEntry.getKey()); - parentTask.moduleInstaller.installModule(updateEntry.getValue(), modulesDir); - server.setModuleProperties(updateEntry.getValue()); + /** + * should: + * - ignore modules which are already on server, but not included in distro properties of upgrade + * - keep new platform artifact if distro properties declares newer version + * - updateMap include modules which are already on server with newer/equal SNAPSHOT version + * - add modules which are not installed on server yet + */ + public UpgradeDifferential calculateUpdateDifferential(Server server, Distribution distribution) { + + UpgradeDifferential upgradeDifferential = new UpgradeDifferential(server, distribution); + DistroProperties distroProperties = distribution.getEffectiveProperties(); + + // War File + List oldWars = server.getWarArtifacts(); + List newWars = distroProperties.getWarArtifacts(); + upgradeDifferential.setWarChanges(new UpgradeDifferential.ArtifactChanges(oldWars, newWars)); + + // Modules + List oldModules = server.getModuleArtifacts(); + List newModules = distroProperties.getModuleArtifacts(); + upgradeDifferential.setModuleChanges(new UpgradeDifferential.ArtifactChanges(oldModules, newModules)); + + // Owas + List oldOwas = server.getOwaArtifacts(); + List newOwas = distroProperties.getOwaArtifacts(); + upgradeDifferential.setOwaChanges(new UpgradeDifferential.ArtifactChanges(oldOwas, newOwas)); + + // Spa + List oldSpa = server.getSpaArtifacts(); + List newSpa = distroProperties.getSpaArtifacts(); + upgradeDifferential.setSpaArtifactChanges(new UpgradeDifferential.ArtifactChanges(oldSpa, newSpa)); + + Map oldSpaProps = server.getSpaBuildProperties(); + Map newSpaProps = distroProperties.getSpaBuildProperties(); + upgradeDifferential.setSpaBuildChanges(new UpgradeDifferential.PropertyChanges(oldSpaProps, newSpaProps)); + + // Config + List oldConfig = server.getConfigArtifacts(); + List newConfig = distroProperties.getConfigArtifacts(); + upgradeDifferential.setConfigChanges(new UpgradeDifferential.ArtifactChanges(oldConfig, newConfig)); + + // Content + List oldContent = server.getContentArtifacts(); + List newContent = distroProperties.getContentArtifacts(); + upgradeDifferential.setContentChanges(new UpgradeDifferential.ArtifactChanges(oldContent, newContent)); + + return upgradeDifferential; } /** @@ -128,8 +254,10 @@ private void confirmUpgrade(String prevVersion, String nextVersion) throws MojoE * @throws MojoExecutionException */ private void replaceWebapp(Server server, String version) throws MojoExecutionException { - File webapp = new File(server.getServerDirectory(), "openmrs-"+server.getPlatformVersion()+".war"); - webapp.delete(); + File webapp = server.getWarFile(); + if (webapp.delete()) { + parentTask.wizard.showMessage("Replacing existing war: " + webapp.getName()); + } Artifact webappArtifact = new Artifact(SDKConstants.WEBAPP_ARTIFACT_ID, version, Artifact.GROUP_WEB, Artifact.TYPE_WAR); parentTask.moduleInstaller.installModule(webappArtifact, server.getServerDirectory().getPath()); server.setPlatformVersion(version); @@ -191,11 +319,7 @@ public void validateServerMetadata(Path serverPath) throws MojoExecutionExceptio distroProperties.saveTo(serverPath.toAbsolutePath().toFile()); } if(StringUtils.isNotBlank(server.getParam(Server.PROPERTY_PLATFORM))){ - server.setValuesFromDistroPropertiesModules( - server.getDistroProperties().getWarArtifacts(), - server.getDistroProperties().getModuleArtifacts(), - server.getDistroProperties() - ); + server.setValuesFromDistroProperties(server.getDistroProperties()); updateModulesPropertiesWithUserModules(server); server.removePlatformVersionProperty(); server.removeUserModulesProperty(); 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 81c23a04..d473e0d1 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 @@ -204,10 +204,21 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu } List options = new ArrayList<>(); - DistroProperties distroProperties = distroHelper.getDistroPropertiesFromDir(); - if (distroProperties != null) { - options.add(distroProperties.getName() + " " + distroProperties.getVersion() + " from current directory"); + + Distribution currentDirectoryDistribution = null; + File distroPropertiesFile = distroHelper.getDistroPropertiesFileFromDir(); + if (distroPropertiesFile != null) { + try { + currentDirectoryDistribution = builder.buildFromFile(distroPropertiesFile); + if (currentDirectoryDistribution != null) { + options.add(currentDirectoryDistribution.getName() + " " + currentDirectoryDistribution.getVersion() + " from current directory"); + } + } + catch (Exception e) { + wizard.showWarning("Found " + distroPropertiesFile.getAbsolutePath() + " but unable to load this into a distribution: " + e.getMessage()); + } } + options.add(O3_DISTRIBUTION); options.add(O2_DISTRIBUTION); options.add(PLATFORM); @@ -230,7 +241,10 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu } // If here, it is because the option to set up from current directory was chosen, and these properties were already loaded, just return them - return distroProperties; + if (currentDirectoryDistribution == null) { + throw new MojoExecutionException("No valid distribution could be found"); + } + return currentDirectoryDistribution.getEffectiveProperties(); } private DistroProperties resolveDistroPropertiesForPlatform(Server server, String version) throws MojoExecutionException { @@ -296,9 +310,7 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE setJdk(server); - server.setValuesFromDistroPropertiesModules( - distroProperties.getWarArtifacts(), - distroProperties.getModuleArtifacts(), distroProperties); + server.setValuesFromDistroProperties(distroProperties); server.setUnspecifiedToDefault(); server.save(); } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ConfigurationInstaller.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ConfigurationInstaller.java index eb247b48..f8d2f804 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ConfigurationInstaller.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ConfigurationInstaller.java @@ -10,7 +10,6 @@ import java.io.IOException; import java.util.List; import java.util.Objects; -import java.util.UUID; /** * Supports retrieving the configuration artifacts specified in the distribution @@ -35,21 +34,15 @@ public ConfigurationInstaller(DistroHelper distroHelper) { */ public void installToServer(Server server, DistroProperties distroProperties) throws MojoExecutionException { File directory = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_CONFIGURATION); - File tempDir = new File(server.getServerTmpDirectory(), UUID.randomUUID().toString()); - installToDirectory(directory, tempDir, distroProperties); + installToDirectory(directory, distroProperties); } public void installToDirectory(File installDir, DistroProperties distroProperties) throws MojoExecutionException { - File tempDir = new File(installDir.getParentFile(), UUID.randomUUID().toString()); - installToDirectory(installDir, tempDir, distroProperties); - } - - protected void installToDirectory(File installDir, File tempDir, DistroProperties distroProperties) throws MojoExecutionException { if (distroProperties.getConfigArtifacts().isEmpty()) { return; } if (installDir.mkdirs()) { - wizard.showMessage("Created configuration directory: " + installDir.getAbsolutePath()); + wizard.showMessage("Created configuration directory"); } wizard.showMessage("Downloading Configuration...\n"); @@ -58,13 +51,10 @@ protected void installToDirectory(File installDir, File tempDir, DistroPropertie for (Artifact configArtifact : configs) { // Some config artifacts have their configuration packaged in an "openmrs_config" subfolder within the zip // If such a folder is found in the downloaded artifact, use it. Otherwise, use the entire zip contents - try { - if (!tempDir.mkdirs()) { - throw new MojoExecutionException("Unable to create temporary directory " + tempDir + "\n"); - } + try (TempDirectory tempDir = TempDirectory.create(configArtifact.getArtifactId())){ moduleInstaller.installAndUnpackModule(configArtifact, tempDir.getAbsolutePath()); - File directoryToCopy = tempDir; - for (File f : Objects.requireNonNull(tempDir.listFiles())) { + File directoryToCopy = tempDir.getFile(); + for (File f : Objects.requireNonNull(tempDir.getFile().listFiles())) { if (f.isDirectory() && f.getName().equals("openmrs_config")) { directoryToCopy = f; } @@ -75,9 +65,6 @@ protected void installToDirectory(File installDir, File tempDir, DistroPropertie throw new MojoExecutionException("Unable to copy config: " + directoryToCopy + "\n"); } } - finally { - FileUtils.deleteQuietly(tempDir); - } } } } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java index 46870bee..0028e25c 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java @@ -88,11 +88,9 @@ public void installModulesForDistro(Server server, DistroProperties properties) } public void installModules(List artifacts, String outputDir) throws MojoExecutionException { - prepareModules(artifacts.toArray(new Artifact[0]), outputDir, GOAL_COPY); - } - - public void installModules(Artifact[] artifacts, String outputDir) throws MojoExecutionException { - prepareModules(artifacts, outputDir, GOAL_COPY); + if (!artifacts.isEmpty()) { + prepareModules(artifacts.toArray(new Artifact[0]), outputDir, GOAL_COPY); + } } public void installModule(Artifact artifact, String outputDir) throws MojoExecutionException { 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 e6cf19dc..1817caac 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 @@ -36,8 +36,6 @@ public class SpaInstaller { static final String NPM_VERSION = "10.8.2"; - static final String BUILD_TARGET_DIR = "frontend"; - private final NodeHelper nodeHelper; private final DistroHelper distroHelper; @@ -73,35 +71,37 @@ public void installFromDistroProperties(File appDataDir, DistroProperties distro public void installFromDistroProperties(File appDataDir, DistroProperties distroProperties, boolean ignorePeerDependencies, Boolean overrideReuseNodeCache) throws MojoExecutionException { - File buildTargetDir = new File(appDataDir, BUILD_TARGET_DIR); + File buildTargetDir = new File(appDataDir, SDKConstants.OPENMRS_SERVER_FRONTEND); if (buildTargetDir.exists()) { try { FileUtils.deleteDirectory(buildTargetDir); } catch (IOException e) { - throw new MojoExecutionException("Unable to delete existing " + BUILD_TARGET_DIR + " directory", e); + throw new MojoExecutionException("Unable to delete existing " + SDKConstants.OPENMRS_SERVER_FRONTEND + " directory", e); } } - // Retrieve the properties with a spa. prefix out of the distro properties - Map spaProperties = distroProperties.getSpaProperties(); + Map spaArtifactProperties = distroProperties.getSpaArtifactProperties(); + Map spaBuildProperties = distroProperties.getSpaBuildProperties(); + if (!spaArtifactProperties.isEmpty() && !spaBuildProperties.isEmpty()) { + throw new MojoExecutionException("You cannot specify both spa artifact and build properties"); + } // If a maven artifact is defined, then we download the artifact and unpack it - String artifactId = spaProperties.remove(BaseSdkProperties.ARTIFACT_ID); - if (artifactId != null) { - wizard.showMessage("Found spa.artifactId in distro properties: " + artifactId); - String groupId = spaProperties.remove(BaseSdkProperties.GROUP_ID); - String version = spaProperties.remove(BaseSdkProperties.VERSION); - if (groupId == null || version == null) { + List spaArtifacts = distroProperties.getSpaArtifacts(); + if (!spaArtifacts.isEmpty()) { + if (spaArtifacts.size() > 1) { + throw new MojoExecutionException("Only a single spa artifact is supported"); + } + Artifact artifact = spaArtifacts.get(0); + if (artifact.getGroupId() == null || artifact.getVersion() == null) { throw new MojoExecutionException("If specifying a spa.artifactId, you must also specify a spa.groupId and spa.version property"); } - String type = spaProperties.remove(BaseSdkProperties.ARTIFACT_ID); - String includes = spaProperties.remove(BaseSdkProperties.INCLUDES); - Artifact artifact = new Artifact(artifactId, version, groupId, (type == null ? BaseSdkProperties.TYPE_ZIP : type)); wizard.showMessage("Installing SPA from Maven artifact: " + artifact); if (buildTargetDir.mkdirs()) { - wizard.showMessage("Created " + BUILD_TARGET_DIR + " directory: " + buildTargetDir.getAbsolutePath()); + wizard.showMessage("Created " + SDKConstants.OPENMRS_SERVER_FRONTEND + " directory: " + buildTargetDir.getAbsolutePath()); } + String includes = spaArtifactProperties.get(BaseSdkProperties.INCLUDES); moduleInstaller.installAndUnpackModule(artifact, buildTargetDir, includes); wizard.showMessage("SPA successfully installed to " + buildTargetDir.getAbsolutePath()); return; @@ -111,27 +111,27 @@ public void installFromDistroProperties(File appDataDir, DistroProperties distro // First pull any optional properties that may be used to specify the core, node, or npm versions // These properties are not passed to the build tool, but are used to specify the build execution itself - String coreVersion = spaProperties.remove("core"); + String coreVersion = spaBuildProperties.remove("core"); if (coreVersion == null) { coreVersion = "next"; } - String nodeVersion = spaProperties.remove("node"); + String nodeVersion = spaBuildProperties.remove("node"); if (nodeVersion == null) { nodeVersion = NODE_VERSION; } - String npmVersion = spaProperties.remove("npm"); + String npmVersion = spaBuildProperties.remove("npm"); if (npmVersion == null) { npmVersion = NPM_VERSION; } // If there are no remaining spa properties, then no spa configuration has been provided - if (spaProperties.isEmpty()) { + if (spaBuildProperties.isEmpty()) { wizard.showMessage("No spa configuration found in the distro properties"); return; } // If there are remaining spa properties, then build and install using node - Map spaConfigJson = convertPropertiesToJSON(spaProperties); + Map spaConfigJson = convertPropertiesToJSON(spaBuildProperties); File spaConfigFile = new File(appDataDir, "spa-build-config.json"); writeJSONObject(spaConfigFile, spaConfigJson); diff --git a/maven-plugin/src/test/java/org/openmrs/maven/plugins/ServerUpgraderTest.java b/maven-plugin/src/test/java/org/openmrs/maven/plugins/ServerUpgraderTest.java new file mode 100644 index 00000000..2690f88b --- /dev/null +++ b/maven-plugin/src/test/java/org/openmrs/maven/plugins/ServerUpgraderTest.java @@ -0,0 +1,235 @@ +package org.openmrs.maven.plugins; + +import org.junit.Test; +import org.openmrs.maven.plugins.model.Artifact; +import org.openmrs.maven.plugins.model.Distribution; +import org.openmrs.maven.plugins.model.DistroProperties; +import org.openmrs.maven.plugins.model.Server; +import org.openmrs.maven.plugins.model.UpgradeDifferential; + +import java.util.Properties; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.mockito.Mockito.mock; + +public class ServerUpgraderTest { + + ServerUpgrader upgrader = new ServerUpgrader(mock(AbstractServerTask.class)); + UpgradeDifferential differential = null; + + @Test + public void calculateUpdateDifferential_shouldCalculateArtifactsToAdd() { + Server server = server(properties()); + Properties p = new Properties(); + p.put("war.openmrs", "2.5.9"); + p.put("omod.owa", "1.5"); + p.put("owa.openmrs-owa-sysadmin", "1.2"); + p.put("content.hiv", "1.0.0"); + p.put("config.referenceapplication", "3.0.0"); + p.put("spa.artifactId", "spaArtifactId"); + p.put("spa.frontendModules.@openmrs/esm-login-app", "5.6.0"); + Distribution distribution = distribution(p); + differential = upgrader.calculateUpdateDifferential(server, distribution); + assertNumChanges(differential.getWarChanges(), 1, 0, 0, 0); + assertNumChanges(differential.getModuleChanges(), 1, 0, 0, 0); + assertNumChanges(differential.getContentChanges(), 1, 0, 0, 0); + assertNumChanges(differential.getConfigChanges(), 1, 0, 0, 0); + assertNumChanges(differential.getSpaArtifactChanges(), 1, 0, 0, 0); + assertNumChanges(differential.getSpaBuildChanges(), 1, 0, 0); + assertModuleAdded(differential, "owa", "1.5"); + } + + @Test + public void calculateUpdateDifferential_shouldCalculateArtifactsToRemove() { + Properties p = new Properties(); + p.put("war.openmrs", "2.5.9"); + p.put("omod.owa", "1.5"); + p.put("owa.openmrs-owa-sysadmin", "1.2"); + p.put("content.hiv", "1.0.0"); + p.put("config.referenceapplication", "3.0.0"); + p.put("spa.artifactId", "spaArtifactId"); + p.put("spa.frontendModules.@openmrs/esm-login-app", "5.6.0"); + Server server = server(p); + Distribution distribution = distribution(properties()); + differential = upgrader.calculateUpdateDifferential(server, distribution); + assertNumChanges(differential.getWarChanges(), 0, 1, 0, 0); + assertNumChanges(differential.getModuleChanges(), 0, 1, 0, 0); + assertNumChanges(differential.getContentChanges(), 0, 1, 0, 0); + assertNumChanges(differential.getConfigChanges(), 0, 1, 0, 0); + assertNumChanges(differential.getSpaArtifactChanges(), 0, 1, 0, 0); + assertNumChanges(differential.getSpaBuildChanges(), 0, 1, 0); + assertModuleRemoved(differential, "owa", "1.5"); + } + + @Test + public void calculateUpdateDifferential_shouldCalculateArtifactsToUpgrade() { + Properties serverProperties = new Properties(); + serverProperties.put("war.openmrs", "1.11.5"); + serverProperties.put("omod.owa", "1.5"); + serverProperties.put("owa.openmrs-owa-sysadmin", "1.2"); + serverProperties.put("content.hiv", "1.0.0"); + serverProperties.put("config.referenceapplication", "3.0.0"); + serverProperties.put("spa.artifactId", "refapp"); + serverProperties.put("spa.groupId", "org.openmrs.frontend"); + serverProperties.put("spa.version", "1.0.0"); + serverProperties.put("spa.frontendModules.@openmrs/esm-login-app", "5.6.0"); + Server server = server(serverProperties); + Properties distroProperties = new Properties(); + distroProperties.put("war.openmrs", "2.5.9"); + distroProperties.put("omod.owa", "1.6"); + distroProperties.put("owa.openmrs-owa-sysadmin", "2.0"); + distroProperties.put("content.hiv", "1.1.0"); + distroProperties.put("config.referenceapplication", "3.1.0"); + distroProperties.put("spa.artifactId", "refapp"); + distroProperties.put("spa.groupId", "org.openmrs.frontend"); + distroProperties.put("spa.version", "1.1.0"); + distroProperties.put("spa.frontendModules.@openmrs/esm-login-app", "5.7.0"); + Distribution distribution = distribution(distroProperties); + differential = upgrader.calculateUpdateDifferential(server, distribution); + assertNumChanges(differential.getWarChanges(), 0, 0, 1, 0); + assertNumChanges(differential.getModuleChanges(), 0, 0, 1, 0); + assertNumChanges(differential.getContentChanges(), 0, 0, 1, 0); + assertNumChanges(differential.getConfigChanges(), 0, 0, 1, 0); + assertNumChanges(differential.getSpaArtifactChanges(), 0, 0, 1, 0); + assertNumChanges(differential.getSpaBuildChanges(), 0, 0, 1); + assertModuleUpgraded(differential, "owa", "1.5", "1.6"); + } + + @Test + public void calculateUpdateDifferential_shouldCalculateArtifactsToDowngrade() { + Properties serverProperties = new Properties(); + serverProperties.put("war.openmrs", "2.5.9"); + serverProperties.put("omod.owa", "1.6"); + serverProperties.put("owa.openmrs-owa-sysadmin", "2.0"); + serverProperties.put("content.hiv", "1.1.0"); + serverProperties.put("config.referenceapplication", "3.1.0"); + serverProperties.put("spa.artifactId", "refapp"); + serverProperties.put("spa.groupId", "org.openmrs.frontend"); + serverProperties.put("spa.version", "1.1.0"); + serverProperties.put("spa.frontendModules.@openmrs/esm-login-app", "5.7.0"); + Server server = server(serverProperties); + Properties distroProperties = new Properties(); + distroProperties.put("war.openmrs", "1.11.5"); + distroProperties.put("omod.owa", "1.5"); + distroProperties.put("owa.openmrs-owa-sysadmin", "1.2"); + distroProperties.put("content.hiv", "1.0.0"); + distroProperties.put("config.referenceapplication", "3.0.0"); + distroProperties.put("spa.artifactId", "refapp"); + distroProperties.put("spa.groupId", "org.openmrs.frontend"); + distroProperties.put("spa.version", "1.0.0"); + distroProperties.put("spa.frontendModules.@openmrs/esm-login-app", "5.6.0"); + Distribution distribution = distribution(distroProperties); + differential = upgrader.calculateUpdateDifferential(server, distribution); + assertNumChanges(differential.getWarChanges(), 0, 0, 0, 1); + assertNumChanges(differential.getModuleChanges(), 0, 0, 0, 1); + assertNumChanges(differential.getContentChanges(), 0, 0, 0, 1); + assertNumChanges(differential.getConfigChanges(), 0, 0, 0, 1); + assertNumChanges(differential.getSpaArtifactChanges(), 0, 0, 0, 1); + assertNumChanges(differential.getSpaBuildChanges(), 0, 0, 1); + assertModuleDowngraded(differential, "owa", "1.6", "1.5"); + } + + @Test + public void calculateUpdateDifferential_shouldNotUpgradeIfNoChanges() { + Properties serverProperties = new Properties(); + serverProperties.put("war.openmrs", "2.5.9"); + serverProperties.put("omod.owa", "1.6"); + serverProperties.put("owa.openmrs-owa-sysadmin", "2.0"); + serverProperties.put("content.hiv", "1.1.0"); + serverProperties.put("config.referenceapplication", "3.1.0"); + serverProperties.put("spa.artifactId", "refapp"); + serverProperties.put("spa.groupId", "org.openmrs.frontend"); + serverProperties.put("spa.version", "1.1.0"); + serverProperties.put("spa.frontendModules.@openmrs/esm-login-app", "5.7.0"); + Server server = server(serverProperties); + Properties distroProperties = new Properties(); + distroProperties.putAll(serverProperties); + Distribution distribution = distribution(distroProperties); + differential = upgrader.calculateUpdateDifferential(server, distribution); + assertNumChanges(differential.getWarChanges(), 0, 0, 0, 0); + assertNumChanges(differential.getModuleChanges(), 0, 0, 0, 0); + assertNumChanges(differential.getContentChanges(), 0, 0, 0, 0); + assertNumChanges(differential.getConfigChanges(), 0, 0, 0, 0); + assertNumChanges(differential.getSpaArtifactChanges(), 0, 0, 0, 0); + assertNumChanges(differential.getSpaBuildChanges(), 0, 0, 0); + } + + @Test + public void calculateUpdateDifferential_shouldUpgradeSnapshots() { + Properties serverProperties = new Properties(); + serverProperties.put("war.openmrs", "2.5.9-SNAPSHOT"); + serverProperties.put("omod.owa", "1.6-SNAPSHOT"); + serverProperties.put("owa.openmrs-owa-sysadmin", "2.0-SNAPSHOT"); + serverProperties.put("content.hiv", "1.1.0-SNAPSHOT"); + serverProperties.put("config.referenceapplication", "3.1.0-SNAPSHOT"); + serverProperties.put("spa.artifactId", "refapp"); + serverProperties.put("spa.groupId", "org.openmrs.frontend"); + serverProperties.put("spa.version", "1.1.0-SNAPSHOT"); + serverProperties.put("spa.frontendModules.@openmrs/esm-login-app", "next"); + Server server = server(serverProperties); + Properties distroProperties = new Properties(); + distroProperties.putAll(serverProperties); + Distribution distribution = distribution(distroProperties); + differential = upgrader.calculateUpdateDifferential(server, distribution); + assertNumChanges(differential.getWarChanges(), 0, 0, 1, 0); + assertNumChanges(differential.getModuleChanges(), 0, 0, 1, 0); + assertNumChanges(differential.getContentChanges(), 0, 0, 1, 0); + assertNumChanges(differential.getConfigChanges(), 0, 0, 1, 0); + assertNumChanges(differential.getSpaArtifactChanges(), 0, 0, 1, 0); + assertNumChanges(differential.getSpaBuildChanges(), 0, 0, 1); + } + + public void assertNumChanges(UpgradeDifferential.ArtifactChanges artifactChanges, int added, int removed, int upgraded, int downgraded) { + assertThat(artifactChanges.getAddedArtifacts(), hasSize(added)); + assertThat(artifactChanges.getRemovedArtifacts(), hasSize(removed)); + assertThat(artifactChanges.getUpgradedArtifacts().keySet(), hasSize(upgraded)); + assertThat(artifactChanges.getDowngradedArtifacts().keySet(), hasSize(downgraded)); + assertThat(artifactChanges.hasChanges(), equalTo((added + removed + upgraded + downgraded) > 0)); + } + + public void assertNumChanges(UpgradeDifferential.PropertyChanges propertyChanges, int added, int removed, int changed) { + assertThat(propertyChanges.getAddedProperties().keySet(), hasSize(added)); + assertThat(propertyChanges.getRemovedProperties().keySet(), hasSize(removed)); + assertThat(propertyChanges.getChangedProperties().keySet(), hasSize(changed)); + assertThat(propertyChanges.hasChanges(), equalTo((added + removed + changed) > 0)); + } + + public void assertModuleAdded(UpgradeDifferential differential, String moduleId, String version) { + assertThat(differential.getModuleChanges().getAddedArtifacts(), hasItem(new Artifact(moduleId + "-omod", version))); + } + + public void assertModuleRemoved(UpgradeDifferential differential, String moduleId, String version) { + assertThat(differential.getModuleChanges().getRemovedArtifacts(), hasItem(new Artifact(moduleId + "-omod", version))); + } + + public void assertModuleUpgraded(UpgradeDifferential differential, String moduleId, String fromVersion, String toVersion) { + assertThat(differential.getModuleChanges().getUpgradedArtifacts().keySet(), hasItem(new Artifact(moduleId + "-omod", fromVersion))); + assertThat(differential.getModuleChanges().getUpgradedArtifacts().values(), hasItem(new Artifact(moduleId + "-omod", toVersion))); + } + + public void assertModuleDowngraded(UpgradeDifferential differential, String moduleId, String fromVersion, String toVersion) { + assertThat(differential.getModuleChanges().getDowngradedArtifacts().keySet(), hasItem(new Artifact(moduleId + "-omod", fromVersion))); + assertThat(differential.getModuleChanges().getDowngradedArtifacts().values(), hasItem(new Artifact(moduleId + "-omod", toVersion))); + } + + Distribution distribution(Properties properties) { + Distribution distribution = new Distribution(); + distribution.setEffectiveProperties(new DistroProperties(properties)); + return distribution; + } + + Server server(Properties properties) { + return new Server(null, properties); + } + + Properties properties(String...keyValuePairs) { + Properties properties = new Properties(); + for (int i=0; i artifactCaptor = ArgumentCaptor.forClass(Artifact.class); + ArgumentCaptor targetDirectoryCaptor = ArgumentCaptor.forClass(File.class); + ArgumentCaptor includesCaptor = ArgumentCaptor.forClass(String.class); + verify(moduleInstaller, times(1)).installAndUnpackModule(artifactCaptor.capture(), targetDirectoryCaptor.capture(), includesCaptor.capture()); + Artifact artifact = artifactCaptor.getValue(); + assertThat(artifact.getType(), equalTo(BaseSdkProperties.TYPE_ZIP)); + } } diff --git a/pom.xml b/pom.xml index 720acbc0..6915f8d9 100644 --- a/pom.xml +++ b/pom.xml @@ -79,6 +79,7 @@ 3.20.0 2.13.4.2 1.18.26 + 3.8.1 @@ -197,40 +198,39 @@ org.apache.maven maven-core - 3.8.1 + ${maven.version} org.apache.maven maven-model - 3.3.9 + ${maven.version} org.apache.maven maven-plugin-api - 3.3.9 + ${maven.version} org.apache.maven.plugin-tools maven-plugin-annotations - 3.6.1 + ${maven.version} true provided org.codehaus.plexus plexus-utils - - 3.0.24 + 3.5.1 org.codehaus.plexus plexus-component-annotations - 2.1.0 + 2.1.1 org.codehaus.plexus plexus-container-default - 2.1.0 + 2.1.1 com.google.code.google-collections @@ -251,12 +251,12 @@ org.apache.maven.plugins maven-archetype-plugin - 3.2.0 + 3.2.1 org.codehaus.mojo exec-maven-plugin - 1.5.0 + 3.3.0 @@ -301,7 +301,7 @@ org.apache.maven.shared maven-invoker - 2.2 + 3.2.0 org.apache.tomcat diff --git a/sdk-commons/pom.xml b/sdk-commons/pom.xml index 60133553..e52a1e4b 100644 --- a/sdk-commons/pom.xml +++ b/sdk-commons/pom.xml @@ -65,6 +65,12 @@ jackson-databind + + + org.projectlombok + lombok + + junit @@ -86,11 +92,6 @@ mockito-core test - - org.projectlombok - lombok - provided - diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java index 263765cc..9bafe225 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java @@ -3,6 +3,7 @@ import org.apache.commons.lang.StringUtils; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -32,6 +33,7 @@ public abstract class BaseSdkProperties { public static final String TYPE_CONFIG = "config"; public static final String TYPE_ZIP = "zip"; public static final String INCLUDES = "includes"; + public static final List SPA_ARTIFACT_PROPERTIES = Arrays.asList(ARTIFACT_ID, GROUP_ID, VERSION, TYPE, INCLUDES); protected Properties properties; @@ -79,7 +81,7 @@ public String getVersion(){ return getParam("version"); } - public void setVersion(String version){ + public void setVersion(String version) { properties.setProperty("version", version); } @@ -87,11 +89,11 @@ public String getName(){ return getParam("name", "openmrs"); } - public void setName(String name){ + public void setName(String name) { properties.setProperty("name", name); } - public List getModuleArtifacts(){ + public List getModuleArtifacts() { List artifactList = new ArrayList<>(); for (Object keyObject: getAllKeys()) { String key = keyObject.toString(); @@ -126,7 +128,32 @@ public Map getSpaProperties() { return spaProperties; } - public List getWarArtifacts(){ + public Map getSpaArtifactProperties() { + Map properties = getSpaProperties(); + properties.keySet().retainAll(SPA_ARTIFACT_PROPERTIES); + return properties; + } + + public Map getSpaBuildProperties() { + Map properties = getSpaProperties(); + SPA_ARTIFACT_PROPERTIES.forEach(properties.keySet()::remove); + return properties; + } + + public List getSpaArtifacts() { + List ret = new ArrayList<>(); + Map spaProperties = getSpaProperties(); + String artifactId = spaProperties.get(BaseSdkProperties.ARTIFACT_ID); + if (artifactId != null) { + String groupId = spaProperties.get(BaseSdkProperties.GROUP_ID); + String version = spaProperties.get(BaseSdkProperties.VERSION); + String type = spaProperties.get(BaseSdkProperties.TYPE); + ret.add(new Artifact(artifactId, version, groupId, (type == null ? BaseSdkProperties.TYPE_ZIP : type))); + } + return ret; + } + + public List getWarArtifacts() { List artifactList = new ArrayList<>(); for (Object keyObject: getAllKeys()) { String key = keyObject.toString(); @@ -290,7 +317,6 @@ public void setModuleProperties(Artifact newModule) { setCustomModuleType(newModule); } setModule(newModule); - } public void removeModuleProperties(Artifact artifact) { @@ -312,6 +338,24 @@ public void removeModuleProperties(Artifact artifact) { } } + public void removePropertiesForArtifact(String type, Artifact artifact) { + Properties newProperties = new Properties(); + for (Object keyObject : properties.keySet()) { + String key = keyObject.toString(); + if (!key.startsWith(type + "." + artifact.getArtifactId())) { + properties.put(key, properties.get(key)); + } + } + properties = newProperties; + } + + public void addPropertiesForArtifact(String type, Artifact artifact) { + String base = type + "." + artifact.getArtifactId(); + properties.put(base, artifact.getVersion()); + properties.put(base + "." + GROUP_ID, artifact.getGroupId()); + properties.put(base + "." + TYPE, artifact.getType()); + } + /** * Removes `-omod` or `-webapp` suffix from artifact ID. * @@ -353,8 +397,16 @@ public void synchronize(BaseSdkProperties other){ } } - private boolean isBaseSdkProperty(String key) { - return (key.startsWith(TYPE_OMOD) || key.startsWith(TYPE_WAR) || key.equals(NAME) || key.equals(VERSION)); + public boolean isBaseSdkProperty(String key) { + return (key.startsWith(TYPE_WAR) || + key.startsWith(TYPE_OMOD) || + key.startsWith(TYPE_OWA) || + key.startsWith(TYPE_CONFIG) || + key.startsWith(TYPE_CONTENT) || + key.startsWith(TYPE_SPA) || + key.equals(NAME) || + key.equals(VERSION) + ); } diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Server.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Server.java index 80687b98..6510e647 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Server.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Server.java @@ -1,7 +1,5 @@ package org.openmrs.maven.plugins.model; -import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromFile; - import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; @@ -33,6 +31,8 @@ import java.util.Properties; import java.util.Set; +import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromFile; + /** * Class for Server model */ @@ -170,7 +170,7 @@ private Server() { properties = new Properties(); } - private Server(File file, Properties properties) { + public Server(File file, Properties properties) { if (file != null) { this.propertiesFile = new File(file, SDKConstants.OPENMRS_SERVER_PROPERTIES); this.serverDirectory = file; @@ -536,16 +536,6 @@ public List getUserModules() throws MojoExecutionException { return result; } - /** - * Get artifacts of core and all modules on server - */ - public List getServerModules() { - List artifacts = new ArrayList<>(); - artifacts.addAll(getModuleArtifacts()); - artifacts.addAll(getWarArtifacts()); - return artifacts; - } - /** * returns lists of baseArtifacts updated with updateArtifacts(add absent objects and update versions) * @@ -589,9 +579,14 @@ public String getArtifactId(String filename) { } } - public void setValuesFromDistroPropertiesModules(List warArtifacts, List moduleArtifacts, DistroProperties distroProperties) { + public void setValuesFromDistroProperties(DistroProperties distroProperties) { if (distroProperties != null) { - this.properties.putAll(distroProperties.getModuleAndWarProperties(warArtifacts, moduleArtifacts)); + for (Object property : distroProperties.getAllKeys()) { + String key = property.toString(); + if (distroProperties.isBaseSdkProperty(key)) { + this.properties.put(key, distroProperties.getParam(key)); + } + } setName(distroProperties.getName()); setVersion(distroProperties.getVersion()); } @@ -874,6 +869,10 @@ public void deleteServerTmpDirectory() { } } + public File getWarFile() { + return new File(getServerDirectory(), "openmrs-" + getPlatformVersion() + ".war"); + } + public String getWebappVersionFromFilesystem() throws MojoExecutionException { File[] files = serverDirectory.listFiles(new FilenameFilter() { @Override diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/UpgradeDifferential.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/UpgradeDifferential.java index 10dc8d18..fc9208e4 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/UpgradeDifferential.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/UpgradeDifferential.java @@ -1,90 +1,212 @@ package org.openmrs.maven.plugins.model; +import lombok.Data; + import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -/** - * Basic wrapper for list and map of artifacts - */ +@Data public class UpgradeDifferential { - private final List modulesToAdd = new ArrayList<>(); - private final List modulesToDelete = new ArrayList<>(); - private final Map updateOldToNewMap = new HashMap<>(); - private final Map downgradeNewToOldMap = new HashMap<>(); - private Artifact platformArtifact; - private boolean platformUpgraded; - - public boolean isPlatformUpgraded() { - return platformUpgraded; - } - - public void setPlatformUpgraded(boolean platformUpgraded) { - this.platformUpgraded = platformUpgraded; - } - - public boolean isEmpty(){ - return platformArtifact ==null&& updateOldToNewMap.isEmpty()&&modulesToAdd.isEmpty() - &&modulesToDelete.isEmpty()&&downgradeNewToOldMap.isEmpty(); - } - - public Artifact getPlatformArtifact() { - return platformArtifact; - } - - public void setPlatformArtifact(Artifact platformArtifact) { - this.platformArtifact = platformArtifact; - } - - public List getModulesToAdd() { - return modulesToAdd; - } - - public List getModulesToDelete() { - return modulesToDelete; - } - - /** - * IMPORTANT: convention is: key is old version artifact, value is new version artifact - */ - public Map getUpdateOldToNewMap() { - return updateOldToNewMap; - } - - public Map getDowngradeNewToOldMap() { - return downgradeNewToOldMap; - } - - public boolean addModuleToAdd(Artifact artifact) { - return modulesToAdd.add(artifact); - } - - public boolean removeModuleToAdd(Object o) { - return modulesToAdd.remove(o); - } - - public boolean addModuleToDelete(Artifact artifact){ - return modulesToDelete.add(artifact); - } - - public boolean removeModuleToDelete(Object o) { - return modulesToDelete.remove(o); - } - - public Artifact putUpdateEntry(Artifact oldVersionArtifact, Artifact newVersionArtifact) { - return updateOldToNewMap.put(oldVersionArtifact, newVersionArtifact); - } - - public Artifact removeUpdateEntry(Object oldVersionArtifact) { - return updateOldToNewMap.remove(oldVersionArtifact); - } - - public Artifact putDowngradeEntry(Artifact oldVersionArtifact, Artifact newVersionArtifact) { - return downgradeNewToOldMap.put(oldVersionArtifact, newVersionArtifact); - } - public Artifact removeDowngradeEntry(Object oldVersionArtifact) { - return downgradeNewToOldMap.remove(oldVersionArtifact); + private final Server server; + private final Distribution distribution; + private ArtifactChanges warChanges = new ArtifactChanges(null, null); + private ArtifactChanges moduleChanges = new ArtifactChanges(null, null); + private ArtifactChanges owaChanges = new ArtifactChanges(null, null); + private ArtifactChanges spaArtifactChanges = new ArtifactChanges(null, null); + private PropertyChanges spaBuildChanges = new PropertyChanges(null, null); + private ArtifactChanges configChanges = new ArtifactChanges(null, null); + private ArtifactChanges contentChanges = new ArtifactChanges(null, null); + + public UpgradeDifferential(Server server, Distribution distribution) { + this.server = server; + this.distribution = distribution; + } + + @Data + public static class ArtifactChanges { + + private final List oldArtifacts = new ArrayList<>(); + private final List newArtifacts = new ArrayList<>(); + + public ArtifactChanges(List oldArtifacts, List newArtifacts) { + if (oldArtifacts != null) { + this.oldArtifacts.addAll(oldArtifacts); + } + if (newArtifacts != null) { + this.newArtifacts.addAll(newArtifacts); + } + } + + public boolean hasChanges() { + return !getAddedArtifacts().isEmpty() || !getRemovedArtifacts().isEmpty() || !getUpgradedArtifacts().isEmpty() || !getDowngradedArtifacts().isEmpty(); + } + + public List getAddedArtifacts() { + List ret = new ArrayList<>(); + for (Artifact newArtifact : newArtifacts) { + boolean found = false; + for (Artifact oldArtifact : oldArtifacts) { + found = found || (isSameArtifact(oldArtifact, newArtifact)); + } + if (!found) { + ret.add(newArtifact); + } + } + return ret; + } + + public List getRemovedArtifacts() { + List ret = new ArrayList<>(); + for (Artifact oldArtifact : oldArtifacts) { + boolean found = false; + for (Artifact newArtifact : newArtifacts) { + found = found || (isSameArtifact(oldArtifact, newArtifact)); + } + if (!found) { + ret.add(oldArtifact); + } + } + return ret; + } + + public Map getUpgradedArtifacts() { + Map ret = new HashMap<>(); + for (Artifact newArtifact : newArtifacts) { + for (Artifact oldArtifact : oldArtifacts) { + if (isSameArtifact(oldArtifact, newArtifact)) { + if (isHigherVersion(oldArtifact, newArtifact)) { + ret.put(oldArtifact, newArtifact); + } + } + } + } + return ret; + } + + public Map getDowngradedArtifacts() { + Map ret = new HashMap<>(); + for (Artifact newArtifact : newArtifacts) { + for (Artifact oldArtifact : oldArtifacts) { + if (isSameArtifact(oldArtifact, newArtifact)) { + if (isLowerVersion(oldArtifact, newArtifact)) { + ret.put(oldArtifact, newArtifact); + } + } + } + } + return ret; + } + + public List getArtifactsToRemove() { + List ret = getRemovedArtifacts(); + ret.addAll(getUpgradedArtifacts().keySet()); + ret.addAll(getDowngradedArtifacts().keySet()); + return ret; + } + + public List getArtifactsToAdd() { + List ret = getAddedArtifacts(); + ret.addAll(getUpgradedArtifacts().values()); + ret.addAll(getDowngradedArtifacts().values()); + return ret; + } + + public boolean isSameArtifact(Artifact left, Artifact right) { + return getId(left.getDestFileName()).equals(getId(right.getDestFileName())); + } + + public String getId(String name) { + int index = name.indexOf('-'); + if (index == -1) { + return name; + } + return name.substring(0, index); + } + + /** + * checks if next artifact is higher version of the same artifact + * returns true for equal version snapshots + */ + public boolean isHigherVersion(Artifact previous, Artifact next) { + if (artifactsToCompareAreInvalid(previous, next)) { + return false; + } + Version previousVersion = new Version(previous.getVersion()); + Version nextVersion = new Version(next.getVersion()); + return nextVersion.higher(previousVersion) || (previousVersion.isSnapshot() && nextVersion.isSnapshot()); + } + + public boolean isLowerVersion(Artifact previous, Artifact next) { + if (artifactsToCompareAreInvalid(previous, next)) { + return false; + } + Version previousVersion = new Version(previous.getVersion()); + Version nextVersion = new Version(next.getVersion()); + return nextVersion.lower(previousVersion); + } + + public boolean artifactsToCompareAreInvalid(Artifact previous, Artifact next) { + return previous == null || next == null + || previous.getArtifactId() == null || next.getArtifactId() == null + || previous.getVersion() == null || next.getVersion() == null + || !isSameArtifact(previous, next); + } + } + + @Data + public static class PropertyChanges { + + private final Map oldProperties = new LinkedHashMap<>(); + private final Map newProperties = new LinkedHashMap<>(); + + public PropertyChanges(Map oldProperties, Map newProperties) { + if (oldProperties != null) { + this.oldProperties.putAll(oldProperties); + } + if (newProperties != null) { + this.newProperties.putAll(newProperties); + } + } + + public Map getAddedProperties() { + Map ret = new HashMap<>(newProperties); + ret.keySet().removeAll(oldProperties.keySet()); + return ret; + } + + public Map getRemovedProperties() { + Map ret = new HashMap<>(oldProperties); + ret.keySet().removeAll(newProperties.keySet()); + return ret; + } + + public Map getChangedProperties() { + Map ret = new HashMap<>(); + for (String key : oldProperties.keySet()) { + String newValue = newProperties.get(key); + if (newValue != null) { + if (!newValue.equals((oldProperties.get(key))) || isUnresolvedVersion(newValue)) { + ret.put(key, newProperties.get(key)); + } + } + } + return ret; + } + + public boolean isUnresolvedVersion(String version) { + if (version == null) { + return false; + } + version = version.toLowerCase(); + return version.equals("next") || version.endsWith("-snapshot"); + } + + public boolean hasChanges() { + return !getAddedProperties().isEmpty() || !getRemovedProperties().isEmpty() || !getChangedProperties().isEmpty(); + } } } diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DefaultWizard.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DefaultWizard.java index ba48c1fb..6b8bbd95 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DefaultWizard.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DefaultWizard.java @@ -15,7 +15,7 @@ import org.jline.terminal.Terminal; import org.jline.terminal.TerminalBuilder; import org.openmrs.maven.plugins.model.Artifact; -import org.openmrs.maven.plugins.model.DistroProperties; +import org.openmrs.maven.plugins.model.Distribution; import org.openmrs.maven.plugins.model.Server; import org.openmrs.maven.plugins.model.UpgradeDifferential; import org.openmrs.maven.plugins.model.Version; @@ -58,55 +58,55 @@ @Component(role = Wizard.class) public class DefaultWizard implements Wizard { - private static final String EMPTY_STRING = ""; + static final String EMPTY_STRING = ""; - private static final String NONE = "(none)"; + static final String NONE = "(none)"; - private static final String DEFAULT_CHOICE_TMPL = "Which one do you choose?"; + static final String DEFAULT_CHOICE_TMPL = "Which one do you choose?"; - private static final String DEFAULT_OPTION_TMPL = "%d) %s"; + static final String DEFAULT_OPTION_TMPL = "%d) %s"; - private static final String DEFAULT_CUSTOM_OPTION_TMPL = "%d) Other..."; + static final String DEFAULT_CUSTOM_OPTION_TMPL = "%d) Other..."; - private static final String DEFAULT_SERVER_NAME = "server"; + static final String DEFAULT_SERVER_NAME = "server"; - private static final String DEFAULT_PROMPT_TMPL = "Please specify %s"; + static final String DEFAULT_PROMPT_TMPL = "Please specify %s"; - private static final String DEFAULT_VALUE_TMPL = " (default: '%s')"; + static final String DEFAULT_VALUE_TMPL = " (default: '%s')"; - private static final String DEFAULT_VALUE_TMPL_WITH_DEFAULT = "Please specify %s: (default: '%s')"; + static final String DEFAULT_VALUE_TMPL_WITH_DEFAULT = "Please specify %s: (default: '%s')"; - private static final String INVALID_SERVER = "Invalid server Id"; + static final String INVALID_SERVER = "Invalid server Id"; - private static final String YESNO = " [Y/n]"; + static final String YESNO = " [Y/n]"; - private static final String NOYES = " [N/y]"; + static final String NOYES = " [N/y]"; - private static final String REFERENCEAPPLICATION_2_4 = "org.openmrs.distro:referenceapplication-package:2.4"; + static final String REFERENCEAPPLICATION_2_4 = "org.openmrs.distro:referenceapplication-package:2.4"; - private static final String REFERENCEAPPLICATION_O3 = "org.openmrs:emr-distro-configuration:3.0.0"; + static final String REFERENCEAPPLICATION_O3 = "org.openmrs:emr-distro-configuration:3.0.0"; - private static final String SDK_PROPERTIES_FILE = "SDK Properties file"; + static final String SDK_PROPERTIES_FILE = "SDK Properties file"; - private static final String REFAPP_OPTION_TMPL = "Reference Application %s"; + static final String REFAPP_OPTION_TMPL = "Reference Application %s"; - private static final String REFAPP_ARTIFACT_TMPL = "org.openmrs.distro:referenceapplication-package:%s"; + static final String REFAPP_ARTIFACT_TMPL = "org.openmrs.distro:referenceapplication-package:%s"; - private static final String JDK_ERROR_TMPL = "\nThe JDK %s is not compatible with OpenMRS Platform %s. " + + static final String JDK_ERROR_TMPL = "\nThe JDK %s is not compatible with OpenMRS Platform %s. " + "Please use %s to run this server.\n\nIf you are running " + "in a forked mode, correct the java.home property in %s\n"; - private static final String UPGRADE_CONFIRM_TMPL = "\nThe %s %s introduces the following changes:"; + static final String UPGRADE_CONFIRM_TMPL = "\nThe %s %s introduces the following changes:"; - private static final String UPDATE_MODULE_TMPL = "^ Updates %s %s to %s"; + static final String UPDATE_ARTIFACT_TMPL = "^ Updates %s %s to %s"; - private static final String DOWNGRADE_MODULE_TMPL = "v Downgrades %s %s to %s"; + static final String DOWNGRADE_ARTIFACT_TMPL = "v Downgrades %s %s to %s"; - private static final String ADD_MODULE_TMPL = "+ Adds %s %s"; + static final String ADD_ARTIFACT_TMPL = "+ Adds %s %s"; - private static final String DELETE_MODULE_TMPL = "- Deletes %s %s"; + static final String DELETE_ARTIFACT_TMPL = "- Deletes %s %s"; - private static final String NO_DIFFERENTIAL = "\nNo modules to update or add found"; + static final String NO_DIFFERENTIAL = "\nNo distribution changes found"; public static final String PLATFORM_VERSION_PROMPT = "You can deploy the following versions of a platform"; @@ -1151,71 +1151,107 @@ public void showJdkErrorMessage(String jdk, String platform, String recommendedJ * @return */ @Override - public boolean promptForConfirmDistroUpgrade(UpgradeDifferential upgradeDifferential, Server server, - DistroProperties distroProperties) throws MojoExecutionException { - if (upgradeDifferential.isEmpty()) { + public boolean promptForConfirmDistroUpgrade(UpgradeDifferential upgradeDifferential) throws MojoExecutionException { + + Server server = upgradeDifferential.getServer(); + Distribution distribution = upgradeDifferential.getDistribution(); + + UpgradeDifferential.ArtifactChanges warChanges = upgradeDifferential.getWarChanges(); + UpgradeDifferential.ArtifactChanges moduleChanges = upgradeDifferential.getModuleChanges(); + UpgradeDifferential.ArtifactChanges owaChanges = upgradeDifferential.getOwaChanges(); + UpgradeDifferential.ArtifactChanges spaArtifactChanges = upgradeDifferential.getSpaArtifactChanges(); + UpgradeDifferential.PropertyChanges spaBuildChanges = upgradeDifferential.getSpaBuildChanges(); + UpgradeDifferential.ArtifactChanges configChanges = upgradeDifferential.getConfigChanges(); + UpgradeDifferential.ArtifactChanges contentChanges = upgradeDifferential.getContentChanges(); + + boolean hasChanges = ( + warChanges.hasChanges() || + moduleChanges.hasChanges() || + owaChanges.hasChanges() || + spaArtifactChanges.hasChanges() || + spaBuildChanges.hasChanges() || + configChanges.hasChanges() || + contentChanges.hasChanges() + ); + + if (!hasChanges) { showMessage(NO_DIFFERENTIAL); return false; } - boolean needConfirmation = false; + writer.printf((UPGRADE_CONFIRM_TMPL) + "%n", distribution.getName(), distribution.getVersion()); - if (upgradeDifferential.getPlatformArtifact() != null) { - needConfirmation = showUpdateHeader(distroProperties, needConfirmation); + if (warChanges.hasChanges()) { writer.printf( - (upgradeDifferential.isPlatformUpgraded() ? UPDATE_MODULE_TMPL : DOWNGRADE_MODULE_TMPL) + "%n", - upgradeDifferential.getPlatformArtifact().getArtifactId(), - server.getPlatformVersion(), - upgradeDifferential.getPlatformArtifact().getVersion()); - } - for (Entry updateEntry : upgradeDifferential.getUpdateOldToNewMap().entrySet()) { - //update map should contain entry with equal versions only when they are same snapshots - //(e.g. update 'appui 0.2-SNAPSHOT' to 'appui 0.2-SNAPSHOT') - //updating to same SNAPSHOT doesn't require confirmation, they are not shown - if (!updateEntry.getKey().getVersion().equals(updateEntry.getValue().getVersion())) { - needConfirmation = showUpdateHeader(distroProperties, needConfirmation); - writer.printf((UPDATE_MODULE_TMPL) + "%n", - updateEntry.getKey().getArtifactId(), - updateEntry.getKey().getVersion(), - updateEntry.getValue().getVersion()); - } + (warChanges.getDowngradedArtifacts().isEmpty() ? UPDATE_ARTIFACT_TMPL : DOWNGRADE_ARTIFACT_TMPL) + "%n", + warChanges.getNewArtifacts().get(0).getArtifactId(), + upgradeDifferential.getServer().getPlatformVersion(), + warChanges.getNewArtifacts().get(0).getVersion()); } - for (Entry downgradeEntry : upgradeDifferential.getDowngradeNewToOldMap().entrySet()) { - if (!downgradeEntry.getKey().getVersion().equals(downgradeEntry.getValue().getVersion())) { - needConfirmation = showUpdateHeader(distroProperties, needConfirmation); - writer.printf((DOWNGRADE_MODULE_TMPL) + "%n", - downgradeEntry.getKey().getArtifactId(), - downgradeEntry.getKey().getVersion(), - downgradeEntry.getValue().getVersion()); + promptForArtifactChangesIfNecessary(moduleChanges); + promptForArtifactChangesIfNecessary(owaChanges); + + if (spaArtifactChanges.hasChanges() || spaBuildChanges.hasChanges()) { + if (hasExistingFilesInDirectory(server, SDKConstants.OPENMRS_SERVER_FRONTEND)) { + writer.print("^ Updates frontend spa%n"); + } + else { + writer.print("+ Adds frontend spa%n"); } } - for (Artifact addArtifact : upgradeDifferential.getModulesToAdd()) { - needConfirmation = showUpdateHeader(distroProperties, needConfirmation); - writer.printf((ADD_MODULE_TMPL) + "%n", - addArtifact.getArtifactId(), - addArtifact.getVersion()); + if (configChanges.hasChanges() || contentChanges.hasChanges()) { + if (hasExistingFilesInDirectory(server, SDKConstants.OPENMRS_SERVER_CONFIGURATION)) { + writer.print("^ Updates frontend configuration%n"); + } + else { + writer.print("+ Adds frontend configuration%n"); + } } - for (Artifact deleteArtifact : upgradeDifferential.getModulesToDelete()) { - needConfirmation = showUpdateHeader(distroProperties, needConfirmation); - writer.printf((DELETE_MODULE_TMPL) + "%n", - deleteArtifact.getArtifactId(), - deleteArtifact.getVersion()); - } + return promptYesNo(String.format("Would you like to apply those changes to '%s'?", upgradeDifferential.getServer().getServerId())); + } - if (needConfirmation) { - return promptYesNo(String.format("Would you like to apply those changes to '%s'?", server.getServerId())); - } else - return true; + protected boolean hasExistingFilesInDirectory(Server server, String directory) { + File frontendDir = new File(server.getServerDirectory(), directory); + if (frontendDir.exists()) { + File[] files = frontendDir.listFiles(); + return files != null && files.length > 0; + } + return false; } - private boolean showUpdateHeader(DistroProperties distroProperties, boolean needConfirmation) { - if (!needConfirmation) { - writer.printf((UPGRADE_CONFIRM_TMPL) + "%n", distroProperties.getName(), distroProperties.getVersion()); + protected void promptForArtifactChangesIfNecessary(UpgradeDifferential.ArtifactChanges artifactChanges) { + if (artifactChanges.hasChanges()) { + for (Entry updateEntry : artifactChanges.getUpgradedArtifacts().entrySet()) { + if (!updateEntry.getKey().getVersion().equals(updateEntry.getValue().getVersion())) { + writer.printf((UPDATE_ARTIFACT_TMPL) + "%n", + updateEntry.getKey().getArtifactId(), + updateEntry.getKey().getVersion(), + updateEntry.getValue().getVersion()); + } + } + for (Entry downgradeEntry : artifactChanges.getDowngradedArtifacts().entrySet()) { + if (!downgradeEntry.getKey().getVersion().equals(downgradeEntry.getValue().getVersion())) { + writer.printf((DOWNGRADE_ARTIFACT_TMPL) + "%n", + downgradeEntry.getKey().getArtifactId(), + downgradeEntry.getKey().getVersion(), + downgradeEntry.getValue().getVersion()); + } + } + for (Artifact addArtifact : artifactChanges.getAddedArtifacts()) { + writer.printf((ADD_ARTIFACT_TMPL) + "%n", + addArtifact.getArtifactId(), + addArtifact.getVersion()); + } + + for (Artifact deleteArtifact : artifactChanges.getRemovedArtifacts()) { + writer.printf((DELETE_ARTIFACT_TMPL) + "%n", + deleteArtifact.getArtifactId(), + deleteArtifact.getVersion()); + } } - return true; } @Override diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DistroHelper.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DistroHelper.java index 2cb5fa11..d90234bb 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DistroHelper.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DistroHelper.java @@ -10,7 +10,6 @@ import org.openmrs.maven.plugins.model.DistroProperties; import org.openmrs.maven.plugins.model.PackageJson; import org.openmrs.maven.plugins.model.Server; -import org.openmrs.maven.plugins.model.UpgradeDifferential; import org.openmrs.maven.plugins.model.Version; import org.semver4j.Semver; import org.semver4j.SemverException; @@ -68,10 +67,10 @@ public DistroHelper(MavenEnvironment mavenEnvironment) { /** * @return distro properties from openmrs-distro.properties file in current directory or null if not exist */ - public DistroProperties getDistroPropertiesFromDir() { + public File getDistroPropertiesFileFromDir() { File distroFile = new File(new File(System.getProperty("user.dir")), "openmrs-distro.properties"); if (distroFile.exists()) { - return getDistroPropertiesFromFile(distroFile); + return distroFile; } return null; } @@ -89,26 +88,6 @@ public DistroProperties createDistroForPlatform(Server server) { return distroProperties; } - /** - * @param distroFile file which contains distro properties - * @return distro properties loaded from specified file or null if file is not distro properties - */ - public DistroProperties getDistroPropertiesFromFile(File distroFile) { - if (distroFile.exists()) { - try { - DistributionBuilder builder = new DistributionBuilder(mavenEnvironment); - Distribution distribution = builder.buildFromFile(distroFile); - if (distribution != null) { - return distribution.getEffectiveProperties(); - } - } - catch (MojoExecutionException ignored) { - } - } - - return null; - } - /** * Saves all custom properties from distroProperties starting with "property." to server * @@ -353,129 +332,6 @@ public void saveDistroPropertiesTo(File destination, String distro) throws MojoE } } - /** - * should: - * - ignore modules which are already on server, but not included in distro properties of upgrade - * - keep new platform artifact if distro properties declares newer version - * - updateMap include modules which are already on server with newer/equal SNAPSHOT version - * - add modules which are not installed on server yet - */ - public static UpgradeDifferential calculateUpdateDifferential(Server server, DistroProperties distroProperties) throws MojoExecutionException { - List newList = new ArrayList<>(distroProperties.getWarArtifacts()); - newList.addAll(distroProperties.getModuleArtifacts()); - return calculateUpdateDifferential(server.getServerModules(), newList); - } - - static UpgradeDifferential calculateUpdateDifferential(List oldList, List newList) - throws MojoExecutionException { - UpgradeDifferential upgradeDifferential = new UpgradeDifferential(); - for (Artifact newListModule : newList) { - boolean toAdd = true; - for (Artifact oldListModule : oldList) { - if (isSameArtifact(oldListModule, newListModule)) { - if (isHigherVersion(oldListModule, newListModule)) { - if (isOpenmrsWebapp(newListModule)) { - upgradeDifferential.setPlatformArtifact(newListModule); - upgradeDifferential.setPlatformUpgraded(true); - } else { - upgradeDifferential.putUpdateEntry(oldListModule, newListModule); - } - } else if (isLowerVersion(oldListModule, newListModule)) { - if (isOpenmrsWebapp(newListModule)) { - upgradeDifferential.setPlatformArtifact(newListModule); - upgradeDifferential.setPlatformUpgraded(false); - } else { - upgradeDifferential.putDowngradeEntry(oldListModule, newListModule); - } - } - toAdd = false; - break; - } - } - if (toAdd) { - upgradeDifferential.addModuleToAdd(newListModule); - } - } - for (Artifact oldListModule : oldList) { - boolean moduleNotFound = true; - for (Artifact newListModule : newList) { - if (isSameArtifact(newListModule, oldListModule)) { - moduleNotFound = false; - break; - } - } - if (moduleNotFound) { - if (isOpenmrsWebapp(oldListModule)) { - throw new MojoExecutionException("You can delete only modules. Deleting openmrs core is not possible"); - } else { - upgradeDifferential.addModuleToDelete(oldListModule); - } - } - } - return upgradeDifferential; - } - - private static boolean isOpenmrsWebapp(Artifact artifact) { - return Artifact.TYPE_WAR.equals(artifact.getType()) && SDKConstants.WEBAPP_ARTIFACT_ID - .equals(artifact.getArtifactId()); - } - - private static boolean isSameArtifact(Artifact left, Artifact right) { - return getId(left.getDestFileName()).equals(getId(right.getDestFileName())); - } - - private static String getId(String name) { - int index = name.indexOf('-'); - if (index == -1) - return name; - return name.substring(0, index); - } - - /** - * checks if next artifact is higher version of the same artifact - * returns true for equal version snapshots - */ - private static boolean isHigherVersion(Artifact previous, Artifact next) { - if (artifactsToCompareAreInvalid(previous, next)) { - return false; - } - - Version previousVersion = new Version(previous.getVersion()); - Version nextVersion = new Version(next.getVersion()); - - if (nextVersion.higher(previousVersion)) { - return true; - } else if (nextVersion.equal(previousVersion)) { - return (previousVersion.isSnapshot() && nextVersion.isSnapshot()); - } else { - return false; - } - } - - private static boolean isLowerVersion(Artifact previous, Artifact next) { - if (artifactsToCompareAreInvalid(previous, next)) { - return false; - } - - Version previousVersion = new Version(previous.getVersion()); - Version nextVersion = new Version(next.getVersion()); - - if (nextVersion.lower(previousVersion)) { - return true; - } else if (nextVersion.equal(previousVersion)) { - return (previousVersion.isSnapshot() && nextVersion.isSnapshot()); - } else { - return false; - } - } - - private static boolean artifactsToCompareAreInvalid(Artifact previous, Artifact next) { - return previous == null || next == null - || previous.getArtifactId() == null || next.getArtifactId() == null - || previous.getVersion() == null || next.getVersion() == null - || !isSameArtifact(previous, next); - } - /** * Parses and processes content properties from content packages defined in the given {@code DistroProperties} object. * diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/SDKConstants.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/SDKConstants.java index c35f7954..07497f6c 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/SDKConstants.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/SDKConstants.java @@ -53,7 +53,10 @@ public class SDKConstants { public static final String OPENMRS_SDK_JDK_CUSTOM_INVALID = "JDK path is invalid"; public static final String OPENMRS_SDK_PROPERTIES = "sdk.properties"; public static final String OPENMRS_SERVER_MODULES = "modules"; + public static final String OPENMRS_SERVER_OWA = "owa"; public static final String OPENMRS_SERVER_CONFIGURATION = "configuration"; + public static final String OPENMRS_SERVER_FRONTEND = "frontend"; + // properties names public static final String OPENMRS_SDK_PROPERTIES_JAVA_HOME_OPTIONS = "javaHomeOptions"; // dbUri for different db diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/Wizard.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/Wizard.java index 0c19230c..ad1934bf 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/Wizard.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/Wizard.java @@ -72,8 +72,7 @@ String promptForValueIfMissingWithDefault(String message, String value, String p void showJdkErrorMessage(String jdk, String platform, String recommendedJdk, String pathToProps); - boolean promptForConfirmDistroUpgrade(UpgradeDifferential upgradeDifferential, Server server, DistroProperties distroProperties) - throws MojoExecutionException; + boolean promptForConfirmDistroUpgrade(UpgradeDifferential upgradeDifferential) throws MojoExecutionException; void setAnswers(ArrayDeque batchAnswers); } diff --git a/sdk-commons/src/test/java/org/openmrs/maven/plugins/model/UpgradeDifferentialTest.java b/sdk-commons/src/test/java/org/openmrs/maven/plugins/model/UpgradeDifferentialTest.java new file mode 100644 index 00000000..86a2474c --- /dev/null +++ b/sdk-commons/src/test/java/org/openmrs/maven/plugins/model/UpgradeDifferentialTest.java @@ -0,0 +1,194 @@ +package org.openmrs.maven.plugins.model; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.openmrs.maven.plugins.model.UpgradeDifferential.ArtifactChanges; +import static org.openmrs.maven.plugins.model.UpgradeDifferential.PropertyChanges; + +public class UpgradeDifferentialTest { + + ArtifactChanges artifactChanges; + PropertyChanges propertyChanges; + + @Test + public void artifactChanges_shouldSupportNullLists() { + assertArtifactChanges(new ArtifactChanges(null, null), 0, 0, 0, 0, false); + assertArtifactChanges(new ArtifactChanges(null, new ArrayList<>()), 0, 0, 0, 0, false); + assertArtifactChanges(new ArtifactChanges(new ArrayList<>(), null), 0, 0, 0, 0, false); + } + + @Test + public void artifactChanges_shouldIdentifyNoChanges() { + Artifact startingModule = new Artifact("moduleId", "1.2.3", "org.openmrs.module"); + Artifact newModule = new Artifact("moduleId", "1.2.3", "org.openmrs.module"); + artifactChanges = new ArtifactChanges(Collections.singletonList(startingModule), Collections.singletonList(newModule)); + assertArtifactChanges(artifactChanges, 0, 0, 0, 0, false); + } + + @Test + public void artifactChanges_shouldIdentifyAdditions() { + Artifact newModule = new Artifact("moduleId", "1.2.4", "org.openmrs.module"); + artifactChanges = new ArtifactChanges(Collections.emptyList(), Collections.singletonList(newModule)); + assertArtifactChanges(artifactChanges, 1, 0, 0, 0, true); + } + + @Test + public void artifactChanges_shouldIdentifyRemovals() { + Artifact startingModule = new Artifact("moduleId", "1.2.3", "org.openmrs.module"); + artifactChanges = new ArtifactChanges(Collections.singletonList(startingModule), Collections.emptyList()); + assertArtifactChanges(artifactChanges, 0, 1, 0, 0, true); + } + + @Test + public void artifactChanges_shouldIdentifyUpgrades() { + Artifact startingModule = new Artifact("moduleId", "1.2.3", "org.openmrs.module"); + Artifact newModule = new Artifact("moduleId", "1.2.4", "org.openmrs.module"); + artifactChanges = new ArtifactChanges(Collections.singletonList(startingModule), Collections.singletonList(newModule)); + assertArtifactChanges(artifactChanges, 0, 0, 1, 0, true); + } + + @Test + public void artifactChanges_shouldIdentifyDowngrades() { + Artifact startingModule = new Artifact("moduleId", "1.2.4", "org.openmrs.module"); + Artifact newModule = new Artifact("moduleId", "1.2.3", "org.openmrs.module"); + artifactChanges = new ArtifactChanges(Collections.singletonList(startingModule), Collections.singletonList(newModule)); + assertArtifactChanges(artifactChanges, 0, 0, 0, 1, true); + } + + @Test + public void artifactChanges_shouldIdentifySameArtifact() { + artifactChanges = new ArtifactChanges(null, null); + Artifact startingModule = new Artifact("moduleId", "1.2.4", "org.openmrs.module"); + Artifact newModule = new Artifact("moduleId", "1.2.4", "org.openmrs.module"); + assertTrue(artifactChanges.isSameArtifact(startingModule, newModule)); + newModule = new Artifact("moduleId", "1.2.5", "org.openmrs.module"); + assertTrue(artifactChanges.isSameArtifact(startingModule, newModule)); + newModule = new Artifact("moduleId2", "1.2.4", "org.openmrs.module"); + assertFalse(artifactChanges.isSameArtifact(startingModule, newModule)); + } + + @Test + public void artifactChanges_shouldIdentifyHigherVersion() { + artifactChanges = new ArtifactChanges(null, null); + Artifact startingModule = new Artifact("moduleId", "1.2.4", "org.openmrs.module"); + Artifact newModule = new Artifact("moduleId", "1.2.4", "org.openmrs.module"); + assertFalse(artifactChanges.isHigherVersion(startingModule, newModule)); + newModule = new Artifact("moduleId", "1.2.3", "org.openmrs.module"); + assertFalse(artifactChanges.isHigherVersion(startingModule, newModule)); + newModule = new Artifact("moduleId", "1.2.5", "org.openmrs.module"); + assertTrue(artifactChanges.isHigherVersion(startingModule, newModule)); + startingModule = new Artifact("moduleId", "1.2.4-SNAPSHOT", "org.openmrs.module"); + newModule = new Artifact("moduleId", "1.2.4-SNAPSHOT", "org.openmrs.module"); + assertTrue(artifactChanges.isHigherVersion(startingModule, newModule)); + } + + @Test + public void artifactChanges_shouldIdentifyLowerVersion() { + artifactChanges = new ArtifactChanges(null, null); + Artifact startingModule = new Artifact("moduleId", "1.2.4", "org.openmrs.module"); + Artifact newModule = new Artifact("moduleId", "1.2.4", "org.openmrs.module"); + assertFalse(artifactChanges.isLowerVersion(startingModule, newModule)); + newModule = new Artifact("moduleId", "1.2.5", "org.openmrs.module"); + assertFalse(artifactChanges.isLowerVersion(startingModule, newModule)); + newModule = new Artifact("moduleId", "1.2.3", "org.openmrs.module"); + assertTrue(artifactChanges.isLowerVersion(startingModule, newModule)); + startingModule = new Artifact("moduleId", "1.2.4-SNAPSHOT", "org.openmrs.module"); + newModule = new Artifact("moduleId", "1.2.4-SNAPSHOT", "org.openmrs.module"); + assertFalse(artifactChanges.isLowerVersion(startingModule, newModule)); + } + + @Test + public void propertyChanges_shouldSupportNullLists() { + propertyChanges = new PropertyChanges(null, null); + assertTrue(propertyChanges.getAddedProperties().isEmpty()); + assertTrue(propertyChanges.getRemovedProperties().isEmpty()); + assertTrue(propertyChanges.getChangedProperties().isEmpty()); + assertFalse(propertyChanges.hasChanges()); + } + + @Test + public void propertyChanges_shouldIdentifyNoChanges() { + Map starting = map("prop1", "val1", "prop2", "val2"); + Map ending = map("prop1", "val1", "prop2", "val2"); + propertyChanges = new PropertyChanges(starting, ending); + assertTrue(propertyChanges.getAddedProperties().isEmpty()); + assertTrue(propertyChanges.getRemovedProperties().isEmpty()); + assertTrue(propertyChanges.getChangedProperties().isEmpty()); + assertFalse(propertyChanges.hasChanges()); + } + + @Test + public void propertyChanges_shouldIdentifyAdditions() { + Map starting = map("prop1", "val1"); + Map ending = map("prop1", "val1", "prop2", "val2"); + propertyChanges = new PropertyChanges(starting, ending); + assertThat(propertyChanges.getAddedProperties().size(), equalTo(1)); + assertThat(propertyChanges.getAddedProperties().get("prop2"), equalTo("val2")); + assertTrue(propertyChanges.getRemovedProperties().isEmpty()); + assertTrue(propertyChanges.getChangedProperties().isEmpty()); + assertTrue(propertyChanges.hasChanges()); + } + + @Test + public void propertyChanges_shouldIdentifyRemovals() { + Map starting = map("prop1", "val1", "prop2", "val2"); + Map ending = map("prop1", "val1"); + propertyChanges = new PropertyChanges(starting, ending); + assertTrue(propertyChanges.getAddedProperties().isEmpty()); + assertThat(propertyChanges.getRemovedProperties().size(), equalTo(1)); + assertThat(propertyChanges.getRemovedProperties().get("prop2"), equalTo("val2")); + assertTrue(propertyChanges.getChangedProperties().isEmpty()); + assertTrue(propertyChanges.hasChanges()); + } + + @Test + public void propertyChanges_shouldIdentifyChanges() { + Map starting = map("prop1", "val1", "prop2", "val2"); + Map ending = map("prop1", "val1", "prop2", "val3"); + propertyChanges = new PropertyChanges(starting, ending); + assertTrue(propertyChanges.getAddedProperties().isEmpty()); + assertTrue(propertyChanges.getRemovedProperties().isEmpty()); + assertThat(propertyChanges.getChangedProperties().size(), equalTo(1)); + assertThat(propertyChanges.getChangedProperties().get("prop2"), equalTo("val3")); + assertTrue(propertyChanges.hasChanges()); + } + + @Test + public void propertyChanges_shouldIdentifySnapshotChanges() { + Map starting = map("prop1", "next"); + Map ending = map("prop1", "next"); + propertyChanges = new PropertyChanges(starting, ending); + assertTrue(propertyChanges.getAddedProperties().isEmpty()); + assertTrue(propertyChanges.getRemovedProperties().isEmpty()); + assertThat(propertyChanges.getChangedProperties().size(), equalTo(1)); + assertThat(propertyChanges.getChangedProperties().get("prop1"), equalTo("next")); + assertTrue(propertyChanges.hasChanges()); + } + + void assertArtifactChanges(UpgradeDifferential.ArtifactChanges artifactChanges, int added, int removed, int upgraded, int downgraded, boolean hasChanges) { + assertThat(artifactChanges.getAddedArtifacts().size(), equalTo(added)); + assertThat(artifactChanges.getRemovedArtifacts().size(), equalTo(removed)); + assertThat(artifactChanges.getUpgradedArtifacts().size(), equalTo(upgraded)); + assertThat(artifactChanges.getDowngradedArtifacts().size(), equalTo(downgraded)); + assertThat(artifactChanges.getArtifactsToAdd().size(), equalTo(added + upgraded + downgraded)); + assertThat(artifactChanges.getArtifactsToRemove().size(), equalTo(removed + upgraded + downgraded)); + assertThat(artifactChanges.hasChanges(), equalTo(hasChanges)); + } + + Map map(String... keysAndValues) { + Map properties = new HashMap<>(); + for (int i=0; i getMockOldestArtifactList(){ - List oldList = new ArrayList<>(Arrays.asList( - new Artifact("webservices", "0.7"), - new Artifact("webapp", "1.7"), - new Artifact("openmrs-webapp", "10.7", Artifact.GROUP_WEB, Artifact.TYPE_WAR) - )); - - return oldList; - } - - private List getMockOldArtifactList(){ - List oldList = new ArrayList<>(Arrays.asList( - new Artifact("webservices", "1.0"), - new Artifact("webapp", "1.12"), - new Artifact("owa", "1.5"), - new Artifact("legacyui", "1.5"), - new Artifact("appui", "0.1-SNAPSHOT"), - new Artifact("openmrs-webapp", "10.7", Artifact.GROUP_WEB, Artifact.TYPE_WAR) - )); - - return oldList; - } - - private List getMockNewArtifactList(){ - List oldList = new ArrayList<>(Arrays.asList( - new Artifact("webservices", "1.2"), - new Artifact("webapp", "1.12"), - new Artifact("appui", "0.1-SNAPSHOT"), - new Artifact("legacyui", "1.4"), - new Artifact("drugs", "0.2-SNAPSHOT"), - new Artifact("openmrs-webapp", "12.0", Artifact.GROUP_WEB, Artifact.TYPE_WAR) - )); - return oldList; - } }