You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/02/01 09:27:17 UTC

svn commit: r739711 - in /camel/trunk/camel-core/src/main/java/org/apache/camel/component/file: ./ strategy/

Author: ningjiang
Date: Sun Feb  1 08:27:16 2009
New Revision: 739711

URL: http://svn.apache.org/viewvc?rev=739711&view=rev
Log:
CAMEL-1306 fixed a bunch of test failures in windows

Modified:
    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/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/GenericFileRenameProcessStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewFileLockExclusiveReadLockStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewMarkerFileExclusiveReadLockStrategy.java

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=739711&r1=739710&r2=739711&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 Feb  1 08:27:16 2009
@@ -56,8 +56,8 @@
         }
         result.setAbsoluteFileName(source.getAbsoluteFileName());
         result.setCanonicalFileName(source.getCanonicalFileName());
-        result.setRelativeFileName(source.getRelativeFileName());
-        result.setFileName(source.getFileName());
+        result.setRelativeFileName(source.getRelativeFileName());              
+        result.setFileName(source.getFileName());        
         result.setFileLength(source.getFileLength());
         result.setLastModified(source.getLastModified());
         result.setFile(source.getFile());
@@ -73,8 +73,11 @@
      * @param newName the new name
      */
     public void changeFileName(String newName) {
+        if (System.getProperty("os.name").startsWith("Windows") && newName.indexOf("/") >= 0) {
+            newName = newName.replaceAll("/", "\\\\");
+        }
         setAbsoluteFileName(getParent() + File.separator + 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;
@@ -149,7 +152,7 @@
         getBinding().setBody(this, os);
     }
 
-    public String getParent() {
+    public String getParent() {       
         if (getAbsoluteFileName().lastIndexOf(File.separator) > 0) {
             return getAbsoluteFileName().substring(0, getAbsoluteFileName().lastIndexOf(File.separator));
         } else {
@@ -172,7 +175,12 @@
      * @param absoluteFileName the absoluteFileName to set
      */
     public void setAbsoluteFileName(String absoluteFileName) {
-        this.absoluteFileName = absoluteFileName;
+        // should replace the "/" with "\\" in windows
+        if (absoluteFileName != null && System.getProperty("os.name").startsWith("Windows") && absoluteFileName.indexOf("/") >= 0) {
+            this.absoluteFileName = absoluteFileName.replaceAll("/", "\\\\");
+        } else {
+            this.absoluteFileName = absoluteFileName;
+        }
     }
 
     /**

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=739711&r1=739710&r2=739711&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 Feb  1 08:27:16 2009
@@ -144,7 +144,7 @@
         String answer;
 
         String name = exchange.getIn().getHeader(FileComponent.HEADER_FILE_NAME, String.class);
-
+                
         // expression support
         Expression expression = endpoint.getExpression();
         if (name != null) {
@@ -164,10 +164,15 @@
             Object result = expression.evaluate(exchange);
             name = exchange.getContext().getTypeConverter().convertTo(String.class, result);
         }
+        
+        // replace the "/" with the "\\" for Windows
+        if (name != null && System.getProperty("os.name").startsWith("Windows") && name.indexOf("/") >= 0) {           
+            name = name.replaceAll("/", "\\\\");            
+        }
 
         String endpointFile = endpoint.getConfiguration().getFile();
         if (endpoint.isDirectory()) {
-            // Its a directory so we should use it as a basepath for the filename
+            // Its a directory so we should use it as a base path for the filename
             // If the path isn't empty, we need to add a trailing / if it isn't already there
             String baseDir = "";
             if (endpointFile.length() > 0) {
@@ -188,6 +193,10 @@
     }
 
     protected String createTempFileName(String fileName) {
+        if (fileName != null && System.getProperty("os.name").startsWith("Windows") && fileName.indexOf("/") >= 0) {
+            fileName = fileName.replaceAll("/", "\\\\");
+        }
+        
         int path = fileName.lastIndexOf(File.separator);
         if (path == -1) {
             // no path

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=739711&r1=739710&r2=739711&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 Feb  1 08:27:16 2009
@@ -50,7 +50,7 @@
         this.endpoint = (NewFileEndpoint) endpoint;
     }
 
-    public boolean deleteFile(String name) throws GenericFileOperationFailedException {
+    public boolean deleteFile(String name) throws GenericFileOperationFailedException {        
         File file = new File(name);
         return file.exists() && file.delete();
     }
@@ -62,7 +62,7 @@
     }
 
     public boolean buildDirectory(String directory, boolean absolute) throws GenericFileOperationFailedException {
-        ObjectHelper.notNull(endpoint, "endpoint");
+        ObjectHelper.notNull(endpoint, "endpoint");       
 
         // always create endpoint defined directory
         if (endpoint.isAutoCreate() && endpoint.isDirectory() && !endpoint.getFile().exists()) {
@@ -79,7 +79,7 @@
                 directory = directory.substring(endpoint.getFile().getPath().length());
             }
             path = new File(endpoint.getFile(), directory);
-        }
+        }       
 
         if (path.isDirectory() && path.exists()) {
             // the directory already exists
@@ -113,10 +113,10 @@
         return true;
     }
 
-    public boolean storeFile(String name, GenericFileExchange<File> exchange) throws GenericFileOperationFailedException {
+    public boolean storeFile(String fileName, GenericFileExchange<File> exchange) throws GenericFileOperationFailedException {
         ObjectHelper.notNull(endpoint, "endpoint");
-
-        File file = new File(name);
+        
+        File file = new File(fileName);
         try {
             boolean fileSource = exchange.getIn().getBody() instanceof File;
             if (fileSource) {
@@ -126,7 +126,7 @@
                 InputStream in = ExchangeHelper.getMandatoryInBody(exchange, InputStream.class);
                 writeFileByStream(in, file);
             }
-        } catch (IOException e) {
+        } catch (IOException e) {            
             throw new GenericFileOperationFailedException("Can not store file: " + file, e);
         } catch (InvalidPayloadException e) {
             throw new GenericFileOperationFailedException("Can not store file: " + file, e);

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=739711&r1=739710&r2=739711&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 Feb  1 08:27:16 2009
@@ -82,9 +82,10 @@
         } catch (GenericFileOperationFailedException e) {
             // ignore the file does not exists
         }
-
+        
         // make parent folder if missing
         boolean mkdir = operations.buildDirectory(to.getParent(), true);
+        
         if (!mkdir) {
             throw new GenericFileOperationFailedException("Can not create directory: " + to.getParent() + " (could be because of denied permissions)");
         }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewFileLockExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewFileLockExclusiveReadLockStrategy.java?rev=739711&r1=739710&r2=739711&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewFileLockExclusiveReadLockStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewFileLockExclusiveReadLockStrategy.java Sun Feb  1 08:27:16 2009
@@ -111,8 +111,14 @@
         try {
             lock.release();
         } finally {
-            // must close channel
+            // must close channel first
             ObjectHelper.close(channel, "while acquiring exclusive read lock for file: " + lockFileName, LOG);
+            // need to delete the lock file
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Deleting lock file: " + lockFileName);
+            }            
+            File lockfile = new File(lockFileName);
+            lockfile.delete();
         }
     }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewMarkerFileExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewMarkerFileExclusiveReadLockStrategy.java?rev=739711&r1=739710&r2=739711&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewMarkerFileExclusiveReadLockStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewMarkerFileExclusiveReadLockStrategy.java Sun Feb  1 08:27:16 2009
@@ -73,14 +73,14 @@
         try {
             lock.release();
         } finally {
+            // must close channel
+            ObjectHelper.close(channel, "Closing channel", LOG);
+            
             if (LOG.isTraceEnabled()) {
                 LOG.trace("Deleting lock file: " + lockFileName);
             }
             File lockfile = new File(lockFileName);
-            lockfile.delete();
-
-            // must close channel
-            ObjectHelper.close(channel, "Closing channel", LOG);
+            lockfile.delete();            
         }
     }