Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

REVIEW: Workaround to automatically share method interceptors #773

Merged
merged 3 commits into from

2 participants

@mcculls
Owner

Support/workaround for sharing interceptor modules pending core sisu support for this feature.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=403108

mcculls and others added some commits
@jdillon
Owner

This is for after 2.4 is done and should be merged in 2.4.1 or 2.5.

@jdillon jdillon merged commit 28ab207 into master
@jdillon jdillon deleted the workaround-non-shared-interceptors branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 12, 2013
  1. @mcculls

    Workaround to automatically share method interceptors via explicitly …

    mcculls authored
    …bound module sub-types while the Sisu feature to do this properly is implemented
Commits on Mar 13, 2013
  1. @jdillon
  2. @jdillon

    clearify docs

    jdillon authored
This page is out of date. Refresh to see the latest.
View
57 nexus-core/src/main/java/org/sonatype/nexus/guice/AbstractInterceptorModule.java
@@ -0,0 +1,57 @@
+/*
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+
+package org.sonatype.nexus.guice;
+
+import java.lang.reflect.Method;
+
+import org.aopalliance.intercept.MethodInterceptor;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Key;
+import com.google.inject.matcher.Matcher;
+import com.google.inject.name.Names;
+
+/**
+ * Workaround to automatically share method interceptors until
+ * <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=403108">proper Sisu feature</a> is implemented.
+ *
+ * <p>
+ * This module is only bound once in its originating realm, when the bindInterceptor method is first called. The Nexus
+ * Plugin Manager can then see this module via the injected dynamic list of AbstractInterceptorModules and will install
+ * it in any plugins registered after this point.
+ *
+ * <p>
+ * Note: you can't contribute interceptors to earlier plugins or from a plugin to core, but the other direction works fine.
+ *
+ * @since 2.4
+ */
+public abstract class AbstractInterceptorModule
+ extends AbstractModule
+{
+ private boolean bound;
+
+ @Override
+ protected void bindInterceptor( final Matcher<? super Class<?>> classMatcher,
+ final Matcher<? super Method> methodMatcher,
+ final MethodInterceptor... interceptors )
+ {
+ if ( !bound )
+ {
+ // Explicitly bind module instance under a specific sub-type (not Module as Guice forbids that)
+ bind( Key.get( AbstractInterceptorModule.class, Names.named( getClass().getName() ) ) ).toInstance( this );
+ bound = true;
+ }
+ super.bindInterceptor( classMatcher, methodMatcher, interceptors );
+ }
+}
View
5 nexus-core/src/main/java/org/sonatype/nexus/guice/NexusModules.java
@@ -13,9 +13,9 @@
package org.sonatype.nexus.guice;
-import com.google.inject.AbstractModule;
import org.apache.shiro.guice.aop.ShiroAopModule;
-import org.sonatype.nexus.timing.TimingModule;
+
+import com.google.inject.AbstractModule;
/**
* Nexus guice modules.
@@ -33,7 +33,6 @@
@Override
protected void configure() {
install(new ShiroAopModule());
- install(new TimingModule());
}
}
View
17 nexus-core/src/main/java/org/sonatype/nexus/plugins/DefaultNexusPluginManager.java
@@ -40,6 +40,7 @@
import org.sonatype.guice.plexus.binders.PlexusXmlBeanModule;
import org.sonatype.guice.plexus.config.PlexusBeanModule;
import org.sonatype.inject.Parameters;
+import org.sonatype.nexus.guice.AbstractInterceptorModule;
import org.sonatype.nexus.guice.NexusModules.PluginModule;
import org.sonatype.nexus.mime.MimeSupport;
import org.sonatype.nexus.plugins.events.PluginActivatedEvent;
@@ -91,6 +92,8 @@
private final Map<String, String> variables;
+ private final List<AbstractInterceptorModule> interceptorModules;
+
private final Map<GAVCoordinate, PluginDescriptor> activePlugins = new HashMap<GAVCoordinate, PluginDescriptor>();
private final Map<GAVCoordinate, PluginResponse> pluginResponses = new HashMap<GAVCoordinate, PluginResponse>();
@@ -103,7 +106,8 @@ public DefaultNexusPluginManager( final RepositoryTypeRegistry repositoryTypeReg
final PluginRepositoryManager repositoryManager,
final DefaultPlexusContainer container,
final MimeSupport mimeSupport,
- final @Parameters Map<String, String> variables )
+ final @Parameters Map<String, String> variables,
+ final List<AbstractInterceptorModule> interceptorModules )
{
this.repositoryTypeRegistry = checkNotNull( repositoryTypeRegistry );
this.eventBus = checkNotNull( eventBus );
@@ -111,6 +115,7 @@ public DefaultNexusPluginManager( final RepositoryTypeRegistry repositoryTypeReg
this.container = checkNotNull( container );
this.mimeSupport = checkNotNull( mimeSupport );
this.variables = checkNotNull( variables );
+ this.interceptorModules = checkNotNull( interceptorModules );
}
// ----------------------------------------------------------------------
@@ -462,12 +467,12 @@ protected void configure()
final ClassSpace annSpace = new URLClassSpace( pluginRealm, scanList.toArray( new URL[scanList.size()] ) );
beanModules.add( new NexusAnnotatedBeanModule( annSpace, variables, exportedClassNames, repositoryTypes ) );
- final Module[] modules = {
- resourceModule,
- new PluginModule()
- };
+ final List<Module> modules = new ArrayList<Module>();
+ modules.add( resourceModule );
+ modules.add( new PluginModule() );
+ modules.addAll( interceptorModules );
- container.addPlexusInjector( beanModules, modules );
+ container.addPlexusInjector( beanModules, modules.toArray( new Module[modules.size()] ) );
for ( final RepositoryTypeDescriptor r : repositoryTypes )
{
View
8 nexus-core/src/main/java/org/sonatype/nexus/timing/TimingModule.java
@@ -12,7 +12,10 @@
*/
package org.sonatype.nexus.timing;
-import com.google.inject.AbstractModule;
+import javax.inject.Named;
+
+import org.sonatype.nexus.guice.AbstractInterceptorModule;
+
import com.google.inject.matcher.Matchers;
/**
@@ -22,8 +25,9 @@
*
* @since 2.4
*/
+@Named
public class TimingModule
- extends AbstractModule
+ extends AbstractInterceptorModule
{
@Override
protected void configure() {
View
5 nexus-core/src/test/java/org/sonatype/nexus/plugins/DefaultNexusPluginManagerTest.java
@@ -18,12 +18,14 @@
import static org.mockito.Mockito.when;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.junit.Test;
import org.mockito.Mock;
+import org.sonatype.nexus.guice.AbstractInterceptorModule;
import org.sonatype.nexus.mime.MimeSupport;
import org.sonatype.nexus.plugins.repository.NexusPluginRepository;
import org.sonatype.nexus.plugins.repository.NoSuchPluginRepositoryArtifactException;
@@ -66,7 +68,8 @@ public void pluginDependenciesAreActivatedByGA()
{
final DefaultNexusPluginManager underTest = new DefaultNexusPluginManager(
repositoryTypeRegistry, eventBus, pluginRepositoryManager,
- new DefaultPlexusContainer(), mimeSupport, new HashMap<String, String>()
+ new DefaultPlexusContainer(), mimeSupport, new HashMap<String, String>(),
+ Collections.<AbstractInterceptorModule>emptyList()
)
{
@Override
Something went wrong with that request. Please try again.