1
1
package com .marklogic .appdeployer ;
2
2
3
- import java .io .FileFilter ;
4
- import java .util .ArrayList ;
5
- import java .util .HashMap ;
6
- import java .util .List ;
7
- import java .util .Map ;
8
-
9
- import javax .net .ssl .SSLContext ;
10
-
11
3
import com .marklogic .client .DatabaseClient ;
12
4
import com .marklogic .client .DatabaseClientFactory ;
13
5
import com .marklogic .client .DatabaseClientFactory .Authentication ;
14
6
import com .marklogic .client .DatabaseClientFactory .SSLHostnameVerifier ;
15
7
import com .marklogic .client .modulesloader .impl .XccAssetLoader ;
16
8
import com .marklogic .client .modulesloader .ssl .SimpleX509TrustManager ;
9
+ import com .marklogic .client .modulesloader .tokenreplacer .DefaultModuleTokenReplacer ;
10
+ import com .marklogic .client .modulesloader .tokenreplacer .ModuleTokenReplacer ;
11
+ import com .marklogic .client .modulesloader .tokenreplacer .PropertiesSource ;
12
+ import com .marklogic .client .modulesloader .tokenreplacer .RoxyModuleTokenReplacer ;
17
13
import com .marklogic .client .modulesloader .xcc .DefaultDocumentFormatGetter ;
18
14
15
+ import javax .net .ssl .SSLContext ;
16
+ import java .io .FileFilter ;
17
+ import java .util .*;
18
+
19
19
/**
20
20
* Encapsulates common configuration properties for an application deployed to MarkLogic. These properties include not
21
21
* just names of application resources - such as app servers and databases - but also connection information for loading
22
22
* modules into an application as well as paths for modules and configuration files.
23
- *
23
+ * <p>
24
24
* An instance of this class is passed in as the main argument to the methods in the {@code AppDeployer} interface,
25
25
* meaning that you're free to not just configure this as needed but also subclass it and add anything that you would
26
26
* like.
@@ -106,6 +106,13 @@ public class AppConfig {
106
106
// Path to use for DeployFlexrepCommand
107
107
private String flexrepPath ;
108
108
109
+ // Whether or not to replace tokens in modules
110
+ private boolean replaceTokensInModules = true ;
111
+ // Whether or not to prefix each module token with "@ml."
112
+ private boolean useRoxyTokenPrefix = true ;
113
+ // Additional PropertiesSources instance to use for replacing module tokens
114
+ private List <PropertiesSource > moduleTokensPropertiesSources = new ArrayList <>();
115
+
109
116
private Map <String , Integer > forestCounts = new HashMap <>();
110
117
111
118
public AppConfig () {
@@ -131,7 +138,7 @@ public void setSimpleSslConfig() {
131
138
/**
132
139
* Convenience method for constructing a MarkLogic Java API DatabaseClient based on the host, restPort,
133
140
* restAdminUsername, restAdminPassword, restAuthentication, restSslContext, and restSslHostnameVerifier properties.
134
- *
141
+ *
135
142
* @return
136
143
*/
137
144
public DatabaseClient newDatabaseClient () {
@@ -141,7 +148,7 @@ public DatabaseClient newDatabaseClient() {
141
148
142
149
/**
143
150
* Just like newDatabaseClient, but uses testRestPort.
144
- *
151
+ *
145
152
* @return
146
153
*/
147
154
public DatabaseClient newTestDatabaseClient () {
@@ -151,7 +158,7 @@ public DatabaseClient newTestDatabaseClient() {
151
158
152
159
/**
153
160
* Like newDatabaseClient, but connects to schemas database.
154
- *
161
+ *
155
162
* @return
156
163
*/
157
164
public DatabaseClient newSchemasDatabaseClient () {
@@ -191,14 +198,39 @@ public XccAssetLoader newXccAssetLoader() {
191
198
l .setFileFilter (assetFileFilter );
192
199
}
193
200
201
+ if (isReplaceTokensInModules ()) {
202
+ l .setModuleTokenReplacer (buildModuleTokenReplacer ());
203
+ }
204
+
194
205
return l ;
206
+ }
195
207
208
+ protected ModuleTokenReplacer buildModuleTokenReplacer () {
209
+ DefaultModuleTokenReplacer r = isUseRoxyTokenPrefix () ? new RoxyModuleTokenReplacer () : new DefaultModuleTokenReplacer ();
210
+ if (customTokens != null && !customTokens .isEmpty ()) {
211
+ r .addPropertiesSource (new PropertiesSource () {
212
+ @ Override
213
+ public Properties getProperties () {
214
+ Properties p = new Properties ();
215
+ p .putAll (customTokens );
216
+ return p ;
217
+ }
218
+ });
219
+ }
220
+
221
+ if (getModuleTokensPropertiesSources () != null ) {
222
+ for (PropertiesSource ps : getModuleTokensPropertiesSources ()) {
223
+ r .addPropertiesSource (ps );
224
+ }
225
+ }
226
+
227
+ return r ;
196
228
}
197
229
198
230
/**
199
231
* @return true if {@code testRestPort} is set and greater than zero. This is used as an indicator that an
200
- * application wants test resources - most likely a separate app server and content database - created as
201
- * part of a deployment.
232
+ * application wants test resources - most likely a separate app server and content database - created as
233
+ * part of a deployment.
202
234
*/
203
235
public boolean isTestPortSet () {
204
236
return testRestPort != null && testRestPort > 0 ;
@@ -211,51 +243,79 @@ public String getRestServerName() {
211
243
return restServerName != null ? restServerName : name ;
212
244
}
213
245
246
+ public void setRestServerName (String restServerName ) {
247
+ this .restServerName = restServerName ;
248
+ }
249
+
214
250
/**
215
251
* @return {@code testRestServerName} if it is set; {@code name}-test otherwise
216
252
*/
217
253
public String getTestRestServerName () {
218
254
return testRestServerName != null ? testRestServerName : name + "-test" ;
219
255
}
220
256
257
+ public void setTestRestServerName (String testRestServerName ) {
258
+ this .testRestServerName = testRestServerName ;
259
+ }
260
+
221
261
/**
222
262
* @return {@code contentDatabaseName} if it is set; {@code name}-content otherwise
223
263
*/
224
264
public String getContentDatabaseName () {
225
265
return contentDatabaseName != null ? contentDatabaseName : name + "-content" ;
226
266
}
227
267
268
+ public void setContentDatabaseName (String contentDatabaseName ) {
269
+ this .contentDatabaseName = contentDatabaseName ;
270
+ }
271
+
228
272
/**
229
273
* @return {@code testContentDatabaseName} if it is set; {@code name}-test-content otherwise
230
274
*/
231
275
public String getTestContentDatabaseName () {
232
276
return testContentDatabaseName != null ? testContentDatabaseName : name + "-test-content" ;
233
277
}
234
278
279
+ public void setTestContentDatabaseName (String testContentDatabaseName ) {
280
+ this .testContentDatabaseName = testContentDatabaseName ;
281
+ }
282
+
235
283
/**
236
284
* @return {@code modulesDatabaseName} if it is set; {@code name}-modules otherwise
237
285
*/
238
286
public String getModulesDatabaseName () {
239
287
return modulesDatabaseName != null ? modulesDatabaseName : name + "-modules" ;
240
288
}
241
289
290
+ public void setModulesDatabaseName (String modulesDatabaseName ) {
291
+ this .modulesDatabaseName = modulesDatabaseName ;
292
+ }
293
+
242
294
/**
243
295
* @return {@code triggersDatabaseName} if it is set; {@code name}-triggers otherwise
244
296
*/
245
297
public String getTriggersDatabaseName () {
246
298
return triggersDatabaseName != null ? triggersDatabaseName : name + "-triggers" ;
247
299
}
248
300
301
+ public void setTriggersDatabaseName (String triggersDatabaseName ) {
302
+ this .triggersDatabaseName = triggersDatabaseName ;
303
+ }
304
+
249
305
/**
250
306
* @return {@code schemasDatabaseName} if it is set; {@code name}-schemas otherwise
251
307
*/
252
308
public String getSchemasDatabaseName () {
253
309
return schemasDatabaseName != null ? schemasDatabaseName : name + "-schemas" ;
254
310
}
255
311
312
+ public void setSchemasDatabaseName (String schemasDatabaseName ) {
313
+ this .schemasDatabaseName = schemasDatabaseName ;
314
+ }
315
+
256
316
/**
257
317
* @return the name of the application, which is then used to generate app server and database names unless those
258
- * are set via their respective properties
318
+ * are set via their respective properties
259
319
*/
260
320
public String getName () {
261
321
return name ;
@@ -311,7 +371,7 @@ public void setRestPort(Integer restPort) {
311
371
312
372
/**
313
373
* @return the post of the REST API server used for loading modules that are specific to a test server (currently,
314
- * just search options)
374
+ * just search options)
315
375
*/
316
376
public Integer getTestRestPort () {
317
377
return testRestPort ;
@@ -345,7 +405,7 @@ public void setModulePaths(List<String> modulePaths) {
345
405
346
406
/**
347
407
* @return the name of the group in which the application associated with this configuration should have its app
348
- * servers and other group-specific resources
408
+ * servers and other group-specific resources
349
409
*/
350
410
public String getGroupName () {
351
411
return groupName ;
@@ -357,7 +417,7 @@ public void setGroupName(String groupName) {
357
417
358
418
/**
359
419
* @return the MarkLogic Java Client {@code Authentication} object that is used for authenticating with a REST API
360
- * server for loading modules
420
+ * server for loading modules
361
421
*/
362
422
public Authentication getRestAuthentication () {
363
423
return restAuthentication ;
@@ -369,8 +429,8 @@ public void setRestAuthentication(Authentication authentication) {
369
429
370
430
/**
371
431
* @return a {@code ConfigDir} instance that defines the location of the configuration directory (where files are
372
- * stored that are then loaded via MarkLogic Management API endpoints) as well as paths to specific
373
- * resources within that directory
432
+ * stored that are then loaded via MarkLogic Management API endpoints) as well as paths to specific
433
+ * resources within that directory
374
434
*/
375
435
public ConfigDir getConfigDir () {
376
436
return configDir ;
@@ -382,8 +442,8 @@ public void setConfigDir(ConfigDir configDir) {
382
442
383
443
/**
384
444
* @return a map of tokens that are intended to be replaced with their associated values in configuration files.
385
- * This map allows for externalized properties to be passed into configuration files - e.g. Gradle
386
- * properties can be swapped in for tokens in configuration files at deploy time.
445
+ * This map allows for externalized properties to be passed into configuration files - e.g. Gradle
446
+ * properties can be swapped in for tokens in configuration files at deploy time.
387
447
*/
388
448
public Map <String , String > getCustomTokens () {
389
449
return customTokens ;
@@ -395,7 +455,7 @@ public void setCustomTokens(Map<String, String> customTokens) {
395
455
396
456
/**
397
457
* @return whether a triggers database should be created by default; defaults to true, as it's very common to need a
398
- * triggers database, such as for CPF, Alerting, custom triggers, etc.
458
+ * triggers database, such as for CPF, Alerting, custom triggers, etc.
399
459
*/
400
460
public boolean isCreateTriggersDatabase () {
401
461
return createTriggersDatabase ;
@@ -407,7 +467,7 @@ public void setCreateTriggersDatabase(boolean createTriggerDatabase) {
407
467
408
468
/**
409
469
* @return a Java {@code SSLContext} for making an SSL connection with the REST API server for loading modules; null
410
- * if an SSL connection is not required
470
+ * if an SSL connection is not required
411
471
*/
412
472
public SSLContext getRestSslContext () {
413
473
return restSslContext ;
@@ -419,7 +479,7 @@ public void setRestSslContext(SSLContext restSslContext) {
419
479
420
480
/**
421
481
* @return a MarkLogic Java Client {@code SSLHostnameVerifier} that is used to make an SSL connection to the REST
422
- * API server for loading modules; null if an SSL connection is not required
482
+ * API server for loading modules; null if an SSL connection is not required
423
483
*/
424
484
public SSLHostnameVerifier getRestSslHostnameVerifier () {
425
485
return restSslHostnameVerifier ;
@@ -429,34 +489,6 @@ public void setRestSslHostnameVerifier(SSLHostnameVerifier restSslHostnameVerifi
429
489
this .restSslHostnameVerifier = restSslHostnameVerifier ;
430
490
}
431
491
432
- public void setRestServerName (String restServerName ) {
433
- this .restServerName = restServerName ;
434
- }
435
-
436
- public void setTestRestServerName (String testRestServerName ) {
437
- this .testRestServerName = testRestServerName ;
438
- }
439
-
440
- public void setContentDatabaseName (String contentDatabaseName ) {
441
- this .contentDatabaseName = contentDatabaseName ;
442
- }
443
-
444
- public void setTestContentDatabaseName (String testContentDatabaseName ) {
445
- this .testContentDatabaseName = testContentDatabaseName ;
446
- }
447
-
448
- public void setModulesDatabaseName (String modulesDatabaseName ) {
449
- this .modulesDatabaseName = modulesDatabaseName ;
450
- }
451
-
452
- public void setTriggersDatabaseName (String triggersDatabaseName ) {
453
- this .triggersDatabaseName = triggersDatabaseName ;
454
- }
455
-
456
- public void setSchemasDatabaseName (String schemasDatabaseName ) {
457
- this .schemasDatabaseName = schemasDatabaseName ;
458
- }
459
-
460
492
public String [] getAdditionalBinaryExtensions () {
461
493
return additionalBinaryExtensions ;
462
494
}
@@ -520,4 +552,28 @@ public Integer getAppServicesPort() {
520
552
public void setAppServicesPort (Integer appServicesPort ) {
521
553
this .appServicesPort = appServicesPort ;
522
554
}
555
+
556
+ public boolean isReplaceTokensInModules () {
557
+ return replaceTokensInModules ;
558
+ }
559
+
560
+ public void setReplaceTokensInModules (boolean replaceTokensInModules ) {
561
+ this .replaceTokensInModules = replaceTokensInModules ;
562
+ }
563
+
564
+ public boolean isUseRoxyTokenPrefix () {
565
+ return useRoxyTokenPrefix ;
566
+ }
567
+
568
+ public void setUseRoxyTokenPrefix (boolean useRoxyTokenPrefix ) {
569
+ this .useRoxyTokenPrefix = useRoxyTokenPrefix ;
570
+ }
571
+
572
+ public List <PropertiesSource > getModuleTokensPropertiesSources () {
573
+ return moduleTokensPropertiesSources ;
574
+ }
575
+
576
+ public void setModuleTokensPropertiesSources (List <PropertiesSource > moduleTokensPropertiesSources ) {
577
+ this .moduleTokensPropertiesSources = moduleTokensPropertiesSources ;
578
+ }
523
579
}
0 commit comments