OsgiArchiveInstaller { @VisibleForTesting static Optional<VersionedName> inferBundleNameFromMvnUrl(String url) { assert url.startsWith("mvn:") : "url="+url; String[] parts = url.substring(4).split("/"); if (parts.length != 3) return Optional.absent(); if (parts[0].trim().isEmpty() || parts[1].trim().isEmpty() || parts[2].trim().isEmpty()) return Optional.absent(); return Optional.of(new VersionedName(parts[0]+"."+parts[1], parts[2])); } OsgiArchiveInstaller(OsgiManager osgiManager, ManagedBundle knownBundleMetadata, InputStream zipIn); void setStart(boolean start); void setLoadCatalogBom(boolean loadCatalogBom); void setForce(boolean force); void setDeferredStart(boolean deferredStart); void setValidateTypes(boolean validateTypes); ReferenceWithError<OsgiBundleInstallationResult> install(); static final ConfigKey<String> PERSIST_MANAGED_BUNDLE_WHITELIST_REGEX; static final ConfigKey<String> PERSIST_MANAGED_BUNDLE_BLACKLIST_REGEX; }
@Test public void testInferBundleNameFromMvnUrl() throws Exception { assertFalse(OsgiArchiveInstaller.inferBundleNameFromMvnUrl("mvn:toofewslashes/1.0.0").isPresent()); assertFalse(OsgiArchiveInstaller.inferBundleNameFromMvnUrl("mvn:too/many/slashes/1.0.0").isPresent()); assertFalse(OsgiArchiveInstaller.inferBundleNameFromMvnUrl("mvn:emptystring assertFalse(OsgiArchiveInstaller.inferBundleNameFromMvnUrl("mvn:/emptystring/1.0.0").isPresent()); assertFalse(OsgiArchiveInstaller.inferBundleNameFromMvnUrl("mvn:/emptystring/emptystring/").isPresent()); assertEquals(OsgiArchiveInstaller.inferBundleNameFromMvnUrl("mvn:mygroupid/myartifactid/1.0.0").get(), new VersionedName("mygroupid.myartifactid", "1.0.0")); assertEquals(OsgiArchiveInstaller.inferBundleNameFromMvnUrl("mvn:my.group.id/my.artifact.id/1.0.0").get(), new VersionedName("my.group.id.my.artifact.id", "1.0.0")); }