@Test public void testDoesRestApiZipFileContainJaxJars() throws IOException { when(sBuildServer.getServerRootPath()).thenReturn("src/test/resources/empty_teamcity_home/webapps/ROOT"); WebHookTeamCityRestApiZipPluginFixer fixer = new WebHookTeamCityRestApiZipPluginFixer(sBuildServer); List<Path> filesFound = fixer.findRestApiZipFileInTomcatDir(new File("src/test/resources/catalina_home"), "rest-api.zip"); assertEquals(1, filesFound.size()); String restApiUnpackedDir = filesFound.get(0).toFile().getParent() + WebHookTeamCityRestApiZipPluginFixer.UNPACKED_LOCATION; JarReport jarReport = new JarReport(filesFound.get(0), restApiUnpackedDir, WebHookTeamCityRestApiZipPluginFixer.getFilenames()); boolean fileContainsJars = fixer.doesRestApiZipFileContainJaxJars(filesFound.get(0).toFile(), WebHookTeamCityRestApiZipPluginFixer.getFilenames(), jarReport); assertTrue(fileContainsJars); }
protected boolean doesRestApiZipFileContainJaxJars(File restApiZip, String[] filenames, JarReport jarReport) throws IOException { Map<String, String> zipProperties = new HashMap<>(); zipProperties.put("create", "false"); URI zipDisk = null; try { Path path = Paths.get(restApiZip.getAbsolutePath()); zipDisk = new URI("jar",path.toUri().toString(), null); } catch(URISyntaxException e) { Loggers.SERVER.warn("WebHookTeamCityRestApiZipPluginFixer :: Could not convert to JAR URI.", e); } boolean fileFoundInZip = false; try (FileSystem zipfs = FileSystems.newFileSystem(zipDisk, zipProperties)) { for (String filename : filenames) { Path pathInZipfile = zipfs.getPath(filename); if (Files.exists(pathInZipfile)) { fileFoundInZip = true; jarReport.setJarFoundInZipFile(filename, true); } else { jarReport.setJarFoundInZipFile(filename, false); } } } catch(IllegalArgumentException e) { Loggers.SERVER.error("WebHookTeamCityRestApiZipPluginFixer :: Could not create filesystem: " + e.getMessage()); Loggers.SERVER.debug(e); } return fileFoundInZip; }
WebHookTeamCityRestApiZipPluginFixer { protected boolean doesRestApiZipFileContainJaxJars(File restApiZip, String[] filenames, JarReport jarReport) throws IOException { Map<String, String> zipProperties = new HashMap<>(); zipProperties.put("create", "false"); URI zipDisk = null; try { Path path = Paths.get(restApiZip.getAbsolutePath()); zipDisk = new URI("jar",path.toUri().toString(), null); } catch(URISyntaxException e) { Loggers.SERVER.warn("WebHookTeamCityRestApiZipPluginFixer :: Could not convert to JAR URI.", e); } boolean fileFoundInZip = false; try (FileSystem zipfs = FileSystems.newFileSystem(zipDisk, zipProperties)) { for (String filename : filenames) { Path pathInZipfile = zipfs.getPath(filename); if (Files.exists(pathInZipfile)) { fileFoundInZip = true; jarReport.setJarFoundInZipFile(filename, true); } else { jarReport.setJarFoundInZipFile(filename, false); } } } catch(IllegalArgumentException e) { Loggers.SERVER.error("WebHookTeamCityRestApiZipPluginFixer :: Could not create filesystem: " + e.getMessage()); Loggers.SERVER.debug(e); } return fileFoundInZip; } }
WebHookTeamCityRestApiZipPluginFixer { protected boolean doesRestApiZipFileContainJaxJars(File restApiZip, String[] filenames, JarReport jarReport) throws IOException { Map<String, String> zipProperties = new HashMap<>(); zipProperties.put("create", "false"); URI zipDisk = null; try { Path path = Paths.get(restApiZip.getAbsolutePath()); zipDisk = new URI("jar",path.toUri().toString(), null); } catch(URISyntaxException e) { Loggers.SERVER.warn("WebHookTeamCityRestApiZipPluginFixer :: Could not convert to JAR URI.", e); } boolean fileFoundInZip = false; try (FileSystem zipfs = FileSystems.newFileSystem(zipDisk, zipProperties)) { for (String filename : filenames) { Path pathInZipfile = zipfs.getPath(filename); if (Files.exists(pathInZipfile)) { fileFoundInZip = true; jarReport.setJarFoundInZipFile(filename, true); } else { jarReport.setJarFoundInZipFile(filename, false); } } } catch(IllegalArgumentException e) { Loggers.SERVER.error("WebHookTeamCityRestApiZipPluginFixer :: Could not create filesystem: " + e.getMessage()); Loggers.SERVER.debug(e); } return fileFoundInZip; } WebHookTeamCityRestApiZipPluginFixer(SBuildServer sBuildServer); }
WebHookTeamCityRestApiZipPluginFixer { protected boolean doesRestApiZipFileContainJaxJars(File restApiZip, String[] filenames, JarReport jarReport) throws IOException { Map<String, String> zipProperties = new HashMap<>(); zipProperties.put("create", "false"); URI zipDisk = null; try { Path path = Paths.get(restApiZip.getAbsolutePath()); zipDisk = new URI("jar",path.toUri().toString(), null); } catch(URISyntaxException e) { Loggers.SERVER.warn("WebHookTeamCityRestApiZipPluginFixer :: Could not convert to JAR URI.", e); } boolean fileFoundInZip = false; try (FileSystem zipfs = FileSystems.newFileSystem(zipDisk, zipProperties)) { for (String filename : filenames) { Path pathInZipfile = zipfs.getPath(filename); if (Files.exists(pathInZipfile)) { fileFoundInZip = true; jarReport.setJarFoundInZipFile(filename, true); } else { jarReport.setJarFoundInZipFile(filename, false); } } } catch(IllegalArgumentException e) { Loggers.SERVER.error("WebHookTeamCityRestApiZipPluginFixer :: Could not create filesystem: " + e.getMessage()); Loggers.SERVER.debug(e); } return fileFoundInZip; } WebHookTeamCityRestApiZipPluginFixer(SBuildServer sBuildServer); List<Path> getFoundApiZipFilesContainingJaxbJars(); boolean foundApiZipFilesContainingJaxbJars(); synchronized void findRestApiZipPlugins(); synchronized JarReport fixRestApiZipPlugin(Path p); }
WebHookTeamCityRestApiZipPluginFixer { protected boolean doesRestApiZipFileContainJaxJars(File restApiZip, String[] filenames, JarReport jarReport) throws IOException { Map<String, String> zipProperties = new HashMap<>(); zipProperties.put("create", "false"); URI zipDisk = null; try { Path path = Paths.get(restApiZip.getAbsolutePath()); zipDisk = new URI("jar",path.toUri().toString(), null); } catch(URISyntaxException e) { Loggers.SERVER.warn("WebHookTeamCityRestApiZipPluginFixer :: Could not convert to JAR URI.", e); } boolean fileFoundInZip = false; try (FileSystem zipfs = FileSystems.newFileSystem(zipDisk, zipProperties)) { for (String filename : filenames) { Path pathInZipfile = zipfs.getPath(filename); if (Files.exists(pathInZipfile)) { fileFoundInZip = true; jarReport.setJarFoundInZipFile(filename, true); } else { jarReport.setJarFoundInZipFile(filename, false); } } } catch(IllegalArgumentException e) { Loggers.SERVER.error("WebHookTeamCityRestApiZipPluginFixer :: Could not create filesystem: " + e.getMessage()); Loggers.SERVER.debug(e); } return fileFoundInZip; } WebHookTeamCityRestApiZipPluginFixer(SBuildServer sBuildServer); List<Path> getFoundApiZipFilesContainingJaxbJars(); boolean foundApiZipFilesContainingJaxbJars(); synchronized void findRestApiZipPlugins(); synchronized JarReport fixRestApiZipPlugin(Path p); static final String UNPACKED_LOCATION; }