@Override public ClassLoader getClassLoader(JavaArchive jar) throws Exception { File tmp = File.createTempFile("root", "tmp"); assertTrue(tmp.delete()); assertTrue(tmp.mkdir()); tmp.deleteOnExit(); jar.as(ExplodedExporter.class).exportExploded(tmp, "root"); URL url = new File(tmp, "root").toURI().toURL(); return new URLClassLoader(new URL[]{url}); } });
public static File toExploded(Archive archive, String ext) { File tmp = assertTmpFile(ext); if (tmp.delete()) { ExplodedExporter exporter = archive.as(ExplodedExporter.class); exporter.exportExploded(tmp.getParentFile(), tmp.getName()); tmp.deleteOnExit(); return tmp; } else { throw failure("Could not delete tmp file " + tmp.getAbsolutePath()); } } }
/** * Processes a nested archive by delegating to the ExplodedArchiveExporter * * @param parentDirectory * @param nestedArchiveAsset */ private void processArchiveAsset(File parentDirectory, ArchiveAsset nestedArchiveAsset) { // Get the nested archive Archive<?> nestedArchive = nestedArchiveAsset.getArchive(); nestedArchive.as(ExplodedExporter.class).exportExploded(parentDirectory); }
/** * Processes a nested archive by delegating to the ExplodedArchiveExporter * * @param parentDirectory * @param nestedArchiveAsset */ private void processArchiveAsset(File parentDirectory, ArchiveAsset nestedArchiveAsset) { // Get the nested archive Archive<?> nestedArchive = nestedArchiveAsset.getArchive(); nestedArchive.as(ExplodedExporter.class).exportExploded(parentDirectory); }
/** * @return The URL to the default deployment or null */ private URL getDefaultDeploymentURL() throws IOException { if (defaultDeploymentURL == null) { Archive<?> archive = getDefaultDeployment(); if (archive != null) { File tmpdir = TempFileManager.INSTANCE.newTempDirectory("deployment", ".d"); archive.as(ExplodedExporter.class).exportExploded(tmpdir); defaultDeploymentURL = new File(tmpdir, archive.getName()).toURI().toURL(); } } return defaultDeploymentURL; }
/** * Ensure an baseDirectory is required to export. * * @throws Exception */ @Test(expected = IllegalArgumentException.class) public void testExportExplodedRequiresBaseDirectroy() throws Exception { log.info("testExportExplodedRequiresBaseDirectroy"); ShrinkWrap.create(ExplodedExporter.class, "test.jar").exportExploded(null); }
/** * Ensure ExpolodedExporter requires a directory */ @Test(expected = IllegalArgumentException.class) public void testExportExplodedRequiresValidDirectory() throws Exception { log.info("testExportExplodedRequiresValidDirectory"); final File nonDirectory = new File(this.getTarget(), "tempFile.txt"); ShrinkWrap.create(ExplodedExporter.class, "test.jar").exportExploded(nonDirectory); }
/** * Ensure an ArchiveExportException is thrown when output directory can not be created */ @Test(expected = ArchiveExportException.class) public void testExportExplodedOutpuDirCreationFails() throws Exception { log.info("testExportExplodedOutpuDirCreationFails"); final File directory = createTempDirectory("testExportExplodedOutpuDirCreationFails"); directory.deleteOnExit(); ShrinkWrap.create(ExplodedExporter.class, "test/" + NAME_ARCHIVE).exportExploded(directory); }
/** * Ensure an baseDirectory must exist is required to export. * * @throws Exception */ @Test(expected = IllegalArgumentException.class) public void testExportExplodedRequiresExistingDirectory() throws Exception { log.info("testExportExplodedRequiresExisitingDirectroy"); final File directory = this.getNonexistantDirectory(); ShrinkWrap.create(ExplodedExporter.class, "test.jar").exportExploded(directory); }
@Test public void testFile() throws Exception { File f = File.createTempFile("test", ""); assertTrue(f.delete()); assertTrue(f.mkdirs()); f.deleteOnExit(); File dir = jar.as(ExplodedExporter.class).exportExploded(f); assertFS(dir.toURI().toURL()); }
@Test public void testFile() throws Exception { File f = File.createTempFile("test", ""); assertTrue(f.delete()); assertTrue(f.mkdirs()); f.deleteOnExit(); File dir = jar.as(ExplodedExporter.class).exportExploded(f); assertFS(dir.toURI().toURL()); }
@Test public void testFromClassLoaderWithFile() throws Exception { File f = File.createTempFile("test", ""); assertTrue(f.delete()); assertTrue(f.mkdirs()); f.deleteOnExit(); File dir = jar.as(ExplodedExporter.class).exportExploded(f); // URLClassLoader loader = new URLClassLoader(new URL[]{dir.toURI().toURL()}, Thread.currentThread().getContextClassLoader()); URLFileSystem fs = new URLFileSystem(); fs.add(loader); assertFS(fs); }
@Test public void testFromClassLoaderWithFile() throws Exception { File f = File.createTempFile("test", ""); assertTrue(f.delete()); assertTrue(f.mkdirs()); f.deleteOnExit(); File dir = jar.as(ExplodedExporter.class).exportExploded(f); // URLClassLoader loader = new URLClassLoader(new URL[]{dir.toURI().toURL()}, Thread.currentThread().getContextClassLoader()); URLFileSystem fs = new URLFileSystem(); fs.add(loader); assertFS(fs); }
@Override public File call() throws Exception { return Maven.resolver().resolve(distributableCoordinate.toCanonicalForm()) .withoutTransitivity() .asSingle(GenericArchive.class) .as(ExplodedExporter.class) .exportExploded(targetDirectory, "."); } });
@Override public File call() throws Exception { return Maven.resolver().resolve(distributableCoordinate.toCanonicalForm()) .withoutTransitivity() .asSingle(GenericArchive.class) .as(ExplodedExporter.class) .exportExploded(targetDirectory, "."); } });
/** * https://jira.jboss.org/jira/browse/SHRINKWRAP-86 Ensure an IllegalArgumentException is thrown when output * directory is a file */ @Test(expected = IllegalArgumentException.class) public void testExportExplodedOutpuDirIsAFile() throws Exception { log.info("testExportExplodedOutpuDirIsAFile"); final File directory = createTempDirectory("testExportExplodedOutpuDirIsAFile"); // Will cause the creation of Archive directory to fail final File existingFile = new File(directory, NAME_ARCHIVE + this.getArchiveExtension()); final boolean created = existingFile.createNewFile(); IOUtil.copyWithClose(new ByteArrayInputStream("test-test".getBytes()), new FileOutputStream(existingFile)); Assert.assertEquals("Could not create test file", true, created); createArchiveWithAssets().as(ExplodedExporter.class).exportExploded(directory); }
/** * https://jira.jboss.org/jira/browse/SHRINKWRAP-84 <br/> * Should be able to use a existing directory as parent directory for ExplodedExports */ @Test public void testShouldBeAbleToUseExistingDirectoryAsParent() throws Exception { Archive<?> archive = createArchiveWithAssets(); File existingParentFolder = new File("target/"); existingParentFolder.mkdirs(); Assert.assertTrue("Internal error, the directory need to exist for test case to work", existingParentFolder.exists()); File archiveFolder = new File(existingParentFolder, archive.getName()); archiveFolder.mkdirs(); Assert.assertTrue("Internal error, the directory need to exist for test case to work", existingParentFolder.exists()); archive.as(ExplodedExporter.class).exportExploded(existingParentFolder); Assert.assertTrue("A subfolder with archive name should have been created", new File(existingParentFolder, archive.getName()).exists()); }
private File explode(File targetDir, JavaArchive classes, JavaArchive lib) { WebArchive archive = ShrinkWrap.create(WebArchive.class); archive.merge(classes, "WEB-INF/classes"); archive.addAsDirectory("WEB-INF/lib"); File explodedDir = archive.as(ExplodedExporter.class).exportExploded(targetDir); File libJar = new File(explodedDir, "WEB-INF/lib/lib.jar"); lib.as(ZipExporter.class).exportTo(libJar); return explodedDir; }
private File explode(File targetDir, JavaArchive classes, JavaArchive lib) { WebArchive archive = ShrinkWrap.create(WebArchive.class); archive.merge(classes, "WEB-INF/classes"); archive.addAsDirectory("WEB-INF/lib"); File explodedDir = archive.as(ExplodedExporter.class).exportExploded(targetDir); File libJar = new File(explodedDir, "WEB-INF/lib/lib.jar"); lib.as(ZipExporter.class).exportTo(libJar); return explodedDir; }
/** * Ensure ArchiveException is thrown if Asset can not be written */ @Test(expected = ArchiveExportException.class) public void testExportExplodedThrowsExceptionOnAssetWrite() throws Exception { log.info("testExportExplodedThrowsExceptionOnAssetWrite"); Archive<?> archive = createArchiveWithAssets(); archive.add(new Asset() { @Override public InputStream openStream() { throw new RuntimeException("Mock Exception getting Stream"); } }, new BasicPath("badAsset")); final File directory = createTempDirectory("testExportExplodedThrowsExceptionOnAssetWrite"); archive.as(ExplodedExporter.class).exportExploded(directory); }