BundleUpgradeParser { public static CatalogUpgrades parseBundleManifestForCatalogUpgrades(Bundle bundle, Supplier<? extends Iterable<? extends RegisteredType>> typeSupplier) { Dictionary<String, String> headers = bundle.getHeaders(); String upgradesForBundlesHeader = headers.get(MANIFEST_HEADER_UPGRADE_FOR_BUNDLES); Multimap<VersionedName,VersionRangedName> upgradesForBundles = parseUpgradeForBundlesHeader(upgradesForBundlesHeader, bundle); return CatalogUpgrades.builder() .removedLegacyItems(parseForceRemoveLegacyItemsHeader(headers.get(MANIFEST_HEADER_FORCE_REMOVE_LEGACY_ITEMS), bundle, typeSupplier)) .removedBundles(parseForceRemoveBundlesHeader(headers.get(MANIFEST_HEADER_FORCE_REMOVE_BUNDLES), bundle)) .upgradeBundles(upgradesForBundles) .upgradeTypes(parseUpgradeForTypesHeader(headers.get(MANIFEST_HEADER_UPGRADE_FOR_TYPES), bundle, typeSupplier, upgradesForBundlesHeader==null ? null : upgradesForBundles)) .build(); }  static CatalogUpgrades parseBundleManifestForCatalogUpgrades(Bundle bundle, Supplier<? extends Iterable<? extends RegisteredType>> typeSupplier); @Beta
    static final String MANIFEST_HEADER_FORCE_REMOVE_LEGACY_ITEMS; @Beta
    static final String MANIFEST_HEADER_FORCE_REMOVE_BUNDLES; @Beta
    static final String MANIFEST_HEADER_UPGRADE_FOR_BUNDLES; @Beta
    static final String MANIFEST_HEADER_UPGRADE_FOR_TYPES; }
@Test public void testParseBundleEmptyManifest() throws Exception { Bundle bundle = newMockBundle(ImmutableMap.of()); Supplier<Iterable<RegisteredType>> typeSupplier = Suppliers.ofInstance(ImmutableList.of()); CatalogUpgrades upgrades = BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier); assertTrue(upgrades.isEmpty()); assertFalse(upgrades.isBundleRemoved(new VersionedName("org.example.brooklyn.mybundle", "0.1.0"))); assertFalse(upgrades.isLegacyItemRemoved(newMockCatalogItem("foo", "0.1.0"))); }
@Test public void testParseBundleManifestUpgradesInfersTypes() throws Exception { Supplier<Iterable<RegisteredType>> typeSupplier = Suppliers.ofInstance(ImmutableList.of( new BasicRegisteredType(null, "foo", "2.0", null) )); Bundle bundle = newMockBundle(new VersionedName("bundle", "2.0"), ImmutableMap.of(BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_BUNDLES, "*")); CatalogUpgrades ups = BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier); assertTypeUpgrade(ups, "foo", "1", "foo", "2.0.0"); assertTypeUpgrade(ups, "foo", "2", null, null); assertTypeUpgrade(ups, "far", "1", null, null); }
@Test public void testParseBundleManifestUpgradesValidatesIfNoBundleUpgradeVersion() throws Exception { Supplier<Iterable<RegisteredType>> typeSupplier = Suppliers.ofInstance(ImmutableList.of( new BasicRegisteredType(null, "foo", "1.0", null) )); Bundle bundle = newMockBundle(new VersionedName("bundle", "1.0"), ImmutableMap.of(BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_TYPES, "foo")); try { BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "foo", "version", "cannot be inferred"); } }
@Test public void testParseBundleManifestUpgradesValidatesIfTypeNotContained() throws Exception { Supplier<Iterable<RegisteredType>> typeSupplier = Suppliers.ofInstance(ImmutableList.of()); Bundle bundle = newMockBundle(new VersionedName("bundle", "1.0"), ImmutableMap.of( BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_BUNDLES, "*", BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_TYPES, "foo")); try { BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "foo", "bundle", "upgrade", "does not contain", "target"); } }
@Test public void testForgetQuotesGivesNiceError() throws Exception { Bundle bundle = newMockBundle(ImmutableMap.of( BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_LEGACY_ITEMS, "foo:[0,1.0.0),bar:[0,1.0.0)")); Supplier<Iterable<RegisteredType>> typeSupplier = Suppliers.ofInstance(ImmutableList.of()); try { BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "quote"); } }