Skip to content

Commit

Permalink
Merge branch '2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrudin committed Aug 7, 2017
2 parents 45209b0 + 2854395 commit be93279
Show file tree
Hide file tree
Showing 16 changed files with 551 additions and 60 deletions.
71 changes: 36 additions & 35 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
/bin
/.classpath
/build
/.gradle
/.nb-gradle
/.settings
/.project
ml-gradle-all/build/
ml-gradle-all/.gradle/
ml-gradle-all/.classpath
ml-gradle-all/.project
ml-gradle-all/.settings/
sample-project/rob/
sample-project/data/export/
disconnected-project/build/
disconnected-project/.gradle/
sample-project/local.gradle
examples/disconnected-project/build/
examples/disconnected-project/.gradle/
examples/flexrep-project/.gradle/
examples/sample-project/local.gradle
examples/failover-project/.gradle/
examples/mlcp-project/.gradle/
examples/mlcp-project/build/
examples/mlcp-project/data/export/
examples/shell-project/.gradle/
examples/shell-project/build/
examples/shell-project/.gradle
examples/shell-project/.settings
examples/shell-project/.project
examples/shell-project/.classpath
examples/minimal-project/.gradle
examples/ignore-resources-project/.gradle/
.idea
*.iml
/bin
/.classpath
/build
/.gradle
/.nb-gradle
/.settings
/.project
ml-gradle-all/build/
ml-gradle-all/.gradle/
ml-gradle-all/.classpath
ml-gradle-all/.project
ml-gradle-all/.settings/
sample-project/rob/
sample-project/data/export/
disconnected-project/build/
disconnected-project/.gradle/
sample-project/local.gradle
examples/disconnected-project/build/
examples/disconnected-project/.gradle/
examples/flexrep-project/.gradle/
examples/sample-project/local.gradle
examples/failover-project/.gradle/
examples/mlcp-project/.gradle/
examples/mlcp-project/build/
examples/mlcp-project/data/export/
examples/shell-project/.gradle/
examples/shell-project/build/
examples/shell-project/.gradle
examples/shell-project/.settings
examples/shell-project/.project
examples/shell-project/.classpath
examples/minimal-project/.gradle
examples/ignore-resources-project/.gradle/
.idea
*.iml
out
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ plugins {
id "eclipse"
id "idea"
id "com.jfrog.bintray" version "1.6"
id "com.github.jk1.dependency-license-report" version "0.3.11"
id "com.gradle.plugin-publish" version "0.9.7"
}

apply plugin: "com.gradle.plugin-publish"
Expand All @@ -37,6 +39,7 @@ dependencies {
compile localGroovy()
compile mlAppDeployerDependency
compile mlcpUtilDependency
compile group: 'commons-io', name: 'commons-io', version: '2.5'
}

task sourcesJar(type: Jar, dependsOn: classes) {
Expand Down Expand Up @@ -87,11 +90,11 @@ pluginBundle {
displayName = 'ml-gradle for MarkLogic'
description = 'Gradle plugin for configuring and deploying applications to MarkLogic'
tags = ['marklogic']
version = "2.8.0"
version = "2.9.0"
}
}

mavenCoordinates {
version = "2.8.0"
version = "2.9.0"
}
}
2 changes: 1 addition & 1 deletion examples/local-testing-project/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Set this to the version you used when running
# "gradle -Pversion=(something) publishToMavenLocal" on your local ml-gradle repo
mlGradleVersion=2.8.0
mlGradleVersion=2.9.0

mlHost=localhost
mlAppName=example
Expand Down
8 changes: 8 additions & 0 deletions examples/roxy-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/bin
.classpath
.project
/build
.gradle
.settings
src
backup-*
24 changes: 13 additions & 11 deletions examples/roxy-project/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
plugins {
id "com.marklogic.ml-gradle" version "2.7.1"
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath "com.marklogic:ml-gradle:2.9.0"
}
}

/**
* ml-gradle defaults to a modules path of src/main/ml-modules. Roxy applications almost always store
* asset modules under ./src, so we need to modify the module paths. Note that since Roxy stores REST API
* extensions under ./ext, "gradle mlWatch" will not load these.
*/
ext {
mlAppConfig {
modulePaths = ["src"]
}
apply plugin: "com.marklogic.ml-gradle"

repositories {
mavenLocal()
jcenter()
}
85 changes: 85 additions & 0 deletions examples/roxy-project/deploy/app_specific.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#
# Put your custom functions in this class in order to keep the files under lib untainted
#
# This class has access to all of the private variables in deploy/lib/server_config.rb
#
# any public method you create here can be called from the command line. See
# the examples below for more information.
#
class ServerConfig

def hello_world()
@logger.info "trying to run a custom query"
r = execute_query %Q{
xquery version "1.0-ml";
("one", "two", "three") ! element span { . }
},
{
:app_name => "#{@properties['ml.app-name']}"
}
JSON.parse(r.body).each do |item|
output = item['result']
@logger.info " " + output
end
end

def get_document_count()
r = execute_query %Q{
xdmp:estimate(fn:doc())
}
@logger.info(r.body)
end

def delete_view()
r = execute_query %Q{
xquery version "1.0-ml";
import module namespace view = "http://marklogic.com/xdmp/view"
at "/MarkLogic/views.xqy";
try {
view:remove(
"main",
"Compliance"
)
} catch ($e) { () }
(: Deletes a view, of the 'main' schema that contains columns, with a scope on the element, 'html'. :)
},
{ :db_name => @properties["ml.content-db"] }
end

def create_view()
r = execute_query %Q{
xquery version "1.0-ml";
import module namespace view = "http://marklogic.com/xdmp/view"
at "/MarkLogic/views.xqy";
try {
view:schema-create(
"main",
()
)
} catch ($e) {()},
view:create(
"main",
"Compliance",
view:element-view-scope(fn:QName("http://www.w3.org/1999/xhtml","html")),
( view:column("uri", cts:uri-reference()),
view:column("entityName", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "entityName"]/@content',("collation=http://marklogic.com/collation/"))),
view:column("entityStreetAddress", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "entityStreetAddress"]/@content',("collation=http://marklogic.com/collation/", ("nullable")))),
view:column("entityCityAddress", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "entityCityAddress"]/@content',("collation=http://marklogic.com/collation/", ("nullable")))),
view:column("entityCountryAddress", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "entityCountryAddress"]/@content',("collation=http://marklogic.com/collation//S2", ("nullable")))),
view:column("foreignEntityStatus", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "foreignEntityStatus"]/@content',("collation=http://marklogic.com/collation/", ("nullable")))),
view:column("intermediaryEntityStatus", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "intermediaryEntityStatus"]/@content',("collation=http://marklogic.com/collation/codepoint", ("nullable")))),
view:column("EIN", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "EIN"]/@content',("collation=http://marklogic.com/collation/", ("nullable")))),
view:column("docType", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "docType"]/@content',("collation=http://marklogic.com/collation//S1", ("nullable"))))
),
()
)
(: Creates a view, of the 'main' schema that contains columns, with a scope on the element, 'html'. :)
},
{ :db_name => @properties["ml.content-db"] }
end
end
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=com.marklogic
version=2.8.0
mlAppDeployerDependency=com.marklogic:ml-app-deployer:2.8.0
version=2.9.0
mlAppDeployerDependency=com.marklogic:ml-app-deployer:2.9.0
mlcpUtilDependency=com.marklogic:mlcp-util:0.3.0

15 changes: 14 additions & 1 deletion src/main/groovy/com/marklogic/gradle/MarkLogicPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import com.marklogic.gradle.task.groups.SetTraceEventsTask
import com.marklogic.gradle.task.mimetypes.DeployMimetypesTask
import com.marklogic.gradle.task.qconsole.ExportWorkspacesTask
import com.marklogic.gradle.task.qconsole.ImportWorkspacesTask
import com.marklogic.gradle.task.roxy.RoxyMigrateBuildStepsTask
import com.marklogic.gradle.task.roxy.RoxyMigrateFilesTask
import com.marklogic.gradle.task.roxy.RoxyMigratePropertiesTask
import com.marklogic.gradle.task.scaffold.GenerateScaffoldTask
import com.marklogic.gradle.task.schemas.LoadSchemasTask
import com.marklogic.gradle.task.security.*
Expand Down Expand Up @@ -80,7 +83,8 @@ class MarkLogicPlugin implements Plugin<Project> {
String deployGroup = "ml-gradle Deploy"
project.task("mlPostDeploy", group: deployGroup, description: "Add dependsOn to this task to add tasks at the end of mlDeploy").mustRunAfter(["mlDeployApp"])
project.task("mlPostUndeploy", group: deployGroup, description: "Add dependsOn to this task to add tasks at the end of mlUndeploy").mustRunAfter(["mlUndeployApp"])
project.task("mlDeploy", group: deployGroup, dependsOn: ["mlDeployApp", "mlPostDeploy"], description: "Deploys all application resources in the configuration directory and allows for additional steps via mlPostDeploy.dependsOn").mustRunAfter("mlClearModulesDatabase")
project.task("mlDeploy", group: deployGroup, dependsOn: ["mlDeployApp", "mlPostDeploy"],
description: "Deploys all application resources in the configuration directory and allows for additional steps via mlPostDeploy.dependsOn. Use -Pignore to specify a comma-delimited list of short class names of ml-app-deployer command classes to ignore while deploying.").mustRunAfter("mlClearModulesDatabase")
project.task("mlUndeploy", group: deployGroup, dependsOn: ["mlUndeployApp", "mlPostUndeploy"], description: "Undeploys all application resources in the configuration directory and allows for additional steps via mlPostUndeploy.dependsOn")
project.task("mlRedeploy", group: deployGroup, dependsOn: ["mlClearModulesDatabase", "mlDeploy"], description: "Clears the modules database and then deploys the application")

Expand Down Expand Up @@ -207,6 +211,15 @@ class MarkLogicPlugin implements Plugin<Project> {
String shellGroup = "ml-gradle Shell"
project.task("mlShell", type: ShellTask, group: shellGroup, description: "Run groovysh with MarkLogic-specific support built in")

String roxyGroup = "ml-gradle Roxy";
project.task("mlRoxyMigrateBuildSteps", type: RoxyMigrateBuildStepsTask, group: roxyGroup, description: "Migrate build steps from deploy/app_specific.rb into custom Gradle tasks. " +
"Use -ProxyProjectPath to define the location of your Roxy project, and -PappSpecificPath to define a path other than deploy/app_specific.rb")
project.task("mlRoxyMigrateFiles", type: RoxyMigrateFilesTask, group: roxyGroup, description: "Migrate Roxy source files into this Gradle project. " +
"Use -ProxyProjectPath to define the location of your Roxy project.")
project.task("mlRoxyMigrateProperties", type: RoxyMigratePropertiesTask, group: roxyGroup, description: "Migrate Roxy properties into the gradle.properties file in this project. " +
"Use -ProxyProjectPath to define the location of your Roxy project.")
project.task("mlRoxyMigrateProject", group: roxyGroup, description: "Run all tasks for migrating a Roxy project into this Gradle project. " +
"Use -ProxyProjectPath to define the location of your Roxy project.", dependsOn: ["mlRoxyMigrateBuildSteps", "mlRoxyMigrateFiles", "mlRoxyMigrateProperties"])
logger.info("Finished initializing ml-gradle\n")
}

Expand Down
25 changes: 24 additions & 1 deletion src/main/groovy/com/marklogic/gradle/task/DeployAppTask.groovy
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
package com.marklogic.gradle.task

import com.marklogic.appdeployer.impl.SimpleAppDeployer
import org.gradle.api.tasks.TaskAction

class DeployAppTask extends MarkLogicTask {

/**
* Use "-Pignore" to specify the short class names of ml-app-deployer commands to ignore. The commands are then
* removed from the mlAppDeployer object, as long as it is an instance of SimpleAppDeployer from ml-app-deployer.
*/
@TaskAction
void deployApp() {
getAppDeployer().deploy(getAppConfig())
def appDeployer = getAppDeployer()
if (project.hasProperty("ignore")) {
if (appDeployer instanceof SimpleAppDeployer) {
String[] commandNames = project.property("ignore").split(",")
SimpleAppDeployer deployer = (SimpleAppDeployer)appDeployer
for (String commandName : commandNames) {
def command = deployer.removeCommand(commandName)
if (command != null) {
println "Ignoring command: " + commandName
} else {
println "Could not find command specified by ignore property: " + commandName
}
}
}
else {
println "ignore property defined, but mlAppDeployer is not an instance of SimpleAppDeployer, so not able to ignore commands"
}
}
appDeployer.deploy(getAppConfig())
}
}
10 changes: 5 additions & 5 deletions src/main/groovy/com/marklogic/gradle/task/MarkLogicTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class MarkLogicTask extends DefaultTask {
project.hasProperty("mlAdminPassword") ? project.property("mlAdminPassword") : project.property("mlPassword")
}

DatabaseClient newClient() {
DatabaseClient newClient() {
getAppConfig().newDatabaseClient()
}

void deployWithCommandListProperty(String propertyName) {
deployWithCommands(getProject().property(propertyName))
}
Expand All @@ -57,7 +57,7 @@ class MarkLogicTask extends DefaultTask {
deployer.setCommands(commands)
deployer.deploy(getAppConfig())
}

void undeployWithCommandListProperty(String propertyName) {
undeployWithCommands(getProject().property(propertyName))
}
Expand All @@ -67,12 +67,12 @@ class MarkLogicTask extends DefaultTask {
deployer.setCommands(commands)
deployer.undeploy(getAppConfig())
}

void invokeDeployerCommandWithClassName(String className) {
SimpleAppDeployer d = (SimpleAppDeployer)getAppDeployer()
new SimpleAppDeployer(getManageClient(), getAdminManager(), d.getCommand(className)).deploy(getAppConfig())
}

void undeployWithCommandWithClassName(String className) {
SimpleAppDeployer d = (SimpleAppDeployer)getAppDeployer()
new SimpleAppDeployer(getManageClient(), getAdminManager(), d.getCommand(className)).undeploy(getAppConfig())
Expand Down
28 changes: 28 additions & 0 deletions src/main/groovy/com/marklogic/gradle/task/ServerEvalTask.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.marklogic.gradle.task

import com.marklogic.client.DatabaseClient
import org.gradle.api.tasks.TaskAction

class ServerEvalTask extends MarkLogicTask {

String xquery
String javascript

@TaskAction
void serverEval() {
DatabaseClient client = newClient()
try {
String result
if (xquery != null) {
result = client.newServerEval().xquery(xquery).evalAs(String.class)
} else {
result = client.newServerEval().javascript(javascript).evalAs(String.class)
}
if (result != null) {
println result
}
} finally {
client.release()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.marklogic.appdeployer.export.ExportedResources
import com.marklogic.appdeployer.export.Exporter
import com.marklogic.gradle.task.MarkLogicTask
import com.marklogic.mgmt.selector.PrefixResourceSelector
import com.marklogic.mgmt.selector.PropertiesFileResourceSelector
import com.marklogic.mgmt.selector.PropertiesResourceSelector
import com.marklogic.mgmt.selector.RegexResourceSelector
import com.marklogic.mgmt.selector.ResourceSelector
import org.gradle.api.tasks.TaskAction
Expand All @@ -27,7 +27,7 @@ class ExportResourcesTask extends MarkLogicTask {
String filename = getProject().property(filePropName)
File file = new File(filename)
if (file.exists()) {
export(new PropertiesFileResourceSelector(file))
export(new PropertiesResourceSelector(file))
} else {
println "File " + filename + " does not exist"
}
Expand Down
Loading

0 comments on commit be93279

Please sign in to comment.