use of io.fabric8.agent.model.Repository in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceIT method installRollupPatch.
@Test
public void installRollupPatch() throws IOException, GitAPIException {
freshKarafStandaloneDistro();
GitPatchRepository repository = patchManagement();
PatchManagement management = (PatchManagement) pm;
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
repository.prepareCommit(fork, "artificial change, not treated as user change (could be a patch)").call();
repository.prepareCommit(fork, "artificial change, not treated as user change").call();
// no changes, but commit
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
FileUtils.write(new File(karafHome, "bin/start"), "echo \"another user change\"\n", true);
// conflicting change, but commit
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
FileUtils.write(new File(karafHome, "bin/test"), "echo \"another user change\"\n");
// non-conflicting
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
repository.closeRepository(fork, true);
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));
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-6.2.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] Apply user changes", "[PATCH] Rollup patch patch-4 - resetting etc/overrides.properties", "[PATCH] Installing rollup patch patch-4");
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-6.2.0"));
assertTrue(repository.containsTag(fork, "baseline-6.2.0.redhat-002"));
}
use of io.fabric8.agent.model.Repository in project fabric8 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");
((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-6.2.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-6.2.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")), equalTo("JAVA_MIN_MEM=2G # Minimum memory for the JVM\n"));
}
use of io.fabric8.agent.model.Repository in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceIT method addPatch1.
/**
* Patch 1 is non-rollup patch
* @throws IOException
* @throws GitAPIException
*/
@Test
public void addPatch1() throws IOException, GitAPIException {
initializationPerformedBaselineDistributionFoundInSystem();
// prepare some ZIP patches
preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
PatchManagement service = (PatchManagement) pm;
PatchData patchData = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
assertThat(patchData.getId(), equalTo("my-patch-1"));
Patch patch = service.trackPatch(patchData);
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
// we should see remote branch for the patch, but without checking it out, it won't be available in the clone's local branches
List<Ref> branches = fork.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call();
Ref patchBranch = null;
for (Ref remoteBranch : branches) {
if (String.format("refs/remotes/origin/patch-%s", patchData.getId()).equals(remoteBranch.getName())) {
patchBranch = remoteBranch;
break;
}
}
assertNotNull("Should find remote branch for the added patch", patchBranch);
assertThat(patch.getManagedPatch().getCommitId(), equalTo(patchBranch.getObjectId().getName()));
RevCommit patchCommit = new RevWalk(fork.getRepository()).parseCommit(patchBranch.getObjectId());
// patch commit should be child of baseline commit
RevCommit baselineCommit = new RevWalk(fork.getRepository()).parseCommit(patchCommit.getParent(0));
// this baseline commit should be tagged "baseline-VERSION"
Ref tag = fork.tagList().call().get(0);
assertThat(tag.getName(), equalTo("refs/tags/baseline-6.2.0"));
RevCommit baselineCommitFromTag = new RevWalk(fork.getRepository()).parseCommit(tag.getTarget().getObjectId());
assertThat(baselineCommit.getId(), equalTo(baselineCommitFromTag.getId()));
// let's see the patch applied to baseline-6.2.0
fork.checkout().setName("my-patch-1").setStartPoint("origin/patch-my-patch-1").setCreateBranch(true).call();
String myProperties = FileUtils.readFileToString(new File(fork.getRepository().getWorkTree(), "etc/my.properties"));
assertTrue(myProperties.contains("p1 = v1"));
repository.closeRepository(fork, true);
}
use of io.fabric8.agent.model.Repository in project fabric8 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();
verify(bsl, atLeastOnce()).setStartLevel(2);
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
List<Ref> tags = fork.tagList().call();
boolean found = false;
for (Ref tag : tags) {
if ("refs/tags/baseline-6.2.0".equals(tag.getName())) {
found = true;
break;
}
}
assertTrue("Repository should contain baseline tag for version 6.2.0", found);
// look in etc/startup.properties for installed patch-management bundle
List<String> lines = FileUtils.readLines(new File(karafHome, "etc/startup.properties"));
found = false;
for (String line : lines) {
if ("io/fabric8/patch/patch-management/1.1.9/patch-management-1.1.9.jar=2".equals(line)) {
fail("Should not contain old patch-management bundle in etc/startup.properties");
}
if ("io/fabric8/patch/patch-management/1.2.0/patch-management-1.2.0.jar=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 io.fabric8.agent.model.Repository in project fabric8 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()));
}
Aggregations