camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r737493 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/file/ main/java/org/apache/camel/component/file/strategy/ main/java/org/apache/camel/util/ main/resources/META-INF/services/org/apache/camel/component/ test/java...
Date Sun, 25 Jan 2009 10:00:44 GMT
Author: davsclaus
Date: Sun Jan 25 10:00:43 2009
New Revision: 737493

URL: http://svn.apache.org/viewvc?rev=737493&view=rev
Log:
CAMEL-1241: More improvements to VFS (work in progress).

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileDefaultSorter.java
  (contents, props changed)
      - copied, changed from r737485, camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericDefaultFileSorter.java
Removed:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericDefaultFileSorter.java
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/GenericFile.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileComponent.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileOperations.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java
    camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/newfile
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBatchTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentRefTest.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=737493&r1=737492&r2=737493&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
Sun Jan 25 10:00:43 2009
@@ -251,8 +251,7 @@
                 LOG.trace("File did not match. Will skip this file: " + file);
             }
             return false;
-        } else if (endpoint.isIdempotent() && endpoint.getIdempotentRepository().contains(file.getPath()))
{
-            // use file.getPath as key for the idempotent repository to support files with
same name but in different folders
+        } else if (endpoint.isIdempotent() && endpoint.getIdempotentRepository().contains(file.getName()))
{
             if (LOG.isTraceEnabled()) {
                 LOG.trace("FileConsumer is idempotent and the file has been consumed before.
Will skip this file: " + file);
             }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java?rev=737493&r1=737492&r2=737493&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
Sun Jan 25 10:00:43 2009
@@ -68,12 +68,30 @@
      */
     public void changeFileName(String newName) {
         setAbsoluteFileName(getParent() + "/" + newName);
+
+        // relative name is a bit more complex to set as newName itself can contain
+        // folders we need to consider as well
+        String baseNewName = null;
+        if (newName.indexOf("/") != -1) {
+            baseNewName = newName.substring(0, newName.lastIndexOf("/"));
+            newName = newName.substring(newName.lastIndexOf("/") + 1);
+        }
+
         if (relativeFileName.indexOf("/") != -1) {
             String relative = relativeFileName.substring(0, relativeFileName.lastIndexOf("/"));
-            setRelativeFileName(relative + newName);
+            if (baseNewName != null) {
+                setRelativeFileName(relative + "/" + baseNewName + "/" + newName);
+            } else {
+                setRelativeFileName(relative + "/" + newName);
+            }
         } else {
-            setRelativeFileName(newName);
+            if (baseNewName != null) {
+                setRelativeFileName(baseNewName + "/" + newName);
+            } else {
+                setRelativeFileName(newName);
+            }
         }
+
         setFileName(newName);
     }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileComponent.java?rev=737493&r1=737492&r2=737493&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileComponent.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileComponent.java
Sun Jan 25 10:00:43 2009
@@ -96,7 +96,7 @@
         ObjectHelper.notEmpty(reminder, "sortBy expression", this);
 
         // recursive add nested sorters
-        return GenericDefaultFileSorter.sortByFileLanguage(reminder, reverse, ignoreCase,
createSortByComparator(it));
+        return GenericFileDefaultSorter.sortByFileLanguage(reminder, reverse, ignoreCase,
createSortByComparator(it));
     }
 
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java?rev=737493&r1=737492&r2=737493&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
Sun Jan 25 10:00:43 2009
@@ -215,9 +215,8 @@
                                          GenericFileExchange exchange, GenericFile<T>
file, boolean failureHandled) {
         if (endpoint.isIdempotent()) {
             // only add to idempotent repository if we could process the file
-            // use file.getAbsoluteFileName as key for the idempotent repository
-            // to support files with same name but in different folders
-            endpoint.getIdempotentRepository().add(file.getAbsoluteFileName());
+            // only use the filename as the key as the file could be moved into a done folder
+            endpoint.getIdempotentRepository().add(file.getFileName());
         }
 
         try {
@@ -262,9 +261,8 @@
                 log.trace("Remote file did not match. Will skip this remote file: " + file);
             }
             return false;
-        } else if (endpoint.isIdempotent() && endpoint.getIdempotentRepository().contains(file.getAbsoluteFileName()))
{
-            // use file.getAbsoluteFileName as key for the idempotent repository
-            // to support files with same name but in different folders
+        } else if (endpoint.isIdempotent() && endpoint.getIdempotentRepository().contains(file.getFileName()))
{
+            // only use the filename as the key as the file could be moved into a done folder
             if (log.isTraceEnabled()) {
                 log.trace("RemoteFileConsumer is idempotent and the file has been consumed
before. Will skip this remote file: " + file);
             }

Copied: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileDefaultSorter.java
(from r737485, camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericDefaultFileSorter.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileDefaultSorter.java?p2=camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileDefaultSorter.java&p1=camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericDefaultFileSorter.java&r1=737485&r2=737493&rev=737493&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericDefaultFileSorter.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileDefaultSorter.java
Sun Jan 25 10:00:43 2009
@@ -23,11 +23,11 @@
 import org.apache.camel.util.ObjectHelper;
 
 /**
- * Default remote file sorter.
+ * Default file sorter.
  */
-public final class GenericDefaultFileSorter {
+public final class GenericFileDefaultSorter {
 
-    private GenericDefaultFileSorter() {
+    private GenericFileDefaultSorter() {
     }
 
     /**

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

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

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java?rev=737493&r1=737492&r2=737493&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
Sun Jan 25 10:00:43 2009
@@ -27,7 +27,6 @@
 import org.apache.camel.Expression;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
-import org.apache.camel.component.file.strategy.GenericFileProcessStrategyFactory;
 import org.apache.camel.impl.ScheduledPollEndpoint;
 import org.apache.camel.language.simple.FileLanguage;
 import org.apache.camel.spi.IdempotentRepository;
@@ -335,7 +334,7 @@
     }
 
     public void setSortBy(String expression, boolean reverse) {
-        setSortBy(GenericDefaultFileSorter.sortByFileLanguage(expression, reverse));
+        setSortBy(GenericFileDefaultSorter.sortByFileLanguage(expression, reverse));
     }
 
     public String getTempPrefix() {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java?rev=737493&r1=737492&r2=737493&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
Sun Jan 25 10:00:43 2009
@@ -105,7 +105,7 @@
         if (lastPathIndex != -1) {
             String directory = fileName.substring(0, lastPathIndex);
             if (!operations.buildDirectory(directory)) {
-                log.warn("Couldn't build directory: " + directory + " (could be because of
denied permissions)");
+                log.warn("Can not build directory: " + directory + " (could be because of
denied permissions)");
             }
         }
         boolean success = operations.storeFile(fileName, exchange);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileOperations.java?rev=737493&r1=737492&r2=737493&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileOperations.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileOperations.java
Sun Jan 25 10:00:43 2009
@@ -53,7 +53,8 @@
 
     public boolean renameFile(String from, String to) throws GenericFileOperationFailedException
{
         File file = new File(from);
-        return file.exists() && file.renameTo(new File(to));
+        File target = new File(to);
+        return file.renameTo(target);
     }
 
     public boolean buildDirectory(String directory) throws GenericFileOperationFailedException
{
@@ -61,7 +62,7 @@
         if (dir.exists()) {
             return true;
         }
-        return endpoint.isAutoCreate() && dir.mkdirs();
+        return dir.mkdirs();
     }
 
     public String getCurrentDirectory(File file) throws GenericFileOperationFailedException
{

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java?rev=737493&r1=737492&r2=737493&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
Sun Jan 25 10:00:43 2009
@@ -36,6 +36,8 @@
 public class FileLockExclusiveReadLockStrategy implements ExclusiveReadLockStrategy {
     private static final transient Log LOG = LogFactory.getLog(FileLockExclusiveReadLockStrategy.class);
     private long timeout;
+
+    // TODO: We shall keep this with the GenericFileXX to support FileLock for java.io.File
     
     public boolean acquireExclusiveReadLock(File file) {
         if (LOG.isTraceEnabled()) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java?rev=737493&r1=737492&r2=737493&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
Sun Jan 25 10:00:43 2009
@@ -68,24 +68,17 @@
 
     private static GenericFile renameFile(GenericFileOperations operations, GenericFile from,
GenericFile to) throws IOException {
         // deleting any existing files before renaming
-        boolean deleted = false;
         try {
-            deleted = operations.deleteFile(to.getAbsoluteFileName());
+            operations.deleteFile(to.getAbsoluteFileName());
         } catch (GenericFileOperationFailedException e) {
             // ignore the file does not exists
         }
 
-        if (!deleted) {
-            // if we could not delete any existing file then maybe the folder is missing
-            // build folder if needed
-            String name = to.getAbsoluteFileName();
-            int lastPathIndex = name.lastIndexOf('/');
-            if (lastPathIndex != -1) {
-                String directory = name.substring(0, lastPathIndex);
-                if (!operations.buildDirectory(directory)) {
-                    LOG.warn("Cannot build directory: " + directory + " (maybe because of
denied permissions)");
-                }
-            }
+        // make parent folder if missing
+        String parent = to.getParent();
+        boolean mkdir = operations.buildDirectory(parent);
+        if (!mkdir) {
+            throw new GenericFileOperationFailedException("Cannot create directory: " + parent
+ " (could be because of denied permissions)");
         }
 
         if (LOG.isDebugEnabled()) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java?rev=737493&r1=737492&r2=737493&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java Sun Jan
25 10:00:43 2009
@@ -115,8 +115,7 @@
         return findClasses(key, null);
     }
 
-    public List<Class> findClasses(String key, String propertyPrefix) throws ClassNotFoundException,
-        IOException {
+    public List<Class> findClasses(String key, String propertyPrefix) throws ClassNotFoundException,
IOException {
         // TODO change to support finding multiple classes on the classpath!
         Class type = findClass(key, propertyPrefix);
         return Collections.singletonList(type);
@@ -126,15 +125,17 @@
         return path;
     }
 
-    private Class newInstance(Properties properties, String propertyPrefix) throws ClassNotFoundException,
-        IOException {
-
+    private Class newInstance(Properties properties, String propertyPrefix) throws ClassNotFoundException,
IOException {
         String className = properties.getProperty(propertyPrefix + "class");
         if (className == null) {
             throw new IOException("Expected property is missing: " + propertyPrefix + "class");
         }
 
-        return ObjectHelper.loadClass(className);
+        Class clazz = ObjectHelper.loadClass(className);
+        if (clazz == null) {
+            throw new ClassNotFoundException(className);
+        }
+        return clazz;
     }
 
     private Properties doFindFactoryProperties(String key) throws IOException {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java?rev=737493&r1=737492&r2=737493&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java Sun Jan
25 10:00:43 2009
@@ -61,12 +61,12 @@
             hostName = "localhost";
             stub = "-1-" + System.currentTimeMillis() + "-";
         }
-        UNIQUE_STUB = stub;
+        UNIQUE_STUB = generateSanitizedId(stub);
     }
 
     public UuidGenerator(String prefix) {
         synchronized (UNIQUE_STUB) {
-            this.seed = prefix + UNIQUE_STUB + (instanceCount++) + "-";
+            this.seed = generateSanitizedId(prefix + UNIQUE_STUB + (instanceCount++) + "-");
         }
     }
 
@@ -110,6 +110,8 @@
         id = id.replace(':', '-');
         id = id.replace('_', '-');
         id = id.replace('.', '-');
+        id = id.replace('/', '-');
+        id = id.replace('\\', '-');
         return id;
     }
 

Modified: camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/newfile
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/newfile?rev=737493&r1=737492&r2=737493&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/newfile
(original)
+++ camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/newfile
Sun Jan 25 10:00:43 2009
@@ -16,4 +16,4 @@
 #
 
 class=org.apache.camel.component.file.NewFileComponent
-strategy.factory.class=org.apache.camel.component.file.strategy.NewFileProcessStrategyFactory
\ No newline at end of file
+strategy.factory.class=org.apache.camel.component.file.strategy.GenericFileProcessStrategyFactory
\ No newline at end of file

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBatchTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBatchTest.java?rev=737493&r1=737492&r2=737493&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBatchTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBatchTest.java
Sun Jan 25 10:00:43 2009
@@ -28,7 +28,7 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        deleteDirectory("target/idempotent");
+        deleteDirectory("target/file-batch");
         template.sendBodyAndHeader("file://target/file-batch/", "Hello World", FileComponent.HEADER_FILE_NAME,
"hello.txt");
         template.sendBodyAndHeader("file://target/file-batch/", "Bye World", FileComponent.HEADER_FILE_NAME,
"bye.txt");
     }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentRefTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentRefTest.java?rev=737493&r1=737492&r2=737493&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentRefTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentRefTest.java
Sun Jan 25 10:00:43 2009
@@ -92,7 +92,7 @@
         }
 
         public boolean contains(String key) {
-            return false;
+            return invoked;
         }
     }
     



Mime
View raw message