Skip to content

Commit 92e71c9

Browse files
author
Rob Rudin
committed
#151 Can now write mlcp log output to a URI in ML
1 parent e6c7331 commit 92e71c9

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ examples/flexrep-project/.gradle/
2121
examples/sample-project/local.gradle
2222
examples/failover-project/.gradle/
2323
examples/mlcp-project/.gradle/
24+
examples/mlcp-project/build/
2425
examples/mlcp-project/data/export/
2526
examples/shell-project/.gradle/
2627
examples/shell-project/build/

examples/mlcp-project/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ buildscript {
1010
mavenLocal()
1111
}
1212
dependencies {
13-
classpath "com.marklogic:ml-gradle:2.5.0"
13+
classpath "com.marklogic:ml-gradle:2.6.0"
1414
}
1515
}
1616

@@ -71,6 +71,11 @@ task importSampleData(type: com.marklogic.gradle.task.MlcpTask) {
7171
output_collections = "sample-import"
7272
output_permissions = "rest-reader,read,rest-writer,update"
7373
output_uri_replace = ".*import,'/import'"
74+
/**
75+
* New in ml-gradle 2.6.0 - set this to define a URI in your content database for mlcp's log output to be written to
76+
* as a text document. This can also be a variable, Gradle property, etc.
77+
*/
78+
logOutputUri = "/slappy.txt"
7479
}
7580

7681
/**

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.marklogic.gradle.task
22

3+
import com.marklogic.client.DatabaseClient
4+
import com.marklogic.client.io.FileHandle
35
import com.marklogic.contentpump.bean.MlcpBean
46
import org.gradle.api.logging.Logger
57
import org.gradle.api.logging.Logging
@@ -23,13 +25,16 @@ class MlcpTask extends JavaExec {
2325
@Delegate
2426
MlcpBean mlcpBean = new MlcpBean();
2527

26-
public Logger getLogger() {
28+
// Set this to define a URI in your content database for mlcp output to be written to as a text document
29+
String logOutputUri
30+
31+
Logger getLogger() {
2732
return Logging.getLogger(MlcpTask.class)
2833
}
2934

3035
@TaskAction
3136
@Override
32-
public void exec() {
37+
void exec() {
3338
setMain("com.marklogic.contentpump.ContentPump")
3439
AppConfig config = getProject().property("mlAppConfig")
3540

@@ -91,6 +96,20 @@ class MlcpTask extends JavaExec {
9196

9297
setArgs(newArgs)
9398

99+
File logOutputFile = null
100+
if (logOutputUri) {
101+
println "Will write mlcp log output to URI: " + logOutputUri
102+
logOutputFile = new File(getProject().getBuildDir(), "mlcp-log-output-" + System.currentTimeMillis() + ".txt")
103+
setStandardOutput(logOutputFile.newOutputStream())
104+
}
105+
94106
super.exec()
107+
108+
if (logOutputFile != null) {
109+
AppConfig appConfig = project.property("mlAppConfig")
110+
DatabaseClient client = appConfig.newDatabaseClient()
111+
client.newDocumentManager().write(logOutputUri, new FileHandle(logOutputFile))
112+
println "Wrote mlcp log output to URI: " + logOutputUri
113+
}
95114
}
96115
}

0 commit comments

Comments
 (0)