Skip to content

Commit 9a36741

Browse files
committed
Add support to passing a custom spa-build-config.json file
1 parent ad96c4f commit 9a36741

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ public class Setup extends AbstractServerTask {
153153
@Parameter(property = "reuseNodeCache")
154154
public Boolean overrideReuseNodeCache;
155155

156+
@Parameter(property = "spaConfigFile")
157+
public String spaConfigFile;
158+
156159
private ServerHelper serverHelper;
157160

158161
public Setup() {
@@ -239,10 +242,11 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu
239242

240243
if (REFAPP_3X_PROMPT.equals(choice)) {
241244
Artifact artifact = wizard.promptForRefApp3xArtifact(versionsHelper);
242-
Distribution distribution = builder.buildFromArtifact(artifact);
243-
return distribution.getEffectiveProperties();
245+
Distribution distribution = builder.buildFromArtifact(artifact, spaConfigFile);
246+
return distribution.getEffectiveProperties();
244247
}
245248

249+
246250
// If here, it is because custom distribution was chosen and the choice reflects the Maven coordinates
247251
Distribution distribution = distroHelper.resolveDistributionForStringSpecifier(choice, versionsHelper);
248252
return distribution.getEffectiveProperties();

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
import java.io.File;
1010
import java.io.FileInputStream;
11+
import java.io.IOException;
12+
import java.nio.file.Files;
13+
import java.nio.file.Paths;
1114
import java.util.Objects;
1215
import java.util.Properties;
1316

@@ -47,7 +50,7 @@ public Distribution buildFromFile(File propertiesFile) throws MojoExecutionExcep
4750
/**
4851
* Build from a distro properties file bundled in a zip or jar in Maven with the given artifact coordinates
4952
*/
50-
public Distribution buildFromArtifact(Artifact artifact) throws MojoExecutionException {
53+
public Distribution buildFromArtifact(Artifact artifact, String spaConfigFile) throws MojoExecutionException {
5154
mavenEnvironment.getWizard().showMessage("Building distribution from artifact: " + artifact);
5255
Distribution distribution = new Distribution();
5356
artifact = DistroHelper.normalizeArtifact(artifact, mavenEnvironment.getVersionsHelper());
@@ -92,11 +95,15 @@ public Distribution buildFromArtifact(Artifact artifact) throws MojoExecutionExc
9295
// Special handling for referenceapplication 3.x, which does not define everything needed in the published distro properties file
9396
if (REFAPP_3X_GROUP_ID.equals(artifact.getGroupId()) && REFAPP_3X_ARTIFACT_ID.equals(artifact.getArtifactId())) {
9497
mavenEnvironment.getWizard().showMessage("This is a 3.x refapp distribution");
95-
populateRefApp3xProperties(distribution, properties);
98+
populateRefApp3xProperties(distribution, properties, spaConfigFile);
9699
}
97100
return populateDistributionFromProperties(distribution, properties);
98101
}
99102

103+
public Distribution buildFromArtifact(Artifact artifact) throws MojoExecutionException {
104+
return buildFromArtifact(artifact, null);
105+
}
106+
100107
public void populateRefApp2xProperties(Distribution distribution, Properties properties) {
101108
// Some refapp versions (eg. 2.13.0) include atlas version 2.2.6, which is not published in Maven. Adjust this.
102109
if ("2.2.6".equals(properties.getProperty("omod.atlas"))) {
@@ -110,7 +117,7 @@ public void populateRefApp2xProperties(Distribution distribution, Properties pro
110117
* This encapsulates these and applies them only for distributions that match the 3.x refapp Maven coordinates
111118
* Ideally this would not be needed
112119
*/
113-
protected void populateRefApp3xProperties(Distribution distribution, Properties properties) throws MojoExecutionException {
120+
protected void populateRefApp3xProperties(Distribution distribution, Properties properties, String spaConfigFile) throws MojoExecutionException {
114121

115122
String distroArtifactId = distribution.getArtifact().getArtifactId();
116123
String distroGroupId = distribution.getArtifact().getGroupId();
@@ -137,7 +144,14 @@ protected void populateRefApp3xProperties(Distribution distribution, Properties
137144
// Add spa properties if they are not included explicitly
138145
if (includedProperties.getSpaProperties().isEmpty()) {
139146
Properties frontendProperties;
140-
if (new Version(distroVersion).higher(new Version("3.0.0-beta.16"))) {
147+
if (spaConfigFile != null) {
148+
try {
149+
frontendProperties = PropertiesUtils.getFrontendPropertiesFromJson(Files.newInputStream(Paths.get(spaConfigFile)));
150+
} catch (IOException e) {
151+
throw new RuntimeException(e);
152+
}
153+
}
154+
else if (new Version(distroVersion).higher(new Version("3.0.0-beta.16"))) {
141155
com.github.zafarkhaja.semver.Version v = com.github.zafarkhaja.semver.Version.parse(distroVersion);
142156
String frontendArtifactId = v.satisfies(">=3.0.0") ? "distro-emr-frontend" : "referenceapplication-frontend";
143157
Artifact frontendArtifact = new Artifact(frontendArtifactId, distroVersion, distroGroupId, "zip");
@@ -169,6 +183,10 @@ protected void populateRefApp3xProperties(Distribution distribution, Properties
169183
}
170184
}
171185

186+
protected void populateRefApp3xProperties(Distribution distribution, Properties properties) throws MojoExecutionException {
187+
populateRefApp3xProperties(distribution, properties, null);
188+
}
189+
172190
/**
173191
* Consistently populate the common properties of the distribution from the given properties
174192
* This includes handling parent distributions and building a set of effective properties based on

0 commit comments

Comments
 (0)