From 26a4909c88b49d1cb78adf77f2dbf86fb02a9d27 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Sat, 6 Jan 2018 11:23:37 +0100 Subject: [PATCH] Use shaded utils in start for JavaVersion and TopologicalSort #2090 (#2094) * shaded TopologicalSort. Use shaded start in jetty-home * removed unused property * jetty-start shaded dependency * removed component dependencies from TopologicalSort Signed-off-by: Greg Wilkins --- jetty-home/pom.xml | 2 + jetty-start/pom.xml | 5 +- .../java/org/eclipse/jetty/start/Modules.java | 2 + .../eclipse/jetty/start/TopologicalSort.java | 204 ------------------ .../eclipse/jetty/util/TopologicalSort.java | 20 +- 5 files changed, 8 insertions(+), 225 deletions(-) delete mode 100644 jetty-start/src/main/java/org/eclipse/jetty/start/TopologicalSort.java diff --git a/jetty-home/pom.xml b/jetty-home/pom.xml index 7959d55f049..df9c3afc80d 100644 --- a/jetty-home/pom.xml +++ b/jetty-home/pom.xml @@ -84,6 +84,7 @@ org.eclipse.jetty jetty-start ${project.version} + shaded jar true ** @@ -403,6 +404,7 @@ org.eclipse.jetty jetty-start ${project.version} + shaded org.eclipse.jetty diff --git a/jetty-start/pom.xml b/jetty-start/pom.xml index 883f5c656a4..33d3b9d6e67 100644 --- a/jetty-start/pom.xml +++ b/jetty-start/pom.xml @@ -11,7 +11,6 @@ http://www.eclipse.org/jetty ${project.groupId}.start - start.jar @@ -44,11 +43,14 @@ false true + true + shaded org.eclipse.jetty:jetty-util org/eclipse/jetty/util/JavaVersion* + org/eclipse/jetty/util/TopologicalSort* @@ -69,7 +71,6 @@ org.eclipse.jetty jetty-util ${project.version} - compile org.eclipse.jetty.toolchain diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java index d0ab02faab1..aa3f1fecf7c 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java @@ -37,6 +37,8 @@ import java.util.function.Consumer; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.eclipse.jetty.util.TopologicalSort; + /** * Access for all modules declared, as well as what is enabled. */ diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/TopologicalSort.java b/jetty-start/src/main/java/org/eclipse/jetty/start/TopologicalSort.java deleted file mode 100644 index fec237c689c..00000000000 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/TopologicalSort.java +++ /dev/null @@ -1,204 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty.start; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -/** - * Topological sort a list or array. - *

A Topological sort is used when you have a partial ordering expressed as - * dependencies between elements (also often represented as edges in a directed - * acyclic graph). A Topological sort should not be used when you have a total - * ordering expressed as a {@link Comparator} over the items. The algorithm has - * the additional characteristic that dependency sets are sorted by the original - * list order so that order is preserved when possible.

- *

- * The sort algorithm works by recursively visiting every item, once and - * only once. On each visit, the items dependencies are first visited and then the - * item is added to the sorted list. Thus the algorithm ensures that dependency - * items are always added before dependent items.

- * - * @param The type to be sorted. It must be able to be added to a {@link HashSet} - */ -public class TopologicalSort -{ - private final Map> _dependencies = new HashMap<>(); - - /** - * Add a dependency to be considered in the sort. - * @param dependent The dependent item will be sorted after all its dependencies - * @param dependency The dependency item, will be sorted before its dependent item - */ - public void addDependency(T dependent, T dependency) - { - Set set = _dependencies.get(dependent); - if (set==null) - { - set=new HashSet<>(); - _dependencies.put(dependent,set); - } - set.add(dependency); - } - - /** Sort the passed array according to dependencies previously set with - * {@link #addDependency(Object, Object)}. Where possible, ordering will be - * preserved if no dependency - * @param array The array to be sorted. - */ - public void sort(T[] array) - { - List sorted = new ArrayList<>(); - Set visited = new HashSet<>(); - Comparator comparator = new InitialOrderComparator<>(array); - - // Visit all items in the array - for (T t : array) - visit(t,visited,sorted,comparator); - - sorted.toArray(array); - } - - /** Sort the passed list according to dependencies previously set with - * {@link #addDependency(Object, Object)}. Where possible, ordering will be - * preserved if no dependency - * @param list The list to be sorted. - */ - public void sort(Collection list) - { - List sorted = new ArrayList<>(); - Set visited = new HashSet<>(); - Comparator comparator = new InitialOrderComparator<>(list); - - // Visit all items in the list - for (T t : list) - visit(t,visited,sorted,comparator); - - list.clear(); - list.addAll(sorted); - } - - /** Visit an item to be sorted. - * @param item The item to be visited - * @param visited The Set of items already visited - * @param sorted The list to sort items into - * @param comparator A comparator used to sort dependencies. - */ - private void visit(T item, Set visited, List sorted,Comparator comparator) - { - // If the item has not been visited - if(!visited.contains(item)) - { - // We are visiting it now, so add it to the visited set - visited.add(item); - - // Lookup the items dependencies - Set dependencies = _dependencies.get(item); - if (dependencies!=null) - { - // Sort the dependencies - SortedSet ordered_deps = new TreeSet<>(comparator); - ordered_deps.addAll(dependencies); - - // recursively visit each dependency - try - { - for (T d:ordered_deps) - visit(d,visited,sorted,comparator); - } - catch (CyclicException e) - { - throw new CyclicException(item,e); - } - } - - // Now that we have visited all our dependencies, they and their - // dependencies will have been added to the sorted list. So we can - // now add the current item and it will be after its dependencies - sorted.add(item); - } - else if (!sorted.contains(item)) - // If we have already visited an item, but it has not yet been put in the - // sorted list, then we must be in a cycle! - throw new CyclicException(item); - } - - - /** A comparator that is used to sort dependencies in the order they - * were in the original list. This ensures that dependencies are visited - * in the original order and no needless reordering takes place. - * @param - */ - private static class InitialOrderComparator implements Comparator - { - private final Map _indexes = new HashMap<>(); - InitialOrderComparator(T[] initial) - { - int i=0; - for (T t : initial) - _indexes.put(t,i++); - } - - InitialOrderComparator(Collection initial) - { - int i=0; - for (T t : initial) - _indexes.put(t,i++); - } - - @Override - public int compare(T o1, T o2) - { - Integer i1=_indexes.get(o1); - Integer i2=_indexes.get(o2); - if (i1==null || i2==null || i1.equals(o2)) - return 0; - if (i1 The type to be sorted. It must be able to be added to a {@link HashSet} */ -public class TopologicalSort implements Dumpable +public class TopologicalSort { private final Map> _dependencies = new HashMap<>(); @@ -185,7 +181,6 @@ public class TopologicalSort implements Dumpable return -1; return 1; } - } @Override @@ -193,19 +188,6 @@ public class TopologicalSort implements Dumpable { return "TopologicalSort "+_dependencies; } - - @Override - public String dump() - { - return ContainerLifeCycle.dump(this); - } - - @Override - public void dump(Appendable out, String indent) throws IOException - { - out.append(String.format("TopologicalSort@%x%n",hashCode())); - ContainerLifeCycle.dump(out, indent,_dependencies.entrySet()); - } private static class CyclicException extends IllegalStateException {