Skip to content

Commit

Permalink
Fix NPE when trying to refresh class from external module
Browse files Browse the repository at this point in the history
  • Loading branch information
marekpiechut committed Sep 19, 2012
1 parent 7c8c666 commit f13c5c5
Showing 1 changed file with 34 additions and 38 deletions.
72 changes: 34 additions & 38 deletions src/play/groovysupport/GroovyPlugin.groovy
Expand Up @@ -209,51 +209,47 @@ class GroovyPlugin extends PlayPlugin {
def updateJava(sources) { def updateJava(sources) {


if (currentSources?.java != sources) { if (currentSources?.java != sources) {

def result = [] def result = []

sources.each { file, time -> sources.each { file, time ->
def src = file.toString() def src = file.absolutePath
// remove .java at the end // remove .java at the end
src = src.substring(0, src.length()-5) src = src.substring(0, src.length()-5)

// we need to turn this source into a class name, but we can't just //We have to remove classpath prefix from file name
// assume it's in /modules/ (it could be anywhere...) so run through //to make sure we can get fully qualified class name from it
// the loaded modules and if it matches, remove the matching path for (jPath in Play.javaPath) {
for (modName in loadedModuleNames()) { def path = jPath.realFile.absolutePath;
if (src.startsWith(modName)) { if (src.startsWith(path)) {
src = src.substring(modName.length()) src = src.substring(path.length() + 1)
break break
} }
} }
// is it OK to assume the file is in /app? it might not be, but
// for now it seems to work def className = src.replace(File.separator, '.')
if (src.startsWith('/app')) {
src = src.substring(5)
}
else {
println 'Not sure what to do with this source. This is probably a bug'
}

def className = src.replace(File.separator, '.')
def appClass = Play.classes.getApplicationClass(className) def appClass = Play.classes.getApplicationClass(className)


// TODO: refresh based on lastmodified timestamp, etc.. if(appClass) {
appClass.refresh() // TODO: refresh based on lastmodified timestamp, etc..

appClass.refresh()
if (appClass.compile() == null) {
Play.classes.classes.remove(appClass.name) if (appClass.compile() == null) {
} else { Play.classes.classes.remove(appClass.name)
result << appClass } else {
} result << appClass
} }

} else {
currentSources.java = sources println("Could not get class for name: ${src}.")

}
return result }
}

currentSources.java = sources
return null
return result
}

return null
} }


def updateGroovy(sources) { def updateGroovy(sources) {
Expand Down

0 comments on commit f13c5c5

Please sign in to comment.