org.jboss.shrinkwrap.api.asset.ArchiveAsset Java Examples
The following examples show how to use
org.jboss.shrinkwrap.api.asset.ArchiveAsset.
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: ConfigApplicationArchiveProcessor.java From quarkus with Apache License 2.0 | 6 votes |
@Override public void process(Archive<?> applicationArchive, TestClass testClass) { if (applicationArchive instanceof WebArchive) { WebArchive war = applicationArchive.as(WebArchive.class); Node libNode = war.get(PATH_LIBRARY); if (libNode != null) { for (Node child : libNode.getChildren()) { Asset childAsset = child.getAsset(); if (childAsset instanceof ArchiveAsset) { ArchiveAsset archiveAsset = (ArchiveAsset) childAsset; if (archiveAsset.getArchive() instanceof JavaArchive) { JavaArchive libArchive = (JavaArchive) archiveAsset.getArchive(); libArchive.deleteClass(testClass.getName()); } } } } } }
Example #2
Source File: JAXRSArchiveImpl.java From thorntail with Apache License 2.0 | 6 votes |
private static boolean isJAXRS(ArchivePath path, Asset asset) { if (asset == null) { return false; } if (asset instanceof ArchiveAsset) { return isJAXRS(((ArchiveAsset) asset).getArchive()); } if (!path.get().endsWith(".class")) { return false; } try (InputStream in = asset.openStream()) { ClassReader reader = new ClassReader(in); JAXRSAnnotationSeekingClassVisitor visitor = new JAXRSAnnotationSeekingClassVisitor(); reader.accept(visitor, 0); return visitor.isFound(); } catch (IOException ignored) { } return false; }
Example #3
Source File: DefaultApplicationDeploymentProcessor.java From thorntail with Apache License 2.0 | 6 votes |
static boolean hasApplicationPathAnnotation(ArchivePath path, Asset asset) { if (asset == null) { return false; } if (asset instanceof ArchiveAsset) { return hasApplicationPathAnnotation(((ArchiveAsset) asset).getArchive()); } if (!path.get().endsWith(".class")) { return false; } try (InputStream in = asset.openStream()) { ClassReader reader = new ClassReader(in); ApplicationPathAnnotationSeekingClassVisitor visitor = new ApplicationPathAnnotationSeekingClassVisitor(); reader.accept(visitor, 0); return visitor.isFound(); } catch (IOException ignored) { } return false; }
Example #4
Source File: MainIT.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
@Test public void testRunMainWithError() throws Throwable { JavaArchive archive = createBootstrapArchive(MyMainThatThrows.class.getName(), "_bootstrap/myapp.jar"); JavaArchive app = ShrinkWrap.create(JavaArchive.class); app.addClass(MyMainThatThrows.class); archive.add(new ArchiveAsset(app, ZipExporter.class), "_bootstrap/myapp.jar"); ClassLoader cl = createClassLoader(archive); Class<?> mainClass = cl.loadClass(Main.class.getName()); Constructor<?> ctor = mainClass.getConstructor(String[].class); Object main = ctor.newInstance((Object) new String[]{}); Method run = mainClass.getMethod("run"); boolean exceptionFound = false; try { run.invoke(main); fail("should have thrown"); } catch (Throwable t) { while (t != null) { if (t.getMessage() != null && t.getMessage().equals("expected to throw")) { exceptionFound = true; break; } t = t.getCause(); } } assertThat(exceptionFound).isTrue(); }
Example #5
Source File: ManagedSEDeployableContainer.java From camel-spring-boot with Apache License 2.0 | 4 votes |
@Override public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException { LOGGER.info("Deploying " + archive.getName()); // First of all clear the list of previously materialized deployments - otherwise the class path would grow indefinitely materializedFiles.clear(); // Create a new classpath classpathDependencies.clear(); if (ClassPath.isRepresentedBy(archive)) { for (Node child : archive.get(ClassPath.ROOT_ARCHIVE_PATH).getChildren()) { Asset asset = child.getAsset(); if (asset instanceof ArchiveAsset) { Archive<?> assetArchive = ((ArchiveAsset) asset).getArchive(); if (ClassPathDirectory.isRepresentedBy(assetArchive)) { materializeDirectory(assetArchive); } else { materializeArchive(assetArchive); } } } } else { materializeArchive(archive); } Properties systemProperties = getSystemProperties(archive); readJarFilesFromDirectory(); addTestResourcesDirectory(systemProperties); List<String> processCommand = buildProcessCommand(systemProperties); logExecutedCommand(processCommand); // Launch the process final ProcessBuilder processBuilder = new ProcessBuilder(processCommand); String path = systemProperties.getProperty("container.user.dir"); if (path != null) { processBuilder.directory(new File(path)); } processBuilder.environment().put("JAVA_HOME", new File(System.getProperty(SYSPROP_KEY_JAVA_HOME)).getAbsolutePath()); processBuilder.redirectErrorStream(true); processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT); processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT); try { process = processBuilder.start(); } catch (final IOException e) { throw new DeploymentException("Could not start process", e); } int finalWaitTime = debugModeEnabled ? (3 * waitTime) : waitTime; // Wait for socket connection if (!isServerStarted(host, port, finalWaitTime)) { throw new DeploymentException("Child JVM process failed to start within " + finalWaitTime + " seconds."); } if (!isJMXTestRunnerMBeanRegistered(host, port, finalWaitTime)) { throw new DeploymentException("JMXTestRunnerMBean not registered within " + finalWaitTime + " seconds."); } ProtocolMetaData protocolMetaData = new ProtocolMetaData(); protocolMetaData.addContext(new JMXContext(host, port)); return protocolMetaData; }
Example #6
Source File: MainIT.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 4 votes |
@Test public void testNoUserMain() throws Throwable { JavaArchive archive = createBootstrapArchive(); JavaArchive app = ShrinkWrap.create(JavaArchive.class); app.addClass(MyMain.class); archive.add(new ArchiveAsset(app, ZipExporter.class), "_bootstrap/myapp.jar"); ClassLoader cl = createClassLoader(archive); Class<?> mainClass = cl.loadClass(Main.class.getName()); Constructor<?> ctor = mainClass.getConstructor(String[].class); Object main = ctor.newInstance((Object) new String[]{}); Method getMainClassName = mainClass.getMethod("getMainClassName"); String mainClassName = (String) getMainClassName.invoke(main); assertThat(mainClassName).isEqualTo(Main.DEFAULT_MAIN_CLASS_NAME); }
Example #7
Source File: MainIT.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 4 votes |
@Test public void testWithUserMain() throws Throwable { JavaArchive archive = createBootstrapArchive(MyMain.class.getName()); JavaArchive app = ShrinkWrap.create(JavaArchive.class); app.addClass(MyMain.class); archive.add(new ArchiveAsset(app, ZipExporter.class), "_bootstrap/myapp.jar"); ClassLoader cl = createClassLoader(archive); Class<?> mainClass = cl.loadClass(Main.class.getName()); Constructor<?> ctor = mainClass.getConstructor(String[].class); Object main = ctor.newInstance((Object) new String[]{}); Method getMainClassName = mainClass.getMethod("getMainClassName"); String mainClassName = (String) getMainClassName.invoke(main); assertThat(mainClassName).isEqualTo(MyMain.class.getName()); }
Example #8
Source File: MainIT.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 4 votes |
@Test public void testRunWithoutError() throws Throwable { JavaArchive archive = createBootstrapArchive(MyMain.class.getName(), "_bootstrap/myapp.jar"); JavaArchive app = ShrinkWrap.create(JavaArchive.class); app.addClass(MyMain.class); archive.add(new ArchiveAsset(app, ZipExporter.class), "_bootstrap/myapp.jar"); ClassLoader cl = createClassLoader(archive); Class<?> mainClass = cl.loadClass(Main.class.getName()); Constructor<?> ctor = mainClass.getConstructor(String[].class); Object main = ctor.newInstance((Object) new String[]{}); Method run = mainClass.getMethod("run"); run.invoke(main); }