@@ -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 ))
0 commit comments