/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.asset.Asset#openStream() */ @Override public InputStream openStream() { // Export via the specified exporter return this.getArchive().as(this.exporter).exportAsInputStream(); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.asset.Asset#openStream() */ @Override public InputStream openStream() { // Export via the specified exporter return this.getArchive().as(this.exporter).exportAsInputStream(); }
public static void createExtensionModule(File extensionModuleRoot, Class<? extends Extension> extension, Package... additionalPackages) throws IOException { deleteRecursively(extensionModuleRoot.toPath()); if (extensionModuleRoot.exists() && !extensionModuleRoot.isDirectory()) { throw new IllegalArgumentException(extensionModuleRoot + " already exists and is not a directory"); } File file = new File(extensionModuleRoot, "main"); if (!file.mkdirs() && !file.exists()) { throw new IllegalArgumentException("Could not create " + file); } final InputStream is = createResourceRoot(extension, additionalPackages).exportAsInputStream(); try { copyFile(new File(file, JAR_NAME), is); } finally { IoUtils.safeClose(is); } URL url = extension.getResource("module.xml"); if (url == null) { throw new IllegalStateException("Could not find module.xml"); } copyFile(new File(file, "module.xml"), url.openStream()); }
/** * Exports the specified archive as an {@link InputStream} */ private InputStream exportAsInputStream(final Archive<?> archive) { assert archive != null : "archive must be specified"; final Class<? extends StreamExporter> exporter = this.getExporterClass(); assert exporter != null : "Exporter class must be specified"; return archive.as(this.getExporterClass()).exportAsInputStream(); }
/** * Ensures that we may import an archive, add content to it, export, and that the added content has been reflected * to the exported view. * * @throws Exception */ @Test public void shouldBeAbleToImportAddAndExport() throws Exception { // Get the delegate final ContentAssertionDelegateBase delegate = this.getDelegate(); assert delegate != null : "Delegate must be specified by implementations"; final File testFile = delegate.getExistingResource(); // Import from file final Class<? extends StreamImporter<?>> importerClass = this.getImporterClass(); assert importerClass != null : "Importer class must be specified by implementations"; final Archive<?> archive = ShrinkWrap.create(importerClass, "test.jar").importFrom(testFile) .as(JavaArchive.class); Assert.assertNotNull("Should not return a null archive", archive); // Add a new resource archive.add(new ClassLoaderAsset(EXISTING_RESOURCE), ArchivePaths.create("test.properties")); // Export File tempFile = new File("target/testOutput"); tempFile.deleteOnExit(); final Class<? extends StreamExporter> exporterClass = this.getExporterClass(); Assert.assertNotNull("Exporter class must be specified by implementations", exporterClass); final InputStream stream = archive.as(exporterClass).exportAsInputStream(); IOUtil.copyWithClose(stream, new FileOutputStream(tempFile)); // Ensure the exported view matches that of the archive delegate.assertContent(archive, tempFile); }