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

x33g5p2x  于2022-01-24 转载在 其他  
字(12.8k)|赞(0)|评价(0)|浏览(189)

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

Node介绍

[英]Represents an entry inside an Archive. Indicates an empty directory if Node#getAsset() returns null. May be the parent of child Nodes. Lives inside the Archive under the context denoted by Node#getPath().
[中]表示存档中的条目。如果节点#getAsset()返回null,则指示空目录。可能是子节点的父节点。在节点#getPath()表示的上下文中存在于存档中。

代码示例

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

  1. @Override
  2. public ClassLoader getClassLoader(final JavaArchive jar) throws Exception {
  3. WebArchive war = ShrinkWrap.create(WebArchive.class);
  4. war.setManifest(Thread.currentThread().getContextClassLoader().getResource("META-INF/MANIFEST.MF"));
  5. war.addAsLibrary(jar);
  6. assertTrue(tmp.delete());
  7. war.as(ZipExporter.class).exportTo(tmp);
  8. final byte[] bytes = Utils.readAsBytes(jar.get("foo/A.class").getAsset().openStream());
  9. return new ClassLoader(Thread.currentThread().getContextClassLoader()) {
  10. Class<?> aClass = null;

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

  1. Map<ArchivePath, Node> archiveContents = archive.getContent();
  2. for (Map.Entry<ArchivePath, Node> entry : archiveContents.entrySet()) {
  3. ArchivePath path = entry.getKey();
  4. Node n = entry.getValue();
  5. Path f = subpath(deployDir, path.get());
  6. if (n.getAsset() == null) {
  7. Files.copy(n.getAsset().openStream(), f, StandardCopyOption.REPLACE_EXISTING);
  8. String p = n.getPath().get();
  9. if (callback != null) {
  10. callback.accept(p);

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

  1. @Override
  2. public Manifest getManifest() throws IOException
  3. {
  4. ArchivePath manifestPath = ArchivePaths.create("META-INF/MANIFEST.MF");
  5. final Archive<?> archive = this.getArchive();
  6. if (archive.contains(manifestPath))
  7. {
  8. return new Manifest(archive.get(manifestPath).getAsset().openStream());
  9. }
  10. return null;
  11. }

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

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

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

  1. /**
  2. * Ensure an asset can be retrieved by a string path
  3. *
  4. * @throws Exception
  5. */
  6. @Test
  7. public void testGetAssetWithString() throws Exception {
  8. Archive<T> archive = getArchive();
  9. ArchivePath location = new BasicPath("/", "test.properties");
  10. Asset asset = new ClassLoaderAsset(NAME_TEST_PROPERTIES);
  11. archive.add(asset, location);
  12. Node fetchedNode = archive.get(location.get());
  13. Assert.assertTrue("Asset should be returned from path: " + location.get(),
  14. compareAssets(asset, fetchedNode.getAsset()));
  15. }

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

  1. public static Manifest getManifest(Archive<?> archive) {
  2. try {
  3. Node node = archive.get(JarFile.MANIFEST_NAME);
  4. if (node != null && node.getAsset() != null) {
  5. return new Manifest(node.getAsset().openStream());
  6. }
  7. } catch (Exception ex) {
  8. throw new IllegalStateException("Cannot obtain manifest", ex);
  9. }
  10. return null;
  11. }

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

  1. private static InputStream getKeycloakJsonFromClasspath(String resourceName) {
  2. InputStream keycloakJson = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
  3. if (keycloakJson == null) {
  4. String appArtifact = System.getProperty(BootstrapProperties.APP_ARTIFACT);
  5. if (appArtifact != null) {
  6. try (InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream("_bootstrap/" + appArtifact)) {
  7. Archive<?> tmpArchive = ShrinkWrap.create(JARArchive.class);
  8. tmpArchive.as(ZipImporter.class).importFrom(in);
  9. Node jsonNode = tmpArchive.get(resourceName);
  10. if (jsonNode == null) {
  11. jsonNode = getKeycloakJsonNodeFromWebInf(tmpArchive, resourceName, true);
  12. }
  13. if (jsonNode == null) {
  14. jsonNode = getKeycloakJsonNodeFromWebInf(tmpArchive, resourceName, false);
  15. }
  16. if (jsonNode != null && jsonNode.getAsset() != null) {
  17. keycloakJson = jsonNode.getAsset().openStream();
  18. }
  19. } catch (IOException e) {
  20. // ignore
  21. }
  22. }
  23. }
  24. return keycloakJson;
  25. }

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

  1. private void format(StringBuilder sb, Node node) {
  2. sb.append(node.getPath().get());
  3. if (node.getAsset() == null) {
  4. sb.append(FormattingConstants.SLASH);
  5. }
  6. sb.append(FormattingConstants.NEWLINE);
  7. for (Node child : node.getChildren()) {
  8. format(sb, child);
  9. }
  10. }

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

  1. @Test
  2. public void shouldMoveDirectory() {
  3. final Archive<JavaArchive> archive = ShrinkWrap.create(JavaArchive.class, "archive.jar");
  4. final String sourcePath = "path1";
  5. final String targetPath = "path2";
  6. archive.addAsDirectory(sourcePath);
  7. archive.move(sourcePath, targetPath);
  8. Assert.assertTrue("Directory should be at the new path", archive.get(targetPath).getAsset() == null);
  9. }

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

  1. /**
  2. * Converts {@link ArchiveAsset}s in parentDir to {@link ByteArrayAsset}s.
  3. * <p>
  4. * By default {@link org.jboss.shrinkwrap.api.exporter.ExplodedExporter} exports {@link ArchiveAsset}s in parent
  5. * archive as exploded directories. Since we need to export them as archives, we convert them to
  6. * {@link ByteArrayAsset}s.
  7. *
  8. * @param a Archive to fix
  9. * @param parentDir Directory to scan for {@link ArchiveAsset}s
  10. */
  11. private static void fixArchiveAssets(Archive<?> a, String parentDir) {
  12. Node n = a.get(parentDir);
  13. Archive<?> tmp = ShrinkWrap.create(JavaArchive.class);
  14. List<ArchivePath> pathsToDelete = new ArrayList<>();
  15. for (Node child : n.getChildren()) {
  16. Asset childAsset = child.getAsset();
  17. if (childAsset instanceof ArchiveAsset && child.getPath().get().endsWith(".jar")) {
  18. LOG.fine("Converting archive " + child.getPath().get() + " to ByteArrayAsset");
  19. ArchiveAsset archiveAsset = (ArchiveAsset) childAsset;
  20. ByteArrayAsset bas = new ByteArrayAsset(archiveAsset.openStream());
  21. pathsToDelete.add(child.getPath());
  22. tmp.add(bas, child.getPath());
  23. }
  24. }
  25. for (ArchivePath ap : pathsToDelete) {
  26. a.delete(ap);
  27. }
  28. a.merge(tmp);
  29. }

代码示例来源:origin: wildfly-swarm-archive/ARCHIVE-wildfly-swarm

  1. protected List<Properties> extractPomProperties(final Node node) {
  2. final List<Properties> properties = new ArrayList<>();
  3. try (final InputStream in = node.getAsset().openStream()) {
  4. ShrinkWrap.create(ZipImporter.class)
  5. .importFrom(in)
  6. .as(JavaArchive.class)
  7. .getContent(p -> POM_PROPERTIES.matcher(p.get()).matches())
  8. .values()
  9. .forEach(propNode -> {
  10. final Properties props = new Properties();
  11. try (final InputStream in2 = propNode.getAsset().openStream()) {
  12. props.load(in2);
  13. } catch (IOException e) {
  14. throw new RuntimeException(e);
  15. }
  16. properties.add(props);
  17. });
  18. } catch (IOException e) {
  19. throw new RuntimeException(e);
  20. }
  21. return properties;
  22. }

代码示例来源:origin: org.jboss.as/jboss-as-testsuite-shared

  1. public static EnterpriseArchive createSsoEar() {
  2. ClassLoader tccl = Thread.currentThread().getContextClassLoader();
  3. String resourcesLocation = "org/jboss/as/test/integration/web/sso/resources/";
  4. WebArchive war1 = createSsoWar("sso-form-auth1.war");
  5. WebArchive war2 = createSsoWar("sso-form-auth2.war");
  6. WebArchive war3 = createSsoWar("sso-with-no-auth.war");
  7. // Remove jboss-web.xml so the war will not have an authenticator
  8. war3.delete(war3.get("WEB-INF/jboss-web.xml").getPath());
  9. JavaArchive webEjbs = ShrinkWrap.create(JavaArchive.class, "jbosstest-web-ejbs.jar");
  10. webEjbs.addAsManifestResource(tccl.getResource(resourcesLocation + "ejb-jar.xml"), "ejb-jar.xml");
  11. webEjbs.addAsManifestResource(tccl.getResource(resourcesLocation + "jboss.xml"), "jboss.xml");
  12. webEjbs.addPackage(StatelessSession.class.getPackage());
  13. EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "web-sso.ear");
  14. ear.setApplicationXML(tccl.getResource(resourcesLocation + "application.xml"));
  15. ear.addAsModule(war1);
  16. ear.addAsModule(war2);
  17. ear.addAsModule(war3);
  18. ear.addAsModule(webEjbs);
  19. return ear;
  20. }

代码示例来源:origin: org.juzu/juzu-core

  1. public static WebArchive createDeployment(String packageName) throws IOException {
  2. WebArchive war = createPortletDeployment(packageName);
  3. Node node = war.get("WEB-INF/portlet.xml");
  4. ArchivePath path = node.getPath();
  5. String s = Tools.read(node.getAsset().openStream(), Tools.UTF_8);
  6. s = s.replace("<portlet-info>", "<resource-bundle>bundle</resource-bundle>" + "<portlet-info>");
  7. war.delete(path);
  8. war.add(new StringAsset(s), path);
  9. war.addAsResource(new StringAsset("abc=def"), "bundle_fr_FR.properties");
  10. return war;
  11. }

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

  1. @Override
  2. public Enumeration<String> entries()
  3. {
  4. List<String> entries = new ArrayList<String>();
  5. for (Entry<ArchivePath, Node> entry : this.getArchive().getContent().entrySet())
  6. {
  7. if (entry.getValue().getAsset() != null)
  8. {
  9. entries.add(entry.getKey().get());
  10. }
  11. }
  12. return Collections.enumeration(entries);
  13. }

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

  1. @Override
  2. public String format(final Archive<?> archive) throws IllegalArgumentException {
  3. // Precondition checks
  4. if (archive == null) {
  5. throw new IllegalArgumentException("archive must be specified");
  6. }
  7. // Start the output with the name of the archive
  8. StringBuilder sb = new StringBuilder(archive.getName()).append(FormattingConstants.COLON).append(
  9. FormattingConstants.NEWLINE);
  10. // format recursively, except the parent
  11. Node rootNode = archive.get(ROOT);
  12. for (Node child : rootNode.getChildren()) {
  13. format(sb, child);
  14. }
  15. // remove the last NEWLINE
  16. sb.deleteCharAt(sb.length() - 1);
  17. return sb.toString();
  18. }

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

  1. @Override
  2. public void undeploy(Archive<?> archive) throws DeploymentException {
  3. try {
  4. Manifest manifest = new Manifest(archive.get("/META-INF/MANIFEST.MF").getAsset().openStream());
  5. OSGiMetaData metadata = OSGiMetaDataBuilder.load(manifest);
  6. undeploy(metadata.getBundleSymbolicName());
  7. }
  8. catch (IOException e) {
  9. throw new DeploymentException("Cannot undeploy: " + archive.getName(), e);
  10. }
  11. }

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

  1. @Override
  2. public InputStream getInputStream() throws IOException
  3. {
  4. ArchivePath path = convertToArchivePath(u);
  5. Node node = archive.get(prefix + path.get());
  6. if (node == null && !prefix.isEmpty())
  7. { // WEB-INF/lib/x.jar!*
  8. node = archive.get(path);
  9. }
  10. // SHRINKWRAP-308
  11. if (node == null)
  12. {
  13. throw new FileNotFoundException("Requested path: " + path + " does not exist in " + archive.toString());
  14. }
  15. Asset asset = node.getAsset();
  16. if (asset == null)
  17. {
  18. return null;
  19. }
  20. InputStream input = asset.openStream();
  21. synchronized (this)
  22. {
  23. openedStreams.add(input);
  24. }
  25. return input;
  26. }

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

  1. private static void copyDir(Archive<?> sourceArchive, Archive<?> targetArchive, String source, String target) {
  2. Node sourceNode = sourceArchive.get(source);
  3. if (sourceNode.getAsset() != null) {
  4. targetArchive.add(sourceNode.getAsset(), target);
  5. } else {
  6. for (Node child : sourceNode.getChildren()) {
  7. String childName = child.getPath().get().replaceFirst(child.getPath().getParent().get(), "");
  8. copyDir(sourceArchive, targetArchive,
  9. child.getPath().get(), ArchivePaths.create(target, childName).get());
  10. }
  11. }
  12. }
  13. }

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

  1. /**
  2. * Explodes archive marked with {@link ApplicationArchiveMarker} to root of the archive.
  3. *
  4. * @param javaArchive Archive with all jars in /WEB-INF/lib (war)
  5. */
  6. private static void explodeAppArchiveToRoot(JavaArchive javaArchive) {
  7. for (Node n : javaArchive.get("/WEB-INF/lib").getChildren()) {
  8. if (n.getAsset() instanceof ArchiveAsset) {
  9. Archive<?> dependencyJar = ((ArchiveAsset) n.getAsset()).getArchive();
  10. if (dependencyJar.contains(ApplicationArchiveMarker.MARKER_FILENAME)) {
  11. LOG.fine("Found application archive: " + dependencyJar.getName());
  12. dependencyJar.delete(ApplicationArchiveMarker.MARKER_FILENAME);
  13. javaArchive.merge(dependencyJar);
  14. javaArchive.delete(n.getPath());
  15. break;
  16. }
  17. }
  18. }
  19. }

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

  1. @Test
  2. public void move() throws IOException {
  3. final String source = "path";
  4. final String contents = "contents";
  5. this.getArchive().add(new StringAsset(contents), source);
  6. final String dest = "newPath";
  7. final Path src = fs.getPath(source);
  8. final Path dst = fs.getPath(dest);
  9. final Path moved = Files.move(src, dst);
  10. Assert.assertEquals(dest, moved.toString());
  11. final String roundtrip = new BufferedReader(new InputStreamReader(this.getArchive().get(dest).getAsset()
  12. .openStream())).readLine();
  13. Assert.assertEquals("Contents not as expected after move", contents, roundtrip);
  14. }

相关文章