Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2016-02-02 12:00:55 -0500
committerJoakim Erdfelt2016-02-02 12:00:55 -0500
commit7d50167ec194280901d764571424949d28dfbfb0 (patch)
tree7d25276aa7279941841899370b0eb7926fed01db
parent717955ac7d77fe1d43fc151b6e890b35c3746b83 (diff)
downloadorg.eclipse.jetty.project-7d50167ec194280901d764571424949d28dfbfb0.tar.gz
org.eclipse.jetty.project-7d50167ec194280901d764571424949d28dfbfb0.tar.xz
org.eclipse.jetty.project-7d50167ec194280901d764571424949d28dfbfb0.zip
486674 - Quickstart path attribute normalization should be based on longest path match
+ Adding weight to individual PathAttribute's to allow specific keys to win in the situation where more than 1 key is the same path value
-rw-r--r--jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/AttributeNormalizer.java44
1 files changed, 38 insertions, 6 deletions
diff --git a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/AttributeNormalizer.java b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/AttributeNormalizer.java
index 0f893b42f1..aae4361f6f 100644
--- a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/AttributeNormalizer.java
+++ b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/AttributeNormalizer.java
@@ -59,6 +59,7 @@ public class AttributeNormalizer
{
public final Path path;
public final String key;
+ private int weight = -1;
public PathAttribute(String key, Path path) throws IOException
{
@@ -83,12 +84,28 @@ public class AttributeNormalizer
private static Path toCanonicalPath(Path path) throws IOException
{
+ if (path == null)
+ {
+ return null;
+ }
if (Files.exists(path))
{
return path.toRealPath();
}
return path.toAbsolutePath();
}
+
+ public PathAttribute weight(int newweight)
+ {
+ this.weight = newweight;
+ return this;
+ }
+
+ @Override
+ public String toString()
+ {
+ return String.format("PathAttribute[%s=>%s,%d]",key,path,weight);
+ }
}
private static class PathAttributeComparator implements Comparator<PathAttribute>
@@ -106,7 +123,22 @@ public class AttributeNormalizer
return 1;
}
- return o2.path.getNameCount() - o1.path.getNameCount();
+ // Different lengths?
+ int diff = o2.path.getNameCount() - o1.path.getNameCount();
+ if(diff != 0)
+ {
+ return diff;
+ }
+
+ // Different names?
+ diff = o2.path.compareTo(o1.path);
+ if(diff != 0)
+ {
+ return diff;
+ }
+
+ // The paths are the same, base now on weight
+ return o2.weight - o1.weight;
}
}
@@ -117,11 +149,11 @@ public class AttributeNormalizer
try
{
// Track path attributes for expansion
- attributes.add(new PathAttribute("WAR", baseResource == null ? null : baseResource.getFile().toPath()));
- attributes.add(new PathAttribute("jetty.base", "jetty.base"));
- attributes.add(new PathAttribute("jetty.home", "jetty.home"));
- attributes.add(new PathAttribute("user.home", "user.home"));
- attributes.add(new PathAttribute("user.dir", "user.dir"));
+ 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));
+ attributes.add(new PathAttribute("user.dir", "user.dir").weight(6));
Collections.sort(attributes, new PathAttributeComparator());
}

Back to the top