Skip to content

Commit

Permalink
Use ResourceUtils.getURL to resolve the viewsDir location to a `j…
Browse files Browse the repository at this point in the history
…ava.net.URL`

It will make Grace apps works with Spring Framework 6.1 and Spring Boot 3.2 and 3.3

Closes gh-526
  • Loading branch information
rainboyan committed Sep 1, 2024
1 parent 7892088 commit 55d7b1a
Showing 1 changed file with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;

import grails.config.Config;
Expand Down Expand Up @@ -97,13 +98,13 @@ public GroovyPageResourceLoader groovyPageResourceLoader(ObjectProvider<GrailsAp
GroovyPageResourceLoader groovyPageResourceLoader = new GroovyPageResourceLoader();
Resource baseResource;
if (StringUtils.hasText(viewsDir)) {
baseResource = new FileUrlResource(viewsDir);
baseResource = new FileUrlResource(ResourceUtils.getURL(viewsDir));
}
else if (warDeployedWithReload && env.hasReloadLocation()) {
baseResource = new FileUrlResource(transformToValidLocation(env.getReloadLocation()));
baseResource = new FileUrlResource(ResourceUtils.getURL(env.getReloadLocation()));
}
else {
baseResource = new FileUrlResource(transformToValidLocation(BuildSettings.BASE_DIR.getAbsolutePath()));
baseResource = new FileUrlResource(ResourceUtils.getURL(BuildSettings.BASE_DIR.getCanonicalPath()));
}
groovyPageResourceLoader.setBaseResource(baseResource);

Expand Down Expand Up @@ -321,14 +322,4 @@ public DefaultGroovyPagesUriService groovyPagesUriService() {
return new DefaultGroovyPagesUriService();
}

private static String transformToValidLocation(String location) {
if (location.equals(".")) {
return location;
}
if (!location.endsWith(java.io.File.separator)) {
return location + java.io.File.separator;
}
return location;
}

}

0 comments on commit 55d7b1a

Please sign in to comment.