AntennaUtils { public static Path getJarPath(URL url) throws URISyntaxException, MalformedURLException { if("jar".equals(url.getProtocol())) { String file = url.getFile(); if(file.contains("!")){ file = file.split("!",2)[0]; } url = new URL(file); } Path jarPath = Paths.get(url.toURI()); return getJarPath(jarPath); } private  AntennaUtils(); static Iterator<Path> getJarPathIteratorFromPath(Path jarPath); static Path getJarPath(URL url); static Path getJarPath(Path jarPath); static String replaceDotInJarExtension(String path); static Path computeInnerReplacementJarPath(Path jarPath);  }
@Test public void getJarPathTestStripsPrefix() throws Exception { String fileBasename = "AntennaUtilsTest_testfile.arc"; final URL url = this.getClass().getClassLoader().getResource(fileBasename); final Path jarPath = AntennaUtils.getJarPath(url); assertThat(jarPath.toString()).doesNotStartWith("file:"); assertThat(jarPath.toString()).doesNotStartWith("jar:"); assertThat(jarPath).hasFileName(fileBasename); assertThat(jarPath).exists(); }
@Test public void getJarPathTestDoesWorkOnWinBackwardSlashes() throws Exception { onlyForWindows(); final URL url = new URL("file: final Path jarPath = AntennaUtils.getJarPath(url); assertThat(jarPath).hasToString("C:\\Documents and Settings\\antenna\\someFile.jar"); }
@Test public void getJarPathTestDoesWorkOnWinForwardSlashes() throws Exception { onlyForWindows(); final URL url = new URL("file: final Path jarPath = AntennaUtils.getJarPath(url); assertThat(jarPath).hasToString("C:\\Documents and Settings\\antenna\\someFile.jar"); }
@Test public void getJarPathTestWithoutChilds() { Path filePath = Paths.get("/some/path/to/file.jar").toAbsolutePath(); final Path jarPath = AntennaUtils.getJarPath(filePath); assertThat(jarPath).hasToString(toAbsolutePathname("/some/path/to/file.jar")); }
@Test(expected = ExecutionException.class) public void getJarRelativePathTestExpectedFail() { Path filePath = Paths.get("some/path/to/file.jar"); AntennaUtils.getJarPath(filePath); }
@Test public void getJarPathTestWithJarFile() { Path filePath = Paths.get("/some/path/to/file.jar/child.war/subChild.jar").toAbsolutePath(); final Path jarPath = AntennaUtils.getJarPath(filePath); assertThat(jarPath).hasToString(toAbsolutePathname("/some/path/to/file.jar")); }
@Test public void getJarPathTestWithFile() { Path filePath = Paths.get("/some/path/to/file.jar/child.war/subChild.jar").toAbsolutePath(); final Path jarPath = AntennaUtils.getJarPath(filePath); assertThat(jarPath).hasToString(toAbsolutePathname("/some/path/to/file.jar")); }
@Test public void computeJarPathFromURLWithExclemationMarkOnWin() throws Exception { onlyForWindows(); final URL url = new URL("jar:file:/C:/some/path/to/file.jar!/some/inner/thing.class"); final Path jarPath = AntennaUtils.getJarPath(url); assertThat(jarPath).hasToString("C:\\some\\path\\to\\file.jar"); }
@Test public void computeJarPathFromURLWithExclamationMark() throws Exception { onlyForNonWindows(); final URL url = new URL("jar:file: final Path jarPath = AntennaUtils.getJarPath(url); assertThat(jarPath).hasToString("/some/path/to/file.jar"); }