Adjusting quickstart AttributeNormalizer to treat 'WAR' as a URI, not a Path

This commit is contained in:
Joakim Erdfelt 2016-02-12 09:10:55 -07:00
parent 7c7c49f06b
commit bc59c0853d
2 changed files with 15 additions and 3 deletions

View File

@ -142,14 +142,19 @@ public class AttributeNormalizer
}
}
private URI warURI;
private List<PathAttribute> attributes = new ArrayList<>();
public AttributeNormalizer(Resource baseResource)
{
// WAR URI is always evaluated before paths.
warURI = baseResource == null ? null : baseResource.getURI();
// We don't normalize or resolve the baseResource URI
if (!warURI.isAbsolute())
throw new IllegalArgumentException("WAR URI is not absolute: " + warURI);
try
{
// Track path attributes for expansion
attributes.add(new PathAttribute("WAR", baseResource == null ? null : baseResource.getFile().toPath()).weight(10));
attributes.add(new PathAttribute("jetty.base", "jetty.base").weight(9));
attributes.add(new PathAttribute("jetty.home", "jetty.home").weight(8));
attributes.add(new PathAttribute("user.home", "user.home").weight(7));
@ -306,7 +311,13 @@ public class AttributeNormalizer
private String getString(String property)
{
// Use known attributes first
// Use war path (if known)
if("WAR".equalsIgnoreCase(property))
{
return warURI.toASCIIString();
}
// Use known path attributes
for (PathAttribute attr : attributes)
{
if (attr.key.equalsIgnoreCase(property))

View File

@ -48,7 +48,8 @@ public class AttributeNormalizerTest
public static List<String[]> data()
{
String[][] tests = {
{ "WAR", toSystemPath("/opt/jetty-distro/demo.base/webapps/root") },
// Can't test 'WAR' property, as its not a Path (which this testcase works with)
// { "WAR", toSystemPath("http://localhost/resources/webapps/root") },
{ "jetty.home", toSystemPath("/opt/jetty-distro") },
{ "jetty.base", toSystemPath("/opt/jetty-distro/demo.base") },
{ "user.home", toSystemPath("/home/user") },