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 22507a00f966dca1010028a5bb92623ca383c702
Author: Benoit Tellier <btell...@linagora.com>
AuthorDate: Mon Mar 4 11:33:26 2019 +0700

    JAMES-2664 Guice module for PreDeletion hooks injections
---
 .../org/apache/james/modules/MailboxModule.java    |  6 +--
 .../modules/mailbox/PreDeletionHookModule.java     | 51 ++++++++++++++++++++++
 2 files changed, 54 insertions(+), 3 deletions(-)

diff --git 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
index 82ba294..9f3ed0b 100644
--- 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
+++ 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
@@ -23,8 +23,8 @@ import org.apache.james.mailbox.acl.GroupMembershipResolver;
 import org.apache.james.mailbox.acl.MailboxACLResolver;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
 import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
-import org.apache.james.mailbox.extension.PreDeletionHook;
 import org.apache.james.mailbox.store.SystemMailboxesProviderImpl;
+import org.apache.james.modules.mailbox.PreDeletionHookModule;
 import org.apache.james.utils.GuiceProbe;
 
 import com.google.inject.AbstractModule;
@@ -35,6 +35,8 @@ public class MailboxModule extends AbstractModule {
 
     @Override
     protected void configure() {
+        install(new PreDeletionHookModule());
+
         Multibinder<GuiceProbe> probeMultiBinder = 
Multibinder.newSetBinder(binder(), GuiceProbe.class);
         probeMultiBinder.addBinding().to(MailboxProbeImpl.class);
         probeMultiBinder.addBinding().to(QuotaProbesImpl.class);
@@ -49,8 +51,6 @@ public class MailboxModule extends AbstractModule {
 
         bind(SystemMailboxesProviderImpl.class).in(Scopes.SINGLETON);
         
bind(SystemMailboxesProvider.class).to(SystemMailboxesProviderImpl.class);
-
-        Multibinder<PreDeletionHook> noPreDeletionHooks = 
Multibinder.newSetBinder(binder(), PreDeletionHook.class);
     }
 
 }
diff --git 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/PreDeletionHookModule.java
 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/PreDeletionHookModule.java
new file mode 100644
index 0000000..0e8de41
--- /dev/null
+++ 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/PreDeletionHookModule.java
@@ -0,0 +1,51 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you 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 org.apache.james.modules.mailbox;
+
+import java.util.Set;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.james.mailbox.extension.PreDeletionHook;
+import org.apache.james.server.core.configuration.ConfigurationProvider;
+
+import com.github.fge.lambdas.Throwing;
+import com.github.steveash.guavate.Guavate;
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+
+public class PreDeletionHookModule extends AbstractModule {
+    @Override
+    protected void configure() {
+        bind(PreDeletionHookLoader.class).to(PreDeletionHookLoaderImpl.class);
+    }
+
+    @Provides
+    PreDeletionHooksConfiguration providesConfiguration(ConfigurationProvider 
configurationProvider) throws ConfigurationException {
+        return 
PreDeletionHooksConfiguration.from(configurationProvider.getConfiguration("listeners"));
+    }
+
+    @Provides
+    Set<PreDeletionHook> createHooks(PreDeletionHooksConfiguration 
configuration, PreDeletionHookLoader loader) throws ClassNotFoundException {
+        return configuration.getHooksConfiguration()
+            .stream()
+            .map(Throwing.function(loader::createHook).sneakyThrow())
+            .collect(Guavate.toImmutableSet());
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to