Skip to content

Commit fb1a852

Browse files
committed
#428 Now setting the Gradle projectDir on the AppConfig object
This allows ml-gradle to work with Java 11 and the Gradle daemon, as paths in AppConfig are now constructed relative to the projectDir. While testing CreateResource/CreateTransform, also made a little fix so that the last module path is used when writing out a file. This avoids a problem where the files could be written to e.g. mlRestApi paths.
1 parent cf5509b commit fb1a852

File tree

6 files changed

+46
-15
lines changed

6 files changed

+46
-15
lines changed

examples/sample-project/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ dependencies {
5858
testCompile "com.marklogic:ml-junit:3.0.0"
5959
testCompile "com.jayway.restassured:rest-assured:2.4.1"
6060

61+
// Required for Java 11
62+
testRuntime "javax.xml.bind:jaxb-api:2.3.1"
63+
testRuntime "com.sun.xml.bind:jaxb-core:2.3.0.1"
64+
testRuntime "com.sun.xml.bind:jaxb-impl:2.3.2"
65+
6166
// corb jar available from jcenter
6267
corb "com.marklogic:marklogic-corb:2.3.2"
6368
}

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
group=com.marklogic
2-
version=3.11.0
2+
version=3.12.dev
33
javadocsDir=../gh-pages-marklogic-java/javadocs
44

5-
mlAppDeployerDependency=com.marklogic:ml-app-deployer:3.11.0
5+
mlAppDeployerDependency=com.marklogic:ml-app-deployer:3.12.dev
66
mlcpUtilDependency=com.marklogic:mlcp-util:0.9.0
77
mlDataMovementDependency=com.marklogic:marklogic-data-movement-components:1.1
88
mlUnitTestDependency=com.marklogic:marklogic-unit-test-client:0.12.0

src/main/groovy/com/marklogic/gradle/MarkLogicPlugin.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,17 @@ class MarkLogicPlugin implements Plugin<Project> {
345345
project.extensions.add("mlAdminConfig", adminConfig)
346346

347347
ProjectPropertySource propertySource = new ProjectPropertySource(project);
348+
348349
DefaultAppConfigFactory appConfigFactory = new DefaultAppConfigFactory(propertySource)
350+
// The ConfigDir objects constructed by AppConfig must all be relative to the project directory
351+
// when using Java 11. In case this causes problems, a user can disable this via the below property
352+
if ("true".equals(project.property("mlIgnoreProjectDir"))) {
353+
println "The Gradle projectDir will not be used to resolve file paths"
354+
} else {
355+
appConfigFactory.setProjectDir(project.getProjectDir())
356+
}
349357
project.extensions.add("mlAppConfigFactory", appConfigFactory)
358+
350359
AppConfig appConfig = appConfigFactory.newAppConfig()
351360
project.extensions.add("mlAppConfig", appConfig)
352361

src/main/groovy/com/marklogic/gradle/task/client/CreateResourceTask.groovy

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,15 @@ declare function delete(
9090
void createResource() {
9191
String propName = "resourceName"
9292
if (getProject().hasProperty(propName)) {
93-
servicesDir = servicesDir ? servicesDir : getAppConfig().getModulePaths().get(0) + "/services"
94-
93+
String servicesPath = servicesDir
94+
if (!servicesPath) {
95+
List<String> modulePaths = getAppConfig().getModulePaths()
96+
if (modulePaths != null && !modulePaths.isEmpty()) {
97+
// Use the last path so modules aren't written to e.g. mlRestApi paths
98+
servicesPath = modulePaths.get(modulePaths.size() - 1) + "/services"
99+
}
100+
}
101+
95102
String name = getProject().getProperties().get(propName)
96103

97104
String template = RESOURCE_TEMPLATE
@@ -102,12 +109,12 @@ declare function delete(
102109
}
103110

104111
String resource = template.replace("%%RESOURCE_NAME%%", name)
105-
new File(servicesDir).mkdirs()
106-
def resourceFile = new File(servicesDir, name + fileExtension)
112+
new File(servicesPath).mkdirs()
113+
def resourceFile = new File(servicesPath, name + fileExtension)
107114
println "Creating new resource at " + resourceFile.getAbsolutePath()
108115
resourceFile.write(resource)
109116

110-
def metadataDir = new File(servicesDir, "metadata")
117+
def metadataDir = new File(servicesPath, "metadata")
111118
metadataDir.mkdirs()
112119
String metadata = METADATA_TEMPLATE.replace("%%RESOURCE_NAME%%", name)
113120
def metadataFile = new File(metadataDir, name + ".xml")

src/main/groovy/com/marklogic/gradle/task/client/CreateTransformTask.groovy

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.marklogic.gradle.task.client
22

3-
import org.gradle.api.DefaultTask;
4-
import org.gradle.api.tasks.TaskAction;
5-
6-
import com.marklogic.gradle.task.MarkLogicTask;
3+
import com.marklogic.gradle.task.MarkLogicTask
4+
import org.gradle.api.tasks.TaskAction
75

86
class CreateTransformTask extends MarkLogicTask {
97

@@ -54,7 +52,14 @@ exports.transform = transform;
5452
void createResource() {
5553
String propName = "transformName"
5654
if (getProject().hasProperty(propName)) {
57-
transformsDir = transformsDir ? transformsDir : getAppConfig().getModulePaths().get(0) + "/transforms"
55+
String transformsPath = transformsDir
56+
if (!transformsPath) {
57+
List<String> modulePaths = getAppConfig().getModulePaths()
58+
if (modulePaths != null && !modulePaths.isEmpty()) {
59+
// Use the last path so modules aren't written to e.g. mlRestApi paths
60+
transformsPath = modulePaths.get(modulePaths.size() - 1) + "/transforms"
61+
}
62+
}
5863

5964
String name = getProject().getProperties().get(propName)
6065

@@ -76,12 +81,12 @@ exports.transform = transform;
7681

7782
String transform = template.replace("%%TRANSFORM_NAME%%", name)
7883

79-
new File(transformsDir).mkdirs()
80-
def transformFile = new File(transformsDir, name + fileExtension)
84+
new File(transformsPath).mkdirs()
85+
def transformFile = new File(transformsPath, name + fileExtension)
8186
println "Creating new transform at " + transformFile.getAbsolutePath()
8287
transformFile.write(transform)
8388

84-
def metadataDir = new File(transformsDir, "metadata")
89+
def metadataDir = new File(transformsPath, "metadata")
8590
metadataDir.mkdirs()
8691
String metadata = METADATA_TEMPLATE.replace("%%TRANSFORM_NAME%%", name)
8792
def metadataFile = new File(metadataDir, name + ".xml")

src/main/groovy/com/marklogic/gradle/task/export/ExportResourcesTask.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ class ExportResourcesTask extends MarkLogicTask {
5252
void export(ResourceSelector selector) {
5353
def path = getAppConfig().getConfigDir().getBaseDir()
5454
if (getProject().hasProperty("exportPath")) {
55+
/**
56+
* Note that if a user provides a path and they're using Java 11 and the Gradle daemon, then the path
57+
* should be absolute. Otherwise, it will be resolved from the directory that the daemon was launched
58+
* from, which is likely not desirable.
59+
*/
5560
path = new File(getProject().property("exportPath"))
5661
}
5762
println "Exporting resources to: " + path

0 commit comments

Comments
 (0)