You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/08/29 03:14:40 UTC
[12/34] james-project git commit: JAMES-2521 Copier shouldhave its
own tool module
JAMES-2521 Copier shouldhave its own tool module
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/4fea9913
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4fea9913
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4fea9913
Branch: refs/heads/master
Commit: 4fea99136b97dd14b9cdc76eab68e29926f75839
Parents: 0c652ab
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Aug 15 10:23:57 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Aug 29 10:11:46 2018 +0700
----------------------------------------------------------------------
mailbox/pom.xml | 1 -
mailbox/spring/pom.xml | 2 +-
.../META-INF/spring/spring-mailbox.xml | 2 +-
.../james/mailbox/spring/SpringMailboxTest.java | 2 +-
mailbox/tool/pom.xml | 94 ------------
.../james/mailbox/copier/MailboxCopierImpl.java | 141 -----------------
mailbox/tool/src/reporting-site/site.xml | 29 ----
.../james/mailbox/copier/MailboxCopierTest.java | 152 -------------------
mailbox/tools/copier/pom.xml | 94 ++++++++++++
.../mailbox/tools/copier/MailboxCopierImpl.java | 142 +++++++++++++++++
.../mailbox/tools/copier/MailboxCopierTest.java | 152 +++++++++++++++++++
mailbox/tools/pom.xml | 1 +
pom.xml | 2 +-
server/container/guice/jmx/pom.xml | 4 +
.../james/modules/server/JMXServerModule.java | 2 +-
server/container/spring/pom.xml | 4 -
.../META-INF/org/apache/james/spring-server.xml | 2 +-
17 files changed, 399 insertions(+), 427 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/mailbox/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/pom.xml b/mailbox/pom.xml
index 2660dc6..16dc75d 100644
--- a/mailbox/pom.xml
+++ b/mailbox/pom.xml
@@ -50,7 +50,6 @@
<module>spring</module>
<module>store</module>
<module>tika</module>
- <module>tool</module>
<module>zoo-seq-provider</module>
<module>plugin/quota-mailing</module>
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/mailbox/spring/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/pom.xml b/mailbox/spring/pom.xml
index a7f40b5..4376d68 100644
--- a/mailbox/spring/pom.xml
+++ b/mailbox/spring/pom.xml
@@ -73,7 +73,7 @@
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
- <artifactId>apache-james-mailbox-tool</artifactId>
+ <artifactId>apache-james-mailbox-tools-copier</artifactId>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml b/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
index 353cdfd..9544103 100644
--- a/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
+++ b/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
@@ -45,7 +45,7 @@
<!--
Mailbox Copier
-->
- <bean id="mailboxcopier" class="org.apache.james.mailbox.copier.MailboxCopierImpl"/>
+ <bean id="mailboxcopier" class="org.apache.james.mailbox.tools.copier.MailboxCopierImpl"/>
<!--
Mailbox ACL Resolver
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/mailbox/spring/src/test/java/org/apache/james/mailbox/spring/SpringMailboxTest.java
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/test/java/org/apache/james/mailbox/spring/SpringMailboxTest.java b/mailbox/spring/src/test/java/org/apache/james/mailbox/spring/SpringMailboxTest.java
index 5c847c5..4e5bae8 100644
--- a/mailbox/spring/src/test/java/org/apache/james/mailbox/spring/SpringMailboxTest.java
+++ b/mailbox/spring/src/test/java/org/apache/james/mailbox/spring/SpringMailboxTest.java
@@ -22,7 +22,7 @@ import static org.junit.Assert.assertEquals;
import java.io.IOException;
-import org.apache.james.mailbox.copier.MailboxCopierImpl;
+import org.apache.james.mailbox.tools.copier.MailboxCopierImpl;
import org.junit.BeforeClass;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/mailbox/tool/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/tool/pom.xml b/mailbox/tool/pom.xml
deleted file mode 100644
index 0f4ccd3..0000000
--- a/mailbox/tool/pom.xml
+++ /dev/null
@@ -1,94 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<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">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.james</groupId>
- <artifactId>apache-james-mailbox</artifactId>
- <version>3.2.0-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
-
- <artifactId>apache-james-mailbox-tool</artifactId>
- <packaging>bundle</packaging>
- <name>Apache James :: Mailbox :: Tools</name>
-
- <dependencies>
- <dependency>
- <groupId>${james.groupId}</groupId>
- <artifactId>apache-james-mailbox-api</artifactId>
- </dependency>
- <dependency>
- <groupId>${james.groupId}</groupId>
- <artifactId>apache-james-mailbox-api</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${james.groupId}</groupId>
- <artifactId>apache-james-mailbox-memory</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${james.groupId}</groupId>
- <artifactId>apache-james-mailbox-memory</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${james.groupId}</groupId>
- <artifactId>apache-james-mailbox-store</artifactId>
- </dependency>
- <dependency>
- <groupId>${james.groupId}</groupId>
- <artifactId>apache-james-mailbox-store</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>javax.inject</groupId>
- <artifactId>javax.inject</artifactId>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- </dependencies>
-</project>
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/mailbox/tool/src/main/java/org/apache/james/mailbox/copier/MailboxCopierImpl.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/copier/MailboxCopierImpl.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/copier/MailboxCopierImpl.java
deleted file mode 100644
index b49e01b..0000000
--- a/mailbox/tool/src/main/java/org/apache/james/mailbox/copier/MailboxCopierImpl.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/****************************************************************
- * 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.mailbox.copier;
-
-import java.io.IOException;
-import java.util.Calendar;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import javax.mail.Flags.Flag;
-
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageManager;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.exception.MailboxExistsException;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MessageRange;
-import org.apache.james.mailbox.model.MessageResult;
-import org.apache.james.mailbox.model.MessageResult.FetchGroup;
-import org.apache.james.mailbox.store.streaming.InputStreamContent;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Implementation of the {@link MailboxCopier} interface.
- *
- */
-public class MailboxCopierImpl implements MailboxCopier {
- private static final Logger LOGGER = LoggerFactory.getLogger(MailboxCopierImpl.class.getName());
-
- private static final FetchGroup GROUP = new FetchGroup() {
-
- @Override
- public int content() {
- return FULL_CONTENT;
- }
-
- @Override
- public Set<PartContentDescriptor> getPartContentDescriptors() {
- return new HashSet<>();
- }
-
- };
-
- @Override
- public void copyMailboxes(MailboxManager srcMailboxManager, MailboxManager dstMailboxManager) throws MailboxException, IOException {
-
- Calendar start = Calendar.getInstance();
-
- MailboxSession srcMailboxSession;
- MailboxSession dstMailboxSession;
-
- List<MailboxPath> mailboxPathList = null;
-
- srcMailboxSession = srcMailboxManager.createSystemSession("manager");
- srcMailboxManager.startProcessingRequest(srcMailboxSession);
- mailboxPathList = srcMailboxManager.list(srcMailboxSession);
- srcMailboxManager.endProcessingRequest(srcMailboxSession);
-
- if (LOGGER.isInfoEnabled()) {
- LOGGER.info("Found " + mailboxPathList.size() + " mailboxes in source mailbox manager.");
- for (int i = 0; i < mailboxPathList.size(); i++) {
- LOGGER.info("Mailbox#" + i + " path=" + mailboxPathList.get(i));
- }
- }
-
- MailboxPath mailboxPath = null;
-
- for (int i = 0; i < mailboxPathList.size(); i++) {
-
- mailboxPath = mailboxPathList.get(i);
-
- if ((mailboxPath.getName() != null) && (mailboxPath.getName().trim().length() > 0)) {
-
- LOGGER.info("Ready to copy source mailbox path={}", mailboxPath);
-
- srcMailboxSession = srcMailboxManager.createSystemSession(mailboxPath.getUser());
- dstMailboxSession = dstMailboxManager.createSystemSession(mailboxPath.getUser());
-
- dstMailboxManager.startProcessingRequest(dstMailboxSession);
- try {
- dstMailboxManager.createMailbox(mailboxPath, dstMailboxSession);
- LOGGER.info("Destination mailbox {}/{} created with path={} after {} ms.", i, mailboxPathList.size(), mailboxPath, Calendar.getInstance().getTimeInMillis() - start.getTimeInMillis());
- } catch (MailboxExistsException e) {
- LOGGER.error("Mailbox {} with path={} already exists.", i, mailboxPath, e);
- }
- dstMailboxManager.endProcessingRequest(dstMailboxSession);
-
- srcMailboxManager.startProcessingRequest(srcMailboxSession);
- MessageManager srcMessageManager = srcMailboxManager.getMailbox(mailboxPath, srcMailboxSession);
- srcMailboxManager.endProcessingRequest(srcMailboxSession);
-
- dstMailboxManager.startProcessingRequest(dstMailboxSession);
- MessageManager dstMessageManager = dstMailboxManager.getMailbox(mailboxPath, dstMailboxSession);
-
- int j = 0;
- Iterator<MessageResult> messageResultIterator = srcMessageManager.getMessages(MessageRange.all(), GROUP, srcMailboxSession);
-
- while (messageResultIterator.hasNext()) {
-
- MessageResult messageResult = messageResultIterator.next();
- InputStreamContent content = (InputStreamContent) messageResult.getFullContent();
-
- dstMailboxManager.startProcessingRequest(dstMailboxSession);
- dstMessageManager.appendMessage(content.getInputStream(), messageResult.getInternalDate(), dstMailboxSession, messageResult.getFlags().contains(Flag.RECENT), messageResult.getFlags());
- dstMailboxManager.endProcessingRequest(dstMailboxSession);
- LOGGER.info("MailboxMessage #{} appended in destination mailbox with path={}", j, mailboxPath);
- j++;
-
- }
- dstMailboxManager.endProcessingRequest(dstMailboxSession);
-
- } else {
- LOGGER.info("Destination mailbox {}/{} with path={} has a null or empty name", i, mailboxPathList.size(), mailboxPath);
- }
-
- }
-
- LOGGER.info("Mailboxes copied in {} ms.", Calendar.getInstance().getTimeInMillis() - start.getTimeInMillis());
-
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/mailbox/tool/src/reporting-site/site.xml
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/reporting-site/site.xml b/mailbox/tool/src/reporting-site/site.xml
deleted file mode 100644
index d919164..0000000
--- a/mailbox/tool/src/reporting-site/site.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- 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.
--->
-<project name="${project.name}">
-
- <body>
-
- <menu ref="parent" />
- <menu ref="reports" />
-
- </body>
-
-</project>
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/mailbox/tool/src/test/java/org/apache/james/mailbox/copier/MailboxCopierTest.java
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/test/java/org/apache/james/mailbox/copier/MailboxCopierTest.java b/mailbox/tool/src/test/java/org/apache/james/mailbox/copier/MailboxCopierTest.java
deleted file mode 100644
index 77d4c42..0000000
--- a/mailbox/tool/src/test/java/org/apache/james/mailbox/copier/MailboxCopierTest.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/****************************************************************
- * 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.mailbox.copier;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageManager;
-import org.apache.james.mailbox.MessageManager.MetaData.FetchGroup;
-import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
-import org.apache.james.mailbox.exception.BadCredentialsException;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
-import org.apache.james.mailbox.mock.DataProvisioner;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.store.StoreMailboxManager;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Test class for the {@link MailboxCopierImpl} implementation.
- *
- * The InMemoryMailboxManager will be used as source and destination
- * Mailbox Manager.
- *
- */
-public class MailboxCopierTest {
- /**
- * The instance for the test mailboxCopier.
- */
- private MailboxCopierImpl mailboxCopier;
-
- /**
- * The instance for the source Mailbox Manager.
- */
- private MailboxManager srcMemMailboxManager;
-
- /**
- * The instance for the destination Mailbox Manager.
- */
- private MailboxManager dstMemMailboxManager;
-
- /**
- * Setup the mailboxCopier and the source and destination
- * Mailbox Manager.
- *
- * We use a InMemoryMailboxManager implementation.
- *
- * @throws BadCredentialsException
- * @throws MailboxException
- */
- @Before
- public void setup() throws BadCredentialsException, MailboxException {
- mailboxCopier = new MailboxCopierImpl();
-
- srcMemMailboxManager = newInMemoryMailboxManager();
- dstMemMailboxManager = newInMemoryMailboxManager();
-
- }
-
- /**
- * Feed the source MailboxManager with the number of mailboxes and
- * messages per mailbox.
- *
- * Copy the mailboxes to the destination Mailbox Manager, and assert the number
- * of mailboxes and messages per mailbox is the same as in the source
- * Mailbox Manager.
- *
- * @throws MailboxException
- * @throws IOException
- */
- @Test
- public void testMailboxCopy() throws MailboxException, IOException {
- if (srcMemMailboxManager instanceof StoreMailboxManager) {
- ((StoreMailboxManager) srcMemMailboxManager).init();
- }
- if (dstMemMailboxManager instanceof StoreMailboxManager) {
- ((StoreMailboxManager) dstMemMailboxManager).init();
- }
-
- DataProvisioner.feedMailboxManager(srcMemMailboxManager);
-
- assertMailboxManagerSize(srcMemMailboxManager, 1);
-
- mailboxCopier.copyMailboxes(srcMemMailboxManager, dstMemMailboxManager);
- assertMailboxManagerSize(dstMemMailboxManager, 1);
-
- // We copy a second time to assert existing mailboxes does not give issue.
- mailboxCopier.copyMailboxes(srcMemMailboxManager, dstMemMailboxManager);
- assertMailboxManagerSize(dstMemMailboxManager, 2);
-
- }
-
- /**
- * Utility method to assert the number of mailboxes and messages per mailbox
- * are the ones expected.
- *
- * @throws MailboxException
- * @throws BadCredentialsException
- */
- private void assertMailboxManagerSize(MailboxManager mailboxManager, int multiplicationFactor) throws BadCredentialsException, MailboxException {
- MailboxSession mailboxSession = mailboxManager.createSystemSession("manager");
- mailboxManager.startProcessingRequest(mailboxSession);
-
- List<MailboxPath> mailboxPathList = mailboxManager.list(mailboxSession);
-
- assertThat(mailboxPathList).hasSize(DataProvisioner.EXPECTED_MAILBOXES_COUNT);
-
- for (MailboxPath mailboxPath: mailboxPathList) {
- MailboxSession userSession = mailboxManager.createSystemSession(mailboxPath.getUser());
- mailboxManager.startProcessingRequest(mailboxSession);
- MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, userSession);
- assertThat(messageManager.getMetaData(false, userSession, FetchGroup.NO_UNSEEN).getMessageCount()).isEqualTo(DataProvisioner.MESSAGE_PER_MAILBOX_COUNT * multiplicationFactor);
- }
-
- mailboxManager.endProcessingRequest(mailboxSession);
- mailboxManager.logout(mailboxSession, true);
-
- }
-
- /**
- * Utility method to instanciate a new InMemoryMailboxManger with
- * the needed MailboxSessionMapperFactory, Authenticator and UidProvider.
- *
- * @return a new InMemoryMailboxManager
- */
- private MailboxManager newInMemoryMailboxManager() throws MailboxException {
- return new InMemoryIntegrationResources()
- .createMailboxManager(new SimpleGroupMembershipResolver());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/mailbox/tools/copier/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/tools/copier/pom.xml b/mailbox/tools/copier/pom.xml
new file mode 100644
index 0000000..b7fc4c4
--- /dev/null
+++ b/mailbox/tools/copier/pom.xml
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<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">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>apache-james-mailbox-tools</artifactId>
+ <groupId>org.apache.james</groupId>
+ <version>3.2.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>apache-james-mailbox-tools-copier</artifactId>
+ <name>Apache James :: Mailbox :: Tools :: Copier</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-mailbox-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-mailbox-api</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-mailbox-memory</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-mailbox-memory</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-mailbox-store</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-mailbox-store</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/mailbox/tools/copier/src/main/java/org/apache/james/mailbox/tools/copier/MailboxCopierImpl.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/copier/src/main/java/org/apache/james/mailbox/tools/copier/MailboxCopierImpl.java b/mailbox/tools/copier/src/main/java/org/apache/james/mailbox/tools/copier/MailboxCopierImpl.java
new file mode 100644
index 0000000..88adef4
--- /dev/null
+++ b/mailbox/tools/copier/src/main/java/org/apache/james/mailbox/tools/copier/MailboxCopierImpl.java
@@ -0,0 +1,142 @@
+/****************************************************************
+ * 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.mailbox.tools.copier;
+
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.mail.Flags.Flag;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.copier.MailboxCopier;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.exception.MailboxExistsException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.model.MessageResult;
+import org.apache.james.mailbox.model.MessageResult.FetchGroup;
+import org.apache.james.mailbox.store.streaming.InputStreamContent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implementation of the {@link MailboxCopier} interface.
+ *
+ */
+public class MailboxCopierImpl implements MailboxCopier {
+ private static final Logger LOGGER = LoggerFactory.getLogger(MailboxCopierImpl.class.getName());
+
+ private static final FetchGroup GROUP = new FetchGroup() {
+
+ @Override
+ public int content() {
+ return FULL_CONTENT;
+ }
+
+ @Override
+ public Set<PartContentDescriptor> getPartContentDescriptors() {
+ return new HashSet<>();
+ }
+
+ };
+
+ @Override
+ public void copyMailboxes(MailboxManager srcMailboxManager, MailboxManager dstMailboxManager) throws MailboxException, IOException {
+
+ Calendar start = Calendar.getInstance();
+
+ MailboxSession srcMailboxSession;
+ MailboxSession dstMailboxSession;
+
+ List<MailboxPath> mailboxPathList = null;
+
+ srcMailboxSession = srcMailboxManager.createSystemSession("manager");
+ srcMailboxManager.startProcessingRequest(srcMailboxSession);
+ mailboxPathList = srcMailboxManager.list(srcMailboxSession);
+ srcMailboxManager.endProcessingRequest(srcMailboxSession);
+
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info("Found " + mailboxPathList.size() + " mailboxes in source mailbox manager.");
+ for (int i = 0; i < mailboxPathList.size(); i++) {
+ LOGGER.info("Mailbox#" + i + " path=" + mailboxPathList.get(i));
+ }
+ }
+
+ MailboxPath mailboxPath = null;
+
+ for (int i = 0; i < mailboxPathList.size(); i++) {
+
+ mailboxPath = mailboxPathList.get(i);
+
+ if ((mailboxPath.getName() != null) && (mailboxPath.getName().trim().length() > 0)) {
+
+ LOGGER.info("Ready to copy source mailbox path={}", mailboxPath);
+
+ srcMailboxSession = srcMailboxManager.createSystemSession(mailboxPath.getUser());
+ dstMailboxSession = dstMailboxManager.createSystemSession(mailboxPath.getUser());
+
+ dstMailboxManager.startProcessingRequest(dstMailboxSession);
+ try {
+ dstMailboxManager.createMailbox(mailboxPath, dstMailboxSession);
+ LOGGER.info("Destination mailbox {}/{} created with path={} after {} ms.", i, mailboxPathList.size(), mailboxPath, Calendar.getInstance().getTimeInMillis() - start.getTimeInMillis());
+ } catch (MailboxExistsException e) {
+ LOGGER.error("Mailbox {} with path={} already exists.", i, mailboxPath, e);
+ }
+ dstMailboxManager.endProcessingRequest(dstMailboxSession);
+
+ srcMailboxManager.startProcessingRequest(srcMailboxSession);
+ MessageManager srcMessageManager = srcMailboxManager.getMailbox(mailboxPath, srcMailboxSession);
+ srcMailboxManager.endProcessingRequest(srcMailboxSession);
+
+ dstMailboxManager.startProcessingRequest(dstMailboxSession);
+ MessageManager dstMessageManager = dstMailboxManager.getMailbox(mailboxPath, dstMailboxSession);
+
+ int j = 0;
+ Iterator<MessageResult> messageResultIterator = srcMessageManager.getMessages(MessageRange.all(), GROUP, srcMailboxSession);
+
+ while (messageResultIterator.hasNext()) {
+
+ MessageResult messageResult = messageResultIterator.next();
+ InputStreamContent content = (InputStreamContent) messageResult.getFullContent();
+
+ dstMailboxManager.startProcessingRequest(dstMailboxSession);
+ dstMessageManager.appendMessage(content.getInputStream(), messageResult.getInternalDate(), dstMailboxSession, messageResult.getFlags().contains(Flag.RECENT), messageResult.getFlags());
+ dstMailboxManager.endProcessingRequest(dstMailboxSession);
+ LOGGER.info("MailboxMessage #{} appended in destination mailbox with path={}", j, mailboxPath);
+ j++;
+
+ }
+ dstMailboxManager.endProcessingRequest(dstMailboxSession);
+
+ } else {
+ LOGGER.info("Destination mailbox {}/{} with path={} has a null or empty name", i, mailboxPathList.size(), mailboxPath);
+ }
+
+ }
+
+ LOGGER.info("Mailboxes copied in {} ms.", Calendar.getInstance().getTimeInMillis() - start.getTimeInMillis());
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/mailbox/tools/copier/src/test/java/org/apache/james/mailbox/tools/copier/MailboxCopierTest.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/copier/src/test/java/org/apache/james/mailbox/tools/copier/MailboxCopierTest.java b/mailbox/tools/copier/src/test/java/org/apache/james/mailbox/tools/copier/MailboxCopierTest.java
new file mode 100644
index 0000000..6c6db9c
--- /dev/null
+++ b/mailbox/tools/copier/src/test/java/org/apache/james/mailbox/tools/copier/MailboxCopierTest.java
@@ -0,0 +1,152 @@
+/****************************************************************
+ * 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.mailbox.tools.copier;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.MessageManager.MetaData.FetchGroup;
+import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
+import org.apache.james.mailbox.exception.BadCredentialsException;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
+import org.apache.james.mailbox.mock.DataProvisioner;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test class for the {@link MailboxCopierImpl} implementation.
+ *
+ * The InMemoryMailboxManager will be used as source and destination
+ * Mailbox Manager.
+ *
+ */
+public class MailboxCopierTest {
+ /**
+ * The instance for the test mailboxCopier.
+ */
+ private MailboxCopierImpl mailboxCopier;
+
+ /**
+ * The instance for the source Mailbox Manager.
+ */
+ private MailboxManager srcMemMailboxManager;
+
+ /**
+ * The instance for the destination Mailbox Manager.
+ */
+ private MailboxManager dstMemMailboxManager;
+
+ /**
+ * Setup the mailboxCopier and the source and destination
+ * Mailbox Manager.
+ *
+ * We use a InMemoryMailboxManager implementation.
+ *
+ * @throws BadCredentialsException
+ * @throws MailboxException
+ */
+ @Before
+ public void setup() throws BadCredentialsException, MailboxException {
+ mailboxCopier = new MailboxCopierImpl();
+
+ srcMemMailboxManager = newInMemoryMailboxManager();
+ dstMemMailboxManager = newInMemoryMailboxManager();
+
+ }
+
+ /**
+ * Feed the source MailboxManager with the number of mailboxes and
+ * messages per mailbox.
+ *
+ * Copy the mailboxes to the destination Mailbox Manager, and assert the number
+ * of mailboxes and messages per mailbox is the same as in the source
+ * Mailbox Manager.
+ *
+ * @throws MailboxException
+ * @throws IOException
+ */
+ @Test
+ public void testMailboxCopy() throws MailboxException, IOException {
+ if (srcMemMailboxManager instanceof StoreMailboxManager) {
+ ((StoreMailboxManager) srcMemMailboxManager).init();
+ }
+ if (dstMemMailboxManager instanceof StoreMailboxManager) {
+ ((StoreMailboxManager) dstMemMailboxManager).init();
+ }
+
+ DataProvisioner.feedMailboxManager(srcMemMailboxManager);
+
+ assertMailboxManagerSize(srcMemMailboxManager, 1);
+
+ mailboxCopier.copyMailboxes(srcMemMailboxManager, dstMemMailboxManager);
+ assertMailboxManagerSize(dstMemMailboxManager, 1);
+
+ // We copy a second time to assert existing mailboxes does not give issue.
+ mailboxCopier.copyMailboxes(srcMemMailboxManager, dstMemMailboxManager);
+ assertMailboxManagerSize(dstMemMailboxManager, 2);
+
+ }
+
+ /**
+ * Utility method to assert the number of mailboxes and messages per mailbox
+ * are the ones expected.
+ *
+ * @throws MailboxException
+ * @throws BadCredentialsException
+ */
+ private void assertMailboxManagerSize(MailboxManager mailboxManager, int multiplicationFactor) throws BadCredentialsException, MailboxException {
+ MailboxSession mailboxSession = mailboxManager.createSystemSession("manager");
+ mailboxManager.startProcessingRequest(mailboxSession);
+
+ List<MailboxPath> mailboxPathList = mailboxManager.list(mailboxSession);
+
+ assertThat(mailboxPathList).hasSize(DataProvisioner.EXPECTED_MAILBOXES_COUNT);
+
+ for (MailboxPath mailboxPath: mailboxPathList) {
+ MailboxSession userSession = mailboxManager.createSystemSession(mailboxPath.getUser());
+ mailboxManager.startProcessingRequest(mailboxSession);
+ MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, userSession);
+ assertThat(messageManager.getMetaData(false, userSession, FetchGroup.NO_UNSEEN).getMessageCount()).isEqualTo(DataProvisioner.MESSAGE_PER_MAILBOX_COUNT * multiplicationFactor);
+ }
+
+ mailboxManager.endProcessingRequest(mailboxSession);
+ mailboxManager.logout(mailboxSession, true);
+
+ }
+
+ /**
+ * Utility method to instanciate a new InMemoryMailboxManger with
+ * the needed MailboxSessionMapperFactory, Authenticator and UidProvider.
+ *
+ * @return a new InMemoryMailboxManager
+ */
+ private MailboxManager newInMemoryMailboxManager() throws MailboxException {
+ return new InMemoryIntegrationResources()
+ .createMailboxManager(new SimpleGroupMembershipResolver());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/mailbox/tools/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/tools/pom.xml b/mailbox/tools/pom.xml
index 342fe84..83b6bbf 100644
--- a/mailbox/tools/pom.xml
+++ b/mailbox/tools/pom.xml
@@ -32,6 +32,7 @@
<name>Apache James :: Mailbox :: Tools</name>
<modules>
+ <module>copier</module>
<module>indexer</module>
<module>jpa-migrator</module>
<module>maildir-utils</module>
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 929fece..ebcb293 100644
--- a/pom.xml
+++ b/pom.xml
@@ -874,7 +874,7 @@
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
- <artifactId>apache-james-mailbox-tool</artifactId>
+ <artifactId>apache-james-mailbox-tools-copier</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/server/container/guice/jmx/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/jmx/pom.xml b/server/container/guice/jmx/pom.xml
index 6d76d07..c813246 100644
--- a/server/container/guice/jmx/pom.xml
+++ b/server/container/guice/jmx/pom.xml
@@ -34,6 +34,10 @@
<dependencies>
<dependency>
<groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-mailbox-tools-copier</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
<artifactId>apache-james-mailbox-tools-indexer</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java b/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java
index 1a6fae0..1910697 100644
--- a/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java
+++ b/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java
@@ -36,8 +36,8 @@ import org.apache.james.domainlist.api.DomainListManagementMBean;
import org.apache.james.domainlist.lib.DomainListManagement;
import org.apache.james.lifecycle.api.Configurable;
import org.apache.james.mailbox.copier.MailboxCopier;
-import org.apache.james.mailbox.copier.MailboxCopierImpl;
import org.apache.james.mailbox.indexer.ReIndexer;
+import org.apache.james.mailbox.tools.copier.MailboxCopierImpl;
import org.apache.james.mailetcontainer.api.jmx.MailSpoolerMBean;
import org.apache.james.mailetcontainer.impl.JamesMailSpooler;
import org.apache.james.rrt.api.RecipientRewriteTableManagementMBean;
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/server/container/spring/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/spring/pom.xml b/server/container/spring/pom.xml
index cb430c4..b01fdc4 100644
--- a/server/container/spring/pom.xml
+++ b/server/container/spring/pom.xml
@@ -43,10 +43,6 @@
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
- <artifactId>apache-james-mailbox-tool</artifactId>
- </dependency>
- <dependency>
- <groupId>${james.groupId}</groupId>
<artifactId>apache-mailet-api</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/4fea9913/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
----------------------------------------------------------------------
diff --git a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
index 297b579..78b0d71 100644
--- a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
+++ b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
@@ -156,7 +156,7 @@
<import resource="classpath:META-INF/spring/event-system.xml"/>
<!-- Mailbox Copier -->
- <bean id="mailboxcopier" class="org.apache.james.mailbox.copier.MailboxCopierImpl"/>
+ <bean id="mailboxcopier" class="org.apache.james.mailbox.tools.copier.MailboxCopierImpl"/>
<bean id="mailboxmanagerresolver" class="org.apache.james.container.spring.mailbox.SpringResolver" />
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org