@Test public void zippedArtifactExtractsArtifactsWithaDotInTheName() throws URISyntaxException, IOException { Path zipFile = zipFileDir.resolve("tf-module-my.module2-0.1.zip"); Expandable expandableArtifact = new ExpandableZippedArtifact(zipFile); expandableArtifact.expand(); Path expandedDir = zipFileDir.resolve("my.module2"); Assert.assertTrue(expandedDir.toFile().isDirectory()); Assert.assertEquals(Files.walk(expandedDir, 1) .filter(path -> !path.equals(expandedDir)) .count(), 2); Assert.assertTrue(Files.walk(expandedDir, 1) .filter(path -> !path.equals(expandedDir)) .allMatch(path -> path.getFileName().toString().startsWith("test.file") && path.getFileName().toString().endsWith(".txt"))); Assert.assertFalse(zipFile.toFile().exists()); }
@Override public Optional<Path> expand() { log.info("Expanding " + zipFile); Path artifactDir; try (IterableZipInputStream zipStream = new IterableZipInputStream(new FileInputStream(zipFile.toFile()))) { String[] zipFilenamePathSplit = zipFile.getFileName().toString().split(File.separator.equals("/") ? "\\/" : "\\\\"); String[] zipFilenameSplitByHyphen = zipFilenamePathSplit[zipFilenamePathSplit.length - 1].split("-"); String artifactName = Arrays.stream(zipFilenameSplitByHyphen) .filter(s -> !s.startsWith("SNAPSHOT")) .filter(s -> !s.equals("rc")) .filter(s -> !s.equals("tf")) .filter(s -> !s.equals("module")) .filter(s -> { if (s.contains(".")) { String[] splitByDot = s.split("\\."); return !StringUtils.isNumeric(splitByDot[0]) && !splitByDot[splitByDot.length - 1].equals("zip"); } return true; }) .reduce("", (s1, s2) -> s1 + (s1.length() > 0 ? "-" : "") + s2); Path modulesDir = zipFile.getParent(); artifactDir = Paths.get(modulesDir.toString(), artifactName); artifactDir.toFile().mkdir(); for (ZipEntry entry : zipStream) { if (entry.isDirectory()) { Paths.get(modulesDir.toString(), artifactName, entry.getName()).toFile().mkdir(); } else { extractFile(zipStream, Paths.get(modulesDir.toString(), artifactName, entry.getName())); } } } catch (IOException e) { log.error("Error expanding " + zipFile.getFileName(), e); return Optional.empty(); } if (!zipFile.toFile().delete()) { log.warn("Unable to delete " + zipFile.toAbsolutePath()); } return Optional.of(artifactDir); }
ExpandableZippedArtifact implements Expandable { @Override public Optional<Path> expand() { log.info("Expanding " + zipFile); Path artifactDir; try (IterableZipInputStream zipStream = new IterableZipInputStream(new FileInputStream(zipFile.toFile()))) { String[] zipFilenamePathSplit = zipFile.getFileName().toString().split(File.separator.equals("/") ? "\\/" : "\\\\"); String[] zipFilenameSplitByHyphen = zipFilenamePathSplit[zipFilenamePathSplit.length - 1].split("-"); String artifactName = Arrays.stream(zipFilenameSplitByHyphen) .filter(s -> !s.startsWith("SNAPSHOT")) .filter(s -> !s.equals("rc")) .filter(s -> !s.equals("tf")) .filter(s -> !s.equals("module")) .filter(s -> { if (s.contains(".")) { String[] splitByDot = s.split("\\."); return !StringUtils.isNumeric(splitByDot[0]) && !splitByDot[splitByDot.length - 1].equals("zip"); } return true; }) .reduce("", (s1, s2) -> s1 + (s1.length() > 0 ? "-" : "") + s2); Path modulesDir = zipFile.getParent(); artifactDir = Paths.get(modulesDir.toString(), artifactName); artifactDir.toFile().mkdir(); for (ZipEntry entry : zipStream) { if (entry.isDirectory()) { Paths.get(modulesDir.toString(), artifactName, entry.getName()).toFile().mkdir(); } else { extractFile(zipStream, Paths.get(modulesDir.toString(), artifactName, entry.getName())); } } } catch (IOException e) { log.error("Error expanding " + zipFile.getFileName(), e); return Optional.empty(); } if (!zipFile.toFile().delete()) { log.warn("Unable to delete " + zipFile.toAbsolutePath()); } return Optional.of(artifactDir); } }
ExpandableZippedArtifact implements Expandable { @Override public Optional<Path> expand() { log.info("Expanding " + zipFile); Path artifactDir; try (IterableZipInputStream zipStream = new IterableZipInputStream(new FileInputStream(zipFile.toFile()))) { String[] zipFilenamePathSplit = zipFile.getFileName().toString().split(File.separator.equals("/") ? "\\/" : "\\\\"); String[] zipFilenameSplitByHyphen = zipFilenamePathSplit[zipFilenamePathSplit.length - 1].split("-"); String artifactName = Arrays.stream(zipFilenameSplitByHyphen) .filter(s -> !s.startsWith("SNAPSHOT")) .filter(s -> !s.equals("rc")) .filter(s -> !s.equals("tf")) .filter(s -> !s.equals("module")) .filter(s -> { if (s.contains(".")) { String[] splitByDot = s.split("\\."); return !StringUtils.isNumeric(splitByDot[0]) && !splitByDot[splitByDot.length - 1].equals("zip"); } return true; }) .reduce("", (s1, s2) -> s1 + (s1.length() > 0 ? "-" : "") + s2); Path modulesDir = zipFile.getParent(); artifactDir = Paths.get(modulesDir.toString(), artifactName); artifactDir.toFile().mkdir(); for (ZipEntry entry : zipStream) { if (entry.isDirectory()) { Paths.get(modulesDir.toString(), artifactName, entry.getName()).toFile().mkdir(); } else { extractFile(zipStream, Paths.get(modulesDir.toString(), artifactName, entry.getName())); } } } catch (IOException e) { log.error("Error expanding " + zipFile.getFileName(), e); return Optional.empty(); } if (!zipFile.toFile().delete()) { log.warn("Unable to delete " + zipFile.toAbsolutePath()); } return Optional.of(artifactDir); } ExpandableZippedArtifact(Path zipFile, Log log);  ExpandableZippedArtifact(Path zipFile); }
ExpandableZippedArtifact implements Expandable { @Override public Optional<Path> expand() { log.info("Expanding " + zipFile); Path artifactDir; try (IterableZipInputStream zipStream = new IterableZipInputStream(new FileInputStream(zipFile.toFile()))) { String[] zipFilenamePathSplit = zipFile.getFileName().toString().split(File.separator.equals("/") ? "\\/" : "\\\\"); String[] zipFilenameSplitByHyphen = zipFilenamePathSplit[zipFilenamePathSplit.length - 1].split("-"); String artifactName = Arrays.stream(zipFilenameSplitByHyphen) .filter(s -> !s.startsWith("SNAPSHOT")) .filter(s -> !s.equals("rc")) .filter(s -> !s.equals("tf")) .filter(s -> !s.equals("module")) .filter(s -> { if (s.contains(".")) { String[] splitByDot = s.split("\\."); return !StringUtils.isNumeric(splitByDot[0]) && !splitByDot[splitByDot.length - 1].equals("zip"); } return true; }) .reduce("", (s1, s2) -> s1 + (s1.length() > 0 ? "-" : "") + s2); Path modulesDir = zipFile.getParent(); artifactDir = Paths.get(modulesDir.toString(), artifactName); artifactDir.toFile().mkdir(); for (ZipEntry entry : zipStream) { if (entry.isDirectory()) { Paths.get(modulesDir.toString(), artifactName, entry.getName()).toFile().mkdir(); } else { extractFile(zipStream, Paths.get(modulesDir.toString(), artifactName, entry.getName())); } } } catch (IOException e) { log.error("Error expanding " + zipFile.getFileName(), e); return Optional.empty(); } if (!zipFile.toFile().delete()) { log.warn("Unable to delete " + zipFile.toAbsolutePath()); } return Optional.of(artifactDir); } ExpandableZippedArtifact(Path zipFile, Log log);  ExpandableZippedArtifact(Path zipFile); @Override Optional<Path> expand(); }
ExpandableZippedArtifact implements Expandable { @Override public Optional<Path> expand() { log.info("Expanding " + zipFile); Path artifactDir; try (IterableZipInputStream zipStream = new IterableZipInputStream(new FileInputStream(zipFile.toFile()))) { String[] zipFilenamePathSplit = zipFile.getFileName().toString().split(File.separator.equals("/") ? "\\/" : "\\\\"); String[] zipFilenameSplitByHyphen = zipFilenamePathSplit[zipFilenamePathSplit.length - 1].split("-"); String artifactName = Arrays.stream(zipFilenameSplitByHyphen) .filter(s -> !s.startsWith("SNAPSHOT")) .filter(s -> !s.equals("rc")) .filter(s -> !s.equals("tf")) .filter(s -> !s.equals("module")) .filter(s -> { if (s.contains(".")) { String[] splitByDot = s.split("\\."); return !StringUtils.isNumeric(splitByDot[0]) && !splitByDot[splitByDot.length - 1].equals("zip"); } return true; }) .reduce("", (s1, s2) -> s1 + (s1.length() > 0 ? "-" : "") + s2); Path modulesDir = zipFile.getParent(); artifactDir = Paths.get(modulesDir.toString(), artifactName); artifactDir.toFile().mkdir(); for (ZipEntry entry : zipStream) { if (entry.isDirectory()) { Paths.get(modulesDir.toString(), artifactName, entry.getName()).toFile().mkdir(); } else { extractFile(zipStream, Paths.get(modulesDir.toString(), artifactName, entry.getName())); } } } catch (IOException e) { log.error("Error expanding " + zipFile.getFileName(), e); return Optional.empty(); } if (!zipFile.toFile().delete()) { log.warn("Unable to delete " + zipFile.toAbsolutePath()); } return Optional.of(artifactDir); } ExpandableZippedArtifact(Path zipFile, Log log);  ExpandableZippedArtifact(Path zipFile); @Override Optional<Path> expand();  }