public static List<String> scanZipFile(String parentPath, InputStream is, boolean relativeOnly) { try { ZipInputStream zis = new ZipInputStream(is); ZipEntry entry; List<String> results = new ArrayList<>(); while ((entry = zis.getNextEntry()) != null) { String fullPath = parentPath + "/" + entry.getName(); results.add(relativeOnly ? entry.getName() : fullPath); if (!entry.isDirectory() && ZipUtil.endsWithZipExtension(entry.getName())) { results.addAll(scanZipFile(fullPath, zis, relativeOnly)); } } return results; } catch (IOException e) { System.err.println("Could not read file: " + parentPath + " due to: " + e.getMessage()); return Collections.emptyList(); } }
/** * Unzip a classpath resource using the given {@link Class} as the resource root path. */ public static void unzipFromClassResource(Class<?> clazz, String resourcePath, File extractToPath) throws IOException { File inputFile = File.createTempFile("windup-resource-to-unzip-", ".zip"); try { try (final InputStream stream = clazz.getResourceAsStream(resourcePath)) { FileUtils.copyInputStreamToFile(stream, inputFile); } extractToPath.mkdirs(); ZipUtil.unzipToFolder(inputFile, extractToPath); } finally { inputFile.delete(); } }
public static boolean endsWithZipExtension(String path) { for (String extension : getZipExtensions()) { if (StringUtils.endsWith(path, "." + extension)) { return true; } } return false; }
projectModel.setDescription("Not available"); if(ZipUtil.endsWithZipExtension(archiveModel.getArchiveName())) for (String extension : ZipUtil.getZipExtensions())
private static boolean isJavaArchive(Path path) { return ZipUtil.endsWithZipExtension(path.toString()); } }
public static List<String> scanZipFile(Path zipFilePath, boolean relativeOnly) { try { try (final InputStream is = new FileInputStream(zipFilePath.toFile())) { return scanZipFile(zipFilePath.normalize().toString(), is, relativeOnly); } } catch (IOException e) { System.err.println("Could not read file: " + zipFilePath + " due to: " + e.getMessage()); return Collections.emptyList(); } }
@Override public Configuration getConfiguration(GraphContext context) { return ConfigurationBuilder.begin() .addRule() .when(Query.fromType(FileModel.class) .withProperty(FileModel.IS_DIRECTORY, true) ) .perform(new RecurseDirectoryAndAddFiles() ) .addRule() .when(Query.fromType(FileModel.class) .withProperty(FileModel.IS_DIRECTORY, false) .withProperty(FileModel.FILE_PATH, QueryPropertyComparisonType.REGEX, ZipUtil.getEndsWithZipRegularExpression()) ) .perform( new AddArchiveReferenceInformation() ); } // @formatter:on
projectModel.setDescription("Not available"); if(ZipUtil.endsWithZipExtension(archiveModel.getArchiveName())) for (String extension : ZipUtil.getZipExtensions())
private static boolean isJavaArchive(Path path) { return ZipUtil.endsWithZipExtension(path.toString()); } }
public static List<String> scanZipFile(Path zipFilePath, boolean relativeOnly) { try { try (final InputStream is = new FileInputStream(zipFilePath.toFile())) { return scanZipFile(zipFilePath.normalize().toString(), is, relativeOnly); } } catch (IOException e) { System.err.println("Could not read file: " + zipFilePath + " due to: " + e.getMessage()); return Collections.emptyList(); } }
@Override public Configuration getConfiguration(RuleLoaderContext ruleLoaderContext) { return ConfigurationBuilder.begin() .addRule() .when(Query.fromType(WindupConfigurationModel.class) .piped((GraphRewrite event, GraphTraversal<?, Vertex> pipeline) -> { pipeline.out(WindupConfigurationModel.INPUT_PATH); pipeline.has(FileModel.IS_DIRECTORY, true); }) ) .perform(new RecurseDirectoryAndAddFiles()) .addRule() .when(Query.fromType(FileModel.class) .withProperty(FileModel.IS_DIRECTORY, false) .withProperty(FileModel.FILE_PATH, QueryPropertyComparisonType.REGEX, ZipUtil.getEndsWithZipRegularExpression()) ) .perform( new AddArchiveReferenceInformation() ); } // @formatter:on
public static List<String> scanZipFile(String parentPath, InputStream is, boolean relativeOnly) { try { ZipInputStream zis = new ZipInputStream(is); ZipEntry entry; List<String> results = new ArrayList<>(); while ((entry = zis.getNextEntry()) != null) { String fullPath = parentPath + "/" + entry.getName(); results.add(relativeOnly ? entry.getName() : fullPath); if (!entry.isDirectory() && ZipUtil.endsWithZipExtension(entry.getName())) { results.addAll(scanZipFile(fullPath, zis, relativeOnly)); } } return results; } catch (IOException e) { System.err.println("Could not read file: " + parentPath + " due to: " + e.getMessage()); return Collections.emptyList(); } }
if (subFile.isFile() && ZipUtil.endsWithZipExtension(subFileModel.getFilePath()))
/** * Unzip a classpath resource using the given {@link Class} as the resource root path. */ public static void unzipFromClassResource(Class<?> clazz, String resourcePath, File extractToPath) throws IOException { File inputFile = File.createTempFile("windup-resource-to-unzip-", ".zip"); try { try (final InputStream stream = clazz.getResourceAsStream(resourcePath)) { FileUtils.copyInputStreamToFile(stream, inputFile); } extractToPath.mkdirs(); ZipUtil.unzipToFolder(inputFile, extractToPath); } finally { inputFile.delete(); } }
public static boolean endsWithZipExtension(String path) { for (String extension : getZipExtensions()) { if (StringUtils.endsWith(path, "." + extension)) { return true; } } return false; }
@Override public Configuration getConfiguration(RuleLoaderContext ruleLoaderContext) { return ConfigurationBuilder.begin() .addRule() .when(Query.fromType(WindupConfigurationModel.class) .piped((GraphRewrite event, GraphTraversal<?, Vertex> pipeline) -> { pipeline.out(WindupConfigurationModel.INPUT_PATH); pipeline.has(FileModel.IS_DIRECTORY, true); }) ) .perform(new RecurseDirectoryAndAddFiles()) .addRule() .when(Query.fromType(FileModel.class) .withProperty(FileModel.IS_DIRECTORY, false) .withProperty(FileModel.FILE_PATH, QueryPropertyComparisonType.REGEX, ZipUtil.getEndsWithZipRegularExpression()) ) .perform( new AddArchiveReferenceInformation() ); } // @formatter:on
private static List<String> findPaths(Path path, boolean relativeOnly) { List<String> results = new ArrayList<>(); results.add(path.normalize().toAbsolutePath().toString()); if (Files.isDirectory(path)) { try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path)) { for (Path child : directoryStream) { results.addAll(findPaths(child, relativeOnly)); } } catch (IOException e) { System.err.println("Could not read file: " + path + " due to: " + e.getMessage()); } } else if (Files.isRegularFile(path) && ZipUtil.endsWithZipExtension(path.toString())) { results.addAll(ZipUtil.scanZipFile(path, relativeOnly)); } return results; }
continue; if (subArchivesOnly && !ZipUtil.endsWithZipExtension(subFile.getAbsolutePath())) continue; event.getGraphContext().commit(); if (subFile.isFile() && ZipUtil.endsWithZipExtension(subFileModel.getFilePath()))
public void extractArtifact(Coordinate artifactCoords, File targetDir) throws IOException, DependencyException { final DependencyQueryBuilder query = DependencyQueryBuilder.create(artifactCoords); Dependency dependency = depsResolver.resolveArtifact(query); FileResource<?> artifact = dependency.getArtifact(); ZipUtil.unzipToFolder(new File(artifact.getFullyQualifiedName()), targetDir); }
public static boolean endsWithZipExtension(String path) { for (String extension : getZipExtensions()) { if (StringUtils.endsWith(path, "." + extension)) { return true; } } return false; }