summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/branches/sca-java-2.0-M5/modules/contribution/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/branches/sca-java-2.0-M5/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java69
1 files changed, 45 insertions, 24 deletions
diff --git a/sca-java-2.x/branches/sca-java-2.0-M5/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java b/sca-java-2.x/branches/sca-java-2.0-M5/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java
index 4a1a222da8..6358142244 100644
--- a/sca-java-2.x/branches/sca-java-2.0-M5/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java
+++ b/sca-java-2.x/branches/sca-java-2.0-M5/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java
@@ -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.contribution.scanner.ContributionScanner;
* @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 DirectoryContributionScanner implements ContributionScanner {
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 DirectoryContributionScanner implements ContributionScanner {
return artifacts;
}
-
+
/**
* Scan the contribution to retrieve all artifact uris
- *
+ *
* @param contribution
* @return
* @throws ContributionReadException
@@ -88,10 +94,10 @@ public class DirectoryContributionScanner implements ContributionScanner {
} catch (IOException e) {
throw new ContributionReadException(e);
}
-
+
return artifacts;
}
-
+
/**
* Recursively traverse a root directory
*
@@ -100,28 +106,43 @@ public class DirectoryContributionScanner implements ContributionScanner {
* @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 {
+
+ //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);
+ 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 DirectoryContributionScanner implements ContributionScanner {
}
return file;
}
-
+
}