Skip to content

Commit bea2c14

Browse files
committed
Various fixes to Windows reloading issues. Relates to #9637
1 parent 1808253 commit bea2c14

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

grails-bootstrap/src/main/groovy/grails/io/IOUtils.groovy

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,9 @@ class IOUtils extends SpringIOUtils {
221221
def rootFile = new UrlResource(rootResource).file.canonicalFile
222222

223223
def rootPath = rootFile.path
224-
if(rootPath.contains(BuildSettings.BUILD_CLASSES_PATH)) {
225-
return new File(rootPath - BuildSettings.BUILD_CLASSES_PATH)
224+
def buildClassespath = BuildSettings.BUILD_CLASSES_PATH.replace('/', File.separator)
225+
if(rootPath.contains(buildClassespath)) {
226+
return new File(rootPath - buildClassespath)
226227
}
227228
} catch (FileNotFoundException fnfe) {
228229
return null
@@ -262,8 +263,10 @@ class IOUtils extends SpringIOUtils {
262263
if(classResource) {
263264
def file = new UrlResource(classResource).getFile()
264265
def path = file.canonicalPath
265-
if(path.contains(BuildSettings.BUILD_CLASSES_PATH)) {
266-
location = path.substring(0, path.indexOf(BuildSettings.BUILD_CLASSES_PATH) - 1)
266+
267+
def buildClassespath = BuildSettings.BUILD_CLASSES_PATH.replace('/', File.separator)
268+
if(path.contains(buildClassespath)) {
269+
location = path.substring(0, path.indexOf(buildClassespath) - 1)
267270
}
268271
}
269272
}

grails-core/src/main/groovy/grails/boot/GrailsApp.groovy

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ class GrailsApp extends SpringApplication {
120120
@Override
121121
void onNew(File file, List<String> extensions) {
122122
changedFiles << file.canonicalFile
123+
// For some bizarro reason Windows fires onNew events even for files that have
124+
// just been modified and not created
125+
if(System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) {
126+
return
127+
}
123128
newFiles << file.canonicalFile
124129
}
125130
})
@@ -129,7 +134,7 @@ class GrailsApp extends SpringApplication {
129134
directoryWatcher.addListener(pluginManagerListener)
130135

131136
File baseDir = new File(location).canonicalFile
132-
137+
String baseDirPath = baseDir.canonicalPath
133138
List<File> watchBaseDirectories = [baseDir]
134139
for(GrailsPlugin plugin in pluginManager.allPlugins) {
135140
if(plugin instanceof BinaryGrailsPlugin) {
@@ -155,8 +160,18 @@ class GrailsApp extends SpringApplication {
155160
boolean first = true
156161
for(watchBase in watchBaseDirectories) {
157162
if(!first) {
158-
// the base project will already been in the list of watch patterns, but we add any subprojects here
159-
plugin.watchedResourcePatterns.add(new WatchPattern(directory: watchBase, extension: wp.extension))
163+
if(wp.file != null) {
164+
String relativePath = wp.file.canonicalPath - baseDirPath
165+
File watchFile = new File(watchBase, relativePath)
166+
// the base project will already been in the list of watch patterns, but we add any subprojects here
167+
plugin.watchedResourcePatterns.add(new WatchPattern(file: watchFile, extension: wp.extension))
168+
}
169+
else if(wp.directory != null) {
170+
String relativePath = wp.directory.canonicalPath - baseDirPath
171+
File watchDir = new File(watchBase, relativePath)
172+
// the base project will already been in the list of watch patterns, but we add any subprojects here
173+
plugin.watchedResourcePatterns.add(new WatchPattern(directory: watchDir, extension: wp.extension))
174+
}
160175
}
161176
first = false
162177
if(wp.file) {
@@ -202,7 +217,8 @@ class GrailsApp extends SpringApplication {
202217
def changedFile = uniqueChangedFiles[0]
203218
changedFile = changedFile.canonicalFile
204219
// Groovy files within the 'conf' directory are not compiled
205-
if(changedFile.path.contains('/grails-app/conf/')) {
220+
String confPath = "${File.pathSeparator}grails-app${File.pathSeparator}conf${File.pathSeparator}"
221+
if(changedFile.path.contains(confPath)) {
206222
pluginManager.informOfFileChange(changedFile)
207223
}
208224
else {

grails-core/src/main/groovy/org/grails/plugins/CoreGrailsPlugin.groovy

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,12 @@ class CoreGrailsPlugin extends Plugin {
198198
}
199199
}
200200
else if (event.source instanceof Class) {
201-
RuntimeSpringConfiguration springConfig = new DefaultRuntimeSpringConfiguration(applicationContext)
202-
RuntimeSpringConfigUtilities.reloadSpringResourcesConfig(springConfig, grailsApplication, (Class) event.source)
203-
springConfig.registerBeansWithContext(applicationContext)
201+
def clazz = (Class) event.source
202+
if(Script.isAssignableFrom(clazz)) {
203+
RuntimeSpringConfiguration springConfig = new DefaultRuntimeSpringConfiguration(applicationContext)
204+
RuntimeSpringConfigUtilities.reloadSpringResourcesConfig(springConfig, grailsApplication, clazz)
205+
springConfig.registerBeansWithContext(applicationContext)
206+
}
204207
}
205208
}
206209

0 commit comments

Comments
 (0)