JAMES-1759 Extract property files location

Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/3816200b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/3816200b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/3816200b

Branch: refs/heads/master
Commit: 3816200be68cae2a73b97e1403f81fa0c384d5ce
Parents: 42c4e1c
Author: Benoit Tellier <[email protected]>
Authored: Fri Jun 17 11:13:21 2016 +0700
Committer: Benoit Tellier <[email protected]>
Committed: Wed Jun 22 15:34:19 2016 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/jmap/JMAPModule.java  |  9 ++--
 .../apache/james/utils/PropertiesProvider.java  | 46 ++++++++++++++++++++
 2 files changed, 49 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3816200b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java
 
b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java
index 744a220..40acccb 100644
--- 
a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java
+++ 
b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java
@@ -39,6 +39,7 @@ import org.apache.james.transport.mailets.RemoveMimeHeader;
 import org.apache.james.transport.matchers.All;
 import org.apache.james.transport.matchers.RecipientIsLocal;
 import org.apache.james.utils.ConfigurationPerformer;
+import org.apache.james.utils.PropertiesProvider;
 
 import com.github.fge.lambdas.Throwing;
 import com.google.common.base.Preconditions;
@@ -72,8 +73,8 @@ public class JMAPModule extends AbstractModule {
 
     @Provides
     @Singleton
-    JMAPConfiguration provideConfiguration(FileSystem fileSystem) throws 
ConfigurationException, IOException{
-        PropertiesConfiguration configuration = getConfiguration(fileSystem);
+    JMAPConfiguration provideConfiguration(PropertiesProvider 
propertiesProvider, FileSystem fileSystem) throws ConfigurationException, 
IOException{
+        PropertiesConfiguration configuration = 
propertiesProvider.getConfiguration("jmap");
         return JMAPConfiguration.builder()
                 .keystore(configuration.getString("tls.keystoreURL"))
                 .secret(configuration.getString("tls.secret"))
@@ -82,10 +83,6 @@ public class JMAPModule extends AbstractModule {
                 .build();
     }
 
-    private PropertiesConfiguration getConfiguration(FileSystem fileSystem) 
throws FileNotFoundException, ConfigurationException {
-        return new 
PropertiesConfiguration(fileSystem.getFile(FileSystem.FILE_PROTOCOL_AND_CONF + 
"jmap.properties"));
-    }
-
     private Optional<String> loadPublicKey(FileSystem fileSystem, 
Optional<String> jwtPublickeyPemUrl) {
         return jwtPublickeyPemUrl.map(Throwing.function(url -> 
FileUtils.readFileToString(fileSystem.getFile(url))));
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/3816200b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/PropertiesProvider.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/PropertiesProvider.java
 
b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/PropertiesProvider.java
new file mode 100644
index 0000000..780b5ee
--- /dev/null
+++ 
b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/PropertiesProvider.java
@@ -0,0 +1,46 @@
+/****************************************************************
+ * 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.utils;
+
+import java.io.FileNotFoundException;
+
+import javax.inject.Inject;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.filesystem.api.FileSystem;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+
+public class PropertiesProvider {
+
+    private final FileSystem fileSystem;
+
+    @Inject
+    public PropertiesProvider(FileSystem fileSystem) {
+        this.fileSystem = fileSystem;
+    }
+
+    public PropertiesConfiguration getConfiguration(String fileName) throws 
FileNotFoundException, ConfigurationException {
+        Preconditions.checkArgument(!Strings.isNullOrEmpty(fileName));
+        return new 
PropertiesConfiguration(fileSystem.getFile(FileSystem.FILE_PROTOCOL_AND_CONF + 
fileName + ".properties"));
+    }
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to