undertow/src/main/java/org/wildfly/extension/undertow/deployment/WarMetaDataProcessor.java
protected static void resolveOrder(List<WebOrdering> webOrderings, List<String> order) {
        List<Ordering> work = new ArrayList<Ordering>();

        // Populate the work Ordering list
        Iterator<WebOrdering> webOrderingsIterator = webOrderings.iterator();
        while (webOrderingsIterator.hasNext()) {
            WebOrdering webOrdering = webOrderingsIterator.next();
            Ordering ordering = new Ordering();
            ordering.ordering = webOrdering;
            ordering.afterOthers = webOrdering.isAfterOthers();
            ordering.beforeOthers = webOrdering.isBeforeOthers();
            if (ordering.afterOthers && ordering.beforeOthers) {
                // Cannot be both after and before others
                throw new IllegalStateException(UndertowLogger.ROOT_LOGGER.invalidRelativeOrderingBeforeAndAfter(webOrdering.getJar()));
            }
            work.add(ordering);
        }

        // Create double linked relationships between the orderings,
        // and resolve names
        Iterator<Ordering> workIterator = work.iterator();
        while (workIterator.hasNext()) {
            Ordering ordering = workIterator.next();
            WebOrdering webOrdering = ordering.ordering;
            Iterator<String> after = webOrdering.getAfter().iterator();
            while (after.hasNext()) {
                String name = after.next();
                Iterator<Ordering> workIterator2 = work.iterator();
                boolean found = false;
                while (workIterator2.hasNext()) {
                    Ordering ordering2 = workIterator2.next();
                    if (name.equals(ordering2.ordering.getName())) {
                        if (found) {
                            // Duplicate name
                            throw new IllegalStateException(UndertowLogger.ROOT_LOGGER.invalidRelativeOrderingDuplicateName(webOrdering.getJar()));
                        }
                        ordering.addAfter(ordering2);
                        ordering2.addBefore(ordering);
                        found = true;
                    }
                }
                if (!found) {
                    // Unknown name
                    UndertowLogger.ROOT_LOGGER.invalidRelativeOrderingUnknownName(webOrdering.getJar());
                }
            }
            Iterator<String> before = webOrdering.getBefore().iterator();
            while (before.hasNext()) {
                String name = before.next();
                Iterator<Ordering> workIterator2 = work.iterator();
                boolean found = false;
                while (workIterator2.hasNext()) {
                    Ordering ordering2 = workIterator2.next();
                    if (name.equals(ordering2.ordering.getName())) {
                        if (found) {
                            // Duplicate name
                            throw new IllegalStateException(UndertowLogger.ROOT_LOGGER.invalidRelativeOrderingDuplicateName(webOrdering.getJar()));
                        }
                        ordering.addBefore(ordering2);
                        ordering2.addAfter(ordering);
                        found = true;
                    }
                }
                if (!found) {
                    // Unknown name
                    UndertowLogger.ROOT_LOGGER.invalidRelativeOrderingUnknownName(webOrdering.getJar());
                }
            }
        }

        // Validate ordering
        workIterator = work.iterator();
        while (workIterator.hasNext()) {
            workIterator.next().validate();
        }

        // Create three ordered lists that will then be merged
        List<Ordering> tempOrder = new ArrayList<Ordering>();

        // Create the ordered list of fragments which are before others
        workIterator = work.iterator();
        while (workIterator.hasNext()) {
            Ordering ordering = workIterator.next();
            if (ordering.beforeOthers) {
                // Insert at the first possible position
                int insertAfter = -1;
                boolean last = ordering.isLastBeforeOthers();
                int lastBeforeOthers = -1;
                for (int i = 0; i < tempOrder.size(); i++) {
                    if (ordering.isAfter(tempOrder.get(i))) {
                        insertAfter = i;
                    }
                    if (tempOrder.get(i).beforeOthers) {
                        lastBeforeOthers = i;
                    }
                }
                int pos = insertAfter;
                if (last && lastBeforeOthers > insertAfter) {
                    pos = lastBeforeOthers;
                }
                tempOrder.add(pos + 1, ordering);
            } else if (ordering.afterOthers) {
                // Insert at the last possible element
                int insertBefore = tempOrder.size();
                boolean first = ordering.isFirstAfterOthers();
                int firstAfterOthers = tempOrder.size();
                for (int i = tempOrder.size() - 1; i >= 0; i--) {
                    if (ordering.isBefore(tempOrder.get(i))) {
                        insertBefore = i;
                    }
                    if (tempOrder.get(i).afterOthers) {
                        firstAfterOthers = i;
                    }
                }
                int pos = insertBefore;
                if (first && firstAfterOthers < insertBefore) {
                    pos = firstAfterOthers;
                }
                tempOrder.add(pos, ordering);
            } else {
                // Insert according to other already inserted elements
                int insertAfter = -1;
                int insertBefore = tempOrder.size();
                for (int i = 0; i < tempOrder.size(); i++) {
                    if (ordering.isAfter(tempOrder.get(i)) || tempOrder.get(i).beforeOthers) {
                        insertAfter = i;
                    }
                    if (ordering.isBefore(tempOrder.get(i)) || tempOrder.get(i).afterOthers) {
                        insertBefore = i;
                    }
                }
                if (insertAfter > insertBefore) {
                    // Conflicting order (probably caught earlier)
                    throw new IllegalStateException(UndertowLogger.ROOT_LOGGER.invalidRelativeOrderingConflict(ordering.ordering.getJar()));
                }
                // Insert somewhere in the range
                tempOrder.add(insertAfter + 1, ordering);
            }
        }

        // Create the final ordered list
        Iterator<Ordering> tempOrderIterator = tempOrder.iterator();
        while (tempOrderIterator.hasNext()) {
            Ordering ordering = tempOrderIterator.next();
            order.add(ordering.ordering.getJar());
        }

    }
protected static void resolveOrder(List<WebOrdering> webOrderings, List<String> order) {
        List<Ordering> work = new ArrayList<Ordering>();

        // Populate the work Ordering list
        Iterator<WebOrdering> webOrderingsIterator = webOrderings.iterator();
        while (webOrderingsIterator.hasNext()) {
            WebOrdering webOrdering = webOrderingsIterator.next();
            Ordering ordering = new Ordering();
            ordering.ordering = webOrdering;
            ordering.afterOthers = webOrdering.isAfterOthers();
            ordering.beforeOthers = webOrdering.isBeforeOthers();
            if (ordering.afterOthers && ordering.beforeOthers) {
                // Cannot be both after and before others
                throw new IllegalStateException(UndertowLogger.ROOT_LOGGER.invalidRelativeOrderingBeforeAndAfter(webOrdering.getJar()));
            }
            work.add(ordering);
        }

        // Create double linked relationships between the orderings,
        // and resolve names
        Iterator<Ordering> workIterator = work.iterator();
        while (workIterator.hasNext()) {
            Ordering ordering = workIterator.next();
            WebOrdering webOrdering = ordering.ordering;
            Iterator<String> after = webOrdering.getAfter().iterator();
            while (after.hasNext()) {
                String name = after.next();
                Iterator<Ordering> workIterator2 = work.iterator();
                boolean found = false;
                while (workIterator2.hasNext()) {
                    Ordering ordering2 = workIterator2.next();
                    if (name.equals(ordering2.ordering.getName())) {
                        if (found) {
                            // Duplicate name
                            throw new IllegalStateException(UndertowLogger.ROOT_LOGGER.invalidRelativeOrderingDuplicateName(webOrdering.getJar()));
                        }
                        ordering.addAfter(ordering2);
                        ordering2.addBefore(ordering);
                        found = true;
                    }
                }
                if (!found) {
                    // Unknown name
                    UndertowLogger.ROOT_LOGGER.invalidRelativeOrderingUnknownName(webOrdering.getJar());
                }
            }
            Iterator<String> before = webOrdering.getBefore().iterator();
            while (before.hasNext()) {
                String name = before.next();
                Iterator<Ordering> workIterator2 = work.iterator();
                boolean found = false;
                while (workIterator2.hasNext()) {
                    Ordering ordering2 = workIterator2.next();
                    if (name.equals(ordering2.ordering.getName())) {
                        if (found) {
                            // Duplicate name
                            throw new IllegalStateException(UndertowLogger.ROOT_LOGGER.invalidRelativeOrderingDuplicateName(webOrdering.getJar()));
                        }
                        ordering.addBefore(ordering2);
                        ordering2.addAfter(ordering);
                        found = true;
                    }
                }
                if (!found) {
                    // Unknown name
                    UndertowLogger.ROOT_LOGGER.invalidRelativeOrderingUnknownName(webOrdering.getJar());
                }
            }
        }

        // Validate ordering
        workIterator = work.iterator();
        while (workIterator.hasNext()) {
            workIterator.next().validate();
        }

        // Create three ordered lists that will then be merged
        List<Ordering> tempOrder = new ArrayList<Ordering>();

        // Create the ordered list of fragments which are before others
        workIterator = work.iterator();
        while (workIterator.hasNext()) {
            Ordering ordering = workIterator.next();
            if (ordering.beforeOthers) {
                // Insert at the first possible position
                int insertAfter = -1;
                boolean last = ordering.isLastBeforeOthers();
                int lastBeforeOthers = -1;
                for (int i = 0; i < tempOrder.size(); i++) {
                    if (ordering.isAfter(tempOrder.get(i))) {
                        insertAfter = i;
                    }
                    if (tempOrder.get(i).beforeOthers) {
                        lastBeforeOthers = i;
                    }
                }
                int pos = insertAfter;
                if (last && lastBeforeOthers > insertAfter) {
                    pos = lastBeforeOthers;
                }
                tempOrder.add(pos + 1, ordering);
            } else if (ordering.afterOthers) {
                // Insert at the last possible element
                int insertBefore = tempOrder.size();
                boolean first = ordering.isFirstAfterOthers();
                int firstAfterOthers = tempOrder.size();
                for (int i = tempOrder.size() - 1; i >= 0; i--) {
                    if (ordering.isBefore(tempOrder.get(i))) {
                        insertBefore = i;
                    }
                    if (tempOrder.get(i).afterOthers) {
                        firstAfterOthers = i;
                    }
                }
                int pos = insertBefore;
                if (first && firstAfterOthers < insertBefore) {
                    pos = firstAfterOthers;
                }
                tempOrder.add(pos, ordering);
            } else {
                // Insert according to other already inserted elements
                int insertAfter = -1;
                int insertBefore = tempOrder.size();
                for (int i = 0; i < tempOrder.size(); i++) {
                    if (ordering.isAfter(tempOrder.get(i)) || tempOrder.get(i).beforeOthers) {
                        insertAfter = i;
                    }
                    if (ordering.isBefore(tempOrder.get(i)) || tempOrder.get(i).afterOthers) {
                        insertBefore = i;
                    }
                }
                if (insertAfter > insertBefore) {
                    // Conflicting order (probably caught earlier)
                    throw new IllegalStateException(UndertowLogger.ROOT_LOGGER.invalidRelativeOrderingConflict(ordering.ordering.getJar()));
                }
                // Insert somewhere in the range
                tempOrder.add(insertAfter + 1, ordering);
            }
        }

        // Create the final ordered list
        Iterator<Ordering> tempOrderIterator = tempOrder.iterator();
        while (tempOrderIterator.hasNext()) {
            Ordering ordering = tempOrderIterator.next();
            order.add(ordering.ordering.getJar());
        }

    }
protected static void resolveOrder ( List < WebOrdering > webOrderings , List < String > order ) { List < Ordering > work = new ArrayList < Ordering > ( ) ; // Populate the work Ordering list Iterator < WebOrdering > webOrderingsIterator = webOrderings . iterator ( ) ; while ( webOrderingsIterator . hasNext ( ) ) { WebOrdering webOrdering = webOrderingsIterator . next ( ) ; Ordering ordering = new Ordering ( ) ; ordering . ordering = webOrdering ; ordering . afterOthers = webOrdering . isAfterOthers ( ) ; ordering . beforeOthers = webOrdering . isBeforeOthers ( ) ; if ( ordering . afterOthers && ordering . beforeOthers ) { // Cannot be both after and before others throw new IllegalStateException ( UndertowLogger . ROOT_LOGGER . invalidRelativeOrderingBeforeAndAfter ( webOrdering . getJar ( ) ) ) ; } work . add ( ordering ) ; } // Create double linked relationships between the orderings, // and resolve names Iterator < Ordering > workIterator = work . iterator ( ) ; while ( workIterator . hasNext ( ) ) { Ordering ordering = workIterator . next ( ) ; WebOrdering webOrdering = ordering . ordering ; Iterator < String > after = webOrdering . getAfter ( ) . iterator ( ) ; while ( after . hasNext ( ) ) { String name = after . next ( ) ; Iterator < Ordering > workIterator2 = work . iterator ( ) ; boolean found = false ; while ( workIterator2 . hasNext ( ) ) { Ordering ordering2 = workIterator2 . next ( ) ; if ( name . equals ( ordering2 . ordering . getName ( ) ) ) { if ( found ) { // Duplicate name throw new IllegalStateException ( UndertowLogger . ROOT_LOGGER . invalidRelativeOrderingDuplicateName ( webOrdering . getJar ( ) ) ) ; } ordering . addAfter ( ordering2 ) ; ordering2 . addBefore ( ordering ) ; found = true ; } } if ( ! found ) { // Unknown name UndertowLogger . ROOT_LOGGER . invalidRelativeOrderingUnknownName ( webOrdering . getJar ( ) ) ; } } Iterator < String > before = webOrdering . getBefore ( ) . iterator ( ) ; while ( before . hasNext ( ) ) { String name = before . next ( ) ; Iterator < Ordering > workIterator2 = work . iterator ( ) ; boolean found = false ; while ( workIterator2 . hasNext ( ) ) { Ordering ordering2 = workIterator2 . next ( ) ; if ( name . equals ( ordering2 . ordering . getName ( ) ) ) { if ( found ) { // Duplicate name throw new IllegalStateException ( UndertowLogger . ROOT_LOGGER . invalidRelativeOrderingDuplicateName ( webOrdering . getJar ( ) ) ) ; } ordering . addBefore ( ordering2 ) ; ordering2 . addAfter ( ordering ) ; found = true ; } } if ( ! found ) { // Unknown name UndertowLogger . ROOT_LOGGER . invalidRelativeOrderingUnknownName ( webOrdering . getJar ( ) ) ; } } } // Validate ordering workIterator = work . iterator ( ) ; while ( workIterator . hasNext ( ) ) { workIterator . next ( ) . validate ( ) ; } // Create three ordered lists that will then be merged List < Ordering > tempOrder = new ArrayList < Ordering > ( ) ; // Create the ordered list of fragments which are before others workIterator = work . iterator ( ) ; while ( workIterator . hasNext ( ) ) { Ordering ordering = workIterator . next ( ) ; if ( ordering . beforeOthers ) { // Insert at the first possible position int insertAfter = - 1 ; boolean last = ordering . isLastBeforeOthers ( ) ; int lastBeforeOthers = - 1 ; for ( int i = 0 ; i < tempOrder . size ( ) ; i ++ ) { if ( ordering . isAfter ( tempOrder . get ( i ) ) ) { insertAfter = i ; } if ( tempOrder . get ( i ) . beforeOthers ) { lastBeforeOthers = i ; } } int pos = insertAfter ; if ( last && lastBeforeOthers > insertAfter ) { pos = lastBeforeOthers ; } tempOrder . add ( pos + 1 , ordering ) ; } else if ( ordering . afterOthers ) { // Insert at the last possible element int insertBefore = tempOrder . size ( ) ; boolean first = ordering . isFirstAfterOthers ( ) ; int firstAfterOthers = tempOrder . size ( ) ; for ( int i = tempOrder . size ( ) - 1 ; i >= 0 ; i -- ) { if ( ordering . isBefore ( tempOrder . get ( i ) ) ) { insertBefore = i ; } if ( tempOrder . get ( i ) . afterOthers ) { firstAfterOthers = i ; } } int pos = insertBefore ; if ( first && firstAfterOthers < insertBefore ) { pos = firstAfterOthers ; } tempOrder . add ( pos , ordering ) ; } else { // Insert according to other already inserted elements int insertAfter = - 1 ; int insertBefore = tempOrder . size ( ) ; for ( int i = 0 ; i < tempOrder . size ( ) ; i ++ ) { if ( ordering . isAfter ( tempOrder . get ( i ) ) || tempOrder . get ( i ) . beforeOthers ) { insertAfter = i ; } if ( ordering . isBefore ( tempOrder . get ( i ) ) || tempOrder . get ( i ) . afterOthers ) { insertBefore = i ; } } if ( insertAfter > insertBefore ) { // Conflicting order (probably caught earlier) throw new IllegalStateException ( UndertowLogger . ROOT_LOGGER . invalidRelativeOrderingConflict ( ordering . ordering . getJar ( ) ) ) ; } // Insert somewhere in the range tempOrder . add ( insertAfter + 1 , ordering ) ; } } // Create the final ordered list Iterator < Ordering > tempOrderIterator = tempOrder . iterator ( ) ; while ( tempOrderIterator . hasNext ( ) ) { Ordering ordering = tempOrderIterator . next ( ) ; order . add ( ordering . ordering . getJar ( ) ) ; } }
Generate the Jar processing order.

@param webOrderings The list of orderings, as parsed from the fragments
@param order        The generated order list
Generate the Jar processing order .