org.jboss.shrinkwrap.api.Archive.addAsDirectory()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(141)

本文整理了Java中org.jboss.shrinkwrap.api.Archive.addAsDirectory()方法的一些代码示例,展示了Archive.addAsDirectory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Archive.addAsDirectory()方法的具体详情如下:
包路径:org.jboss.shrinkwrap.api.Archive
类名称:Archive
方法名:addAsDirectory

Archive.addAsDirectory介绍

[英]Adds the specified directory.
[中]添加指定的目录。

代码示例

代码示例来源:origin: wildfly/wildfly-arquillian

@Override
public T addAsDirectory(final String path) throws IllegalArgumentException {
  return delegate.addAsDirectory(path);
}

代码示例来源:origin: wildfly/wildfly-arquillian

@Override
public T addAsDirectory(final ArchivePath path) throws IllegalArgumentException {
  return delegate.addAsDirectory(path);
}

代码示例来源:origin: shrinkwrap/shrinkwrap

/**
 * {@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();
}

代码示例来源:origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

/**
 * {@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();
}

代码示例来源:origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

/**
 * {@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();
}

代码示例来源:origin: shrinkwrap/shrinkwrap

/**
 * {@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();
}

代码示例来源:origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

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);
      }
    }
  }
}

代码示例来源:origin: shrinkwrap/shrinkwrap

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);
      }
    }
  }
}

代码示例来源:origin: shrinkwrap/shrinkwrap

archive.addAsDirectory(entryName);
continue;

代码示例来源:origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

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;
  }
}

代码示例来源:origin: shrinkwrap/shrinkwrap

archive.addAsDirectory(entryName);
continue;

代码示例来源:origin: shrinkwrap/shrinkwrap

@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());
}

代码示例来源:origin: shrinkwrap/shrinkwrap

@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);
}

代码示例来源:origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

archive.addAsDirectory(entryName);
continue;

代码示例来源:origin: shrinkwrap/shrinkwrap

archive.addAsDirectory(entryName);
continue;

代码示例来源:origin: shrinkwrap/shrinkwrap

@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);
}

代码示例来源:origin: shrinkwrap/shrinkwrap

@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));
}

代码示例来源:origin: shrinkwrap/shrinkwrap

/**
 * 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;
}

代码示例来源:origin: shrinkwrap/shrinkwrap

/**
 * 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");
}

代码示例来源:origin: shrinkwrap/shrinkwrap

@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);
}

相关文章