From 46fc5c05e32b757c0d95eb13d4a592aa06593af3 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 27 Mar 2014 16:20:29 +0000 Subject: [PATCH] Work around Groovy compiler bug that can name classes incorrectly If a source URL is added to a CompilationUnit and that source URL does not contain any slashes, the resulting ClassNode in the AST will be incorrectly named. For example, a URL of 'file:foo.groovy' will produce a ClassNode named 'file:foo'. The expected name is 'foo'. This commit works around this problem by adding any URL sources with a file protocol to the compilation unit as File instances. Any URL sources that do not have a file protocol continue to be added as URL instances. Such URLs are still prone to this bug should we be dealing with one that contains no slashes. A fix for the underlying Groovy bug will address this possibility. Fixes #594 --- .../boot/cli/compiler/GroovyCompiler.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java index 1016c62f749..44db3e943d5 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java @@ -20,6 +20,7 @@ import groovy.lang.GroovyClassLoader; import groovy.lang.GroovyClassLoader.ClassCollector; import groovy.lang.GroovyCodeSource; +import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.net.URL; @@ -184,7 +185,13 @@ public class GroovyCompiler { for (String source : sources) { List paths = ResourceUtils.getUrls(source, this.loader); for (String path : paths) { - compilationUnit.addSource(new URL(path)); + URL url = new URL(path); + if ("file".equals(url.getProtocol())) { + compilationUnit.addSource(new File(url.getFile())); + } + else { + compilationUnit.addSource(url); + } } }