@Override public T addAsDirectories(final String... paths) throws IllegalArgumentException { return delegate.addAsDirectories(paths); }
@Override public T addAsDirectories(final ArchivePath... paths) throws IllegalArgumentException { return delegate.addAsDirectories(paths); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.Archive#addAsDirectories(org.jboss.shrinkwrap.api.ArchivePath[]) */ @Override public T addAsDirectories(ArchivePath... paths) throws IllegalArgumentException { this.getArchive().addAsDirectories(paths); return covarientReturn(); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.Archive#addAsDirectories(java.lang.String[]) */ @Override public T addAsDirectories(String... paths) throws IllegalArgumentException { this.getArchive().addAsDirectories(paths); return covarientReturn(); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.Archive#addAsDirectories(org.jboss.shrinkwrap.api.ArchivePath[]) */ @Override public T addAsDirectories(ArchivePath... paths) throws IllegalArgumentException { this.getArchive().addAsDirectories(paths); return covarientReturn(); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.Archive#addAsDirectories(java.lang.String[]) */ @Override public T addAsDirectories(String... paths) throws IllegalArgumentException { this.getArchive().addAsDirectories(paths); return covarientReturn(); }
/** * {@inheritDoc} * * @see java.nio.file.spi.FileSystemProvider#createDirectory(java.nio.file.Path, * java.nio.file.attribute.FileAttribute<?>[]) */ @Override public void createDirectory(final Path dir, final FileAttribute<?>... attrs) throws IOException { final Archive<?> archive = this.getArchive(dir); final ArchivePath parent = ArchivePaths.create(dir.toString()).getParent(); if (parent != null && !archive.contains(parent)) { // IOException? Despite being a stupid choice for this, it's what the NIO.2 API uses. throw new IOException("Cannot recursively create parent directories for: " + dir + "; instead invoke \"createDirectories\""); } archive.addAsDirectories(dir.toString()); if (log.isLoggable(Level.FINEST)) { log.finest("Created directory " + dir.toString() + " on " + archive.toString()); } }
/** * {@inheritDoc} * * @see java.nio.file.spi.FileSystemProvider#createDirectory(java.nio.file.Path, * java.nio.file.attribute.FileAttribute<?>[]) */ @Override public void createDirectory(final Path dir, final FileAttribute<?>... attrs) throws IOException { final Archive<?> archive = this.getArchive(dir); final ArchivePath parent = ArchivePaths.create(dir.toString()).getParent(); if (parent != null && !archive.contains(parent)) { // IOException? Despite being a stupid choice for this, it's what the NIO.2 API uses. throw new IOException("Cannot recursively create parent directories for: " + dir + "; instead invoke \"createDirectories\""); } archive.addAsDirectories(dir.toString()); if (log.isLoggable(Level.FINEST)) { log.finest("Created directory " + dir.toString() + " on " + archive.toString()); } }
@Test public void createTempDirectory() throws IOException { final String tempDir = "/tmp"; this.getArchive().addAsDirectories(tempDir); final String prefix = "prefix"; final Path tempDirPath = fs.getPath(tempDir); final Path newPath = Files.createTempDirectory(tempDirPath, prefix, new FileAttribute<?>[] {}); Assert.assertTrue("temp dir name was not in expected form", newPath.toString().startsWith(tempDir + "/" + prefix)); }
@Test public void copyFromInputStreamToExistingDirectory() throws IOException { final InputStream in = new ByteArrayInputStream("test".getBytes("UTF-8")); final String pathName = "directory"; final Path path = fs.getPath(pathName); // Add some directory to the archive this.getArchive().addAsDirectories(pathName); // Now try to copy to the same path as the dir boolean gotException = false; try { Files.copy(in, path); } catch (final FileAlreadyExistsException faee) { gotException = true; } Assert.assertTrue("Overwrite of existing directory should fail", gotException); }
@Test public void isDirectoryTrue() throws IOException { this.getArchive().addAsDirectories("path"); Assert.assertTrue(Files.isDirectory(fs.getPath("path"), (LinkOption) null)); }
@Test public void copyFromDirectoryPathToOutputStream() throws IOException { // Populate the archive w/ content final String path = "dirPath"; this.getArchive().addAsDirectories(path); // Attempt to copy the dir final ByteArrayOutputStream out = new ByteArrayOutputStream(); boolean gotException = false; try { Files.copy(fs.getPath(path), out); } catch (final IllegalArgumentException iae) { gotException = true; } Assert.assertTrue("Call to copy a directory contents to an outstream should not succeed", gotException); }
@Test public void copyFromInputStreamToExistingNonEmptyDirectoryWithReplaceExistingOption() throws IOException { final InputStream in = new ByteArrayInputStream("test".getBytes("UTF-8")); final String dir = "/directory"; final String subdir = dir + "/subdir"; final Path dirPath = fs.getPath(dir); // Add some nested directory to the archive this.getArchive().addAsDirectories(subdir); // Now try to copy to a nonempty dir boolean gotException = false; try { Files.copy(in, dirPath, StandardCopyOption.REPLACE_EXISTING); } catch (final DirectoryNotEmptyException dnee) { gotException = true; } Assert.assertTrue("Overwrite of existing non-empty dir should fail, even with replace option", gotException); }
@Test public void newDirectoryStream() throws IOException { final String dirs = "a/b/c/d/e"; this.getArchive().addAsDirectories(dirs); final DirectoryStream<Path> stream = Files.newDirectoryStream(fs.getPath("/")); final Iterator<Path> paths = stream.iterator(); int counter = 0; while (paths.hasNext()) { counter++; final Path path = paths.next(); Assert.assertTrue(this.getArchive().contains(path.toString())); } Assert.assertEquals(1, counter); }
/** * SHRINKWRAP-416 */ @Test public void addResourceToExistingDirThrowsIllegalOverwriteException() { // Create the new archive final Archive<?> archive = createNewArchive(); // Put in an asset final ArchivePath path = ArchivePaths.create("testPath"); archive.addAsDirectories(path); // Now try again with a new asset, and this should fail try { archive.add(new StringAsset("failContent"), path); } catch (final IllegalOverwriteException ioe) { // Good return; } // Fail us TestCase.fail("Expected " + IllegalOverwriteException.class.getName() + " not received"); }
@Test public void testHandlerIsCalledWhenAddingDirectoriesWithStringPath() throws Exception { final SimpleHandler simpleHandler1 = new SimpleHandler(); final SimpleHandler simpleHandler2 = new SimpleHandler(); getArchive().addHandlers(simpleHandler1, simpleHandler2); getArchive().addAsDirectories("/path/to/dir1"); Assert.assertTrue("Handler not called", simpleHandler1.called); Assert.assertTrue("Handler not called", simpleHandler2.called); }
@Test public void testHandlerIsCalledWhenAddingDirectoriesWithArchivePath() throws Exception { final SimpleHandler simpleHandler1 = new SimpleHandler(); final SimpleHandler simpleHandler2 = new SimpleHandler(); getArchive().addHandlers(simpleHandler1, simpleHandler2); getArchive().addAsDirectories(ArchivePaths.create("/path/to/dir1")); Assert.assertTrue("Handler not called", simpleHandler1.called); Assert.assertTrue("Handler not called", simpleHandler2.called); }
/** * Delete directory which contains children. */ @Test public void testDeletePathWithChildren() { // given final Archive<T> archive = getArchive(); final String dirName = "dir"; archive.addAsDirectories(dirName); archive.add(new StringAsset("asset"), dirName, "abc.txt").add(new StringAsset("asset"), dirName, "cde.txt"); archive.add(new StringAsset("other"), "other.txt"); // when archive.delete("dir"); // then Assert.assertFalse(archive.contains(dirName)); Assert.assertEquals(1, archive.getContent().size()); }
/** * Tests that empty directories may be added to the archive * * @throws Exception */ @Test public void testAddEmptyDirectories() throws Exception { Archive<T> archive = getArchive(); // Get Paths to add final ArchivePath path1 = ArchivePaths.create("path/to/dir"); final ArchivePath path2 = ArchivePaths.create("path/to/dir2"); final ArchivePath path3 = ArchivePaths.create("path/to"); // Add archive.addAsDirectories(path1, path2, path3); // Test final String message = "Should be able to add directory: "; Assert.assertTrue(message + path1, archive.contains(path1)); Assert.assertTrue(message + path2, archive.contains(path2)); Assert.assertTrue(message + path3, archive.contains(path3)); }