Java Code Examples for org.jboss.shrinkwrap.api.Archive#getName()
The following examples show how to use
org.jboss.shrinkwrap.api.Archive#getName() .
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: EAP6DeploymentArchiveProcessor.java From keycloak with Apache License 2.0 | 6 votes |
private void modifyWebXML(Archive<?> archive, TestClass testClass) { if (!archive.contains(DeploymentArchiveProcessorUtils.WEBXML_PATH)) return; if (testClass.getJavaClass().isAnnotationPresent(UseServletFilter.class) && archive.contains(DeploymentArchiveProcessorUtils.JBOSS_DEPLOYMENT_XML_PATH)) { log.debug("Modifying WEB.XML in " + archive.getName() + " for Servlet Filter."); DeploymentArchiveProcessorUtils.modifyWebXMLForServletFilter(archive, testClass); DeploymentArchiveProcessorUtils.addFilterDependencies(archive, testClass); } try { Document webXmlDoc = IOUtil.loadXML(archive.get(DeploymentArchiveProcessorUtils.WEBXML_PATH).getAsset().openStream()); IOUtil.modifyDocElementValue(webXmlDoc, "param-value", ".*infinispan\\.InfinispanSessionCacheIdMapperUpdater", "org.keycloak.adapters.saml.jbossweb.infinispan.InfinispanSessionCacheIdMapperUpdater"); archive.add(new StringAsset((IOUtil.documentToString(webXmlDoc))), WEBXML_PATH); } catch (IllegalArgumentException ex) { throw new RuntimeException("Error when processing " + archive.getName(), ex); } }
Example 2
Source File: Tomcat7DeploymentArchiveProcessor.java From keycloak with Apache License 2.0 | 6 votes |
@Override public void process(Archive<?> archive, TestClass testClass) { super.process(archive, testClass); if (DeploymentArchiveProcessorUtils.checkRunOnServerDeployment(archive)) return; Set<Class<?>> configClasses = TomcatDeploymentArchiveProcessorUtils.getApplicationConfigClasses(archive); if (!configClasses.isEmpty()) { // Tomcat 7 doesn't work with resteasy-servlet-initializer therefore we need to configure Tomcat the old way // jax-rs docs: http://docs.jboss.org/resteasy/docs/3.6.1.Final/userguide/html_single/#d4e161 Document webXmlDoc; try { webXmlDoc = IOUtil.loadXML( archive.get(WEBXML_PATH).getAsset().openStream()); } catch (Exception ex) { throw new RuntimeException("Error when processing " + archive.getName(), ex); } addContextParam(webXmlDoc); addServlet(webXmlDoc, configClasses.iterator().next().getName()); addServletMapping(webXmlDoc); archive.add(new StringAsset((documentToString(webXmlDoc))), DeploymentArchiveProcessorUtils.WEBXML_PATH); } }
Example 3
Source File: FullReplaceUndeployTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private void testDeployment(final Archive<?> archive) throws IOException { final ModelControllerClient client = domainMasterLifecycleUtil.getDomainClient(); final ModelNode readServerSubsystems = Operations.createOperation(ClientConstants.READ_CHILDREN_NAMES_OPERATION, Operations.createAddress("host", "master", "server", "main-one")); readServerSubsystems.get(ClientConstants.CHILD_TYPE).set(ClientConstants.SUBSYSTEM); final String name = archive.getName(); // Deploy the archive execute(client, createDeployAddOperation(archive.as(ZipExporter.class).exportAsInputStream(), name, null)); Assert.assertTrue("Deployment " + name + " was not deployed.", hasDeployment(client, name)); // Validate the subsystem child names on a server ModelNode result = execute(client, readServerSubsystems); validateSubsystemModel("/host=master/server=main-one", result); // Fully replace the deployment, but with the 'enabled' flag set to false, triggering undeploy final Operation fullReplaceOp = createReplaceAndDisableOperation(archive.as(ZipExporter.class).exportAsInputStream(), name, null); execute(client, fullReplaceOp); // Below validates that WFCORE-1577 is fixed, the model should not be missing on the /host=master/server=main-one or main-two // Validate the subsystem child names result = execute(client, readServerSubsystems); validateSubsystemModel("/host=master/server=main-one", result); }
Example 4
Source File: ShrinkWrapUtil.java From furnace with Eclipse Public License 1.0 | 6 votes |
/** * Creates a tmp folder and exports the file. Returns the URL for that file location. * * @param archive Archive to export * @return */ public static URL toURL(final Archive<?> archive) { // create a random named temp file, then delete and use it as a directory try { File root = File.createTempFile("arquillian", archive.getName()); root.delete(); root.mkdirs(); File deployment = new File(root, archive.getName()); deployment.deleteOnExit(); archive.as(ZipExporter.class).exportTo(deployment, true); return deployment.toURI().toURL(); } catch (Exception e) { throw new RuntimeException("Could not export deployment to temp", e); } }
Example 5
Source File: SWClassLoader.java From tomee with Apache License 2.0 | 6 votes |
public URL getWebResource(final String name) { for (final Archive<?> a : archives) { if (!WebArchive.class.isInstance(a)) { continue; } final Node node = a.get(name); if (node != null) { try { return new URL(null, "archive:" + a.getName() + (!name.startsWith("/") ? "/" : "") + name, new ArchiveStreamHandler()); } catch (final MalformedURLException e) { // no-op } } } return null; }
Example 6
Source File: SWClassLoader.java From tomee with Apache License 2.0 | 5 votes |
@Override protected URL findResource(final String name) { final LinkedList<Archive<?>> node = findNodes(name); if (!node.isEmpty()) { final Archive<?> i = node.getLast(); try { return new URL(null, "archive:" + i.getName() + (!name.startsWith("/") ? "/" : "") + name, new ArchiveStreamHandler()); } catch (final MalformedURLException e) { throw new IllegalArgumentException(e); } } return super.findResource(name); }
Example 7
Source File: TomcatDeploymentArchiveProcessorUtils.java From keycloak with Apache License 2.0 | 5 votes |
public static void removeServletConfigurationInWebXML(Archive<?> archive) { if (!archive.contains(DeploymentArchiveProcessorUtils.WEBXML_PATH)) return; try { Document webXmlDoc = loadXML(archive.get(DeploymentArchiveProcessorUtils.WEBXML_PATH).getAsset().openStream()); LOG.debug("Removing web.xml servlet configuration for " + archive.getName()); removeElementFromDoc(webXmlDoc, "web-app/servlet"); removeElementFromDoc(webXmlDoc, "web-app/servlet-mapping"); archive.add(new StringAsset((documentToString(webXmlDoc))), DeploymentArchiveProcessorUtils.WEBXML_PATH); } catch (IllegalArgumentException ex) { throw new RuntimeException("Error when processing " + archive.getName(), ex); } }
Example 8
Source File: TomcatDeploymentArchiveProcessorUtils.java From keycloak with Apache License 2.0 | 5 votes |
public static void replaceKEYCLOAKMethodWithBASIC(Archive<?> archive) { if (!archive.contains(DeploymentArchiveProcessorUtils.WEBXML_PATH)) return; try { Document webXmlDoc = loadXML(archive.get(DeploymentArchiveProcessorUtils.WEBXML_PATH).getAsset().openStream()); LOG.debug("Setting BASIC as auth-method in WEB.XML for " + archive.getName()); modifyDocElementValue(webXmlDoc, "auth-method", "KEYCLOAK-SAML", "BASIC"); modifyDocElementValue(webXmlDoc, "auth-method", "KEYCLOAK", "BASIC"); archive.add(new StringAsset((documentToString(webXmlDoc))), DeploymentArchiveProcessorUtils.WEBXML_PATH); } catch (IllegalArgumentException ex) { throw new RuntimeException("Error when processing " + archive.getName(), ex); } }
Example 9
Source File: EmbeddedTomEEContainer.java From tomee with Apache License 2.0 | 5 votes |
@Override public void undeploy(final Archive<?> archive) throws DeploymentException { final String name = archive.getName(); stopCdiContexts(name); if (configuration.isSingleDeploymentByArchiveName(name)) { return; } try { this.container.undeploy(name); } catch (final Exception e) { throw new DeploymentException("Unable to undeploy", e); } finally { this.classLoader.get().unregister(archive.getName()); final File file = ARCHIVES.remove(archive); if (!configuration.isSingleDumpByArchiveName()) { final File folder = new File(file.getParentFile(), file.getName().substring(0, file.getName().length() - 4)); if (folder.exists()) { Files.delete(folder); } Files.delete(file); final File parentFile = file.getParentFile(); final File[] parentChildren = parentFile.listFiles(); if (parentChildren == null || parentChildren.length == 0) { Files.delete(file.getParentFile()); } } } }
Example 10
Source File: ManagedSEDeployableContainer.java From camel-spring-boot with Apache License 2.0 | 5 votes |
private void materializeDirectory(Archive<?> archive) throws DeploymentException { if (archive.getContent().isEmpty()) { // Do not materialize an empty directory return; } File entryDirectory = new File(TARGET.concat(File.separator).concat(archive.getName())); try { if (entryDirectory.exists()) { // Always delete previous content FileDeploymentUtils.deleteContent(entryDirectory.toPath()); } else { if (!entryDirectory.mkdirs()) { throw new DeploymentException("Could not create class path directory: " + entryDirectory); } } for (Node child : archive.get(ClassPath.ROOT_ARCHIVE_PATH).getChildren()) { Asset asset = child.getAsset(); if (asset instanceof ClassAsset) { FileDeploymentUtils.materializeClass(entryDirectory, (ClassAsset) asset); } else if (asset == null) { FileDeploymentUtils.materializeSubdirectories(entryDirectory, child); } } } catch (IOException e) { throw new DeploymentException("Could not materialize class path directory: " + archive.getName(), e); } materializedFiles.add(entryDirectory); }
Example 11
Source File: TomEEContainer.java From tomee with Apache License 2.0 | 5 votes |
@Override public void undeploy(final Archive<?> archive) throws DeploymentException { final String archiveName = archive.getName(); if (configuration.isSingleDeploymentByArchiveName(archiveName)) { return; } final DeployedApp deployed = moduleIds.remove(archiveName); try { if (deployed == null) { LOGGER.warning(archiveName + " was not deployed"); return; } doUndeploy(deployed); } catch (final Exception e) { throw new DeploymentException("Unable to undeploy " + archiveName, e); } finally { if (deployed != null && !configuration.isSingleDumpByArchiveName()) { LOGGER.info("cleaning " + deployed.file.getAbsolutePath()); Files.delete(deployed.file); // "i" folder final File pathFile = new File(deployed.path); if (!deployed.path.equals(deployed.file.getAbsolutePath()) && pathFile.exists()) { LOGGER.info("cleaning " + pathFile); Files.delete(pathFile); } final File parentFile = deployed.file.getParentFile(); final File[] parentChildren = parentFile.listFiles(); if (parentChildren == null || parentChildren.length == 0) { Files.delete(deployed.file.getParentFile()); } } } }
Example 12
Source File: TomEEContainer.java From tomee with Apache License 2.0 | 5 votes |
protected String getArchiveNameWithoutExtension(final Archive<?> archive) { final String archiveName = archive.getName(); final int extensionOffset = archiveName.lastIndexOf('.'); if (extensionOffset >= 0) { return archiveName.substring(0, extensionOffset); } return archiveName; }
Example 13
Source File: TomEEContainer.java From tomee with Apache License 2.0 | 5 votes |
protected Assignable archiveWithTestInfo(final Archive<?> archive) { String name = archive.getName(); if (name.endsWith(".war") || name.endsWith(".ear")) { name = name.substring(0, name.length() - ".war".length()); } return archive.add( new StringAsset(testClass.get().getJavaClass().getName() + '#' + name), ArchivePaths.create("arquillian-tomee-info.txt")); }
Example 14
Source File: SWClassLoader.java From tomee with Apache License 2.0 | 4 votes |
public static void set(final Archive<?> ar, final Collection<Closeable> c) { final String archiveName = ar.getName(); archives.put(archiveName, ar); closeables.put(archiveName, c); }
Example 15
Source File: OpenEJBDeployableContainer.java From tomee with Apache License 2.0 | 4 votes |
@Override public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException { final DeploymentInfo info; try { final Closeables cl = new Closeables(); closeablesProducer.set(cl); info = quickDeploy(archive, testClass.get(), cl); // try to switch module context jndi to let test use java:module naming // we could put the managed bean in the war but then test class should respect all the // container rules (CDI) which is not the case with this solution if (archive.getName().endsWith(".war")) { final List<BeanContext> beanContexts = info.appCtx.getBeanContexts(); if (beanContexts.size() > 1) { final Iterator<BeanContext> it = beanContexts.iterator(); while (it.hasNext()) { final BeanContext next = it.next(); if (ModuleTestContext.class.isInstance(next.getModuleContext()) && BeanContext.Comp.class != next.getBeanClass()) { for (final BeanContext b : beanContexts) { if (b.getModuleContext() != next.getModuleContext()) { ModuleTestContext.class.cast(next.getModuleContext()) .setModuleJndiContextOverride(b.getModuleContext().getModuleJndiContext()); break; } } break; } } } } servletContextProducer.set(info.appServletContext); sessionProducer.set(info.appSession); appInfoProducer.set(info.appInfo); appContextProducer.set(info.appCtx); final ClassLoader loader = info.appCtx.getWebContexts().isEmpty() ? info.appCtx.getClassLoader() : info.appCtx.getWebContexts().iterator().next().getClassLoader(); final ClassLoader classLoader = loader == null ? info.appCtx.getClassLoader() : loader; TestObserver.ClassLoaders classLoaders = this.classLoader.get(); if (classLoaders == null) { classLoaders = new TestObserver.ClassLoaders(); this.classLoader.set(classLoaders); } classLoaders.register(archive.getName(), classLoader); } catch (final Exception e) { throw new DeploymentException("can't deploy " + archive.getName(), e); } // if service manager is started allow @ArquillianResource URL injection if (PROPERTIES.containsKey(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE)) { final ProtocolMetaData metaData = ServiceManagers.protocolMetaData(appInfoProducer.get()); HTTPContext http = null; for (final WebAppInfo webapp : info.appInfo.webApps) { for (final ServletInfo servletInfo : webapp.servlets) { if (http == null) { http = HTTPContext.class.cast(metaData.getContexts().iterator().next()); http.add(new Servlet(servletInfo.servletName, webapp.contextRoot)); } } for (final ClassListInfo classListInfo : webapp.webAnnotatedClasses) { for (final String path : classListInfo.list) { if (!path.contains("!")) { continue; } if (http == null) { http = HTTPContext.class.cast(metaData.getContexts().iterator().next()); } http.add(new Servlet(path.substring(path.lastIndexOf('!') + 2).replace(".class", "").replace("/", "."), webapp.contextRoot)); } } } if (metaData != null) { return metaData; } } return new ProtocolMetaData(); }
Example 16
Source File: EmbeddedTomEEContainer.java From tomee with Apache License 2.0 | 4 votes |
@Override public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException { try { /* don't do it since it should be configurable final File tempDir = Files.createTempDir(); final File file = new File(tempDir, name); */ final String name = archive.getName(); final Dump dump = this.dumpFile(archive); final File file = dump.getFile(); if (dump.isCreated() || !configuration.isSingleDeploymentByArchiveName(name)) { ARCHIVES.put(archive, file); final Thread current = Thread.currentThread(); final ClassLoader loader = current.getContextClassLoader(); current.setContextClassLoader(ParentClassLoaderFinder.Helper.get()); // multiple deployments, don't leak a loader try { this.container.deploy(name, file); } finally { current.setContextClassLoader(loader); } } final AppInfo info = this.container.getInfo(name); final String context = this.getArchiveNameWithoutExtension(archive); final HTTPContext httpContext = new HTTPContext(this.configuration.getHost(), this.configuration.getHttpPort()); httpContext.add(new Servlet("ArquillianServletRunner", "/" + context)); this.addServlets(httpContext, info); startCdiContexts(name); // ensure tests can use request/session scopes even if we don't have a request TestObserver.ClassLoaders classLoaders = this.classLoader.get(); if (classLoaders == null) { classLoaders = new TestObserver.ClassLoaders(); this.classLoader.set(classLoaders); } classLoaders.register(archive.getName(), SystemInstance.get().getComponent(ContainerSystem.class).getAppContext(info.appId).getClassLoader()); return new ProtocolMetaData().addContext(httpContext); } catch (final Exception e) { throw new DeploymentException("Unable to deploy", e); } }
Example 17
Source File: MeecrowaveContainer.java From openwebbeans-meecrowave with Apache License 2.0 | 4 votes |
private File toArchiveDump(final Archive<?> archive) { final File file = new File(this.configuration.getTempDir(), archive.getName()); file.getParentFile().mkdirs(); return file; }
Example 18
Source File: CoreUtils.java From wildfly-core with GNU Lesser General Public License v2.1 | 2 votes |
/** * Exports given archive to the given folder. * * @param archive archive to export (not-<code>null</code>) * @param folderPath */ public static void saveArchiveToFolder(Archive<?> archive, String folderPath) { final File exportFile = new File(folderPath, archive.getName()); LOGGER.info("Exporting archive: " + exportFile.getAbsolutePath()); archive.as(ZipExporter.class).exportTo(exportFile, true); }