Skip to content

Commit bc97dbe

Browse files
committed
DEVEXP-183: Fixing bug in mlPrintForestPlan
This was not accounting for the fact that the "deployForestsCommand" will be null when a user is explicitly creating forests instead of dynamically creating them via properties.
1 parent 9a0e249 commit bc97dbe

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
plugins {
2-
id "com.marklogic.ml-gradle" version "3.6.0"
2+
id "com.marklogic.ml-gradle" version "4.5.0"
33
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ class MarkLogicPlugin implements Plugin<Project> {
219219
project.task("mlDeleteForestReplicas", type: DeleteForestReplicasTask, group: forestGroup, description: "Deprecated - delete forest replicas via the command.forestNamesAndReplicaCounts map; requires -Pconfirm=true to be set so this isn't accidentally executed")
220220
project.task("mlDeployCustomForests", type: DeployCustomForestsTask, group: forestGroup, description: "Deploy custom forests as defined in subdirectories of the forests configuration directory")
221221
project.task("mlDeployForestReplicas", type: DeployForestReplicasTask, group: forestGroup, description: "Prefer this over mlConfigureForestReplicas; it does the same thing, but uses the ConfigureForestReplicasCommand that is used by mlDeploy")
222-
project.task("mlPrintForestPlan", type: PrintForestPlanTask, group: forestGroup, description: "Print a list of primary forests to be created for a database specified by -Pdatabase=(name of database) when the database is next deployed")
222+
project.task("mlPrintForestPlan", type: PrintForestPlanTask, group: forestGroup, description: "Print a list of primary forests to be created for a database specified by -Pdatabase=(name of database) when the database is next deployed. " +
223+
"This is only intended to be used when forests are created dynamically via properties.")
223224

224225
String groupsGroup = "ml-gradle Group"
225226
project.task("mlDeployGroups", type: DeployGroupsTask, group: groupsGroup, description: "Deploy each group, updating it if it exists, in the configuration directory")

src/main/groovy/com/marklogic/gradle/task/forests/PrintForestPlanTask.groovy

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@ package com.marklogic.gradle.task.forests
33
import com.marklogic.appdeployer.command.databases.DatabasePlan
44
import com.marklogic.appdeployer.command.databases.DeployDatabaseCommand
55
import com.marklogic.appdeployer.command.databases.DeployOtherDatabasesCommand
6+
import com.marklogic.appdeployer.command.forests.DeployForestsCommand
67
import com.marklogic.appdeployer.impl.SimpleAppDeployer
78
import com.marklogic.gradle.task.MarkLogicTask
89
import com.marklogic.mgmt.api.forest.Forest
910
import org.gradle.api.GradleException
1011
import org.gradle.api.tasks.TaskAction
1112

13+
/**
14+
* This is only intended for use when creating forests via properties. The goal is to look at the properties defined by
15+
* a user and preview what forests will be created based on those properties. If a user is explicitly defining forests
16+
* via payloads instead of properties, the expectation is that a user can simply look at what forests already exist and
17+
* compare those to the files in their project.
18+
*/
1219
class PrintForestPlanTask extends MarkLogicTask {
1320

1421
@TaskAction
@@ -36,16 +43,15 @@ class PrintForestPlanTask extends MarkLogicTask {
3643
throw new GradleException("Did not find any database plan with a database name of: " + database)
3744
}
3845

39-
/**
40-
* Now that we have a command, use it to build its command for deploying forests, and then use that to build
41-
* the list of forests that will be created.
42-
*/
43-
List<Forest> forests = deployDatabaseCommand.buildDeployForestsCommand(
44-
database, getCommandContext()).buildForests(getCommandContext(), true)
45-
46+
DeployForestsCommand deployForestsCommand = deployDatabaseCommand.buildDeployForestsCommand(database, getCommandContext())
47+
List<Forest> forests = deployForestsCommand != null ?
48+
deployForestsCommand.buildForests(getCommandContext(), true) :
49+
new ArrayList<>()
4650

4751
if (forests.isEmpty()) {
48-
println "\nNo primary forests will be created the next time the database '" + database + "' is deployed; this is likely because it already has all of the primary desired forests based on the configuration settings."
52+
println "\nNo primary forests will be created the next time the database '" + database + "' is deployed. This is " +
53+
"likely because it already has all of the primary desired forests based on the configuration settings, or because " +
54+
"you are explicitly defining forests to create instead of creating forests dynamically via properties."
4955
println "\nIf replicas have been configured for the database - e.g. via mlDatabaseNamesAndReplicaCounts - and these do not exist yet, " +
5056
"then replicas will be created the next time either the mlDeploy task or mlConfigureForestReplicas task is run."
5157
} else {

0 commit comments

Comments
 (0)