Skip to content

Commit ee0c1c2

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

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
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
@@ -251,8 +251,9 @@ class IOUtils extends SpringIOUtils {
251251
def rootFile = new UrlResource(rootResource).file.canonicalFile
252252

253253
def rootPath = rootFile.path
254-
if(rootPath.contains(BuildSettings.BUILD_CLASSES_PATH)) {
255-
return new File(rootPath - BuildSettings.BUILD_CLASSES_PATH)
254+
def buildClassespath = BuildSettings.BUILD_CLASSES_PATH.replace('/', File.separator)
255+
if(rootPath.contains(buildClassespath)) {
256+
return new File(rootPath - buildClassespath)
256257
}
257258
}
258259
return null
@@ -289,8 +290,10 @@ class IOUtils extends SpringIOUtils {
289290
if(classResource) {
290291
def file = new UrlResource(classResource).getFile()
291292
def path = file.canonicalPath
292-
if(path.contains(BuildSettings.BUILD_CLASSES_PATH)) {
293-
location = path.substring(0, path.indexOf(BuildSettings.BUILD_CLASSES_PATH) - 1)
293+
294+
def buildClassespath = BuildSettings.BUILD_CLASSES_PATH.replace('/', File.separator)
295+
if(path.contains(buildClassespath)) {
296+
location = path.substring(0, path.indexOf(buildClassespath) - 1)
294297
}
295298
}
296299
}

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

Lines changed: 24 additions & 6 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) {
@@ -151,8 +156,18 @@ class GrailsApp extends SpringApplication {
151156
boolean first = true
152157
for(watchBase in watchBaseDirectories) {
153158
if(!first) {
154-
// the base project will already been in the list of watch patterns, but we add any subprojects here
155-
plugin.watchedResourcePatterns.add(new WatchPattern(directory: watchBase, extension: wp.extension))
159+
if(wp.file != null) {
160+
String relativePath = wp.file.canonicalPath - baseDirPath
161+
File watchFile = new File(watchBase, relativePath)
162+
// the base project will already been in the list of watch patterns, but we add any subprojects here
163+
plugin.watchedResourcePatterns.add(new WatchPattern(file: watchFile, extension: wp.extension))
164+
}
165+
else if(wp.directory != null) {
166+
String relativePath = wp.directory.canonicalPath - baseDirPath
167+
File watchDir = new File(watchBase, relativePath)
168+
// the base project will already been in the list of watch patterns, but we add any subprojects here
169+
plugin.watchedResourcePatterns.add(new WatchPattern(directory: watchDir, extension: wp.extension))
170+
}
156171
}
157172
first = false
158173
if(wp.file) {
@@ -198,7 +213,8 @@ class GrailsApp extends SpringApplication {
198213
def changedFile = uniqueChangedFiles[0]
199214
changedFile = changedFile.canonicalFile
200215
// Groovy files within the 'conf' directory are not compiled
201-
if(changedFile.path.contains('/grails-app/conf/')) {
216+
String confPath = "${File.pathSeparator}grails-app${File.pathSeparator}conf${File.pathSeparator}"
217+
if(changedFile.path.contains(confPath)) {
202218
pluginManager.informOfFileChange(changedFile)
203219
}
204220
else {
@@ -239,8 +255,10 @@ class GrailsApp extends SpringApplication {
239255
protected void recompile(File changedFile, CompilerConfiguration compilerConfig, String location) {
240256
File appDir = null
241257
def changedPath = changedFile.path
242-
if (changedPath.contains('/grails-app')) {
243-
appDir = new File(changedPath.substring(0, changedPath.indexOf('/grails-app')))
258+
259+
String grailsAppDir = "${File.separator}grails-app"
260+
if (changedPath.contains(grailsAppDir)) {
261+
appDir = new File(changedPath.substring(0, changedPath.indexOf(grailsAppDir)))
244262
}
245263
def baseFileLocation = appDir?.absolutePath ?: location
246264
compilerConfig.setTargetDirectory(new File(baseFileLocation, BuildSettings.BUILD_CLASSES_PATH))

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)