@Override public T addAsDirectory(final String path) throws IllegalArgumentException { return delegate.addAsDirectory(path); }
@Override public T addAsDirectory(final ArchivePath path) throws IllegalArgumentException { return delegate.addAsDirectory(path); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.Archive#addAsDirectory(org.jboss.shrinkwrap.api.ArchivePath) */ @Override public T addAsDirectory(ArchivePath path) throws IllegalArgumentException { this.getArchive().addAsDirectory(path); return covarientReturn(); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.Archive#addAsDirectory(org.jboss.shrinkwrap.api.ArchivePath) */ @Override public T addAsDirectory(ArchivePath path) throws IllegalArgumentException { this.getArchive().addAsDirectory(path); return covarientReturn(); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.Archive#addAsDirectory(java.lang.String) */ @Override public T addAsDirectory(String path) throws IllegalArgumentException { this.getArchive().addAsDirectory(path); return covarientReturn(); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.Archive#addAsDirectory(java.lang.String) */ @Override public T addAsDirectory(String path) throws IllegalArgumentException { this.getArchive().addAsDirectory(path); return covarientReturn(); }
private void doImport(File root, File[] files, Filter<ArchivePath> filter) { for (File file : files) { if (log.isLoggable(Level.FINER)) { log.finer("Importing: " + file.getAbsolutePath()); } final Archive<?> archive = this.getArchive(); final ArchivePath path = calculatePath(root, file); if( filter.include(path) ) { if (file.isDirectory()) { archive.addAsDirectory(path); doImport(root, file.listFiles(), filter); } else { archive.add(new FileAsset(file), path); } } } }
private void doImport(File root, File[] files, Filter<ArchivePath> filter) { for (File file : files) { if (log.isLoggable(Level.FINER)) { log.finer("Importing: " + file.getAbsolutePath()); } final Archive<?> archive = this.getArchive(); final ArchivePath path = calculatePath(root, file); if( filter.include(path) ) { if (file.isDirectory()) { archive.addAsDirectory(path); doImport(root, file.listFiles(), filter); } else { archive.add(new FileAsset(file), path); } } } }
archive.addAsDirectory(entryName); continue;
private ZipImporter importFrom(final ZipFile file, Filter<ArchivePath> filter) throws ArchiveImportException { Validate.notNull(file, "File must be specified"); try { Enumeration<? extends ZipEntry> entries = file.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); // Get the entry (path) name final String entryName = entry.getName(); if(!filter.include(ArchivePaths.create(entryName))) { continue; } // Get the archive final Archive<?> archive = this.getArchive(); // Handle directories separately if (entry.isDirectory()) { archive.addAsDirectory(entryName); continue; } archive.add(new ZipFileEntryAsset(file, entry), new BasicPath(entryName)); } } catch (Exception e) { throw new ArchiveImportException("Could not import file", e); } return this; } }
archive.addAsDirectory(entryName); continue;
@Test public void moveDirectory() throws IOException { final String source = "dir"; this.getArchive().addAsDirectory(source); final String dest = "newPath"; final Path src = fs.getPath(source); final Path dst = fs.getPath(dest); final Path moved = Files.move(src, dst); Assert.assertEquals(dest, moved.toString()); Assert.assertNull("Directory expected after move", this.getArchive().get(dest).getAsset()); }
@Test public void shouldMoveDirectory() { final Archive<JavaArchive> archive = ShrinkWrap.create(JavaArchive.class, "archive.jar"); final String sourcePath = "path1"; final String targetPath = "path2"; archive.addAsDirectory(sourcePath); archive.move(sourcePath, targetPath); Assert.assertTrue("Directory should be at the new path", archive.get(targetPath).getAsset() == null); }
archive.addAsDirectory(entryName); continue;
archive.addAsDirectory(entryName); continue;
@Test public void deleteUnemptyDirectory() throws IOException { final String directoryName = "/directory"; final String subDirectoryName = directoryName + "/subdir"; final Archive<?> archive = this.getArchive().addAsDirectory(subDirectoryName); // Preconditions Assert.assertNull("Test archive should contain the directory, not content", archive.get(subDirectoryName) .getAsset()); // Attempt delete final Path path = fs.getPath(directoryName); boolean gotException = false; try { Files.delete(path); } catch (final DirectoryNotEmptyException dnee) { gotException = true; } Assert.assertTrue("Should not be able to delete non-empty directory", gotException); }
@Test public void deleteDirectory() throws IOException { final String directoryName = "directory"; final Archive<?> archive = this.getArchive().addAsDirectory(directoryName); // Preconditions Assert.assertNull("Test archive should contain the directory, not content", archive.get(directoryName) .getAsset()); // Attempt delete final Path path = fs.getPath(directoryName); Files.delete(path); // Assertion Assert.assertFalse("Archive should no longer contain directory ", archive.contains(directoryName)); }
/** * Create an archive instance and add some assets and some nested archives */ protected Archive<?> createArchiveWithNestedArchives() { // Create an archive Archive<?> archive = createArchiveWithAssets(); // Create a nested archive Archive<?> nestedArchive = ShrinkWrap.create(JavaArchive.class, NAME_NESTED_ARCHIVE + getArchiveExtension()); // Add some content addContent(nestedArchive); // Add nested archive archive.add(nestedArchive, ArchivePaths.root(), this.getExporterClass()); // Add an archive nested in a directory Archive<?> nestedArchiveTwo = ShrinkWrap.create(JavaArchive.class, NAME_NESTED_ARCHIVE_2 + getArchiveExtension()); // Add some content addContent(nestedArchiveTwo); // Add the archive under a nested path archive.add(nestedArchiveTwo, NESTED_PATH, this.getExporterClass()); // Add empty directories archive.addAsDirectory(PATH_EMPTY_NESTED_DIR); archive.addAsDirectory(PATH_EMPTY_TOPLEVEL_DIR); // Return archive return archive; }
/** * Ensure that trying to add a directory on an illegal path throws an Exception * * @throws Exception */ @Test(expected = IllegalArchivePathException.class) public void shouldNotBeAbleToAddDirectoryOnIllegalPath() throws Exception { Archive<T> archive = getArchive(); // add an asset Asset asset = new ClassLoaderAsset(NAME_TEST_PROPERTIES); ArchivePath location = new BasicPath("/somewhere/test.properties"); archive.add(asset, location); // try to add a directory on an illegal path archive.addAsDirectory("/somewhere/test.properties/test"); }
@Test public void shouldMoveNotEmptyDirectory() { final Archive<JavaArchive> archive = ShrinkWrap.create(JavaArchive.class, "archive.jar"); final String sourcePath = "path1"; final String targetPath = "path2"; final String childDirName = "childDir"; final String childDirPath = sourcePath + "/" + childDirName; final String childDirTargetPath = targetPath + "/" + childDirName; final String childFileName = "file1"; final String childFilePath = childDirPath + "/" + childFileName; final String childFileTargetPath = childDirTargetPath + "/" + childFileName; archive.addAsDirectory(sourcePath); archive.addAsDirectory(childDirName); archive.add(EmptyAsset.INSTANCE, childFilePath); archive.move(sourcePath, targetPath); Assert.assertTrue("Directory should be at the new path", archive.get(targetPath).getAsset() == null); Assert.assertTrue("Child dir should be at the new path", archive.get(childDirTargetPath).getAsset() == null); Assert.assertTrue("Child asset should be at the new path", archive.get(childFileTargetPath).getAsset() != null); }