11package com.marklogic.gradle.task
22
3+ import com.marklogic.contentpump.bean.MlcpBean
4+ import org.gradle.api.logging.Logger
5+ import org.gradle.api.logging.Logging
36import org.gradle.api.tasks.JavaExec
47import org.gradle.api.tasks.TaskAction
58
69import com.marklogic.appdeployer.AppConfig
710
11+
812/**
913 * Provides parameters for some, but not all, mlcp arguments. Arguments that aren't supported can be passed in
1014 * via JavaExec's "args" property. The main benefit of using this class is that it assumes usage of the connection
@@ -16,32 +20,12 @@ import com.marklogic.appdeployer.AppConfig
1620 */
1721class MlcpTask extends JavaExec {
1822
19- String host
20- Integer port = 8000
21- String username
22- String password
23- String database
24-
25- String command
26- String input_file_path
27- String input_file_type
28- String input_file_pattern
29- String input_compressed
30- String document_type
31- String output_collections
32- String delimited_root_name
33- String delimited_uri_id
34- String namespace
35- String options_file
36- String output_file_path
37- String output_uri_prefix
38- String output_uri_replace
39- String output_permissions
40- String transform_module
41- String transform_namespace
42- String transform_param
43- String thread_count
44-
23+ @Delegate MlcpBean mlcpBean = new MlcpBean ();
24+
25+ public Logger getLogger () {
26+ return Logging . getLogger(MlcpTask . class)
27+ }
28+
4529 @TaskAction
4630 @Override
4731 public void exec () {
@@ -50,92 +34,33 @@ class MlcpTask extends JavaExec {
5034
5135 List<String > newArgs = new ArrayList<> ()
5236 newArgs. add(command)
53- newArgs. add(" -host" )
54- newArgs. add(host ? host : config. getHost())
55- newArgs. add(" -port" )
56- newArgs. add(port)
57- newArgs. add(" -username" )
58- newArgs. add(username ? username : config. getRestAdminUsername())
59-
60- if (database) {
61- newArgs. add(" -database" )
62- newArgs. add(database)
63- }
64- if (input_file_path) {
65- newArgs. add(" -input_file_path" )
66- newArgs. add(input_file_path)
67- }
68- if (input_file_type) {
69- newArgs. add(" -input_file_type" )
70- newArgs. add(input_file_type)
71- }
72- if (input_file_pattern) {
73- newArgs. add(" -input_file_pattern" )
74- newArgs. add(input_file_pattern)
75- }
76- if (input_compressed) {
77- newArgs. add(" -input_compressed" )
78- newArgs. add(input_compressed)
79- }
80- if (document_type) {
81- newArgs. add(" -document_type" )
82- newArgs. add(document_type)
83- }
84- if (output_collections) {
85- newArgs. add(" -output_collections" )
86- newArgs. add(output_collections)
87- }
88- if (delimited_root_name) {
89- newArgs. add(" -delimited_root_name" )
90- newArgs. add(delimited_root_name)
91- }
92- if (delimited_uri_id) {
93- newArgs. add(" -delimited_uri_id" )
94- newArgs. add(delimited_uri_id)
95- }
96- if (namespace) {
97- newArgs. add(" -namespace" )
98- newArgs. add(namespace)
99- }
100- if (options_file) {
101- newArgs. add(" -options_file" )
102- newArgs. add(options_file)
103- }
104- if (output_file_path) {
105- newArgs. add(" -output_file_path" )
106- newArgs. add(output_file_path)
107- }
108- if (output_uri_prefix) {
109- newArgs. add(" -output_uri_prefix" )
110- newArgs. add(output_uri_prefix)
111- }
112- if (output_uri_replace) {
113- newArgs. add(" -output_uri_replace" )
114- newArgs. add(output_uri_replace)
115- }
116- if (output_permissions) {
117- newArgs. add(" -output_permissions" )
118- newArgs. add(output_permissions)
119- }
120- if (transform_module) {
121- newArgs. add(" -transform_module" )
122- newArgs. add(transform_module)
123- }
124- if (transform_namespace) {
125- newArgs. add(" -transform_namespace" )
126- newArgs. add(transform_namespace)
127- }
128- if (transform_param) {
129- newArgs. add(" -transform_param" )
130- newArgs. add(transform_param)
131- }
132- if (thread_count) {
133- newArgs. add(" -thread_count" )
134- newArgs. add(thread_count)
37+
38+ mlcpBean. properties. each { prop , val ->
39+ def propVal
40+ if (val) {
41+ switch (prop) {
42+ case " host" :
43+ propVal = (val ? val : config. getHost())
44+ break
45+ case " port" :
46+ propVal = (val ? val : 8000 )
47+ break
48+ case " username" :
49+ propVal = (val ? val : config. getRestAdminUsername())
50+ break
51+ case [" class" , " logger" , " command" , " password" ]:
52+ // skip for now
53+ return
54+ default :
55+ propVal = val
56+ break
57+ }
58+
59+ newArgs. add(" -" + prop);
60+ newArgs. add(String . valueOf(propVal));
61+ }
13562 }
136-
137- newArgs. addAll(getArgs())
138-
63+
13964 println " mlcp arguments, excluding password: " + newArgs
14065
14166 newArgs. add(" -password" )
0 commit comments