/** * Creates a new archive of the specified type. The archive will be be backed by the default {@link Configuration}. * Invoking this method is functionally equivalent to calling {@link ArchiveFactory#create(Class, String)} upon * {@link Domain#getArchiveFactory()} upon the domain returned by {@link ShrinkWrap#getDefaultDomain()}. * * @param type * The type of the archive e.g. {@link WebArchive} * @param archiveName * The name of the archive * @return An {@link Assignable} archive base * @throws IllegalArgumentException * either argument is not specified */ public static <T extends Assignable> T create(final Class<T> type, final String archiveName) throws IllegalArgumentException { // Precondition checks if (type == null) { throw new IllegalArgumentException("Type must be specified"); } if (archiveName == null || archiveName.length() == 0) { throw new IllegalArgumentException("ArchiveName must be specified"); } // Delegate to the default domain's archive factory for creation return ShrinkWrap.getDefaultDomain().getArchiveFactory().create(type, archiveName); }
/** * Creates a new archive of the specified type. The archive will be be backed by the default {@link Configuration}. * Invoking this method is functionally equivalent to calling {@link ArchiveFactory#create(Class, String)} upon * {@link Domain#getArchiveFactory()} upon the domain returned by {@link ShrinkWrap#getDefaultDomain()}. * * @param type * The type of the archive e.g. {@link WebArchive} * @param archiveName * The name of the archive * @return An {@link Assignable} archive base * @throws IllegalArgumentException * either argument is not specified */ public static <T extends Assignable> T create(final Class<T> type, final String archiveName) throws IllegalArgumentException { // Precondition checks if (type == null) { throw new IllegalArgumentException("Type must be specified"); } if (archiveName == null || archiveName.length() == 0) { throw new IllegalArgumentException("ArchiveName must be specified"); } // Delegate to the default domain's archive factory for creation return ShrinkWrap.getDefaultDomain().getArchiveFactory().create(type, archiveName); }
/** * Creates a new archive of the specified type. The archive will be be backed by the default {@link Configuration}. * specific to this {@link ArchiveFactory}. Generates a random name for the archive and adds proper extension based * on the service descriptor properties file if extension property is present (e.g. * shrinkwrap/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.spec.JavaArchive) * * Invoking this method is functionally equivalent to calling {@link ArchiveFactory#create(Class)} upon * {@link Domain#getArchiveFactory()} upon the domain returned by {@link ShrinkWrap#getDefaultDomain()}. * * @param type * The type of the archive e.g. {@link WebArchive} * @return An {@link Assignable} archive base * @throws IllegalArgumentException * if type is not specified * @throws UnknownExtensionTypeException * If no extension mapping is found for the specified type */ public static <T extends Assignable> T create(final Class<T> type) throws IllegalArgumentException, UnknownExtensionTypeException { // Precondition checks if (type == null) { throw new IllegalArgumentException("Type must be specified"); } // Delegate to the default domain's archive factory for creation return ShrinkWrap.getDefaultDomain().getArchiveFactory().create(type); }
/** * Creates a new archive of the specified type. The archive will be be backed by the default {@link Configuration}. * specific to this {@link ArchiveFactory}. Generates a random name for the archive and adds proper extension based * on the service descriptor properties file if extension property is present (e.g. * shrinkwrap/impl-base/src/main/resources/META-INF/services/org.jboss.shrinkwrap.api.spec.JavaArchive) * * Invoking this method is functionally equivalent to calling {@link ArchiveFactory#create(Class)} upon * {@link Domain#getArchiveFactory()} upon the domain returned by {@link ShrinkWrap#getDefaultDomain()}. * * @param type * The type of the archive e.g. {@link WebArchive} * @return An {@link Assignable} archive base * @throws IllegalArgumentException * if type is not specified * @throws UnknownExtensionTypeException * If no extension mapping is found for the specified type */ public static <T extends Assignable> T create(final Class<T> type) throws IllegalArgumentException, UnknownExtensionTypeException { // Precondition checks if (type == null) { throw new IllegalArgumentException("Type must be specified"); } // Delegate to the default domain's archive factory for creation return ShrinkWrap.getDefaultDomain().getArchiveFactory().create(type); }
/** * Creates a new archive of the specified type as imported from the specified {@link File}. The file is expected to * be encoded as ZIP (ie. JAR/WAR/EAR). The name of the archive will be set to {@link File#getName()}. The archive * will be be backed by the {@link Configuration} within the {@link ShrinkWrap#getDefaultDomain()} * * @param type * The type of the archive e.g. {@link org.jboss.shrinkwrap.api.spec.WebArchive} * @param archiveFile * the archiveName to use * @return An {@link Assignable} view * @throws IllegalArgumentException * If either argument is not supplied, if the specified {@link File} does not exist, or is not a valid * ZIP file * @throws org.jboss.shrinkwrap.api.importer.ArchiveImportException * If an error occurred during the import process */ public static <T extends Assignable> T createFromZipFile(final Class<T> type, final File archiveFile) throws IllegalArgumentException, ArchiveImportException { // Delegate return getDefaultDomain().getArchiveFactory().createFromZipFile(type, archiveFile); }
/** * Creates a new archive of the specified type as imported from the specified {@link File}. The file is expected to * be encoded as ZIP (ie. JAR/WAR/EAR). The name of the archive will be set to {@link File#getName()}. The archive * will be be backed by the {@link Configuration} within the {@link ShrinkWrap#getDefaultDomain()} * * @param type * The type of the archive e.g. {@link org.jboss.shrinkwrap.api.spec.WebArchive} * @param archiveFile * the archiveName to use * @return An {@link Assignable} view * @throws IllegalArgumentException * If either argument is not supplied, if the specified {@link File} does not exist, or is not a valid * ZIP file * @throws org.jboss.shrinkwrap.api.importer.ArchiveImportException * If an error occurred during the import process */ public static <T extends Assignable> T createFromZipFile(final Class<T> type, final File archiveFile) throws IllegalArgumentException, ArchiveImportException { // Delegate return getDefaultDomain().getArchiveFactory().createFromZipFile(type, archiveFile); }
/** * Creates a new {@link Filter} instance using the given impl class name, constructor arguments and type * * @param filterClassName * @param ctorTypes * @param ctorArguments * @return */ @SuppressWarnings("unchecked") private static Filter<ArchivePath> getFilterInstance(final String filterClassName, final Class<?>[] ctorTypes, final Object[] ctorArguments) { // Precondition checks assert filterClassName != null && filterClassName.length() > 0 : "Filter class name must be specified"; assert ctorTypes != null : "Construction types must be specified"; assert ctorArguments != null : "Construction arguments must be specified"; assert ctorTypes.length == ctorArguments.length : "The number of ctor arguments and their types must match"; // Find the filter impl class in the configured CLs final Class<Filter<ArchivePath>> filterClass; try { filterClass = (Class<Filter<ArchivePath>>) ClassLoaderSearchUtil.findClassFromClassLoaders(filterClassName, ShrinkWrap.getDefaultDomain().getConfiguration().getClassLoaders()); } catch (final ClassNotFoundException cnfe) { throw new IllegalStateException("Could not find filter implementation class " + filterClassName + " in any of the configured CLs", cnfe); } // Make the new instance return SecurityActions.newInstance(filterClass, ctorTypes, ctorArguments, Filter.class); }
private void createShrinkWrapDomain() throws ModuleLoadException { ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); try { if (isFatJar()) { Thread.currentThread().setContextClassLoader(Container.class.getClassLoader()); Module appModule = Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("swarm.application")); Thread.currentThread().setContextClassLoader(appModule.getClassLoader()); } this.domain = ShrinkWrap.getDefaultDomain(); this.domain.getConfiguration().getExtensionLoader().addOverride(ZipExporter.class, ZipExporterImpl.class); this.domain.getConfiguration().getExtensionLoader().addOverride(JavaArchive.class, JavaArchiveImpl.class); this.domain.getConfiguration().getExtensionLoader().addOverride(WebArchive.class, WebArchiveImpl.class); } catch (IOException e) { e.printStackTrace(); } finally { Thread.currentThread().setContextClassLoader(originalCl); } }
private void createShrinkWrapDomain() throws ModuleLoadException { ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); try { if (isFatJar()) { Thread.currentThread().setContextClassLoader(Container.class.getClassLoader()); Module appModule = Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("swarm.application")); Thread.currentThread().setContextClassLoader(appModule.getClassLoader()); } this.domain = ShrinkWrap.getDefaultDomain(); this.domain.getConfiguration().getExtensionLoader().addOverride(ZipExporter.class, ZipExporterImpl.class); this.domain.getConfiguration().getExtensionLoader().addOverride(JavaArchive.class, JavaArchiveImpl.class); this.domain.getConfiguration().getExtensionLoader().addOverride(WebArchive.class, WebArchiveImpl.class); } catch (IOException e) { e.printStackTrace(); } finally { Thread.currentThread().setContextClassLoader(originalCl); } }
/** * Creates a new {@link Filter} instance using the given impl class name, constructor arguments and type * * @param filterClassName * @param ctorTypes * @param ctorArguments * @return */ @SuppressWarnings("unchecked") private static Filter<ArchivePath> getFilterInstance(final String filterClassName, final Class<?>[] ctorTypes, final Object[] ctorArguments) { // Precondition checks assert filterClassName != null && filterClassName.length() > 0 : "Filter class name must be specified"; assert ctorTypes != null : "Construction types must be specified"; assert ctorArguments != null : "Construction arguments must be specified"; assert ctorTypes.length == ctorArguments.length : "The number of ctor arguments and their types must match"; // Find the filter impl class in the configured CLs final Class<Filter<ArchivePath>> filterClass; try { filterClass = (Class<Filter<ArchivePath>>) ClassLoaderSearchUtil.findClassFromClassLoaders(filterClassName, ShrinkWrap.getDefaultDomain().getConfiguration().getClassLoaders()); } catch (final ClassNotFoundException cnfe) { throw new IllegalStateException("Could not find filter implementation class " + filterClassName + " in any of the configured CLs", cnfe); } // Make the new instance return SecurityActions.newInstance(filterClass, ctorTypes, ctorArguments, Filter.class); }
public static VDBArchive archiveFromCurrentApp() throws Exception { Configuration config = ShrinkWrap.getDefaultDomain().getConfiguration(); ArrayList<ClassLoader> existing = new ArrayList<>(); Iterator<ClassLoader> it = config.getClassLoaders().iterator(); while (it.hasNext()) { existing.add(it.next()); } existing.add(VDBArchive.class.getClassLoader()); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.classLoaders(existing); builder.extensionLoader(new ServiceExtensionLoader(existing)); Domain domain = ShrinkWrap.createDomain(builder); final VDBArchive archive = domain.getArchiveFactory().create(VDBArchive.class, determineName()); //final VDBArchive archive = ShrinkWrap.create(VDBArchive.class, determineName()); final DefaultDeploymentFactory factory = new DefaultVDBDeploymentFactory(); factory.setup(archive); archive.addAllDependencies(); return archive; }
@Override protected MemoryMapArchive createNewArchive() { return new MemoryMapArchiveImpl(ShrinkWrap.getDefaultDomain().getConfiguration()); }
private void createShrinkWrapDomain() throws ModuleLoadException { ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); try { if (isFatJar()) { Thread.currentThread().setContextClassLoader(Container.class.getClassLoader()); Module appModule = Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("swarm.application")); Thread.currentThread().setContextClassLoader(appModule.getClassLoader()); } this.domain = ShrinkWrap.getDefaultDomain(); this.domain.getConfiguration().getExtensionLoader().addOverride(ZipExporter.class, ZipExporterImpl.class); this.domain.getConfiguration().getExtensionLoader().addOverride(ZipImporter.class, ZipImporterImpl.class); this.domain.getConfiguration().getExtensionLoader().addOverride(ExplodedExporter.class, ExplodedExporterImpl.class); this.domain.getConfiguration().getExtensionLoader().addOverride(JavaArchive.class, JavaArchiveImpl.class); this.domain.getConfiguration().getExtensionLoader().addOverride(WebArchive.class, WebArchiveImpl.class); } catch (IOException e) { e.printStackTrace(); } finally { Thread.currentThread().setContextClassLoader(originalCl); } }
/** * Ensures all calls to get the default domain return the same reference */ @Test public void getDefaultDomain() { // Get the default domain twice final Domain domain1 = ShrinkWrap.getDefaultDomain(); final Domain domain2 = ShrinkWrap.getDefaultDomain(); // Ensure they exist TestCase.assertNotNull("Domain should exist", domain1); TestCase.assertNotNull("Domain should exist", domain2); // Ensure they're not equal TestCase.assertSame( "Obtaining the default domain should always return the same instance (idempotent operation)", domain1, domain2); }
/** * Test to ensure MemoryMap archives can be created with a name * * @throws Exception */ @Test public void testConstructorWithName() throws Exception { String name = "test.jar"; MemoryMapArchive tmp = new MemoryMapArchiveImpl(name, ShrinkWrap.getDefaultDomain().getConfiguration()); Assert.assertEquals("Should return the same name as construtor arg", name, tmp.getName()); }
/** * Ensures we can create a new Archive fro a ZIP file via an {@link ArchiveFactory} */ @Test public void shouldBeAbleToimportZipFileViaArchiveFactory() throws Exception { // Get the test file final File testFile = delegate.getExistingResource(); // Make a new archive via the default domain final JavaArchive archive = ShrinkWrap.getDefaultDomain().getArchiveFactory() .createFromZipFile(JavaArchive.class, testFile); // Assert Assert.assertNotNull("Should not return a null archive", archive); Assert.assertEquals("name of the archive imported from a ZIP file was not as expected", testFile.getName(), archive.getName()); delegate.assertContent(archive, testFile); }
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); } }
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); } }
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); } }