JAMES-2502 merge util and util-java8
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/630dcab1 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/630dcab1 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/630dcab1 Branch: refs/heads/master Commit: 630dcab1ace49b8f8592c41a624a000964cec7ee Parents: 136acc1 Author: Matthieu Baechler <matth...@apache.org> Authored: Tue Jul 31 16:35:00 2018 +0200 Committer: Matthieu Baechler <matth...@apache.org> Committed: Wed Aug 1 14:20:23 2018 +0200 ---------------------------------------------------------------------- backends-common/cassandra/pom.xml | 4 +- backends-common/elasticsearch/pom.xml | 2 +- core/pom.xml | 5 - mailbox/api/pom.xml | 5 - mailbox/cassandra/pom.xml | 1 - mailbox/elasticsearch/pom.xml | 2 +- mailbox/jpa/pom.xml | 1 - mailbox/memory/pom.xml | 1 - mailbox/store/pom.xml | 4 - mailet/standard/pom.xml | 5 - mdn/pom.xml | 2 +- mpt/impl/smtp/cassandra/pom.xml | 2 +- mpt/impl/smtp/core/pom.xml | 2 +- pom.xml | 11 - protocols/imap/pom.xml | 5 - protocols/netty/pom.xml | 2 +- server/blob/blob-api/pom.xml | 2 +- server/blob/blob-cassandra/pom.xml | 2 +- server/container/guice/cassandra-guice/pom.xml | 2 +- .../guice/cassandra-ldap-guice/pom.xml | 2 +- server/container/guice/guice-utils/pom.xml | 2 +- server/container/mailbox-adapter/pom.xml | 2 +- .../metrics/metrics-es-reporter/pom.xml | 2 +- server/container/util-java8/pom.xml | 110 ---- .../org/apache/james/util/ClassLoaderUtils.java | 54 -- .../james/util/CompletableFutureUtil.java | 124 ----- .../apache/james/util/FluentFutureStream.java | 191 ------- .../java/org/apache/james/util/GuavaUtils.java | 37 -- .../main/java/org/apache/james/util/Host.java | 137 ----- .../java/org/apache/james/util/MDCBuilder.java | 147 ------ .../apache/james/util/MDCStructuredLogger.java | 50 -- .../org/apache/james/util/MemoizedSupplier.java | 30 -- .../org/apache/james/util/OptionalUtils.java | 68 --- .../main/java/org/apache/james/util/Port.java | 58 --- .../java/org/apache/james/util/Runnables.java | 40 -- .../java/org/apache/james/util/StreamUtils.java | 52 -- .../org/apache/james/util/StructuredLogger.java | 30 -- .../java/org/apache/james/util/ValuePatch.java | 125 ----- .../util/date/DefaultZonedDateTimeProvider.java | 31 -- .../james/util/date/ImapDateTimeFormatter.java | 94 ---- .../james/util/date/ZonedDateTimeProvider.java | 28 - .../util/mime/MessageContentExtractor.java | 233 --------- .../apache/james/util/streams/Iterators.java | 32 -- .../james/util/streams/JamesCollectors.java | 80 --- .../org/apache/james/util/streams/Limit.java | 81 --- .../org/apache/james/util/streams/Offset.java | 66 --- .../apache/james/util/CommutativityChecker.java | 58 --- .../james/util/CommutativityCheckerTest.java | 101 ---- .../james/util/CompletableFutureUtilTest.java | 424 --------------- .../james/util/FluentFutureStreamTest.java | 258 ---------- .../org/apache/james/util/GuavaUtilsTest.java | 80 --- .../java/org/apache/james/util/HostTest.java | 219 -------- .../org/apache/james/util/MDCBuilderTest.java | 138 ----- .../apache/james/util/MemoizedSupplierTest.java | 84 --- .../apache/james/util/OptionalUtilsTest.java | 243 --------- .../java/org/apache/james/util/PortTest.java | 92 ---- .../org/apache/james/util/StreamUtilsTest.java | 115 ----- .../org/apache/james/util/ValuePatchTest.java | 220 -------- .../util/date/ImapDateTimeFormatterTest.java | 252 --------- .../util/mime/MessageContentExtractorTest.java | 514 ------------------- .../util/streams/ImmutableCollectorsTest.java | 123 ----- .../james/util/streams/IteratorsTest.java | 58 --- .../james/util/streams/JamesCollectorsTest.java | 121 ----- .../apache/james/util/streams/LimitTest.java | 115 ----- .../apache/james/util/streams/OffsetTest.java | 58 --- .../test/resources/testcontainers.properties | 4 - server/container/util/pom.xml | 26 + .../org/apache/james/util/ClassLoaderUtils.java | 54 ++ .../james/util/CompletableFutureUtil.java | 124 +++++ .../apache/james/util/FluentFutureStream.java | 191 +++++++ .../java/org/apache/james/util/GuavaUtils.java | 37 ++ .../main/java/org/apache/james/util/Host.java | 137 +++++ .../java/org/apache/james/util/MDCBuilder.java | 147 ++++++ .../apache/james/util/MDCStructuredLogger.java | 50 ++ .../org/apache/james/util/MemoizedSupplier.java | 30 ++ .../org/apache/james/util/OptionalUtils.java | 68 +++ .../main/java/org/apache/james/util/Port.java | 58 +++ .../java/org/apache/james/util/Runnables.java | 40 ++ .../java/org/apache/james/util/StreamUtils.java | 52 ++ .../org/apache/james/util/StructuredLogger.java | 30 ++ .../java/org/apache/james/util/ValuePatch.java | 125 +++++ .../util/date/DefaultZonedDateTimeProvider.java | 31 ++ .../james/util/date/ImapDateTimeFormatter.java | 94 ++++ .../james/util/date/ZonedDateTimeProvider.java | 28 + .../util/mime/MessageContentExtractor.java | 233 +++++++++ .../apache/james/util/streams/Iterators.java | 32 ++ .../james/util/streams/JamesCollectors.java | 80 +++ .../org/apache/james/util/streams/Limit.java | 81 +++ .../org/apache/james/util/streams/Offset.java | 66 +++ .../apache/james/util/CommutativityChecker.java | 58 +++ .../james/util/CommutativityCheckerTest.java | 102 ++++ .../james/util/CompletableFutureUtilTest.java | 424 +++++++++++++++ .../james/util/FluentFutureStreamTest.java | 258 ++++++++++ .../org/apache/james/util/GuavaUtilsTest.java | 81 +++ .../java/org/apache/james/util/HostTest.java | 219 ++++++++ .../org/apache/james/util/MDCBuilderTest.java | 139 +++++ .../apache/james/util/MemoizedSupplierTest.java | 84 +++ .../apache/james/util/OptionalUtilsTest.java | 243 +++++++++ .../java/org/apache/james/util/PortTest.java | 92 ++++ .../org/apache/james/util/StreamUtilsTest.java | 115 +++++ .../org/apache/james/util/ValuePatchTest.java | 220 ++++++++ .../util/date/ImapDateTimeFormatterTest.java | 252 +++++++++ .../util/mime/MessageContentExtractorTest.java | 514 +++++++++++++++++++ .../util/streams/ImmutableCollectorsTest.java | 123 +++++ .../james/util/streams/IteratorsTest.java | 58 +++ .../james/util/streams/JamesCollectorsTest.java | 121 +++++ .../apache/james/util/streams/LimitTest.java | 115 +++++ .../apache/james/util/streams/OffsetTest.java | 58 +++ server/data/data-jmap/pom.xml | 2 +- .../data/data-ldap-integration-testing/pom.xml | 2 +- server/mailet/integration-testing/pom.xml | 2 +- server/mailet/mailetcontainer-camel/pom.xml | 2 +- .../cassandra-jmap-integration-testing/pom.xml | 6 - .../jmap-integration-testing-common/pom.xml | 6 - .../memory-jmap-integration-testing/pom.xml | 6 - server/protocols/jmap/pom.xml | 6 +- server/protocols/protocols-imap4/pom.xml | 2 +- server/protocols/protocols-managesieve/pom.xml | 2 +- server/protocols/webadmin/webadmin-core/pom.xml | 2 +- server/protocols/webadmin/webadmin-data/pom.xml | 2 +- .../protocols/webadmin/webadmin-mailbox/pom.xml | 2 +- .../webadmin/webadmin-mailrepository/pom.xml | 2 +- server/queue/queue-rabbitmq/pom.xml | 2 +- server/task/pom.xml | 2 +- server/testing/pom.xml | 2 +- 125 files changed, 5119 insertions(+), 5264 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/backends-common/cassandra/pom.xml ---------------------------------------------------------------------- diff --git a/backends-common/cassandra/pom.xml b/backends-common/cassandra/pom.xml index 1b16ea0..675bae5 100644 --- a/backends-common/cassandra/pom.xml +++ b/backends-common/cassandra/pom.xml @@ -45,11 +45,11 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> + <artifactId>james-server-util</artifactId> </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> + <artifactId>james-server-util</artifactId> <type>test-jar</type> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/backends-common/elasticsearch/pom.xml ---------------------------------------------------------------------- diff --git a/backends-common/elasticsearch/pom.xml b/backends-common/elasticsearch/pom.xml index bf4ba84..02af1ed 100644 --- a/backends-common/elasticsearch/pom.xml +++ b/backends-common/elasticsearch/pom.xml @@ -30,7 +30,7 @@ <dependencies> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> + <artifactId>james-server-util</artifactId> </dependency> <dependency> <groupId>${james.groupId}</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/core/pom.xml ---------------------------------------------------------------------- diff --git a/core/pom.xml b/core/pom.xml index 0f533dc..ba3bce5 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -39,11 +39,6 @@ <dependency> <groupId>${james.groupId}</groupId> <artifactId>james-server-util</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> </dependency> <dependency> <groupId>com.google.guava</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/mailbox/api/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/api/pom.xml b/mailbox/api/pom.xml index d136e63..9081a9b 100644 --- a/mailbox/api/pom.xml +++ b/mailbox/api/pom.xml @@ -39,11 +39,6 @@ <dependency> <groupId>${james.groupId}</groupId> <artifactId>james-server-util</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> </dependency> <dependency> <groupId>${james.groupId}</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/mailbox/cassandra/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/cassandra/pom.xml b/mailbox/cassandra/pom.xml index dd20476..fb1c5aa 100644 --- a/mailbox/cassandra/pom.xml +++ b/mailbox/cassandra/pom.xml @@ -84,7 +84,6 @@ <dependency> <groupId>${james.groupId}</groupId> <artifactId>james-server-util</artifactId> - <scope>test</scope> </dependency> <dependency> <groupId>${james.groupId}</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/mailbox/elasticsearch/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/elasticsearch/pom.xml b/mailbox/elasticsearch/pom.xml index b9563c9..193e472 100644 --- a/mailbox/elasticsearch/pom.xml +++ b/mailbox/elasticsearch/pom.xml @@ -86,7 +86,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> + <artifactId>james-server-util</artifactId> <type>test-jar</type> <scope>test</scope> </dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/mailbox/jpa/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/jpa/pom.xml b/mailbox/jpa/pom.xml index b9b0e64..45b057f 100644 --- a/mailbox/jpa/pom.xml +++ b/mailbox/jpa/pom.xml @@ -65,7 +65,6 @@ <dependency> <groupId>${james.groupId}</groupId> <artifactId>james-server-util</artifactId> - <scope>test</scope> </dependency> <dependency> <groupId>ch.qos.logback</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/mailbox/memory/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/memory/pom.xml b/mailbox/memory/pom.xml index ffee6aa..f8616f3 100644 --- a/mailbox/memory/pom.xml +++ b/mailbox/memory/pom.xml @@ -55,7 +55,6 @@ <dependency> <groupId>${james.groupId}</groupId> <artifactId>james-server-util</artifactId> - <scope>test</scope> </dependency> <dependency> <groupId>ch.qos.logback</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/mailbox/store/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/store/pom.xml b/mailbox/store/pom.xml index 8c45a55..8033192 100644 --- a/mailbox/store/pom.xml +++ b/mailbox/store/pom.xml @@ -69,10 +69,6 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> <artifactId>metrics-api</artifactId> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/mailet/standard/pom.xml ---------------------------------------------------------------------- diff --git a/mailet/standard/pom.xml b/mailet/standard/pom.xml index d0dc22b..e0de349 100644 --- a/mailet/standard/pom.xml +++ b/mailet/standard/pom.xml @@ -53,11 +53,6 @@ <dependency> <groupId>${james.groupId}</groupId> <artifactId>james-server-util</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> </dependency> <dependency> <groupId>${james.groupId}</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/mdn/pom.xml ---------------------------------------------------------------------- diff --git a/mdn/pom.xml b/mdn/pom.xml index f04a46d..d925395 100644 --- a/mdn/pom.xml +++ b/mdn/pom.xml @@ -37,7 +37,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> + <artifactId>james-server-util</artifactId> </dependency> <dependency> <groupId>${james.groupId}</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/mpt/impl/smtp/cassandra/pom.xml ---------------------------------------------------------------------- diff --git a/mpt/impl/smtp/cassandra/pom.xml b/mpt/impl/smtp/cassandra/pom.xml index e38c657..3942beb 100644 --- a/mpt/impl/smtp/cassandra/pom.xml +++ b/mpt/impl/smtp/cassandra/pom.xml @@ -69,7 +69,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> + <artifactId>james-server-util</artifactId> <type>test-jar</type> <scope>test</scope> </dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/mpt/impl/smtp/core/pom.xml ---------------------------------------------------------------------- diff --git a/mpt/impl/smtp/core/pom.xml b/mpt/impl/smtp/core/pom.xml index 045de64..8489164 100644 --- a/mpt/impl/smtp/core/pom.xml +++ b/mpt/impl/smtp/core/pom.xml @@ -53,7 +53,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> + <artifactId>james-server-util</artifactId> <type>test-jar</type> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 2007c5f..de9542f 100644 --- a/pom.xml +++ b/pom.xml @@ -1522,17 +1522,6 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> - <version>${project.version}</version> - <type>test-jar</type> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> <artifactId>james-server-webadmin</artifactId> <version>${project.version}</version> </dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/protocols/imap/pom.xml ---------------------------------------------------------------------- diff --git a/protocols/imap/pom.xml b/protocols/imap/pom.xml index a14726a..484cfe4 100644 --- a/protocols/imap/pom.xml +++ b/protocols/imap/pom.xml @@ -59,11 +59,6 @@ <dependency> <groupId>${james.groupId}</groupId> <artifactId>james-server-util</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> </dependency> <dependency> <groupId>${james.groupId}</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/protocols/netty/pom.xml ---------------------------------------------------------------------- diff --git a/protocols/netty/pom.xml b/protocols/netty/pom.xml index 062a2cb..7161638 100644 --- a/protocols/netty/pom.xml +++ b/protocols/netty/pom.xml @@ -35,7 +35,7 @@ <dependencies> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> + <artifactId>james-server-util</artifactId> </dependency> <dependency> <groupId>${james.protocols.groupId}</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/blob/blob-api/pom.xml ---------------------------------------------------------------------- diff --git a/server/blob/blob-api/pom.xml b/server/blob/blob-api/pom.xml index 9ebf1cf..8eba84b 100644 --- a/server/blob/blob-api/pom.xml +++ b/server/blob/blob-api/pom.xml @@ -35,7 +35,7 @@ <dependencies> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> + <artifactId>james-server-util</artifactId> </dependency> <dependency> <groupId>com.google.guava</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/blob/blob-cassandra/pom.xml ---------------------------------------------------------------------- diff --git a/server/blob/blob-cassandra/pom.xml b/server/blob/blob-cassandra/pom.xml index e99e241..af1456d 100644 --- a/server/blob/blob-cassandra/pom.xml +++ b/server/blob/blob-cassandra/pom.xml @@ -55,7 +55,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> + <artifactId>james-server-util</artifactId> </dependency> <dependency> <groupId>com.google.guava</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/guice/cassandra-guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-guice/pom.xml b/server/container/guice/cassandra-guice/pom.xml index 77bd32b..af6166b 100644 --- a/server/container/guice/cassandra-guice/pom.xml +++ b/server/container/guice/cassandra-guice/pom.xml @@ -209,7 +209,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> + <artifactId>james-server-util</artifactId> <type>test-jar</type> <scope>test</scope> </dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/guice/cassandra-ldap-guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-ldap-guice/pom.xml b/server/container/guice/cassandra-ldap-guice/pom.xml index 30b5382..3f14183 100644 --- a/server/container/guice/cassandra-ldap-guice/pom.xml +++ b/server/container/guice/cassandra-ldap-guice/pom.xml @@ -104,7 +104,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> + <artifactId>james-server-util</artifactId> <type>test-jar</type> <scope>test</scope> </dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/guice/guice-utils/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-utils/pom.xml b/server/container/guice/guice-utils/pom.xml index bed5d72..ce22975 100644 --- a/server/container/guice/guice-utils/pom.xml +++ b/server/container/guice/guice-utils/pom.xml @@ -35,7 +35,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> + <artifactId>james-server-util</artifactId> </dependency> <dependency> <groupId>com.github.fge</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/mailbox-adapter/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/mailbox-adapter/pom.xml b/server/container/mailbox-adapter/pom.xml index 8a8927a..8e3c338 100644 --- a/server/container/mailbox-adapter/pom.xml +++ b/server/container/mailbox-adapter/pom.xml @@ -86,7 +86,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> + <artifactId>james-server-util</artifactId> </dependency> <dependency> <groupId>com.google.guava</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/metrics/metrics-es-reporter/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/metrics/metrics-es-reporter/pom.xml b/server/container/metrics/metrics-es-reporter/pom.xml index 89b5e4a..f989919 100644 --- a/server/container/metrics/metrics-es-reporter/pom.xml +++ b/server/container/metrics/metrics-es-reporter/pom.xml @@ -36,7 +36,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> + <artifactId>james-server-util</artifactId> </dependency> <dependency> <groupId>${james.groupId}</groupId> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/util-java8/pom.xml b/server/container/util-java8/pom.xml deleted file mode 100644 index 5a3e2d0..0000000 --- a/server/container/util-java8/pom.xml +++ /dev/null @@ -1,110 +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>james-server</artifactId> - <version>3.2.0-SNAPSHOT</version> - <relativePath>../../pom.xml</relativePath> - </parent> - - <artifactId>james-server-util-java8</artifactId> - <name>Apache James :: Server :: Common Utilities :: Java 8</name> - - <dependencies> - <dependency> - <groupId>${james.groupId}</groupId> - <artifactId>apache-mime4j-dom</artifactId> - </dependency> - <dependency> - <groupId>com.github.fge</groupId> - <artifactId>throwing-lambdas</artifactId> - </dependency> - <dependency> - <groupId>com.github.steveash.guavate</groupId> - <artifactId>guavate</artifactId> - </dependency> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - </dependency> - <dependency> - <groupId>com.sun.mail</groupId> - <artifactId>javax.mail</artifactId> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - </dependency> - <dependency> - <groupId>javax.inject</groupId> - <artifactId>javax.inject</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>nl.jqno.equalsverifier</groupId> - <artifactId>equalsverifier</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.assertj</groupId> - <artifactId>assertj-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - </dependency> - <dependency> - <groupId>org.testcontainers</groupId> - <artifactId>testcontainers</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.github.dpaukov</groupId> - <artifactId>combinatoricslib3</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <reuseForks>true</reuseForks> - <forkCount>1C</forkCount> - </configuration> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/src/main/java/org/apache/james/util/ClassLoaderUtils.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/ClassLoaderUtils.java b/server/container/util-java8/src/main/java/org/apache/james/util/ClassLoaderUtils.java deleted file mode 100644 index 68d9b08..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/ClassLoaderUtils.java +++ /dev/null @@ -1,54 +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.util; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; - -import javax.mail.util.SharedByteArrayInputStream; - -import org.apache.commons.io.IOUtils; - -public class ClassLoaderUtils { - public static String getSystemResourceAsString(String filename, Charset charset) { - try { - return IOUtils.toString(ClassLoader.getSystemResourceAsStream(filename), charset); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static String getSystemResourceAsString(String filename) { - return getSystemResourceAsString(filename, StandardCharsets.US_ASCII); - } - - public static byte[] getSystemResourceAsByteArray(String filename) { - try { - return IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream(filename)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static SharedByteArrayInputStream getSystemResourceAsSharedStream(String filename) { - return new SharedByteArrayInputStream(getSystemResourceAsByteArray(filename)); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/src/main/java/org/apache/james/util/CompletableFutureUtil.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/CompletableFutureUtil.java b/server/container/util-java8/src/main/java/org/apache/james/util/CompletableFutureUtil.java deleted file mode 100644 index d2e83af..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/CompletableFutureUtil.java +++ /dev/null @@ -1,124 +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.util; - -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.BiFunction; -import java.util.function.BinaryOperator; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.stream.Stream; - -public class CompletableFutureUtil { - - public static <T> CompletableFuture<Optional<T>> unwrap(CompletableFuture<Optional<CompletableFuture<T>>> base) { - return base.thenCompose( - optional -> optional.map(future -> future.thenApply(Optional::of)) - .orElse(CompletableFuture.completedFuture(Optional.empty()))); - } - - @SafeVarargs - public static <T> CompletableFuture<Stream<T>> allOfArray(CompletableFuture<T>... futures) { - return allOf(Stream.of(futures)); - } - - public static <T, U, V> CompletableFuture<V> combine(CompletableFuture<T> t, CompletableFuture<U> u, BiFunction<T,U,V> combiner) { - return t.thenCompose(valueT -> - u.thenApply(valueU -> combiner.apply(valueT, valueU))); - } - - public static <T> CompletableFuture<Stream<T>> allOf(Stream<CompletableFuture<T>> futureStream) { - return futureStream - .map((CompletableFuture<T> future) -> future.thenApply(Stream::of)) - .parallel() - .reduce((future1, future2) -> - future1.thenCompose( - stream1 -> future2.thenCompose( - stream2 -> { - Stream<T> concatStream = Stream.concat(stream1, stream2); - return CompletableFuture.completedFuture(concatStream); - }))) - .orElse(CompletableFuture.completedFuture(Stream.of())); - } - - public static <R, T> CompletableFuture<Stream<R>> chainAll(Stream<T> futureStream, - Function<T, CompletableFuture<R>> transformationToChain) { - return futureStream - .map(t -> (Supplier<CompletableFuture<R>>) (() -> transformationToChain.apply(t))) - .reduce(CompletableFuture.<Stream<R>>completedFuture(Stream.of()), - (accumulator, supplier) -> - accumulator.thenCompose( - accumulatedStream -> - supplier.get() - .thenCompose(r -> - CompletableFuture.completedFuture(Stream.<R>concat(accumulatedStream, Stream.of(r)))) - ), - getCompletableFutureBinaryOperator()); - } - - private static <R> BinaryOperator<CompletableFuture<Stream<R>>> getCompletableFutureBinaryOperator() { - return (future1, future2) -> - future1.thenCompose(stream1 -> - future2.<Stream<R>>thenCompose(stream2 -> - CompletableFuture.completedFuture(Stream.concat(stream1, stream2)))); - } - - public static <T> CompletableFuture<Stream<T>> performOnAll(CompletableFuture<Stream<T>> futurStream, Function<T, CompletableFuture<Void>> action) { - return thenComposeOnAll(futurStream, value -> - keepValue(() -> - action.apply(value), - value)); - } - - public static <T, U> CompletableFuture<Stream<U>> thenComposeOnAll(CompletableFuture<Stream<T>> futurStream, Function<T, CompletableFuture<U>> action) { - return futurStream - .thenCompose(stream -> - CompletableFutureUtil.allOf( - stream.map(action))); - } - - public static <T, U> CompletableFuture<Stream<U>> map(CompletableFuture<Stream<T>> futurStream, Function<T, U> action) { - return futurStream - .thenApply(stream -> - stream.map(action)); - } - - public static <T> CompletableFuture<Optional<T>> reduce(BinaryOperator<T> binaryOperator, CompletableFuture<Stream<T>> futureStream) { - return futureStream.thenApply(stream -> stream.reduce(binaryOperator)); - } - - public static <T> CompletableFuture<T> reduce(BinaryOperator<T> binaryOperator, CompletableFuture<Stream<T>> futureStream, T emptyAccumulator) { - return futureStream.thenApply(stream -> stream.reduce(binaryOperator).orElse(emptyAccumulator)); - } - - public static <T> CompletableFuture<T> keepValue(Supplier<CompletableFuture<Void>> supplier, T value) { - return supplier.get().thenApply(any -> value); - } - - public static <T> Function<Boolean, CompletableFuture<Boolean>> composeIfTrue(Supplier<CompletableFuture<T>> composeOperation) { - return b -> { - if (b) { - return composeOperation.get().thenApply(any -> b); - } - return CompletableFuture.completedFuture(b); - }; - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/src/main/java/org/apache/james/util/FluentFutureStream.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/FluentFutureStream.java b/server/container/util-java8/src/main/java/org/apache/james/util/FluentFutureStream.java deleted file mode 100644 index 9dcae7a..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/FluentFutureStream.java +++ /dev/null @@ -1,191 +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.util; - -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.BinaryOperator; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.stream.Collector; -import java.util.stream.Stream; - -public class FluentFutureStream<T> { - - private final CompletableFuture<Stream<T>> completableFuture; - - /** - * Constructs a FluentFutureStream from a future of Stream. - */ - public static <T> FluentFutureStream<T> of(CompletableFuture<Stream<T>> completableFuture) { - return new FluentFutureStream<>(completableFuture); - } - - /** - * Constructs a FluentFutureStream from a Stream of Future - */ - public static <T> FluentFutureStream<T> of(Stream<CompletableFuture<T>> completableFutureStream) { - return new FluentFutureStream<>(CompletableFutureUtil.allOf(completableFutureStream)); - } - - /** - * Constructs a FluentFutureStream from a Stream of Future of Stream. - * - * Underlying streams are flatMapped. - */ - public static <T> FluentFutureStream<T> ofNestedStreams(Stream<CompletableFuture<Stream<T>>> completableFuture) { - return of(completableFuture) - .flatMap(Function.identity()); - } - - /** - * Constructs a FluentFutureStream from a Stream of Future of Optionals. - * - * Underlying optionals are unboxed. - */ - public static <T> FluentFutureStream<T> ofOptionals(Stream<CompletableFuture<Optional<T>>> completableFuture) { - return of(completableFuture) - .flatMapOptional(Function.identity()); - } - - /** - * Constructs a FluentFutureStream from the supplied futures. - */ - @SafeVarargs - public static <T> FluentFutureStream<T> ofFutures(CompletableFuture<T>... completableFutures) { - return new FluentFutureStream<>(CompletableFutureUtil.allOfArray(completableFutures)); - } - - private FluentFutureStream(CompletableFuture<Stream<T>> completableFuture) { - this.completableFuture = completableFuture; - } - - /** - * For all values of the underlying stream, an action will be performed. - */ - public FluentFutureStream<T> performOnAll(Function<T, CompletableFuture<Void>> action) { - return FluentFutureStream.of( - CompletableFutureUtil.performOnAll(completableFuture(), action)); - } - - /** - * Apply a transformation to all values of the underlying stream. - */ - public <U> FluentFutureStream<U> map(Function<T, U> function) { - return FluentFutureStream.of( - CompletableFutureUtil.map(completableFuture(), function)); - } - - /** - * Apply a transformation to all value of the underlying stream. - * - * As the supplied transformation produces streams, the results will be flatMapped. - */ - public <U> FluentFutureStream<U> flatMap(Function<T, Stream<U>> function) { - return FluentFutureStream.of(completableFuture().thenApply(stream -> - stream.flatMap(function))); - } - - /** - * Apply a transformation to all value of the underlying stream. - * - * As the supplied transformation produces optionals, the results will be unboxed. - */ - public <U> FluentFutureStream<U> flatMapOptional(Function<T, Optional<U>> function) { - return map(function) - .flatMap(OptionalUtils::toStream); - } - - /** - * Apply a transformation to all value of the underlying stream. - * - * As the supplied transformation produces futures, we need to compose the returned values. - */ - public <U> FluentFutureStream<U> thenComposeOnAll(Function<T, CompletableFuture<U>> function) { - return FluentFutureStream.of( - CompletableFutureUtil.thenComposeOnAll(completableFuture(), function)); - } - - /** - * Apply a transformation to all value of the underlying stream. - * - * As the supplied transformation produces futures of stream, we need to compose then flatMap the returned values. - */ - public <U> FluentFutureStream<U> thenFlatCompose(Function<T, CompletableFuture<Stream<U>>> function) { - return FluentFutureStream.of( - CompletableFutureUtil.thenComposeOnAll(completableFuture(), function)) - .flatMap(Function.identity()); - } - - /** - * Apply a transformation to all value of the underlying stream. - * - * As the supplied transformation produces futures of optionals, we need to compose then unbox the returned values. - */ - public <U> FluentFutureStream<U> thenFlatComposeOnOptional(Function<T, CompletableFuture<Optional<U>>> function) { - return FluentFutureStream.of( - CompletableFutureUtil.thenComposeOnAll(completableFuture(), function)) - .flatMapOptional(Function.identity()); - } - - /** - * Filter the values of the underlying stream. - */ - public FluentFutureStream<T> filter(Predicate<T> predicate) { - return FluentFutureStream.of(completableFuture - .thenApply(stream -> stream.filter(predicate))); - } - - /** - * Reduces the underlying stream. Reduced value is supplied as a Future of optional, as no empty value is supplied. - */ - public CompletableFuture<Optional<T>> reduce(BinaryOperator<T> combiner) { - return CompletableFutureUtil.reduce(combiner, completableFuture); - } - - /** - * educes the underlying stream. Reduced value is supplied as a Future, as an empty value is specified. - */ - public CompletableFuture<T> reduce(T emptyAccumulator, BinaryOperator<T> combiner) { - return CompletableFutureUtil.reduce(combiner, completableFuture, emptyAccumulator); - } - - /** - * Returns a future of the underlying stream. - */ - public CompletableFuture<Stream<T>> completableFuture() { - return this.completableFuture; - } - - /** - * Returns the future of the underlying collected stream. - */ - public <C> CompletableFuture<C> collect(Collector<T, ?, C> collector) { - return this.completableFuture - .thenApply(stream -> stream.collect(collector)); - } - - /** - * Join and returns the underlying stream. - */ - public Stream<T> join() { - return completableFuture().join(); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/src/main/java/org/apache/james/util/GuavaUtils.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/GuavaUtils.java b/server/container/util-java8/src/main/java/org/apache/james/util/GuavaUtils.java deleted file mode 100644 index 518ead1..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/GuavaUtils.java +++ /dev/null @@ -1,37 +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.util; - -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.tuple.Pair; - -import com.github.steveash.guavate.Guavate; -import com.google.common.collect.ImmutableListMultimap; - -public class GuavaUtils { - public static <K, V> ImmutableListMultimap<K, V> toMultimap(Map<K, List<V>> rights) { - return rights.entrySet() - .stream() - .flatMap(e -> e.getValue().stream().map(right -> Pair.of(e.getKey(), right))) - .collect(Guavate.toImmutableListMultimap(Pair::getKey, Pair::getValue)); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/src/main/java/org/apache/james/util/Host.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/Host.java b/server/container/util-java8/src/main/java/org/apache/james/util/Host.java deleted file mode 100644 index cb6acce..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/Host.java +++ /dev/null @@ -1,137 +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.util; - -import java.util.List; -import java.util.Optional; - -import com.github.steveash.guavate.Guavate; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Objects; -import com.google.common.base.Preconditions; -import com.google.common.base.Splitter; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; - -public class Host { - - public static ImmutableList<Host> parseHosts(String hostsString) { - return parseHosts(hostsString, Optional.empty()); - } - - public static ImmutableList<Host> parseHosts(String hostsString, int defaultPort) { - return parseHosts(hostsString, Optional.of(defaultPort)); - } - - private static ImmutableList<Host> parseHosts(String hostsString, Optional<Integer> defaultPort) { - return Splitter.on(',') - .omitEmptyStrings() - .splitToList(hostsString) - .stream() - .map(string -> Host.parse(string, defaultPort)) - .distinct() - .collect(Guavate.toImmutableList()); - } - - public static Host from(String hostname, int port) { - return new Host(hostname, port); - } - - public static Host parseConfString(String ipAndPort, int defaultPort) { - return parse(ipAndPort, Optional.of(defaultPort)); - } - - public static Host parseConfString(String ipAndPort) { - return parse(ipAndPort, Optional.empty()); - } - - public static Host parse(String ipAndPort, Optional<Integer> defaultPort) { - Preconditions.checkNotNull(ipAndPort); - Preconditions.checkArgument(!ipAndPort.isEmpty()); - - List<String> parts = retrieveHostParts(ipAndPort); - - String ip = parts.get(0); - int port = getPortFromConfPart(parts, defaultPort); - - return new Host(ip, port); - } - - private static List<String> retrieveHostParts(String ipAndPort) { - List<String> parts = Splitter.on(':') - .trimResults() - .splitToList(ipAndPort); - - if (parts.size() < 1 || parts.size() > 2) { - throw new IllegalArgumentException(ipAndPort + " is not a valid cassandra node"); - } - return parts; - } - - private static int getPortFromConfPart(List<String> parts, Optional<Integer> defaultPort) { - if (parts.size() == 2) { - return Integer.valueOf(parts.get(1)); - } - if (parts.size() == 1) { - return defaultPort.orElseThrow(() -> new IllegalArgumentException("Host do not have port part but no default port provided")); - } - throw new RuntimeException("A host should be either a hostname or a hostname and a port separated by a ':'"); - } - - private final String hostName; - private final int port; - - @VisibleForTesting - Host(String hostName, int port) { - Preconditions.checkNotNull(hostName, "Hostname could not be null"); - Preconditions.checkArgument(!Strings.isNullOrEmpty(hostName), "Hostname could not be empty"); - Port.assertValid(port); - this.hostName = hostName; - this.port = port; - } - - public String getHostName() { - return hostName; - } - - public int getPort() { - return port; - } - - @Override - public final int hashCode() { - return Objects.hashCode(hostName, port); - } - - @Override - public final boolean equals(Object object) { - if (object instanceof Host) { - Host that = (Host) object; - return Objects.equal(this.hostName, that.hostName) - && Objects.equal(this.port, that.port); - } - return false; - } - - @Override - public String toString() { - return this.hostName + ":" + this.port; - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/src/main/java/org/apache/james/util/MDCBuilder.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/MDCBuilder.java b/server/container/util-java8/src/main/java/org/apache/james/util/MDCBuilder.java deleted file mode 100644 index e6709c8..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/MDCBuilder.java +++ /dev/null @@ -1,147 +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.util; - -import java.io.Closeable; -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.function.Supplier; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.MDC; - -import com.github.steveash.guavate.Guavate; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -public class MDCBuilder { - - public interface VoidOperation { - void perform(); - } - - public static <T> T withMdc(MDCBuilder mdcBuilder, Supplier<T> answerSupplier) { - try (Closeable closeable = mdcBuilder.build()) { - try { - return answerSupplier.get(); - } catch (RuntimeException e) { - LOGGER.error("Got error, logging its context", e); - throw e; - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static void withMdc(MDCBuilder mdcBuilder, VoidOperation logOperation) { - withMdc(mdcBuilder, () -> { - logOperation.perform(); - return null; - }); - } - - public static final String HOST = "host"; - public static final String IP = "ip"; - public static final String PROTOCOL = "protocol"; - public static final String USER = "user"; - public static final String ACTION = "action"; - public static final String SESSION_ID = "sessionId"; - public static final String CHARSET = "charset"; - - private static final Logger LOGGER = LoggerFactory.getLogger(MDCBuilder.class); - - public static class Closeables implements Closeable { - private final List<Closeable> closeables; - - public Closeables(List<Closeable> closeables) { - Preconditions.checkNotNull(closeables); - this.closeables = ImmutableList.copyOf(closeables); - } - - @Override - public void close() throws IOException { - closeables.forEach(this::closeQuietly); - } - - private void closeQuietly(Closeable closeable) { - try { - closeable.close(); - } catch (IOException e) { - LOGGER.warn("Failed to close Closeable", e); - } - } - } - - public static MDCBuilder create() { - return new MDCBuilder(); - } - - private final ImmutableMap.Builder<String, String> contextMap = ImmutableMap.builder(); - private final ImmutableList.Builder<MDCBuilder> nestedBuilder = ImmutableList.builder(); - - private MDCBuilder() {} - - public MDCBuilder addContext(MDCBuilder nested) { - this.nestedBuilder.add(nested); - return this; - } - - public MDCBuilder addContext(String key, Object value) { - Preconditions.checkNotNull(key); - Optional.ofNullable(value) - .ifPresent(nonNullValue -> contextMap.put(key, nonNullValue.toString())); - return this; - } - - @VisibleForTesting - Map<String, String> buildContextMap() { - return ImmutableMap.<String, String>builder() - .putAll(nestedBuilder.build() - .stream() - .map(MDCBuilder::buildContextMap) - .flatMap(map -> map.entrySet().stream()) - .collect(Guavate.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue))) - .putAll(contextMap.build()) - .build(); - } - - public <T> T execute(Supplier<T> supplier) { - return MDCBuilder.withMdc(this, supplier); - } - - public <T> Supplier<T> wrapArround(Supplier<T> supplier) { - return () -> execute(supplier); - } - - public Closeable build() { - return new Closeables( - buildContextMap() - .entrySet() - .stream() - .map(entry -> MDC.putCloseable(entry.getKey(), entry.getValue())) - .collect(Guavate.toImmutableList())); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/src/main/java/org/apache/james/util/MDCStructuredLogger.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/MDCStructuredLogger.java b/server/container/util-java8/src/main/java/org/apache/james/util/MDCStructuredLogger.java deleted file mode 100644 index cf970ea..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/MDCStructuredLogger.java +++ /dev/null @@ -1,50 +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.util; - -import java.util.function.Consumer; - -import org.slf4j.Logger; - -public class MDCStructuredLogger implements StructuredLogger { - - public static MDCStructuredLogger forLogger(Logger logger) { - return new MDCStructuredLogger(logger); - } - - private final Logger logger; - private final MDCBuilder mdcBuilder; - - public MDCStructuredLogger(Logger logger) { - this.logger = logger; - this.mdcBuilder = MDCBuilder.create(); - } - - @Override - public StructuredLogger addField(String name, Object value) { - mdcBuilder.addContext(name, value); - return this; - } - - @Override - public void log(Consumer<Logger> logOperation) { - MDCBuilder.withMdc(mdcBuilder, () -> logOperation.accept(logger)); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/src/main/java/org/apache/james/util/MemoizedSupplier.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/MemoizedSupplier.java b/server/container/util-java8/src/main/java/org/apache/james/util/MemoizedSupplier.java deleted file mode 100644 index d0b4e3b..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/MemoizedSupplier.java +++ /dev/null @@ -1,30 +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.util; - -import java.util.function.Supplier; - -import com.google.common.base.Suppliers; - -public class MemoizedSupplier { - public static <T> Supplier<T> of(Supplier<T> originalSupplier) { - return Suppliers.memoize(originalSupplier::get)::get; - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/src/main/java/org/apache/james/util/OptionalUtils.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/OptionalUtils.java b/server/container/util-java8/src/main/java/org/apache/james/util/OptionalUtils.java deleted file mode 100644 index 4a3449c..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/OptionalUtils.java +++ /dev/null @@ -1,68 +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.util; - -import java.util.Arrays; -import java.util.Optional; -import java.util.function.Supplier; -import java.util.stream.Stream; - -public class OptionalUtils { - - @FunctionalInterface - public interface Operation { - void perform(); - } - - public static <T> Optional<T> executeIfEmpty(Optional<T> optional, Operation operation) { - if (!optional.isPresent()) { - operation.perform(); - } - return optional; - } - - public static <T> Stream<T> toStream(Optional<T> optional) { - return optional.map(Stream::of) - .orElse(Stream.of()); - } - - @SafeVarargs - public static <T> Optional<T> or(Optional<T>... optionals) { - return orStream(Arrays.stream(optionals)); - } - - @SafeVarargs - public static <T> Optional<T> orSuppliers(Supplier<Optional<T>>... suppliers) { - return orStream(Arrays.stream(suppliers) - .map(Supplier::get)); - } - - private static <T> Optional<T> orStream(Stream<Optional<T>> stream) { - return stream - .filter(Optional::isPresent) - .findFirst() - .orElse(Optional.empty()); - } - - public static <T> boolean containsDifferent(Optional<T> requestValue, T storeValue) { - return requestValue - .filter(value -> !value.equals(storeValue)) - .isPresent(); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/src/main/java/org/apache/james/util/Port.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/Port.java b/server/container/util-java8/src/main/java/org/apache/james/util/Port.java deleted file mode 100644 index 016c4b4..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/Port.java +++ /dev/null @@ -1,58 +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.util; - -import java.util.Random; - -import com.google.common.base.Preconditions; -import com.google.common.collect.Range; - -public class Port { - public static final int MAX_PORT_VALUE = 65535; - public static final int PRIVILEGED_PORT_BOUND = 1024; - private static final Range<Integer> VALID_PORT_RANGE = Range.closed(1, MAX_PORT_VALUE); - - public static int generateValidUnprivilegedPort() { - return new Random().nextInt(Port.MAX_PORT_VALUE - PRIVILEGED_PORT_BOUND) + PRIVILEGED_PORT_BOUND; - } - - public static void assertValid(int port) { - Preconditions.checkArgument(isValid(port), "Port should be between 1 and 65535"); - } - - public static boolean isValid(int port) { - return VALID_PORT_RANGE.contains(port); - } - - private final int value; - - public Port(int value) { - validate(value); - this.value = value; - } - - protected void validate(int port) { - assertValid(port); - } - - public int getValue() { - return value; - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/src/main/java/org/apache/james/util/Runnables.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/Runnables.java b/server/container/util-java8/src/main/java/org/apache/james/util/Runnables.java deleted file mode 100644 index c199f31..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/Runnables.java +++ /dev/null @@ -1,40 +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.util; - -import java.util.Arrays; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - -public class Runnables { - public static void runParallel(Runnable... runnables) { - FluentFutureStream.of( - Arrays.stream(runnables) - .map(runnable -> CompletableFuture.supplyAsync(toVoidSupplier(runnable)))) - .join(); - } - - private static Supplier<Void> toVoidSupplier(Runnable runnable) { - return () -> { - runnable.run(); - return null; - }; - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/src/main/java/org/apache/james/util/StreamUtils.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/StreamUtils.java b/server/container/util-java8/src/main/java/org/apache/james/util/StreamUtils.java deleted file mode 100644 index e8a71bd..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/StreamUtils.java +++ /dev/null @@ -1,52 +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.util; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Optional; -import java.util.function.Function; -import java.util.stream.Stream; - -public class StreamUtils { - - public static <T> Stream<T> ofNullable(T[] array) { - return ofOptional(Optional.ofNullable(array)); - } - - public static <T> Stream<T> ofOptional(Optional<T[]> array) { - return array - .map(Arrays::stream) - .orElse(Stream.empty()); - } - - public static <T> Stream<T> flatten(Collection<Stream<T>> streams) { - return flatten(streams.stream()); - } - - public static <T> Stream<T> flatten(Stream<Stream<T>> streams) { - return streams.flatMap(Function.identity()); - } - - @SafeVarargs - public static <T> Stream<T> flatten(Stream<T>... streams) { - return flatten(Arrays.stream(streams)); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/src/main/java/org/apache/james/util/StructuredLogger.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/StructuredLogger.java b/server/container/util-java8/src/main/java/org/apache/james/util/StructuredLogger.java deleted file mode 100644 index f6fcec4..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/StructuredLogger.java +++ /dev/null @@ -1,30 +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.util; - -import java.util.function.Consumer; - -import org.slf4j.Logger; - -public interface StructuredLogger { - StructuredLogger addField(String name, Object value); - - void log(Consumer<Logger> logOperation); -} http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/src/main/java/org/apache/james/util/ValuePatch.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/ValuePatch.java b/server/container/util-java8/src/main/java/org/apache/james/util/ValuePatch.java deleted file mode 100644 index 5c3d01a..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/ValuePatch.java +++ /dev/null @@ -1,125 +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.util; - -import java.util.NoSuchElementException; -import java.util.Objects; -import java.util.Optional; -import java.util.function.Function; - -import com.google.common.base.Preconditions; - -public class ValuePatch<T> { - - private enum State { - KEEP, - REMOVE, - MODIFY - } - - public static <T> ValuePatch<T> modifyTo(T value) { - Preconditions.checkNotNull(value); - return new ValuePatch<>(value, State.MODIFY); - } - - public static <T> ValuePatch<T> ofNullable(T value) { - return ofOptional(Optional.ofNullable(value)); - } - - public static <T> ValuePatch<T> ofOptional(Optional<T> value) { - Preconditions.checkNotNull(value); - return value.map(ValuePatch::modifyTo) - .orElse(ValuePatch.remove()); - } - - public static <T> ValuePatch<T> remove() { - return new ValuePatch<>(null, State.REMOVE); - } - - public static <T> ValuePatch<T> keep() { - return new ValuePatch<>(null, State.KEEP); - } - - private final T value; - private final State state; - - private ValuePatch(T value, State state) { - this.value = value; - this.state = state; - } - - public boolean isRemoved() { - return state == State.REMOVE; - } - - public boolean isModified() { - return state == State.MODIFY; - } - - public boolean isKept() { - return state == State.KEEP; - } - - public <S> Optional<S> mapNotKeptToOptional(Function<Optional<T>, S> updateTransformation) { - if (isKept()) { - return Optional.empty(); - } - return Optional.of(updateTransformation.apply(Optional.ofNullable(value))); - } - - public T get() { - if (isModified()) { - return value; - } else { - throw new NoSuchElementException(); - } - } - - public Optional<T> notKeptOrElse(Optional<T> replacement) { - if (isKept()) { - return replacement; - } - return Optional.ofNullable(value); - } - - public Optional<T> toOptional() { - return Optional.ofNullable(value); - } - - public T getOrElse(T replacement) { - return toOptional().orElse(replacement); - } - - @Override - public boolean equals(Object o) { - if (o instanceof ValuePatch) { - ValuePatch<?> that = (ValuePatch<?>) o; - return Objects.equals(this.value, that.value) && - Objects.equals(this.state, that.state); - } else { - return false; - } - } - - @Override - public int hashCode() { - return Objects.hash(value, state); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/src/main/java/org/apache/james/util/date/DefaultZonedDateTimeProvider.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/date/DefaultZonedDateTimeProvider.java b/server/container/util-java8/src/main/java/org/apache/james/util/date/DefaultZonedDateTimeProvider.java deleted file mode 100644 index 47b776a..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/date/DefaultZonedDateTimeProvider.java +++ /dev/null @@ -1,31 +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.util.date; - -import java.time.ZoneOffset; -import java.time.ZonedDateTime; - -public class DefaultZonedDateTimeProvider implements ZonedDateTimeProvider { - - @Override - public ZonedDateTime get() { - return ZonedDateTime.now(ZoneOffset.UTC); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/630dcab1/server/container/util-java8/src/main/java/org/apache/james/util/date/ImapDateTimeFormatter.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/date/ImapDateTimeFormatter.java b/server/container/util-java8/src/main/java/org/apache/james/util/date/ImapDateTimeFormatter.java deleted file mode 100644 index 0a0d633..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/date/ImapDateTimeFormatter.java +++ /dev/null @@ -1,94 +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.util.date; - -import static java.time.temporal.ChronoField.DAY_OF_MONTH; -import static java.time.temporal.ChronoField.DAY_OF_WEEK; -import static java.time.temporal.ChronoField.HOUR_OF_DAY; -import static java.time.temporal.ChronoField.MINUTE_OF_HOUR; -import static java.time.temporal.ChronoField.MONTH_OF_YEAR; -import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; -import static java.time.temporal.ChronoField.YEAR; - -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeFormatterBuilder; -import java.time.format.SignStyle; - -import com.google.common.collect.ImmutableMap; - -public class ImapDateTimeFormatter { - - private static final int INITIAL_YEAR = 1970; - - public static DateTimeFormatter rfc5322() { - return new DateTimeFormatterBuilder() - .parseCaseInsensitive() - .parseLenient() - .optionalStart() - .appendText(DAY_OF_WEEK, dayOfWeek()) - .appendLiteral(", ") - .optionalEnd() - .appendValue(DAY_OF_MONTH, 1, 2, SignStyle.NOT_NEGATIVE) - .appendLiteral(' ') - .appendText(MONTH_OF_YEAR, monthOfYear()) - .appendLiteral(' ') - .appendValueReduced(YEAR, 2, 4, INITIAL_YEAR) - .appendLiteral(' ') - .appendValue(HOUR_OF_DAY, 2) - .appendLiteral(':') - .appendValue(MINUTE_OF_HOUR, 2) - .optionalStart() - .appendLiteral(':') - .appendValue(SECOND_OF_MINUTE, 2) - .optionalEnd() - .appendLiteral(' ') - .appendOffset("+HHMM", "GMT") - .toFormatter(); - } - - private static ImmutableMap<Long, String> monthOfYear() { - return ImmutableMap.<Long, String>builder() - .put(1L, "Jan") - .put(2L, "Feb") - .put(3L, "Mar") - .put(4L, "Apr") - .put(5L, "May") - .put(6L, "Jun") - .put(7L, "Jul") - .put(8L, "Aug") - .put(9L, "Sep") - .put(10L, "Oct") - .put(11L, "Nov") - .put(12L, "Dec") - .build(); - } - - private static ImmutableMap<Long, String> dayOfWeek() { - return ImmutableMap.<Long, String>builder() - .put(1L, "Mon") - .put(2L, "Tue") - .put(3L, "Wed") - .put(4L, "Thu") - .put(5L, "Fri") - .put(6L, "Sat") - .put(7L, "Sun") - .build(); - } - -} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org