Bug 509502: Ensure bundle location is resolved correctly when EquinoxBundleFileResolver cannot be used.
diff --git a/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/BundleDependenciesJarScanner.java b/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/BundleDependenciesJarScanner.java
index 334cbae..c38390f 100644
--- a/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/BundleDependenciesJarScanner.java
+++ b/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/BundleDependenciesJarScanner.java
@@ -19,8 +19,6 @@
 import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Set;
 
@@ -60,8 +58,6 @@
 
     private static final String JAR_URL_PREFIX = "jar:";
 
-    private static final String REFERENCE_URL_PREFIX = "reference";
-
     private static final Logger LOGGER = LoggerFactory.getLogger(BundleDependenciesJarScanner.class);
 
     private final BundleDependencyDeterminer bundleDependencyDeterminer;
@@ -127,31 +123,17 @@
 
     private void scanJarUrlConnection(Bundle bundle, JarScannerCallback callback, boolean isWebapp) {
         URL bundleUrl;
-        String bundleLocation = bundle.getLocation();
+        URL root = bundle.getEntry("/");
         try {
-            bundleUrl = new URL(bundleLocation);
-            if (REFERENCE_URL_PREFIX.equals(bundleUrl.getProtocol())) {
-                bundleUrl = new URL(JAR_URL_PREFIX + transformBundleLocation(bundleUrl.getFile()) + JAR_URL_SUFFIX);
-            } else {
-                bundleUrl = new URL(JAR_URL_PREFIX + transformBundleLocation(bundleLocation) + JAR_URL_SUFFIX);
-            }
-        } catch (MalformedURLException | URISyntaxException e) {
-            LOGGER.warn("Failed to create jar: url for bundle location [" + bundleLocation + "].");
+            bundleUrl = new URL(JAR_URL_PREFIX + root.toExternalForm() + JAR_URL_SUFFIX);
+        } catch (MalformedURLException e) {
+            LOGGER.warn("Failed to create jar: url for bundle location [" + root + "].");
             return;
         }
 
         scanBundleUrl(bundleUrl, callback, isWebapp);
     }
 
-    private String transformBundleLocation(String location) throws URISyntaxException {
-        URI url = new URI(location);
-        if (!url.isOpaque()) {
-            return location;
-        }
-        String scheme = url.getScheme();
-        return scheme + ":/" + location.substring(scheme.length() + 1);
-    }
-
     private void scanBundleFile(File bundleFile, JarScannerCallback callback, boolean isWebapp) {
         if (bundleFile.isDirectory()) {
             try {
diff --git a/org.eclipse.gemini.web.tomcat/src/test/java/org/eclipse/gemini/web/tomcat/internal/BundleDependenciesJarScannerTests.java b/org.eclipse.gemini.web.tomcat/src/test/java/org/eclipse/gemini/web/tomcat/internal/BundleDependenciesJarScannerTests.java
index 1cb734f..bb2c071 100644
--- a/org.eclipse.gemini.web.tomcat/src/test/java/org/eclipse/gemini/web/tomcat/internal/BundleDependenciesJarScannerTests.java
+++ b/org.eclipse.gemini.web.tomcat/src/test/java/org/eclipse/gemini/web/tomcat/internal/BundleDependenciesJarScannerTests.java
@@ -27,6 +27,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.Arrays;
 import java.util.Collections;
@@ -124,23 +125,21 @@
 
     @Test
     public void scanJarUrlConnection() throws IOException {
-        expect(this.dependencyDeterminer.getDependencies(this.bundle)).andReturn(new HashSet<>(Arrays.asList(this.dependency))).times(2);
-        String bundleLocation = new File("./src/test/resources/bundle.jar").toURI().toString();
-        expect(this.dependency.getLocation()).andReturn(bundleLocation).andReturn("reference:" + bundleLocation);
-        expect(this.dependency.getSymbolicName()).andReturn("bundle").anyTimes();
+        expect(this.dependencyDeterminer.getDependencies(this.bundle)).andReturn(new HashSet<>(Arrays.asList(this.dependency)));
+        URL bundleLocation = new File("./src/test/resources/bundle.jar").toURI().toURL();
+        expect(this.dependency.getEntry("/")).andReturn(bundleLocation);
+        expect(this.dependency.getSymbolicName()).andReturn("bundle");
 
-        expect(this.bundleFileResolver.resolve(this.dependency)).andReturn(null).times(2);
+        expect(this.bundleFileResolver.resolve(this.dependency)).andReturn(null);
         this.callback.scan(isA(Jar.class), (String) isNull(), eq(true));
 
         ClassLoader classLoader = new BundleWebappClassLoader(this.bundle, this.classLoaderCustomizer);
-        expect(this.servletContext.getClassLoader()).andReturn(classLoader).times(2);
+        expect(this.servletContext.getClassLoader()).andReturn(classLoader);
 
         replay(this.dependencyDeterminer, this.bundleFileResolver, this.callback, this.dependency, this.servletContext);
 
         this.scanner.scan(null, this.servletContext, this.callback);
 
-        this.scanner.scan(null, this.servletContext, this.callback);
-
         ((URLClassLoader) classLoader).close();
 
         verify(this.dependencyDeterminer, this.bundleFileResolver, this.callback, this.dependency, this.servletContext);