diff --git a/0001-Revert-Some-work-on-issue-910-ensure-that-anonymous-.patch b/0001-Revert-Some-work-on-issue-910-ensure-that-anonymous-.patch deleted file mode 100644 index 77abf33..0000000 --- a/0001-Revert-Some-work-on-issue-910-ensure-that-anonymous-.patch +++ /dev/null @@ -1,456 +0,0 @@ -From 31b1e22561d5db89abfd09a8ecd9932d20f5eda3 Mon Sep 17 00:00:00 2001 -From: Mikolaj Izdebski -Date: Mon, 18 May 2015 12:05:45 +0200 -Subject: [PATCH] Revert "Some work on issue 910 -- ensure that anonymous keys - & typeliterals don't" - -This reverts commit 825f8c1df885b9d7643a9e18e336984f0138edaf. ---- - .../com/google/inject/internal/InjectorImpl.java | 1 - - core/src/com/google/inject/internal/MoreTypes.java | 37 ++----------------- - core/src/com/google/inject/spi/Dependency.java | 3 +- - core/src/com/google/inject/spi/Elements.java | 14 +++---- - core/test/com/google/inject/Asserts.java | 42 --------------------- - core/test/com/google/inject/KeyTest.java | 43 ---------------------- - .../com/google/inject/internal/WeakKeySetTest.java | 11 +++++- - .../google/inject/internal/WeakKeySetUtils.java | 42 +++++++++++++++++++++ - .../google/inject/multibindings/MapBinderTest.java | 3 +- - .../inject/multibindings/OptionalBinderTest.java | 3 +- - 10 files changed, 62 insertions(+), 137 deletions(-) - -diff --git a/core/src/com/google/inject/internal/InjectorImpl.java b/core/src/com/google/inject/internal/InjectorImpl.java -index 54ce8a3..d260046 100644 ---- a/core/src/com/google/inject/internal/InjectorImpl.java -+++ b/core/src/com/google/inject/internal/InjectorImpl.java -@@ -801,7 +801,6 @@ final class InjectorImpl implements Injector, Lookups { - throw errors.childBindingAlreadySet(key, sources).toException(); - } - -- key = MoreTypes.canonicalizeKey(key); // before storing the key long-term, canonicalize it. - BindingImpl binding = createJustInTimeBinding(key, errors, jitDisabled, jitType); - state.parent().blacklist(key, state, binding.getSource()); - jitBindings.put(key, binding); -diff --git a/core/src/com/google/inject/internal/MoreTypes.java b/core/src/com/google/inject/internal/MoreTypes.java -index bdf6029..12a7625 100644 ---- a/core/src/com/google/inject/internal/MoreTypes.java -+++ b/core/src/com/google/inject/internal/MoreTypes.java -@@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull; - import com.google.common.base.Objects; - import com.google.common.collect.ImmutableMap; - import com.google.inject.ConfigurationException; --import com.google.inject.Key; - import com.google.inject.TypeLiteral; - import com.google.inject.util.Types; - -@@ -65,25 +64,6 @@ public class MoreTypes { - .build(); - - /** -- * Returns a key that doesn't hold any references to parent classes. -- * This is necessary for anonymous keys, so ensure we don't hold a ref -- * to the containing module (or class) forever. -- */ -- public static Key canonicalizeKey(Key key) { -- // If we know this isn't a subclass, return as-is. -- // Otherwise, recreate the key to avoid the subclass -- if (key.getClass() == Key.class) { -- return key; -- } else if (key.getAnnotation() != null) { -- return Key.get(key.getTypeLiteral(), key.getAnnotation()); -- } else if (key.getAnnotationType() != null) { -- return Key.get(key.getTypeLiteral(), key.getAnnotationType()); -- } else { -- return Key.get(key.getTypeLiteral()); -- } -- } -- -- /** - * Returns an type that's appropriate for use in a key. - * - *

If the raw type of {@code typeLiteral} is a {@code javax.inject.Provider}, this returns a -@@ -113,20 +93,9 @@ public class MoreTypes { - - @SuppressWarnings("unchecked") - TypeLiteral wrappedPrimitives = (TypeLiteral) PRIMITIVE_TO_WRAPPER.get(typeLiteral); -- if (wrappedPrimitives != null) { -- return wrappedPrimitives; -- } -- -- // If we know this isn't a subclass, return as-is. -- if (typeLiteral.getClass() == TypeLiteral.class) { -- return typeLiteral; -- } -- -- // recreate the TypeLiteral to avoid anonymous TypeLiterals from holding refs to their -- // surrounding classes. -- @SuppressWarnings("unchecked") -- TypeLiteral recreated = (TypeLiteral) TypeLiteral.get(typeLiteral.getType()); -- return recreated; -+ return wrappedPrimitives != null -+ ? wrappedPrimitives -+ : typeLiteral; - } - - /** -diff --git a/core/src/com/google/inject/spi/Dependency.java b/core/src/com/google/inject/spi/Dependency.java -index f86e255..c51d87c 100644 ---- a/core/src/com/google/inject/spi/Dependency.java -+++ b/core/src/com/google/inject/spi/Dependency.java -@@ -22,7 +22,6 @@ import com.google.common.base.Objects; - import com.google.common.collect.ImmutableSet; - import com.google.common.collect.Lists; - import com.google.inject.Key; --import com.google.inject.internal.MoreTypes; - - import java.util.List; - import java.util.Set; -@@ -55,7 +54,7 @@ public final class Dependency { - * nullable. - */ - public static Dependency get(Key key) { -- return new Dependency(null, MoreTypes.canonicalizeKey(key), true, -1); -+ return new Dependency(null, key, true, -1); - } - - /** -diff --git a/core/src/com/google/inject/spi/Elements.java b/core/src/com/google/inject/spi/Elements.java -index 9348276..f5bbe89 100644 ---- a/core/src/com/google/inject/spi/Elements.java -+++ b/core/src/com/google/inject/spi/Elements.java -@@ -44,7 +44,6 @@ import com.google.inject.internal.ConstantBindingBuilderImpl; - import com.google.inject.internal.Errors; - import com.google.inject.internal.ExposureBuilder; - import com.google.inject.internal.InternalFlags.IncludeStackTraceOption; --import com.google.inject.internal.MoreTypes; - import com.google.inject.internal.PrivateElementsImpl; - import com.google.inject.internal.ProviderMethodsModule; - import com.google.inject.internal.util.SourceProvider; -@@ -243,14 +242,13 @@ public final class Elements { - - @Override - public void requestInjection(TypeLiteral type, T instance) { -- elements.add(new InjectionRequest(getElementSource(), MoreTypes.canonicalizeForKey(type), -- instance)); -+ elements.add(new InjectionRequest(getElementSource(), type, instance)); - } - - @Override - public MembersInjector getMembersInjector(final TypeLiteral typeLiteral) { -- final MembersInjectorLookup element = new MembersInjectorLookup(getElementSource(), -- MoreTypes.canonicalizeForKey(typeLiteral)); -+ final MembersInjectorLookup element -+ = new MembersInjectorLookup(getElementSource(), typeLiteral); - elements.add(element); - return element.getMembersInjector(); - } -@@ -372,8 +370,7 @@ public final class Elements { - } - - public AnnotatedBindingBuilder bind(Key key) { -- BindingBuilder builder = -- new BindingBuilder(this, elements, getElementSource(), MoreTypes.canonicalizeKey(key)); -+ BindingBuilder builder = new BindingBuilder(this, elements, getElementSource(), key); - return builder; - } - -@@ -483,8 +480,7 @@ public final class Elements { - }; - } - -- ExposureBuilder builder = -- new ExposureBuilder(this, getElementSource(), MoreTypes.canonicalizeKey(key)); -+ ExposureBuilder builder = new ExposureBuilder(this, getElementSource(), key); - privateElements.addExposureBuilder(builder); - return builder; - } -diff --git a/core/test/com/google/inject/Asserts.java b/core/test/com/google/inject/Asserts.java -index 6c63158..363e161 100644 ---- a/core/test/com/google/inject/Asserts.java -+++ b/core/test/com/google/inject/Asserts.java -@@ -21,14 +21,12 @@ import static com.google.inject.internal.InternalFlags.IncludeStackTraceOption; - import static com.google.inject.internal.InternalFlags.getIncludeStackTraceOption; - import static junit.framework.Assert.assertEquals; - import static junit.framework.Assert.assertNotNull; --import static junit.framework.Assert.assertSame; - import static junit.framework.Assert.assertTrue; - - import com.google.common.base.Function; - import com.google.common.base.Joiner; - import com.google.common.collect.ImmutableList; - import com.google.common.collect.Iterables; --import com.google.common.testing.GcFinalization; - - import junit.framework.Assert; - -@@ -38,8 +36,6 @@ import java.io.IOException; - import java.io.NotSerializableException; - import java.io.ObjectInputStream; - import java.io.ObjectOutputStream; --import java.lang.ref.ReferenceQueue; --import java.lang.ref.WeakReference; - - /** - * @author jessewilson@google.com (Jesse Wilson) -@@ -163,42 +159,4 @@ public class Asserts { - } catch (NotSerializableException expected) { - } - } -- -- public static void awaitFullGc() { -- // GcFinalization *should* do it, but doesn't work well in practice... -- // so we put a second latch and wait for a ReferenceQueue to tell us. -- ReferenceQueue queue = new ReferenceQueue(); -- WeakReference ref = new WeakReference(new Object(), queue); -- GcFinalization.awaitFullGc(); -- try { -- assertSame("queue didn't return ref in time", ref, queue.remove(5000)); -- } catch (IllegalArgumentException e) { -- throw new RuntimeException(e); -- } catch (InterruptedException e) { -- throw new RuntimeException(e); -- } -- } -- -- public static void awaitClear(WeakReference ref) { -- // GcFinalization *should* do it, but doesn't work well in practice... -- // so we put a second latch and wait for a ReferenceQueue to tell us. -- Object data = ref.get(); -- ReferenceQueue queue = null; -- WeakReference extraRef = null; -- if (data != null) { -- queue = new ReferenceQueue(); -- extraRef = new WeakReference(data, queue); -- data = null; -- } -- GcFinalization.awaitClear(ref); -- if (queue != null) { -- try { -- assertSame("queue didn't return ref in time", extraRef, queue.remove(5000)); -- } catch (IllegalArgumentException e) { -- throw new RuntimeException(e); -- } catch (InterruptedException e) { -- throw new RuntimeException(e); -- } -- } -- } - } -diff --git a/core/test/com/google/inject/KeyTest.java b/core/test/com/google/inject/KeyTest.java -index d9dd943..c0401e0 100644 ---- a/core/test/com/google/inject/KeyTest.java -+++ b/core/test/com/google/inject/KeyTest.java -@@ -19,12 +19,10 @@ package com.google.inject; - import static com.google.inject.Asserts.assertContains; - import static com.google.inject.Asserts.assertEqualsBothWays; - import static com.google.inject.Asserts.assertNotSerializable; --import static com.google.inject.Asserts.awaitClear; - import static java.lang.annotation.RetentionPolicy.RUNTIME; - - import com.google.inject.name.Named; - import com.google.inject.name.Names; --import com.google.inject.spi.Dependency; - import com.google.inject.util.Types; - - import junit.framework.TestCase; -@@ -33,15 +31,12 @@ import java.io.IOException; - import java.lang.annotation.ElementType; - import java.lang.annotation.Retention; - import java.lang.annotation.Target; --import java.lang.ref.WeakReference; - import java.lang.reflect.Method; - import java.lang.reflect.ParameterizedType; - import java.lang.reflect.Type; - import java.lang.reflect.TypeVariable; --import java.util.ArrayList; - import java.util.List; - import java.util.Map; --import java.util.concurrent.atomic.AtomicReference; - - /** - * @author crazybob@google.com (Bob Lee) -@@ -280,42 +275,4 @@ public class KeyTest extends TestCase { - @Marker - class HasAnnotations {} - -- public void testAnonymousClassesDontHoldRefs() { -- final AtomicReference>> stringProvider = -- new AtomicReference>>(); -- final AtomicReference>> intProvider = -- new AtomicReference>>(); -- final Object foo = new Object() { -- @SuppressWarnings("unused") @Inject List list; -- }; -- Module module = new AbstractModule() { -- @Override protected void configure() { -- bind(new Key>() {}).toInstance(new ArrayList()); -- bind(new TypeLiteral>() {}).toInstance(new ArrayList()); -- -- stringProvider.set(getProvider(new Key>() {})); -- intProvider.set(binder().getProvider(Dependency.get(new Key>() {}))); -- -- binder().requestInjection(new TypeLiteral() {}, foo); -- } -- }; -- WeakReference moduleRef = new WeakReference(module); -- final Injector injector = Guice.createInjector(module); -- module = null; -- awaitClear(moduleRef); // Make sure anonymous keys & typeliterals don't hold the module. -- -- Runnable runner = new Runnable() { -- @Override public void run() { -- injector.getInstance(new Key>() {}); -- injector.getInstance(Key.get(new TypeLiteral>() {})); -- } -- }; -- WeakReference runnerRef = new WeakReference(runner); -- runner.run(); -- runner = null; -- awaitClear(runnerRef); // also make sure anonymous keys & typeliterals don't hold for JITs -- } -- -- static class Typed {} -- - } -diff --git a/core/test/com/google/inject/internal/WeakKeySetTest.java b/core/test/com/google/inject/internal/WeakKeySetTest.java -index 4a81ebb..3797d88 100644 ---- a/core/test/com/google/inject/internal/WeakKeySetTest.java -+++ b/core/test/com/google/inject/internal/WeakKeySetTest.java -@@ -16,13 +16,13 @@ - - package com.google.inject.internal; - --import static com.google.inject.Asserts.awaitClear; --import static com.google.inject.Asserts.awaitFullGc; - import static com.google.inject.internal.WeakKeySetUtils.assertBlacklisted; - import static com.google.inject.internal.WeakKeySetUtils.assertInSet; - import static com.google.inject.internal.WeakKeySetUtils.assertNotBlacklisted; - import static com.google.inject.internal.WeakKeySetUtils.assertNotInSet; - import static com.google.inject.internal.WeakKeySetUtils.assertSourceNotInSet; -+import static com.google.inject.internal.WeakKeySetUtils.awaitClear; -+import static com.google.inject.internal.WeakKeySetUtils.awaitFullGc; - - import com.google.common.collect.ImmutableList; - import com.google.common.collect.ImmutableMap; -@@ -34,6 +34,13 @@ import com.google.inject.Injector; - import com.google.inject.Key; - import com.google.inject.Scope; - import com.google.inject.TypeLiteral; -+import com.google.inject.internal.BindingImpl; -+import com.google.inject.internal.Errors; -+/*if[AOP]*/ -+import com.google.inject.internal.MethodAspect; -+/*end[AOP]*/ -+import com.google.inject.internal.State; -+import com.google.inject.internal.WeakKeySet; - import com.google.inject.spi.ModuleAnnotatedMethodScannerBinding; - import com.google.inject.spi.ProvisionListenerBinding; - import com.google.inject.spi.ScopeBinding; -diff --git a/core/test/com/google/inject/internal/WeakKeySetUtils.java b/core/test/com/google/inject/internal/WeakKeySetUtils.java -index b023aa1..bab9e92 100644 ---- a/core/test/com/google/inject/internal/WeakKeySetUtils.java -+++ b/core/test/com/google/inject/internal/WeakKeySetUtils.java -@@ -18,11 +18,15 @@ import static junit.framework.Assert.assertEquals; - import static junit.framework.Assert.assertFalse; - import static junit.framework.Assert.assertNotNull; - import static junit.framework.Assert.assertNull; -+import static junit.framework.Assert.assertSame; - import static junit.framework.Assert.assertTrue; - -+import com.google.common.testing.GcFinalization; - import com.google.inject.Injector; - import com.google.inject.Key; - -+import java.lang.ref.ReferenceQueue; -+import java.lang.ref.WeakReference; - import java.util.Set; - - /** -@@ -34,6 +38,44 @@ public final class WeakKeySetUtils { - - private WeakKeySetUtils() {} - -+ public static void awaitFullGc() { -+ // GcFinalization *should* do it, but doesn't work well in practice... -+ // so we put a second latch and wait for a ReferenceQueue to tell us. -+ ReferenceQueue queue = new ReferenceQueue(); -+ WeakReference ref = new WeakReference(new Object(), queue); -+ GcFinalization.awaitFullGc(); -+ try { -+ assertSame("queue didn't return ref in time", ref, queue.remove(5000)); -+ } catch (IllegalArgumentException e) { -+ throw new RuntimeException(e); -+ } catch (InterruptedException e) { -+ throw new RuntimeException(e); -+ } -+ } -+ -+ public static void awaitClear(WeakReference ref) { -+ // GcFinalization *should* do it, but doesn't work well in practice... -+ // so we put a second latch and wait for a ReferenceQueue to tell us. -+ Object data = ref.get(); -+ ReferenceQueue queue = null; -+ WeakReference extraRef = null; -+ if (data != null) { -+ queue = new ReferenceQueue(); -+ extraRef = new WeakReference(data, queue); -+ data = null; -+ } -+ GcFinalization.awaitClear(ref); -+ if (queue != null) { -+ try { -+ assertSame("queue didn't return ref in time", extraRef, queue.remove(5000)); -+ } catch (IllegalArgumentException e) { -+ throw new RuntimeException(e); -+ } catch (InterruptedException e) { -+ throw new RuntimeException(e); -+ } -+ } -+ } -+ - public static void assertBlacklisted(Injector injector, Key key) { - assertBlacklistState(injector, key, true); - } -diff --git a/extensions/multibindings/test/com/google/inject/multibindings/MapBinderTest.java b/extensions/multibindings/test/com/google/inject/multibindings/MapBinderTest.java -index 4206521..849993f 100644 ---- a/extensions/multibindings/test/com/google/inject/multibindings/MapBinderTest.java -+++ b/extensions/multibindings/test/com/google/inject/multibindings/MapBinderTest.java -@@ -32,7 +32,6 @@ import com.google.common.collect.Iterables; - import com.google.common.collect.Maps; - import com.google.common.collect.Sets; - import com.google.inject.AbstractModule; --import com.google.inject.Asserts; - import com.google.inject.Binding; - import com.google.inject.BindingAnnotation; - import com.google.inject.ConfigurationException; -@@ -1026,7 +1025,7 @@ public class MapBinderTest extends TestCase { - // Clear the ref, GC, and ensure that we are no longer blacklisting. - childInjector = null; - -- Asserts.awaitClear(weakRef); -+ WeakKeySetUtils.awaitClear(weakRef); - WeakKeySetUtils.assertNotBlacklisted(parentInjector, mapKey); - } - } -diff --git a/extensions/multibindings/test/com/google/inject/multibindings/OptionalBinderTest.java b/extensions/multibindings/test/com/google/inject/multibindings/OptionalBinderTest.java -index f3c9f63..d0a239a 100644 ---- a/extensions/multibindings/test/com/google/inject/multibindings/OptionalBinderTest.java -+++ b/extensions/multibindings/test/com/google/inject/multibindings/OptionalBinderTest.java -@@ -30,7 +30,6 @@ import com.google.common.collect.Iterables; - import com.google.common.collect.Lists; - import com.google.common.collect.Sets; - import com.google.inject.AbstractModule; --import com.google.inject.Asserts; - import com.google.inject.Binding; - import com.google.inject.BindingAnnotation; - import com.google.inject.CreationException; -@@ -1204,7 +1203,7 @@ public class OptionalBinderTest extends TestCase { - // Clear the ref, GC, and ensure that we are no longer blacklisting. - childInjector = null; - -- Asserts.awaitClear(weakRef); -+ WeakKeySetUtils.awaitClear(weakRef); - WeakKeySetUtils.assertNotBlacklisted(parentInjector, Key.get(Integer.class)); - } - --- -2.1.0 - diff --git a/GUICE_492_slf4j_logger_injection.patch b/GUICE_492_slf4j_logger_injection.patch deleted file mode 100644 index b6aefa5..0000000 --- a/GUICE_492_slf4j_logger_injection.patch +++ /dev/null @@ -1,153 +0,0 @@ -Description: Provide built-in injection of SLF4J loggers -Author: Stuart McCulloch -Bug-Google: http://code.google.com/p/google-guice/issues/detail?id=492 -Last-Update: 2014-11-07 - -diff --git a/common.xml b/common.xml -index a23eb90..2d3d9b3 100644 ---- a/common.xml -+++ b/common.xml -@@ -44,6 +44,10 @@ - - - -+ -+ -+ -+ - - - -diff --git a/core/pom.xml b/core/pom.xml -index 33e6dcc..edfa724 100644 ---- a/core/pom.xml -+++ b/core/pom.xml -@@ -15,6 +15,12 @@ - - - -+ org.slf4j -+ slf4j-api -+ 1.6.4 -+ true -+ -+ - javax.inject - javax.inject - -@@ -91,6 +97,12 @@ - maven-surefire-plugin - - -+ -+ org.slf4j:slf4j-api -+ -+ - -@@ -113,6 +125,7 @@ - ${project.artifactId}$(if;$(classes;NAMED;*.MethodAspect);; (no_aop)) - !net.sf.cglib.*,!org.objectweb.asm.*,!com.google.inject.*,* - true -+ org.slf4j - - - -diff --git a/core/src/com/google/inject/internal/InjectorShell.java b/core/src/com/google/inject/internal/InjectorShell.java -index 6100879..56b13b3 100644 ---- a/core/src/com/google/inject/internal/InjectorShell.java -+++ b/core/src/com/google/inject/internal/InjectorShell.java -@@ -251,6 +251,15 @@ final class InjectorShell { - new ProviderInstanceBindingImpl(injector, key, - SourceProvider.UNKNOWN_SOURCE, loggerFactory, Scoping.UNSCOPED, - loggerFactory, ImmutableSet.of())); -+ -+ try { -+ Key slf4jKey = Key.get(org.slf4j.Logger.class); -+ SLF4JLoggerFactory slf4jLoggerFactory = new SLF4JLoggerFactory(injector); -+ injector.state.putBinding(slf4jKey, -+ new ProviderInstanceBindingImpl(injector, slf4jKey, -+ SourceProvider.UNKNOWN_SOURCE, slf4jLoggerFactory, Scoping.UNSCOPED, -+ slf4jLoggerFactory, ImmutableSet.of())); -+ } catch (Throwable e) {} - } - - private static class LoggerFactory implements InternalFactory, Provider { -@@ -270,6 +279,44 @@ final class InjectorShell { - } - } - -+ private static class SLF4JLoggerFactory implements InternalFactory, Provider { -+ private final Injector injector; -+ -+ private org.slf4j.ILoggerFactory loggerFactory; -+ -+ SLF4JLoggerFactory(Injector injector) { -+ this.injector = injector; -+ } -+ -+ org.slf4j.ILoggerFactory loggerFactory() { -+ if (loggerFactory == null) { -+ try { -+ loggerFactory = injector.getInstance(org.slf4j.ILoggerFactory.class); -+ } catch (Throwable e) {} -+ if (loggerFactory == null) { -+ loggerFactory = org.slf4j.LoggerFactory.getILoggerFactory(); -+ } -+ } -+ return loggerFactory; -+ } -+ -+ public org.slf4j.Logger get(Errors errors, InternalContext context, Dependency dependency, boolean linked) { -+ InjectionPoint injectionPoint = dependency.getInjectionPoint(); -+ if (injectionPoint != null) { -+ return loggerFactory().getLogger(injectionPoint.getMember().getDeclaringClass().getName()); -+ } -+ return loggerFactory().getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); -+ } -+ -+ public org.slf4j.Logger get() { -+ return loggerFactory().getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); -+ } -+ -+ public String toString() { -+ return "Provider"; -+ } -+ } -+ - private static void bindStage(InjectorImpl injector, Stage stage) { - Key key = Key.get(Stage.class); - InstanceBindingImpl stageBinding = new InstanceBindingImpl( -diff --git a/extensions/persist/pom.xml b/extensions/persist/pom.xml -index a560f38..e909927 100644 ---- a/extensions/persist/pom.xml -+++ b/extensions/persist/pom.xml -@@ -29,7 +29,7 @@ - - org.slf4j - slf4j-simple -- 1.6.1 -+ 1.6.4 - test - - -diff --git a/lib/build/slf4j-api-1.6.4.jar b/lib/build/slf4j-api-1.6.4.jar -new file mode 100644 -index 0000000..76ef305 -Binary files /dev/null and b/lib/build/slf4j-api-1.6.4.jar differ -diff --git a/pom.xml b/pom.xml -index 37305d0..5834d49 100644 ---- a/pom.xml -+++ b/pom.xml -@@ -283,7 +283,7 @@ See the Apache License Version 2.0 for the specific language governing permissio - - - maven-surefire-plugin -- 2.5 -+ 2.6 - - true - diff --git a/GUICE_618_extensible_filter_pipeline.patch b/GUICE_618_extensible_filter_pipeline.patch deleted file mode 100644 index bbad0e7..0000000 --- a/GUICE_618_extensible_filter_pipeline.patch +++ /dev/null @@ -1,1053 +0,0 @@ -Description: Let sub-classes of GuiceFilter customize the servlet filter pipeline -Author: Stuart McCulloch -Bug-Google: http://code.google.com/p/google-guice/issues/detail?id=618 -Last-Update: 2015-01-20 - -diff --git a/extensions/servlet/src/com/google/inject/servlet/AbstractFilterPipeline.java b/extensions/servlet/src/com/google/inject/servlet/AbstractFilterPipeline.java -new file mode 100644 -index 0000000..ab8f746 ---- /dev/null -+++ b/extensions/servlet/src/com/google/inject/servlet/AbstractFilterPipeline.java -@@ -0,0 +1,150 @@ -+/** -+ * Copyright (C) 2008 Google Inc. -+ * -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+package com.google.inject.servlet; -+ -+import com.google.common.collect.Sets; -+import com.google.inject.Injector; -+import com.google.inject.Provider; -+ -+import java.io.IOException; -+import java.util.Set; -+ -+import javax.servlet.Filter; -+import javax.servlet.FilterChain; -+import javax.servlet.RequestDispatcher; -+import javax.servlet.ServletContext; -+import javax.servlet.ServletException; -+import javax.servlet.ServletRequest; -+import javax.servlet.ServletResponse; -+import javax.servlet.http.HttpServletRequest; -+import javax.servlet.http.HttpServletRequestWrapper; -+ -+/** -+ * Skeleton implementation of a central routing/dispatch class which uses a sequence of -+ * {@link FilterDefinition}s to filter requests before delegating to the servlet pipeline. -+ * -+ * @author dhanji@gmail.com (Dhanji R. Prasanna) -+ */ -+public abstract class AbstractFilterPipeline implements FilterPipeline { -+ -+ private final AbstractServletPipeline servletPipeline; -+ private final Provider servletContext; -+ -+ //Unfortunately, we need the injector itself in order to create filters + servlets -+ private final Injector injector; -+ -+ //Guards a DCL, so needs to be volatile -+ private volatile boolean initialized = false; -+ -+ protected AbstractFilterPipeline(Injector injector, AbstractServletPipeline servletPipeline, -+ Provider servletContext) { -+ this.injector = injector; -+ this.servletPipeline = servletPipeline; -+ this.servletContext = servletContext; -+ } -+ -+ /** -+ * @return {@code true} if any filter mappings exist; otherwise {@code false} -+ */ -+ protected abstract boolean hasFiltersMapped(); -+ -+ /** -+ * @return snapshot of the filter mappings currently defined for this pipeline -+ */ -+ protected abstract FilterDefinition[] filterDefinitions(); -+ -+ public synchronized void initPipeline(ServletContext servletContext) -+ throws ServletException { -+ -+ //double-checked lock, prevents duplicate initialization -+ if (initialized) -+ return; -+ -+ // Used to prevent duplicate initialization. -+ Set initializedSoFar = Sets.newIdentityHashSet(); -+ -+ for (FilterDefinition filterDefinition : filterDefinitions()) { -+ filterDefinition.init(servletContext, injector, initializedSoFar); -+ } -+ -+ //next, initialize servlets... -+ servletPipeline.init(servletContext, injector); -+ -+ //everything was ok... -+ initialized = true; -+ } -+ -+ public void dispatch(ServletRequest request, ServletResponse response, -+ FilterChain proceedingFilterChain) throws IOException, ServletException { -+ -+ //lazy init of filter pipeline (OK by the servlet specification). This is needed -+ //in order for us not to force users to create a GuiceServletContextListener subclass. -+ if (!initialized) { -+ initPipeline(servletContext.get()); -+ } -+ -+ //obtain the servlet pipeline to dispatch against -+ new FilterChainInvocation(filterDefinitions(), servletPipeline, proceedingFilterChain) -+ .doFilter(withDispatcher(request, servletPipeline), response); -+ -+ } -+ -+ /** -+ * Used to create an proxy that dispatches either to the guice-servlet pipeline or the regular -+ * pipeline based on uri-path match. This proxy also provides minimal forwarding support. -+ * -+ * We cannot forward from a web.xml Servlet/JSP to a guice-servlet (because the filter pipeline -+ * is not called again). However, we can wrap requests with our own dispatcher to forward the -+ * *other* way. web.xml Servlets/JSPs can forward to themselves as per normal. -+ * -+ * This is not a problem cuz we intend for people to migrate from web.xml to guice-servlet, -+ * incrementally, but not the other way around (which, we should actively discourage). -+ */ -+ @SuppressWarnings({ "JavaDoc", "deprecation" }) -+ private ServletRequest withDispatcher(ServletRequest servletRequest, -+ final AbstractServletPipeline servletPipeline) { -+ -+ // don't wrap the request if there are no servlets mapped. This prevents us from inserting our -+ // wrapper unless it's actually going to be used. This is necessary for compatibility for apps -+ // that downcast their HttpServletRequests to a concrete implementation. -+ if (!servletPipeline.hasServletsMapped()) { -+ return servletRequest; -+ } -+ -+ HttpServletRequest request = (HttpServletRequest) servletRequest; -+ //noinspection OverlyComplexAnonymousInnerClass -+ return new HttpServletRequestWrapper(request) { -+ -+ @Override -+ public RequestDispatcher getRequestDispatcher(String path) { -+ final RequestDispatcher dispatcher = servletPipeline.getRequestDispatcher(path); -+ -+ return (null != dispatcher) ? dispatcher : super.getRequestDispatcher(path); -+ } -+ }; -+ } -+ -+ public void destroyPipeline() { -+ //destroy servlets first -+ servletPipeline.destroy(); -+ -+ //go down chain and destroy all our filters -+ Set destroyedSoFar = Sets.newIdentityHashSet(); -+ for (FilterDefinition filterDefinition : filterDefinitions()) { -+ filterDefinition.destroy(destroyedSoFar); -+ } -+ } -+} -diff --git a/extensions/servlet/src/com/google/inject/servlet/AbstractServletPipeline.java b/extensions/servlet/src/com/google/inject/servlet/AbstractServletPipeline.java -new file mode 100644 -index 0000000..811820a ---- /dev/null -+++ b/extensions/servlet/src/com/google/inject/servlet/AbstractServletPipeline.java -@@ -0,0 +1,187 @@ -+/** -+ * Copyright (C) 2008 Google Inc. -+ * -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ */ -+package com.google.inject.servlet; -+ -+import com.google.common.base.Preconditions; -+import com.google.common.collect.Sets; -+import com.google.inject.Injector; -+ -+import java.io.IOException; -+import java.util.Set; -+ -+import javax.servlet.RequestDispatcher; -+import javax.servlet.ServletContext; -+import javax.servlet.ServletException; -+import javax.servlet.ServletRequest; -+import javax.servlet.ServletResponse; -+import javax.servlet.http.HttpServlet; -+import javax.servlet.http.HttpServletRequest; -+import javax.servlet.http.HttpServletRequestWrapper; -+ -+/** -+ * Skeleton implementation of a wrapping dispatcher for servlets based on a sequence of -+ * {@link ServletDefinition}s, much like {@link AbstractFilterPipeline} is for filters. -+ * -+ * @author dhanji@gmail.com (Dhanji R. Prasanna) -+ */ -+public abstract class AbstractServletPipeline { -+ -+ /** -+ * @return {@code true} if any servlet mappings exist; otherwise {@code false} -+ */ -+ protected abstract boolean hasServletsMapped(); -+ -+ /** -+ * @return snapshot of the servlet mappings currently defined for this pipeline -+ */ -+ protected abstract ServletDefinition[] servletDefinitions(); -+ -+ void init(ServletContext servletContext, Injector injector) throws ServletException { -+ Set initializedSoFar = Sets.newIdentityHashSet(); -+ -+ for (ServletDefinition servletDefinition : servletDefinitions()) { -+ servletDefinition.init(servletContext, injector, initializedSoFar); -+ } -+ } -+ -+ boolean service(ServletRequest request, ServletResponse response) -+ throws IOException, ServletException { -+ -+ //stop at the first matching servlet and service -+ for (ServletDefinition servletDefinition : servletDefinitions()) { -+ if (servletDefinition.service(request, response)) { -+ return true; -+ } -+ } -+ -+ //there was no match... -+ return false; -+ } -+ -+ void destroy() { -+ Set destroyedSoFar = Sets.newIdentityHashSet(); -+ for (ServletDefinition servletDefinition : servletDefinitions()) { -+ servletDefinition.destroy(destroyedSoFar); -+ } -+ } -+ -+ /** -+ * @return Returns a request dispatcher wrapped with a servlet mapped to -+ * the given path or null if no mapping was found. -+ */ -+ RequestDispatcher getRequestDispatcher(String path) { -+ final String newRequestUri = path; -+ -+ // TODO(dhanji): check servlet spec to see if the following is legal or not. -+ // Need to strip query string if requested... -+ -+ for (final ServletDefinition servletDefinition : servletDefinitions()) { -+ if (servletDefinition.shouldServe(path)) { -+ return new RequestDispatcher() { -+ public void forward(ServletRequest servletRequest, ServletResponse servletResponse) -+ throws ServletException, IOException { -+ Preconditions.checkState(!servletResponse.isCommitted(), -+ "Response has been committed--you can only call forward before" -+ + " committing the response (hint: don't flush buffers)"); -+ -+ // clear buffer before forwarding -+ servletResponse.resetBuffer(); -+ -+ ServletRequest requestToProcess; -+ if (servletRequest instanceof HttpServletRequest) { -+ requestToProcess = wrapRequest((HttpServletRequest)servletRequest, newRequestUri); -+ } else { -+ // This should never happen, but instead of throwing an exception -+ // we will allow a happy case pass thru for maximum tolerance to -+ // legacy (and internal) code. -+ requestToProcess = servletRequest; -+ } -+ -+ // now dispatch to the servlet -+ doServiceImpl(servletDefinition, requestToProcess, servletResponse); -+ } -+ -+ public void include(ServletRequest servletRequest, ServletResponse servletResponse) -+ throws ServletException, IOException { -+ // route to the target servlet -+ doServiceImpl(servletDefinition, servletRequest, servletResponse); -+ } -+ -+ private void doServiceImpl(ServletDefinition servletDefinition, ServletRequest servletRequest, -+ ServletResponse servletResponse) throws ServletException, IOException { -+ servletRequest.setAttribute(REQUEST_DISPATCHER_REQUEST, Boolean.TRUE); -+ -+ try { -+ servletDefinition.doService(servletRequest, servletResponse); -+ } finally { -+ servletRequest.removeAttribute(REQUEST_DISPATCHER_REQUEST); -+ } -+ } -+ }; -+ } -+ } -+ -+ //otherwise, can't process -+ return null; -+ } -+ -+ // visible for testing -+ static HttpServletRequest wrapRequest(HttpServletRequest request, String newUri) { -+ return new RequestDispatcherRequestWrapper(request, newUri); -+ } -+ -+ /** -+ * A Marker constant attribute that when present in the request indicates to Guice servlet that -+ * this request has been generated by a request dispatcher rather than the servlet pipeline. -+ * In accordance with section 8.4.2 of the Servlet 2.4 specification. -+ */ -+ static final String REQUEST_DISPATCHER_REQUEST = "javax.servlet.forward.servlet_path"; -+ -+ private static class RequestDispatcherRequestWrapper extends HttpServletRequestWrapper { -+ private final String newRequestUri; -+ -+ RequestDispatcherRequestWrapper(HttpServletRequest servletRequest, String newRequestUri) { -+ super(servletRequest); -+ this.newRequestUri = newRequestUri; -+ } -+ -+ @Override -+ public String getRequestURI() { -+ return newRequestUri; -+ } -+ -+ @Override -+ public StringBuffer getRequestURL() { -+ StringBuffer url = new StringBuffer(); -+ String scheme = getScheme(); -+ int port = getServerPort(); -+ -+ url.append(scheme); -+ url.append("://"); -+ url.append(getServerName()); -+ // port might be -1 in some cases (see java.net.URL.getPort) -+ if (port > 0 && -+ (("http".equals(scheme) && (port != 80)) || -+ ("https".equals(scheme) && (port != 443)))) { -+ url.append(':'); -+ url.append(port); -+ } -+ url.append(getRequestURI()); -+ -+ return (url); -+ } -+ } -+} -diff --git a/extensions/servlet/src/com/google/inject/servlet/FilterChainInvocation.java b/extensions/servlet/src/com/google/inject/servlet/FilterChainInvocation.java -index b4112cf..bfe5a83 100644 ---- a/extensions/servlet/src/com/google/inject/servlet/FilterChainInvocation.java -+++ b/extensions/servlet/src/com/google/inject/servlet/FilterChainInvocation.java -@@ -50,7 +50,7 @@ class FilterChainInvocation implements FilterChain { - - private final FilterDefinition[] filterDefinitions; - private final FilterChain proceedingChain; -- private final ManagedServletPipeline servletPipeline; -+ private final AbstractServletPipeline servletPipeline; - - //state variable tracks current link in filterchain - private int index = -1; -@@ -58,7 +58,7 @@ class FilterChainInvocation implements FilterChain { - private boolean cleanedStacks = false; - - public FilterChainInvocation(FilterDefinition[] filterDefinitions, -- ManagedServletPipeline servletPipeline, FilterChain proceedingChain) { -+ AbstractServletPipeline servletPipeline, FilterChain proceedingChain) { - - this.filterDefinitions = filterDefinitions; - this.servletPipeline = servletPipeline; -diff --git a/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java b/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java -index ff1e5b6..76ece31 100644 ---- a/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java -+++ b/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java -@@ -37,11 +37,11 @@ import javax.servlet.ServletException; - import javax.servlet.http.HttpServletRequest; - - /** -- * An internal representation of a filter definition against a particular URI pattern. -+ * Defines a filter mapped to a URI pattern and performs the request filtering for that filter. - * - * @author dhanji@gmail.com (Dhanji R. Prasanna) - */ --class FilterDefinition implements ProviderWithExtensionVisitor { -+public class FilterDefinition implements ProviderWithExtensionVisitor { - private final String pattern; - private final Key filterKey; - private final UriPatternMatcher patternMatcher; -@@ -90,7 +90,7 @@ class FilterDefinition implements ProviderWithExtensionVisitor - return uri != null && patternMatcher.matches(uri); - } - -- public void init(final ServletContext servletContext, Injector injector, -+ void init(final ServletContext servletContext, Injector injector, - Set initializedSoFar) throws ServletException { - - // This absolutely must be a singleton, and so is only initialized once. -@@ -130,7 +130,7 @@ class FilterDefinition implements ProviderWithExtensionVisitor - initializedSoFar.add(filter); - } - -- public void destroy(Set destroyedSoFar) { -+ void destroy(Set destroyedSoFar) { - // filters are always singletons - Filter reference = filter.get(); - -@@ -150,7 +150,7 @@ class FilterDefinition implements ProviderWithExtensionVisitor - } - } - -- public Filter getFilterIfMatching(HttpServletRequest request) { -+ Filter getFilterIfMatching(HttpServletRequest request) { - - final String path = ServletUtils.getContextRelativePath(request); - if (shouldFilter(path)) { -diff --git a/extensions/servlet/src/com/google/inject/servlet/FilterPipeline.java b/extensions/servlet/src/com/google/inject/servlet/FilterPipeline.java -index 985064b..c745d20 100644 ---- a/extensions/servlet/src/com/google/inject/servlet/FilterPipeline.java -+++ b/extensions/servlet/src/com/google/inject/servlet/FilterPipeline.java -@@ -26,7 +26,7 @@ import javax.servlet.ServletRequest; - import javax.servlet.ServletResponse; - - /** -- * An internal dispatcher for guice-servlet registered servlets and filters. -+ * A dispatcher abstraction for guice-servlet registered servlets and filters. - * By default, we assume a Guice 1.0 style servlet module is in play. In other - * words, we dispatch directly to the web.xml pipeline after setting up scopes. - * -@@ -39,10 +39,27 @@ import javax.servlet.ServletResponse; - * @author dhanji@gmail.com (Dhanji R. Prasanna) - */ - @ImplementedBy(DefaultFilterPipeline.class) --interface FilterPipeline { -+public interface FilterPipeline { -+ -+ /** -+ * Initializes the pipeline, putting it into service. -+ * -+ * @param context of the web application -+ */ - void initPipeline(ServletContext context) throws ServletException; -+ -+ /** -+ * Destroys the pipeline, taking it out of service. -+ */ - void destroyPipeline(); - -+ /** -+ * Dispatches a request against the pipeline. -+ * -+ * @param request to dispatch -+ * @param response to populate -+ * @param defaultFilterChain for last resort filtering -+ */ - void dispatch(ServletRequest request, ServletResponse response, - FilterChain defaultFilterChain) throws IOException, ServletException; - } -diff --git a/extensions/servlet/src/com/google/inject/servlet/GuiceFilter.java b/extensions/servlet/src/com/google/inject/servlet/GuiceFilter.java -index ba7a5af..0737b38 100644 ---- a/extensions/servlet/src/com/google/inject/servlet/GuiceFilter.java -+++ b/extensions/servlet/src/com/google/inject/servlet/GuiceFilter.java -@@ -89,7 +89,7 @@ public class GuiceFilter implements Filter { - this(null); - } - -- @Inject GuiceFilter(FilterPipeline filterPipeline) { -+ @Inject protected GuiceFilter(FilterPipeline filterPipeline) { - injectedPipeline = filterPipeline; - } - -diff --git a/extensions/servlet/src/com/google/inject/servlet/ManagedFilterPipeline.java b/extensions/servlet/src/com/google/inject/servlet/ManagedFilterPipeline.java -index 538e10a..76bc269 100644 ---- a/extensions/servlet/src/com/google/inject/servlet/ManagedFilterPipeline.java -+++ b/extensions/servlet/src/com/google/inject/servlet/ManagedFilterPipeline.java -@@ -16,7 +16,6 @@ - package com.google.inject.servlet; - - import com.google.common.collect.Lists; --import com.google.common.collect.Sets; - import com.google.inject.Binding; - import com.google.inject.Inject; - import com.google.inject.Injector; -@@ -24,50 +23,41 @@ import com.google.inject.Provider; - import com.google.inject.Singleton; - import com.google.inject.TypeLiteral; - --import java.io.IOException; - import java.util.List; --import java.util.Set; - --import javax.servlet.Filter; --import javax.servlet.FilterChain; --import javax.servlet.RequestDispatcher; - import javax.servlet.ServletContext; --import javax.servlet.ServletException; --import javax.servlet.ServletRequest; --import javax.servlet.ServletResponse; --import javax.servlet.http.HttpServletRequest; --import javax.servlet.http.HttpServletRequestWrapper; - - /** -- * Central routing/dispatch class handles lifecycle of managed filters, and delegates to the servlet -- * pipeline. -+ * Managed implementation of a central routing/dispatch class which handles lifecycle of managed -+ * filters, and delegates to a managed servlet pipeline. - * - * @author dhanji@gmail.com (Dhanji R. Prasanna) - */ - @Singleton --class ManagedFilterPipeline implements FilterPipeline{ -+class ManagedFilterPipeline extends AbstractFilterPipeline { - private final FilterDefinition[] filterDefinitions; -- private final ManagedServletPipeline servletPipeline; -- private final Provider servletContext; - -- //Unfortunately, we need the injector itself in order to create filters + servlets -- private final Injector injector; -- -- //Guards a DCL, so needs to be volatile -- private volatile boolean initialized = false; - private static final TypeLiteral FILTER_DEFS = - TypeLiteral.get(FilterDefinition.class); - - @Inject - public ManagedFilterPipeline(Injector injector, ManagedServletPipeline servletPipeline, - Provider servletContext) { -- this.injector = injector; -- this.servletPipeline = servletPipeline; -- this.servletContext = servletContext; -+ super(injector, servletPipeline, servletContext); - - this.filterDefinitions = collectFilterDefinitions(injector); - } - -+ @Override -+ protected boolean hasFiltersMapped() { -+ return filterDefinitions.length > 0; -+ } -+ -+ @Override -+ protected FilterDefinition[] filterDefinitions() { -+ return filterDefinitions; -+ } -+ - /** - * Introspects the injector and collects all instances of bound {@code List} - * into a master list. -@@ -84,86 +74,4 @@ class ManagedFilterPipeline implements FilterPipeline{ - // Copy to a fixed-size array for speed of iteration. - return filterDefinitions.toArray(new FilterDefinition[filterDefinitions.size()]); - } -- -- public synchronized void initPipeline(ServletContext servletContext) -- throws ServletException { -- -- //double-checked lock, prevents duplicate initialization -- if (initialized) -- return; -- -- // Used to prevent duplicate initialization. -- Set initializedSoFar = Sets.newIdentityHashSet(); -- -- for (FilterDefinition filterDefinition : filterDefinitions) { -- filterDefinition.init(servletContext, injector, initializedSoFar); -- } -- -- //next, initialize servlets... -- servletPipeline.init(servletContext, injector); -- -- //everything was ok... -- initialized = true; -- } -- -- public void dispatch(ServletRequest request, ServletResponse response, -- FilterChain proceedingFilterChain) throws IOException, ServletException { -- -- //lazy init of filter pipeline (OK by the servlet specification). This is needed -- //in order for us not to force users to create a GuiceServletContextListener subclass. -- if (!initialized) { -- initPipeline(servletContext.get()); -- } -- -- //obtain the servlet pipeline to dispatch against -- new FilterChainInvocation(filterDefinitions, servletPipeline, proceedingFilterChain) -- .doFilter(withDispatcher(request, servletPipeline), response); -- -- } -- -- /** -- * Used to create an proxy that dispatches either to the guice-servlet pipeline or the regular -- * pipeline based on uri-path match. This proxy also provides minimal forwarding support. -- * -- * We cannot forward from a web.xml Servlet/JSP to a guice-servlet (because the filter pipeline -- * is not called again). However, we can wrap requests with our own dispatcher to forward the -- * *other* way. web.xml Servlets/JSPs can forward to themselves as per normal. -- * -- * This is not a problem cuz we intend for people to migrate from web.xml to guice-servlet, -- * incrementally, but not the other way around (which, we should actively discourage). -- */ -- @SuppressWarnings({ "JavaDoc", "deprecation" }) -- private ServletRequest withDispatcher(ServletRequest servletRequest, -- final ManagedServletPipeline servletPipeline) { -- -- // don't wrap the request if there are no servlets mapped. This prevents us from inserting our -- // wrapper unless it's actually going to be used. This is necessary for compatibility for apps -- // that downcast their HttpServletRequests to a concrete implementation. -- if (!servletPipeline.hasServletsMapped()) { -- return servletRequest; -- } -- -- HttpServletRequest request = (HttpServletRequest) servletRequest; -- //noinspection OverlyComplexAnonymousInnerClass -- return new HttpServletRequestWrapper(request) { -- -- @Override -- public RequestDispatcher getRequestDispatcher(String path) { -- final RequestDispatcher dispatcher = servletPipeline.getRequestDispatcher(path); -- -- return (null != dispatcher) ? dispatcher : super.getRequestDispatcher(path); -- } -- }; -- } -- -- public void destroyPipeline() { -- //destroy servlets first -- servletPipeline.destroy(); -- -- //go down chain and destroy all our filters -- Set destroyedSoFar = Sets.newIdentityHashSet(); -- for (FilterDefinition filterDefinition : filterDefinitions) { -- filterDefinition.destroy(destroyedSoFar); -- } -- } - } -diff --git a/extensions/servlet/src/com/google/inject/servlet/ManagedServletPipeline.java b/extensions/servlet/src/com/google/inject/servlet/ManagedServletPipeline.java -index 455551a..ab58a8e 100644 ---- a/extensions/servlet/src/com/google/inject/servlet/ManagedServletPipeline.java -+++ b/extensions/servlet/src/com/google/inject/servlet/ManagedServletPipeline.java -@@ -15,27 +15,14 @@ - */ - package com.google.inject.servlet; - --import com.google.common.base.Preconditions; - import com.google.common.collect.Lists; --import com.google.common.collect.Sets; - import com.google.inject.Binding; - import com.google.inject.Inject; - import com.google.inject.Injector; - import com.google.inject.Singleton; - import com.google.inject.TypeLiteral; - --import java.io.IOException; - import java.util.List; --import java.util.Set; -- --import javax.servlet.RequestDispatcher; --import javax.servlet.ServletContext; --import javax.servlet.ServletException; --import javax.servlet.ServletRequest; --import javax.servlet.ServletResponse; --import javax.servlet.http.HttpServlet; --import javax.servlet.http.HttpServletRequest; --import javax.servlet.http.HttpServletRequestWrapper; - - /** - * A wrapping dispatcher for servlets, in much the same way as {@link ManagedFilterPipeline} is for -@@ -44,7 +31,7 @@ import javax.servlet.http.HttpServletRequestWrapper; - * @author dhanji@gmail.com (Dhanji R. Prasanna) - */ - @Singleton --class ManagedServletPipeline { -+class ManagedServletPipeline extends AbstractServletPipeline { - private final ServletDefinition[] servletDefinitions; - private static final TypeLiteral SERVLET_DEFS = - TypeLiteral.get(ServletDefinition.class); -@@ -54,10 +41,16 @@ class ManagedServletPipeline { - this.servletDefinitions = collectServletDefinitions(injector); - } - -- boolean hasServletsMapped() { -+ @Override -+ protected boolean hasServletsMapped() { - return servletDefinitions.length > 0; - } - -+ @Override -+ protected ServletDefinition[] servletDefinitions() { -+ return servletDefinitions; -+ } -+ - /** - * Introspects the injector and collects all instances of bound {@code List} - * into a master list. -@@ -74,140 +67,4 @@ class ManagedServletPipeline { - // Copy to a fixed size array for speed. - return servletDefinitions.toArray(new ServletDefinition[servletDefinitions.size()]); - } -- -- public void init(ServletContext servletContext, Injector injector) throws ServletException { -- Set initializedSoFar = Sets.newIdentityHashSet(); -- -- for (ServletDefinition servletDefinition : servletDefinitions) { -- servletDefinition.init(servletContext, injector, initializedSoFar); -- } -- } -- -- public boolean service(ServletRequest request, ServletResponse response) -- throws IOException, ServletException { -- -- //stop at the first matching servlet and service -- for (ServletDefinition servletDefinition : servletDefinitions) { -- if (servletDefinition.service(request, response)) { -- return true; -- } -- } -- -- //there was no match... -- return false; -- } -- -- public void destroy() { -- Set destroyedSoFar = Sets.newIdentityHashSet(); -- for (ServletDefinition servletDefinition : servletDefinitions) { -- servletDefinition.destroy(destroyedSoFar); -- } -- } -- -- /** -- * @return Returns a request dispatcher wrapped with a servlet mapped to -- * the given path or null if no mapping was found. -- */ -- RequestDispatcher getRequestDispatcher(String path) { -- final String newRequestUri = path; -- -- // TODO(dhanji): check servlet spec to see if the following is legal or not. -- // Need to strip query string if requested... -- -- for (final ServletDefinition servletDefinition : servletDefinitions) { -- if (servletDefinition.shouldServe(path)) { -- return new RequestDispatcher() { -- public void forward(ServletRequest servletRequest, ServletResponse servletResponse) -- throws ServletException, IOException { -- Preconditions.checkState(!servletResponse.isCommitted(), -- "Response has been committed--you can only call forward before" -- + " committing the response (hint: don't flush buffers)"); -- -- // clear buffer before forwarding -- servletResponse.resetBuffer(); -- -- ServletRequest requestToProcess; -- if (servletRequest instanceof HttpServletRequest) { -- requestToProcess = wrapRequest((HttpServletRequest)servletRequest, newRequestUri); -- } else { -- // This should never happen, but instead of throwing an exception -- // we will allow a happy case pass thru for maximum tolerance to -- // legacy (and internal) code. -- requestToProcess = servletRequest; -- } -- -- // now dispatch to the servlet -- doServiceImpl(servletDefinition, requestToProcess, servletResponse); -- } -- -- public void include(ServletRequest servletRequest, ServletResponse servletResponse) -- throws ServletException, IOException { -- // route to the target servlet -- doServiceImpl(servletDefinition, servletRequest, servletResponse); -- } -- -- private void doServiceImpl(ServletDefinition servletDefinition, ServletRequest servletRequest, -- ServletResponse servletResponse) throws ServletException, IOException { -- servletRequest.setAttribute(REQUEST_DISPATCHER_REQUEST, Boolean.TRUE); -- -- try { -- servletDefinition.doService(servletRequest, servletResponse); -- } finally { -- servletRequest.removeAttribute(REQUEST_DISPATCHER_REQUEST); -- } -- } -- }; -- } -- } -- -- //otherwise, can't process -- return null; -- } -- -- // visible for testing -- static HttpServletRequest wrapRequest(HttpServletRequest request, String newUri) { -- return new RequestDispatcherRequestWrapper(request, newUri); -- } -- -- /** -- * A Marker constant attribute that when present in the request indicates to Guice servlet that -- * this request has been generated by a request dispatcher rather than the servlet pipeline. -- * In accordance with section 8.4.2 of the Servlet 2.4 specification. -- */ -- public static final String REQUEST_DISPATCHER_REQUEST = "javax.servlet.forward.servlet_path"; -- -- private static class RequestDispatcherRequestWrapper extends HttpServletRequestWrapper { -- private final String newRequestUri; -- -- public RequestDispatcherRequestWrapper(HttpServletRequest servletRequest, String newRequestUri) { -- super(servletRequest); -- this.newRequestUri = newRequestUri; -- } -- -- @Override -- public String getRequestURI() { -- return newRequestUri; -- } -- -- @Override -- public StringBuffer getRequestURL() { -- StringBuffer url = new StringBuffer(); -- String scheme = getScheme(); -- int port = getServerPort(); -- -- url.append(scheme); -- url.append("://"); -- url.append(getServerName()); -- // port might be -1 in some cases (see java.net.URL.getPort) -- if (port > 0 && -- (("http".equals(scheme) && (port != 80)) || -- ("https".equals(scheme) && (port != 443)))) { -- url.append(':'); -- url.append(port); -- } -- url.append(getRequestURI()); -- -- return (url); -- } -- } - } -diff --git a/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java b/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java -index 11328ed..285ff31 100644 ---- a/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java -+++ b/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java -@@ -46,12 +46,11 @@ import javax.servlet.http.HttpServletRequestWrapper; - import javax.servlet.http.HttpServletResponse; - - /** -- * An internal representation of a servlet definition mapped to a particular URI pattern. Also -- * performs the request dispatch to that servlet. How nice and OO =) -+ * Defines a servlet mapped to a URI pattern and performs the request dispatch to that servlet. - * - * @author dhanji@gmail.com (Dhanji R. Prasanna) - */ --class ServletDefinition implements ProviderWithExtensionVisitor { -+public class ServletDefinition implements ProviderWithExtensionVisitor { - private final String pattern; - private final Key servletKey; - private final UriPatternMatcher patternMatcher; -@@ -100,7 +99,7 @@ class ServletDefinition implements ProviderWithExtensionVisitor initializedSoFar) throws ServletException { - - // This absolutely must be a singleton, and so is only initialized once. -@@ -140,7 +139,7 @@ class ServletDefinition implements ProviderWithExtensionVisitor destroyedSoFar) { -+ void destroy(Set destroyedSoFar) { - HttpServlet reference = httpServlet.get(); - - // Do nothing if this Servlet was invalid (usually due to not being scoped -@@ -169,7 +168,7 @@ class ServletDefinition implements ProviderWithExtensionVisitor -Date: Tue Jan 20 18:51:01 2015 +0000 - - Enhance logging in filter/servlet definitions - -diff --git a/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java b/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java -index 76ece31..6819665 100644 ---- a/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java -+++ b/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java -@@ -15,6 +15,7 @@ - */ - package com.google.inject.servlet; - -+import com.google.common.base.Strings; - import com.google.common.collect.Iterators; - import com.google.inject.Injector; - import com.google.inject.Key; -@@ -29,6 +30,8 @@ import java.util.HashMap; - import java.util.Map; - import java.util.Set; - import java.util.concurrent.atomic.AtomicReference; -+import java.util.logging.Level; -+import java.util.logging.Logger; - - import javax.servlet.Filter; - import javax.servlet.FilterConfig; -@@ -42,6 +45,8 @@ import javax.servlet.http.HttpServletRequest; - * @author dhanji@gmail.com (Dhanji R. Prasanna) - */ - public class FilterDefinition implements ProviderWithExtensionVisitor { -+ private static final Logger logger = Logger.getLogger(FilterDefinition.class.getName()); -+ - private final String pattern; - private final Key filterKey; - private final UriPatternMatcher patternMatcher; -@@ -154,7 +159,11 @@ public class FilterDefinition implements ProviderWithExtensionVisitor { -+ private static final Logger logger = Logger.getLogger(ServletDefinition.class.getName()); -+ - private final String pattern; - private final Key servletKey; - private final UriPatternMatcher patternMatcher; -@@ -283,7 +288,14 @@ public class ServletDefinition implements ProviderWithExtensionVisitor - 4.1-6 +- Remove unused patches + * Fri Feb 24 2017 Mikolaj Izdebski - 4.1-5 - Remove maven-javadoc-plugin from all POMs