use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceIT method installPPatchAndThenRPatch.
@Test
public void installPPatchAndThenRPatch() throws IOException, GitAPIException {
initializationPerformedBaselineDistributionFoundInSystem();
// prepare some ZIP patches
preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
preparePatchZip("src/test/resources/content/patch4", "target/karaf/patches/source/patch-4.zip", false);
// simulation of P patch installed using old patching mechanism
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
FileUtils.write(new File(karafHome, "etc/overrides.properties"), "mvn:org.jboss.fuse/fuse-oceans/1.4.2\n", "UTF-8");
// non-conflicting
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
repository.closeRepository(fork, true);
// overrides.properties as after installing P patch with old mechanism
String etcOverridesProperties = FileUtils.readFileToString(new File(karafHome, "etc/overrides.properties"), "UTF-8");
assertThat(etcOverridesProperties, equalTo("mvn:org.jboss.fuse/fuse-oceans/1.4.2\n"));
PatchManagement service = (PatchManagement) pm;
PatchData patchData1 = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
Patch patch1 = service.trackPatch(patchData1);
PatchData patchData4 = service.fetchPatches(new File("target/karaf/patches/source/patch-4.zip").toURI().toURL()).get(0);
Patch patch4 = service.trackPatch(patchData4);
String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
service.install(tx, patch1, null);
service.commitInstallation(tx);
assertTrue("There should be no changes to etc/overrides.properties after installing non-rollup patch", new File(karafHome, "etc/overrides.properties").exists());
// overrides.properties as after installing P patch with new mechanism
etcOverridesProperties = FileUtils.readFileToString(new File(karafHome, "etc/overrides.properties"), "UTF-8");
assertThat(etcOverridesProperties, equalTo("mvn:org.jboss.fuse/fuse-oceans/1.4.2\n"));
// override from P-Patch should go to etc/org.apache.karaf.features.xml
FeaturesProcessing fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
List<BundleReplacements.OverrideBundle> bundles = fp.getBundleReplacements().getOverrideBundles();
assertThat(bundles.size(), equalTo(1));
assertThat(bundles.get(0).getReplacement(), equalTo("mvn:org.jboss.fuse/fuse-tranquility/1.2.3"));
fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
assertTrue(repository.containsTag(fork, "patch-my-patch-1"));
assertFalse(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
repository.closeRepository(fork, true);
tx = service.beginInstallation(PatchKind.ROLLUP);
service.install(tx, patch4, null);
service.commitInstallation(tx);
fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
assertFalse(repository.containsTag(fork, "patch-my-patch-1"));
assertTrue(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
assertFalse("There should be no etc/overrides.properties after installing rollup patch", new File(karafHome, "etc/overrides.properties").exists());
repository.closeRepository(fork, true);
}
use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceIT method installPPatchHotFixPPatchAndThenRPatch.
/**
* Installation of R patch <strong>may</strong> leave P patches installed when they provide <strong>only</strong>
* bundles and the bundles are at higher version
* @throws IOException
* @throws GitAPIException
*/
@Test
public void installPPatchHotFixPPatchAndThenRPatch() throws IOException, GitAPIException {
freshKarafStandaloneDistro();
preparePatchZip("src/test/resources/baselines/baseline5", "target/karaf/system/org/jboss/fuse/fuse-karaf/7.0.0/fuse-karaf-7.0.0-baseline.zip", true);
validateInitialGitRepository();
// prepare some ZIP patches
preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
preparePatchZip("src/test/resources/content/patch2", "target/karaf/patches/source/patch-2.zip", false);
preparePatchZip("src/test/resources/content/patch9", "target/karaf/patches/source/patch-9.zip", false);
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
PatchManagement service = (PatchManagement) pm;
PatchData patchData1 = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
Patch patch1 = service.trackPatch(patchData1);
PatchData patchData2 = service.fetchPatches(new File("target/karaf/patches/source/patch-2.zip").toURI().toURL()).get(0);
Patch patch2 = service.trackPatch(patchData2);
PatchData patchData9 = service.fetchPatches(new File("target/karaf/patches/source/patch-9.zip").toURI().toURL()).get(0);
Patch patch9 = service.trackPatch(patchData9);
String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
service.install(tx, patch1, null);
service.commitInstallation(tx);
tx = service.beginInstallation(PatchKind.NON_ROLLUP);
service.install(tx, patch2, null);
service.commitInstallation(tx);
assertFalse("There should be no etc/overrides.properties after installing non-rollup patches", new File(karafHome, "etc/overrides.properties").exists());
FeaturesProcessing fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
List<BundleReplacements.OverrideBundle> bundles = fp.getBundleReplacements().getOverrideBundles();
assertThat(bundles.size(), equalTo(3));
assertThat(bundles.get(0).getReplacement(), equalTo("mvn:org.jboss.fuse/fuse-observations/3.2"));
assertThat(bundles.get(1).getReplacement(), equalTo("mvn:org.jboss.fuse/fuse-temporary-workaround/2.2.1"));
assertThat(bundles.get(2).getReplacement(), equalTo("mvn:org.jboss.fuse/fuse-tranquility/1.2.5"));
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
assertTrue(repository.containsTag(fork, "patch-my-patch-1"));
assertTrue(repository.containsTag(fork, "patch-my-patch-2"));
assertFalse(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
repository.closeRepository(fork, true);
tx = service.beginInstallation(PatchKind.ROLLUP);
service.install(tx, patch9, null);
service.commitInstallation(tx);
fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
assertFalse(repository.containsTag(fork, "patch-my-patch-1"));
assertFalse(repository.containsTag(fork, "patch-my-patch-2"));
assertTrue(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
assertFalse("There still should be no etc/overrides.properties after installing rollup patch", new File(karafHome, "etc/overrides.properties").exists());
// features processing should be conflict-resolved (R-patch version and P-patch version).
// newer version of fuse-tranquility (from P-Patch) should win
fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
bundles = fp.getBundleReplacements().getOverrideBundles();
assertThat(bundles.size(), equalTo(2));
assertThat(bundles.get(1).getReplacement(), equalTo("mvn:org.jboss.fuse/fuse-tranquility/1.2.5"));
repository.closeRepository(fork, true);
}
use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl in project fuse-karaf 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", "UTF-8", true);
// conflicting change, but commit
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
FileUtils.write(new File(karafHome, "bin/test"), "echo \"another user change\"\n", "UTF-8");
// 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-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] Apply user changes", "[PATCH] Rollup patch patch-4 - resetting overrides", "[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-7.0.0"));
assertTrue(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
}
use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceIT method installThreeNonRollupPatches.
@Test
public void installThreeNonRollupPatches() throws IOException, GitAPIException {
initializationPerformedBaselineDistributionFoundInSystem();
// prepare some ZIP patches
preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
preparePatchZip("src/test/resources/content/patch5", "target/karaf/patches/source/patch-5.zip", false);
preparePatchZip("src/test/resources/content/patch6", "target/karaf/patches/source/patch-6.zip", false);
PatchManagement service = (PatchManagement) pm;
PatchData patchData1 = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
Patch patch1 = service.trackPatch(patchData1);
PatchData patchData5 = service.fetchPatches(new File("target/karaf/patches/source/patch-5.zip").toURI().toURL()).get(0);
Patch patch5 = service.trackPatch(patchData5);
PatchData patchData6 = service.fetchPatches(new File("target/karaf/patches/source/patch-6.zip").toURI().toURL()).get(0);
Patch patch6 = service.trackPatch(patchData6);
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
List<BundleUpdate> patch1Updates = new LinkedList<>();
patch1Updates.add(BundleUpdate.from("mvn:org.jboss.fuse/fuse-tranquility/1.2.0").to("mvn:org.jboss.fuse/fuse-tranquility/1.2.3"));
service.install(tx, patch1, patch1Updates);
List<BundleUpdate> patch5Updates = new LinkedList<>();
patch5Updates.add(BundleUpdate.from("mvn:org.jboss.fuse/fuse-zen/1.1.44/war").to("mvn:org.jboss.fuse/fuse-zen/1.2.0/war"));
service.install(tx, patch5, patch5Updates);
List<BundleUpdate> patch6Updates = new LinkedList<>();
patch5Updates.add(BundleUpdate.from("mvn:org.jboss.fuse/fuse-zen/1.2.4/war").to("mvn:org.jboss.fuse/fuse-zen/1.3.0/war"));
service.install(tx, patch6, patch6Updates);
service.commitInstallation(tx);
String binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/instance"), "UTF-8");
assertTrue(binAdmin.contains("system/org/jboss/fuse/fuse-tranquility/1.2.3/fuse-tranquility-1.2.3.jar"));
String etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"), "UTF-8");
// version from patch-5 should be chosen, because there's 1.1.44->1.2.0
assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.2.0/war = 42"));
assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-tranquility/1.2.3 = 42"));
assertFalse(new File(karafHome, "etc/overrides.properties").exists());
FeaturesProcessing fp = InternalUtils.loadFeatureProcessing(karafHome);
List<BundleReplacements.OverrideBundle> bundles = fp.getBundleReplacements().getOverrideBundles();
assertThat(bundles.size(), equalTo(3));
assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-tranquility/[1.2.0,1.3.0)".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-tranquility/1.2.3".equals(b.getReplacement())));
assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.1,1.2)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.2.0/war".equals(b.getReplacement())));
assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.3.0,1.4.0)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.3.3/war".equals(b.getReplacement())));
/* rollback time! */
Patch p5 = service.loadPatch(new PatchDetailsRequest("my-patch-5"));
service.rollback(p5.getPatchData());
binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/instance"), "UTF-8");
assertTrue(binAdmin.contains("system/org/jboss/fuse/fuse-tranquility/1.2.3/fuse-tranquility-1.2.3.jar"));
etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"), "UTF-8");
// rollback wasn't successful
assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.2.0/war = 42"));
assertFalse(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.1.44/war = 42"));
assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-tranquility/1.2.3 = 42"));
fp = InternalUtils.loadFeatureProcessing(karafHome);
bundles = fp.getBundleReplacements().getOverrideBundles();
assertThat(bundles.size(), equalTo(3));
assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-tranquility/[1.2.0,1.3.0)".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-tranquility/1.2.3".equals(b.getReplacement())));
assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.1,1.2)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.2.0/war".equals(b.getReplacement())));
assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.3.0,1.4.0)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.3.3/war".equals(b.getReplacement())));
Patch p6 = service.loadPatch(new PatchDetailsRequest("my-patch-6"));
service.rollback(p6.getPatchData());
binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/instance"), "UTF-8");
assertTrue(binAdmin.contains("system/org/jboss/fuse/fuse-tranquility/1.2.3/fuse-tranquility-1.2.3.jar"));
etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"), "UTF-8");
assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.2.0/war = 42"));
assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-tranquility/1.2.3 = 42"));
fp = InternalUtils.loadFeatureProcessing(karafHome);
bundles = fp.getBundleReplacements().getOverrideBundles();
assertThat(bundles.size(), equalTo(2));
assertTrue(bundles.stream().noneMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.3.0,1.4.0)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.3.3/war".equals(b.getReplacement())));
repository.closeRepository(fork, true);
}
use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl in project fuse-karaf 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-7.0.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-7.0.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"), "UTF-8");
assertTrue(myProperties.contains("p1 = v1"));
repository.closeRepository(fork, true);
}
Aggregations