@@ -12,41 +12,43 @@ import com.marklogic.gradle.task.MarkLogicTask
1212/**
1313 * Runs an infinite loop, and each second, it loads any new/modified modules. Often useful to run with the Gradle "-i" flag
1414 * so you can see which modules are loaded.
15- *
15+ *
1616 * Depends on an instance of LoadModulesCommand being in the Gradle Project, which should have been placed there by
1717 * MarkLogicPlugin. This prevents this class from having to know how to construct a ModulesLoader.
1818 */
1919class WatchTask extends MarkLogicTask {
2020
21- long sleepTime = 1000
22-
23- @TaskAction
24- public void watchModules () {
25- LoadModulesCommand command = getProject(). property(" mlLoadModulesCommand" )
26-
27- // Adjust the loader to catch exceptions by default
28- ModulesLoader loader = command. getModulesLoader()
29- if (loader == null ) {
30- command. initializeDefaultModulesLoader(getCommandContext())
31- loader = command. getModulesLoader()
32- }
33- if (loader instanceof DefaultModulesLoader ) {
34- ((DefaultModulesLoader )loader). setCatchExceptions(true )
35- }
36-
37- List<String > paths = getAppConfig(). getModulePaths()
38- println " Watching modules in paths: " + paths
39-
40- DatabaseClient client = newClient()
41- while (true ) {
42- for (String path : paths) {
43- loader. loadModules(new File (path), new DefaultModulesFinder (), client);
44- }
45- try {
46- Thread . sleep(sleepTime);
47- } catch (InterruptedException ie) {
48- // Ignore
49- }
50- }
51- }
21+ long sleepTime = 1000
22+
23+ @TaskAction
24+ void watchModules () {
25+ LoadModulesCommand command = getProject(). property(" mlLoadModulesCommand" )
26+
27+ ModulesLoader loader = command. getModulesLoader()
28+ if (loader == null ) {
29+ command. initializeDefaultModulesLoader(getCommandContext())
30+ loader = command. getModulesLoader()
31+ }
32+
33+ if (loader instanceof DefaultModulesLoader ) {
34+ DefaultModulesLoader dml = (DefaultModulesLoader ) loader;
35+ dml. setCatchExceptions(true )
36+ dml. setShutdownTaskExecutorAfterLoadingModules(false )
37+ }
38+
39+ List<String > paths = getAppConfig(). getModulePaths()
40+ println " Watching modules in paths: " + paths
41+
42+ DatabaseClient client = newClient()
43+ while (true ) {
44+ for (String path : paths) {
45+ loader. loadModules(new File (path), new DefaultModulesFinder (), client);
46+ }
47+ try {
48+ Thread . sleep(sleepTime);
49+ } catch (InterruptedException ie) {
50+ // Ignore
51+ }
52+ }
53+ }
5254}
0 commit comments