james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject svn commit: r1709628 - in /james/project/trunk/server/container: core/ core/src/main/java/org/apache/james/core/ filesystem-api/src/main/java/org/apache/james/filesystem/api/ spring/src/main/java/org/apache/james/container/spring/context/ spring/src/ma...
Date Tue, 20 Oct 2015 15:48:31 GMT
Author: matthieu
Date: Tue Oct 20 15:48:30 2015
New Revision: 1709628

URL: http://svn.apache.org/viewvc?rev=1709628&view=rev
Log:
JAMES-1606: Split JamesResourceLoader and define a non spring interface to provide directories

Added:
    james/project/trunk/server/container/core/src/main/java/org/apache/james/core/JamesServerResourceLoader.java
    james/project/trunk/server/container/filesystem-api/src/main/java/org/apache/james/filesystem/api/JamesDirectoriesProvider.java
    james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/resource/DefaultJamesResourceLoader.java
Removed:
    james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/resource/AbstractJamesResourceLoader.java
    james/project/trunk/server/container/spring/src/test/java/org/apache/james/container/spring/context/
Modified:
    james/project/trunk/server/container/core/pom.xml
    james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/context/JamesServerApplicationContext.java
    james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/context/web/JamesServerWebApplicationContext.java
    james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/resource/JamesResourceLoader.java
    james/project/trunk/server/container/spring/src/test/java/org/apache/james/container/spring/filesystem/FileSystemImplTest.java

Modified: james/project/trunk/server/container/core/pom.xml
URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/core/pom.xml?rev=1709628&r1=1709627&r2=1709628&view=diff
==============================================================================
--- james/project/trunk/server/container/core/pom.xml (original)
+++ james/project/trunk/server/container/core/pom.xml Tue Oct 20 15:48:30 2015
@@ -38,6 +38,10 @@
         <dependency>
             <groupId>org.apache.james</groupId>
             <artifactId>james-server-filesystem-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.james</groupId>
+            <artifactId>james-server-filesystem-api</artifactId>
             <scope>test</scope>
             <type>test-jar</type>
         </dependency>

Added: james/project/trunk/server/container/core/src/main/java/org/apache/james/core/JamesServerResourceLoader.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/core/src/main/java/org/apache/james/core/JamesServerResourceLoader.java?rev=1709628&view=auto
==============================================================================
--- james/project/trunk/server/container/core/src/main/java/org/apache/james/core/JamesServerResourceLoader.java
(added)
+++ james/project/trunk/server/container/core/src/main/java/org/apache/james/core/JamesServerResourceLoader.java
Tue Oct 20 15:48:30 2015
@@ -0,0 +1,66 @@
+/****************************************************************
+ * 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.core;
+
+import org.apache.james.filesystem.api.JamesDirectoriesProvider;
+
+public class JamesServerResourceLoader implements JamesDirectoriesProvider {
+
+    /**
+     * @see org.apache.james.container.spring.resource.JamesResourceLoader#getAbsoluteDirectory()
+     */
+    public String getAbsoluteDirectory() {
+        return "/";
+    }
+
+    /**
+     * @see
+     * org.apache.james.container.spring.resource.JamesResourceLoader#getConfDirectory()
+     */
+    public String getConfDirectory() {
+        return getRootDirectory() + "/conf/";
+    }
+
+    /**
+     * @see
+     * org.apache.james.container.spring.resource.JamesResourceLoader#getVarDirectory()
+     */
+    public String getVarDirectory() {
+        return getRootDirectory() + "/var/";
+    }
+
+    /**
+     * Return the directory where the external jar libraries must be placed
+     * by the administrator. The jars may contain mailets, jdbc drivers,...
+     * 
+     * @return externalLibraryDirectory
+     */
+    public String getExternalLibraryDirectory() {
+        return getRootDirectory() + "/conf/lib/";
+    }
+
+    /**
+     * @see
+     * org.apache.james.container.spring.resource.JamesResourceLoader#getRootDirectory()
+     */
+    public String getRootDirectory() {
+        return "../";
+    }
+
+}
\ No newline at end of file

Added: james/project/trunk/server/container/filesystem-api/src/main/java/org/apache/james/filesystem/api/JamesDirectoriesProvider.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/filesystem-api/src/main/java/org/apache/james/filesystem/api/JamesDirectoriesProvider.java?rev=1709628&view=auto
==============================================================================
--- james/project/trunk/server/container/filesystem-api/src/main/java/org/apache/james/filesystem/api/JamesDirectoriesProvider.java
(added)
+++ james/project/trunk/server/container/filesystem-api/src/main/java/org/apache/james/filesystem/api/JamesDirectoriesProvider.java
Tue Oct 20 15:48:30 2015
@@ -0,0 +1,51 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.filesystem.api;
+
+public interface JamesDirectoriesProvider {
+
+    /**
+     * Return the configuration directory of the application
+     * 
+     * @return confDir
+     */
+    String getAbsoluteDirectory();
+
+    /**
+     * Return the var directory of the application
+     * 
+     * @return var
+     */
+    String getConfDirectory();
+
+    /**
+     * Return the absolute directory of the application
+     * 
+     * @return absolute
+     */
+    String getVarDirectory();
+
+    /**
+     * Return the root directory of the application
+     * 
+     * @return rootDir
+     */
+    String getRootDirectory();
+
+}

Modified: james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/context/JamesServerApplicationContext.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/context/JamesServerApplicationContext.java?rev=1709628&r1=1709627&r2=1709628&view=diff
==============================================================================
--- james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/context/JamesServerApplicationContext.java
(original)
+++ james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/context/JamesServerApplicationContext.java
Tue Oct 20 15:48:30 2015
@@ -18,8 +18,9 @@
  ****************************************************************/
 package org.apache.james.container.spring.context;
 
-import org.apache.james.container.spring.resource.AbstractJamesResourceLoader;
+import org.apache.james.container.spring.resource.DefaultJamesResourceLoader;
 import org.apache.james.container.spring.resource.JamesResourceLoader;
+import org.apache.james.core.JamesServerResourceLoader;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 import org.springframework.core.io.Resource;
@@ -33,13 +34,20 @@ public class JamesServerApplicationConte
      * The resourceloader to use. This must be defined as static, otherwise it
      * will fail to startup..
      */
-    private final static JamesServerResourceLoader resourceLoader = new JamesServerResourceLoader();
+    private final static JamesResourceLoader resourceLoader = new DefaultJamesResourceLoader(new
JamesServerResourceLoader());
 
     public JamesServerApplicationContext(String[] configs) {
         super(configs);
     }
 
     /**
+     * Protected accessor for the resource loader.
+     */
+    protected JamesResourceLoader getResourceLoader() {
+        return resourceLoader;
+    }
+    
+    /**
      * @see
      * org.springframework.core.io.DefaultResourceLoader#getResource(java.lang.String)
      */
@@ -84,56 +92,4 @@ public class JamesServerApplicationConte
         return getResourceLoader().getRootDirectory();
     }
 
-    /**
-     * Protected accessor for the resource loader.
-     */
-    protected JamesServerResourceLoader getResourceLoader() {
-        return resourceLoader;
-    }
-
-    protected static class JamesServerResourceLoader extends AbstractJamesResourceLoader
{
-
-        /**
-         * @see org.apache.james.container.spring.resource.JamesResourceLoader#getAbsoluteDirectory()
-         */
-        public String getAbsoluteDirectory() {
-            return "/";
-        }
-
-        /**
-         * @see
-         * org.apache.james.container.spring.resource.JamesResourceLoader#getConfDirectory()
-         */
-        public String getConfDirectory() {
-            return getRootDirectory() + "/conf/";
-        }
-
-        /**
-         * @see
-         * org.apache.james.container.spring.resource.JamesResourceLoader#getVarDirectory()
-         */
-        public String getVarDirectory() {
-            return getRootDirectory() + "/var/";
-        }
-
-        /**
-         * Return the directory where the external jar libraries must be placed
-         * by the administrator. The jars may contain mailets, jdbc drivers,...
-         * 
-         * @return externalLibraryDirectory
-         */
-        public String getExternalLibraryDirectory() {
-            return getRootDirectory() + "/conf/lib/";
-        }
-
-        /**
-         * @see
-         * org.apache.james.container.spring.resource.JamesResourceLoader#getRootDirectory()
-         */
-        public String getRootDirectory() {
-            return "../";
-        }
-
-    }
-
 }

Modified: james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/context/web/JamesServerWebApplicationContext.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/context/web/JamesServerWebApplicationContext.java?rev=1709628&r1=1709627&r2=1709628&view=diff
==============================================================================
--- james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/context/web/JamesServerWebApplicationContext.java
(original)
+++ james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/context/web/JamesServerWebApplicationContext.java
Tue Oct 20 15:48:30 2015
@@ -18,8 +18,9 @@
  ****************************************************************/
 package org.apache.james.container.spring.context.web;
 
-import org.apache.james.container.spring.resource.AbstractJamesResourceLoader;
+import org.apache.james.container.spring.resource.DefaultJamesResourceLoader;
 import org.apache.james.container.spring.resource.JamesResourceLoader;
+import org.apache.james.filesystem.api.JamesDirectoriesProvider;
 import org.springframework.core.io.Resource;
 import org.springframework.web.context.support.XmlWebApplicationContext;
 
@@ -32,10 +33,8 @@ public class JamesServerWebApplicationCo
     /**
      * The resourceloader to use
      */
-    private final JamesResourceLoader resourceLoader = new AbstractJamesResourceLoader()
{
-
-        /**
-         */
+    private final JamesResourceLoader resourceLoader = new DefaultJamesResourceLoader(new
JamesDirectoriesProvider() {
+        
         public String getAbsoluteDirectory() {
             if (absoluteDirectory == null) {
                 return getRootDirectory();
@@ -74,7 +73,8 @@ public class JamesServerWebApplicationCo
                 return varDirectory;
             }
         }
-    };
+    });
+    
     private String rootDirectory;
     private String absoluteDirectory;
     private String varDirectory;

Added: james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/resource/DefaultJamesResourceLoader.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/resource/DefaultJamesResourceLoader.java?rev=1709628&view=auto
==============================================================================
--- james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/resource/DefaultJamesResourceLoader.java
(added)
+++ james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/resource/DefaultJamesResourceLoader.java
Tue Oct 20 15:48:30 2015
@@ -0,0 +1,89 @@
+/****************************************************************
+ * 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.container.spring.resource;
+
+import java.io.File;
+
+import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.filesystem.api.JamesDirectoriesProvider;
+import org.springframework.context.ApplicationContext;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.DefaultResourceLoader;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.Resource;
+
+/**
+ * Abstract base class which load JAMES files based on the prefix. This can be
+ * used in different {@link ApplicationContext} implementations
+ */
+public class DefaultJamesResourceLoader extends DefaultResourceLoader implements JamesResourceLoader
{
+
+    private JamesDirectoriesProvider jamesDirectoriesProvider;
+
+    public DefaultJamesResourceLoader(JamesDirectoriesProvider jamesDirectoriesProvider)
{
+        this.jamesDirectoriesProvider = jamesDirectoriesProvider;
+    }
+    
+    /**
+     * Return the {@link Resource} for the given url. If the resource can not be
+     * found null get returned
+     * 
+     * @see org.springframework.core.io.ResourceLoader#getResource(java.lang.String)
+     */
+    public Resource getResource(String fileURL) {
+        Resource r;
+        if (fileURL.startsWith(FileSystem.CLASSPATH_PROTOCOL)) {
+            String resourceName = fileURL.substring(FileSystem.CLASSPATH_PROTOCOL.length());
+            r = new ClassPathResource(resourceName);
+        } else if (fileURL.startsWith(FileSystem.FILE_PROTOCOL)) {
+            File file;
+            if (fileURL.startsWith(FileSystem.FILE_PROTOCOL_AND_CONF)) {
+                file = new File(jamesDirectoriesProvider.getConfDirectory() + "/" + fileURL.substring(FileSystem.FILE_PROTOCOL_AND_CONF.length()));
+            } else if (fileURL.startsWith(FileSystem.FILE_PROTOCOL_AND_VAR)) {
+                file = new File(jamesDirectoriesProvider.getVarDirectory() + "/" + fileURL.substring(FileSystem.FILE_PROTOCOL_AND_VAR.length()));
+            } else if (fileURL.startsWith(FileSystem.FILE_PROTOCOL_ABSOLUTE)) {
+                file = new File(jamesDirectoriesProvider.getAbsoluteDirectory() + fileURL.substring(FileSystem.FILE_PROTOCOL_ABSOLUTE.length()));
+            } else {
+                // move to the root folder of the spring deployment
+                file = new File(jamesDirectoriesProvider.getRootDirectory() + "/" + fileURL.substring(FileSystem.FILE_PROTOCOL.length()));
+            }
+            r = new FileSystemResource(file);
+        } else {
+            return null;
+        }
+        return r;
+    }
+
+    public String getAbsoluteDirectory() {
+        return jamesDirectoriesProvider.getAbsoluteDirectory();
+    }
+
+    public String getConfDirectory() {
+        return jamesDirectoriesProvider.getConfDirectory();
+    }
+
+    public String getVarDirectory() {
+        return jamesDirectoriesProvider.getVarDirectory();
+    }
+
+    public String getRootDirectory() {
+        return jamesDirectoriesProvider.getRootDirectory();
+    }
+    
+}

Modified: james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/resource/JamesResourceLoader.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/resource/JamesResourceLoader.java?rev=1709628&r1=1709627&r2=1709628&view=diff
==============================================================================
--- james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/resource/JamesResourceLoader.java
(original)
+++ james/project/trunk/server/container/spring/src/main/java/org/apache/james/container/spring/resource/JamesResourceLoader.java
Tue Oct 20 15:48:30 2015
@@ -18,40 +18,13 @@
  ****************************************************************/
 package org.apache.james.container.spring.resource;
 
+import org.apache.james.filesystem.api.JamesDirectoriesProvider;
 import org.springframework.core.io.ResourceLoader;
 
 /**
  * {@link ResourceLoader} which offer extra methods to retrieve the Path to all
  * important Directories, which are in use by JAMES.
  */
-public interface JamesResourceLoader extends ResourceLoader {
-
-    /**
-     * Return the configuration directory of the application
-     * 
-     * @return confDir
-     */
-    String getAbsoluteDirectory();
-
-    /**
-     * Return the var directory of the application
-     * 
-     * @return var
-     */
-    String getConfDirectory();
-
-    /**
-     * Return the absolute directory of the application
-     * 
-     * @return absolute
-     */
-    String getVarDirectory();
-
-    /**
-     * Return the root directory of the application
-     * 
-     * @return rootDir
-     */
-    String getRootDirectory();
+public interface JamesResourceLoader extends ResourceLoader, JamesDirectoriesProvider {
 
 }

Modified: james/project/trunk/server/container/spring/src/test/java/org/apache/james/container/spring/filesystem/FileSystemImplTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/spring/src/test/java/org/apache/james/container/spring/filesystem/FileSystemImplTest.java?rev=1709628&r1=1709627&r2=1709628&view=diff
==============================================================================
--- james/project/trunk/server/container/spring/src/test/java/org/apache/james/container/spring/filesystem/FileSystemImplTest.java
(original)
+++ james/project/trunk/server/container/spring/src/test/java/org/apache/james/container/spring/filesystem/FileSystemImplTest.java
Tue Oct 20 15:48:30 2015
@@ -18,7 +18,10 @@
  ****************************************************************/
 package org.apache.james.container.spring.filesystem;
 
-import org.apache.james.container.spring.context.TestApplicationContextProvider;
+import org.apache.james.container.spring.context.JamesServerApplicationContext;
+import org.apache.james.container.spring.resource.DefaultJamesResourceLoader;
+import org.apache.james.container.spring.resource.JamesResourceLoader;
+import org.apache.james.core.JamesServerResourceLoader;
 import org.apache.james.filesystem.api.AbstractFileSystemTest;
 import org.apache.james.filesystem.api.FileSystem;
 
@@ -30,5 +33,33 @@ public class FileSystemImplTest extends
         fs.setApplicationContext(new TestApplicationContextProvider(configurationRootDirectory,
null));
         return fs;
     }
+    
+    private class TestApplicationContextProvider extends JamesServerApplicationContext {
+        private String configurationRootDirectory;
+
+        public TestApplicationContextProvider(String configurationRootDirectory, String[]
configs) {
+            super(configs);
+            this.configurationRootDirectory = configurationRootDirectory;
+        }
+
+        @Override
+        public JamesResourceLoader getResourceLoader() {
+            return new DefaultJamesResourceLoader(new TestDirectoryProvider(configurationRootDirectory));
+        }
+    }
+
+    private static class TestDirectoryProvider extends JamesServerResourceLoader {
+
+        private String configurationRootDirectory;
+
+        public TestDirectoryProvider(String configurationRootDirectory) {
+            this.configurationRootDirectory = configurationRootDirectory;
+        }
+
+        @Override
+        public String getRootDirectory() {
+            return configurationRootDirectory;
+        }
+    }
 
 }



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


Mime
View raw message