Skip to content

Commit 10884fd

Browse files
committed
#595 Reworked MlcpTask so that it works on Gradle 7
Had to effectively duplicate all the properties in MlcpBean since @DeleGate won't work in Gradle 7.
1 parent ebb7b56 commit 10884fd

File tree

6 files changed

+227
-41
lines changed

6 files changed

+227
-41
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ Groovy - ml-gradle is then a fairly thin wrapper around ml-app-deployer to expos
2626
Start using ml-gradle
2727
=========
2828

29-
ml-gradle depends on at least [Java 9](https://java.com/en/download/) and [MarkLogic 9 or 10](https://developer.marklogic.com/products),
29+
ml-gradle depends on at least [Java 8](https://java.com/en/download/) and [MarkLogic 9 or 10](https://developer.marklogic.com/products),
3030
so if you have those installed, you're just a couple minutes away from using ml-gradle to start a new project and deploy an
31-
application from it. If you're using ml-gradle 2.x or 3.x, you only need Java 8.
31+
application from it.
3232

33-
First, [install Gradle](https://gradle.org/install/).
33+
First, [install Gradle](https://gradle.org/install/) - it is recommended to use the latest version, though note that
34+
ml-gradle 4.3.0 is the first version that can run on Gradle 7.
3435

3536
Then, in an empty directory, create a file named "build.gradle" with your favorite text editor and enter the following:
3637

examples/flexrep-with-path-project/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
buildscript {
22
repositories {
3-
mavenCentral
3+
mavenCentral()
44
mavenLocal()
55
}
66
dependencies {

examples/mlcp-project/build.gradle

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,23 @@
44
* JavaExec task that exposes mlcp arguments as task attributes.
55
*/
66

7-
plugins {
8-
id "com.marklogic.ml-gradle" version "4.3.0"
7+
buildscript {
8+
repositories {
9+
mavenLocal()
10+
mavenCentral()
11+
}
12+
dependencies {
13+
classpath "com.marklogic:ml-gradle:4.3.1-SNAPSHOT"
14+
}
915
}
1016

17+
apply plugin: "com.marklogic.ml-gradle"
18+
1119
repositories {
12-
mavenCentral
20+
mavenCentral()
1321

1422
// Needed for some mlcp dependencies, such as commons-csv:1.5.1-marklogic
15-
maven { url "http://developer.marklogic.com/maven2/" }
23+
maven { url "https://developer.marklogic.com/maven2/" }
1624
}
1725

1826

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mlHost=localhost
22
mlAppName=mlcp-project
3-
mlRestPort=8130
3+
mlRestPort=8003
44
mlUsername=admin
55
mlPassword=admin
66
mlContentForestsPerHost=1

examples/mlcp-project/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip

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

Lines changed: 208 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,142 @@
11
package com.marklogic.gradle.task
22

3+
import com.marklogic.appdeployer.AppConfig
34
import com.marklogic.client.DatabaseClient
45
import com.marklogic.client.io.FileHandle
56
import com.marklogic.contentpump.bean.MlcpBean
67
import org.gradle.api.Task
78
import org.gradle.api.logging.Logger
89
import org.gradle.api.logging.Logging
910
import org.gradle.api.tasks.Input
11+
import org.gradle.api.tasks.Internal
1012
import org.gradle.api.tasks.JavaExec
1113
import org.gradle.api.tasks.Optional
1214
import org.gradle.api.tasks.TaskAction
1315

14-
import com.marklogic.appdeployer.AppConfig
15-
16-
1716
/**
18-
* Delegates properties to an instance of MlcpBean, which has properties for all MLCP arguments (and if it's out of date
19-
* and missing one, you can pass them via this class's args property that's inherited from JavaExec). This task
20-
* will also default the host/port to the values defined in the mlAppConfig instance populated by the plugin.
17+
* As of version 4.3.1, this no longer uses "@Delegate" and an instance of MlcpBean, which no longer works in Gradle 7.
18+
* See issue #595 for more details.
19+
*
20+
* Instead, this task now has each property that MlcpBean has. And when the task is run, each property is copied onto
21+
* an instance of MlcpBean, and the task otherwise functions the same as it used to. This of course makes little reuse
22+
* of MlcpBean, but it's not clear how to do that anymore in Gradle 7.
2123
*
2224
* Note that this defaults to using appConfig.restAdminUsername and appConfig.restAdminPassword. That user may not
2325
* have permission to perform the mlcp operation you wish to perform. In that case, just set the username/password
2426
* parameters of this task for the appropriate user.
2527
*/
2628
class MlcpTask extends JavaExec {
2729

28-
// This isn't yet working on Gradle 7; see https://github.com/marklogic-community/ml-gradle/issues/595
29-
@Input
30-
@Delegate
31-
MlcpBean mlcpBean = new MlcpBean();
30+
@Input String command = "IMPORT"
31+
@Input @Optional String host
32+
@Input @Optional Integer port
33+
@Input @Optional String username
34+
@Input @Optional String password
35+
@Input @Optional String database
36+
@Input @Optional String input_host
37+
@Input @Optional Integer input_port
38+
@Input @Optional String input_username
39+
@Input @Optional String input_password
40+
@Input @Optional String input_database
41+
@Input @Optional String output_host
42+
@Input @Optional Integer output_port
43+
@Input @Optional String output_username
44+
@Input @Optional String output_password
45+
@Input @Optional String output_database
46+
@Input @Optional String aggregate_record_element
47+
@Input @Optional String aggregate_record_namespace
48+
@Input @Optional Boolean archive_metadata_optional
49+
@Input @Optional Integer batch_size
50+
@Input @Optional String collection_filter
51+
@Input @Optional Boolean compress
52+
@Input @Optional String conf
53+
@Input @Optional String content_encoding
54+
@Input @Optional String copy_collections
55+
@Input @Optional String copy_metadata
56+
@Input @Optional String copy_permissions
57+
@Input @Optional String copy_properties
58+
@Input @Optional String copy_quality
59+
@Input @Optional String data_type
60+
@Input @Optional String delimiter
61+
@Input @Optional String delimited_root_name
62+
@Input @Optional String directory_filter
63+
@Input @Optional String document_selector
64+
@Input @Optional String document_type
65+
@Input @Optional Boolean fastload
66+
@Input @Optional String filename_as_collection
67+
@Input @Optional Boolean generate_uri
68+
@Input @Optional String hadoop_conf_dir
69+
@Input @Optional Boolean indented
70+
@Input @Optional Boolean input_compressed
71+
@Input @Optional String input_compression_codec
72+
@Input @Optional String input_file_path
73+
@Input @Optional String input_file_pattern
74+
@Input @Optional String input_file_type
75+
@Input @Optional Boolean input_ssl
76+
@Input @Optional Integer max_split_size
77+
@Input @Optional Integer min_split_size
78+
@Input @Optional String mode
79+
@Input @Optional String modules
80+
@Input @Optional String modules_root
81+
@Input @Optional String namespace
82+
@Input @Optional String options_file
83+
@Input @Optional Boolean output_cleandir
84+
@Input @Optional String output_collections
85+
@Input @Optional String output_directory
86+
@Input @Optional String output_file_path
87+
@Input @Optional String output_graph
88+
@Input @Optional String output_language
89+
@Input @Optional String output_override_graph
90+
@Input @Optional String output_partition
91+
@Input @Optional String output_permissions
92+
@Input @Optional String output_quality
93+
@Input @Optional Boolean output_ssl
94+
@Input @Optional String output_type
95+
@Input @Optional String output_uri_prefix
96+
@Input @Optional String output_uri_replace
97+
@Input @Optional String output_uri_suffix
98+
@Input @Optional String path_namespace
99+
@Input @Optional String query_filter
100+
@Input @Optional String redaction
101+
@Input @Optional Boolean restrict_hosts
102+
@Input @Optional Boolean restrict_input_hosts
103+
@Input @Optional Boolean restrict_output_hosts
104+
@Input @Optional String sequencefile_key_class
105+
@Input @Optional String sequencefile_value_class
106+
@Input @Optional String sequencefile_value_type
107+
@Input @Optional Boolean snapshot
108+
@Input @Optional Boolean split_input
109+
@Input @Optional Boolean ssl
110+
@Input @Optional Boolean streaming
111+
@Input @Optional String temporal_collection
112+
@Input @Optional Integer thread_count
113+
@Input @Optional Integer thread_count_per_split
114+
@Input @Optional Boolean tolerate_errors
115+
@Input @Optional String transform_function
116+
@Input @Optional String transform_module
117+
@Input @Optional String transform_namespace
118+
@Input @Optional String transform_param
119+
@Input @Optional Integer transaction_size
120+
@Input @Optional String type_filter
121+
@Input @Optional String uri_id
122+
@Input @Optional String xml_repair_level
32123

33124
// Set this to define a URI in your content database for mlcp output to be written to as a text document
34-
@Input
35-
@Optional
36-
String logOutputUri
125+
@Input @Optional String logOutputUri
37126

38127
// Allow the user to provide a custom DatabaseClient for logging mlcp output
39-
@Input
40-
@Optional
41-
DatabaseClient logClient
128+
@Input @Optional DatabaseClient logClient
42129

130+
@Override @Internal
43131
Logger getLogger() {
44132
return Logging.getLogger(MlcpTask.class)
45133
}
46134

47-
MlcpTask() {
48-
mainClass.set("com.marklogic.contentpump.ContentPump")
135+
// Starting in Gradle 6.4, setMain must be called here instead of in a TaskAction method
136+
@Override
137+
Task configure(Closure closure) {
138+
setMain("com.marklogic.contentpump.ContentPump")
139+
return super.configure(closure)
49140
}
50141

51142
@TaskAction
@@ -56,24 +147,15 @@ class MlcpTask extends JavaExec {
56147
List<String> newArgs = new ArrayList<>()
57148
newArgs.add(command)
58149

150+
MlcpBean mlcpBean = new MlcpBean()
151+
applyTaskPropertiesToMlcpBean(mlcpBean)
152+
59153
mlcpBean.properties.each { prop, val ->
60154
def propVal
61155
if (val) {
62156
switch (prop) {
63-
case "host":
64-
propVal = (val ? val : config.getHost())
65-
break
66-
case "port":
67-
propVal = (val ? val : 8000)
68-
break
69-
case "username":
70-
propVal = (val ? val : config.getRestAdminUsername())
71-
break
72157
case ["class", "logger", "command", "password"]:
73-
// skip for now
74-
return
75-
case "additionalOptions":
76-
// Not supported by this task; use JavaExec's args instead
158+
// skip, as these aren't MLCP key/value args, and we don't want password to be shown below
77159
return
78160
default:
79161
propVal = val
@@ -145,4 +227,99 @@ class MlcpTask extends JavaExec {
145227
println "Wrote mlcp log output to URI: " + logOutputUri
146228
}
147229
}
230+
231+
void applyTaskPropertiesToMlcpBean(MlcpBean mlcpBean) {
232+
mlcpBean.setHost(host)
233+
mlcpBean.setPort(port)
234+
mlcpBean.setUsername(username)
235+
mlcpBean.setPassword(password)
236+
mlcpBean.setDatabase(database)
237+
mlcpBean.setInput_host(input_host)
238+
mlcpBean.setInput_port(input_port)
239+
mlcpBean.setInput_username(input_username)
240+
mlcpBean.setInput_password(input_password)
241+
mlcpBean.setInput_database(input_database)
242+
mlcpBean.setOutput_host(output_host)
243+
mlcpBean.setOutput_port(output_port)
244+
mlcpBean.setOutput_username(output_username)
245+
mlcpBean.setOutput_password(output_password)
246+
mlcpBean.setOutput_database(output_database)
247+
mlcpBean.setAggregate_record_element(aggregate_record_element)
248+
mlcpBean.setAggregate_record_namespace(aggregate_record_namespace)
249+
mlcpBean.setArchive_metadata_optional(archive_metadata_optional)
250+
mlcpBean.setBatch_size(batch_size)
251+
mlcpBean.setCollection_filter(collection_filter)
252+
mlcpBean.setCompress(compress)
253+
mlcpBean.setConf(conf)
254+
mlcpBean.setContent_encoding(content_encoding)
255+
mlcpBean.setCopy_collections(copy_collections)
256+
mlcpBean.setCopy_metadata(copy_metadata)
257+
mlcpBean.setCopy_permissions(copy_permissions)
258+
mlcpBean.setCopy_properties(copy_properties)
259+
mlcpBean.setCopy_quality(copy_quality)
260+
mlcpBean.setData_type(data_type)
261+
mlcpBean.setDelimiter(delimiter)
262+
mlcpBean.setDelimited_root_name(delimited_root_name)
263+
mlcpBean.setDirectory_filter(directory_filter)
264+
mlcpBean.setDocument_selector(document_selector)
265+
mlcpBean.setDocument_type(document_type)
266+
mlcpBean.setFastload(fastload)
267+
mlcpBean.setFilename_as_collection(filename_as_collection)
268+
mlcpBean.setGenerate_uri(generate_uri)
269+
mlcpBean.setHadoop_conf_dir(hadoop_conf_dir)
270+
mlcpBean.setIndented(indented)
271+
mlcpBean.setInput_compressed(input_compressed)
272+
mlcpBean.setInput_compression_codec(input_compression_codec)
273+
mlcpBean.setInput_file_path(input_file_path)
274+
mlcpBean.setInput_file_pattern(input_file_pattern)
275+
mlcpBean.setInput_file_type(input_file_type)
276+
mlcpBean.setInput_ssl(input_ssl)
277+
mlcpBean.setMax_split_size(max_split_size)
278+
mlcpBean.setMin_split_size(min_split_size)
279+
mlcpBean.setMode(mode)
280+
mlcpBean.setModules(modules)
281+
mlcpBean.setModules_root(modules_root)
282+
mlcpBean.setNamespace(namespace)
283+
mlcpBean.setOptions_file(options_file)
284+
mlcpBean.setOutput_cleandir(output_cleandir)
285+
mlcpBean.setOutput_collections(output_collections)
286+
mlcpBean.setOutput_directory(output_directory)
287+
mlcpBean.setOutput_file_path(output_file_path)
288+
mlcpBean.setOutput_graph(output_graph)
289+
mlcpBean.setOutput_language(output_language)
290+
mlcpBean.setOutput_override_graph(output_override_graph)
291+
mlcpBean.setOutput_partition(output_partition)
292+
mlcpBean.setOutput_permissions(output_permissions)
293+
mlcpBean.setOutput_quality(output_quality)
294+
mlcpBean.setOutput_ssl(output_ssl)
295+
mlcpBean.setOutput_type(output_type)
296+
mlcpBean.setOutput_uri_prefix(output_uri_prefix)
297+
mlcpBean.setOutput_uri_replace(output_uri_replace)
298+
mlcpBean.setOutput_uri_suffix(output_uri_suffix)
299+
mlcpBean.setPath_namespace(path_namespace)
300+
mlcpBean.setQuery_filter(query_filter)
301+
mlcpBean.setRedaction(redaction)
302+
mlcpBean.setRestrict_hosts(restrict_hosts)
303+
mlcpBean.setRestrict_input_hosts(restrict_input_hosts)
304+
mlcpBean.setRestrict_output_hosts(restrict_output_hosts)
305+
mlcpBean.setSequencefile_key_class(sequencefile_key_class)
306+
mlcpBean.setSequencefile_value_class(sequencefile_value_class)
307+
mlcpBean.setSequencefile_value_type(sequencefile_value_type)
308+
mlcpBean.setSnapshot(snapshot)
309+
mlcpBean.setSplit_input(split_input)
310+
mlcpBean.setSsl(ssl)
311+
mlcpBean.setStreaming(streaming)
312+
mlcpBean.setTemporal_collection(temporal_collection)
313+
mlcpBean.setThread_count(thread_count)
314+
mlcpBean.setThread_count_per_split(thread_count_per_split)
315+
mlcpBean.setTolerate_errors(tolerate_errors)
316+
mlcpBean.setTransform_function(transform_function)
317+
mlcpBean.setTransform_module(transform_module)
318+
mlcpBean.setTransform_namespace(transform_namespace)
319+
mlcpBean.setTransform_param(transform_param)
320+
mlcpBean.setTransaction_size(transaction_size)
321+
mlcpBean.setType_filter(type_filter)
322+
mlcpBean.setUri_id(uri_id)
323+
mlcpBean.setXml_repair_level(xml_repair_level)
324+
}
148325
}

0 commit comments

Comments
 (0)