Java Code Examples for org.jboss.shrinkwrap.api.Archive#getContent()
The following examples show how to use
org.jboss.shrinkwrap.api.Archive#getContent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DependencyManagerTest.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 6 votes |
@Test public void populateUberJarMavenRepository() throws Exception { manager.addDependency(BOOTSTRAP_JAR); manager.addDependency(BOOTSTRAP_CONF); manager.addDependency(MODULES_EMPTY_A); manager.addDependency(MODULES_A); manager.analyzeDependencies(false); Archive archive = ShrinkWrap.create(JavaArchive.class); manager.populateUberJarMavenRepository(archive); Map<ArchivePath, Node> content = archive.getContent(); List<String> jars = content.keySet().stream().map(ArchivePath::get).filter((e) -> e.endsWith(".jar")).collect(Collectors.toList()); assertThat(jars).hasSize(5); assertThat(jars).contains("/m2repo/" + MODULES_EMPTY_A.repoPath(true)); assertThat(jars).contains("/m2repo/" + BOOTSTRAP_CONF.repoPath(true)); assertThat(jars).contains("/m2repo/" + MODULES_A.repoPath(true)); assertThat(jars).contains("/m2repo/" + CXF.repoPath(true)); assertThat(jars).contains("/m2repo/" + WS_INTEGRATION.repoPath(true)); }
Example 2
Source File: ArchiveResourceIteratorFactory.java From tomee with Apache License 2.0 | 6 votes |
private Collection<Resource> findResources(final String path, final String suffix) { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final Collection<Resource> resources = new ArrayList<Resource>(); if (SWClassLoader.class.isInstance(loader)) { final Collection<Archive<?>> archives = SWClassLoader.class.cast(loader).getArchives(); final ClassLoader parent = loader.getParent(); for (final Archive<?> archive : archives) { final Map<ArchivePath, Node> content = archive.getContent(new Filter<ArchivePath>() { @Override public boolean include(final ArchivePath object) { final String currentPath = classloaderPath(object); return !(parent != null && parent.getResource(currentPath) != null) && currentPath.startsWith('/' + path) && currentPath.endsWith(suffix); } }); for (final Map.Entry<ArchivePath, Node> entry : content.entrySet()) { resources.add(new SWResource(entry.getKey(), entry.getValue())); } } } return resources; }
Example 3
Source File: ArchiveUtil.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * Indexes the given archive. * * @param config * @param indexer * @param archive */ private static void indexArchive(OpenApiConfig config, Indexer indexer, Archive<?> archive) { FilteredIndexView filter = new FilteredIndexView(null, config); Map<ArchivePath, Node> c = archive.getContent(); try { for (Map.Entry<ArchivePath, Node> each : c.entrySet()) { ArchivePath archivePath = each.getKey(); if (archivePath.get().endsWith(OpenApiConstants.CLASS_SUFFIX) && acceptClassForScanning(filter, archivePath.get())) { try (InputStream contentStream = each.getValue().getAsset().openStream()) { TckLogging.log.indexing(archivePath.get(), archive.getName()); indexer.index(contentStream); } continue; } if (archivePath.get().endsWith(OpenApiConstants.JAR_SUFFIX) && acceptJarForScanning(config, archivePath.get())) { try (InputStream contentStream = each.getValue().getAsset().openStream()) { JavaArchive jarArchive = ShrinkWrap.create(JavaArchive.class, archivePath.get()) .as(ZipImporter.class).importFrom(contentStream).as(JavaArchive.class); indexArchive(config, indexer, jarArchive); } continue; } } } catch (IOException e) { throw new RuntimeException(e); } }
Example 4
Source File: JAXRSArchiveImpl.java From thorntail with Apache License 2.0 | 5 votes |
public static boolean isJAXRS(Archive<?> archive) { Map<ArchivePath, Node> content = archive.getContent(); for (Map.Entry<ArchivePath, Node> entry : content.entrySet()) { Node node = entry.getValue(); Asset asset = node.getAsset(); if (isJAXRS(node.getPath(), asset)) { return true; } } return false; }
Example 5
Source File: DefaultApplicationDeploymentProcessor.java From thorntail with Apache License 2.0 | 5 votes |
private static boolean hasApplicationPathAnnotation(Archive<?> archive) { Map<ArchivePath, Node> content = archive.getContent(); for (Map.Entry<ArchivePath, Node> entry : content.entrySet()) { Node node = entry.getValue(); Asset asset = node.getAsset(); if (hasApplicationPathAnnotation(node.getPath(), asset)) { return true; } } return false; }
Example 6
Source File: AdvertisingMetadataProcessorTest.java From thorntail with Apache License 2.0 | 5 votes |
Index createIndex(Archive<?> archive) throws IOException { Indexer indexer = new Indexer(); Map<ArchivePath, Node> c = archive.getContent(); for (Map.Entry<ArchivePath, Node> each : c.entrySet()) { if (each.getKey().get().endsWith(".class")) { indexer.index(each.getValue().getAsset().openStream()); } } return indexer.complete(); }
Example 7
Source File: DependencyManagerTest.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
@Test public void populateUberJarMavenRepositoryAvoidingProvided() throws Exception { manager.addDependency(BOOTSTRAP_JAR); manager.addDependency(BOOTSTRAP_CONF); manager.addDependency(MODULES_EMPTY_A); manager.addDependency(MODULES_A); manager.addDependency(PROVIDED_A); manager.addDependency(COM_SUN_MAIL); manager.analyzeDependencies(false); assertThat(manager.getProvidedGAVs()).contains("com.sun.mail:javax.mail"); Archive archive = ShrinkWrap.create(JavaArchive.class); manager.populateUberJarMavenRepository(archive); Map<ArchivePath, Node> content = archive.getContent(); List<String> jars = content.keySet().stream().map(ArchivePath::get).filter((e) -> e.endsWith(".jar")).collect(Collectors.toList()); assertThat(jars).hasSize(6); assertThat(jars).contains("/m2repo/" + MODULES_EMPTY_A.repoPath(true)); assertThat(jars).contains("/m2repo/" + BOOTSTRAP_CONF.repoPath(true)); assertThat(jars).contains("/m2repo/" + MODULES_A.repoPath(true)); assertThat(jars).contains("/m2repo/" + CXF.repoPath(true)); assertThat(jars).contains("/m2repo/" + WS_INTEGRATION.repoPath(true)); assertThat(jars).contains("/m2repo/" + PROVIDED_A.repoPath(true)); }
Example 8
Source File: UndertowDeployerHelper.java From keycloak with Apache License 2.0 | 5 votes |
private void addAnnotatedServlets(DeploymentInfo di, Archive<?> archive) { Map<ArchivePath, Node> classNodes = archive.getContent((ArchivePath path) -> { String stringPath = path.get(); return (stringPath.startsWith("/WEB-INF/classes") && stringPath.endsWith("class")); }); for (Map.Entry<ArchivePath, Node> entry : classNodes.entrySet()) { Node n = entry.getValue(); if (n.getAsset() instanceof ClassAsset) { ClassAsset classAsset = (ClassAsset) n.getAsset(); Class<?> clazz = classAsset.getSource(); WebServlet annotation = clazz.getAnnotation(WebServlet.class); if (annotation != null) { ServletInfo undertowServlet = new ServletInfo(clazz.getSimpleName(), (Class<? extends Servlet>) clazz); String[] mappings = annotation.value(); if (mappings != null) { for (String urlPattern : mappings) { undertowServlet.addMapping(urlPattern); } } di.addServlet(undertowServlet); } } } }