Return-Path: X-Original-To: apmail-brooklyn-commits-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9106011F32 for ; Thu, 26 Jun 2014 11:42:36 +0000 (UTC) Received: (qmail 33613 invoked by uid 500); 26 Jun 2014 11:42:36 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 33592 invoked by uid 500); 26 Jun 2014 11:42:36 -0000 Mailing-List: contact commits-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list commits@brooklyn.incubator.apache.org Received: (qmail 33553 invoked by uid 99); 26 Jun 2014 11:42:36 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Jun 2014 11:42:36 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 26 Jun 2014 11:42:34 +0000 Received: (qmail 31540 invoked by uid 99); 26 Jun 2014 11:42:08 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Jun 2014 11:42:08 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id B8414834C78; Thu, 26 Jun 2014 11:42:07 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: heneveld@apache.org To: commits@brooklyn.incubator.apache.org Date: Thu, 26 Jun 2014 11:42:16 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [10/21] git commit: Add comments explaining the reason for the code changes. X-Virus-Checked: Checked by ClamAV on apache.org Add comments explaining the reason for the code changes. Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/0232e220 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/0232e220 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/0232e220 Branch: refs/heads/master Commit: 0232e2201b779dd1191a474a980e8df284a2ac79 Parents: f67d7c4 Author: Svetoslav Neykov Authored: Mon Jun 23 12:29:25 2014 +0300 Committer: Svetoslav Neykov Committed: Wed Jun 25 18:28:54 2014 +0300 ---------------------------------------------------------------------- core/src/main/java/brooklyn/util/ResourceUtils.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0232e220/core/src/main/java/brooklyn/util/ResourceUtils.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/brooklyn/util/ResourceUtils.java b/core/src/main/java/brooklyn/util/ResourceUtils.java index 412b781..347e0a2 100644 --- a/core/src/main/java/brooklyn/util/ResourceUtils.java +++ b/core/src/main/java/brooklyn/util/ResourceUtils.java @@ -378,21 +378,31 @@ public class ResourceUtils { Class cc = contextObject instanceof Class ? (Class)contextObject : contextObject.getClass(); return getClassLoaderDir(cc.getCanonicalName().replace('.', '/')+".class"); } + public String getClassLoaderDir(String resourceInThatDir) { resourceInThatDir = Strings.removeFromStart(resourceInThatDir, "/"); URL url = getLoader().getResource(resourceInThatDir); if (url==null) throw new NoSuchElementException("Resource ("+resourceInThatDir+") not found"); + //Switching from manual parsing of jar: and file: URLs to java provided functionality. + //The old code was breaking on any Windows path and instead of fixing it, using + //the provided Java APIs seemed like the better option since they are already tested + //on multiple platforms. boolean isJar = "jar".equals(url.getProtocol()); if(isJar) { try { - //let java handle the parsing of jar url, no network connection is established. + //let java handle the parsing of jar URL, no network connection is established. + //Strips the jar protocol: + // jar:file:/! + // becomes + // file:/ JarURLConnection connection = (JarURLConnection) url.openConnection(); url = connection.getJarFileURL(); } catch (IOException e) { throw new IllegalStateException(e); } } else { + //Remove the trailing resouceInThatDir path from the URL, thus getting the parent folder. String path = url.toString(); int i = path.indexOf(resourceInThatDir); if (i==-1) throw new IllegalStateException("Resource path ("+resourceInThatDir+") not in url substring ("+url+")"); @@ -406,6 +416,7 @@ public class ResourceUtils { if (!"file".equals(url.getProtocol())) throw new IllegalStateException("Resource ("+resourceInThatDir+") not on file system (at "+url+")"); + //convert from file: URL to File File file; try { file = new File(url.toURI());