Author: ssmiweve
Date: 2008-05-14 10:54:09 +0200 (Wed, 14 May 2008)
New Revision: 6614
Modified:
branches/2.17/core-api/src/test/java/no/sesat/search/view/velocity/VelocityTemplateTest.java
branches/2.17/site-spi/src/test/java/no/sesat/search/site/config/FileResourceLoader.java
Log:
Issue SKER4742: (VelocityTemplateTest.VelocityLoader.getUrl(..) doesn't handle
parent sites)
Modified:
branches/2.17/core-api/src/test/java/no/sesat/search/view/velocity/VelocityTemplateTest.java
===================================================================
---
branches/2.17/core-api/src/test/java/no/sesat/search/view/velocity/VelocityTemplateTest.java
2008-05-14 08:53:32 UTC (rev 6613)
+++
branches/2.17/core-api/src/test/java/no/sesat/search/view/velocity/VelocityTemplateTest.java
2008-05-14 08:54:09 UTC (rev 6614)
@@ -181,33 +181,40 @@
}
public URL getURL(final String resource, final Site site) {
- LOG.trace("getURL(" + resource + ')');
-
- try{
-
- final String siteFolder = site.getConfigContext();
-
- final String base = System.getProperty("basedir") // test jvm
sets this property
- + (System.getProperty("basedir").endsWith("war") ?
"/../../" : "/../")
- + getProjectName(siteFolder);
-
- final File wf = new File(base + "/war");
-
- final String rsc = resource
- .substring(resource.lastIndexOf("templates/") + 10)
- .replaceAll(".vm.vm", ".vm");
-
- final String urlStr = base
- + (wf.exists() && wf.isDirectory() ?
"/war/src/main/templates/" : "/src/main/templates/")
- + rsc;
-
- return new URI("file://" + urlStr.replace(File.separatorChar,
'/')).normalize().toURL();
-
- }catch (URISyntaxException ex) {
- throw new ResourceLoadException(ex.getMessage(), ex);
- } catch (final MalformedURLException ex) {
- throw new ResourceLoadException(ex.getMessage(), ex);
- }
+
+ LOG.debug("getURL(" + resource + ", site)");
+
+ final String rsc = resource
+ .substring(resource.lastIndexOf("templates/") + 10)
+ .replaceAll(".vm.vm", ".vm");
+
+ return super.getResource("src/main/templates/", rsc, site, true);
+
+// try{
+//
+// final String siteFolder = site.getConfigContext();
+//
+// final String base = System.getProperty("basedir") // test
jvm sets this property
+// + (System.getProperty("basedir").endsWith("war") ?
"/../../" : "/../")
+// + getProjectName(siteFolder);
+//
+// final File wf = new File(base + "/war");
+//
+// final String rsc = resource
+// .substring(resource.lastIndexOf("templates/") + 10)
+// .replaceAll(".vm.vm", ".vm");
+//
+// final String urlStr = base
+// + (wf.exists() && wf.isDirectory() ?
"/war/src/main/templates/" : "/src/main/templates/")
+// + rsc;
+//
+// return new URI("file://" +
urlStr.replace(File.separatorChar, '/')).normalize().toURL();
+//
+// }catch (URISyntaxException ex) {
+// throw new ResourceLoadException(ex.getMessage(), ex);
+// } catch (final MalformedURLException ex) {
+// throw new ResourceLoadException(ex.getMessage(), ex);
+// }
}
}
}
Modified:
branches/2.17/site-spi/src/test/java/no/sesat/search/site/config/FileResourceLoader.java
===================================================================
---
branches/2.17/site-spi/src/test/java/no/sesat/search/site/config/FileResourceLoader.java
2008-05-14 08:53:32 UTC (rev 6613)
+++
branches/2.17/site-spi/src/test/java/no/sesat/search/site/config/FileResourceLoader.java
2008-05-14 08:54:09 UTC (rev 6614)
@@ -140,13 +140,20 @@
LOG.debug("getResource(" + site + ')');
final String suffix = "target" + File.separatorChar +
getResourceDirectory();
+ return getResource(suffix, getResource(), site, false);
+ }
+
+ protected final URL getResource(final String directory, final String
resource, final Site site, final boolean forceUrl){
+
+ LOG.debug("getResource(" + directory + ", " + resource + ", " + site +
")");
+
final String project = getProjectName(site.getName());
int genericSesamLoop = 0;
try{
- if(getResource().contains("jar!") ||
getResource().endsWith(".class")){
- final String classname =
getResource().substring(getResource().indexOf("jar!") + 4);
+ if(resource.contains("jar!") || resource.endsWith(".class")){
+ final String classname =
resource.substring(resource.indexOf("jar!") + 4);
// this will actually fail. but the class is loaded eventually
cause everything is in one classloader.
return
FileResourceLoader.class.getClassLoader().getResource(classname);
}
@@ -164,7 +171,10 @@
LOG.debug("basedirNormalised " + basedirNormalised);
- if((File.separatorChar + "war" +
File.separatorChar).equals(basedirNormalised)){
+ if((File.separatorChar + "war" +
File.separatorChar).equals(basedirNormalised)
+ || (File.separatorChar + "generic.sesam" +
File.separatorChar + "war" + File.separatorChar).equals(basedirNormalised)
+ || (File.separatorChar + "sesat-kernel" +
File.separatorChar + "generic.sesam" + File.separatorChar + "war" +
File.separatorChar).equals(basedirNormalised)){
+
throw new IllegalStateException("At root of filesystem!" +
"+ Current requirement of tests is that
sesat-kernel is checked out, and named such," +
" in any parent folder from here. I've searched
all the way to the root of the filesystem");
@@ -173,9 +183,9 @@
if(basedirNormalised.endsWith(project)
|| basedirNormalised.endsWith(project + "war" +
File.separatorChar)){
- LOG.debug("looking in " + basedir + suffix);
- final File f = new File(basedir + suffix + getResource());
- if(f.exists()){
+ LOG.debug("looking in " + basedir + directory);
+ final File f = new File(basedir + directory + resource);
+ if(f.exists() || forceUrl){
return f.toURI().normalize().toURL();
}
}
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits