This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 35ca6d84613fa8657f14491465da564c64b822b4 Author: Benoit Tellier <btell...@linagora.com> AuthorDate: Thu Sep 19 16:16:49 2019 +0700 JAMES-2886 Demonstrate custom guice modules for extentions works --- .../apache/james/utils/ExtensionConfiguration.java | 2 +- .../org/apache/james/utils/GuiceGenericLoader.java | 7 ++++ .../apache/james/utils/GuiceMailetLoaderTest.java | 43 ++++++++++++++------- .../apache/james/utils/GuiceMatcherLoaderTest.java | 18 ++++----- ...ustom-mailets-implementation-3.5.0-SNAPSHOT.jar | Bin 0 -> 11147 bytes ...ailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar | Bin 30472149 -> 30473134 bytes .../{ => custom-mailets-implementation}/pom.xml | 26 +++++++------ .../transport/mailets/MyExtensionModule.java} | 34 ++++------------ .../mailets/MyInterfaceImplementation.java} | 31 ++------------- .../james/transport/mailets/MyGenericMailet.java} | 36 +++++++---------- .../james/transport/mailets/MyInterface.java} | 32 ++------------- server/container/guice/testing/pom.xml | 1 + 12 files changed, 86 insertions(+), 144 deletions(-) diff --git a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/ExtensionConfiguration.java b/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/ExtensionConfiguration.java index 88069b0..205229a 100644 --- a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/ExtensionConfiguration.java +++ b/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/ExtensionConfiguration.java @@ -40,7 +40,7 @@ public class ExtensionConfiguration { private final List<ClassName> additionalGuiceModulesForExtensions; - private ExtensionConfiguration(List<ClassName> additionalGuiceModulesForExtensions) { + public ExtensionConfiguration(List<ClassName> additionalGuiceModulesForExtensions) { this.additionalGuiceModulesForExtensions = additionalGuiceModulesForExtensions; } diff --git a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java b/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java index 871c52b..71fd966 100644 --- a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java +++ b/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/GuiceGenericLoader.java @@ -23,6 +23,8 @@ import java.util.stream.Stream; import com.github.fge.lambdas.Throwing; import com.github.steveash.guavate.Guavate; +import com.google.common.annotations.VisibleForTesting; +import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Module; @@ -31,6 +33,11 @@ import com.google.inject.util.Modules; public class GuiceGenericLoader { private static final Module NO_CHILD_MODULE = binder -> { }; + @VisibleForTesting + public static GuiceGenericLoader forTesting(ExtendedClassLoader extendedClassLoader) { + return new GuiceGenericLoader(Guice.createInjector(), extendedClassLoader, ExtensionConfiguration.DEFAULT); + } + public static class InvocationPerformer<T> { private final Injector injector; private final ExtendedClassLoader extendedClassLoader; diff --git a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java index 635685b..b5333d6 100644 --- a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java +++ b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java @@ -37,20 +37,19 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.inject.Guice; -import com.google.inject.Injector; public class GuiceMailetLoaderTest { public static final ImmutableSet<MailetConfigurationOverride> NO_MAILET_CONFIG_OVERRIDES = ImmutableSet.of(); @Rule public ExpectedException expectedException = ExpectedException.none(); - private Injector injector = Guice.createInjector(); @Test public void getMailetShouldLoadClass() throws Exception { - GuiceGenericLoader genericLoader = new GuiceGenericLoader(injector, new ExtendedClassLoader(THROWING_FILE_SYSTEM)); + GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(THROWING_FILE_SYSTEM)); GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(genericLoader, NO_MAILET_CONFIG_OVERRIDES); Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() @@ -63,7 +62,7 @@ public class GuiceMailetLoaderTest { @Test public void getMailetShouldLoadClassWhenInSubPackageFromDefaultPackage() throws Exception { - GuiceGenericLoader genericLoader = new GuiceGenericLoader(injector, new ExtendedClassLoader(THROWING_FILE_SYSTEM)); + GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(THROWING_FILE_SYSTEM)); GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(genericLoader, NO_MAILET_CONFIG_OVERRIDES); Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() @@ -76,7 +75,7 @@ public class GuiceMailetLoaderTest { @Test public void getMailetShouldThrowOnBadType() throws Exception { - GuiceGenericLoader genericLoader = new GuiceGenericLoader(injector, new ExtendedClassLoader(THROWING_FILE_SYSTEM)); + GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(THROWING_FILE_SYSTEM)); GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(genericLoader, NO_MAILET_CONFIG_OVERRIDES); expectedException.expect(MessagingException.class); @@ -89,7 +88,7 @@ public class GuiceMailetLoaderTest { @Test public void getMailetShouldLoadClassWhenInExtensionsJars() throws Exception { - GuiceGenericLoader genericLoader = new GuiceGenericLoader(injector, new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); + GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(genericLoader, NO_MAILET_CONFIG_OVERRIDES); Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() @@ -103,7 +102,7 @@ public class GuiceMailetLoaderTest { @Test public void getMailetShouldBrowseRecursivelyExtensionsJars() throws Exception { - GuiceGenericLoader genericLoader = new GuiceGenericLoader(injector, new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM)); + GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM)); GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(genericLoader, NO_MAILET_CONFIG_OVERRIDES); Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() @@ -117,7 +116,7 @@ public class GuiceMailetLoaderTest { @Test public void getMailedShouldAllowCustomPackages() throws Exception { - GuiceGenericLoader genericLoader = new GuiceGenericLoader(injector, new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); + GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(genericLoader, NO_MAILET_CONFIG_OVERRIDES); Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() @@ -131,7 +130,7 @@ public class GuiceMailetLoaderTest { @Test public void getMailetShouldThrowOnUnknownMailet() throws Exception { - GuiceGenericLoader genericLoader = new GuiceGenericLoader(injector, new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); + GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(genericLoader, NO_MAILET_CONFIG_OVERRIDES); expectedException.expect(MessagingException.class); @@ -144,9 +143,8 @@ public class GuiceMailetLoaderTest { @Test public void getMailetShouldLoadMailetsWithCustomDependencyInConstructor() throws Exception { - GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, - new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM), - NO_MAILET_CONFIG_OVERRIDES); + GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM)); + GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(genericLoader, NO_MAILET_CONFIG_OVERRIDES); Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() .mailetName("CustomMailetWithCustomDependencyInConstructor") @@ -159,9 +157,8 @@ public class GuiceMailetLoaderTest { @Test public void getMailetShouldLoadMailetsWithCustomDependencyInService() throws Exception { - GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, - new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM), - NO_MAILET_CONFIG_OVERRIDES); + GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM)); + GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(genericLoader, NO_MAILET_CONFIG_OVERRIDES); Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() .mailetName("CustomMailetWithCustomDependencyInService") @@ -170,4 +167,20 @@ public class GuiceMailetLoaderTest { assertThatCode(() -> mailet.service(FakeMail.defaultFakeMail())).doesNotThrowAnyException(); } + + @Test + public void getMailetShouldAllowCustomInjections() throws Exception { + GuiceGenericLoader genericLoader = new GuiceGenericLoader( + Guice.createInjector(), + new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM), + new ExtensionConfiguration(ImmutableList.of(new ClassName("org.apache.james.transport.mailets.MyExtensionModule")))); + GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(genericLoader, NO_MAILET_CONFIG_OVERRIDES); + + Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() + .mailetName("MyGenericMailet") + .mailetContext(FakeMailContext.defaultContext()) + .build()); + + assertThatCode(() -> mailet.service(FakeMail.defaultFakeMail())).doesNotThrowAnyException(); + } } diff --git a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMatcherLoaderTest.java b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMatcherLoaderTest.java index 7f77af8..f3e110f 100644 --- a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMatcherLoaderTest.java +++ b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMatcherLoaderTest.java @@ -34,18 +34,14 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import com.google.inject.Guice; -import com.google.inject.Injector; - public class GuiceMatcherLoaderTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - private Injector injector = Guice.createInjector(); @Test public void getMatcherShouldLoadClass() throws Exception { - GuiceGenericLoader genericLoader = new GuiceGenericLoader(injector, new ExtendedClassLoader(THROWING_FILE_SYSTEM)); + GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(THROWING_FILE_SYSTEM)); GuiceMatcherLoader guiceMailetLoader = new GuiceMatcherLoader(genericLoader); Matcher matcher = guiceMailetLoader.getMatcher(FakeMatcherConfig.builder() @@ -58,7 +54,7 @@ public class GuiceMatcherLoaderTest { @Test public void getMatcherShouldLoadClassWhenInSubPackageFromDefaultPackage() throws Exception { - GuiceGenericLoader genericLoader = new GuiceGenericLoader(injector, new ExtendedClassLoader(THROWING_FILE_SYSTEM)); + GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(THROWING_FILE_SYSTEM)); GuiceMatcherLoader guiceMailetLoader = new GuiceMatcherLoader(genericLoader); Matcher matcher = guiceMailetLoader.getMatcher(FakeMatcherConfig.builder() @@ -71,7 +67,7 @@ public class GuiceMatcherLoaderTest { @Test public void getMatcherShouldThrowOnBadType() throws Exception { - GuiceGenericLoader genericLoader = new GuiceGenericLoader(injector, new ExtendedClassLoader(THROWING_FILE_SYSTEM)); + GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(THROWING_FILE_SYSTEM)); GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(genericLoader); expectedException.expect(MessagingException.class); @@ -84,7 +80,7 @@ public class GuiceMatcherLoaderTest { @Test public void getMatcherShouldLoadClassWhenInExtensionsJars() throws Exception { - GuiceGenericLoader genericLoader = new GuiceGenericLoader(injector, new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); + GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(genericLoader); Matcher matcher = guiceMatcherLoader.getMatcher(FakeMatcherConfig.builder() @@ -98,7 +94,7 @@ public class GuiceMatcherLoaderTest { @Test public void getMatcherShouldBrowseRecursivelyExtensionJars() throws Exception { - GuiceGenericLoader genericLoader = new GuiceGenericLoader(injector, new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM)); + GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM)); GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(genericLoader); Matcher matcher = guiceMatcherLoader.getMatcher(FakeMatcherConfig.builder() @@ -112,7 +108,7 @@ public class GuiceMatcherLoaderTest { @Test public void getMatcherShouldAllowCustomPackages() throws Exception { - GuiceGenericLoader genericLoader = new GuiceGenericLoader(injector, new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM)); + GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM)); GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(genericLoader); Matcher matcher = guiceMatcherLoader.getMatcher(FakeMatcherConfig.builder() @@ -126,7 +122,7 @@ public class GuiceMatcherLoaderTest { @Test public void getMatcherShouldThrowOnUnknownMailet() throws Exception { - GuiceGenericLoader genericLoader = new GuiceGenericLoader(injector, new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); + GuiceGenericLoader genericLoader = GuiceGenericLoader.forTesting(new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(genericLoader); expectedException.expect(MessagingException.class); diff --git a/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/custom-mailets-implementation-3.5.0-SNAPSHOT.jar b/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/custom-mailets-implementation-3.5.0-SNAPSHOT.jar new file mode 100644 index 0000000..bd866d9 Binary files /dev/null and b/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/custom-mailets-implementation-3.5.0-SNAPSHOT.jar differ diff --git a/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar b/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar index 99e2b38..2f73d5b 100644 Binary files a/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar and b/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar differ diff --git a/server/container/guice/testing/pom.xml b/server/container/guice/testing/custom-mailets-implementation/pom.xml similarity index 66% copy from server/container/guice/testing/pom.xml copy to server/container/guice/testing/custom-mailets-implementation/pom.xml index c646376..6132e7f 100644 --- a/server/container/guice/testing/pom.xml +++ b/server/container/guice/testing/custom-mailets-implementation/pom.xml @@ -17,23 +17,27 @@ specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <parent> <groupId>org.apache.james</groupId> - <artifactId>james-server-guice</artifactId> + <artifactId>james-server-guice-testing</artifactId> <version>3.5.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> - <artifactId>james-server-guice-testing</artifactId> - <packaging>pom</packaging> - <name>Apache James :: Server :: Guice :: testing</name> + <artifactId>custom-mailets-implementation</artifactId> + + <dependencies> + <dependency> + <groupId>${james.groupId}</groupId> + <artifactId>james-server-guice-custom-mailets</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.google.inject</groupId> + <artifactId>guice</artifactId> + </dependency> + </dependencies> - <modules> - <module>custom-mailets</module> - <module>dependency</module> - </modules> </project> \ No newline at end of file diff --git a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/ExtensionConfiguration.java b/server/container/guice/testing/custom-mailets-implementation/src/main/java/org/apache/james/transport/mailets/MyExtensionModule.java similarity index 52% copy from server/container/guice/guice-utils/src/main/java/org/apache/james/utils/ExtensionConfiguration.java copy to server/container/guice/testing/custom-mailets-implementation/src/main/java/org/apache/james/transport/mailets/MyExtensionModule.java index 88069b0..cd6b70f 100644 --- a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/ExtensionConfiguration.java +++ b/server/container/guice/testing/custom-mailets-implementation/src/main/java/org/apache/james/transport/mailets/MyExtensionModule.java @@ -17,34 +17,14 @@ * under the License. * ****************************************************************/ -package org.apache.james.utils; +package org.apache.james.transport.mailets; -import java.util.Arrays; -import java.util.List; +import com.google.inject.AbstractModule; -import org.apache.commons.configuration2.Configuration; - -import com.github.steveash.guavate.Guavate; -import com.google.common.collect.ImmutableList; - -public class ExtensionConfiguration { - public static final ExtensionConfiguration DEFAULT = new ExtensionConfiguration(ImmutableList.of()); - - public static ExtensionConfiguration from(Configuration configuration) { - List<String> list = Arrays.asList(configuration.getStringArray("guice.extension.module")); - - return new ExtensionConfiguration(list.stream() - .map(ClassName::new) - .collect(Guavate.toImmutableList())); - } - - private final List<ClassName> additionalGuiceModulesForExtensions; - - private ExtensionConfiguration(List<ClassName> additionalGuiceModulesForExtensions) { - this.additionalGuiceModulesForExtensions = additionalGuiceModulesForExtensions; - } - - public List<ClassName> getAdditionalGuiceModulesForExtensions() { - return additionalGuiceModulesForExtensions; +public class MyExtensionModule extends AbstractModule { + @Override + protected void configure() { + bind(MyInterface.class) + .to(MyInterfaceImplementation.class); } } diff --git a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/ExtensionConfiguration.java b/server/container/guice/testing/custom-mailets-implementation/src/main/java/org/apache/james/transport/mailets/MyInterfaceImplementation.java similarity index 52% copy from server/container/guice/guice-utils/src/main/java/org/apache/james/utils/ExtensionConfiguration.java copy to server/container/guice/testing/custom-mailets-implementation/src/main/java/org/apache/james/transport/mailets/MyInterfaceImplementation.java index 88069b0..49dd7c8 100644 --- a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/ExtensionConfiguration.java +++ b/server/container/guice/testing/custom-mailets-implementation/src/main/java/org/apache/james/transport/mailets/MyInterfaceImplementation.java @@ -17,34 +17,11 @@ * under the License. * ****************************************************************/ -package org.apache.james.utils; +package org.apache.james.transport.mailets; -import java.util.Arrays; -import java.util.List; +public class MyInterfaceImplementation implements MyInterface { + @Override + public void doSomething() { -import org.apache.commons.configuration2.Configuration; - -import com.github.steveash.guavate.Guavate; -import com.google.common.collect.ImmutableList; - -public class ExtensionConfiguration { - public static final ExtensionConfiguration DEFAULT = new ExtensionConfiguration(ImmutableList.of()); - - public static ExtensionConfiguration from(Configuration configuration) { - List<String> list = Arrays.asList(configuration.getStringArray("guice.extension.module")); - - return new ExtensionConfiguration(list.stream() - .map(ClassName::new) - .collect(Guavate.toImmutableList())); - } - - private final List<ClassName> additionalGuiceModulesForExtensions; - - private ExtensionConfiguration(List<ClassName> additionalGuiceModulesForExtensions) { - this.additionalGuiceModulesForExtensions = additionalGuiceModulesForExtensions; - } - - public List<ClassName> getAdditionalGuiceModulesForExtensions() { - return additionalGuiceModulesForExtensions; } } diff --git a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/ExtensionConfiguration.java b/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/MyGenericMailet.java similarity index 53% copy from server/container/guice/guice-utils/src/main/java/org/apache/james/utils/ExtensionConfiguration.java copy to server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/MyGenericMailet.java index 88069b0..a0e28d4 100644 --- a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/ExtensionConfiguration.java +++ b/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/MyGenericMailet.java @@ -17,34 +17,24 @@ * under the License. * ****************************************************************/ -package org.apache.james.utils; +package org.apache.james.transport.mailets; -import java.util.Arrays; -import java.util.List; +import javax.inject.Inject; +import javax.mail.MessagingException; -import org.apache.commons.configuration2.Configuration; +import org.apache.mailet.Mail; +import org.apache.mailet.base.GenericMailet; -import com.github.steveash.guavate.Guavate; -import com.google.common.collect.ImmutableList; +public class MyGenericMailet extends GenericMailet { + private final MyInterface myInterface; -public class ExtensionConfiguration { - public static final ExtensionConfiguration DEFAULT = new ExtensionConfiguration(ImmutableList.of()); - - public static ExtensionConfiguration from(Configuration configuration) { - List<String> list = Arrays.asList(configuration.getStringArray("guice.extension.module")); - - return new ExtensionConfiguration(list.stream() - .map(ClassName::new) - .collect(Guavate.toImmutableList())); - } - - private final List<ClassName> additionalGuiceModulesForExtensions; - - private ExtensionConfiguration(List<ClassName> additionalGuiceModulesForExtensions) { - this.additionalGuiceModulesForExtensions = additionalGuiceModulesForExtensions; + @Inject + public MyGenericMailet(MyInterface myInterface) { + this.myInterface = myInterface; } - public List<ClassName> getAdditionalGuiceModulesForExtensions() { - return additionalGuiceModulesForExtensions; + @Override + public void service(Mail mail) throws MessagingException { + myInterface.doSomething(); } } diff --git a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/ExtensionConfiguration.java b/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/MyInterface.java similarity index 52% copy from server/container/guice/guice-utils/src/main/java/org/apache/james/utils/ExtensionConfiguration.java copy to server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/MyInterface.java index 88069b0..f1748ce 100644 --- a/server/container/guice/guice-utils/src/main/java/org/apache/james/utils/ExtensionConfiguration.java +++ b/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/MyInterface.java @@ -17,34 +17,8 @@ * under the License. * ****************************************************************/ -package org.apache.james.utils; +package org.apache.james.transport.mailets; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.configuration2.Configuration; - -import com.github.steveash.guavate.Guavate; -import com.google.common.collect.ImmutableList; - -public class ExtensionConfiguration { - public static final ExtensionConfiguration DEFAULT = new ExtensionConfiguration(ImmutableList.of()); - - public static ExtensionConfiguration from(Configuration configuration) { - List<String> list = Arrays.asList(configuration.getStringArray("guice.extension.module")); - - return new ExtensionConfiguration(list.stream() - .map(ClassName::new) - .collect(Guavate.toImmutableList())); - } - - private final List<ClassName> additionalGuiceModulesForExtensions; - - private ExtensionConfiguration(List<ClassName> additionalGuiceModulesForExtensions) { - this.additionalGuiceModulesForExtensions = additionalGuiceModulesForExtensions; - } - - public List<ClassName> getAdditionalGuiceModulesForExtensions() { - return additionalGuiceModulesForExtensions; - } +public interface MyInterface { + void doSomething(); } diff --git a/server/container/guice/testing/pom.xml b/server/container/guice/testing/pom.xml index c646376..6b561ce 100644 --- a/server/container/guice/testing/pom.xml +++ b/server/container/guice/testing/pom.xml @@ -35,5 +35,6 @@ <modules> <module>custom-mailets</module> <module>dependency</module> + <module>custom-mailets-implementation</module> </modules> </project> \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org