This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 6454 - Velocity unable to find templates when running from css-validator.jar
Summary: Velocity unable to find templates when running from css-validator.jar
Status: RESOLVED FIXED
Alias: None
Product: CSSValidator
Classification: Unclassified
Component: Other (show other bugs)
Version: CSS Validator
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Olivier Thereaux
QA Contact: qa-dev tracking
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-19 22:43 UTC by Marshall Roch
Modified: 2009-01-21 18:25 UTC (History)
2 users (show)

See Also:


Attachments

Description Marshall Roch 2009-01-19 22:43:20 UTC
After applying the patch I attached to bug 5578 to fix that problem, Velocity can't find the <format>.properties files (e.g. text.properties) when running from the command line:

Unable to find resource 'text.properties'
org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'text.properties'
	at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452)
	at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335)
	at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102)
	at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1077)
	at org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleton.java:303)
	at org.apache.velocity.app.Velocity.getTemplate(Velocity.java:503)
	at org.w3c.css.css.StyleSheetGenerator.<init>(StyleSheetGenerator.java:160)
	at org.w3c.css.css.StyleReportFactory.getStyleReport(StyleReportFactory.java:19)
	at org.w3c.css.css.CssValidator.handleRequest(CssValidator.java:178)
	at org.w3c.css.css.CssValidator.main(CssValidator.java:151)
java.lang.NullPointerException
	at org.w3c.css.css.StyleSheetGenerator.print(StyleSheetGenerator.java:418)
	at org.w3c.css.css.CssValidator.handleRequest(CssValidator.java:187)
	at org.w3c.css.css.CssValidator.main(CssValidator.java:151)

Relevant lines from the log:

[info] Velocity not initialized yet. Calling init()...
[debug] Starting Apache Velocity v1.5 (compiled: 2007-02-22 08:52:29)
[trace] RuntimeInstance initializing.
[debug] Default Properties File: org/apache/velocity/runtime/defaults/velocity.properties
[debug] Default ResourceManager initializing. (class org.apache.velocity.runtime.resource.ResourceManagerImpl)
[debug] ResourceLoader instantiated: org.apache.velocity.runtime.resource.loader.FileResourceLoader
[trace] FileResourceLoader : initialization starting.
[info] FileResourceLoader : adding path '.'
[trace] FileResourceLoader : initialization complete.
...
[error] ResourceManager : unable to find resource 'text.properties' in any resource loader.

It is looking for text.properties in . (current directory) rather than inside css-validator.jar. If you copy text.proprties to the current dir, it works.
Comment 1 Jean-Guilhem Rouel 2009-01-20 14:54:23 UTC
This problem should be fixed in the latest cvs revision.
Please give it a try and let me know if that works for you.

Jean-Gui
Comment 2 Marshall Roch 2009-01-21 07:05:21 UTC
Works, thanks!
Comment 3 Marshall Roch 2009-01-21 08:39:00 UTC
Actually it doesn't... it works if you do "ant jar; java -jar css-validator.jar ..." because `org/w3c/css/css` is in the same directory. Try moving the jar elsewhere and it fails:

{output=text, medium=all, warning=2, profile=css21, lang=en}
Jan 21, 2009 12:33:44 AM org.apache.velocity.runtime.log.JdkLogChute log
INFO: Velocity not initialized yet. Calling init()...
Jan 21, 2009 12:33:44 AM org.apache.velocity.runtime.log.JdkLogChute log
INFO: FileResourceLoader : adding path '.'
Jan 21, 2009 12:33:44 AM org.apache.velocity.runtime.log.JdkLogChute log
SEVERE: ResourceManager : unable to find resource 'org/w3c/css/css/text.properties' in any resource loader.
Unable to find resource 'org/w3c/css/css/text.properties'
org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'org/w3c/css/css/text.properties'
	at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452)
	at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335)
	at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102)
	at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1077)
	at org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleton.java:303)
	at org.apache.velocity.app.Velocity.getTemplate(Velocity.java:503)
	at org.w3c.css.css.StyleSheetGenerator.<init>(StyleSheetGenerator.java:160)
	at org.w3c.css.css.StyleReportFactory.getStyleReport(StyleReportFactory.java:19)
	at org.w3c.css.css.CssValidator.handleRequest(CssValidator.java:178)
	at org.w3c.css.css.CssValidator.main(CssValidator.java:151)
java.lang.NullPointerException
	at org.w3c.css.css.StyleSheetGenerator.print(StyleSheetGenerator.java:418)
	at org.w3c.css.css.CssValidator.handleRequest(CssValidator.java:187)
	at org.w3c.css.css.CssValidator.main(CssValidator.java:151)

Is it possible for IndexGenerator.java to tell whether it's inside a jar and use Velocity's JarResourceLoader instead? Or, if it was possible to specify the template path as an argument, then we could either store our own templates outside the jar, or pass "jar:file:/path/to/css-validator.jar!/org/w3c/css/css/" to use the templates inside the jar.
Comment 4 Jean-Guilhem Rouel 2009-01-21 18:25:48 UTC
Jar files are driving me nuts... Anyway, I think this should be fixed for good this time, using JarResourceLoader.
So now, if the validator finds templates in the filesystem (in org/w3c/css/css, same basedir as css-validator.jar), it uses them. If not, it uses the ones bundled in css-validator.jar.

Note that lib/ dir needs to be at the same place as css-validator.jar (AFAIK there's no way to bundle jars into jars), but that's the only restriction. You can run css-validator.jar from anywhere, that should work too (I'm not too proud of that part though).

Marshall, does that work for you too?