|
34 | 34 | import java.nio.charset.StandardCharsets;
|
35 | 35 | import java.util.ArrayList;
|
36 | 36 | import java.util.List;
|
| 37 | +import java.util.Objects; |
37 | 38 |
|
38 | 39 | /**
|
39 | 40 | * Create docker configuration for distributions.
|
@@ -120,6 +121,9 @@ public class BuildDistro extends AbstractTask {
|
120 | 121 | @Parameter(defaultValue = "false", property = "reset")
|
121 | 122 | private boolean reset;
|
122 | 123 |
|
| 124 | + @Parameter(property = "appShellVersion") |
| 125 | + private String appShellVersion; |
| 126 | + |
123 | 127 | @Override
|
124 | 128 | public void executeTask() throws MojoExecutionException, MojoFailureException {
|
125 | 129 | File buildDirectory = getBuildDirectory();
|
@@ -176,22 +180,9 @@ public void executeTask() throws MojoExecutionException, MojoFailureException {
|
176 | 180 | break;
|
177 | 181 | case O3_DISTRIBUTION:
|
178 | 182 | wizard.promptForO3RefAppVersionIfMissing(server, versionsHelper);
|
179 |
| - Artifact artifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), server.getDistroGroupId(), "zip"); |
180 |
| - try { |
181 |
| - String gitHubUrl = "https://github.com/openmrs/openmrs-distro-referenceapplication"; |
182 |
| - CloneCommand cloneCommand = Git.cloneRepository().setURI(gitHubUrl) |
183 |
| - .setDirectory(new File(dir)); |
184 |
| - if (!server.getVersion().equals(versionsHelper.getLatestSnapshotVersion(artifact))) { |
185 |
| - cloneCommand.setBranch(server.getVersion()); |
186 |
| - } |
187 |
| - wizard.showMessage("Cloning from " + gitHubUrl); |
188 |
| - cloneCommand.call(); |
189 |
| - } catch (GitAPIException e) { |
190 |
| - throw new RuntimeException(e); |
191 |
| - } |
192 |
| - wizard.showMessage("The '"+ artifact.getArtifactId() +" " + artifact.getVersion() + |
193 |
| - "' distribution created! To start up the server run 'docker-compose up' from" + buildDirectory.getAbsolutePath()); |
194 |
| - return; |
| 183 | + server.setServerDirectory(buildDirectory); |
| 184 | + distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), server.getDistroGroupId(), "zip"); |
| 185 | + distroProperties = new DistroProperties(distroHelper.getArtifactProperties(distroArtifact, server, appShellVersion)); |
195 | 186 | }
|
196 | 187 |
|
197 | 188 | }
|
@@ -312,8 +303,16 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro
|
312 | 303 | moduleInstaller.installModules(distroProperties.getModuleArtifacts(distroHelper, targetDirectory),
|
313 | 304 | modulesDir.getAbsolutePath());
|
314 | 305 |
|
| 306 | + File frontendDir = new File(web, "frontend"); |
| 307 | + frontendDir.mkdir(); |
| 308 | + |
| 309 | + File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION); |
| 310 | + configDir.mkdir(); |
| 311 | + setConfigFolder(configDir, distroProperties, distroArtifact); |
| 312 | + |
315 | 313 | spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache);
|
316 | 314 |
|
| 315 | + |
317 | 316 | File owasDir = new File(web, "owa");
|
318 | 317 | owasDir.mkdir();
|
319 | 318 | downloadOWAs(targetDirectory, distroProperties, owasDir);
|
@@ -341,6 +340,49 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro
|
341 | 340 | return distroName;
|
342 | 341 | }
|
343 | 342 |
|
| 343 | + private void setConfigFolder(File configDir, DistroProperties distroProperties, Artifact distroArtifact) throws MojoExecutionException { |
| 344 | + if (distroProperties.getConfigArtifacts().isEmpty()) { |
| 345 | + return; |
| 346 | + } |
| 347 | + |
| 348 | + |
| 349 | + downloadConfigs(distroProperties, configDir); |
| 350 | + |
| 351 | + File refappConfigFile = new File(configDir, distroArtifact.getArtifactId() + "-" + distroArtifact.getVersion() + ".zip"); |
| 352 | + |
| 353 | + // Handle O2 configuration |
| 354 | + if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(distroArtifact.getGroupId()) && "referenceapplication-distro".equals(distroArtifact.getArtifactId())) { |
| 355 | + refappConfigFile = new File(configDir, "referenceapplication-distro.owa"); |
| 356 | + } |
| 357 | + |
| 358 | + if (!refappConfigFile.exists()) { |
| 359 | + wizard.showError("No Configuration file found at " + refappConfigFile.getAbsolutePath()); |
| 360 | + return; |
| 361 | + } |
| 362 | + |
| 363 | + try { |
| 364 | + ZipFile zipFile = new ZipFile(refappConfigFile); |
| 365 | + zipFile.extractAll(configDir.getPath()); |
| 366 | + for (File file : Objects.requireNonNull(configDir.listFiles())) { |
| 367 | + if (file.getName().equals("openmrs_config")) { |
| 368 | + FileUtils.copyDirectory(file, configDir); |
| 369 | + } |
| 370 | + FileUtils.deleteQuietly(file); |
| 371 | + } |
| 372 | + FileUtils.deleteQuietly(refappConfigFile); |
| 373 | + } catch (ZipException | IOException e) { |
| 374 | + throw new RuntimeException(e); |
| 375 | + } |
| 376 | + } |
| 377 | + |
| 378 | + private void downloadConfigs(DistroProperties distroProperties, File configDir) throws MojoExecutionException { |
| 379 | + List<Artifact> configs = distroProperties.getConfigArtifacts(); |
| 380 | + wizard.showMessage("Downloading Configs...\n"); |
| 381 | + if (!configs.isEmpty()) { |
| 382 | + moduleInstaller.installModules(configs, configDir.getAbsolutePath()); |
| 383 | + } |
| 384 | + } |
| 385 | + |
344 | 386 | private void downloadOWAs(File targetDirectory, DistroProperties distroProperties, File owasDir)
|
345 | 387 | throws MojoExecutionException {
|
346 | 388 | List<Artifact> owas = distroProperties.getOwaArtifacts(distroHelper, targetDirectory);
|
|
0 commit comments