Skip to content

Commit 275d4cc

Browse files
authored
O3-3426: Distro Inheritance Tool for the Build-Distro plugin
1 parent 393b7ba commit 275d4cc

File tree

3 files changed

+63
-30
lines changed

3 files changed

+63
-30
lines changed

maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ public void executeTask() throws MojoExecutionException, MojoFailureException {
138138
if (distroFile.exists()) {
139139
wizard.showMessage("Building distribution from the distro file at " + distroFile + "...\n");
140140
distroProperties = new DistroProperties(distroFile);
141+
distroArtifact = distroProperties.getParentArtifact();
142+
distroProperties = handleParentDistroProperties(distroArtifact, buildDirectory, distroProperties);
141143
} else if (Project.hasProject(userDir)) {
142144
Project config = Project.loadProject(userDir);
143145
distroArtifact = DistroHelper
@@ -157,6 +159,8 @@ public void executeTask() throws MojoExecutionException, MojoFailureException {
157159
}
158160
} else if (StringUtils.isNotBlank(distro)) {
159161
distroProperties = distroHelper.resolveDistroPropertiesForStringSpecifier(distro, versionsHelper);
162+
distroArtifact = distroProperties.getParentArtifact();
163+
distroProperties = handleParentDistroProperties(distroArtifact, buildDirectory, distroProperties);
160164
}
161165

162166
if (distroProperties == null) {
@@ -198,6 +202,13 @@ public void executeTask() throws MojoExecutionException, MojoFailureException {
198202
+ buildDirectory.getAbsolutePath() + "\n");
199203
}
200204

205+
private DistroProperties handleParentDistroProperties(Artifact distroArtifact, File buildDirectory, DistroProperties distroProperties) throws MojoExecutionException {
206+
if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) && StringUtils.isNotBlank(distroArtifact.getVersion())) {
207+
distroProperties = distroHelper.resolveParentArtifact(distroArtifact, buildDirectory, distroProperties, appShellVersion);
208+
}
209+
return distroProperties;
210+
}
211+
201212
private File getBuildDirectory() throws MojoExecutionException {
202213
final File targetDir;
203214
if (StringUtils.isBlank(dir)) {

maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121
import java.util.Objects;
22-
import java.util.Properties;
2322

2423
import net.lingala.zip4j.core.ZipFile;
2524
import net.lingala.zip4j.exception.ZipException;
@@ -219,20 +218,7 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu
219218
default: // distro properties from current directory
220219
Artifact distroArtifact = distroProperties.getParentArtifact();
221220
if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) && StringUtils.isNotBlank(distroArtifact.getVersion())) {
222-
server.setDistroArtifactId(distroArtifact.getArtifactId());
223-
server.setDistroGroupId(distroArtifact.getGroupId());
224-
server.setVersion(distroArtifact.getVersion());
225-
Properties properties = distroHelper.getArtifactProperties(distroArtifact, server, appShellVersion);
226-
for (Object key : distroProperties.getAllKeys()) {
227-
String keyStr = (String) key;
228-
properties.setProperty(keyStr, distroProperties.getParam(keyStr));
229-
}
230-
List<String> exclusions = distroProperties.getExclusions();
231-
232-
for (String exclusion : exclusions) {
233-
properties.remove(exclusion);
234-
}
235-
distroProperties = new DistroProperties(properties);
221+
distroProperties = distroHelper.resolveParentArtifact(distroArtifact, server, distroProperties, appShellVersion);
236222
} else {
237223
server.setPlatformVersion(
238224
distroProperties.getPlatformVersion(distroHelper, server.getServerTmpDirectory()));

sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DistroHelper.java

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -457,17 +457,17 @@ private static boolean artifactsToCompareAreInvalid(Artifact previous, Artifact
457457
|| !isSameArtifact(previous, next);
458458
}
459459

460-
public Properties getFrontendProperties(Server server) throws MojoExecutionException {
461-
com.github.zafarkhaja.semver.Version v = com.github.zafarkhaja.semver.Version.parse(server.getVersion());
460+
public Properties getFrontendProperties(Artifact distroArtifact, File directory) throws MojoExecutionException {
461+
com.github.zafarkhaja.semver.Version v = com.github.zafarkhaja.semver.Version.parse(distroArtifact.getVersion());
462462

463463
Artifact artifact;
464464
if (v.satisfies(">=3.0.0")) {
465-
artifact = new Artifact("distro-emr-frontend", server.getVersion(), server.getDistroGroupId(), "zip");
465+
artifact = new Artifact("distro-emr-frontend", distroArtifact.getVersion(), distroArtifact.getGroupId(), "zip");
466466
} else {
467-
artifact = new Artifact("referenceapplication-frontend", server.getVersion(), server.getDistroGroupId(), "zip");
467+
artifact = new Artifact("referenceapplication-frontend", distroArtifact.getVersion(), distroArtifact.getGroupId(), "zip");
468468
}
469469

470-
File frontendDistroFile = downloadDistro(server.getServerDirectory(), artifact, "frontend.zip");
470+
File frontendDistroFile = downloadDistro(directory, artifact, "frontend.zip");
471471
Properties frontendProperties = new Properties();
472472

473473
try (ZipFile zipFile = new ZipFile(frontendDistroFile)) {
@@ -479,7 +479,7 @@ public Properties getFrontendProperties(Server server) throws MojoExecutionExcep
479479
frontendProperties = PropertiesUtils.getFrontendPropertiesFromJson(inputStream);
480480
}
481481
break;
482-
}
482+
}
483483
}
484484
}
485485
catch (IOException e) {
@@ -493,20 +493,30 @@ public Properties getFrontendProperties(Server server) throws MojoExecutionExcep
493493
return frontendProperties;
494494
}
495495

496+
public Properties getFrontendProperties(Server server) throws MojoExecutionException {
497+
Artifact artifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), server.getDistroGroupId());
498+
return getFrontendProperties(artifact, server.getServerDirectory());
499+
}
500+
501+
public Properties getFrontendPropertiesForServer(Artifact artifact, File directory) throws MojoExecutionException {
502+
if (new Version(artifact.getVersion()).higher(new Version("3.0.0-beta.16"))) {
503+
return getFrontendProperties(artifact, directory);
504+
} else {
505+
return PropertiesUtils.getFrontendPropertiesFromSpaConfigUrl(
506+
"https://raw.githubusercontent.com/openmrs/openmrs-distro-referenceapplication/" + artifact.getVersion() + "/frontend/spa-build-config.json");
507+
}
508+
}
509+
496510
public Properties getFrontendPropertiesForServer(Server server) throws MojoExecutionException {
497-
if (new Version(server.getVersion()).higher(new Version("3.0.0-beta.16"))) {
498-
return getFrontendProperties(server);
499-
} else {
500-
return PropertiesUtils.getFrontendPropertiesFromSpaConfigUrl(
501-
"https://raw.githubusercontent.com/openmrs/openmrs-distro-referenceapplication/" + server.getVersion() + "/frontend/spa-build-config.json");
502-
}
511+
Artifact artifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), server.getDistroGroupId());
512+
return getFrontendPropertiesForServer(artifact, server.getServerDirectory());
503513
}
504514

505-
public Properties getArtifactProperties(Artifact artifact, Server server, String appShellVersion) throws MojoExecutionException {
506-
File file = downloadDistro(server.getServerDirectory(), artifact);
515+
public Properties getArtifactProperties(Artifact artifact, File directory, String appShellVersion) throws MojoExecutionException {
516+
File file = downloadDistro(directory, artifact);
507517
Properties properties = new Properties();
508518
properties.putAll(PropertiesUtils.getDistroProperties(file));
509-
properties.putAll(getFrontendPropertiesForServer(server));
519+
properties.putAll(getFrontendPropertiesForServer(artifact, directory));
510520
properties.putAll(PropertiesUtils.getConfigurationProperty(artifact));
511521
properties.put(PROPERTY_DISTRO_GROUP_ID, artifact.getGroupId());
512522
properties.put(PROPERTY_DISTRO_ARTIFACT_ID, artifact.getArtifactId());
@@ -517,4 +527,30 @@ public Properties getArtifactProperties(Artifact artifact, Server server, String
517527
return properties;
518528
}
519529

530+
531+
public Properties getArtifactProperties(Artifact artifact, Server server, String appShellVersion) throws MojoExecutionException {
532+
return getArtifactProperties(artifact, server.getServerDirectory(), appShellVersion);
533+
}
534+
535+
public DistroProperties resolveParentArtifact(Artifact parentArtifact, File directory, DistroProperties distroProperties, String appShellVersion) throws MojoExecutionException {
536+
Properties properties = getArtifactProperties(parentArtifact, directory, appShellVersion);
537+
for (Object key : distroProperties.getAllKeys()) {
538+
String keyStr = (String) key;
539+
properties.setProperty(keyStr, distroProperties.getParam(keyStr));
540+
}
541+
List<String> exclusions = distroProperties.getExclusions();
542+
543+
for (String exclusion : exclusions) {
544+
properties.remove(exclusion);
545+
}
546+
return new DistroProperties(properties);
547+
}
548+
549+
public DistroProperties resolveParentArtifact(Artifact parentArtifact, Server server, DistroProperties distroProperties, String appShellVersion) throws MojoExecutionException {
550+
server.setDistroArtifactId(parentArtifact.getArtifactId());
551+
server.setDistroGroupId(parentArtifact.getGroupId());
552+
server.setVersion(parentArtifact.getVersion());
553+
return resolveParentArtifact(parentArtifact, server.getServerDirectory(), distroProperties, appShellVersion);
554+
}
555+
520556
}

0 commit comments

Comments
 (0)