use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceIT method installRollupPatchWithFeatureProcessingConflicts.
@Test
public void installRollupPatchWithFeatureProcessingConflicts() throws IOException, GitAPIException {
freshKarafStandaloneDistro();
GitPatchRepository repository = patchManagement("baseline5");
PatchManagement management = (PatchManagement) pm;
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
// conflicting user change to critical "etc/org.apache.karaf.features.xml" file
FileUtils.copyFile(new File("src/test/resources/processing/oakf.3.xml"), new File(fork.getRepository().getWorkTree(), "etc/org.apache.karaf.features.xml"));
// non-conflicting
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
repository.closeRepository(fork, true);
preparePatchZip("src/test/resources/content/patch9", "target/karaf/patches/source/patch-9.zip", false);
List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-9.zip").toURI().toURL());
Patch patch = management.trackPatch(patches.get(0));
String tx = management.beginInstallation(PatchKind.ROLLUP);
management.install(tx, patch, null);
@SuppressWarnings("unchecked") Map<String, Git> transactions = (Map<String, Git>) getField(management, "pendingTransactions");
assertThat(transactions.size(), equalTo(1));
fork = transactions.values().iterator().next();
ObjectId since = fork.getRepository().resolve("baseline-7.0.0^{commit}");
ObjectId to = fork.getRepository().resolve(tx);
Iterable<RevCommit> commits = fork.log().addRange(since, to).call();
// only one "user change", because we had two conflicts with new baseline - they were resolved
// by picking what already comes from rollup patch ("ours"):
/*
* Problem with applying the change 657f11c4b65bb7893a2b82f888bb9731a6d5f7d0:
* - bin/start: BOTH_MODIFIED
* Choosing "ours" change
* Problem with applying the change d9272b97582582f4b056f7170130ec91fc21aeac:
* - bin/start: BOTH_MODIFIED
* Choosing "ours" change
*/
List<String> commitList = Arrays.asList("[PATCH] Apply user changes", "[PATCH] Apply user changes", "[PATCH] Rollup patch patch-9 - resetting overrides", "[PATCH] Installing rollup patch patch-9");
int n = 0;
for (RevCommit c : commits) {
String msg = c.getShortMessage();
assertThat(msg, equalTo(commitList.get(n++)));
}
assertThat(n, equalTo(commitList.size()));
assertThat(fork.tagList().call().size(), equalTo(3));
assertTrue(repository.containsTag(fork, "patch-management"));
assertTrue(repository.containsTag(fork, "baseline-7.0.0"));
assertTrue(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
String rPatchVersion = FileUtils.readFileToString(new File("src/test/resources/content/patch9/etc/org.apache.karaf.features.xml"), "UTF-8");
String afterPatching = FileUtils.readFileToString(new File(fork.getRepository().getWorkTree(), "etc/org.apache.karaf.features.xml"), "UTF-8");
assertEquals(rPatchVersion, afterPatching);
}
use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceIT method installNonRollupPatch.
@Test
public void installNonRollupPatch() throws IOException, GitAPIException {
freshKarafStandaloneDistro();
GitPatchRepository repository = patchManagement();
PatchManagement management = (PatchManagement) pm;
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
// no changes, but commit
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
repository.prepareCommit(fork, "artificial change, not treated as user change (could be a patch)").call();
repository.push(fork);
FileUtils.write(new File(karafHome, "bin/shutdown"), "#!/bin/bash\nexit 42", "UTF-8");
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
repository.closeRepository(fork, true);
preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL());
Patch patch = management.trackPatch(patches.get(0));
String tx = management.beginInstallation(PatchKind.NON_ROLLUP);
management.install(tx, patch, null);
@SuppressWarnings("unchecked") Map<String, Git> transactions = (Map<String, Git>) getField(management, "pendingTransactions");
assertThat(transactions.size(), equalTo(1));
fork = transactions.values().iterator().next();
ObjectId since = fork.getRepository().resolve("baseline-7.0.0^{commit}");
ObjectId to = fork.getRepository().resolve(tx);
Iterable<RevCommit> commits = fork.log().addRange(since, to).call();
List<String> commitList = Arrays.asList("[PATCH] Installing patch my-patch-1", "[PATCH] Apply user changes", "artificial change, not treated as user change (could be a patch)", "[PATCH] Apply user changes");
int n = 0;
for (RevCommit c : commits) {
String msg = c.getShortMessage();
assertThat(msg, equalTo(commitList.get(n++)));
}
assertThat(n, equalTo(commitList.size()));
assertThat(fork.tagList().call().size(), equalTo(3));
assertTrue(repository.containsTag(fork, "patch-management"));
assertTrue(repository.containsTag(fork, "baseline-7.0.0"));
assertTrue(repository.containsTag(fork, "patch-my-patch-1"));
assertThat("The conflict should be resolved in special way", FileUtils.readFileToString(new File(karafHome, "bin/setenv"), "UTF-8"), equalTo("JAVA_MIN_MEM=2G # Minimum memory for the JVM\n"));
}
use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceIT method validateInitialGitRepository.
private void validateInitialGitRepository() throws IOException, GitAPIException {
pm = new GitPatchManagementServiceImpl(bundleContext);
pm.start();
pm.ensurePatchManagementInitialized();
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
List<Ref> tags = fork.tagList().call();
boolean found = false;
for (Ref tag : tags) {
if ("refs/tags/baseline-7.0.0".equals(tag.getName())) {
found = true;
break;
}
}
assertTrue("Repository should contain baseline tag for version 7.0.0", found);
// look in etc/startup.properties for installed patch-management bundle
List<String> lines = FileUtils.readLines(new File(karafHome, "etc/startup.properties"), "UTF-8");
found = false;
for (String line : lines) {
if ("mvn:org.jboss.fuse.modules.patch/patch-management/1.1.9=2".equals(line)) {
fail("Should not contain old patch-management bundle in etc/startup.properties");
}
if ("mvn:org.jboss.fuse.modules.patch/patch-management/1.2.0=2".equals(line)) {
if (found) {
fail("Should contain only one declaration of patch-management bundle in etc/startup.properties");
}
found = true;
}
}
repository.closeRepository(fork, true);
}
use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl in project fuse-karaf by jboss-fuse.
the class PatchServiceImplTest method testLoadWithoutRanges.
@Test
public void testLoadWithoutRanges() throws IOException, GitAPIException {
BundleContext bundleContext = mock(BundleContext.class);
ComponentContext componentContext = mock(ComponentContext.class);
Bundle sysBundle = mock(Bundle.class);
BundleContext sysBundleContext = mock(BundleContext.class);
Bundle bundle = mock(Bundle.class);
Bundle bundle2 = mock(Bundle.class);
FrameworkWiring wiring = mock(FrameworkWiring.class);
GitPatchRepository repository = mock(GitPatchRepository.class);
//
// Create a new service, download a patch
//
when(componentContext.getBundleContext()).thenReturn(bundleContext);
when(bundleContext.getBundle(0)).thenReturn(sysBundle);
when(sysBundle.getBundleContext()).thenReturn(sysBundleContext);
when(sysBundleContext.getProperty(PatchService.PATCH_LOCATION)).thenReturn(storage.toString());
when(repository.getManagedPatch(anyString())).thenReturn(null);
when(repository.findOrCreateMainGitRepository()).thenReturn(null);
when(sysBundleContext.getProperty("karaf.default.repository")).thenReturn("system");
when(sysBundleContext.getProperty("karaf.home")).thenReturn(karaf.getCanonicalPath());
when(sysBundleContext.getProperty("karaf.base")).thenReturn(karaf.getCanonicalPath());
when(sysBundleContext.getProperty("karaf.name")).thenReturn("root");
when(sysBundleContext.getProperty("karaf.instances")).thenReturn(karaf.getCanonicalPath() + "/instances");
when(sysBundleContext.getProperty("karaf.data")).thenReturn(karaf.getCanonicalPath() + "/data");
when(sysBundleContext.getProperty("karaf.etc")).thenReturn(karaf.getCanonicalPath() + "/etc");
PatchManagement pm = new GitPatchManagementServiceImpl(bundleContext);
((GitPatchManagementServiceImpl) pm).setGitPatchRepository(repository);
PatchServiceImpl service = new PatchServiceImpl();
setField(service, "patchManagement", pm);
service.activate(componentContext);
PatchData pd = PatchData.load(getClass().getClassLoader().getResourceAsStream("test1.patch"));
assertEquals(2, pd.getBundles().size());
assertTrue(pd.getRequirements().isEmpty());
}
use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl in project fuse-karaf by jboss-fuse.
the class PatchServiceImplTest method testPatchWithVersionRanges.
@Test
public void testPatchWithVersionRanges() throws Exception {
ComponentContext componentContext = mock(ComponentContext.class);
BundleContext bundleContext = mock(BundleContext.class);
Bundle sysBundle = mock(Bundle.class);
BundleContext sysBundleContext = mock(BundleContext.class);
Bundle bundle = mock(Bundle.class);
Bundle bundle2 = mock(Bundle.class);
FrameworkWiring wiring = mock(FrameworkWiring.class);
GitPatchRepository repository = mock(GitPatchRepository.class);
//
// Create a new service, download a patch
//
when(componentContext.getBundleContext()).thenReturn(bundleContext);
when(bundleContext.getBundle(0)).thenReturn(sysBundle);
when(sysBundle.getBundleContext()).thenReturn(sysBundleContext);
when(sysBundleContext.getProperty(PatchService.PATCH_LOCATION)).thenReturn(storage.toString());
when(repository.getManagedPatch(anyString())).thenReturn(null);
when(repository.findOrCreateMainGitRepository()).thenReturn(null);
when(sysBundleContext.getProperty("karaf.default.repository")).thenReturn("system");
when(sysBundleContext.getProperty("karaf.home")).thenReturn(karaf.getCanonicalPath());
when(sysBundleContext.getProperty("karaf.base")).thenReturn(karaf.getCanonicalPath());
when(sysBundleContext.getProperty("karaf.name")).thenReturn("root");
when(sysBundleContext.getProperty("karaf.instances")).thenReturn(karaf.getCanonicalPath() + "/instances");
when(sysBundleContext.getProperty("karaf.data")).thenReturn(karaf.getCanonicalPath() + "/data");
when(sysBundleContext.getProperty("karaf.etc")).thenReturn(karaf.getCanonicalPath() + "/etc");
PatchManagement pm = mockManagementService(bundleContext);
((GitPatchManagementServiceImpl) pm).setGitPatchRepository(repository);
PatchServiceImpl service = new PatchServiceImpl();
setField(service, "patchManagement", pm);
service.activate(componentContext);
Iterable<Patch> patches = service.download(patch140.toURI().toURL());
assertNotNull(patches);
Iterator<Patch> it = patches.iterator();
assertTrue(it.hasNext());
Patch patch = it.next();
assertNotNull(patch);
assertEquals("patch-1.4.0", patch.getPatchData().getId());
assertNotNull(patch.getPatchData().getBundles());
assertEquals(1, patch.getPatchData().getBundles().size());
Iterator<String> itb = patch.getPatchData().getBundles().iterator();
assertEquals("mvn:foo/my-bsn/1.4.0", itb.next());
assertNull(patch.getResult());
//
// Simulate the patch
//
when(sysBundleContext.getBundles()).thenReturn(new Bundle[] { bundle });
when(sysBundleContext.getServiceReference("io.fabric8.api.FabricService")).thenReturn(null);
when(bundle.getSymbolicName()).thenReturn("my-bsn");
when(bundle.getVersion()).thenReturn(new Version("1.3.1"));
when(bundle.getLocation()).thenReturn("location");
when(bundle.getBundleId()).thenReturn(123L);
BundleStartLevel bsl = mock(BundleStartLevel.class);
when(bsl.getStartLevel()).thenReturn(30);
when(bundle.adapt(BundleStartLevel.class)).thenReturn(bsl);
when(bundle.getState()).thenReturn(1);
when(sysBundleContext.getProperty("karaf.default.repository")).thenReturn("system");
PatchResult result = service.install(patch, true);
assertNotNull(result);
assertEquals(1, result.getBundleUpdates().size());
assertTrue(result.isSimulation());
}
Aggregations