Skip to content

Commit

Permalink
Merge pull request #110 from PawelGutkowski/SDK-172
Browse files Browse the repository at this point in the history
SDK-172 Fix failing openmrs-core build when watched
  • Loading branch information
rkorytkowski authored Oct 14, 2016
2 parents 0449c63 + adf9fa6 commit 6df8400
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions maven-plugin/src/main/java/org/openmrs/maven/plugins/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.maven.shared.invoker.Invoker;
import org.apache.maven.shared.invoker.MavenInvocationException;
import org.openmrs.maven.plugins.model.Server;
import org.openmrs.maven.plugins.utility.DistroHelper;
import org.openmrs.maven.plugins.utility.Project;
import org.openmrs.maven.plugins.utility.SDKConstants;
import org.twdata.maven.mojoexecutor.MojoExecutor;
Expand Down Expand Up @@ -133,6 +134,7 @@ private void buildWatchedProjects() throws MojoExecutionException, MojoFailureEx

File tempFolder = createTempReactorProject(server);
try {
buildCoreIfWatched(server);
cleanInstallServerProject(tempFolder);
} catch (Exception e) {
throw new IllegalStateException("Failed to build project in "+tempFolder.getAbsolutePath(), e);
Expand All @@ -141,12 +143,22 @@ private void buildWatchedProjects() throws MojoExecutionException, MojoFailureEx
}

try {
deployWatchedModules(server);
deployWatchedProjects(server);
} catch (MavenInvocationException e) {
throw new MojoFailureException("Failed to deploy watched modules", e);
}
}

private boolean buildCoreIfWatched(Server server) throws MojoFailureException {
for (Project project : server.getWatchedProjects()) {
if(project.isOpenmrsCore()){
cleanInstallServerProject(new File(project.getPath()));
return true;
}
}
return false;
}

private void buildOwaProject() throws MojoExecutionException {

System.out.println("Building OWA project...");
Expand Down Expand Up @@ -217,15 +229,19 @@ private File createTempReactorProject(Server server) throws MojoFailureException
"Unwatch this module by running mvn openmrs-sdk:unwatch -DartifactId="+module.getArtifactId()+" -DserverId=" + serverId);
}

Path newLink = Paths.get(new File(tempFolder, module.getArtifactId()).getAbsolutePath());
Path existingfile = Paths.get(module.getPath());
try {
Files.createSymbolicLink(newLink, existingfile);
} catch (IOException e) {
copyModuleToTempServer(module.getPath(), newLink.toString());
} finally {
tempModel.addModule(module.getArtifactId());
//core is built before, its plugins fail when it is built as submodule
if(!module.isOpenmrsCore()){
Path newLink = Paths.get(new File(tempFolder, module.getArtifactId()).getAbsolutePath());
Path existingfile = Paths.get(module.getPath());
try {
Files.createSymbolicLink(newLink, existingfile);
} catch (IOException e) {
copyModuleToTempServer(module.getPath(), newLink.toString());
} finally {
tempModel.addModule(module.getArtifactId());
}
}

}

try {
Expand Down Expand Up @@ -282,11 +298,15 @@ private Model createModel(){
* @throws MojoExecutionException
* @throws MavenInvocationException
*/
private void deployWatchedModules(Server server) throws MojoFailureException, MojoExecutionException, MavenInvocationException {
private void deployWatchedProjects(Server server) throws MojoFailureException, MojoExecutionException, MavenInvocationException {
Set<Project> watchedProject = server.getWatchedProjects();
for (Project module: watchedProject) {
Project project = Project.loadProject(new File(module.getPath()));
new Deploy(this).deployModule(project.getGroupId(), project.getArtifactId(), project.getVersion(), server);
if(project.isOpenmrsModule()){
new Deploy(this).deployModule(project.getGroupId(), project.getArtifactId(), project.getVersion(), server);
} else if(project.isOpenmrsCore()){
new ServerUpgrader(this).upgradePlatform(server, project.getVersion());
}
}
}

Expand Down

0 comments on commit 6df8400

Please sign in to comment.