From adf9fa6fd0140fd405dc6c8809f42b7b0d1475ad Mon Sep 17 00:00:00 2001 From: Pawel Date: Fri, 14 Oct 2016 12:35:18 +0200 Subject: [PATCH] SDK-172 Fix failing openmrs-core build when watched --- .../java/org/openmrs/maven/plugins/Build.java | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Build.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Build.java index 0964bba0..b7aeb680 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Build.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Build.java @@ -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; @@ -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); @@ -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..."); @@ -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 { @@ -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 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()); + } } }