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

x33g5p2x  于2022-01-16 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(62)

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

ArchiveAsset介绍

[英]An Asset representing an Archive; a specified StreamExporter type will be used to fulfill the Asset#openStream() contract.
[中]代表档案的资产;指定的StreamExporter类型将用于履行资产#openStream()契约。

代码示例

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

/**
 * {@inheritDoc}
 *
 * @see org.jboss.shrinkwrap.api.asset.Asset#openStream()
 */
@Override
public InputStream openStream() {
  // Export via the specified exporter
  return this.getArchive().as(this.exporter).exportAsInputStream();
}

代码示例来源:origin: com.kumuluz.ee.testing/kumuluzee-arquillian-container

private static JavaArchive generateWar(Archive<?> archive, List<String> deploymentLibraries) {
  JavaArchive javaArchive = archive.as(JavaArchive.class);
  Archive<?>[] requiredLibraries = RequiredLibraries.getRequiredLibraries(deploymentLibraries);
  Arrays.stream(requiredLibraries).forEach(f -> javaArchive.add(new ArchiveAsset(f, ZipExporter.class),
      "/WEB-INF/lib/" + f.getName()));
  return javaArchive;
}

代码示例来源:origin: org.apache.openwebbeans.arquillian/owb-arquillian-standalone

asset = new ArchiveAsset(fileArchive, ZipExporter.class);
JavaArchive jarArchive = (JavaArchive) archiveAsset.getArchive();
scanJarArchive(jarArchive);

代码示例来源:origin: com.kumuluz.ee.testing/kumuluzee-arquillian-container

/**
 * Converts {@link ArchiveAsset}s in parentDir to {@link ByteArrayAsset}s.
 * <p>
 * By default {@link org.jboss.shrinkwrap.api.exporter.ExplodedExporter} exports {@link ArchiveAsset}s in parent
 * archive as exploded directories. Since we need to export them as archives, we convert them to
 * {@link ByteArrayAsset}s.
 *
 * @param a         Archive to fix
 * @param parentDir Directory to scan for {@link ArchiveAsset}s
 */
private static void fixArchiveAssets(Archive<?> a, String parentDir) {
  Node n = a.get(parentDir);
  Archive<?> tmp = ShrinkWrap.create(JavaArchive.class);
  List<ArchivePath> pathsToDelete = new ArrayList<>();
  for (Node child : n.getChildren()) {
    Asset childAsset = child.getAsset();
    if (childAsset instanceof ArchiveAsset && child.getPath().get().endsWith(".jar")) {
      LOG.fine("Converting archive " + child.getPath().get() + " to ByteArrayAsset");
      ArchiveAsset archiveAsset = (ArchiveAsset) childAsset;
      ByteArrayAsset bas = new ByteArrayAsset(archiveAsset.openStream());
      pathsToDelete.add(child.getPath());
      tmp.add(bas, child.getPath());
    }
  }
  for (ArchivePath ap : pathsToDelete) {
    a.delete(ap);
  }
  a.merge(tmp);
}

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

return ArchiveAsset.class.cast(asset).getArchive().as(type);
X archive = ShrinkWrap.create(formatBinding.getImporter(), path.get()).importFrom(stream).as(type);
delete(path);
add(new ArchiveAsset(archive, formatBinding.getExporter()), path);

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

/**
 * Processes a nested archive by delegating to the ExplodedArchiveExporter
 *
 * @param parentDirectory
 * @param nestedArchiveAsset
 */
private void processArchiveAsset(File parentDirectory, ArchiveAsset nestedArchiveAsset) {
  // Get the nested archive
  Archive<?> nestedArchive = nestedArchiveAsset.getArchive();
  nestedArchive.as(ExplodedExporter.class).exportExploded(parentDirectory);
}

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

return ArchiveAsset.class.cast(asset).getArchive().as(type);
X archive = ShrinkWrap.create(formatBinding.getImporter(), path.get()).importFrom(stream).as(type);
delete(path);
add(new ArchiveAsset(archive, formatBinding.getExporter()), path);

代码示例来源:origin: org.jboss.arquillian.extension/arquillian-extension-byteman

jar.add(new ArchiveAsset(agentJar, ZipExporter.class), BytemanConfiguration.BYTEMAN_JAR);
} else {

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

/**
 * {@inheritDoc}
 *
 * @see org.jboss.shrinkwrap.api.asset.Asset#openStream()
 */
@Override
public InputStream openStream() {
  // Export via the specified exporter
  return this.getArchive().as(this.exporter).exportAsInputStream();
}

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

/**
 * {@inheritDoc}
 *
 * @see org.jboss.shrinkwrap.api.Archive#add(org.jboss.shrinkwrap.api.Archive, org.jboss.shrinkwrap.api.ArchivePath,
 *      java.lang.Class)
 */
@Override
public T add(final Archive<?> archive, final ArchivePath path, Class<? extends StreamExporter> exporter) {
  // Precondition checks
  Validate.notNull(path, "No path was specified");
  Validate.notNull(archive, "No archive was specified");
  Validate.notNull(exporter, "No exporter was specified");
  // Make a Path
  final String archiveName = archive.getName();
  final ArchivePath contentPath = new BasicPath(path, archiveName);
  // Create ArchiveAsset
  final ArchiveAsset archiveAsset = new ArchiveAsset(archive, exporter);
  // Delegate
  return add(archiveAsset, contentPath);
}

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

/**
 * Processes a nested archive by delegating to the ExplodedArchiveExporter
 *
 * @param parentDirectory
 * @param nestedArchiveAsset
 */
private void processArchiveAsset(File parentDirectory, ArchiveAsset nestedArchiveAsset) {
  // Get the nested archive
  Archive<?> nestedArchive = nestedArchiveAsset.getArchive();
  nestedArchive.as(ExplodedExporter.class).exportExploded(parentDirectory);
}

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

/**
 * {@inheritDoc}
 *
 * @see org.jboss.shrinkwrap.api.Archive#add(org.jboss.shrinkwrap.api.Archive, org.jboss.shrinkwrap.api.ArchivePath,
 *      java.lang.Class)
 */
@Override
public T add(final Archive<?> archive, final ArchivePath path, Class<? extends StreamExporter> exporter) {
  // Precondition checks
  Validate.notNull(path, "No path was specified");
  Validate.notNull(archive, "No archive was specified");
  Validate.notNull(exporter, "No exporter was specified");
  // Make a Path
  final String archiveName = archive.getName();
  final ArchivePath contentPath = new BasicPath(path, archiveName);
  // Create ArchiveAsset
  final ArchiveAsset archiveAsset = new ArchiveAsset(archive, exporter);
  // Delegate
  return add(archiveAsset, contentPath);
}

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

/**
 * Check to see if a path is found in a nested archive
 */
private boolean nestedContains(ArchivePath path) {
  // Iterate through nested archives
  for (Entry<ArchivePath, ArchiveAsset> nestedArchiveEntry : nestedArchives.entrySet()) {
    ArchivePath archivePath = nestedArchiveEntry.getKey();
    ArchiveAsset archiveAsset = nestedArchiveEntry.getValue();
    // Check to see if the requested path starts with the nested archive path
    if (startsWith(path, archivePath)) {
      Archive<?> nestedArchive = archiveAsset.getArchive();
      // Get the asset path from within the nested archive
      ArchivePath nestedAssetPath = getNestedPath(path, archivePath);
      // Recurse the call to the nested archive
      return nestedArchive.contains(nestedAssetPath);
    }
  }
  return false;
}

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

/**
 * Check to see if a path is found in a nested archive
 */
private boolean nestedContains(ArchivePath path) {
  // Iterate through nested archives
  for (Entry<ArchivePath, ArchiveAsset> nestedArchiveEntry : nestedArchives.entrySet()) {
    ArchivePath archivePath = nestedArchiveEntry.getKey();
    ArchiveAsset archiveAsset = nestedArchiveEntry.getValue();
    // Check to see if the requested path starts with the nested archive path
    if (startsWith(path, archivePath)) {
      Archive<?> nestedArchive = archiveAsset.getArchive();
      // Get the asset path from within the nested archive
      ArchivePath nestedAssetPath = getNestedPath(path, archivePath);
      // Recurse the call to the nested archive
      return nestedArchive.contains(nestedAssetPath);
    }
  }
  return false;
}

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

/**
 * Attempt to get the asset from a nested archive.
 *
 * @param path
 * @return
 */
private Node getNestedNode(ArchivePath path) {
  // Iterate through nested archives
  for (Entry<ArchivePath, ArchiveAsset> nestedArchiveEntry : nestedArchives.entrySet()) {
    ArchivePath archivePath = nestedArchiveEntry.getKey();
    ArchiveAsset archiveAsset = nestedArchiveEntry.getValue();
    // Check to see if the requested path starts with the nested archive path
    if (startsWith(path, archivePath)) {
      Archive<?> nestedArchive = archiveAsset.getArchive();
      // Get the asset path from within the nested archive
      ArchivePath nestedAssetPath = getNestedPath(path, archivePath);
      // Recurse the call to the nested archive
      return nestedArchive.get(nestedAssetPath);
    }
  }
  return null;
}

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

/**
 * Attempt to get the asset from a nested archive.
 *
 * @param path
 * @return
 */
private Node getNestedNode(ArchivePath path) {
  // Iterate through nested archives
  for (Entry<ArchivePath, ArchiveAsset> nestedArchiveEntry : nestedArchives.entrySet()) {
    ArchivePath archivePath = nestedArchiveEntry.getKey();
    ArchiveAsset archiveAsset = nestedArchiveEntry.getValue();
    // Check to see if the requested path starts with the nested archive path
    if (startsWith(path, archivePath)) {
      Archive<?> nestedArchive = archiveAsset.getArchive();
      // Get the asset path from within the nested archive
      ArchivePath nestedAssetPath = getNestedPath(path, archivePath);
      // Recurse the call to the nested archive
      return nestedArchive.get(nestedAssetPath);
    }
  }
  return null;
}

代码示例来源:origin: arquillian/arquillian-extension-persistence

/**
 * Recursively scans archive content (including sub archives) for persistence.xml descriptors.
 */
private Collection<Node> collectPersistenceXml(final Archive<?> archive) {
  final Collection<Node> nodes = new LinkedList<Node>(getPersistenceDescriptors(archive));
  for (Node node : collectSubArchives(archive)) {
    if (node.getAsset() instanceof ArchiveAsset) {
      final ArchiveAsset archiveAsset = (ArchiveAsset) node.getAsset();
      nodes.addAll(collectPersistenceXml(archiveAsset.getArchive()));
    }
  }
  return nodes;
}

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

public void formatNode(Node node, StringBuilder xml) {
  if (node.getAsset() != null) {
    String source = findResourceLocation(node.getAsset());
    xml.append("\t<asset")
      .append(" type=\"").append(node.getAsset().getClass().getSimpleName()).append("\"")
      .append(" path=\"").append(node.getPath().get()).append("\"");
    if (source != null) {
      xml.append(" source=\"").append(source).append("\"");
    }
    if (node.getAsset().getClass() == ArchiveAsset.class) {
      xml.append(">");
      xml.append("\n");
      formatNode(
        ((ArchiveAsset) node.getAsset()).getArchive().get(ArchivePaths.root()),
        xml);
      xml.append("</asset>").append("\n");
    } else {
      xml.append("/>").append("\n");
    }
  } else {
    xml.append("\t<asset type=\"Directory\" path=\"").append(node.getPath().get()).append("\"/>\n");
  }
  for (Node child : node.getChildren()) {
    formatNode(child, xml);
  }
}

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

private static boolean isJAXRS(ArchivePath path, Asset asset) {
  if (asset == null) {
    return false;
  }
  if (asset instanceof ArchiveAsset) {
    return isJAXRS(((ArchiveAsset) asset).getArchive());
  }
  if (!path.get().endsWith(".class")) {
    return false;
  }
  try (InputStream in = asset.openStream()) {
    ClassReader reader = new ClassReader(in);
    JAXRSAnnotationSeekingClassVisitor visitor = new JAXRSAnnotationSeekingClassVisitor();
    reader.accept(visitor, 0);
    return visitor.isFound();
  } catch (IOException ignored) {
  }
  return false;
}

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

static boolean hasApplicationPathAnnotation(ArchivePath path, Asset asset) {
  if (asset == null) {
    return false;
  }
  if (asset instanceof ArchiveAsset) {
    return hasApplicationPathAnnotation(((ArchiveAsset) asset).getArchive());
  }
  if (!path.get().endsWith(".class")) {
    return false;
  }
  try (InputStream in = asset.openStream()) {
    ClassReader reader = new ClassReader(in);
    ApplicationPathAnnotationSeekingClassVisitor visitor = new ApplicationPathAnnotationSeekingClassVisitor();
    reader.accept(visitor, 0);
    return visitor.isFound();
  } catch (IOException ignored) {
  }
  return false;
}

相关文章

微信公众号

最新文章

更多