OpearFile implements Opear { static Result<OpearMetadata> validateOpearManifest(final @Nullable Manifest manifest) { return Result.success(manifest) .map(Optional::ofNullable) .flatMap(optMan -> optMan.map(Result::success).orElseGet(() -> Result.failure("specified opear file does not contain manifest.")) .flatMap(man -> ofNullable(man.getMainAttributes().getValue(NAME_BUNDLE_SYMBOLICNAME)) .map(Result::success) .orElseGet(() -> Result.failure("opear manifest does not specify " + NAME_BUNDLE_SYMBOLICNAME.toString())) .map(bsn -> ofNullable(man.getMainAttributes().getValue(NAME_BUNDLE_VERSION)) .map(bvn -> bsn + "_" + bvn).orElse(bsn)) .flatMap(bid -> validateUriHeaderValuesWithDefaultForMissing(man, NAME_CLASS_PATH, ".") .flatMap(planClassPath -> validateUriHeaderValues(man, NAME_OAKPAL_PLAN).flatMap(plans -> Result.success(new OpearMetadata(plans, planClassPath, false)) ))))); } 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; }
@Test public void testValidateOpearManifest() throws Exception { assertTrue("invalid manifest when null", OpearFile.validateOpearManifest(null).isFailure()); assertTrue("invalid manifest when no bsn specified", OpearFile.validateOpearManifest( new Manifest(new ByteArrayInputStream(new byte[0]))) .isFailure()); }