Skip to content

Commit 1b5f369

Browse files
committed
#507 Creating transforms and resources in first valid module path
1 parent 6df9ed2 commit 1b5f369

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

examples/unit-test-project/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mlGradleVersion=3.15.2
1+
mlGradleVersion=3.16.3
22
marklogicUnitTestVersion=1.0.beta
33

44
mlHost=localhost
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.marklogic.gradle.task.client
2+
3+
import com.marklogic.gradle.task.MarkLogicTask
4+
5+
class AbstractModuleCreationTask extends MarkLogicTask{
6+
7+
/**
8+
* Select the first modules path that is a valid location for creating a new module. Intent is to filter out
9+
* paths containing "mlRestApi" or "mlBundle" as those almost certainly point to directories where bundles have been
10+
* unzipped to, and we don't want to create new modules in those directories.
11+
*
12+
* @return
13+
*/
14+
String selectModulesPath() {
15+
String path
16+
List<String> modulePaths = getAppConfig().getModulePaths()
17+
for (String modulePath : modulePaths) {
18+
if (modulePath != null && !modulePath.contains("mlRestApi") && !modulePath.contains("mlBundle")) {
19+
path = modulePath
20+
break
21+
}
22+
}
23+
24+
// Should never get here, but need to pick a path if we do
25+
if (path == null) {
26+
path = modulePaths.get(modulePaths.size() - 1)
27+
}
28+
29+
return path
30+
}
31+
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.gradle.api.tasks.TaskAction
44

55
import com.marklogic.gradle.task.MarkLogicTask
66

7-
class CreateResourceTask extends MarkLogicTask {
7+
class CreateResourceTask extends AbstractModuleCreationTask {
88

99
final static String SJS_RESOURCE_TEMPLATE =
1010
'''function get(context, params) {
@@ -92,11 +92,7 @@ declare function delete(
9292
if (getProject().hasProperty(propName)) {
9393
String servicesPath = servicesDir
9494
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. mlBundle paths
98-
servicesPath = modulePaths.get(modulePaths.size() - 1) + "/services"
99-
}
95+
servicesPath = selectModulesPath() + "/services"
10096
}
10197

10298
String name = getProject().getProperties().get(propName)

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.marklogic.gradle.task.client
33
import com.marklogic.gradle.task.MarkLogicTask
44
import org.gradle.api.tasks.TaskAction
55

6-
class CreateTransformTask extends MarkLogicTask {
6+
class CreateTransformTask extends AbstractModuleCreationTask {
77

88
final static String XQUERY_TEMPLATE = '''xquery version "1.0-ml";
99
@@ -54,11 +54,7 @@ exports.transform = transform;
5454
if (getProject().hasProperty(propName)) {
5555
String transformsPath = transformsDir
5656
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. mlBundle paths
60-
transformsPath = modulePaths.get(modulePaths.size() - 1) + "/transforms"
61-
}
57+
transformsPath = selectModulesPath() + "/transforms"
6258
}
6359

6460
String name = getProject().getProperties().get(propName)

0 commit comments

Comments
 (0)