From 47dc69e02b1d9952b30abacbbcf52c37b4b9d896 Mon Sep 17 00:00:00 2001 From: AdamGrzybkowski Date: Fri, 23 Dec 2016 14:21:07 +0100 Subject: [PATCH] AC-182 Deploy shows incorrect platform versions --- .../maven/plugins/DeployIntegrationTest.java | 15 +++++++ .../maven/plugins/SetupIntegrationTest.java | 27 +++++++++++ .../org/openmrs/maven/plugins/Deploy.java | 45 +++++++++++++++++-- .../plugins/model/BaseSdkProperties.java | 11 +++++ 4 files changed, 94 insertions(+), 4 deletions(-) diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/DeployIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/DeployIntegrationTest.java index 65174fc0..a5662786 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/DeployIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/DeployIntegrationTest.java @@ -43,6 +43,21 @@ public void deploy_shouldReplaceWebapp() throws Exception { assertSuccess(); assertFilePresent(testServerId + File.separator + "openmrs-1.11.5.war"); assertPlatformUpdated(testServerId, "1.11.5"); + assertFileNotPresent(testServerId + File.separator + "modules" + File.separator + "webservices.rest-2.14.omod"); + } + + @Test + public void deploy_shouldReplaceDistroPlatform() throws Exception{ + addTaskParam("platform", "2.0.2"); + + addAnswer(testServerId); + addAnswer("y"); + + executeTask("deploy"); + + assertSuccess(); + assertFilePresent(testServerId + File.separator + "openmrs-2.0.2.war"); + assertModulesInstalled(testServerId, "webservices.rest-2.16.omod"); } @Test diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/SetupIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/SetupIntegrationTest.java index 99a1ce32..933b4449 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/SetupIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/SetupIntegrationTest.java @@ -13,6 +13,7 @@ import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; +import static org.openmrs.maven.plugins.SdkMatchers.hasModuleVersion; import static org.openmrs.maven.plugins.SdkMatchers.hasPropertyEqualTo; import static org.openmrs.maven.plugins.SdkMatchers.serverHasName; import static org.openmrs.maven.plugins.SdkMatchers.serverHasDebugPort; @@ -74,6 +75,32 @@ public void setup_shouldInstallPlatform1_11_5() throws Exception{ assertThat(server, serverHasDebugPort("1044")); } + @Test + public void setup_shouldInstallDistroPlatform2_0_2() throws Exception{ + String serverId = UUID.randomUUID().toString(); + + addTaskParam("platform", "2.0.2"); + addMockDbSettings(); + + addAnswer(serverId); + addAnswer("1044"); + addAnswer(System.getProperty("java.home")); + + executeTask("setup"); + + assertSuccess(); + assertServerInstalled(serverId); + assertFilePresent(serverId + File.separator + "openmrs-2.0.2.war"); + assertFilePresent(serverId + File.separator + "modules"); + + Server.setServersPath(testDirectory.getAbsolutePath()); + Server server = Server.loadServer(serverId); + assertThat(server, serverHasVersion("2.0.2")); + assertFilePresent(serverId + File.separator + "openmrs-distro.properties"); + assertThat(server, serverHasDebugPort("1044")); + assertThat(server, hasModuleVersion("webservices.rest", "2.16")); + } + @Test public void setup_shouldInstallServerFromGivenDistroProperties() throws Exception{ String serverId = UUID.randomUUID().toString(); 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 a9eac473..31a78da3 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 @@ -107,7 +107,7 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { Artifact artifact = checkCurrentDirectoryForOpenmrsWebappUpdate(server); DistroProperties distroProperties = checkCurrentDirectoryForDistroProperties(server); if(artifact != null){ - deployOpenmrsWar(server, artifact); + deployOpenmrsFromDir(server, artifact); } else if(distroProperties!=null){ serverUpgrader.upgradeToDistro(server, distroProperties); } else if(checkCurrentDirForModuleProject()) { @@ -119,7 +119,7 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { DistroProperties distroProperties = distroHelper.retrieveDistroProperties(distro); serverUpgrader.upgradeToDistro(server, distroProperties); } else if(platform != null) { - serverUpgrader.upgradePlatform(server, platform); + deployOpenmrs(server, platform); } else if(owa != null){ BintrayId id = OpenmrsBintray.parseOwa(owa); deployOwa(server, id.getName(), id.getVersion()); @@ -159,9 +159,9 @@ private void runInteractiveMode(Server server, ServerUpgrader upgrader) throws M TEMPLATE_CURRENT_VERSION, "platform", server.getPlatformVersion())); - Artifact webapp = new Artifact(SDKConstants.WEBAPP_ARTIFACT_ID, SDKConstants.SETUP_DEFAULT_PLATFORM_VERSION, Artifact.GROUP_WEB); + Artifact webapp = new Artifact(SDKConstants.PLATFORM_ARTIFACT_ID, SDKConstants.SETUP_DEFAULT_PLATFORM_VERSION, Artifact.GROUP_DISTRO); platform = wizard.promptForPlatformVersion(versionsHelper.getVersionAdvice(webapp, 3)); - upgrader.upgradePlatform(server, platform); + deployOpenmrs(server, platform); break; } case(DEPLOY_OWA_OPTION):{ @@ -256,6 +256,35 @@ public void deployModule(String serverId, String groupId, String artifactId, Str deployModule(groupId, artifactId, version, server); } + public void deployOpenmrs(Server server, String version) throws MojoFailureException, MojoExecutionException { + Artifact artifact = new Artifact(SDKConstants.PLATFORM_ARTIFACT_ID, version, Artifact.GROUP_DISTRO); + try { + deployOpenmrsPlatform(server, artifact); + } catch (MojoExecutionException e) { + ServerUpgrader serverUpgrader = new ServerUpgrader(this); + serverUpgrader.upgradePlatform(server, platform); + } + } + + public void deployOpenmrsFromDir(Server server, Artifact artifact) throws MojoExecutionException, MojoFailureException { + String artifactId = artifact.getArtifactId(); + if(artifactId.equals("openmrs-webapp")){ + deployOpenmrsWar(server, artifact); + } else if(artifactId.equals("openmrs-distro-platform")){ + artifact.setArtifactId("platform"); + deployOpenmrsPlatform(server, artifact); + } + } + + private void deployOpenmrsPlatform(Server server, Artifact artifact) throws MojoExecutionException, MojoFailureException { + DistroProperties platformDistroProperties = distroHelper.downloadDistroProperties(server.getServerDirectory(), artifact); + DistroProperties serverDistroProperties = server.getDistroProperties(); + serverDistroProperties.setArtifacts(platformDistroProperties); + serverDistroProperties.saveTo(server.getServerDirectory()); + ServerUpgrader serverUpgrader = new ServerUpgrader(this); + serverUpgrader.upgradeToDistro(server, serverDistroProperties); + } + /** * Deploy openmrs.war file to server * @param server @@ -380,6 +409,14 @@ public Artifact checkCurrentDirectoryForOpenmrsWebappUpdate(Server server) throw return new Artifact("openmrs-webapp", mavenProject.getVersion(), Artifact.GROUP_WEB, Artifact.TYPE_WAR); } } + } else if("platform".equals(moduleName)){ + if(!new Version(mavenProject.getVersion()).equals(new Version(server.getPlatformVersion())) || new Version(mavenProject.getVersion()).isSnapshot()){ + String message = String.format("The server currently has openmrs platform in version %s. Would you like to update it to %s from the current directory?", server.getPlatformVersion(), mavenProject.getVersion()); + boolean agree = wizard.promptYesNo(message); + if(agree){ + return new Artifact("openmrs-distro-platform", mavenProject.getVersion(), Artifact.GROUP_DISTRO); + } + } } return null; } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java index f4f5dd98..5ab096b7 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java @@ -230,4 +230,15 @@ private boolean isBaseSdkProperty(String key) { } + public void setArtifacts(BaseSdkProperties baseSdkProperties){ + List moduleArtifacts = baseSdkProperties.getModuleArtifacts(); + for (Artifact moduleArtifact : moduleArtifacts) { + this.setModuleProperties(moduleArtifact); + } + List warArtifacts = baseSdkProperties.getWarArtifacts(); + for (Artifact warArtifact : warArtifacts) { + this.setPlatformVersion(warArtifact.getVersion()); + } + } + }