/** * Creates a zip fie from the given source directory and output zip file name */ public static void createZipFile(Logger log, File sourceDir, File outputZipFile) throws IOException { FileFilter filter = null; createZipFile(log, sourceDir, outputZipFile, filter); }
if (f.isDirectory()) { String prefix = path + f.getName() + "/"; if (matches(filter, f)) { zos.putNextEntry(new ZipEntry(prefix)); zipDirectory(log, f, zos, prefix, filter); if (matches(filter, f)) { FileInputStream fis = new FileInputStream(f); try {
public static List<String> getMavenDependencies(Session session) throws IOException { List<String> dependencies = new ArrayList<>(); try { File[] files = Maven.resolver().loadPomFromFile("pom.xml").importTestDependencies().resolve().withoutTransitivity().asFile(); for (File f : files) { if (f.getName().endsWith("jar") && hasKubernetesJson(f)) { Path dir = Files.createTempDirectory(session.getId()); try (FileInputStream fis = new FileInputStream(f); JarInputStream jis = new JarInputStream(fis)) { Zips.unzip(new FileInputStream(f), dir.toFile()); File jsonPath = dir.resolve(DEFAULT_CONFIG_FILE_NAME).toFile(); if (jsonPath.exists()) { dependencies.add(jsonPath.toURI().toString()); } } } else if (f.getName().endsWith(".json")) { dependencies.add(f.toURI().toString()); } } } catch (Exception e) { session.getLogger().warn("Skipping maven project dependencies. Caused by:" + e.getMessage()); } return dependencies; }
public static void createZipFile(Logger log, File sourceDir, File outputZipFile, FileFilter filter) throws IOException { outputZipFile.getParentFile().mkdirs(); OutputStream os = new FileOutputStream(outputZipFile); ZipOutputStream zos = new ZipOutputStream(os); try { //zos.setLevel(Deflater.DEFAULT_COMPRESSION); //zos.setLevel(Deflater.NO_COMPRESSION); String path = ""; zipDirectory(log, sourceDir, zos, path, filter); } finally { Closeables.closeQuietly(zos); } }
/** * Unzips the given input stream of a ZIP to the given directory */ public static void unzip(InputStream in, File toDir) throws IOException { ZipInputStream zis = new ZipInputStream(new BufferedInputStream(in)); try { ZipEntry entry = zis.getNextEntry(); while (entry != null) { if (!entry.isDirectory()) { String entryName = entry.getName(); File toFile = new File(toDir, entryName); toFile.getParentFile().mkdirs(); OutputStream os = new FileOutputStream(toFile); try { try { copy(zis, os); } finally { zis.closeEntry(); } } finally { Closeables.closeQuietly(os); } } entry = zis.getNextEntry(); } } finally { closeQuietly(zis); } }
public List<String> resolve(Session session) throws IOException { List<String> dependencies = new ArrayList<>(); try { File[] files = Maven.resolver().loadPomFromFile(pathToPomFile).importTestDependencies().resolve().withoutTransitivity().asFile(); for (File f : files) { if (f.getName().endsWith("jar") && hasKubernetesJson(f)) { Path dir = Files.createTempDirectory(session.getId()); try (FileInputStream fis = new FileInputStream(f); JarInputStream jis = new JarInputStream(fis)) { Zips.unzip(new FileInputStream(f), dir.toFile()); File jsonPath = dir.resolve(DEFAULT_CONFIG_FILE_NAME).toFile(); if (jsonPath.exists()) { dependencies.add(jsonPath.toURI().toString()); } } } else if (f.getName().endsWith(".json")) { dependencies.add(f.toURI().toString()); } } } catch (Exception e) { if (rethrowExcpetions) { throw e; } else { session.getLogger().warn("Skipping maven project dependencies. Caused by:" + e.getMessage()); } } return dependencies; }
@Override public void install(InstallContext installContext, ProcessConfig config, String id, File installDir) throws Exception { config.setName(options.getName()); installDir.mkdirs(); File archive = getDownloadStrategy(options).downloadContent(options.getUrl(), installDir); if (archive == null) { archive = new File(installDir, INSTALLED_BINARY); } File nestedProcessDirectory = null; if (archive.exists()) { Zips.unzip(new FileInputStream(archive), installDir); InstallHelper.chmodAllScripts(installDir); nestedProcessDirectory = findInstallDir(installDir); allocatePorts(options, nestedProcessDirectory); exportInstallDirEnvVar(options, nestedProcessDirectory, installContext, config); } } };
Zips.createZipFile(LOG, buildDir, outputZipFile); getLog().info("Created image zip: " + outputZipFile);
protected void unpackBaseImage(File buildDir, boolean useDefaultPrefix) throws Exception { String imageName = project.getProperties().getProperty(DOCKER_BASE_IMAGE_PROPERTY); Objects.notNull(imageName, DOCKER_BASE_IMAGE_PROPERTY); ImageMavenCoords baseImageCoords = ImageMavenCoords.parse(imageName, useDefaultPrefix); String coords = baseImageCoords.getAetherCoords(); Artifact artifact = repositorySystem.createArtifactWithClassifier(baseImageCoords.getGroupId(), baseImageCoords.getArtifactId(), baseImageCoords.getVersion(), baseImageCoords.getType(), baseImageCoords.getClassifier()); getLog().info("Resolving Jube image: " + artifact); ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact); request.setLocalRepository(localRepository); request.setRemoteRepositories(pomRemoteRepositories); ArtifactResolutionResult result = artifactResolver.resolve(request); if (!result.isSuccess()) { throw new ArtifactNotFoundException("Cannot download Jube image", artifact); } getLog().info("Resolved Jube image: " + artifact); if (artifact.getFile() != null) { File file = artifact.getFile(); getLog().info("File: " + file); if (!file.exists() || file.isDirectory()) { throw new MojoExecutionException("Resolved file for " + coords + " is not a valid file: " + file.getAbsolutePath()); } getLog().info("Unpacking base image " + file.getAbsolutePath() + " to build dir: " + buildDir); Zips.unzip(new FileInputStream(file), buildDir); } }