32
32
import org .apache .maven .plugins .annotations .Mojo ;
33
33
import org .apache .maven .plugins .annotations .Parameter ;
34
34
import org .openmrs .maven .plugins .model .Artifact ;
35
+ import org .openmrs .maven .plugins .model .BaseSdkProperties ;
35
36
import org .openmrs .maven .plugins .model .DistroProperties ;
36
37
import org .openmrs .maven .plugins .model .Server ;
37
38
import org .openmrs .maven .plugins .model .Version ;
41
42
import org .openmrs .maven .plugins .utility .SDKConstants ;
42
43
import org .openmrs .maven .plugins .utility .ServerHelper ;
43
44
45
+ import static org .openmrs .maven .plugins .model .BaseSdkProperties .PROPERTY_DISTRO_ARTIFACT_ID ;
46
+ import static org .openmrs .maven .plugins .model .BaseSdkProperties .PROPERTY_DISTRO_GROUP_ID ;
47
+
44
48
/**
45
49
* Set up a new instance of OpenMRS server. It can be used for setting up a platform or a distribution. It prompts for any missing, but required parameters.
46
50
*/
@@ -55,11 +59,11 @@ public class Setup extends AbstractServerTask {
55
59
"If you want to enable remote debugging by default when running the server, "
56
60
+ "\n specify the %s here (e.g. 1044). Leave blank to disable debugging. \n (Do not do this on a production server)" ;
57
61
58
- private static final String O2_Distribution = "2.x Distribution" ;
62
+ private static final String O2_DISTRIBUTION = "2.x Distribution" ;
59
63
60
64
private static final String PLATFORM = "Platform" ;
61
65
62
- private static final String O3_Distribution = "O3 Distribution" ;
66
+ private static final String O3_DISTRIBUTION = "O3 Distribution" ;
63
67
64
68
private static final String CLASSPATH_SCRIPT_PREFIX = "classpath://" ;
65
69
@@ -189,16 +193,17 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu
189
193
if (distroProperties != null ) {
190
194
options .add (distroProperties .getName () + " " + distroProperties .getVersion () + " from current directory" );
191
195
}
192
- options .add (O2_Distribution );
196
+
197
+ options .add (O3_DISTRIBUTION );
198
+ options .add (O2_DISTRIBUTION );
193
199
options .add (PLATFORM );
194
- options .add (O3_Distribution );
195
200
String choice = wizard .promptForMissingValueWithOptions (SETUP_SERVERS_PROMPT , null , null , options );
196
201
197
202
switch (choice ) {
198
203
case PLATFORM :
199
204
platformMode = true ;
200
205
break ;
201
- case O2_Distribution :
206
+ case O2_DISTRIBUTION :
202
207
wizard .promptForRefAppVersionIfMissing (server , versionsHelper );
203
208
if (DistroHelper .isRefapp2_3_1orLower (server .getDistroArtifactId (), server .getVersion ())) {
204
209
distroProperties = new DistroProperties (server .getVersion ());
@@ -207,30 +212,34 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu
207
212
}
208
213
platformMode = false ;
209
214
break ;
210
- case O3_Distribution :
215
+ case O3_DISTRIBUTION :
211
216
wizard .promptForO3RefAppVersionIfMissing (server , versionsHelper );
212
217
Artifact artifact = new Artifact (server .getDistroArtifactId (), server .getVersion (),
213
218
server .getDistroGroupId (), "zip" );
214
219
Properties frontendProperties ;
215
220
if (new Version (server .getVersion ()).higher (new Version ("3.0.0-beta.16" ))) {
216
221
frontendProperties = distroHelper .getFrontendProperties (server );
217
- }
218
- else {
222
+ } else {
219
223
frontendProperties = PropertiesUtils .getFrontendPropertiesFromSpaConfigUrl (
220
224
"https://raw.githubusercontent.com/openmrs/openmrs-distro-referenceapplication/" + server .getVersion () +"/frontend/spa-build-config.json" );
221
225
}
226
+
222
227
Properties configurationProperties = PropertiesUtils .getConfigurationProperty (artifact );
223
228
File file = distroHelper .downloadDistro (server .getServerDirectory (), artifact );
224
229
Properties backendProperties = PropertiesUtils .getDistroProperties (file );
225
230
Properties spaModuleProperty = PropertiesUtils .getModuleProperty ("https://raw.githubusercontent.com/openmrs/openmrs-module-spa/master/pom.xml" );
231
+
226
232
if (appShellVersion != null ) {
227
233
frontendProperties .setProperty ("spa.core" , appShellVersion );
228
234
}
235
+
229
236
Properties allProperties = new Properties ();
230
237
allProperties .putAll (backendProperties );
231
238
allProperties .putAll (spaModuleProperty );
232
239
allProperties .putAll (frontendProperties );
233
240
allProperties .putAll (configurationProperties );
241
+ allProperties .put (PROPERTY_DISTRO_GROUP_ID , artifact .getGroupId ());
242
+ allProperties .put (PROPERTY_DISTRO_ARTIFACT_ID , artifact .getArtifactId ());
234
243
distroProperties = new DistroProperties (allProperties );
235
244
platformMode = false ;
236
245
break ;
@@ -368,26 +377,31 @@ private void setConfigFolder(Server server, DistroProperties distroProperties) t
368
377
if (distroProperties .getConfigArtifacts ().isEmpty ()) {
369
378
return ;
370
379
}
380
+
371
381
File configDir = new File (server .getServerDirectory (), SDKConstants .OPENMRS_SERVER_CONFIGURATION );
372
382
configDir .mkdir ();
383
+
373
384
downloadConfigs (distroProperties , configDir );
374
- File referenceApplicationFile = new File (configDir , "referenceapplication-distro.owa" );
375
- if (!referenceApplicationFile .exists ()) {
376
- return ;
377
- }
378
- try {
379
- ZipFile zipFile = new ZipFile (referenceApplicationFile );
380
- zipFile .extractAll (configDir .getPath ());
381
- for (File file : Objects .requireNonNull (configDir .listFiles ())) {
382
- if (file .getName ().equals ("openmrs_config" )) {
383
- FileUtils .copyDirectory (file , configDir );
385
+
386
+ // Handle O2 configuration
387
+ if (Artifact .GROUP_DISTRO .equals (server .getDistroGroupId ()) && "referenceapplication-distro" .equals (server .getDistroArtifactId ())) {
388
+ File referenceApplicationFile = new File (configDir , "referenceapplication-distro.owa" );
389
+ if (!referenceApplicationFile .exists ()) {
390
+ return ;
391
+ }
392
+ try {
393
+ ZipFile zipFile = new ZipFile (referenceApplicationFile );
394
+ zipFile .extractAll (configDir .getPath ());
395
+ for (File file : Objects .requireNonNull (configDir .listFiles ())) {
396
+ if (file .getName ().equals ("openmrs_config" )) {
397
+ FileUtils .copyDirectory (file , configDir );
398
+ }
399
+ FileUtils .deleteQuietly (file );
384
400
}
385
- FileUtils .deleteQuietly (file );
401
+ FileUtils .deleteQuietly (referenceApplicationFile );
402
+ } catch (ZipException | IOException e ) {
403
+ throw new RuntimeException (e );
386
404
}
387
- FileUtils .deleteQuietly (referenceApplicationFile );
388
- }
389
- catch (ZipException | IOException e ) {
390
- throw new RuntimeException (e );
391
405
}
392
406
}
393
407
@@ -402,10 +416,7 @@ private void downloadConfigs(DistroProperties distroProperties, File configDir)
402
416
List <Artifact > configs = distroProperties .getConfigArtifacts ();
403
417
wizard .showMessage ("Downloading Configs...\n " );
404
418
if (!configs .isEmpty ()) {
405
- for (Artifact config : configs ) {
406
- wizard .showMessage ("Downloading Config: " + config );
407
- owaHelper .downloadOwa (configDir , config , moduleInstaller );
408
- }
419
+ moduleInstaller .installModules (configs , configDir .getAbsolutePath ());
409
420
}
410
421
}
411
422
0 commit comments