Skip to content

Commit fee70d8

Browse files
committed
#368 mlWatch now accepts a callback for when modules are loaded
1 parent fe35cc9 commit fee70d8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/main/groovy/com/marklogic/gradle/task/client/WatchTask.groovy

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import com.marklogic.client.ext.modulesloader.impl.DefaultModulesLoader
1111
import com.marklogic.client.ext.modulesloader.impl.PropertiesModuleManager
1212
import com.marklogic.gradle.task.MarkLogicTask
1313
import org.gradle.api.tasks.TaskAction
14+
import org.springframework.core.io.Resource
15+
16+
import java.util.function.Consumer
1417

1518
/**
1619
* Runs an infinite loop, and each second, it loads any new/modified modules. Often useful to run with the Gradle "-i" flag
@@ -23,6 +26,8 @@ class WatchTask extends MarkLogicTask {
2326

2427
long sleepTime = 1000
2528

29+
Consumer<Set<Resource>> onModulesLoaded
30+
2631
@TaskAction
2732
void watchModules() {
2833
LoadModulesCommand command = null
@@ -72,7 +77,10 @@ class WatchTask extends MarkLogicTask {
7277
DatabaseClient client = newClient()
7378
while (true) {
7479
for (String path : paths) {
75-
loader.loadModules(path, new DefaultModulesFinder(), client);
80+
Set<Resource> loadedModules = loader.loadModules(path, new DefaultModulesFinder(), client);
81+
if (onModulesLoaded != null && loadedModules != null && !loadedModules.isEmpty()) {
82+
onModulesLoaded.accept(loadedModules)
83+
}
7684
}
7785
try {
7886
Thread.sleep(sleepTime);

0 commit comments

Comments
 (0)