Skip to content

Commit 92c9d07

Browse files
committed
#415 Ensuring that schema loading is disabled during a preview
1 parent fa355f9 commit 92c9d07

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed
Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.marklogic.gradle.task
22

3-
3+
import com.marklogic.appdeployer.AppDeployer
4+
import com.marklogic.appdeployer.command.Command
5+
import com.marklogic.appdeployer.command.modules.LoadModulesCommand
6+
import com.marklogic.appdeployer.command.schemas.LoadSchemasCommand
47
import com.marklogic.appdeployer.command.security.DeployRolesCommand
58
import com.marklogic.appdeployer.impl.SimpleAppDeployer
69
import com.marklogic.mgmt.util.ObjectMapperFactory
@@ -16,32 +19,58 @@ class PreviewDeployTask extends DeployAppTask {
1619

1720
@TaskAction
1821
void deployApp() {
22+
modifyAppConfigBeforePreview()
23+
modifyAppDeployerBeforePreview()
24+
25+
PreviewInterceptor interceptor = configurePreviewInterceptor()
26+
27+
super.deployApp()
28+
29+
println "\nPREVIEW OF DEPLOYMENT:\n"
30+
println ObjectMapperFactory.getObjectMapper().writeValueAsString(interceptor.getResults())
31+
}
32+
33+
void modifyAppConfigBeforePreview() {
1934
// Disable loading of any modules
2035
getAppConfig().setModulePaths(new ArrayList<String>())
2136

22-
// Disable loading of any schemas
37+
// Disable loading of schemas from the default path
38+
// Database-specific schema paths are handled by removing instances of LoadSchemasCommand
2339
getAppConfig().setSchemasPath(null)
40+
}
41+
42+
void modifyAppDeployerBeforePreview() {
43+
AppDeployer deployer = getAppDeployer()
2444

25-
SimpleAppDeployer deployer = getAppDeployer()
45+
if (deployer instanceof SimpleAppDeployer) {
46+
SimpleAppDeployer simpleAppDeployer = (SimpleAppDeployer) deployer
2647

27-
// Loading roles in two phases breaks the preview feature, so it's disabled
28-
DeployRolesCommand deployRolesCommand = deployer.getCommandOfType(DeployRolesCommand.class)
29-
if (deployRolesCommand != null) {
30-
deployRolesCommand.setDeployRolesInTwoPhases(false)
48+
List<Command> newCommands = new ArrayList<>()
49+
for (Command c : simpleAppDeployer.getCommands()) {
50+
if (c instanceof LoadSchemasCommand || c instanceof LoadModulesCommand) {
51+
// Don't include these; no need to load schemas or modules during a preview
52+
}
53+
// Loading roles in two phases breaks the preview feature, so it's disabled
54+
else if (c instanceof DeployRolesCommand) {
55+
DeployRolesCommand deployRolesCommand = (DeployRolesCommand) c
56+
deployRolesCommand.setDeployRolesInTwoPhases(false)
57+
newCommands.add(c)
58+
} else {
59+
newCommands.add(c)
60+
}
61+
}
62+
simpleAppDeployer.setCommands(newCommands)
3163
}
64+
}
3265

66+
PreviewInterceptor configurePreviewInterceptor() {
3367
PreviewInterceptor interceptor = new PreviewInterceptor(getManageClient())
3468
getManageClient().getRestTemplate().getInterceptors().add(interceptor)
3569
getManageClient().getRestTemplate().setErrorHandler(interceptor)
3670
if (getManageClient().getRestTemplate() != getManageClient().getSecurityUserRestTemplate()) {
3771
getManageClient().getSecurityUserRestTemplate().getInterceptors().add(interceptor)
3872
getManageClient().getSecurityUserRestTemplate().setErrorHandler(interceptor)
3973
}
40-
41-
super.deployApp()
42-
43-
println "\nPREVIEW OF DEPLOYMENT:\n"
44-
println ObjectMapperFactory.getObjectMapper().writeValueAsString(interceptor.getResults())
74+
return interceptor
4575
}
46-
4776
}

0 commit comments

Comments
 (0)