-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.gradle
242 lines (215 loc) · 8.73 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import java.text.SimpleDateFormat;
buildscript {
repositories {
// To use gradle in disconnected mode, you just need to set the 'disconnected' property. E.g. gradle compileJava -Pdisconnected
if (project.hasProperty("disconnected") && !"FALSE".equalsIgnoreCase(disconnected)) {
println "Using offline buildscript dependency repositories"
maven { url uri(projectMavenRepo) }
} else {
println "Using online buildscript dependency repositories"
maven {url 'https://developer.marklogic.com/maven2/'}
mavenLocal()
mavenCentral()
}
}
dependencies {
classpath "com.marklogic:marklogic-unit-test-client:1.2.1"
}
}
plugins {
id 'java'
id 'eclipse'
id 'idea'
// We don't need to add ml-gradle since DHS and DHF comes with it.
// This plugin allows you to create different environments
// for your gradle deploy. Each environment is represented
// by a gradle-${env}.properties file
// See https://github.com/stevesaliman/gradle-properties-plugin
// specify the env on the command line with:
// gradle -PenvironmentName=x ...
id 'net.saliman.properties' version '1.5.1'
// This gradle plugin extends the ml-gradle plugin with
// commands that make the Data Hub Framework do its magic
id 'com.marklogic.ml-data-hub' version '5.8.0'
}
repositories {
// To use gradle in disconnected mode, you just need to set the 'disconnected' property. E.g. gradle compileJava -Pdisconnected
if (project.hasProperty("disconnected") && !"FALSE".equalsIgnoreCase(disconnected)) {
println "Using offline dependency repositories"
maven { url uri(projectMavenRepo) }
} else {
println "Using online dependency repositories"
mavenCentral()
maven { url "https://developer.marklogic.com/maven2/" }
}
}
configurations {
corb
mlcp
}
dependencies {
if ("true".equalsIgnoreCase(project.findProperty("isDeployUnitTestFramework"))) {
// Needed to execute tests written using marklogic-unit-test
mlBundle "com.marklogic:marklogic-unit-test-modules:1.0.0"
}
corb "com.marklogic:marklogic-corb:2.4.1"
mlcp "com.marklogic:mlcp:10.0.6.1"
if ("true".equalsIgnoreCase(project.findProperty("isDeployUnitTestFramework"))) {
testCompile "com.marklogic:marklogic-unit-test-client:1.0.beta"
testCompile "junit:junit:4.12"
}
mlcp files("lib")
}
ext {
rpaasGroup = "RPaaS Group"
rpaasTestGroup = "RPaaS Development"
defaultHarmonizeThreads = harmonizeThreadCount.toInteger()
defaultLoadThreads = loadThreadCount.toInteger()
// providing access to classes and configs for subprojects
configurations = configurations
MlcpTask = com.marklogic.gradle.task.MlcpTask
RunFlowTask = com.marklogic.gradle.task.RunFlowTask
ServerEvalTask = com.marklogic.gradle.task.ServerEvalTask
}
task prepareMlcpLog() {
mkdir "./lib/"
def props = new File('./lib/log4j.properties')
props.text = [
"log4j.rootLogger=INFO, stdout",
"log4j.appender.stdout=org.apache.log4j.ConsoleAppender",
"log4j.appender.stdout.Target=System.out",
"log4j.appender.stdout.layout=org.apache.log4j.PatternLayout",
"log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n"
].join("\n")
}
def buildTime() {
// we use this with the ontology
def df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SX':00'")
return df.format(new Date())
}
/* Database client config for mlUnitTest
ext {
mlUnitTest.databaseClientConfig.host = mlHost
mlUnitTest.databaseClientConfig.port = mlTestFinalPort.toInteger()
mlUnitTest.databaseClientConfig.username = mlUsername
mlUnitTest.databaseClientConfig.password = mlPassword
}
/*
/**
* Delete a collection in the Final Database.
* Usage: ./gradlew mlDeleteCollectionFinal -Pcollection=<collection name>
*/
task mlDeleteCollectionFinal {
outputs.upToDateWhen { false }
doLast {
println "Deleting collection " + collection + " in Final database ...\n"
def client = hubConfig.newFinalClient()
def job = new com.marklogic.client.ext.datamovement.job.DeleteCollectionsJob(collection)
try {job.run(client)} finally {client.release()}
}
}
/**
* Delete a collection in the Staging Database.
* Usage: ./gradlew mlDeleteCollectionStaging -Pcollection=<collection name>
*/
task mlDeleteCollectionStaging {
outputs.upToDateWhen { false }
doLast {
println "Deleting collection " + collection + " in Staging database ...\n"
def client = hubConfig.newStagingClient()
def job = new com.marklogic.client.ext.datamovement.job.DeleteCollectionsJob(collection)
try {job.run(client)} finally {client.release()}
println "Delection of " + collection + " collection completed.\n"
}
}
/*** TEST INFRASTRUCTURE *****
***
*** Creates data-hub-FINAL-TEST, data-hub-STAGING-TEST
***
***/
/**
* The below tasks are used for deploying and undeploying test resources for a DHF 5 application. Just copy everything below
* this comment into the build.gradle file in your DHF application - no properties need to be set for these tasks to work.
*
* The task "hubDeployTestResources" will deploy test versions of your staging and final databases and app servers. You
* can customize these tasks if you don't like the resource names and ports that are used by them. This task is automatically
* run with mlDeploy as long as isDeployUnitTestFramework=true is set in the gradle.properties file
*
* The task "hubUndeployTestResources" will undeploy any test resources that were created. mlUndeploy does depend on
* this task as there's typically no downside to undeploying these resources - if they don't exist, the task will
* quickly complete.
*/
task createTestDirs {
doFirst {
(new File(buildDir, "/test-results/marklogic-unit-tests")).mkdirs()
}
}
task hubUndeployTestResources(type: com.marklogic.gradle.task.MarkLogicTask) {
description = "Undeploys the test servers and databases that were created via hubDeployTestResources"
doLast {
mlAdminManager.invokeActionRequiringRestart({
new com.marklogic.mgmt.resource.appservers.ServerManager(mlManageClient).deleteByIdField(mlStagingAppserverName + "-TEST")
return true
})
mlAdminManager.invokeActionRequiringRestart({
new com.marklogic.mgmt.resource.appservers.ServerManager(mlManageClient).deleteByIdField(mlFinalAppserverName + "-TEST")
return true
})
def dbManager = new com.marklogic.mgmt.resource.databases.DatabaseManager(mlManageClient)
dbManager.deleteByName(mlStagingDbName + "-TEST")
dbManager.deleteByName(mlFinalDbName + "-TEST")
}
}
mlUndeploy.dependsOn hubUndeployTestResources
task doctor(type: com.marklogic.grh.DoctorTask) {}
task createEntity(type: com.marklogic.grh.CreateEntityTask) {}
task deleteEntity(type: com.marklogic.grh.DeleteEntityTask) {}
task createConcept(type: com.marklogic.grh.CreateConceptTask) {}
task deleteConcept(type: com.marklogic.grh.DeleteConceptTask) {}
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.ObjectNode
import com.fasterxml.jackson.databind.node.TextNode
import com.marklogic.appdeployer.command.CommandContext;
import com.marklogic.hub.HubConfig
import com.marklogic.hub.DataHub
import java.util.regex.Pattern
class DeployHubTestDatabaseCommand extends com.marklogic.hub.deploy.commands.DeployHubDatabaseCommand {
String testDatabaseName
DeployHubTestDatabaseCommand(HubConfig config, File testDbFile, String sourceDatabaseFilename, String testDatabaseName) {
super(config, testDbFile, sourceDatabaseFilename)
this.testDatabaseName = testDatabaseName
}
@Override
protected String getPayload(CommandContext context) {
String payload = super.getPayload(context)
ObjectNode node = new ObjectMapper().readTree(payload)
node.set("database-name", new TextNode(testDatabaseName))
return node.toString()
}
}
task clearStagingDatabase(type: com.marklogic.gradle.task.databases.ClearDatabaseTask) {
doFirst {
project.ext.database = project.properties.mlStagingDbName
project.ext.confirm = "true"
}
outputs.upToDateWhen { false }
}
task clearFinalDatabase(type: com.marklogic.gradle.task.databases.ClearDatabaseTask) {
doFirst {
project.ext.database = project.properties.mlFinalDbName
project.ext.confirm = "true"
}
outputs.upToDateWhen { false }
}
task clearJobDatabase(type: com.marklogic.gradle.task.databases.ClearDatabaseTask) {
doFirst {
project.ext.database = project.properties.mlJobDbName
project.ext.confirm = "true"
}
outputs.upToDateWhen { false }
}
task clearDatabases() {
dependsOn clearStagingDatabase
dependsOn clearFinalDatabase
dependsOn clearJobDatabase
}