Skip to content

Commit

Permalink
Merge pull request #313 from alexeysergeev/GRAILS-9752
Browse files Browse the repository at this point in the history
(GRAILS-9752) Fixing logic that searches for a page in inline plugin.
  • Loading branch information
graemerocher committed Jan 13, 2013
2 parents b512b5f + 3c77019 commit ebb3d70
Showing 1 changed file with 35 additions and 12 deletions.
Expand Up @@ -20,8 +20,10 @@
import java.io.IOException;
import java.util.List;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.groovy.grails.plugins.GrailsPluginInfo;
import org.codehaus.groovy.grails.support.StaticResourceLoader;
import org.codehaus.groovy.grails.web.pages.discovery.DefaultGroovyPageLocator;
import org.springframework.core.io.FileSystemResource;
Expand Down Expand Up @@ -85,16 +87,40 @@ public Resource getResource(String location) {
if (r.exists()) return r;
}

org.codehaus.groovy.grails.io.support.Resource[] inlinePluginDirectories = pluginSettings.getInlinePluginDirectories();
for (org.codehaus.groovy.grails.io.support.Resource inlinePluginDirectory : inlinePluginDirectories) {
Resource r = findInInlinePlugin(pluginName, pathRelativeToPlugin);
if (r != null && r.exists()) {
return r;
}
}

Resource resource = super.getResource(location);

if (LOG.isDebugEnabled()) {
LOG.debug("Resolved GSP location [" + location + "] to resource [" + resource +
"] (exists? [" + resource.exists() + "]) using base resource [" + localBaseResource + "]");
}
return resource;
}

protected Resource findInInlinePlugin(String pluginFullName, String pathRelativeToPlugin) {
// find plugins between all available
for(GrailsPluginInfo pluginInfo: pluginSettings.getSupportedPluginInfos()) {
if (pluginInfo.getFullName().equals(pluginFullName)) {
try {
File dirFile = inlinePluginDirectory.getFile();
File pageFile = new File(dirFile, pathRelativeToPlugin);
File pluginDir = pluginInfo.getPluginDir().getFile();
// find out whether plugin is inline one
// unfortunately pluginSettings.isInlinePluginLocation() does not work, paths are compare incorrectly
for (org.codehaus.groovy.grails.io.support.Resource pluginDirResource: pluginSettings.getInlinePluginDirectories()) {
if (!compareFilePaths(pluginDirResource.getFile(), pluginDir)) {
continue;
}
}
File pageFile = new File(pluginDir, pathRelativeToPlugin);
if (pageFile.exists()) {
return new FileSystemResource(pageFile);
}

String pathToInlinePluginView = buildPluginViewPathFromBase(dirFile.getAbsolutePath(), pathRelativeToPlugin, new StringBuilder("file:"));
String pathToInlinePluginView = buildPluginViewPathFromBase(pluginDir.getAbsolutePath(), pathRelativeToPlugin, new StringBuilder("file:"));
Resource resource = super.getResource(pathToInlinePluginView);
if (resource.exists()) {
return resource;
Expand All @@ -104,14 +130,11 @@ public Resource getResource(String location) {
}
}
}
return null;
}

Resource resource = super.getResource(location);

if (LOG.isDebugEnabled()) {
LOG.debug("Resolved GSP location [" + location + "] to resource [" + resource +
"] (exists? [" + resource.exists() + "]) using base resource [" + localBaseResource + "]");
}
return resource;
protected boolean compareFilePaths(File f1, File f2) {
return FilenameUtils.normalizeNoEndSeparator(f1.getAbsolutePath()).equals(FilenameUtils.normalizeNoEndSeparator(f2.getAbsolutePath()));
}

protected String buildPluginViewPath(String pluginBaseDirectory, String pluginName, String pathRelativeToPlugin) {
Expand Down

0 comments on commit ebb3d70

Please sign in to comment.