use of org.jboss.as.patching.metadata.BundledPatch in project wildfly-core by wildfly.
the class PatchBundleUnitTestCase method prepare.
/**
* Prepare the multi patch bundle.
*
* @param root the temp dir root
* @param steps the individual steps
* @return the prepared content
* @throws PatchingException
*/
protected File prepare(File root, PatchingTestStepBuilder... steps) throws PatchingException {
final File tempDir = new File(root, randomString());
tempDir.mkdir();
final List<BundledPatch.BundledPatchEntry> entries = new ArrayList<BundledPatch.BundledPatchEntry>();
for (final PatchingTestStepBuilder step : steps) {
// Prepare the patches.
final Patch patch = step.build();
writePatch(step.getPatchDir(), patch);
final String patchId = patch.getPatchId();
final String path = patchId + ".zip";
final File patchOutput = new File(tempDir, path);
ZipUtils.zip(step.getPatchDir(), patchOutput);
entries.add(new BundledPatch.BundledPatchEntry(patchId, path));
}
final File multiPatchXml = new File(tempDir, PatchBundleXml.MULTI_PATCH_XML);
try {
final OutputStream os = new FileOutputStream(multiPatchXml);
try {
PatchBundleXml.marshal(os, new BundledPatch() {
@Override
public List<BundledPatchEntry> getPatches() {
return entries;
}
});
} finally {
safeClose(os);
}
} catch (Exception e) {
throw new PatchingException(e);
}
final File result = new File(root, "multi-step-contents.zip");
ZipUtils.zip(tempDir, result);
return result;
}
use of org.jboss.as.patching.metadata.BundledPatch in project wildfly-core by wildfly.
the class PatchToolImpl method applyPatchBundle.
protected PatchingResult applyPatchBundle(final File workDir, final BundledPatch bundledPatch, final ContentVerificationPolicy contentPolicy) throws PatchingException, IOException {
final List<BundledPatchEntry> patches = bundledPatch.getPatches();
if (patches.isEmpty()) {
throw new PatchingException(PatchLogger.ROOT_LOGGER.patchBundleIsEmpty());
}
PatchingResult result = null;
BundledPatchEntry lastCommittedEntry = null;
final List<BundledPatch.BundledPatchEntry> results = new ArrayList<BundledPatch.BundledPatchEntry>(patches.size());
final List<InstalledIdentity> installedIdentities = manager.getInstalledIdentities();
for (BundledPatchEntry entry : patches) {
// TODO this has to be checked against the specific one targeted by the patch
boolean alreadyApplied = false;
for (InstalledIdentity identity : installedIdentities) {
if (identity.getAllInstalledPatches().contains(entry.getPatchId())) {
alreadyApplied = true;
break;
}
}
if (alreadyApplied) {
continue;
}
if (result != null) {
result.commit();
results.add(0, lastCommittedEntry);
}
final File patch = new File(workDir, entry.getPatchPath());
final FileInputStream is = new FileInputStream(patch);
PatchingResult currentResult = null;
try {
currentResult = applyPatch(workDir, is, contentPolicy);
} catch (PatchingException e) {
// Undo the changes included as part of this patch
for (BundledPatch.BundledPatchEntry committed : results) {
try {
rollback(committed.getPatchId(), contentPolicy, false, false).commit();
} catch (PatchingException oe) {
PatchLogger.ROOT_LOGGER.debugf(oe, "failed to rollback patch '%s'", committed.getPatchId());
}
}
throw e;
} finally {
safeClose(is);
}
if (currentResult != null) {
result = currentResult;
lastCommittedEntry = entry;
}
}
if (result == null) {
throw new PatchingException();
}
return new WrappedMultiInstallPatch(result, contentPolicy, results);
}
use of org.jboss.as.patching.metadata.BundledPatch in project wildfly-core by wildfly.
the class PatchInspect method displayPatchBundleXml.
private void displayPatchBundleXml(CommandContext ctx, List<BundledPatch.BundledPatchEntry> patches, ZipFile patchZip) throws CommandException {
if (patches.isEmpty()) {
return;
}
for (BundledPatch.BundledPatchEntry bundledPatch : patches) {
final ZipEntry bundledZip = patchZip.getEntry(bundledPatch.getPatchPath());
if (bundledZip == null) {
throw new CommandException("Patch file not found in the bundle: " + bundledPatch.getPatchPath());
}
InputStream is = null;
ZipInputStream bundledPatchIs = null;
try {
is = patchZip.getInputStream(bundledZip);
bundledPatchIs = new ZipInputStream(is);
ZipEntry bundledPatchXml = bundledPatchIs.getNextEntry();
while (bundledPatchXml != null) {
if (PatchXml.PATCH_XML.equals(bundledPatchXml.getName())) {
break;
}
bundledPatchXml = bundledPatchIs.getNextEntry();
}
if (bundledPatchXml == null) {
throw new CommandLineException("Failed to locate " + PatchXml.PATCH_XML + " in bundled patch " + bundledPatch.getPatchPath());
}
final Patch patch = PatchXml.parse(bundledPatchIs).resolvePatch(null, null);
if (verbose) {
// to make the separation better in the verbose mode
ctx.printLine("CONTENT OF " + bundledPatch.getPatchPath() + ':' + Util.LINE_SEPARATOR);
}
displayPatchXml(ctx, patch);
ctx.printLine("");
} catch (Exception e) {
throw new CommandException("Failed to inspect " + bundledPatch.getPatchPath(), e);
} finally {
IoUtils.safeClose(bundledPatchIs);
IoUtils.safeClose(is);
}
}
}
use of org.jboss.as.patching.metadata.BundledPatch in project wildfly-core by wildfly.
the class PatchToolImpl method execute.
protected PatchingResult execute(final File workDir, final ContentVerificationPolicy contentPolicy) throws PatchingException, IOException, XMLStreamException {
final File patchBundleXml = new File(workDir, PatchBundleXml.MULTI_PATCH_XML);
if (patchBundleXml.exists()) {
final InputStream patchIs = new FileInputStream(patchBundleXml);
try {
// Handle multi patch installs
final BundledPatch bundledPatch = PatchBundleXml.parse(patchIs);
return applyPatchBundle(workDir, bundledPatch, contentPolicy);
} finally {
safeClose(patchIs);
}
} else {
// Parse the xml
File patchXml = new File(workDir, PatchXml.PATCH_XML);
PatchMetadataResolver patchResolver = parsePatchXml(patchXml);
Patch patch = patchResolver.resolvePatch(null, null);
final InstalledIdentity installedIdentity = manager.getInstalledIdentity(patch.getIdentity().getName(), null);
final String currentVersion = installedIdentity.getIdentity().getVersion();
if (!Constants.UNKNOWN.equals(currentVersion) && !patch.getIdentity().getVersion().equals(currentVersion)) {
patchXml = new File(workDir, currentVersion + PatchMerger.PATCH_XML_SUFFIX);
if (!patchXml.exists()) {
throw new PatchingException("The patch does not contain metadata for currently installed " + patch.getIdentity().getName() + " version " + currentVersion);
}
patchResolver = parsePatchXml(patchXml);
patch = patchResolver.resolvePatch(null, null);
}
return apply(patchResolver, PatchContentProvider.DefaultContentProvider.create(workDir), contentPolicy);
}
}
use of org.jboss.as.patching.metadata.BundledPatch in project wildfly-core by wildfly.
the class TestUtils method createPatchBundleXMLFile.
public static void createPatchBundleXMLFile(File dir, final List<BundledPatch.BundledPatchEntry> patches) throws Exception {
File bundleXMLFile = new File(dir, "patches.xml");
FileOutputStream fos = new FileOutputStream(bundleXMLFile);
try {
PatchBundleXml.marshal(fos, new BundledPatch() {
@Override
public List<BundledPatchEntry> getPatches() {
return patches;
}
});
} finally {
safeClose(fos);
}
}
Aggregations