tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lrese...@apache.org
Subject svn commit: r1003854 - /tuscany/sca-java-2.x/branches/sca-java-2.0-M5/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java
Date Sat, 02 Oct 2010 18:47:45 GMT
Author: lresende
Date: Sat Oct  2 18:47:44 2010
New Revision: 1003854

URL: http://svn.apache.org/viewvc?rev=1003854&view=rev
Log:
TUSCANY-3667 - Handled AccessControlException when processing private folders in a contribution
deployed to Google AppEngine environment


Conflicts:

	modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java

Modified:
    tuscany/sca-java-2.x/branches/sca-java-2.0-M5/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java

Modified: tuscany/sca-java-2.x/branches/sca-java-2.0-M5/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/branches/sca-java-2.0-M5/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java?rev=1003854&r1=1003853&r2=1003854&view=diff
==============================================================================
--- tuscany/sca-java-2.x/branches/sca-java-2.0-M5/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java
(original)
+++ tuscany/sca-java-2.x/branches/sca-java-2.0-M5/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java
Sat Oct  2 18:47:44 2010
@@ -24,8 +24,12 @@ import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.security.AccessControlException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import org.apache.tuscany.sca.contribution.Artifact;
 import org.apache.tuscany.sca.contribution.Contribution;
@@ -40,8 +44,10 @@ import org.apache.tuscany.sca.contributi
  * @version $Rev$ $Date$
  */
 public class DirectoryContributionScanner implements ContributionScanner {
-    private ContributionFactory contributionFactory; 
-        
+	private static final Logger logger = Logger.getLogger(DirectoryContributionScanner.class.getName());
+
+    private ContributionFactory contributionFactory;
+
     public DirectoryContributionScanner(ContributionFactory contributionFactory) {
         this.contributionFactory = contributionFactory;
     }
@@ -61,7 +67,7 @@ public class DirectoryContributionScanne
                 Artifact artifact = contributionFactory.createArtifact();
                 artifact.setURI(uri);
                 artifact.setLocation(file.toURI().toURL().toString());
-                
+
                 artifacts.add(artifact);
             } catch (MalformedURLException e) {
                 throw new ContributionReadException(e);
@@ -72,10 +78,10 @@ public class DirectoryContributionScanne
         return artifacts;
     }
 
-    
+
     /**
      * Scan the contribution to retrieve all artifact uris
-     * 
+     *
      * @param contribution
      * @return
      * @throws ContributionReadException
@@ -88,10 +94,10 @@ public class DirectoryContributionScanne
         } catch (IOException e) {
             throw new ContributionReadException(e);
         }
-        
+
         return artifacts;
     }
-    
+
     /**
      * Recursively traverse a root directory
      *
@@ -100,28 +106,43 @@ public class DirectoryContributionScanne
      * @param root
      * @throws IOException
      */
-    private static void traverse(List<String> fileList, File file, File root) throws
IOException {
-        if (file.isFile()) {
-            fileList.add(root.toURI().relativize(file.toURI()).toString());
-        } else if (file.isDirectory()) {
-            String uri = root.toURI().relativize(file.toURI()).toString();
-            if (uri.endsWith("/")) {
-                uri = uri.substring(0, uri.length() - 1);
-            }
-            fileList.add(uri);
+    private static void traverse(List<String> fileList, File file, File root, Set<File>
visited) throws IOException {
 
-            File[] files = file.listFiles();
-            for (File f: files) {
-                if (!f.getName().startsWith(".")) {
-                    traverse(fileList, f, root);
+    	//TUSCANY-3667 - Google add some private directories when you deploy your application
+    	//to GAE and trying to execute file IO operations on it's contents fails with AccessControlException
+    	try {
+            if (file.isFile()) {
+                fileList.add(root.toURI().relativize(file.toURI()).toString());
+            } else if (file.isDirectory()) {
+                File dir = file.getCanonicalFile();
+                if (!visited.contains(dir)) {
+                    // [rfeng] Add the canonical file into the visited set to avoid duplicate
navigation of directories
+                    // following the symbolic links
+                    visited.add(dir);
+                    String uri = root.toURI().relativize(file.toURI()).toString();
+                    if (uri.endsWith("/")) {
+                        uri = uri.substring(0, uri.length() - 1);
+                    }
+                    fileList.add(uri);
+
+                    File[] files = file.listFiles();
+                    for (File f : files) {
+                        if (!f.getName().startsWith(".")) {
+                            traverse(fileList, f, root, visited);
+                        }
+                    }
                 }
             }
-        }
+    	} catch (AccessControlException e) {
+    		//TUSCANY-3667 - Log the AccessControlException error and continue without processing
the file/directory
+    		logger.log(Level.SEVERE, "Error traversing file:" + file.getPath());
+    	}
+
     }
-        
+
     /**
      * Get the contribution location as a file
-     * 
+     *
      * @param contribution
      * @return
      * @throws ContributionReadException
@@ -143,6 +164,6 @@ public class DirectoryContributionScanne
         }
         return file;
     }
-    
+
 
 }



Mime
View raw message