From b11757a1e29f8193fed948d7b314c492a79b2033 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 14 Oct 2016 15:42:12 +1100 Subject: [PATCH] Issue #984 Improve module listing Fixed cycle in logging from gcloud datastore --- .../main/config/modules/gcloud-datastore.mod | 4 +-- .../eclipse/jetty/start/TopologicalSort.java | 27 +++++++++++++++--- .../usecases/dynamic-loop.0.assert.txt | 2 +- .../test/resources/usecases/loop.assert.txt | 2 +- .../src/main/config/modules/jcl-slf4j.mod | 2 +- .../src/main/config/modules/slf4j-impl.mod | 3 -- .../src/main/config/modules/slf4j-jcl.mod | 2 +- .../eclipse/jetty/util/TopologicalSort.java | 28 +++++++++++++++---- 8 files changed, 52 insertions(+), 18 deletions(-) diff --git a/jetty-gcloud/jetty-gcloud-session-manager/src/main/config/modules/gcloud-datastore.mod b/jetty-gcloud/jetty-gcloud-session-manager/src/main/config/modules/gcloud-datastore.mod index 0a8019a762c..fb0a3c937d5 100644 --- a/jetty-gcloud/jetty-gcloud-session-manager/src/main/config/modules/gcloud-datastore.mod +++ b/jetty-gcloud/jetty-gcloud-session-manager/src/main/config/modules/gcloud-datastore.mod @@ -7,8 +7,8 @@ gcloud [depends] gcloud -jcl-api -jcl-impl +jcl-slf4j +slf4j-impl [files] maven://com.google.cloud/google-cloud-datastore/0.3.0|lib/gcloud/google-cloud-datastore-0.3.0.jar 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 index 5253657b188..b9aca77b6cf 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/TopologicalSort.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/TopologicalSort.java @@ -45,7 +45,6 @@ import java.util.TreeSet; * * @param The type to be sorted. It must be able to be added to a {@link HashSet} */ -@SuppressWarnings("Duplicates") public class TopologicalSort { private final Map> _dependencies = new HashMap<>(); @@ -126,8 +125,15 @@ public class TopologicalSort ordered_deps.addAll(dependencies); // recursively visit each dependency - for (T d:ordered_deps) - visit(d,visited,sorted,comparator); + 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 @@ -138,7 +144,7 @@ public class TopologicalSort 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 IllegalStateException("cyclic at "+item); + throw new CyclicException(item); } @@ -182,4 +188,17 @@ public class TopologicalSort { return "TopologicalSort "+_dependencies; } + + private static class CyclicException extends IllegalStateException + { + CyclicException(Object item) + { + super("cyclic at "+item); + } + + CyclicException(Object item,CyclicException e) + { + super("cyclic at "+item,e); + } + } } diff --git a/jetty-start/src/test/resources/usecases/dynamic-loop.0.assert.txt b/jetty-start/src/test/resources/usecases/dynamic-loop.0.assert.txt index 3388dbdcfb4..2f38bc2e1b0 100644 --- a/jetty-start/src/test/resources/usecases/dynamic-loop.0.assert.txt +++ b/jetty-start/src/test/resources/usecases/dynamic-loop.0.assert.txt @@ -1,2 +1,2 @@ -EX|IllegalStateException +EX|CyclicException EX|cyclic diff --git a/jetty-start/src/test/resources/usecases/loop.assert.txt b/jetty-start/src/test/resources/usecases/loop.assert.txt index 3388dbdcfb4..2f38bc2e1b0 100644 --- a/jetty-start/src/test/resources/usecases/loop.assert.txt +++ b/jetty-start/src/test/resources/usecases/loop.assert.txt @@ -1,2 +1,2 @@ -EX|IllegalStateException +EX|CyclicException EX|cyclic diff --git a/jetty-util/src/main/config/modules/jcl-slf4j.mod b/jetty-util/src/main/config/modules/jcl-slf4j.mod index 7cabf92dcaa..07de04dd86f 100644 --- a/jetty-util/src/main/config/modules/jcl-slf4j.mod +++ b/jetty-util/src/main/config/modules/jcl-slf4j.mod @@ -11,8 +11,8 @@ internal slf4j-api [provides] -jcl-impl jcl-api +jcl-impl [files] maven://org.slf4j/jcl-over-slf4j/${slf4j.version}|lib/slf4j/jcl-over-slf4j-${slf4j.version}.jar diff --git a/jetty-util/src/main/config/modules/slf4j-impl.mod b/jetty-util/src/main/config/modules/slf4j-impl.mod index 20738e8d909..ef21516ae7d 100644 --- a/jetty-util/src/main/config/modules/slf4j-impl.mod +++ b/jetty-util/src/main/config/modules/slf4j-impl.mod @@ -11,9 +11,6 @@ internal slf4j-api resources -[provide] -slf4j-impl - [files] maven://org.slf4j/slf4j-simple/${slf4j.version}|lib/slf4j/slf4j-simple-${slf4j.version}.jar basehome:modules/slf4j/simplelogger.properties|resources/simplelogger.properties diff --git a/jetty-util/src/main/config/modules/slf4j-jcl.mod b/jetty-util/src/main/config/modules/slf4j-jcl.mod index d1819515258..66866beb313 100644 --- a/jetty-util/src/main/config/modules/slf4j-jcl.mod +++ b/jetty-util/src/main/config/modules/slf4j-jcl.mod @@ -9,7 +9,7 @@ internal [depend] slf4j-api -jcl-api +jcl-impl [provide] slf4j-impl diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/TopologicalSort.java b/jetty-util/src/main/java/org/eclipse/jetty/util/TopologicalSort.java index 40dd7266797..8db8a217e7f 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/TopologicalSort.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/TopologicalSort.java @@ -20,7 +20,6 @@ package org.eclipse.jetty.util; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; @@ -32,7 +31,6 @@ import java.util.TreeSet; import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; -import org.eclipse.jetty.util.component.DumpableCollection; /** @@ -131,8 +129,15 @@ public class TopologicalSort implements Dumpable ordered_deps.addAll(dependencies); // recursively visit each dependency - for (T d:ordered_deps) - visit(d,visited,sorted,comparator); + 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 @@ -143,7 +148,7 @@ public class TopologicalSort implements Dumpable 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 IllegalStateException("cyclic at "+item); + throw new CyclicException(item); } @@ -201,4 +206,17 @@ public class TopologicalSort implements Dumpable out.append(String.format("TopologicalSort@%x%n",hashCode())); ContainerLifeCycle.dump(out, indent,_dependencies.entrySet()); } + + private static class CyclicException extends IllegalStateException + { + CyclicException(Object item) + { + super("cyclic at "+item); + } + + CyclicException(Object item,CyclicException e) + { + super("cyclic at "+item,e); + } + } }