Author: markt Date: Thu Nov 1 18:13:20 2012 New Revision: 1404704 URL: http://svn.apache.org/viewvc?rev=1404704&view=rev Log: Handle case where relative ordering refers top fragments that are not present in the application
Modified: tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java tomcat/trunk/test/org/apache/catalina/deploy/TestWebXmlOrdering.java Modified: tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java?rev=1404704&r1=1404703&r2=1404704&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java (original) +++ tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java Thu Nov 1 18:13:20 2012 @@ -2123,14 +2123,29 @@ public class WebXml { // Stage 1. Make all dependencies bi-directional - this makes the // next stage simpler. for (WebXml fragment : fragments.values()) { - for (String before : fragment.getBeforeOrdering()) { - if (!before.equals(ORDER_OTHERS)) { - fragments.get(before).addAfterOrdering(fragment.getName()); + Iterator<String> before = + fragment.getBeforeOrdering().iterator(); + while (before.hasNext()) { + String beforeEntry = before.next(); + if (!beforeEntry.equals(ORDER_OTHERS)) { + WebXml beforeFragment = fragments.get(beforeEntry); + if (beforeFragment == null) { + before.remove(); + } else { + beforeFragment.addAfterOrdering(fragment.getName()); + } } } - for (String after : fragment.getAfterOrdering()) { - if (!after.equals(ORDER_OTHERS)) { - fragments.get(after).addBeforeOrdering(fragment.getName()); + Iterator<String> after = fragment.getAfterOrdering().iterator(); + while (after.hasNext()) { + String afterEntry = after.next(); + if (!afterEntry.equals(ORDER_OTHERS)) { + WebXml afterFragment = fragments.get(afterEntry); + if (afterFragment == null) { + after.remove(); + } else { + afterFragment.addBeforeOrdering(fragment.getName()); + } } } } Modified: tomcat/trunk/test/org/apache/catalina/deploy/TestWebXmlOrdering.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/deploy/TestWebXmlOrdering.java?rev=1404704&r1=1404703&r2=1404704&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/deploy/TestWebXmlOrdering.java (original) +++ tomcat/trunk/test/org/apache/catalina/deploy/TestWebXmlOrdering.java Thu Nov 1 18:13:20 2012 @@ -330,6 +330,11 @@ public class TestWebXmlOrdering { doRelativeOrderingTest(new RelativeTestRunner10()); } + @Test + public void testOrderWebFragmentsRelative11() { + // Test references to non-existant fragments + doRelativeOrderingTest(new RelativeTestRunner11()); + } @Test(expected=IllegalArgumentException.class) public void testOrderWebFragmentsrelativeCircular1() { @@ -673,4 +678,23 @@ public class TestWebXmlOrdering { assertTrue(order, posC > posB); } } + + private class RelativeTestRunner11 implements RelativeOrderingTestRunner { + + @Override + public void init() { + a.addAfterOrdering("b"); + b.addAfterOrdering("z"); + b.addBeforeOrdering("y"); + } + + @Override + public void validate(String order) { + // There is some duplication in the tests below - it is easier to + // check the tests are complete this way. + + // a.addAfterOrdering("b"); + assertTrue(order, posA > posB); + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org