use of org.jboss.fuse.patch.management.impl.GitPatchRepository in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceIT method rollbackRollupPatchInstallation.
@Test
public void rollbackRollupPatchInstallation() throws IOException, GitAPIException {
freshKarafStandaloneDistro();
GitPatchRepository repository = patchManagement();
PatchManagement management = (PatchManagement) pm;
preparePatchZip("src/test/resources/content/patch4", "target/karaf/patches/source/patch-4.zip", false);
List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-4.zip").toURI().toURL());
Patch patch = management.trackPatch(patches.get(0));
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
ObjectId master1 = fork.getRepository().resolve("master");
String tx = management.beginInstallation(PatchKind.ROLLUP);
management.install(tx, patch, null);
management.rollbackInstallation(tx);
fork.pull().call();
ObjectId master2 = fork.getRepository().resolve("master");
assertThat(master1, equalTo(master2));
assertThat(fork.tagList().call().size(), equalTo(2));
assertTrue(repository.containsTag(fork, "patch-management"));
assertTrue(repository.containsTag(fork, "baseline-7.0.0"));
}
use of org.jboss.fuse.patch.management.impl.GitPatchRepository 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.GitPatchRepository 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.GitPatchRepository in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceIT method listSingleTrackedPatch.
@Test
public void listSingleTrackedPatch() throws IOException, GitAPIException {
freshKarafStandaloneDistro();
GitPatchRepository repository = patchManagement();
PatchManagement management = (PatchManagement) pm;
preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
management.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL());
List<Patch> patches = management.listPatches(true);
assertThat(patches.size(), equalTo(1));
Patch p = patches.get(0);
assertNotNull(p.getPatchData());
assertNull(p.getResult());
assertNull(p.getManagedPatch());
((PatchManagement) pm).trackPatch(p.getPatchData());
p = management.listPatches(true).get(0);
assertNotNull(p.getPatchData());
assertNull(p.getResult());
assertNotNull(p.getManagedPatch());
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
Ref ref = fork.checkout().setCreateBranch(true).setName("patch-my-patch-1").setStartPoint("refs/remotes/origin/patch-my-patch-1").call();
// commit stored in ManagedPatch vs. commit of the patch branch
assertThat(ref.getObjectId().getName(), equalTo(p.getManagedPatch().getCommitId()));
}
use of org.jboss.fuse.patch.management.impl.GitPatchRepository 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);
}
Aggregations