Skip to content

Commit

Permalink
AC-182 Deploy shows incorrect platform versions
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamGrzybkowski committed Dec 27, 2016
1 parent 736d60a commit 47dc69e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
45 changes: 41 additions & 4 deletions maven-plugin/src/main/java/org/openmrs/maven/plugins/Deploy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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());
Expand Down Expand Up @@ -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):{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,15 @@ private boolean isBaseSdkProperty(String key) {
}


public void setArtifacts(BaseSdkProperties baseSdkProperties){
List<Artifact> moduleArtifacts = baseSdkProperties.getModuleArtifacts();
for (Artifact moduleArtifact : moduleArtifacts) {
this.setModuleProperties(moduleArtifact);
}
List<Artifact> warArtifacts = baseSdkProperties.getWarArtifacts();
for (Artifact warArtifact : warArtifacts) {
this.setPlatformVersion(warArtifact.getVersion());
}
}

}

0 comments on commit 47dc69e

Please sign in to comment.