@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}); } });
@Override protected void exportArchive() { this.archive.as(ExplodedExporter.class).exportExplodedInto(tmpDir.toFile()); }
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()); } } }
public ContainerOptionsBuilder fromBuildDirectory(Archive<?> buildDirectory) { File output = createTemporalDirectoryForCopyingDockerfile(id); logger.finer(String.format("Created %s directory for storing contents of %s cube.", output, id)); buildDirectory.as(ExplodedExporter.class).exportExplodedInto(output); return fromBuildDirectory(output.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); }
public ContainerOptionsBuilder fromBuildDirectory(Archive<?> buildDirectory) { File output = createTemporalDirectoryForCopyingDockerfile(id); logger.finer(String.format("Created %s directory for storing contents of %s cube.", output, id)); buildDirectory.as(ExplodedExporter.class).exportExplodedInto(output); return fromBuildDirectory(output.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); }
private void prepareImageBuild() throws InvocationTargetException, IllegalAccessException, IOException { // @CubeDockerfile is defined as static method if (classHasMethodWithCubeDockerFile) { cubeDockerFileAnnotation = methodWithCubeDockerFile.getAnnotation(CubeDockerFile.class); final Archive<?> archive = (Archive<?>) methodWithCubeDockerFile.invoke(null, new Object[0]); File output = createTemporalDirectoryForCopyingDockerfile(containerName); logger.finer(String.format("Created %s directory for storing contents of %s cube.", output, containerName)); archive.as(ExplodedExporter.class).exportExplodedInto(output); dockerfileLocation = output; } else if (classDefinesCubeDockerFile) { cubeDockerFileAnnotation = containerObjectClass.getAnnotation(CubeDockerFile.class); //Copy Dockerfile and all contains of the same directory in a known directory. File output = createTemporalDirectoryForCopyingDockerfile(containerName); logger.finer(String.format("Created %s directory for storing contents of %s cube.", output, containerName)); DockerFileUtil.copyDockerfileDirectory(containerObjectClass, cubeDockerFileAnnotation, output); dockerfileLocation = output; } else if (classDefinesImage) { cubeImageAnnotation = containerObjectClass.getAnnotation(Image.class); } }
/** * @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; }
private void prepareImageBuild() throws InvocationTargetException, IllegalAccessException, IOException { // @CubeDockerfile is defined as static method if (classHasMethodWithCubeDockerFile) { cubeDockerFileAnnotation = methodWithCubeDockerFile.getAnnotation(CubeDockerFile.class); final Archive<?> archive = (Archive<?>) methodWithCubeDockerFile.invoke(null, new Object[0]); File output = createTemporalDirectoryForCopyingDockerfile(containerName); logger.finer(String.format("Created %s directory for storing contents of %s cube.", output, containerName)); archive.as(ExplodedExporter.class).exportExplodedInto(output); dockerfileLocation = output; } else if (classDefinesCubeDockerFile) { cubeDockerFileAnnotation = containerObjectClass.getAnnotation(CubeDockerFile.class); //Copy Dockerfile and all contains of the same directory in a known directory. File output = createTemporalDirectoryForCopyingDockerfile(containerName); logger.finer(String.format("Created %s directory for storing contents of %s cube.", output, containerName)); DockerFileUtil.copyDockerfileDirectory(containerObjectClass, cubeDockerFileAnnotation, output); dockerfileLocation = output; } else if (classDefinesImage) { cubeImageAnnotation = containerObjectClass.getAnnotation(Image.class); } }
/** * * @param t - Topology to use for config * @return - path of shiro.ini config file. */ protected String getConfig(Topology t){ File tmpDir = new File(System.getProperty("java.io.tmpdir")); DeploymentFactory.setGatewayServices(services); EnterpriseArchive archive = DeploymentFactory.createDeployment(getGatewayConfig(), t); File war = archive.as(ExplodedExporter.class).exportExploded(tmpDir, t.getName() + "_deploy.tmp"); war.deleteOnExit(); String config = war.getAbsolutePath() + "/%2F/WEB-INF/shiro.ini"; try{ FileUtils.forceDeleteOnExit(war); } catch (IOException e) { out.println(e.toString()); war.deleteOnExit(); } return config; }
@Test public void testExportExplodedIntoDirectory() throws Exception { log.info("testExportExplodedIntoDirectory"); // Get a temp directory File tempDirectory = createTempDirectory("testExportExploded"); // Get an archive instance Archive<?> archive = createArchiveWithAssets(); // Export as Exploded directory File explodedDirectory = archive.as(ExplodedExporter.class).exportExplodedInto(tempDirectory); // Validate the exploded directory was created Assert.assertNotNull(explodedDirectory); // Validate the exploded directory was created in same directory Assert.assertEquals(tempDirectory, explodedDirectory); // Validate entries were written out assertAssetInExploded(explodedDirectory, PATH_ONE, ASSET_ONE); assertAssetInExploded(explodedDirectory, PATH_TWO, ASSET_TWO); }
/** * * @param t - Topology to use for config * @return - path of shiro.ini config file. */ protected String getConfig(Topology t){ File tmpDir = new File(System.getProperty("java.io.tmpdir")); DeploymentFactory.setGatewayServices(services); EnterpriseArchive archive = DeploymentFactory.createDeployment(getGatewayConfig(), t); File war = archive.as(ExplodedExporter.class).exportExploded(tmpDir, t.getName() + "_deploy.tmp"); war.deleteOnExit(); String config = war.getAbsolutePath() + "/%2F/WEB-INF/shiro.ini"; try{ FileUtils.forceDeleteOnExit(war); } catch (IOException e) { out.println(e.toString()); war.deleteOnExit(); } return config; }
/** * 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); }
exporter.exportExploded(targetdir, ""); File[] childDirs = targetdir.listFiles(); if (childDirs.length != 1) containerHome = childDirs[0]; } else { exporter.exportExploded(containerHome, "");
exporter.exportExploded(targetdir, ""); File[] childDirs = targetdir.listFiles(); if (childDirs.length != 1) containerHome = childDirs[0]; } else { exporter.exportExploded(containerHome, "");
/** * 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); }
return archive.as(ExplodedExporter.class).exportExploded(root, archive.getName()); } else
/** * 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); }