summaryrefslogtreecommitdiffstats
path: root/java/sca
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-02 06:23:11 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-02 06:23:11 +0000
commitde0771549ee6ccc40ce167205d2cb1e79fb0c996 (patch)
tree12219ecdb9d8e94af8bc8603d625a98186b39d03 /java/sca
parent677379d4d85b4ab6da457956680a7957528b0587 (diff)
Fix the algorithm to create File from URL
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@790470 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca')
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java30
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java7
2 files changed, 26 insertions, 11 deletions
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java
index 046053af54..4e075fea24 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java
@@ -102,6 +102,20 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso
return Contribution.class;
}
+ private File toFile(URL url) {
+ if("file".equalsIgnoreCase(url.getProtocol())) {
+ try {
+ return new File(url.toURI());
+ } catch(URISyntaxException e) {
+ return new File(url.getPath());
+ } catch(IllegalArgumentException e) {
+ // Hack for file:./a.txt or file:../a/c.wsdl
+ return new File(url.getPath());
+ }
+ }
+ return null;
+ }
+
public Contribution read(URL parentURL, URI contributionURI, URL contributionURL) throws ContributionReadException {
// Create contribution model
@@ -115,16 +129,12 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso
// Create a contribution scanner
ContributionScanner scanner = scanners.getContributionScanner(contributionURL.getProtocol());
if (scanner == null) {
- //try {
- if ("file".equals(contributionURL.getProtocol()) &&
- new File(contributionURL.getFile()).isDirectory()) {
- scanner = new DirectoryContributionScanner();
- } else {
- scanner = new JarContributionScanner();
- }
- //} catch (URISyntaxException e) {
- // throw new ContributionReadException(e);
- //}
+ File file = toFile(contributionURL);
+ if (file != null && file.isDirectory()) {
+ scanner = new DirectoryContributionScanner();
+ } else {
+ scanner = new JarContributionScanner();
+ }
}
// Scan the contribution and list the artifacts contained in it
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java
index 95a4ed69e8..144302c3e4 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java
@@ -98,10 +98,15 @@ public class DirectoryContributionScanner implements ContributionScanner {
private static File directory(Contribution contribution) throws ContributionReadException {
File file;
+ URI uri = null;
try {
- file = new File(new URI(contribution.getLocation()));
+ uri = new URI(contribution.getLocation());
+ file = new File(uri);
} catch (URISyntaxException e) {
throw new ContributionReadException(e);
+ } catch(IllegalArgumentException e) {
+ // Hack for file:./a.txt or file:../a/c.wsdl
+ return new File(uri.getPath());
}
if (!file.exists() || !file.isDirectory()) {
throw new ContributionReadException(contribution.getLocation());