org.jboss.shrinkwrap.api.Archive类的使用及代码示例

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

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

Archive介绍

[英]Represents a collection of resources which may be constructed programmatically. In effect this represents a virtual filesystem.

All Archive types support the addition of Nodes under a designated ArchivePath (context). The contents of a Node are either a directory or Asset.

Archives are generally created via an ArchiveFactory or via the default configuration shortcut ShrinkWrap utility class.

Because Archives are Assignable, they may be wrapped in another user "view" used to perform operations like adding JavaEE Spec-specific resources or exporting in ZIP format.
[中]表示可通过编程方式构造的资源集合。实际上,这表示一个虚拟文件系统。
所有归档类型都支持在指定的归档路径(上下文)下添加节点。节点的内容可以是目录或资源。
存档通常通过ArchiveFactory或默认配置快捷方式包覆面提取实用程序类创建。
因为归档是可分配的,所以它们可能被包装在另一个用户“视图”中,用于执行添加JavaEE规范特定资源或以ZIP格式导出等操作。

代码示例

代码示例来源:origin: crashub/crash

public static File toExploded(Archive archive, String ext) {
  File tmp = assertTmpFile(ext);
  if (tmp.delete()) {
   ExplodedExporter exporter = archive.as(ExplodedExporter.class);
   exporter.exportExploded(tmp.getParentFile(), tmp.getName());
   tmp.deleteOnExit();
   return tmp;
  } else {
   throw failure("Could not delete tmp file " + tmp.getAbsolutePath());
  }
 }
}

代码示例来源:origin: oracle/helidon

Map<ArchivePath, Node> archiveContents = archive.getContent();
for (Map.Entry<ArchivePath, Node> entry : archiveContents.entrySet()) {
  ArchivePath path = entry.getKey();
  Node n = entry.getValue();
  Path f = subpath(deployDir, path.get());
  if (n.getAsset() == null) {
    Files.createDirectories(f);
  } else {
      Files.createDirectories(parent);
    Files.copy(n.getAsset().openStream(), f, StandardCopyOption.REPLACE_EXISTING);
    String p = n.getPath().get();
    if (callback != null) {
      callback.accept(p);

代码示例来源:origin: org.jboss.arquillian.junit/arquillian-junit-container

@Test
  public void shouldGenerateDependencies() throws Exception {
    Archive<?> archive = new JUnitDeploymentAppender().createAuxiliaryArchive();

    Assert.assertTrue(
      "Should have added Extension",
      archive.contains(
        ArchivePaths.create("/META-INF/services/org.jboss.arquillian.container.test.spi.TestRunner")));

    Assert.assertTrue(
      "Should have added TestRunner Impl",
      archive.contains(ArchivePaths.create("/org/jboss/arquillian/junit/container/JUnitTestRunner.class")));
  }
}

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

@Test
public void existsTrue() throws IOException {
  final Archive<?> archive = this.getArchive();
  final String pathString = "file";
  archive.add(EmptyAsset.INSTANCE, pathString);
  final Path path = fs.getPath(pathString);
  final boolean exists = Files.exists(path);
  Assert.assertTrue("Should report exists", exists);
}

代码示例来源:origin: io.thorntail/tools

public void repackageWar(File file) throws IOException {
  this.log.info("Repackaging .war: " + file);
  Path backupPath = get(file);
  move(file, backupPath, this.log);
  Archive original = ShrinkWrap.create(JavaArchive.class);
  try (InputStream inputStream = Files.newInputStream(backupPath)) {
    original.as(ZipImporter.class).importFrom(inputStream);
  }
  WebInfLibFilteringArchive repackaged = new WebInfLibFilteringArchive(original, this.dependencyManager);
  repackaged.as(ZipExporter.class).exportTo(file, true);
  this.log.info("Repackaged .war: " + file);
}

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

@Test
public void copyFromInputStreamToPath() throws IOException {
  final String contents = "Hello, testing content writing!";
  final byte[] bytes = contents.getBytes("UTF-8");
  final InputStream in = new ByteArrayInputStream(bytes);
  final String pathName = "content";
  final Path path = fs.getPath(pathName);
  final long bytesCopied = Files.copy(in, path);
  final String roundtrip = new BufferedReader(new InputStreamReader(this.getArchive().get(pathName).getAsset()
    .openStream())).readLine();
  Assert.assertEquals("Contents after copy were not as expected", contents, roundtrip);
  Assert.assertEquals(bytes.length, bytesCopied);
}

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

@Test
public void readAllBytes() throws IOException {
  final String path = "path";
  final String contents = "contents";
  this.getArchive().add(new StringAsset(contents), path);
  final byte[] bytes = Files.readAllBytes(fs.getPath(path));
  final String roundtrip = new String(bytes);
  Assert.assertEquals("Contents not read as expected from the readAllBytes", contents, roundtrip);
}

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

@Test
@ArchiveType(ManifestContainer.class)
public void testAddManifestPackagePathTarget() throws Exception {
  ArchivePath targetPath = ArchivePaths.create("Test.txt");
  getManifestContainer().addAsManifestResource(AssetUtil.class.getPackage(), "Test.properties", targetPath);
  ArchivePath testPath = new BasicPath(getManifestPath(), targetPath);
  Assert.assertTrue("Archive should contain " + testPath, getArchive().contains(testPath));
}

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

/**
 * Asserts that the archive recursively contains the specified file in the target starting from the base position.
 */
private void assertArchiveContainsFolderRecursively(File file, ArchivePath base, String target) throws Exception {
  ArchivePath testPath = new BasicPath(base, target);
  Assert.assertTrue("Archive should contain " + testPath, this.getArchive().contains(testPath));
  if (file.isDirectory()) {
    for (File child : file.listFiles()) {
      assertArchiveContainsFolderRecursively(child, base, target + "/" + child.getName());
    }
    int folderInArchiveSize = this.getArchive().get(testPath).getChildren().size();
    Assert.assertEquals("Wrong number of files in the archive folder: " + testPath.get(),
      file.listFiles().length, folderInArchiveSize);
  }
}

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

/**
 * SHRINKWRAP-275
 */
@Test
@ArchiveType(WebContainer.class)
public void testAddWebStringTargetResourceFromJar() throws Exception {
  // Causing NPE
  getWebContainer().addAsWebResource("java/lang/String.class", "String.class");
  ArchivePath testPath = new BasicPath(getWebPath(), "String.class");
  Assert.assertTrue("Archive should contain " + testPath, getArchive().contains(testPath));
}

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

@Test
public void newInputStream() throws IOException {
  final String path = "path";
  final String contents = "contents";
  this.getArchive().add(new StringAsset(contents), path);
  final InputStream in = Files.newInputStream(fs.getPath(path), StandardOpenOption.READ);
  final byte[] buffer = new byte[contents.length()];
  in.read(buffer);
  in.close();
  final String roundtrip = new String(buffer);
  Assert.assertEquals("Contents not read as expected from the instream", contents, roundtrip);
}

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

@Test
public void newOutputStream() throws IOException {
  final String path = "path";
  final String contents = "contents";
  final OutputStream outStream = Files.newOutputStream(fs.getPath(path), StandardOpenOption.WRITE);
  outStream.write(contents.getBytes());
  outStream.close();
  final String roundtrip = new BufferedReader(new InputStreamReader(this.getArchive().get(path).getAsset()
    .openStream())).readLine();
  Assert.assertEquals("Contents not read as expected from the outstream", contents, roundtrip);
}

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

@Test
@ArchiveType(LibraryContainer.class)
public void testAddLibrariesArchive() throws Exception {
  Archive<?> archive = createNewArchive();
  Archive<?> archive2 = createNewArchive();
  getLibraryContainer().addAsLibraries(archive, archive2);
  ArchivePath testPath = new BasicPath(getLibraryPath(), archive.getName());
  ArchivePath testPath2 = new BasicPath(getLibraryPath(), archive.getName());
  Assert.assertTrue("Archive should contain " + testPath, getArchive().contains(testPath));
  Assert.assertTrue("Archive should contain " + testPath2, getArchive().contains(testPath2));
}

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

@Test
public void newBufferedWriter() throws IOException {
  final String path = "path";
  final String contents = "contents";
  final BufferedWriter writer = Files.newBufferedWriter(fs.getPath(path), Charset.defaultCharset(),
    (OpenOption) null);
  writer.write(contents);
  writer.close();
  final String roundtrip = new BufferedReader(new InputStreamReader(this.getArchive().get(path).getAsset()
    .openStream())).readLine();
  Assert.assertEquals("Contents not written as expected from the buffered writer", contents, roundtrip);
}

代码示例来源: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 isRegularFile() throws IOException {
  final String path = "path";
  this.getArchive().add(EmptyAsset.INSTANCE, path);
  Assert.assertTrue(Files.isRegularFile(fs.getPath(path)));
}

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

@Test
public void notExistsFalse() throws IOException {
  this.getArchive().add(EmptyAsset.INSTANCE, "path");
  Assert.assertFalse(Files.notExists(fs.getPath("path"), LinkOption.NOFOLLOW_LINKS));
}

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

@Test
public void testImportArchiveAsTypeFromFilterUsingDefaultFormat() throws Exception {
  String resourcePath = "/test/cl-test.jar";
  GenericArchive archive = ShrinkWrap.create(GenericArchive.class).add(
    new FileAsset(TestIOUtil.createFileFromResourceName("cl-test.jar")), resourcePath);
  Collection<JavaArchive> jars = archive.getAsType(JavaArchive.class, Filters.include(".*jar"));
  Assert.assertEquals("Unexpected result found", 1, jars.size());
  JavaArchive jar = jars.iterator().next().add(new StringAsset("test file content"), "test.txt");
  Assert.assertEquals("JAR imported with wrong name", resourcePath, jar.getName());
  Assert.assertNotNull("Class in JAR not imported", jar.get("test/classloader/DummyClass.class"));
  Assert.assertNotNull("Inner Class in JAR not imported",
    jar.get("test/classloader/DummyClass$DummyInnerClass.class"));
  Assert.assertNotNull("Should contain a new asset", ((ArchiveAsset) archive.get(resourcePath).getAsset())
    .getArchive().get("test.txt"));
}

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

@Test(expected = UnsupportedOperationException.class)
public void getLastModifiedTime() throws IOException {
  this.getArchive().add(EmptyAsset.INSTANCE, "path");
  Files.getLastModifiedTime(fs.getPath("path"), (LinkOption) null);
}

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

protected static Stream<Archive> archives(Collection<Path> paths) {
  return paths.stream()
      .map(path -> {
        String simpleName = path.getFileName().toString();
        Archive archive = ShrinkWrap.create(JavaArchive.class, simpleName);
        archive.as(ZipImporter.class).importFrom(path.toFile());
        return archive;
      });
}

相关文章