diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-12 08:43:30 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-12 08:43:30 +0000 |
commit | 06c5a47c354808fe5280c0332a9975aee22c7872 (patch) | |
tree | f21ddc8e7fee767a451d0e4b50c002e4d52eb4d3 | |
parent | d486aafd43b3d7de05718d8841651b8b00c81d73 (diff) |
Merge r790470 from 2.x trunk to M3 branch to fix the algorithm to create File from URL
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@793292 13f79535-47bb-0310-9956-ffa450edef68
2 files changed, 25 insertions, 9 deletions
diff --git a/branches/sca-java-2.0-M3/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java b/branches/sca-java-2.0-M3/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java index 5d8b950c45..4e075fea24 100644 --- a/branches/sca-java-2.0-M3/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java +++ b/branches/sca-java-2.0-M3/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,14 +129,11 @@ 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.toURI().getPath()).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(); } } diff --git a/branches/sca-java-2.0-M3/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java b/branches/sca-java-2.0-M3/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java index 95a4ed69e8..144302c3e4 100644 --- a/branches/sca-java-2.0-M3/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java +++ b/branches/sca-java-2.0-M3/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()); |