public void testCreateArchiveWithStreamTransformer() throws IOException { InputStreamTransformer is = new InputStreamTransformer() { @Nonnull public InputStream transform( @Nonnull PlexusIoResource resource, @Nonnull InputStream inputStream) throws IOException { return new BoundedInputStream(inputStream, 3); } }; final ZipArchiver zipArchiver = getZipArchiver(getTestFile("target/output/all3bytes.zip")); File zipFIle = new File("src/test/resources/test.zip"); DefaultArchivedFileSet afs = new DefaultArchivedFileSet(zipFIle); afs.setStreamTransformer(is); afs.setPrefix("azip/"); zipArchiver.addArchivedFileSet(afs); DefaultFileSet dfs = new DefaultFileSet(new File("src/test/resources/mjar179")); dfs.setStreamTransformer(is); dfs.setPrefix("mj179/"); zipArchiver.addFileSet(dfs); PlexusIoFileResourceCollection files = new PlexusIoFileResourceCollection(); files.setBaseDir(new File("src/test/resources")); files.setStreamTransformer(is); files.setPrefix("plexus/"); zipArchiver.addResources(files); zipArchiver.createArchive(); }
public void testSymlinkZip() throws Exception { final File zipFile = getTestFile("target/output/pasymlinks.zip"); final ZipArchiver zipArchiver = getZipArchiver(zipFile); PlexusIoFileResourceCollection files = new PlexusIoFileResourceCollection(); files.setFollowingSymLinks(false); files.setBaseDir(new File("src/test/resources/symlinks")); files.setPrefix("plexus/"); zipArchiver.addResources(files); zipArchiver.createArchive(); final File output = getTestFile("target/output/unzipped"); output.mkdirs(); final ZipUnArchiver zipUnArchiver = getZipUnArchiver(zipFile); zipUnArchiver.setDestFile(output); zipUnArchiver.extract(); File symDir = new File("target/output/unzipped/plexus/src/symDir"); PlexusIoResourceAttributes fa = Java7FileAttributes.uncached(symDir); assertTrue(fa.isSymbolicLink()); }
public void testForcedFileModes() throws IOException { File step1file = new File("target/output/forced-file-mode.zip"); { final ZipArchiver zipArchiver = getZipArchiver(step1file); zipArchiver.setFileMode(0077); zipArchiver.setDirectoryMode(0007); PlexusIoResourceAttributes attrs = new SimpleResourceAttributes(123, "fred", 22, "filntstones", 0111); PlexusIoResource resource = ResourceFactory.createResource( new File("src/test/resources/folders/File.txt"), "Test.txt", null, attrs); zipArchiver.addResource(resource, "Test2.txt", 0707); PlexusIoFileResourceCollection files = new PlexusIoFileResourceCollection(); files.setBaseDir(new File("src/test/resources/folders")); files.setPrefix("sixsixsix/"); zipArchiver.addResources(files); zipArchiver.createArchive(); ZipFile zf = new ZipFile(step1file); fileModeAssert(040007, zf.getEntry("sixsixsix/a/").getUnixMode()); fileModeAssert(0100077, zf.getEntry("sixsixsix/b/FileInB.txt").getUnixMode()); fileModeAssert(0100707, zf.getEntry("Test2.txt").getUnixMode()); zf.close(); } File Step2file = new File("target/output/forced-file-mode-from-zip.zip"); { final ZipArchiver za2 = getZipArchiver(Step2file); za2.setFileMode(0666); za2.setDirectoryMode(0676); PlexusIoZipFileResourceCollection zipSrc = new PlexusIoZipFileResourceCollection(); zipSrc.setFile(step1file); zipSrc.setPrefix("zz/"); za2.addResources(zipSrc); za2.createArchive(); ZipFile zf = new ZipFile(Step2file); fileModeAssert(040676, zf.getEntry("zz/sixsixsix/a/").getUnixMode()); fileModeAssert(0100666, zf.getEntry("zz/Test2.txt").getUnixMode()); zf.close(); } File step3file = new File("target/output/forced-file-mode-from-zip2.zip"); { final ZipArchiver za2 = getZipArchiver(step3file); za2.setFileMode(0666); za2.setDirectoryMode(0676); PlexusArchiverZipFileResourceCollection zipSrc = new PlexusArchiverZipFileResourceCollection(); zipSrc.setFile(step1file); zipSrc.setPrefix("zz/"); za2.addResources(zipSrc); za2.createArchive(); ZipFile zf = new ZipFile(Step2file); fileModeAssert(040676, zf.getEntry("zz/sixsixsix/a/").getUnixMode()); fileModeAssert(0100666, zf.getEntry("zz/Test2.txt").getUnixMode()); zf.close(); } }