private Stream<Node> getLibraryNodes() { final Node libNode = get(getLibraryPath()); return libNode != null ? libNode.getChildren().stream() : Stream.empty(); }
@Override public String format(final Archive<?> archive) throws IllegalArgumentException { // Precondition checks if (archive == null) { throw new IllegalArgumentException("archive must be specified"); } // Start the output with the name of the archive StringBuilder sb = new StringBuilder(archive.getName()).append(FormattingConstants.COLON).append( FormattingConstants.NEWLINE); // format recursively, except the parent Node rootNode = archive.get(ROOT); for (Node child : rootNode.getChildren()) { format(sb, child); } // remove the last NEWLINE sb.deleteCharAt(sb.length() - 1); return sb.toString(); }
private void format(StringBuilder sb, Node node) { sb.append(node.getPath().get()); if (node.getAsset() == null) { sb.append(FormattingConstants.SLASH); } sb.append(FormattingConstants.NEWLINE); for (Node child : node.getChildren()) { format(sb, child); } }
@Override public String format(final Archive<?> archive) throws IllegalArgumentException { // Precondition checks if (archive == null) { throw new IllegalArgumentException("archive must be specified"); } // Start the output with the name of the archive StringBuilder sb = new StringBuilder(archive.getName()).append(FormattingConstants.COLON).append( FormattingConstants.NEWLINE); // format recursively, except the parent Node rootNode = archive.get(ROOT); for (Node child : rootNode.getChildren()) { format(sb, child); } // remove the last NEWLINE sb.deleteCharAt(sb.length() - 1); return sb.toString(); }
private void format(StringBuilder sb, Node node) { sb.append(node.getPath().get()); if (node.getAsset() == null) { sb.append(FormattingConstants.SLASH); } sb.append(FormattingConstants.NEWLINE); for (Node child : node.getChildren()) { format(sb, child); } }
private void unpack(File destination, JavaArchive file) throws IOException { final Node rootDir = file.get("/"); final Set<Node> contractFiles = rootDir.getChildren(); for (Node contractFile : contractFiles) { final String filename = contractFile.getPath().get().substring(1); final Asset asset = contractFile.getAsset(); try (final InputStream in = asset.openStream()) { Files.copy(in, new File(destination, filename).toPath()); } } }
protected void filter(Set<ArchivePath> remove, Node node, ResolvedDependencies resolvedDependencies) { String path = node.getPath().get(); if (path.startsWith("/WEB-INF/lib") && path.endsWith(".jar")) { if (path.contains("thorntail-runner")) { remove.add(node.getPath()); } if (resolvedDependencies.isRemovable(node)) { remove.add(node.getPath()); } } for (Node each : node.getChildren()) { filter(remove, each, resolvedDependencies); } } }
protected void filter(Set<ArchivePath> remove, Node node, ResolvedDependencies resolvedDependencies) { String path = node.getPath().get(); if (path.startsWith("/WEB-INF/lib") && path.endsWith(".jar")) { if (resolvedDependencies.isRemovable(node)) { remove.add(node.getPath()); } } for (Node each : node.getChildren()) { filter(remove, each, resolvedDependencies); } } }
/** * Recursive call to process all the node hierarchy * * @param node */ private void processNode(final Node node) { processNode(node.getPath(), node); Set<Node> children = node.getChildren(); for (Node child : children) { processNode(child); } }
/** * Recursive call to process all the node hierarchy * * @param node */ private void processNode(final Node node) { processNode(node.getPath(), node); Set<Node> children = node.getChildren(); for (Node child : children) { processNode(child); } }
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); } }
/** * Primary method providing a template for exporting the contents of an archive */ protected void doExport() { // Get archive final Archive<?> archive = getArchive(); if (log.isLoggable(Level.FINE)) { log.fine("Exporting archive - " + archive.getName()); } // Obtain the root final Node rootNode = archive.get(ArchivePaths.root()); // Recursively process the root children for (Node child : rootNode.getChildren()) { processNode(child); } }
/** * Primary method providing a template for exporting the contents of an archive */ protected void doExport() { // Get archive final Archive<?> archive = getArchive(); if (log.isLoggable(Level.FINE)) { log.fine("Exporting archive - " + archive.getName()); } // Obtain the root final Node rootNode = archive.get(ArchivePaths.root()); // Recursively process the root children for (Node child : rootNode.getChildren()) { processNode(child); } }
public static void materializeSubdirectories(File entryDirectory, Node node) throws DeploymentException, IOException { for (Node child : node.getChildren()) { if (child.getAsset() == null) { materializeSubdirectories(entryDirectory, child); } else { if (ClassPathDirectory.isMarkerFileArchivePath(child.getPath())) { // Do not materialize the marker file continue; } // E.g. META-INF/my-super-descriptor.xml File resourceFile = new File(entryDirectory, child.getPath().get().replace(DELIMITER_RESOURCE_PATH, File.separatorChar)); File resoureDirectory = resourceFile.getParentFile(); if (!resoureDirectory.exists() && !resoureDirectory.mkdirs()) { throw new DeploymentException("Could not create class path directory: " + entryDirectory); } resourceFile.createNewFile(); try (InputStream in = child.getAsset().openStream(); OutputStream out = new FileOutputStream(resourceFile)) { copy(in, out); } child.getPath().get(); } } }
private int countChildren(final Node node) { int count = 0; for (final Node child : node.getChildren()) { if (child.getAsset() != null) { count++; } count += countChildren(child); } return count; }
/** * 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); } }
protected void handleWebArchive(WebArchive war) { final Node lib = war.get("WEB-INF/lib"); if (lib != null) { final Set<Node> libs = lib.getChildren(); for (Node jar : libs) { if (jar.getPath().get().contains("appengine-api")) return; } } // do not add GAE jar; e.g. CapeDwarf can work off GAE module boolean ignoreGaeJar = Boolean.getBoolean("ignore.gae.jar"); if (ignoreGaeJar == false) { war.addAsLibraries(Maven.resolver() .loadPomFromFile("pom.xml") .resolve("com.google.appengine:appengine-api-1.0-sdk") .withTransitivity() .as(File.class) ); } } }
/** * Explodes kumuluzee-loader library to root of the archive. * * @param javaArchive Archive with all jars in /WEB-INF/lib (war) */ private static void explodeLoaderArchiveToRoot(JavaArchive javaArchive) { for (Node n : javaArchive.get("/WEB-INF/lib").getChildren()) { if (n.getAsset() instanceof ArchiveAsset && ((ArchiveAsset) n.getAsset()).getArchive().getName().startsWith("kumuluzee-loader-")) { Archive<?> dependencyJar = ((ArchiveAsset) n.getAsset()).getArchive(); LOG.fine("Found kumuluzee-loader archive: " + dependencyJar.getName()); javaArchive.merge(dependencyJar); javaArchive.delete(n.getPath()); break; } } }
/** * Explodes archive marked with {@link ApplicationArchiveMarker} to root of the archive. * * @param javaArchive Archive with all jars in /WEB-INF/lib (war) */ private static void explodeAppArchiveToRoot(JavaArchive javaArchive) { for (Node n : javaArchive.get("/WEB-INF/lib").getChildren()) { if (n.getAsset() instanceof ArchiveAsset) { Archive<?> dependencyJar = ((ArchiveAsset) n.getAsset()).getArchive(); if (dependencyJar.contains(ApplicationArchiveMarker.MARKER_FILENAME)) { LOG.fine("Found application archive: " + dependencyJar.getName()); dependencyJar.delete(ApplicationArchiveMarker.MARKER_FILENAME); javaArchive.merge(dependencyJar); javaArchive.delete(n.getPath()); break; } } } }
private static void copyDir(Archive<?> sourceArchive, Archive<?> targetArchive, String source, String target) { Node sourceNode = sourceArchive.get(source); if (sourceNode.getAsset() != null) { targetArchive.add(sourceNode.getAsset(), target); } else { for (Node child : sourceNode.getChildren()) { String childName = child.getPath().get().replaceFirst(child.getPath().getParent().get(), ""); copyDir(sourceArchive, targetArchive, child.getPath().get(), ArchivePaths.create(target, childName).get()); } } } }