use of org.jboss.shrinkwrap.api.asset.ArchiveAsset in project wildfly-swarm by wildfly-swarm.
the class DeploymentProducer method index.
private void index(Archive<?> archive, List<IndexView> indexes) throws IOException {
LOGGER.debugv("Indexing archive: {0}", archive.getName());
// First try to load attached index
Node indexNode = archive.get(ArchivePaths.create(INDEX_LOCATION));
if (indexNode != null) {
try (InputStream indexStream = indexNode.getAsset().openStream()) {
LOGGER.debugv("Loading attached index from archive: {0}", archive.getName());
indexes.add(new IndexReader(indexStream).read());
}
} else {
// No index found - index all classes found
Indexer indexer = new Indexer();
for (Map.Entry<ArchivePath, Node> entry : archive.getContent(this::isClass).entrySet()) {
try (InputStream contentStream = entry.getValue().getAsset().openStream()) {
LOGGER.debugv("Indexing asset: {0} from archive: {1}", entry.getKey().get(), archive.getName());
indexer.index(contentStream);
} catch (IOException indexerIOException) {
LOGGER.warnv(indexerIOException, "Failed parsing: {0} from archive: {1}", entry.getKey().get(), archive.getName());
}
}
Index index = indexer.complete();
indexes.add(index);
}
if (archive instanceof LibraryContainer) {
for (Map.Entry<ArchivePath, Node> entry : archive.getContent(a -> a.get().endsWith(JAR_SUFFIX)).entrySet()) {
if (entry.getValue().getAsset() instanceof ArchiveAsset) {
ArchiveAsset archiveAsset = (ArchiveAsset) entry.getValue().getAsset();
index(archiveAsset.getArchive(), indexes);
} else {
try (InputStream contentStream = entry.getValue().getAsset().openStream()) {
JARArchive jarArchive = ShrinkWrap.create(JARArchive.class, entry.getKey().get()).as(ZipImporter.class).importFrom(contentStream).as(JARArchive.class);
index(jarArchive, indexes);
}
}
}
}
}
use of org.jboss.shrinkwrap.api.asset.ArchiveAsset in project wildfly by wildfly.
the class SubDirectoryModuleDeploymentTestCase method createDeployment.
@Deployment
public static Archive<?> createDeployment() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "subdirectory.ear");
final JavaArchive jarOne = ShrinkWrap.create(JavaArchive.class, "ejb.jar");
jarOne.addClass(MessageBean.class);
ear.addAsModule(new ArchiveAsset(jarOne, ZipExporter.class), "subdir/ejb/ejb.jar");
final WebArchive war = ShrinkWrap.create(WebArchive.class, "web.war");
war.addClass(MessageServlet.class);
ear.addAsModule(new ArchiveAsset(war, ZipExporter.class), "subdir/web/web.war");
return ear;
}
use of org.jboss.shrinkwrap.api.asset.ArchiveAsset in project camel by apache.
the class ManagedSEDeployableContainer method deploy.
@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;
}
use of org.jboss.shrinkwrap.api.asset.ArchiveAsset in project teiid by teiid.
the class IntegrationTestDynamicViewDefinition method testVdbZipWithDDLAndUDF.
@Test
public void testVdbZipWithDDLAndUDF() throws Exception {
JavaArchive udfJar = ShrinkWrap.create(JavaArchive.class, "func.jar").addClasses(SampleFunctions.class);
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "temp.jar").addAsManifestResource(UnitTestUtil.getTestDataFile("vdb.xml")).addAsResource(UnitTestUtil.getTestDataFile("test.ddl")).addAsResource(new ArchiveAsset(udfJar, ZipExporter.class), "lib/udf.jar");
admin.deploy("dynamic-ddl.vdb", jar.as(ZipExporter.class).exportAsInputStream());
assertTrue(AdminUtil.waitForVDBLoad(admin, "dynamic-ddl", 1, 3));
this.internalConnection = TeiidDriver.getInstance().connect("jdbc:teiid:dynamic-ddl@mm://localhost:31000;user=user;password=user", null);
// $NON-NLS-1$
execute("SELECT * from stock");
assertRowCount(1);
// $NON-NLS-1$
execute("SELECT func('a')");
assertRowCount(1);
}
use of org.jboss.shrinkwrap.api.asset.ArchiveAsset in project wildfly-swarm by wildfly-swarm.
the class JAXRSArchiveImpl method isJAXRS.
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;
}
Aggregations