camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r790121 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/file/ test/java/org/apache/camel/component/file/
Date Wed, 01 Jul 2009 11:20:08 GMT
Author: davsclaus
Date: Wed Jul  1 11:20:08 2009
New Revision: 790121

URL: http://svn.apache.org/viewvc?rev=790121&view=rev
Log:
CAMEL-1779: file consumer now also supports autoCreate option to create the starting directory
if missing.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAutoCreateDirectoryTest.java
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java?rev=790121&r1=790120&r2=790121&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
Wed Jul  1 11:20:08 2009
@@ -39,7 +39,9 @@
         File directory = new File(fileName);
 
         if (!directory.exists() || !directory.isDirectory()) {
-            log.warn("Cannot poll as directory does not exists or its not a directory: "
+ directory);
+            if (log.isDebugEnabled()) {
+                log.debug("Cannot poll as directory does not exists or its not a directory:
" + directory);
+            }
             return;
         }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java?rev=790121&r1=790120&r2=790121&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
Wed Jul  1 11:20:08 2009
@@ -51,6 +51,17 @@
             throw new IllegalArgumentException("Only directory is supported. Endpoint must
be configured with a valid starting directory: " + file);
         }
 
+        // auto create starting directory if needed
+        if (!file.exists() && !file.isDirectory()) {
+            if (isAutoCreate()) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Creating non existing starting directory: " + file);
+                }
+                boolean absolute = file.isAbsolute();
+                operations.buildDirectory(file.getPath(), absolute);
+            }
+        }
+
         FileConsumer result = new FileConsumer(this, processor, operations);
 
         if (isDelete() && getMove() != null) {

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAutoCreateDirectoryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAutoCreateDirectoryTest.java?rev=790121&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAutoCreateDirectoryTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAutoCreateDirectoryTest.java
Wed Jul  1 11:20:08 2009
@@ -0,0 +1,91 @@
+/**
+ * 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.camel.component.file;
+
+import java.io.File;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+/**
+ * @version $Revision$
+ */
+public class FileConsumerAutoCreateDirectoryTest extends ContextTestSupport {
+
+    public void testCreateDirectory() throws Exception {
+        deleteDirectory("target/file/foo");
+
+        Endpoint endpoint = context.getEndpoint("file://target/file/foo");
+        Consumer consumer = endpoint.createConsumer(new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                // noop
+            }
+        });
+
+        consumer.start();
+        consumer.stop();
+
+        // the directory should now exists
+        File dir = new File("target/file/foo").getAbsoluteFile();
+        assertTrue("Directory should be created", dir.exists());
+        assertTrue("Directory should be a directory", dir.isDirectory());
+    }
+
+    public void testCreateAbsoluteDirectory() throws Exception {
+        deleteDirectory("target/file/foo");
+        // use current dir as base as aboslute path
+        String base = new File("").getAbsolutePath() + "/target/file/foo";
+
+        Endpoint endpoint = context.getEndpoint("file://" + base);
+        Consumer consumer = endpoint.createConsumer(new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                // noop
+            }
+        });
+
+        consumer.start();
+        consumer.stop();
+
+        // the directory should now exists
+        File dir = new File(base).getAbsoluteFile();
+        assertTrue("Directory should be created", dir.exists());
+        assertTrue("Directory should be a directory", dir.isDirectory());
+    }
+
+    public void testDoNotCreateDirectory() throws Exception {
+        deleteDirectory("target/file/foo");
+
+        Endpoint endpoint = context.getEndpoint("file://target/file/foo?autoCreate=false");
+        Consumer consumer = endpoint.createConsumer(new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                // noop
+            }
+        });
+
+        consumer.start();
+        consumer.stop();
+
+        // the directory should NOT exists
+        File dir = new File("target/file/foo").getAbsoluteFile();
+        assertFalse("Directory should NOT be created", dir.exists());
+    }
+
+
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAutoCreateDirectoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAutoCreateDirectoryTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message