-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#38 WatchTask now reuses the XccAssetLoader in LoadModulesCommand to …
…cut down on duplication
- Loading branch information
Showing
6 changed files
with
45 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 34 additions & 21 deletions
55
src/main/groovy/com/rjrudin/marklogic/gradle/task/client/WatchTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,46 @@ | ||
package com.rjrudin.marklogic.gradle.task.client | ||
|
||
import org.gradle.api.tasks.JavaExec | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
import com.rjrudin.marklogic.appdeployer.AppConfig | ||
import com.marklogic.client.DatabaseClient | ||
import com.rjrudin.marklogic.appdeployer.AppDeployer | ||
import com.rjrudin.marklogic.appdeployer.command.modules.LoadModulesCommand | ||
import com.rjrudin.marklogic.appdeployer.impl.SimpleAppDeployer | ||
import com.rjrudin.marklogic.gradle.task.MarkLogicTask | ||
import com.rjrudin.marklogic.modulesloader.impl.DefaultModulesLoader | ||
|
||
class WatchTask extends JavaExec { | ||
/** | ||
* Runs an infinite loop, and each second, it loads any new/modified modules. Often useful to run with the Gradle "-i" flag | ||
* so you can see which modules are loaded. | ||
*/ | ||
class WatchTask extends MarkLogicTask { | ||
|
||
String modulesLoaderClassName = DefaultModulesLoader.class.getName() | ||
long sleepTime = 1000 | ||
|
||
@TaskAction | ||
@Override | ||
public void exec() { | ||
setMain("com.marklogic.clientutil.modulesloader.ModulesWatcher") | ||
setClasspath(getProject().sourceSets.main.runtimeClasspath) | ||
public void watchModules() { | ||
println "Getting LoadModulesCommand from mlAppDeployer so it can be reused to load modules" | ||
AppDeployer d = getAppDeployer() | ||
if (d instanceof SimpleAppDeployer) { | ||
LoadModulesCommand command = d.getCommand("LoadModulesCommand") | ||
DefaultModulesLoader loader = new DefaultModulesLoader(command.newXccAssetLoader(getCommandContext())) | ||
List<String> paths = getAppConfig().getModulePaths() | ||
println "Watching modules in paths: " + paths | ||
|
||
AppConfig config = getProject().property("mlAppConfig") | ||
def username = config.getRestAdminUsername() ? config.getRestAdminUsername() : getProject().property("mlUsername") | ||
def password = config.getRestAdminPassword() ? config.getRestAdminPassword() : getProject().property("mlPassword") | ||
setArgs([ | ||
config.getModulePaths().join(","), | ||
config.getHost(), | ||
config.getRestPort(), | ||
username, | ||
password, | ||
modulesLoaderClassName | ||
]) | ||
|
||
super.exec() | ||
DatabaseClient client = newClient() | ||
while (true) { | ||
for (String path : paths) { | ||
loader.loadModules(new File(path), client); | ||
} | ||
try { | ||
Thread.sleep(sleepTime); | ||
} catch (InterruptedException ie) { | ||
// Ignore | ||
} | ||
} | ||
} | ||
else { | ||
throw new RuntimeException("Could not an instance of LoadModulesCommand in mlAppDeployer, thus not able to connect to MarkLogic to load modules") | ||
} | ||
} | ||
} |