@Override
    public int compare(ServletContainerInitializer sci1, ServletContainerInitializer sci2) {
      String c1 = (sci1 != null ? sci1.getClass().getName() : null);
      String c2 = (sci2 != null ? sci2.getClass().getName() : null);

      if (c1 == null && c2 == null) return 0;

      int i1 = _ordering.getIndexOf(c1);
      if (i1 < 0 && _ordering.hasWildcard()) i1 = _ordering.getWildcardIndex();
      int i2 = _ordering.getIndexOf(c2);
      if (i2 < 0 && _ordering.hasWildcard()) i2 = _ordering.getWildcardIndex();

      return Integer.compare(i1, i2);
    }
  /**
   * @param context
   * @return list of non-excluded {@link ServletContainerInitializer}s
   * @throws Exception
   */
  public List<ServletContainerInitializer> getNonExcludedInitializers(WebAppContext context)
      throws Exception {
    ArrayList<ServletContainerInitializer> nonExcludedInitializers =
        new ArrayList<ServletContainerInitializer>();

    // We use the ServiceLoader mechanism to find the ServletContainerInitializer classes to inspect
    long start = 0;

    ClassLoader old = Thread.currentThread().getContextClassLoader();
    ServiceLoader<ServletContainerInitializer> loadedInitializers = null;
    try {
      if (LOG.isDebugEnabled()) start = System.nanoTime();
      Thread.currentThread().setContextClassLoader(context.getClassLoader());
      loadedInitializers = ServiceLoader.load(ServletContainerInitializer.class);
    } finally {
      Thread.currentThread().setContextClassLoader(old);
    }

    if (LOG.isDebugEnabled())
      LOG.debug(
          "Service loaders found in {}ms",
          (TimeUnit.MILLISECONDS.convert((System.nanoTime() - start), TimeUnit.NANOSECONDS)));

    Map<ServletContainerInitializer, Resource> sciResourceMap =
        new HashMap<ServletContainerInitializer, Resource>();
    ServletContainerInitializerOrdering initializerOrdering = getInitializerOrdering(context);

    // Get initial set of SCIs that aren't from excluded jars or excluded by the
    // containerExclusionPattern, or excluded
    // because containerInitializerOrdering omits it
    for (ServletContainerInitializer sci : loadedInitializers) {
      if (matchesExclusionPattern(sci)) {
        if (LOG.isDebugEnabled()) LOG.debug("{} excluded by pattern", sci);
        continue;
      }

      Resource sciResource = getJarFor(sci);
      if (isFromExcludedJar(context, sci, sciResource)) {
        if (LOG.isDebugEnabled()) LOG.debug("{} is from excluded jar", sci);
        continue;
      }

      // check containerInitializerOrdering doesn't exclude it
      String name = sci.getClass().getName();
      if (initializerOrdering != null
          && (!initializerOrdering.hasWildcard() && initializerOrdering.getIndexOf(name) < 0)) {
        if (LOG.isDebugEnabled()) LOG.debug("{} is excluded by ordering", sci);
        continue;
      }

      sciResourceMap.put(sci, sciResource);
    }

    // Order the SCIs that are included
    if (initializerOrdering != null && !initializerOrdering.isDefaultOrder()) {
      if (LOG.isDebugEnabled())
        LOG.debug("Ordering ServletContainerInitializers with " + initializerOrdering);

      // There is an ordering that is not just "*".
      // Arrange ServletContainerInitializers according to the ordering of classnames given,
      // irrespective of coming from container or webapp classpaths
      nonExcludedInitializers.addAll(sciResourceMap.keySet());
      Collections.sort(
          nonExcludedInitializers, new ServletContainerInitializerComparator(initializerOrdering));
    } else {
      // No jetty-specific ordering specified, or just the wildcard value "*" specified.
      // Fallback to ordering the ServletContainerInitializers according to:
      // container classpath first, WEB-INF/classes then WEB-INF/lib (obeying any web.xml jar
      // ordering)

      // no web.xml ordering defined, add SCIs in any order
      if (context.getMetaData().getOrdering() == null) {
        if (LOG.isDebugEnabled())
          LOG.debug("No web.xml ordering, ServletContainerInitializers in random order");
        nonExcludedInitializers.addAll(sciResourceMap.keySet());
      } else {
        if (LOG.isDebugEnabled())
          LOG.debug(
              "Ordering ServletContainerInitializers with ordering {}",
              context.getMetaData().getOrdering());
        for (Map.Entry<ServletContainerInitializer, Resource> entry : sciResourceMap.entrySet()) {
          // add in SCIs from the container classpath
          if (entry.getKey().getClass().getClassLoader() == context.getClassLoader().getParent())
            nonExcludedInitializers.add(entry.getKey());
          else if (entry.getValue()
              == null) // add in SCIs not in a jar, as they must be from WEB-INF/classes and can't
                       // be ordered
          nonExcludedInitializers.add(entry.getKey());
        }

        // add SCIs according to the ordering of its containing jar
        for (Resource webInfJar : context.getMetaData().getOrderedWebInfJars()) {
          for (Map.Entry<ServletContainerInitializer, Resource> entry : sciResourceMap.entrySet()) {
            if (webInfJar.equals(entry.getValue())) nonExcludedInitializers.add(entry.getKey());
          }
        }
      }
    }

    if (LOG.isDebugEnabled()) {
      int i = 0;
      for (ServletContainerInitializer sci : nonExcludedInitializers)
        LOG.debug("ServletContainerInitializer: {} {}", (++i), sci.getClass().getName());
    }
    return nonExcludedInitializers;
  }