org.jboss.shrinkwrap.api.exporter.ExplodedExporter Java Examples
The following examples show how to use
org.jboss.shrinkwrap.api.exporter.ExplodedExporter.
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: ClassLoadingInterruptTestCase.java From quarkus with Apache License 2.0 | 6 votes |
@Test public void testClassLoaderWhenThreadInterrupted() throws Exception { JavaArchive jar = ShrinkWrap.create(JavaArchive.class) .addClasses(ClassToLoad.class, InterruptClass.class); Path path = Files.createTempDirectory("test"); try { jar.as(ExplodedExporter.class).exportExploded(path.toFile(), "tmp"); ClassLoader cl = QuarkusClassLoader.builder("test", getClass().getClassLoader(), false) .addElement(new DirectoryClassPathElement(path.resolve("tmp"))) .build(); Class<?> c = cl.loadClass(InterruptClass.class.getName()); Assertions.assertNotEquals(c, InterruptClass.class); Runnable runnable = (Runnable) c.newInstance(); runnable.run(); } finally { IoUtils.recursiveDelete(path); } }
Example #2
Source File: QuarkusUnitTest.java From quarkus with Apache License 2.0 | 6 votes |
private void exportArchive(Path deploymentDir, Class<?> testClass) { try { JavaArchive archive = getArchiveProducerOrDefault(); Class<?> c = testClass; while (c != Object.class) { archive.addClass(c); c = c.getSuperclass(); } if (customApplicationProperties != null) { archive.add(new PropertiesAsset(customApplicationProperties), "application.properties"); } archive.as(ExplodedExporter.class).exportExplodedInto(deploymentDir.toFile()); //debugging code ExportUtil.exportToQuarkusDeploymentPath(archive); } catch (Exception e) { throw new RuntimeException("Unable to create the archive", e); } }
Example #3
Source File: FractionUsageAnalyzerTest.java From thorntail with Apache License 2.0 | 6 votes |
@Test public void testExplodedFractionMatching() throws Exception { JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class); archive.addClass(MyResource.class); FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer(); File dirFile = TempFileManager.INSTANCE.newTempDirectory("fractionusagetest", null); archive.as(ExplodedExporter.class).exportExplodedInto(dirFile); analyzer.source(dirFile); assertThat(analyzer.detectNeededFractions() .stream() .filter(fd -> fd.getArtifactId().equals("jaxrs")) .count()) .isEqualTo(1); }
Example #4
Source File: JPATest.java From thorntail with Apache License 2.0 | 6 votes |
@Test public void testFractionMatchingExploded() throws Exception { JARArchive archive = ShrinkWrap.create(JARArchive.class); archive.addAsResource("META-INF/persistence.xml"); FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer(); File dirFile = TempFileManager.INSTANCE.newTempDirectory("jpatest", null); archive.as(ExplodedExporter.class).exportExplodedInto(dirFile); analyzer.source(dirFile); assertThat(analyzer.detectNeededFractions() .stream() .filter(fd -> fd.getArtifactId().equals("jpa")) .count()).isEqualTo(1); TempFileManager.deleteRecursively(dirFile); }
Example #5
Source File: Swarm.java From thorntail with Apache License 2.0 | 6 votes |
private void createShrinkWrapDomain() { ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); try { if (isFatJar()) { Module appModule = Module.getBootModuleLoader().loadModule(APPLICATION_MODULE_NAME); Thread.currentThread().setContextClassLoader(appModule.getClassLoader()); } Domain domain = ShrinkWrap.getDefaultDomain(); domain.getConfiguration().getExtensionLoader().addOverride(ZipExporter.class, ZipExporterImpl.class); domain.getConfiguration().getExtensionLoader().addOverride(ZipImporter.class, ZipImporterImpl.class); domain.getConfiguration().getExtensionLoader().addOverride(ExplodedExporter.class, ExplodedExporterImpl.class); domain.getConfiguration().getExtensionLoader().addOverride(ExplodedImporter.class, ExplodedImporterImpl.class); domain.getConfiguration().getExtensionLoader().addOverride(JavaArchive.class, JavaArchiveImpl.class); domain.getConfiguration().getExtensionLoader().addOverride(WebArchive.class, WebArchiveImpl.class); } catch (Exception e) { SwarmMessages.MESSAGES.shrinkwrapDomainSetupFailed(e); } finally { Thread.currentThread().setContextClassLoader(originalCl); } }
Example #6
Source File: KnoxCLI.java From knox with Apache License 2.0 | 6 votes |
/** * * @param t - Topology to use for config * @return - path of shiro.ini config file. */ protected String getConfig(Topology t){ File tmpDir = new File(System.getProperty("java.io.tmpdir")); DeploymentFactory.setGatewayServices(services); EnterpriseArchive archive = DeploymentFactory.createDeployment(getGatewayConfig(), t); File war = archive.as(ExplodedExporter.class).exportExploded(tmpDir, t.getName() + "_deploy.tmp"); war.deleteOnExit(); String config = war.getAbsolutePath() + "/%2F/WEB-INF/shiro.ini"; try{ FileUtils.forceDeleteOnExit(war); } catch (IOException e) { out.println(e.toString()); war.deleteOnExit(); } return config; }
Example #7
Source File: ManualDeploymentTest.java From tomee with Apache License 2.0 | 6 votes |
@Test public void run() throws IOException { final Configuration configuration = new Configuration().randomHttpPort(); configuration.setDir(Files.mkdirs(new File("target/" + getClass().getSimpleName() + "-tomcat")).getAbsolutePath()); try (final Container container = new Container(configuration)) { // tomee-embedded (this "container url" is filtered: name prefix + it is a directory (target/test-classes) final File parent = Files.mkdirs(new File("target/" + getClass().getSimpleName())); final File war = ShrinkWrap.create(WebArchive.class, "the-webapp") .addClass(Foo.class) .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") // activate CDI .as(ExplodedExporter.class) .exportExploded(parent); final Context ctx = container.addContext("", war.getAbsolutePath()); final Wrapper wrapper = Tomcat.addServlet(ctx, "awesome", AServlet.class.getName()); ctx.addServletMappingDecoded("/awesome", wrapper.getName()); assertEquals("Awesome", IO.slurp(new URL("http://localhost:" + configuration.getHttpPort() + "/awesome")).trim()); } catch (final Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example #8
Source File: TomEEContainerEarWithExplodedWarTest.java From tomee with Apache License 2.0 | 6 votes |
@Deployment public static WebArchive createDeployment() throws Exception { final WebArchive web = ShrinkWrap.create(WebArchive.class, WAR_FILE) .addClass(TestServlet.class) .addClass(TestEjb.class) .setWebXML(new StringAsset(Descriptors.create(WebAppDescriptor.class) .createServlet().servletName(SERVLET_NAME).servletClass(TestServlet.class.getName()).up() .createServletMapping().servletName(SERVLET_NAME).urlPattern(URL_PATTERN).up() .exportAsString())); ShrinkWrap.create(EnterpriseArchive.class, EAR_FILE).addAsModule(web) .setApplicationXML(new StringAsset(Descriptors.create(ApplicationDescriptor.class) .createModule().getOrCreateWeb().contextRoot(CONTEXT_PATH).webUri(WAR_FILE).up().up() .exportAsString())) .as(ExplodedExporter.class).exportExploded(new File(TARGET_FOLDER)); return ShrinkWrap.create(WebArchive.class); }
Example #9
Source File: QuarkusProdModeTest.java From quarkus with Apache License 2.0 | 5 votes |
private void exportArchive(Path deploymentDir, Class<?> testClass) { try { JavaArchive archive = getArchiveProducerOrDefault(); if (customApplicationProperties != null) { archive.add(new PropertiesAsset(customApplicationProperties), "application.properties"); } archive.as(ExplodedExporter.class).exportExplodedInto(deploymentDir.toFile()); String exportPath = System.getProperty("quarkus.deploymentExportPath"); if (exportPath != null) { File exportDir = new File(exportPath); if (exportDir.exists()) { if (!exportDir.isDirectory()) { throw new IllegalStateException("Export path is not a directory: " + exportPath); } try (Stream<Path> stream = Files.walk(exportDir.toPath())) { stream.sorted(Comparator.reverseOrder()).map(Path::toFile) .forEach(File::delete); } } else if (!exportDir.mkdirs()) { throw new IllegalStateException("Export path could not be created: " + exportPath); } File exportFile = new File(exportDir, archive.getName()); archive.as(ZipExporter.class).exportTo(exportFile); } } catch (Exception e) { throw new RuntimeException("Unable to create the archive", e); } }
Example #10
Source File: GatewayServer.java From knox with Apache License 2.0 | 5 votes |
private static void explodeWar( File source, File target ) throws IOException { if( source.isDirectory() ) { FileUtils.copyDirectory( source, target ); } else { WebArchive webArchive = ShrinkWrap.createFromZipFile(WebArchive.class, source); webArchive.as(ExplodedExporter.class).exportExploded(target); } }
Example #11
Source File: GatewayServer.java From knox with Apache License 2.0 | 5 votes |
private void handleCreateDeployment(Topology topology, File deployDir) { try { File topoDir = calculateDeploymentDir( topology ); if( !topoDir.exists() ) { auditor.audit( Action.DEPLOY, topology.getName(), ResourceType.TOPOLOGY, ActionOutcome.UNAVAILABLE ); // KNOX-564 - Topology should fail to deploy with no providers configured. //TODO:APPS:This should only fail if there are services in the topology. if(topology.getProviders().isEmpty()) { throw new DeploymentException("No providers found inside topology."); } log.deployingTopology( topology.getName(), topoDir.getAbsolutePath() ); internalDeactivateTopology( topology ); // KNOX-152 EnterpriseArchive ear = DeploymentFactory.createDeployment( config, topology ); if( !deployDir.exists() && !deployDir.mkdirs() ) { throw new DeploymentException( "Failed to create topology deployment temporary directory: " + deployDir.getAbsolutePath() ); } File tmp = ear.as( ExplodedExporter.class ).exportExploded( deployDir, topoDir.getName() + ".tmp" ); if( !tmp.renameTo( topoDir ) ) { FileUtils.deleteQuietly( tmp ); throw new DeploymentException( "Failed to create topology deployment directory: " + topoDir.getAbsolutePath() ); } internalDeployApplications( topology, topoDir ); internalActivateTopology( topology, topoDir ); log.deployedTopology( topology.getName()); } else { auditor.audit( Action.REDEPLOY, topology.getName(), ResourceType.TOPOLOGY, ActionOutcome.UNAVAILABLE ); log.redeployingTopology( topology.getName(), topoDir.getAbsolutePath() ); internalActivateTopology( topology, topoDir ); log.redeployedTopology( topology.getName() ); } cleanupTopologyDeployments( deployDir, topology ); } catch( Throwable e ) { auditor.audit( Action.DEPLOY, topology.getName(), ResourceType.TOPOLOGY, ActionOutcome.FAILURE ); log.failedToDeployTopology( topology.getName(), e ); } }
Example #12
Source File: DistributionController.java From arquillian-container-chameleon with Apache License 2.0 | 5 votes |
private File downloadUsingHttp() { final String distribution = targetAdapter.distribution(); final String serverName = new FileNameFromUrlExtractor(distribution).extract(); final File targetDirectory = new File(new File(distributionDownloadFolder, "server"), serverName); if (serverAlreadyDownloaded(targetDirectory)) { return getDistributionHome(targetDirectory); } System.out.println("Arquillian Chameleon: downloading distribution from " + distribution); final String targetArchive = targetDirectory + "/" + serverName + ".zip"; final Execution<File> download = Spacelift.task(DownloadTool.class).from(distribution).to(targetArchive).execute(); try { while (!download.isFinished()) { System.out.print(PROGRESS_INDICATOR); Thread.sleep(HALF_A_SECOND); } System.out.print(PROGRESS_INDICATOR); final File compressedServer = download.await(); ShrinkWrap.create(ZipImporter.class, serverName) .importFrom(compressedServer) .as(ExplodedExporter.class) .exportExploded(targetDirectory, "."); compressedServer.delete(); return getDistributionHome(targetDirectory); } catch (InterruptedException e) { throw new RuntimeException(e); } }
Example #13
Source File: DistributionController.java From arquillian-container-chameleon with Apache License 2.0 | 5 votes |
private File fetchFromMavenRepository(ExecutorService executor) { final MavenCoordinate distributableCoordinate = toMavenCoordinate(targetAdapter.distribution()); if (distributableCoordinate != null) { final File targetDirectory = new File(new File(distributionDownloadFolder, "server"), distributableCoordinate.getArtifactId() + "_" + distributableCoordinate.getVersion()); if (serverAlreadyDownloaded(targetDirectory)) { return getDistributionHome(targetDirectory); } System.out.println( "Arquillian Chameleon: downloading distribution " + distributableCoordinate.toCanonicalForm()); Future<File> uncompressDirectory = executor.submit(new Callable<File>() { @Override public File call() throws Exception { return Maven.resolver().resolve(distributableCoordinate.toCanonicalForm()) .withoutTransitivity() .asSingle(GenericArchive.class) .as(ExplodedExporter.class) .exportExploded(targetDirectory, "."); } }); try { while (!uncompressDirectory.isDone()) { System.out.print(PROGRESS_INDICATOR); Thread.sleep(HALF_A_SECOND); } System.out.println(); return getDistributionHome(uncompressDirectory.get()); } catch (Exception e) { throw new RuntimeException(e); } } return null; }
Example #14
Source File: GatewayServer.java From hadoop-mini-clusters with Apache License 2.0 | 4 votes |
private void handleCreateDeployment(Topology topology, File deployDir) { try { File topoDir = calculateDeploymentDir(topology); if (!topoDir.exists()) { auditor.audit(Action.DEPLOY, topology.getName(), ResourceType.TOPOLOGY, ActionOutcome.UNAVAILABLE); // KNOX-564 - Topology should fail to deploy with no providers configured. //TODO:APPS:This should only fail if there are services in the topology. if (topology.getProviders().isEmpty()) { throw new DeploymentException("No providers found inside topology."); } log.deployingTopology(topology.getName(), topoDir.getAbsolutePath()); internalDeactivateTopology(topology); // KNOX-152 EnterpriseArchive ear = DeploymentFactory.createDeployment(config, topology); if (!deployDir.exists()) { deployDir.mkdirs(); if (!deployDir.exists()) { throw new DeploymentException("Failed to create topology deployment temporary directory: " + deployDir.getAbsolutePath()); } } File tmp = ear.as(ExplodedExporter.class).exportExploded(deployDir, topoDir.getName() + ".tmp"); if (!tmp.renameTo(topoDir)) { FileUtils.deleteQuietly(tmp); throw new DeploymentException("Failed to create topology deployment directory: " + topoDir.getAbsolutePath()); } // internalDeployApplications(topology, topoDir); internalActivateTopology(topology, topoDir); log.deployedTopology(topology.getName()); } else { auditor.audit(Action.REDEPLOY, topology.getName(), ResourceType.TOPOLOGY, ActionOutcome.UNAVAILABLE); log.redeployingTopology(topology.getName(), topoDir.getAbsolutePath()); internalActivateTopology(topology, topoDir); log.redeployedTopology(topology.getName()); } cleanupTopologyDeployments(deployDir, topology); } catch (Throwable e) { auditor.audit(Action.DEPLOY, topology.getName(), ResourceType.TOPOLOGY, ActionOutcome.FAILURE); log.failedToDeployTopology(topology.getName(), e); } }
Example #15
Source File: SharedEnvironmentTest.java From tomee with Apache License 2.0 | 4 votes |
@Deployment(testable = false) public static WebArchive getArchive() { WebArchive deployment = new SharedEnvironmentTest().createDeployment(TestRun.class, PojoServletFilter.class, Orange.class, Green.class, Environment.class); deployment.as(ExplodedExporter.class).exportExploded(new File(System.getProperty("java.io.tmpdir"))); return deployment; }