@Test public void testFromJar_useCacheDirectory() throws Exception { buildDeepTestJar(); final File cacheDir = new File("target/test-output/OpearFileTest/testFromJar_useCacheDirectory/cache"); if (cacheDir.exists()) { FileUtils.deleteDirectory(cacheDir); } assertTrue("succeed with jar when cache is fresh", OpearFile.fromJar(new JarFile(deepTestTarget), cacheDir).isSuccess()); assertTrue("succeed with cache dir when cache is present", OpearFile.fromJar(new JarFile(deepTestTarget), cacheDir).isSuccess()); }
public static Result<OpearFile> fromJar(final @NotNull JarFile jarFile, final @NotNull File cacheBaseDir) { return getHashCacheKey(jarFile.getName()).flatMap(cacheKey -> { return result1(JarFile::getManifest).apply(jarFile) .flatMap(OpearFile::validateOpearManifest) .flatMap(metadata -> { final File cacheDir = new File(cacheBaseDir, cacheKey); if (cacheDir.isDirectory()) { return fromDirectory(cacheDir); } else { if (!cacheDir.mkdirs()) { return Result.failure(format("failed to create cache dir %s for specified opear file %s", cacheDir.getPath(), jarFile.getName())); } else { return cacheJar(jarFile, cacheDir).flatMap(OpearFile::fromDirectory); } } }); }); }
OpearFile implements Opear { public static Result<OpearFile> fromJar(final @NotNull JarFile jarFile, final @NotNull File cacheBaseDir) { return getHashCacheKey(jarFile.getName()).flatMap(cacheKey -> { return result1(JarFile::getManifest).apply(jarFile) .flatMap(OpearFile::validateOpearManifest) .flatMap(metadata -> { final File cacheDir = new File(cacheBaseDir, cacheKey); if (cacheDir.isDirectory()) { return fromDirectory(cacheDir); } else { if (!cacheDir.mkdirs()) { return Result.failure(format("failed to create cache dir %s for specified opear file %s", cacheDir.getPath(), jarFile.getName())); } else { return cacheJar(jarFile, cacheDir).flatMap(OpearFile::fromDirectory); } } }); }); } }
OpearFile implements Opear { public static Result<OpearFile> fromJar(final @NotNull JarFile jarFile, final @NotNull File cacheBaseDir) { return getHashCacheKey(jarFile.getName()).flatMap(cacheKey -> { return result1(JarFile::getManifest).apply(jarFile) .flatMap(OpearFile::validateOpearManifest) .flatMap(metadata -> { final File cacheDir = new File(cacheBaseDir, cacheKey); if (cacheDir.isDirectory()) { return fromDirectory(cacheDir); } else { if (!cacheDir.mkdirs()) { return Result.failure(format("failed to create cache dir %s for specified opear file %s", cacheDir.getPath(), jarFile.getName())); } else { return cacheJar(jarFile, cacheDir).flatMap(OpearFile::fromDirectory); } } }); }); } OpearFile(final File cacheDir, final OpearMetadata metadata); }
OpearFile implements Opear { public static Result<OpearFile> fromJar(final @NotNull JarFile jarFile, final @NotNull File cacheBaseDir) { return getHashCacheKey(jarFile.getName()).flatMap(cacheKey -> { return result1(JarFile::getManifest).apply(jarFile) .flatMap(OpearFile::validateOpearManifest) .flatMap(metadata -> { final File cacheDir = new File(cacheBaseDir, cacheKey); if (cacheDir.isDirectory()) { return fromDirectory(cacheDir); } else { if (!cacheDir.mkdirs()) { return Result.failure(format("failed to create cache dir %s for specified opear file %s", cacheDir.getPath(), jarFile.getName())); } else { return cacheJar(jarFile, cacheDir).flatMap(OpearFile::fromDirectory); } } }); }); } OpearFile(final File cacheDir, final OpearMetadata metadata); @Override URL getDefaultPlan(); @Override Result<URL> getSpecificPlan(final @NotNull String planName); @Override ClassLoader getPlanClassLoader(final @NotNull ClassLoader parent); static Result<OpearFile> fromDirectory(final @NotNull File directory); static Result<OpearFile> fromJar(final @NotNull JarFile jarFile, final @NotNull File cacheBaseDir); }
OpearFile implements Opear { public static Result<OpearFile> fromJar(final @NotNull JarFile jarFile, final @NotNull File cacheBaseDir) { return getHashCacheKey(jarFile.getName()).flatMap(cacheKey -> { return result1(JarFile::getManifest).apply(jarFile) .flatMap(OpearFile::validateOpearManifest) .flatMap(metadata -> { final File cacheDir = new File(cacheBaseDir, cacheKey); if (cacheDir.isDirectory()) { return fromDirectory(cacheDir); } else { if (!cacheDir.mkdirs()) { return Result.failure(format("failed to create cache dir %s for specified opear file %s", cacheDir.getPath(), jarFile.getName())); } else { return cacheJar(jarFile, cacheDir).flatMap(OpearFile::fromDirectory); } } }); }); } OpearFile(final File cacheDir, final OpearMetadata metadata); @Override URL getDefaultPlan(); @Override Result<URL> getSpecificPlan(final @NotNull String planName); @Override ClassLoader getPlanClassLoader(final @NotNull ClassLoader parent); static Result<OpearFile> fromDirectory(final @NotNull File directory); static Result<OpearFile> fromJar(final @NotNull JarFile jarFile, final @NotNull File cacheBaseDir); static final Attributes.Name NAME_BUNDLE_SYMBOLICNAME; static final Attributes.Name NAME_BUNDLE_VERSION; static final Attributes.Name NAME_CLASS_PATH; static final Attributes.Name NAME_OAKPAL_VERSION; static final Attributes.Name NAME_OAKPAL_PLAN; }