本文整理了Java中org.jboss.shrinkwrap.api.Node
类的一些代码示例,展示了Node
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node
类的具体详情如下:
包路径:org.jboss.shrinkwrap.api.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
@Override
public ClassLoader getClassLoader(final JavaArchive jar) throws Exception {
WebArchive war = ShrinkWrap.create(WebArchive.class);
war.setManifest(Thread.currentThread().getContextClassLoader().getResource("META-INF/MANIFEST.MF"));
war.addAsLibrary(jar);
assertTrue(tmp.delete());
war.as(ZipExporter.class).exportTo(tmp);
final byte[] bytes = Utils.readAsBytes(jar.get("foo/A.class").getAsset().openStream());
return new ClassLoader(Thread.currentThread().getContextClassLoader()) {
Class<?> aClass = null;
代码示例来源: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.copy(n.getAsset().openStream(), f, StandardCopyOption.REPLACE_EXISTING);
String p = n.getPath().get();
if (callback != null) {
callback.accept(p);
代码示例来源:origin: org.jboss.shrinkwrap/shrinkwrap-extension-glassfish
@Override
public Manifest getManifest() throws IOException
{
ArchivePath manifestPath = ArchivePaths.create("META-INF/MANIFEST.MF");
final Archive<?> archive = this.getArchive();
if (archive.contains(manifestPath))
{
return new Manifest(archive.get(manifestPath).getAsset().openStream());
}
return null;
}
代码示例来源: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
/**
* Ensure an asset can be retrieved by a string path
*
* @throws Exception
*/
@Test
public void testGetAssetWithString() throws Exception {
Archive<T> archive = getArchive();
ArchivePath location = new BasicPath("/", "test.properties");
Asset asset = new ClassLoaderAsset(NAME_TEST_PROPERTIES);
archive.add(asset, location);
Node fetchedNode = archive.get(location.get());
Assert.assertTrue("Asset should be returned from path: " + location.get(),
compareAssets(asset, fetchedNode.getAsset()));
}
代码示例来源:origin: org.wildfly/wildfly-arquillian-common
public static Manifest getManifest(Archive<?> archive) {
try {
Node node = archive.get(JarFile.MANIFEST_NAME);
if (node != null && node.getAsset() != null) {
return new Manifest(node.getAsset().openStream());
}
} catch (Exception ex) {
throw new IllegalStateException("Cannot obtain manifest", ex);
}
return null;
}
代码示例来源:origin: io.thorntail/keycloak
private static InputStream getKeycloakJsonFromClasspath(String resourceName) {
InputStream keycloakJson = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
if (keycloakJson == null) {
String appArtifact = System.getProperty(BootstrapProperties.APP_ARTIFACT);
if (appArtifact != null) {
try (InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream("_bootstrap/" + appArtifact)) {
Archive<?> tmpArchive = ShrinkWrap.create(JARArchive.class);
tmpArchive.as(ZipImporter.class).importFrom(in);
Node jsonNode = tmpArchive.get(resourceName);
if (jsonNode == null) {
jsonNode = getKeycloakJsonNodeFromWebInf(tmpArchive, resourceName, true);
}
if (jsonNode == null) {
jsonNode = getKeycloakJsonNodeFromWebInf(tmpArchive, resourceName, false);
}
if (jsonNode != null && jsonNode.getAsset() != null) {
keycloakJson = jsonNode.getAsset().openStream();
}
} catch (IOException e) {
// ignore
}
}
}
return keycloakJson;
}
代码示例来源:origin: org.jboss.shrinkwrap/shrinkwrap-api
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);
}
}
代码示例来源:origin: shrinkwrap/shrinkwrap
@Test
public void shouldMoveDirectory() {
final Archive<JavaArchive> archive = ShrinkWrap.create(JavaArchive.class, "archive.jar");
final String sourcePath = "path1";
final String targetPath = "path2";
archive.addAsDirectory(sourcePath);
archive.move(sourcePath, targetPath);
Assert.assertTrue("Directory should be at the new path", archive.get(targetPath).getAsset() == null);
}
代码示例来源: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: wildfly-swarm-archive/ARCHIVE-wildfly-swarm
protected List<Properties> extractPomProperties(final Node node) {
final List<Properties> properties = new ArrayList<>();
try (final InputStream in = node.getAsset().openStream()) {
ShrinkWrap.create(ZipImporter.class)
.importFrom(in)
.as(JavaArchive.class)
.getContent(p -> POM_PROPERTIES.matcher(p.get()).matches())
.values()
.forEach(propNode -> {
final Properties props = new Properties();
try (final InputStream in2 = propNode.getAsset().openStream()) {
props.load(in2);
} catch (IOException e) {
throw new RuntimeException(e);
}
properties.add(props);
});
} catch (IOException e) {
throw new RuntimeException(e);
}
return properties;
}
代码示例来源:origin: org.jboss.as/jboss-as-testsuite-shared
public static EnterpriseArchive createSsoEar() {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
String resourcesLocation = "org/jboss/as/test/integration/web/sso/resources/";
WebArchive war1 = createSsoWar("sso-form-auth1.war");
WebArchive war2 = createSsoWar("sso-form-auth2.war");
WebArchive war3 = createSsoWar("sso-with-no-auth.war");
// Remove jboss-web.xml so the war will not have an authenticator
war3.delete(war3.get("WEB-INF/jboss-web.xml").getPath());
JavaArchive webEjbs = ShrinkWrap.create(JavaArchive.class, "jbosstest-web-ejbs.jar");
webEjbs.addAsManifestResource(tccl.getResource(resourcesLocation + "ejb-jar.xml"), "ejb-jar.xml");
webEjbs.addAsManifestResource(tccl.getResource(resourcesLocation + "jboss.xml"), "jboss.xml");
webEjbs.addPackage(StatelessSession.class.getPackage());
EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "web-sso.ear");
ear.setApplicationXML(tccl.getResource(resourcesLocation + "application.xml"));
ear.addAsModule(war1);
ear.addAsModule(war2);
ear.addAsModule(war3);
ear.addAsModule(webEjbs);
return ear;
}
代码示例来源:origin: org.juzu/juzu-core
public static WebArchive createDeployment(String packageName) throws IOException {
WebArchive war = createPortletDeployment(packageName);
Node node = war.get("WEB-INF/portlet.xml");
ArchivePath path = node.getPath();
String s = Tools.read(node.getAsset().openStream(), Tools.UTF_8);
s = s.replace("<portlet-info>", "<resource-bundle>bundle</resource-bundle>" + "<portlet-info>");
war.delete(path);
war.add(new StringAsset(s), path);
war.addAsResource(new StringAsset("abc=def"), "bundle_fr_FR.properties");
return war;
}
代码示例来源:origin: org.jboss.shrinkwrap/shrinkwrap-extension-glassfish
@Override
public Enumeration<String> entries()
{
List<String> entries = new ArrayList<String>();
for (Entry<ArchivePath, Node> entry : this.getArchive().getContent().entrySet())
{
if (entry.getValue().getAsset() != null)
{
entries.add(entry.getKey().get());
}
}
return Collections.enumeration(entries);
}
代码示例来源:origin: org.jboss.shrinkwrap/shrinkwrap-api
@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();
}
代码示例来源:origin: org.jboss.arquillian.container/arquillian-container-osgi
@Override
public void undeploy(Archive<?> archive) throws DeploymentException {
try {
Manifest manifest = new Manifest(archive.get("/META-INF/MANIFEST.MF").getAsset().openStream());
OSGiMetaData metadata = OSGiMetaDataBuilder.load(manifest);
undeploy(metadata.getBundleSymbolicName());
}
catch (IOException e) {
throw new DeploymentException("Cannot undeploy: " + archive.getName(), e);
}
}
代码示例来源:origin: org.apache.openwebbeans.arquillian/owb-arquillian-standalone
@Override
public InputStream getInputStream() throws IOException
{
ArchivePath path = convertToArchivePath(u);
Node node = archive.get(prefix + path.get());
if (node == null && !prefix.isEmpty())
{ // WEB-INF/lib/x.jar!*
node = archive.get(path);
}
// SHRINKWRAP-308
if (node == null)
{
throw new FileNotFoundException("Requested path: " + path + " does not exist in " + archive.toString());
}
Asset asset = node.getAsset();
if (asset == null)
{
return null;
}
InputStream input = asset.openStream();
synchronized (this)
{
openedStreams.add(input);
}
return input;
}
代码示例来源:origin: com.kumuluz.ee.testing/kumuluzee-arquillian-container
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());
}
}
}
}
代码示例来源:origin: com.kumuluz.ee.testing/kumuluzee-arquillian-container
/**
* 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;
}
}
}
}
代码示例来源:origin: shrinkwrap/shrinkwrap
@Test
public void move() throws IOException {
final String source = "path";
final String contents = "contents";
this.getArchive().add(new StringAsset(contents), 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());
final String roundtrip = new BufferedReader(new InputStreamReader(this.getArchive().get(dest).getAsset()
.openStream())).readLine();
Assert.assertEquals("Contents not as expected after move", contents, roundtrip);
}
内容来源于网络,如有侵权,请联系作者删除!