Skip to content

Commit b9af432

Browse files
committed
#448 Now supports multiple schema paths, including those from mlBundles
1 parent 3e0cf1d commit b9af432

File tree

10 files changed

+95
-8
lines changed

10 files changed

+95
-8
lines changed

examples/dependency-project/README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
This set of projects demonstrates:
22

3-
- How a "provider" project can publish a zip of MarkLogic modules and data
4-
- How an ml-gradle or DHF project can depend on this zip so that the modules and data are automatically included
3+
- How a "provider" project can publish a zip of MarkLogic files (modules, data, schemas, or system plugins)
4+
- How an ml-gradle or DHF project can depend on this zip so that the files are automatically included
55
in an application
66

77
## Publishing the provider
@@ -31,7 +31,8 @@ Found mlBundle configuration, will extract all of its dependencies to build/mlBu
3131
Finished extracting mlBundle dependencies
3232
Module paths including mlBundle paths: [/Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/build/mlBundle/example-dependency/ml-modules, /Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/src/main/ml-modules]
3333
Data paths including mlBundle paths: [/Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/build/mlBundle/example-dependency/ml-data, /Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/src/main/ml-data]
34-
Plugin paths include mlBundle paths: [/Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/build/mlBundle/example-dependency/ml-plugins, /Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/src/main/ml-plugins]
34+
Plugin paths including mlBundle paths: [/Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/build/mlBundle/example-dependency/ml-plugins, /Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/src/main/ml-plugins]
35+
Schema paths including mlBundle paths: [/Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/build/mlBundle/example-dependency/ml-schemas, /Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/src/main/ml-schemas]
3536
:mlPrepareBundles (Thread[Task worker for ':',5,main]) completed. Took 0.059 secs.
3637
```
3738

@@ -68,9 +69,24 @@ Installed plugin with scope 'native', result: 1
6869
Finished executing command [com.marklogic.appdeployer.command.plugins.InstallPluginsCommand]
6970
```
7071

72+
And finally, some logging like this that indicates that schemas were loaded:
73+
74+
```
75+
Executing command [com.marklogic.appdeployer.command.schemas.LoadSchemasCommand] with sort order [350]
76+
Loading schemas into database ml-gradle-client-schemas from: /Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/build/mlBundle/example-dependency/ml-schemas
77+
TDE templates loaded into ml-gradle-client-schemas will be validated against content database ml-gradle-client-content
78+
Initializing ExecutorService
79+
TDE template passed validation: /Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/build/mlBundle/example-dependency/ml-schemas/tde/template1.json
80+
Writing 1 files
81+
Writing: /tde/template1.json
82+
Shutting down ExecutorService
83+
Writing 1 documents to MarkLogic; port: 8000; database: ml-gradle-client-schemas
84+
```
85+
7186
You can then use qconsole to verify that the following documents were inserted:
7287

73-
- In ml-gradle-client-modules: /example.sjs
88+
- In ml-gradle-client-modules: /example.sjs (in addition to the modules included by this project: /my-lib.xqy and /Default/ml-gradle-client/rest-api/properties.xml)
89+
- In ml-gradle-client-schemas: /tde/template1.json (in addition to the schema file included in this project: /tde/my-template.json)
7490
- In ml-gradle-client-content: /example/data1.json and /example/data2.json (in addition to the data files including
7591
in this project: /testdata/test1.json, /testdata/test2.json, and /testdata/test3.json)
7692
- In Extensions: /native/scope.xml, /native/varianceplugin/libvarianceplugin.dylib, and /native/varianceplugin/manifest.xml

examples/dependency-project/ml-gradle-client-project/src/main/ml-config/databases/content-database.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"database-name": "%%DATABASE%%",
3+
"schema-database": "%%SCHEMAS_DATABASE%%",
34
"range-element-index": [
45
{
56
"collation": "",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"database-name": "%%SCHEMAS_DATABASE%%"
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<test/>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"template": {
3+
"context": "/data",
4+
"collections": [
5+
"data"
6+
],
7+
"rows": [
8+
{
9+
"schemaName": "Data",
10+
"viewName": "default",
11+
"columns": [
12+
{
13+
"name": "Id",
14+
"scalarType": "string",
15+
"val": "Id"
16+
}
17+
]
18+
}
19+
]
20+
}
21+
}

examples/dependency-project/provider-project/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ task bundleJar(type: Jar) {
1919
from("src/main/ml-plugins") {
2020
into("example-dependency/ml-plugins")
2121
}
22+
from("src/main/ml-schemas") {
23+
into("example-dependency/ml-schemas")
24+
}
2225
destinationDir file("build/libs")
2326
baseName "example-dependency"
2427
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"template": {
3+
"context": "/example",
4+
"collections": [
5+
"example"
6+
],
7+
"rows": [
8+
{
9+
"schemaName": "Example",
10+
"viewName": "default",
11+
"columns": [
12+
{
13+
"name": "Id",
14+
"scalarType": "string",
15+
"val": "Id"
16+
}
17+
]
18+
}
19+
]
20+
}
21+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ class MarkLogicPlugin implements Plugin<Project> {
242242

243243
String schemasGroup = "ml-gradle Schemas"
244244
project.task("mlDeleteUserSchemas", type: DeleteUserSchemasTask, group: schemasGroup, description: "Delete documents in a schemas database that were not created via the deployment of resources such as temporal collections or view schemas")
245-
project.task("mlLoadSchemas", type: LoadSchemasTask, group: schemasGroup, description: "Loads special-purpose data into the schemas database (XSD schemas, Inference rules, and [MarkLogic 9] Extraction Templates)").mustRunAfter("mlDeleteUserSchemas")
245+
project.task("mlLoadSchemas", type: LoadSchemasTask, group: schemasGroup, dependsOn: "mlPrepareBundles",
246+
description: "Loads files into schema databases, including schema files that are part of mlBundle dependencies").mustRunAfter("mlDeleteUserSchemas")
246247
project.task("mlReloadSchemas", dependsOn: ["mlDeleteUserSchemas", "mlLoadSchemas"], group: schemasGroup, description: "Deletes user schemas via mlDeleteUserSchemas and then loads schemas via mlLoadSchemas")
247248

248249
String serverGroup = "ml-gradle Server"

src/main/groovy/com/marklogic/gradle/task/PreviewDeployTask.groovy

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,15 @@ class PreviewDeployTask extends DeployAppTask {
3434
// Disable loading of any modules
3535
getAppConfig().setModulePaths(new ArrayList<String>())
3636

37-
// Disable loading of schemas from the default path
37+
// Disable loading of schemas
3838
// Database-specific schema paths are handled by removing instances of LoadSchemasCommand
39-
getAppConfig().setSchemasPath(null)
39+
getAppConfig().setSchemaPaths(null)
40+
41+
// Disable loading of data
42+
getAppConfig().getDataConfig().setDataPaths(null)
43+
44+
// Disable installing of plugins
45+
getAppConfig().getPluginConfig().setPluginPaths(null)
4046
}
4147

4248
void modifyAppDeployerBeforePreview() {

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class PrepareBundlesTask extends MarkLogicTask {
5454
List<String> pluginPaths = getAppConfig().getPluginConfig().getPluginPaths()
5555
List<String> newPluginPaths = new ArrayList<>()
5656

57+
List<String> schemaPaths = getAppConfig().getSchemaPaths()
58+
List<String> newSchemaPaths = new ArrayList<>()
59+
5760
for (dir in buildDir.listFiles()) {
5861
if (dir.isDirectory()) {
5962
File modulesDir = new File(dir, "ml-modules")
@@ -70,6 +73,11 @@ class PrepareBundlesTask extends MarkLogicTask {
7073
if (pluginsDir != null && pluginsDir.exists()) {
7174
newPluginPaths.add(pluginsDir.getAbsolutePath())
7275
}
76+
77+
File schemasDir = new File(dir, "ml-schemas")
78+
if (schemasDir != null && schemasDir.exists()) {
79+
newSchemaPaths.add(schemasDir.getAbsolutePath())
80+
}
7381
}
7482
}
7583

@@ -91,7 +99,13 @@ class PrepareBundlesTask extends MarkLogicTask {
9199
if (!newPluginPaths.isEmpty()) {
92100
newPluginPaths.addAll(pluginPaths)
93101
getAppConfig().getPluginConfig().setPluginPaths(newPluginPaths)
94-
println "Plugin paths include mlBundle paths: " + getAppConfig().getPluginConfig().getPluginPaths()
102+
println "Plugin paths including mlBundle paths: " + getAppConfig().getPluginConfig().getPluginPaths()
103+
}
104+
105+
if (!newSchemaPaths.isEmpty()) {
106+
newSchemaPaths.addAll(schemaPaths)
107+
getAppConfig().setSchemaPaths(newSchemaPaths)
108+
println "Schema paths including mlBundle paths: " + getAppConfig().getSchemaPaths()
95109
}
96110
}
97111
}

0 commit comments

Comments
 (0)