Skip to content

Commit aea8359

Browse files
committed
#205 New task for copying Roxy build steps
Merged in 2.x work; also renamed Copy to Migrate
1 parent a374367 commit aea8359

File tree

12 files changed

+493
-126
lines changed

12 files changed

+493
-126
lines changed

.gitignore

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
1-
/bin
2-
/.classpath
3-
/build
4-
/.gradle
5-
/.nb-gradle
6-
/.settings
7-
/.project
8-
ml-gradle-all/build/
9-
ml-gradle-all/.gradle/
10-
ml-gradle-all/.classpath
11-
ml-gradle-all/.project
12-
ml-gradle-all/.settings/
13-
sample-project/rob/
14-
sample-project/data/export/
15-
disconnected-project/build/
16-
disconnected-project/.gradle/
17-
sample-project/local.gradle
18-
examples/disconnected-project/build/
19-
examples/disconnected-project/.gradle/
20-
examples/flexrep-project/.gradle/
21-
examples/sample-project/local.gradle
22-
examples/failover-project/.gradle/
23-
examples/mlcp-project/.gradle/
24-
examples/mlcp-project/build/
25-
examples/mlcp-project/data/export/
26-
examples/shell-project/.gradle/
27-
examples/shell-project/build/
28-
examples/shell-project/.gradle
29-
examples/shell-project/.settings
30-
examples/shell-project/.project
31-
examples/shell-project/.classpath
32-
examples/minimal-project/.gradle
33-
examples/ignore-resources-project/.gradle/
34-
.idea
35-
*.iml
1+
/bin
2+
/.classpath
3+
/build
4+
/.gradle
5+
/.nb-gradle
6+
/.settings
7+
/.project
8+
ml-gradle-all/build/
9+
ml-gradle-all/.gradle/
10+
ml-gradle-all/.classpath
11+
ml-gradle-all/.project
12+
ml-gradle-all/.settings/
13+
sample-project/rob/
14+
sample-project/data/export/
15+
disconnected-project/build/
16+
disconnected-project/.gradle/
17+
sample-project/local.gradle
18+
examples/disconnected-project/build/
19+
examples/disconnected-project/.gradle/
20+
examples/flexrep-project/.gradle/
21+
examples/sample-project/local.gradle
22+
examples/failover-project/.gradle/
23+
examples/mlcp-project/.gradle/
24+
examples/mlcp-project/build/
25+
examples/mlcp-project/data/export/
26+
examples/shell-project/.gradle/
27+
examples/shell-project/build/
28+
examples/shell-project/.gradle
29+
examples/shell-project/.settings
30+
examples/shell-project/.project
31+
examples/shell-project/.classpath
32+
examples/minimal-project/.gradle
33+
examples/ignore-resources-project/.gradle/
34+
.idea
35+
*.iml
36+
out

examples/roxy-project/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/bin
2+
.classpath
3+
.project
4+
/build
5+
.gradle
6+
.settings
7+
src
8+
backup-*

examples/roxy-project/build.gradle

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
plugins {
2-
id "com.marklogic.ml-gradle" version "2.7.1"
1+
buildscript {
2+
repositories {
3+
mavenLocal()
4+
jcenter()
5+
}
6+
dependencies {
7+
classpath "com.marklogic:ml-gradle:2.9.0"
8+
}
39
}
410

5-
/**
6-
* ml-gradle defaults to a modules path of src/main/ml-modules. Roxy applications almost always store
7-
* asset modules under ./src, so we need to modify the module paths. Note that since Roxy stores REST API
8-
* extensions under ./ext, "gradle mlWatch" will not load these.
9-
*/
10-
ext {
11-
mlAppConfig {
12-
modulePaths = ["src"]
13-
}
11+
apply plugin: "com.marklogic.ml-gradle"
12+
13+
repositories {
14+
mavenLocal()
15+
jcenter()
1416
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#
2+
# Put your custom functions in this class in order to keep the files under lib untainted
3+
#
4+
# This class has access to all of the private variables in deploy/lib/server_config.rb
5+
#
6+
# any public method you create here can be called from the command line. See
7+
# the examples below for more information.
8+
#
9+
class ServerConfig
10+
11+
def hello_world()
12+
@logger.info "trying to run a custom query"
13+
r = execute_query %Q{
14+
xquery version "1.0-ml";
15+
("one", "two", "three") ! element span { . }
16+
},
17+
{
18+
:app_name => "#{@properties['ml.app-name']}"
19+
}
20+
JSON.parse(r.body).each do |item|
21+
output = item['result']
22+
@logger.info " " + output
23+
end
24+
end
25+
26+
def get_document_count()
27+
r = execute_query %Q{
28+
xdmp:estimate(fn:doc())
29+
}
30+
@logger.info(r.body)
31+
end
32+
33+
def delete_view()
34+
r = execute_query %Q{
35+
xquery version "1.0-ml";
36+
37+
import module namespace view = "http://marklogic.com/xdmp/view"
38+
at "/MarkLogic/views.xqy";
39+
40+
try {
41+
view:remove(
42+
"main",
43+
"Compliance"
44+
)
45+
} catch ($e) { () }
46+
(: Deletes a view, of the 'main' schema that contains columns, with a scope on the element, 'html'. :)
47+
},
48+
{ :db_name => @properties["ml.content-db"] }
49+
end
50+
51+
def create_view()
52+
r = execute_query %Q{
53+
xquery version "1.0-ml";
54+
55+
import module namespace view = "http://marklogic.com/xdmp/view"
56+
at "/MarkLogic/views.xqy";
57+
58+
try {
59+
view:schema-create(
60+
"main",
61+
()
62+
)
63+
} catch ($e) {()},
64+
view:create(
65+
"main",
66+
"Compliance",
67+
view:element-view-scope(fn:QName("http://www.w3.org/1999/xhtml","html")),
68+
( view:column("uri", cts:uri-reference()),
69+
view:column("entityName", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "entityName"]/@content',("collation=http://marklogic.com/collation/"))),
70+
view:column("entityStreetAddress", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "entityStreetAddress"]/@content',("collation=http://marklogic.com/collation/", ("nullable")))),
71+
view:column("entityCityAddress", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "entityCityAddress"]/@content',("collation=http://marklogic.com/collation/", ("nullable")))),
72+
view:column("entityCountryAddress", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "entityCountryAddress"]/@content',("collation=http://marklogic.com/collation//S2", ("nullable")))),
73+
view:column("foreignEntityStatus", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "foreignEntityStatus"]/@content',("collation=http://marklogic.com/collation/", ("nullable")))),
74+
view:column("intermediaryEntityStatus", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "intermediaryEntityStatus"]/@content',("collation=http://marklogic.com/collation/codepoint", ("nullable")))),
75+
view:column("EIN", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "EIN"]/@content',("collation=http://marklogic.com/collation/", ("nullable")))),
76+
view:column("docType", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "docType"]/@content',("collation=http://marklogic.com/collation//S1", ("nullable"))))
77+
),
78+
()
79+
)
80+
81+
(: Creates a view, of the 'main' schema that contains columns, with a scope on the element, 'html'. :)
82+
},
83+
{ :db_name => @properties["ml.content-db"] }
84+
end
85+
end

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ import com.marklogic.gradle.task.groups.SetTraceEventsTask
3333
import com.marklogic.gradle.task.mimetypes.DeployMimetypesTask
3434
import com.marklogic.gradle.task.qconsole.ExportWorkspacesTask
3535
import com.marklogic.gradle.task.qconsole.ImportWorkspacesTask
36-
import com.marklogic.gradle.task.roxy.RoxyCopyFilesTask
37-
import com.marklogic.gradle.task.roxy.RoxyCopyPropertiesTask
36+
import com.marklogic.gradle.task.roxy.RoxyMigrateBuildStepsTask
37+
import com.marklogic.gradle.task.roxy.RoxyMigrateFilesTask
38+
import com.marklogic.gradle.task.roxy.RoxyMigratePropertiesTask
3839
import com.marklogic.gradle.task.scaffold.GenerateScaffoldTask
3940
import com.marklogic.gradle.task.schemas.LoadSchemasTask
4041
import com.marklogic.gradle.task.security.*
@@ -210,9 +211,14 @@ class MarkLogicPlugin implements Plugin<Project> {
210211
project.task("mlShell", type: ShellTask, group: shellGroup, description: "Run groovysh with MarkLogic-specific support built in")
211212

212213
String roxyGroup = "ml-gradle Roxy";
213-
project.task("mlRoxyCopyProperties", type: RoxyCopyPropertiesTask, group: roxyGroup, description: "Copy Roxy properties to gradle.properties file")
214-
project.task("mlRoxyCopyFiles", type: RoxyCopyFilesTask, group: roxyGroup, description: "Copy roxy files")
215-
214+
project.task("mlRoxyMigrateBuildSteps", type: RoxyMigrateBuildStepsTask, group: roxyGroup, description: "Migrate build steps from deploy/app_specific.rb into custom Gradle tasks. " +
215+
"Use -ProxyProjectPath to define the location of your Roxy project, and -PappSpecificPath to define a path other than deploy/app_specific.rb")
216+
project.task("mlRoxyMigrateFiles", type: RoxyMigrateFilesTask, group: roxyGroup, description: "Migrate Roxy source files into this Gradle project. " +
217+
"Use -ProxyProjectPath to define the location of your Roxy project.")
218+
project.task("mlRoxyMigrateProperties", type: RoxyMigratePropertiesTask, group: roxyGroup, description: "Migrate Roxy properties into the gradle.properties file in this project. " +
219+
"Use -ProxyProjectPath to define the location of your Roxy project.")
220+
project.task("mlRoxyMigrateProject", group: roxyGroup, description: "Run all tasks for migrating a Roxy project into this Gradle project. " +
221+
"Use -ProxyProjectPath to define the location of your Roxy project.", dependsOn: ["mlRoxyMigrateBuildSteps", "mlRoxyMigrateFiles", "mlRoxyMigrateProperties"])
216222
logger.info("Finished initializing ml-gradle\n")
217223
}
218224

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MarkLogicTask extends DefaultTask {
4444
project.hasProperty("mlAdminPassword") ? project.property("mlAdminPassword") : project.property("mlPassword")
4545
}
4646

47-
DatabaseClient newClient() {
47+
DatabaseClient newClient() {
4848
getAppConfig().newDatabaseClient()
4949
}
5050

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.marklogic.gradle.task
2+
3+
import com.marklogic.client.DatabaseClient
4+
import org.gradle.api.tasks.TaskAction
5+
6+
class ServerEvalTask extends MarkLogicTask {
7+
8+
String xquery
9+
String javascript
10+
11+
@TaskAction
12+
void serverEval() {
13+
DatabaseClient client = newClient()
14+
try {
15+
String result
16+
if (xquery != null) {
17+
result = client.newServerEval().xquery(xquery).evalAs(String.class)
18+
} else {
19+
result = client.newServerEval().javascript(javascript).evalAs(String.class)
20+
}
21+
if (result != null) {
22+
println result
23+
}
24+
} finally {
25+
client.release()
26+
}
27+
}
28+
}

src/main/groovy/com/marklogic/gradle/task/roxy/RoxyCopyPropertiesTask.groovy

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)