Skip to content

Commit

Permalink
Merge pull request #684 from marklogic/feature/bundle-project
Browse files Browse the repository at this point in the history
#676 Simplified example project for bundles
  • Loading branch information
rjrudin authored Jan 11, 2024
2 parents 976ccdb + 8131837 commit 6a90d2d
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 202 deletions.
72 changes: 13 additions & 59 deletions examples/dependency-project/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
This set of projects demonstrates:

- How a "provider" project can publish a zip of MarkLogic files (modules, data, schemas, or system plugins)
- How an ml-gradle or DHF project can depend on this zip so that the files are automatically included
in an application
- How a "provider" project can publish a zip of MarkLogic files (modules, data, schemas, or system plugins).
- How an ml-gradle project can depend on this zip so that the files are automatically included in an application.

## Publishing the provider

To try this out, you'll first need Gradle installed locally.

Then, begin by publishing the zip from the provider project:
To try this out, begin by publishing the zip from the provider project:

cd provider-project
gradle publishToMavenLocal
../../gradlew publishToMavenLocal

If you'd like to inspect the zip, you'll find it at ~/.m2/repository/com/marklogic/example-dependency.
If you'd like to inspect the zip, you'll find it at `~/.m2/repository/com/marklogic/example-dependency`.

## Deploying and verifying the ml-gradle project

Next, deploy the app in the ml-gradle-client-project, replacing "changeme" below with the password for your admin user
(or using a different admin-like user):

cd ../ml-gradle-client-project
gradle -i mlDeploy -PmlUsername=admin -PmlPassword=change
../../gradlew -i mlDeploy -PmlUsername=admin -PmlPassword=change

You'll see logging like this that lets you know that the modules and data from the example-dependency zip
will be included when the application is deployed:
Expand All @@ -32,7 +29,6 @@ Found mlBundle configuration, will extract all of its dependencies to build/mlBu
Finished extracting mlBundle dependencies
Module paths including mlBundle paths: [/Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/build/mlBundle/example-dependency/ml-modules, /Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/src/main/ml-modules]
Data paths including mlBundle paths: [/Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/build/mlBundle/example-dependency/ml-data, /Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/src/main/ml-data]
Plugin paths including mlBundle paths: [/Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/build/mlBundle/example-dependency/ml-plugins, /Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/src/main/ml-plugins]
Schema paths including mlBundle paths: [/Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/build/mlBundle/example-dependency/ml-schemas, /Users/rrudin/dev/workspace/ml-gradle/examples/dependency-project/ml-gradle-client-project/src/main/ml-schemas]
:mlPrepareBundles (Thread[Task worker for ':',5,main]) completed. Took 0.059 secs.
```
Expand Down Expand Up @@ -60,16 +56,6 @@ Shutting down ExecutorService
Writing 2 documents to MarkLogic; port: 8030
```

And also some logging like this that indicates that a system plugin was installed:

```
Writing plugin zip file to URI: /com.marklogic/plugins/varianceplugin.zip
Writing content for /com.marklogic/plugins/varianceplugin.zip
Installing plugin with scope 'native' from URI: /com.marklogic/plugins/varianceplugin.zip
Installed plugin with scope 'native', result: 1
Finished executing command [com.marklogic.appdeployer.command.plugins.InstallPluginsCommand]
```

And finally, some logging like this that indicates that schemas were loaded:

```
Expand All @@ -86,47 +72,15 @@ Writing 1 documents to MarkLogic; port: 8000; database: ml-gradle-client-schemas

You can then use qconsole to verify that the following documents were inserted:

- In ml-gradle-client-modules: /example.sjs (in addition to the modules included by this project: /my-lib.xqy and /Default/ml-gradle-client/rest-api/properties.xml)
- In ml-gradle-client-schemas: /tde/template1.json (in addition to the schema file included in this project: /tde/my-template.json)
- In ml-gradle-client-content: /example/data1.json and /example/data2.json (in addition to the data files including
in this project: /testdata/test1.json, /testdata/test2.json, and /testdata/test3.json)
- In Extensions: /native/scope.xml, /native/varianceplugin/libvarianceplugin.dylib, and /native/varianceplugin/manifest.xml

Note that ml-gradle-client-content also contains the plugin zip file at /com.marklogic/plugins/varianceplugin.zip . If
you don't want that to remain, you can use a custom Gradle task to delete it after the deployment, or use the
mlPluginDatabaseName property to store the zip file in a different database.

You can also verify that the plugin was installed correctly by running the following task:

gradle testPlugin

Which should return:

```
> Task :testPlugin
66.6666666666667
```
- In ml-gradle-client-modules: `/example.sjs` (in addition to the modules included by this project: `/my-lib.xqy` and `/Default/ml-gradle-client/rest-api/properties.xml`).
- In ml-gradle-client-schemas: `/tde/template1.json` (in addition to the schema file included in this project: `/tde/my-template.json`).
- In ml-gradle-client-content: `/example/data1.json` and `/example/data2.json` (in addition to the data files including
in this project: `/testdata/test1.json`, `/testdata/test2.json`, and `/testdata/test3.json`).

See [Loading data](https://github.com/marklogic/ml-app-deployer/wiki/Loading-data) for more
information on configuring how data is loaded during a deployment.

## Provider project with system plugin

## Deploying and verifying the DHF project

The DHF project is deployed the same way as the ml-gradle project, though you'll first need to run hubInit to
initialize the project (this is to avoid adding a bunch of DHF files to version control that aren't needed for
the purposes of this example):

cd ../dhf-client-project
gradle -i mlDeploy

You'll see the same logging as shown above for the ml-gradle project. And likewise, you can use qconsole
to verify that the following documents were inserted:

- In dhf-client-MODULES: /example.sjs
- In dhf-client-FINAL: /example/data1.json, /example/data2.json

Note that in a DHF project, the final database is equivalent to the default content database in an ml-gradle
project. Thus, data is loaded by default to the final database. This can be overridden via the
mlDataDatabaseName property.

The `./provider-with-plugin-project` directory is included as a reference for including a MarkLogic system plugin
in a bundle. Building this plugin requires a C++ compiler, so it is not included in `./provider-project`.
8 changes: 0 additions & 8 deletions examples/dependency-project/dhf-client-project/.gitignore

This file was deleted.

30 changes: 0 additions & 30 deletions examples/dependency-project/dhf-client-project/build.gradle

This file was deleted.

53 changes: 0 additions & 53 deletions examples/dependency-project/dhf-client-project/gradle.properties

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

17 changes: 0 additions & 17 deletions examples/dependency-project/ml-gradle-client-project/build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
//buildscript {
// repositories {
// mavenCentral()
// mavenLocal()
// }
// dependencies {
// classpath "com.marklogic:ml-gradle:4.2.0"
// }
//}

plugins {
id "net.saliman.properties" version "1.5.1"
id "com.marklogic.ml-gradle" version "4.6.0"
}

//apply plugin: "com.marklogic.ml-gradle"

repositories {
mavenLocal()
}

dependencies {
mlBundle "com.marklogic:example-dependency:1.0.0"
}

task testPlugin(type: com.marklogic.gradle.task.ServerEvalTask) {
description = "Run this to verify that the plugin from the example-dependency bundle was installed correctly; should get 66.67 as a result"
javascript = "cts.aggregate('native/varianceplugin', 'variance', cts.elementReference(xs.QName('amount')))"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mlAppName=ml-gradle-client
mlRestPort=8030
mlRestPort=8037
mlContentForestsPerHost=2

# Define these in gradle-local.properties
Expand Down
3 changes: 0 additions & 3 deletions examples/dependency-project/provider-project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ task bundleJar(type: Jar) {
from("src/main/ml-data") {
into("example-dependency/ml-data")
}
from("src/main/ml-plugins") {
into("example-dependency/ml-plugins")
}
from("src/main/ml-schemas") {
into("example-dependency/ml-schemas")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
id "maven-publish"
}

group = "com.marklogic"
version = "1.0.0"

configurations {
bundle
}

task bundleJar(type: Jar) {
from("src/main/ml-plugins") {
into("example-dependency/ml-plugins")
}
destinationDirectory = file("build/libs")
archiveBaseName = "example-dependency-with-plugin"
}

artifacts {
bundle bundleJar
}

publishing {
publications {
mainBundle(MavenPublication) {
artifactId "example-dependency-with-plugin"
artifact bundleJar
}
}
}

0 comments on commit 6a90d2d

Please sign in to comment.