Permalink
Browse files

expanding configurable behavior, starting the plugin scanner from run…

…-app, and tests for fileIsReloadable
  • Loading branch information...
1 parent f16f9fa commit da38604d550d99fdc3eeb7befa4deb483bdf9f6c Dan Woods committed Aug 29, 2012
@@ -209,11 +209,21 @@ else if (watchPattern.getDirectory() != null) {
}
}
- private boolean fileIsReloadable(File file) {
+ protected boolean fileIsReloadable(File file) {
String classname = GrailsResourceUtils.getClassName(file.getAbsolutePath());
- boolean fileIsExcluded = (reloadExcludes != null) ? !reloadExcludes.contains(classname) : false;
+ boolean fileIsExcluded = (reloadExcludes != null) ? reloadExcludes.contains(classname) : false;
boolean fileIsIncluded = (reloadIncludes != null) ? reloadIncludes.contains(classname) : true;
- return (fileIsExcluded || fileIsIncluded);
+
+ // These are expanded for readability
+ if (fileIsExcluded == true) {
+ return false;
+ } else if (fileIsIncluded == true) {
+ return true;
+ } else if (fileIsExcluded == false && fileIsIncluded == false && reloadIncludes.size() > 0) {
+ return false;
+ } else {
+ return true;
+ }
}
private void reloadPlugin(File file) {
@@ -0,0 +1,158 @@
+package org.codehaus.groovy.grails.compiler
+
+import spock.lang.Specification
+import org.junit.runner.RunWith
+import org.spockframework.runtime.Sputnik
+import grails.util.PluginBuildSettings
+import grails.util.BuildSettings
+import org.codehaus.groovy.grails.commons.GrailsClassUtils
+import org.codehaus.groovy.grails.io.support.GrailsResourceUtils
+
+@RunWith(Sputnik)
+class GrailsProjectWatcherSpec extends Specification {
+ static excludedConfig, includedConfig, includedAndExcludedConfig, slurper
+ static GrailsProjectWatcher projectWatcher
+ void setupSpec() {
+ slurper = new ConfigSlurper()
+ excludedConfig = slurper.parse("""
+ grails.reload.excludes = ['com.domain.package.Class']
+ """)
+ includedConfig = slurper.parse("""
+ grails.reload.includes = ['com.domain.package.Class']
+ """)
+ includedAndExcludedConfig = slurper.parse("""
+ grails.reload.excludes = ['com.domain.package.NonReloadableClass']
+ grails.reload.includes = ['com.domain.package.ReloadableClass']
+ """)
+
+ def compiler = new GrailsProjectCompiler(new PluginBuildSettings(new BuildSettings()))
+ compiler.compilerExtensions = [".java", ".groovy"]
+ projectWatcher = new GrailsProjectWatcher(compiler, null)
+
+ }
+ def "test that excluded reload classes make it to the project watcher"() {
+ given:
+ GrailsProjectWatcher.reloadExcludes = []
+ GrailsProjectWatcher.reloadIncludes = []
+ def excludes = excludedConfig?.grails?.reload?.excludes
+ projectWatcher.reloadExcludes = (excludes instanceof List) ? excludes : []
+
+ expect:
+ 1 == GrailsProjectWatcher.reloadExcludes.size()
+ }
+ def "test that included reload classes make it to the project watcher"() {
+ given:
+ GrailsProjectWatcher.reloadExcludes = []
+ GrailsProjectWatcher.reloadIncludes = []
+ def includes = includedConfig?.grails?.reload?.includes
+ projectWatcher.reloadIncludes = (includes instanceof List) ? includes : []
+
+ expect:
+ 1 == GrailsProjectWatcher.reloadIncludes.size()
+ }
+ def "test that included and excluded reload classes can be configured"() {
+ given:
+ GrailsProjectWatcher.reloadExcludes = []
+ GrailsProjectWatcher.reloadIncludes = []
+ def excludes = excludedConfig?.grails?.reload?.excludes
+ projectWatcher.reloadExcludes = (excludes instanceof List) ? excludes : []
+ def includes = includedConfig?.grails?.reload?.includes
+ projectWatcher.reloadIncludes = (includes instanceof List) ? includes : []
+
+ expect:
+ 1 == GrailsProjectWatcher.reloadExcludes.size()
+ 1 == GrailsProjectWatcher.reloadIncludes.size()
+ }
+ def "test that excluded classes will not be reloaded"() {
+ given:
+ GrailsProjectWatcher.reloadExcludes = []
+ GrailsProjectWatcher.reloadIncludes = []
+ def file = new MockFile(System.properties["java.io.tmpdir"])
+ def excludes = excludedConfig?.grails?.reload?.excludes
+ projectWatcher.reloadExcludes = (excludes instanceof List) ? excludes : []
+
+ when:
+ def isReloadable = projectWatcher.fileIsReloadable(file)
+
+ then:
+ false == isReloadable
+
+ }
+ def "test that included classes will be reloaded"() {
+ given:
+ GrailsProjectWatcher.reloadExcludes = []
+ GrailsProjectWatcher.reloadIncludes = []
+ def file = new MockFile(System.properties["java.io.tmpdir"])
+ def includes = includedConfig?.grails?.reload?.includes
+ projectWatcher.reloadIncludes = (includes instanceof List) ? includes : []
+
+ when:
+ def isReloadable = projectWatcher.fileIsReloadable(file)
+
+ then:
+ true == isReloadable
+
+ }
+ def "test that non-configured classes will be reloaded when includes are not configured"() {
+ given:
+ GrailsProjectWatcher.reloadExcludes = []
+ GrailsProjectWatcher.reloadIncludes = []
+ def file = new MockFile(System.properties["java.io.tmpdir"])
+ file.absPath = "reloading-test/src/java/com/domain/package/NonConfiguredClassTest.java"
+
+ when:
+ def isReloadable = projectWatcher.fileIsReloadable(file)
+
+ then:
+ true == isReloadable
+
+ }
+ def "test that non-configured classes will NOT be reloaded when includes are configured"() {
+ given:
+ GrailsProjectWatcher.reloadExcludes = []
+ GrailsProjectWatcher.reloadIncludes = []
+ def file = new MockFile(System.properties["java.io.tmpdir"])
+ file.absPath = "reloading-test/src/java/com/domain/package/NonConfiguredClassTest.java"
+ def includes = includedConfig?.grails?.reload?.includes
+ projectWatcher.reloadIncludes = (includes instanceof List) ? includes : []
+
+ when:
+ def isReloadable = projectWatcher.fileIsReloadable(file)
+
+ then:
+ false == isReloadable
+ }
+ def "test that configured excluded classes will NOT be reloaded and that configured included classes WILL be reloaded"() {
+ given:
+ GrailsProjectWatcher.reloadExcludes = []
+ GrailsProjectWatcher.reloadIncludes = []
+ def reloadable = new MockFile(System.properties["java.io.tmpdir"])
+ reloadable.absPath = "reloading-test/src/java/com/domain/package/ReloadableClass.java"
+
+ def nonReloadable = new MockFile(System.properties["java.io.tmpdir"])
+ nonReloadable.absPath = "reloading-test/src/java/com/domain/package/NonReloadableClass.java"
+
+ def includes = includedAndExcludedConfig?.grails?.reload?.includes
+ def excludes = includedAndExcludedConfig?.grails?.reload?.excludes
+ projectWatcher.reloadIncludes = (includes instanceof List) ? includes : []
+ projectWatcher.reloadExcludes = (excludes instanceof List) ? excludes : []
+
+ when:
+ def reloadableIsReloadable = projectWatcher.fileIsReloadable(reloadable)
+ def nonReloadableIsReloadable = projectWatcher.fileIsReloadable(nonReloadable)
+
+ then:
+ true == reloadableIsReloadable
+ false == nonReloadableIsReloadable
+ }
+}
+
+class MockFile extends File {
+ String absPath = "reloading-test/src/java/com/domain/package/Class.java"
+ public MockFile(String fileName) {
+ super(fileName)
+ }
+ public String getAbsolutePath() {
+ return absPath
+ }
+}
View
@@ -35,6 +35,8 @@ target('default': "Runs a Grails application") {
runApp()
}
+ startPluginScanner()
+
if (!(grailsServer instanceof ForkedGrailsProcess)) {
watchContext()
}

0 comments on commit da38604

Please sign in to comment.