Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit de6b487

Browse files
committed
#313 AppConfig now constructs paths relative to a project directory
This allows ml-gradle work when using Java 11 and the Gradle daemon
1 parent c1c4234 commit de6b487

File tree

7 files changed

+469
-366
lines changed

7 files changed

+469
-366
lines changed

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ targetCompatibility = "1.8"
1313
repositories {
1414
mavenLocal()
1515
jcenter()
16+
mavenCentral()
1617
}
1718

1819
dependencies {
@@ -27,6 +28,11 @@ dependencies {
2728
// For PreviewInterceptor; can be excluded if that feature is not used
2829
compile "com.flipkart.zjsonpatch:zjsonpatch:0.4.6"
2930

31+
// Required for Java 11
32+
compile "javax.xml.bind:jaxb-api:2.3.1"
33+
compile "com.sun.xml.bind:jaxb-core:2.3.0.1"
34+
compile "com.sun.xml.bind:jaxb-impl:2.3.2"
35+
3036
// Don't want to include this in the published jar, just the executable jar
3137
compileOnly "com.beust:jcommander:1.72"
3238

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
group=com.marklogic
22
javadocsDir=../gh-pages-marklogic-java/javadocs
3-
version=3.11.0
3+
version=3.12.dev
44
mlJavaclientUtilVersion=3.10.0
55
mlJunitVersion=3.1.0
66

src/main/java/com/marklogic/appdeployer/AppConfig.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import javax.net.ssl.SSLContext;
1616
import javax.net.ssl.X509TrustManager;
17+
import java.io.File;
1718
import java.io.FileFilter;
1819
import java.util.*;
1920
import java.util.regex.Pattern;
@@ -223,20 +224,23 @@ public class AppConfig {
223224

224225
private Map<String, Object> additionalProperties = new HashMap<>();
225226

227+
private File projectDir;
228+
226229
public AppConfig() {
227-
this(DEFAULT_MODULES_PATH, DEFAULT_SCHEMAS_PATH);
230+
this(null);
228231
}
229232

230-
public AppConfig(String defaultModulePath) {
231-
this(defaultModulePath, DEFAULT_SCHEMAS_PATH);
232-
}
233+
public AppConfig(File projectDir) {
234+
this.projectDir = projectDir;
235+
236+
modulePaths = new ArrayList<>();
237+
String path = projectDir != null ? new File(projectDir, DEFAULT_MODULES_PATH).getAbsolutePath() : DEFAULT_MODULES_PATH;
238+
modulePaths.add(path);
233239

234-
public AppConfig(String defaultModulePath, String defaultSchemasPath) {
235-
modulePaths = new ArrayList<>();
236-
modulePaths.add(defaultModulePath);
237-
configDirs = new ArrayList<>();
238-
configDirs.add(new ConfigDir());
239-
schemasPath = defaultSchemasPath;
240+
schemasPath = projectDir != null ? new File(projectDir, DEFAULT_SCHEMAS_PATH).getAbsolutePath() : DEFAULT_SCHEMAS_PATH;
241+
242+
configDirs = new ArrayList<>();
243+
configDirs.add(ConfigDir.withProjectDir(projectDir));
240244
}
241245

242246
public void populateCustomTokens(PropertiesSource propertiesSource) {
@@ -552,7 +556,7 @@ public ConfigDir getConfigDir() {
552556
public ConfigDir getFirstConfigDir() {
553557
if (configDirs == null || configDirs.isEmpty()) {
554558
this.configDirs = new ArrayList<>();
555-
this.configDirs.add(new ConfigDir());
559+
this.configDirs.add(ConfigDir.withProjectDir(this.projectDir));
556560
}
557561
return configDirs.get(0);
558562
}
@@ -1269,4 +1273,8 @@ public boolean isDeployPrivilegesWithCma() {
12691273
public void setDeployPrivilegesWithCma(boolean deployPrivilegesWithCma) {
12701274
this.deployPrivilegesWithCma = deployPrivilegesWithCma;
12711275
}
1276+
1277+
public File getProjectDir() {
1278+
return projectDir;
1279+
}
12721280
}

src/main/java/com/marklogic/appdeployer/ConfigDir.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.marklogic.appdeployer;
22

33
import java.io.File;
4-
import java.io.FileFilter;
54
import java.util.ArrayList;
65
import java.util.Arrays;
76
import java.util.List;
@@ -13,6 +12,8 @@
1312
*/
1413
public class ConfigDir {
1514

15+
public final static String DEFAULT_PATH = "src/main/ml-config";
16+
1617
private File baseDir;
1718

1819
private String databasesPath = "databases";
@@ -22,8 +23,17 @@ public class ConfigDir {
2223

2324
private List<File> contentDatabaseFiles;
2425

26+
private File projectDir;
27+
28+
public static ConfigDir withProjectDir(File projectDir) {
29+
File baseDir = projectDir != null ? new File(projectDir, DEFAULT_PATH) : new File(DEFAULT_PATH);
30+
ConfigDir configDir = new ConfigDir(baseDir);
31+
configDir.projectDir = projectDir;
32+
return configDir;
33+
}
34+
2535
public ConfigDir() {
26-
this(new File("src/main/ml-config"));
36+
new File(DEFAULT_PATH);
2737
}
2838

2939
public ConfigDir(File baseDir) {
@@ -226,4 +236,8 @@ public String getDefaultContentDatabaseFilename() {
226236
public void setDefaultContentDatabaseFilename(String contentDatabaseFilename) {
227237
this.defaultContentDatabaseFilename = contentDatabaseFilename;
228238
}
239+
240+
public File getProjectDir() {
241+
return projectDir;
242+
}
229243
}

src/main/java/com/marklogic/appdeployer/DefaultAppConfigFactory.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
public class DefaultAppConfigFactory extends PropertySourceFactory implements AppConfigFactory {
1313

14+
private File projectDir;
15+
1416
public DefaultAppConfigFactory() {
1517
super();
1618
initialize();
@@ -84,18 +86,19 @@ public void initialize() {
8486
logger.info("Config paths: " + prop);
8587
List<ConfigDir> list = new ArrayList<>();
8688
for (String path : prop.split(",")) {
87-
list.add(new ConfigDir(new File(path)));
89+
list.add(buildConfigDir(path));
8890
}
8991
config.setConfigDirs(list);
9092
});
93+
9194
// TODO Only process if mlConfigPaths not set?
9295
propertyConsumerMap.put("mlConfigDir", (config, prop) -> {
9396
logger.info("mlConfigDir is deprecated; please use mlConfigPath; Config dir: " + prop);
94-
config.setConfigDir(new ConfigDir(new File(prop)));
97+
config.setConfigDir(buildConfigDir(prop));
9598
});
9699
propertyConsumerMap.put("mlConfigPath", (config, prop) -> {
97100
logger.info("Config path: " + prop);
98-
config.setConfigDir(new ConfigDir(new File(prop)));
101+
config.setConfigDir(buildConfigDir(prop));
99102
});
100103

101104
/**
@@ -263,7 +266,8 @@ public void initialize() {
263266
*/
264267
propertyConsumerMap.put("mlSchemasPath", (config, prop) -> {
265268
logger.info("Schemas path: " + prop);
266-
config.setSchemasPath(prop);
269+
String path = this.projectDir != null ? new File(this.projectDir, prop).getAbsolutePath() : prop;
270+
config.setSchemasPath(path);
267271
});
268272

269273
propertyConsumerMap.put("mlSchemasDatabaseName", (config, prop) -> {
@@ -502,7 +506,8 @@ public void initialize() {
502506
// Ensure we have a modifiable list
503507
List<String> list = new ArrayList<>();
504508
for (String s : paths) {
505-
list.add(s);
509+
String path = this.projectDir != null ? new File(projectDir, s).getAbsolutePath() : s;
510+
list.add(path);
506511
}
507512
config.setModulePaths(list);
508513
});
@@ -662,7 +667,7 @@ public void initialize() {
662667

663668
@Override
664669
public AppConfig newAppConfig() {
665-
final AppConfig appConfig = new AppConfig();
670+
final AppConfig appConfig = new AppConfig(this.projectDir);
666671
for (String propertyName : propertyConsumerMap.keySet()) {
667672
String value = getProperty(propertyName);
668673
if (value != null) {
@@ -675,6 +680,11 @@ public AppConfig newAppConfig() {
675680
return appConfig;
676681
}
677682

683+
protected ConfigDir buildConfigDir(String path) {
684+
File baseDir = this.projectDir != null ? new File(this.projectDir, path) : new File(path);
685+
return new ConfigDir(baseDir);
686+
}
687+
678688
protected void setDefaultsForDatabasesWithForestsOnOneHost(AppConfig appConfig) {
679689
Set<String> set = appConfig.getDatabasesWithForestsOnOneHost();
680690
if (set == null || set.isEmpty()) {
@@ -725,4 +735,8 @@ protected Map<String, List<String>> buildMapOfListsFromDelimitedString(String st
725735
public Map<String, BiConsumer<AppConfig, String>> getPropertyConsumerMap() {
726736
return propertyConsumerMap;
727737
}
738+
739+
public void setProjectDir(File projectDir) {
740+
this.projectDir = projectDir;
741+
}
728742
}

src/test/java/com/marklogic/appdeployer/AbstractAppDeployerTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ public void initialize() {
3333
}
3434

3535
protected void initializeAppConfig() {
36-
appConfig = new AppConfig("src/test/resources/sample-app/src/main/ml-modules", "src/test/resources/sample-app/src/main/ml-schemas");
36+
appConfig = new AppConfig();
37+
appConfig.getModulePaths().clear();
38+
appConfig.getModulePaths().add("src/test/resources/sample-app/src/main/ml-modules");
39+
appConfig.setSchemasPath("src/test/resources/sample-app/src/main/ml-schemas");
40+
3741
appConfig.setName(SAMPLE_APP_NAME);
3842
appConfig.setRestPort(SAMPLE_APP_REST_PORT);
3943
ConfigDir configDir = new ConfigDir(new File("src/test/resources/sample-app/src/main/ml-config"));

0 commit comments

Comments
 (0)