/** * {@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(); }
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; }
asset = new ArchiveAsset(fileArchive, ZipExporter.class); JavaArchive jarArchive = (JavaArchive) archiveAsset.getArchive(); scanJarArchive(jarArchive);
/** * 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); }
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);
/** * 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); }
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);
jar.add(new ArchiveAsset(agentJar, ZipExporter.class), BytemanConfiguration.BYTEMAN_JAR); } else {
/** * {@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(); }
/** * {@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); }
/** * 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); }
/** * {@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); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
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); } }
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; }
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; }