Search in sources :

Example 11 with BundleUpdate

use of org.jboss.fuse.patch.management.BundleUpdate in project fuse-karaf by jboss-fuse.

the class PatchServiceImpl method bundleUpdatesInPatch.

/**
 * Returns a list of {@link BundleUpdate} for single patch, taking into account already discovered updates
 * @param patch
 * @param allBundles
 * @param bundleUpdateLocations out parameter that gathers update locations for bundles across patches
 * @param history
 * @param updatesForBundleKeys
 * @param kind
 * @param coreBundles
 * @param featureUpdatesInThisPatch
 * @return
 * @throws IOException
 */
private List<BundleUpdate> bundleUpdatesInPatch(Patch patch, Bundle[] allBundles, Map<Bundle, String> bundleUpdateLocations, BundleVersionHistory history, Map<String, BundleUpdate> updatesForBundleKeys, PatchKind kind, Map<String, Bundle> coreBundles, List<FeatureUpdate> featureUpdatesInThisPatch) throws Exception {
    List<BundleUpdate> updatesInThisPatch = new LinkedList<>();
    // for ROLLUP patch we can check which bundles AREN'T updated by this patch - we have to reinstall them
    // at the same version as existing one. "no update" means "require install after clearing cache"
    // Initially all bundles need update. If we find an update in patch, we remove a key from this map
    Map<String, Bundle> updateNotRequired = new LinkedHashMap<>();
    // // let's keep {symbolic name -> list of versions} mapping
    // MultiMap<String, Version> allBundleVersions = new MultiMap<>();
    // bundle location -> bundle key (symbolic name|updateable version)
    Map<String, String> locationsOfBundleKeys = new HashMap<>();
    for (Bundle b : allBundles) {
        if (b.getSymbolicName() == null) {
            continue;
        }
        Version v = b.getVersion();
        Version updateableVersion = new Version(v.getMajor(), v.getMinor(), 0);
        String key = String.format("%s|%s", stripSymbolicName(b.getSymbolicName()), updateableVersion.toString());
        // symbolic name, differing at micro version only
        if (!coreBundles.containsKey(stripSymbolicName(b.getSymbolicName()))) {
            updateNotRequired.put(key, b);
        } else {
            // let's key core (etc/startup.properties) bundles by symbolic name only - there should be only
            // one version of symbolic name
            updateNotRequired.put(stripSymbolicName(b.getSymbolicName()), b);
        }
        // allBundleVersions.put(stripSymbolicName(b.getSymbolicName()), b.getVersion());
        String location = b.getLocation();
        if (location != null && location.startsWith("mvn:") && location.contains("//")) {
            // special case for mvn:org.ops4j.pax.url/pax-url-wrap/2.4.7//uber
            location = location.replace("//", "/jar/");
        }
        locationsOfBundleKeys.put(location, key);
    }
    // let's prepare a set of bundle keys that are part of features that will be updated/reinstalled - those
    // bundle keys don't have to be reinstalled separately
    Set<String> bundleKeysFromFeatures = new HashSet<>();
    if (featureUpdatesInThisPatch != null) {
        for (FeatureUpdate featureUpdate : featureUpdatesInThisPatch) {
            if (featureUpdate.getName() != null) {
                // this is either installation or update of single feature
                String fName = featureUpdate.getName();
                String fVersion = featureUpdate.getPreviousVersion();
                Feature f = featuresService.getFeature(fName, fVersion);
                for (BundleInfo bundleInfo : f.getBundles()) {
                    if (/*!bundleInfo.isDependency() && */
                    locationsOfBundleKeys.containsKey(bundleInfo.getLocation())) {
                        bundleKeysFromFeatures.add(locationsOfBundleKeys.get(bundleInfo.getLocation()));
                    }
                }
                for (Conditional cond : f.getConditional()) {
                    for (BundleInfo bundleInfo : cond.getBundles()) {
                        if (/*!bundleInfo.isDependency() && */
                        locationsOfBundleKeys.containsKey(bundleInfo.getLocation())) {
                            bundleKeysFromFeatures.add(locationsOfBundleKeys.get(bundleInfo.getLocation()));
                        }
                    }
                }
            }
        }
    }
    for (String newLocation : patch.getPatchData().getBundles()) {
        // [symbolicName, version] of the new bundle
        String[] symbolicNameVersion = helper.getBundleIdentity(newLocation);
        if (symbolicNameVersion == null || symbolicNameVersion[0] == null) {
            continue;
        }
        String sn = stripSymbolicName(symbolicNameVersion[0]);
        String vr = symbolicNameVersion[1];
        Version newVersion = VersionTable.getVersion(vr);
        Version updateableVersion = new Version(newVersion.getMajor(), newVersion.getMinor(), 0);
        // this bundle update from a patch may be applied only to relevant bundle|updateable-version, not to
        // *every* bundle with exact symbolic name
        String key = null;
        if (!coreBundles.containsKey(sn)) {
            key = String.format("%s|%s", sn, updateableVersion.toString());
        } else {
            key = sn;
        }
        // if existing bundle is within this range, update is possible
        VersionRange range = getUpdateableRange(patch, newLocation, newVersion);
        if (coreBundles.containsKey(sn)) {
            // so we lower down the lowest possible version of core bundle that we can update
            if (range == null) {
                range = new VersionRange(false, Version.emptyVersion, newVersion, true);
            } else {
                range = new VersionRange(false, Version.emptyVersion, range.getCeiling(), true);
            }
        } else if (range != null) {
            // if range is specified on non core bundle, the key should be different - updateable
            // version should be taken from range
            key = String.format("%s|%s", sn, range.getFloor().toString());
        }
        Bundle bundle = updateNotRequired.get(key);
        if (bundle == null && coreBundles.containsKey(sn)) {
            bundle = updateNotRequired.get(sn);
        }
        if (bundle == null || range == null) {
            // this patch ships a bundle that can't be used as an update for ANY currently installed bundle
            if (kind == PatchKind.NON_ROLLUP) {
                // which is strange, because non rollup patches should update existing bundles...
                if (range == null) {
                    System.err.printf("Skipping bundle %s - unable to process bundle without a version range configuration%n", newLocation);
                } else {
                // range is fine, we simply didn't find installed bundle at all - bundle from patch
                // will be stored in ${karaf.default.repository}, but not used as an update
                }
            }
            continue;
        }
        Version oldVersion = bundle.getVersion();
        if (range.contains(oldVersion)) {
            String oldLocation = history.getLocation(bundle);
            if ("org.ops4j.pax.url.mvn".equals(sn)) {
                Artifact artifact = Utils.mvnurlToArtifact(newLocation, true);
                if (artifact != null) {
                    URL location = new File(repository, String.format("org/ops4j/pax/url/pax-url-aether/%1$s/pax-url-aether-%1$s.jar", artifact.getVersion())).toURI().toURL();
                    newLocation = location.toString();
                }
            }
            int startLevel = bundle.adapt(BundleStartLevel.class).getStartLevel();
            int state = bundle.getState();
            BundleUpdate update = new BundleUpdate(sn, newVersion.toString(), newLocation, oldVersion.toString(), oldLocation, startLevel, state);
            if (bundleKeysFromFeatures.contains(key) || coreBundles.containsKey(sn)) {
                update.setIndependent(false);
            }
            updatesInThisPatch.add(update);
            updateNotRequired.remove(key);
            if (coreBundles.containsKey(sn)) {
                updateNotRequired.remove(sn);
            }
            // Merge result
            BundleUpdate oldUpdate = updatesForBundleKeys.get(key);
            if (oldUpdate != null) {
                Version upv = null;
                if (oldUpdate.getNewVersion() != null) {
                    upv = VersionTable.getVersion(oldUpdate.getNewVersion());
                }
                if (upv == null || upv.compareTo(newVersion) < 0) {
                    // other patch contains newer update for a bundle
                    updatesForBundleKeys.put(key, update);
                    bundleUpdateLocations.put(bundle, newLocation);
                }
            } else {
                // this is the first update of the bundle
                updatesForBundleKeys.put(key, update);
                bundleUpdateLocations.put(bundle, newLocation);
            }
        }
    }
    if (kind == PatchKind.ROLLUP) {
        // user features) and we have (at least try) to install them after restart.
        for (Bundle b : updateNotRequired.values()) {
            if (b.getSymbolicName() == null) {
                continue;
            }
            String symbolicName = stripSymbolicName(b.getSymbolicName());
            Version v = b.getVersion();
            Version updateableVersion = new Version(v.getMajor(), v.getMinor(), 0);
            String key = String.format("%s|%s", symbolicName, updateableVersion.toString());
            int startLevel = b.adapt(BundleStartLevel.class).getStartLevel();
            int state = b.getState();
            BundleUpdate update = new BundleUpdate(symbolicName, null, null, v.toString(), history.getLocation(b), startLevel, state);
            if (bundleKeysFromFeatures.contains(key) || coreBundles.containsKey(symbolicName)) {
                // we don't have to install it separately
                update.setIndependent(false);
            }
            updatesInThisPatch.add(update);
            updatesForBundleKeys.put(key, update);
        }
    }
    return updatesInThisPatch;
}
Also used : BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Bundle(org.osgi.framework.Bundle) Conditional(org.apache.karaf.features.Conditional) VersionRange(org.apache.felix.utils.version.VersionRange) Feature(org.apache.karaf.features.Feature) LinkedList(java.util.LinkedList) Artifact(org.jboss.fuse.patch.management.Artifact) URL(java.net.URL) LinkedHashMap(java.util.LinkedHashMap) BundleInfo(org.apache.karaf.features.BundleInfo) Version(org.osgi.framework.Version) File(java.io.File) BundleUpdate(org.jboss.fuse.patch.management.BundleUpdate) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) FeatureUpdate(org.jboss.fuse.patch.management.FeatureUpdate)

Example 12 with BundleUpdate

use of org.jboss.fuse.patch.management.BundleUpdate in project fuse-karaf by jboss-fuse.

the class PatchServiceImplTest method bundleUpdatesInPatch.

@Test
@SuppressWarnings("unchecked")
public void bundleUpdatesInPatch() throws Exception {
    BundleContext context = mock(BundleContext.class);
    Bundle bundle0 = mock(Bundle.class);
    when(bundle0.getBundleContext()).thenReturn(context);
    when(context.getProperty("karaf.home")).thenReturn("target/bundleUpdatesInPatch");
    when(context.getProperty("karaf.base")).thenReturn("target/bundleUpdatesInPatch");
    when(context.getProperty("karaf.data")).thenReturn("target/bundleUpdatesInPatch/data");
    when(context.getProperty("karaf.etc")).thenReturn("target/bundleUpdatesInPatch/etc");
    when(context.getProperty("karaf.name")).thenReturn("root");
    when(context.getProperty("karaf.instances")).thenReturn("instances");
    when(context.getProperty("karaf.default.repository")).thenReturn("system");
    when(context.getProperty("fuse.patch.location")).thenReturn(null);
    when(context.getBundle(0)).thenReturn(bundle0);
    PatchServiceImpl service = new PatchServiceImpl();
    Method m = service.getClass().getDeclaredMethod("bundleUpdatesInPatch", Patch.class, Bundle[].class, Map.class, PatchServiceImpl.BundleVersionHistory.class, Map.class, PatchKind.class, Map.class, List.class);
    m.setAccessible(true);
    Field f = service.getClass().getDeclaredField("helper");
    f.setAccessible(true);
    f.set(service, new OSGiPatchHelper(new File("target/bundleUpdatesInPatch"), context) {

        @Override
        public String[] getBundleIdentity(String url) throws IOException {
            Artifact a = Utils.mvnurlToArtifact(url, false);
            return a == null ? null : new String[] { a.getArtifactId(), a.getVersion() };
        }
    });
    PatchData pd = new PatchData("patch-x");
    // for these two, bundle.getLocation() will return matching location
    pd.getBundles().add("mvn:io.fabric8/pax-romana/1.0.1");
    pd.getBundles().add("mvn:io.fabric8/pax-hellenica/1.0.1/jar");
    // for these two, bundle.getLocation() will return non-matching location
    pd.getBundles().add("mvn:io.fabric8/pax-bohemia/1.0.1");
    pd.getBundles().add("mvn:io.fabric8/pax-pomerania/1.0.1/jar");
    // for these two, bundle.getLocation() will return matching location
    pd.getBundles().add("mvn:io.fabric8/pax-avaria/1.0.1/jar/uber");
    pd.getBundles().add("mvn:io.fabric8/pax-mazovia/1.0.1//uber");
    // for these two, bundle.getLocation() will return non-matching location
    pd.getBundles().add("mvn:io.fabric8/pax-novgorod/1.0.1/jar/uber");
    pd.getBundles().add("mvn:io.fabric8/pax-castile/1.0.1//uber");
    f = pd.getClass().getDeclaredField("versionRanges");
    f.setAccessible(true);
    f.set(pd, new HashMap<>());
    Patch patch = new Patch(pd, null);
    Bundle[] bundles = new Bundle[8];
    bundles[0] = bundle("mvn:io.fabric8/pax-romana/1.0.0");
    bundles[1] = bundle("mvn:io.fabric8/pax-hellenica/1.0.0/jar");
    bundles[2] = bundle("mvn:io.fabric8/pax-bohemia/1.0.0/jar");
    bundles[3] = bundle("mvn:io.fabric8/pax-pomerania/1.0.0");
    bundles[4] = bundle("mvn:io.fabric8/pax-avaria/1.0.0/jar/uber");
    bundles[5] = bundle("mvn:io.fabric8/pax-mazovia/1.0.0//uber");
    bundles[6] = bundle("mvn:io.fabric8/pax-novgorod/1.0.0//uber");
    bundles[7] = bundle("mvn:io.fabric8/pax-castile/1.0.0/jar/uber");
    Object _list = m.invoke(service, patch, bundles, new HashMap<>(), new PatchServiceImpl.BundleVersionHistory(new HashMap<String, Patch>()), new HashMap<>(), PatchKind.NON_ROLLUP, new HashMap<>(), null);
    List<BundleUpdate> list = (List<BundleUpdate>) _list;
    assertThat(list.size(), equalTo(8));
    assertThat(list.get(0).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-romana/1.0.0"));
    assertThat(list.get(1).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-hellenica/1.0.0/jar"));
    assertThat(list.get(2).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-bohemia/1.0.0/jar"));
    assertThat(list.get(3).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-pomerania/1.0.0"));
    assertThat(list.get(4).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-avaria/1.0.0/jar/uber"));
    assertThat(list.get(5).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-mazovia/1.0.0//uber"));
    assertThat(list.get(6).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-novgorod/1.0.0//uber"));
    assertThat(list.get(7).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-castile/1.0.0/jar/uber"));
    assertThat(list.get(0).getNewLocation(), equalTo("mvn:io.fabric8/pax-romana/1.0.1"));
    assertThat(list.get(1).getNewLocation(), equalTo("mvn:io.fabric8/pax-hellenica/1.0.1/jar"));
    assertThat(list.get(2).getNewLocation(), equalTo("mvn:io.fabric8/pax-bohemia/1.0.1"));
    assertThat(list.get(3).getNewLocation(), equalTo("mvn:io.fabric8/pax-pomerania/1.0.1/jar"));
    assertThat(list.get(4).getNewLocation(), equalTo("mvn:io.fabric8/pax-avaria/1.0.1/jar/uber"));
    assertThat(list.get(5).getNewLocation(), equalTo("mvn:io.fabric8/pax-mazovia/1.0.1//uber"));
    assertThat(list.get(6).getNewLocation(), equalTo("mvn:io.fabric8/pax-novgorod/1.0.1/jar/uber"));
    assertThat(list.get(7).getNewLocation(), equalTo("mvn:io.fabric8/pax-castile/1.0.1//uber"));
    // ---
    Repository repository = mock(Repository.class);
    File tmp = new File("target/bundleUpdatesInPatch/" + UUID.randomUUID().toString());
    tmp.mkdirs();
    File startupProperties = new File(tmp, "etc/startup.properties");
    FileUtils.copyFile(new File("src/test/resources/uber-startup.properties"), startupProperties);
    when(repository.getWorkTree()).thenReturn(tmp);
    Git fork = mock(Git.class);
    when(fork.getRepository()).thenReturn(repository);
    GitPatchManagementServiceImpl gitPatchManagementService = new GitPatchManagementServiceImpl(context);
    m = gitPatchManagementService.getClass().getDeclaredMethod("updateFileReferences", Git.class, PatchData.class, List.class);
    m.setAccessible(true);
    m.invoke(gitPatchManagementService, fork, pd, list);
    try (FileReader reader = new FileReader(startupProperties)) {
        Properties startup = new Properties();
        startup.load(reader);
        assertTrue(startup.containsKey("io/fabric8/pax-romana/1.0.1/pax-romana-1.0.1.jar"));
        assertTrue(startup.containsKey("io/fabric8/pax-hellenica/1.0.1/pax-hellenica-1.0.1.jar"));
        assertTrue(startup.containsKey("io/fabric8/pax-bohemia/1.0.1/pax-bohemia-1.0.1.jar"));
        assertTrue(startup.containsKey("io/fabric8/pax-pomerania/1.0.1/pax-pomerania-1.0.1.jar"));
        assertTrue(startup.containsKey("io/fabric8/pax-avaria/1.0.1/pax-avaria-1.0.1-uber.jar"));
        assertTrue(startup.containsKey("io/fabric8/pax-mazovia/1.0.1/pax-mazovia-1.0.1-uber.jar"));
        assertTrue(startup.containsKey("io/fabric8/pax-novgorod/1.0.1/pax-novgorod-1.0.1-uber.jar"));
        assertTrue(startup.containsKey("io/fabric8/pax-castile/1.0.1/pax-castile-1.0.1-uber.jar"));
        assertFalse(startup.containsKey("io/fabric8/pax-romana/1.0.0/pax-romana-1.0.0.jar"));
        assertFalse(startup.containsKey("io/fabric8/pax-hellenica/1.0.0/pax-hellenica-1.0.0.jar"));
        assertFalse(startup.containsKey("io/fabric8/pax-bohemia/1.0.0/pax-bohemia-1.0.0.jar"));
        assertFalse(startup.containsKey("io/fabric8/pax-pomerania/1.0.0/pax-pomerania-1.0.0.jar"));
        assertFalse(startup.containsKey("io/fabric8/pax-avaria/1.0.0/pax-avaria-1.0.0-uber.jar"));
        assertFalse(startup.containsKey("io/fabric8/pax-mazovia/1.0.0/pax-mazovia-1.0.0-uber.jar"));
        assertFalse(startup.containsKey("io/fabric8/pax-novgorod/1.0.0/pax-novgorod-1.0.0-uber.jar"));
        assertFalse(startup.containsKey("io/fabric8/pax-castile/1.0.0/pax-castile-1.0.0-uber.jar"));
    }
}
Also used : HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Properties(java.util.Properties) Field(java.lang.reflect.Field) List(java.util.List) LinkedList(java.util.LinkedList) FileReader(java.io.FileReader) BundleUpdate(org.jboss.fuse.patch.management.BundleUpdate) PatchData(org.jboss.fuse.patch.management.PatchData) Bundle(org.osgi.framework.Bundle) Method(java.lang.reflect.Method) IOException(java.io.IOException) Artifact(org.jboss.fuse.patch.management.Artifact) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) JarFile(java.util.jar.JarFile) File(java.io.File) Patch(org.jboss.fuse.patch.management.Patch) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 13 with BundleUpdate

use of org.jboss.fuse.patch.management.BundleUpdate in project fuse-karaf by jboss-fuse.

the class PatchServiceImplTest method testVersionHistory.

@Test
public void testVersionHistory() {
    // the same bundle has been patched twice
    Patch patch1 = new Patch(new PatchData("patch1", "First patch", null, null, null, null, null), null);
    patch1.setResult(new PatchResult(patch1.getPatchData(), true, System.currentTimeMillis(), new LinkedList<org.jboss.fuse.patch.management.BundleUpdate>(), null, null));
    patch1.getResult().getBundleUpdates().add(new BundleUpdate("my-bsn", "1.1.0", "mvn:groupId/my-bsn/1.1.0", "1.0.0", "mvn:groupId/my-bsn/1.0.0"));
    Patch patch2 = new Patch(new PatchData("patch2", "Second patch", null, null, null, null, null), null);
    patch2.setResult(new PatchResult(patch1.getPatchData(), true, System.currentTimeMillis(), new LinkedList<org.jboss.fuse.patch.management.BundleUpdate>(), null, null));
    patch2.getResult().getBundleUpdates().add(new BundleUpdate("my-bsn;directive1=true", "1.2.0", "mvn:groupId/my-bsn/1.2.0", "1.1.0", "mvn:groupId/my-bsn/1.1.0"));
    Map<String, Patch> patches = new HashMap<String, Patch>();
    patches.put("patch1", patch1);
    patches.put("patch2", patch2);
    // the version history should return the correct URL, even when bundle.getLocation() does not
    PatchServiceImpl.BundleVersionHistory history = new PatchServiceImpl.BundleVersionHistory(patches);
    assertEquals("Should return version from patch result instead of the original location", "mvn:groupId/my-bsn/1.2.0", history.getLocation(createMockBundle("my-bsn", "1.2.0", "mvn:groupId/my-bsn/1.0.0")));
    assertEquals("Should return version from patch result instead of the original location", "mvn:groupId/my-bsn/1.1.0", history.getLocation(createMockBundle("my-bsn", "1.1.0", "mvn:groupId/my-bsn/1.0.0")));
    assertEquals("Should return original bundle location if no maching version is found in the history", "mvn:groupId/my-bsn/1.0.0", history.getLocation(createMockBundle("my-bsn", "1.0.0", "mvn:groupId/my-bsn/1.0.0")));
    assertEquals("Should return original bundle location if no maching version is found in the history", "mvn:groupId/my-bsn/0.9.0", history.getLocation(createMockBundle("my-bsn", "0.9.0", "mvn:groupId/my-bsn/0.9.0")));
}
Also used : PatchData(org.jboss.fuse.patch.management.PatchData) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedList(java.util.LinkedList) PatchResult(org.jboss.fuse.patch.management.PatchResult) Patch(org.jboss.fuse.patch.management.Patch) BundleUpdate(org.jboss.fuse.patch.management.BundleUpdate) Test(org.junit.Test)

Example 14 with BundleUpdate

use of org.jboss.fuse.patch.management.BundleUpdate in project fuse-karaf by jboss-fuse.

the class FileBackupTest method backupSomeDataFiles.

@Test
public void backupSomeDataFiles() throws IOException {
    PatchData patchData = new PatchData("my-patch");
    patchData.setPatchLocation(new File(karafHome, "patches"));
    PatchResult result = new PatchResult(patchData);
    // updates installed bundle, has data dir
    BundleUpdate b3 = new BundleUpdate("com.irrelevant.services", "1.2", "file:/dev/null", "1.1.0", "file:/dev/random");
    // updates installed bundle, has data dir, but special case
    BundleUpdate b4 = new BundleUpdate("org.apache.karaf.features.core", "1.3", "file:/dev/null", "1.2.1", "file:/dev/random");
    // reinstalled bundle, has data dir
    BundleUpdate b5 = new BundleUpdate("com.irrelevant.iot", null, null, "1.2.5", "file:/dev/random");
    // reinstalled bundle, no data dir
    BundleUpdate b6 = new BundleUpdate("com.irrelevant.space", null, null, "1.1.0", "file:/dev/random");
    // update, but not for installed bundle
    BundleUpdate b7 = new BundleUpdate("com.irrelevant.the.final.frontier", "1.5", "file:/dev/null", "1.1.3", "file:/dev/random");
    result.getBundleUpdates().add(b3);
    result.getBundleUpdates().add(b4);
    result.getBundleUpdates().add(b5);
    result.getBundleUpdates().add(b6);
    result.getBundleUpdates().add(b7);
    new FileBackupService(sys).backupDataFiles(result, Pending.ROLLUP_INSTALLATION);
    Properties props = new Properties();
    props.load(new FileInputStream(new File(karafHome, "patches/my-patch.datafiles/backup-install.properties")));
    assertThat(props.getProperty("com.irrelevant.services$$1.1.0"), equalTo("com.irrelevant.services$$1.1.0"));
    assertThat(props.getProperty("com.irrelevant.services$$1.2"), equalTo("com.irrelevant.services$$1.1.0"));
    assertThat(props.getProperty("com.irrelevant.iot$$1.2.5"), equalTo("com.irrelevant.iot$$1.2.5"));
    assertThat(props.stringPropertyNames().size(), equalTo(3));
    assertTrue(new File(karafHome, "patches/my-patch.datafiles/install/com.irrelevant.services$$1.1.0/data/x").isDirectory());
    assertTrue(new File(karafHome, "patches/my-patch.datafiles/install/com.irrelevant.iot$$1.2.5/data/z").isDirectory());
    assertFalse(new File(karafHome, "patches/my-patch.datafiles/install/com.irrelevant.the.final.frontier$$1.5").isDirectory());
}
Also used : PatchData(org.jboss.fuse.patch.management.PatchData) PatchResult(org.jboss.fuse.patch.management.PatchResult) Properties(java.util.Properties) File(java.io.File) BundleUpdate(org.jboss.fuse.patch.management.BundleUpdate) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 15 with BundleUpdate

use of org.jboss.fuse.patch.management.BundleUpdate in project fuse-karaf by jboss-fuse.

the class PatchCommandSupport method display.

protected void display(PatchResult result) {
    int l1 = "[name]".length();
    int l2 = "[old]".length();
    int l3 = "[new]".length();
    for (BundleUpdate update : result.getBundleUpdates()) {
        if (update.getSymbolicName() != null && stripSymbolicName(update.getSymbolicName()).length() > l1) {
            l1 = stripSymbolicName(update.getSymbolicName()).length();
        }
        if (update.getPreviousVersion().length() > l2) {
            l2 = update.getPreviousVersion().length();
        }
        if (update.getNewVersion().length() > l3) {
            l3 = update.getNewVersion().length();
        }
    }
    System.out.println(String.format("%-" + l1 + "s   %-" + l2 + "s   %-" + l3 + "s", "[name]", "[old]", "[new]"));
    java.util.List<BundleUpdate> updates = new ArrayList<>(result.getBundleUpdates());
    updates.sort(Comparator.comparing(BundleUpdate::getSymbolicName));
    for (BundleUpdate update : updates) {
        System.out.println(String.format("%-" + l1 + "s | %-" + l2 + "s | %-" + l3 + "s", update.getSymbolicName() == null ? "" : stripSymbolicName(update.getSymbolicName()), update.getPreviousVersion(), update.getNewVersion()));
    }
}
Also used : ArrayList(java.util.ArrayList) BundleUpdate(org.jboss.fuse.patch.management.BundleUpdate)

Aggregations

BundleUpdate (org.jboss.fuse.patch.management.BundleUpdate)15 File (java.io.File)12 LinkedList (java.util.LinkedList)9 HashMap (java.util.HashMap)7 Test (org.junit.Test)7 Bundle (org.osgi.framework.Bundle)6 IOException (java.io.IOException)5 Patch (org.jboss.fuse.patch.management.Patch)5 PatchResult (org.jboss.fuse.patch.management.PatchResult)5 LinkedHashMap (java.util.LinkedHashMap)4 PatchData (org.jboss.fuse.patch.management.PatchData)4 PatchException (org.jboss.fuse.patch.management.PatchException)4 URISyntaxException (java.net.URISyntaxException)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Properties (java.util.Properties)3 FeatureUpdate (org.jboss.fuse.patch.management.FeatureUpdate)3 BundleException (org.osgi.framework.BundleException)3 FileInputStream (java.io.FileInputStream)2 URL (java.net.URL)2