use of org.jboss.as.patching.metadata.BundledPatch.BundledPatchEntry 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.BundledPatchEntry in project wildfly-core by wildfly.
the class PatchHandler method displayPatchBundleXml.
private void displayPatchBundleXml(CommandContext ctx, List<BundledPatchEntry> patches, ZipFile patchZip) throws CommandLineException {
if (patches.isEmpty()) {
return;
}
for (BundledPatchEntry bundledPatch : patches) {
final ZipEntry bundledZip = patchZip.getEntry(bundledPatch.getPatchPath());
if (bundledZip == null) {
throw new CommandLineException("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.isPresent(ctx.getParsedCommandLine())) {
// 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 CommandLineException("Failed to inspect " + bundledPatch.getPatchPath(), e);
} finally {
IoUtils.safeClose(bundledPatchIs);
IoUtils.safeClose(is);
}
}
}
use of org.jboss.as.patching.metadata.BundledPatch.BundledPatchEntry in project wildfly-core by wildfly.
the class PatchHandler method doInspect.
protected void doInspect(CommandContext ctx) throws CommandLineException {
final ParsedCommandLine parsedLine = ctx.getParsedCommandLine();
final String patchPath = path.getValue(parsedLine, true);
final File patchFile = new File(patchPath);
if (!patchFile.exists()) {
throw new CommandLineException("Failed to locate " + patchFile.getAbsolutePath());
}
ZipFile patchZip = null;
InputStream is = null;
try {
patchZip = new ZipFile(patchFile);
ZipEntry patchXmlEntry = patchZip.getEntry(PatchBundleXml.MULTI_PATCH_XML);
if (patchXmlEntry == null) {
patchXmlEntry = patchZip.getEntry(PatchXml.PATCH_XML);
if (patchXmlEntry == null) {
throw new CommandLineException("Neither " + PatchBundleXml.MULTI_PATCH_XML + " nor " + PatchXml.PATCH_XML + " were found in " + patchFile.getAbsolutePath());
}
is = patchZip.getInputStream(patchXmlEntry);
final Patch patch = PatchXml.parse(is).resolvePatch(null, null);
displayPatchXml(ctx, patch);
} else {
is = patchZip.getInputStream(patchXmlEntry);
final List<BundledPatchEntry> patches = PatchBundleXml.parse(is).getPatches();
displayPatchBundleXml(ctx, patches, patchZip);
}
} catch (ZipException e) {
throw new CommandLineException("Failed to open " + patchFile.getAbsolutePath(), e);
} catch (IOException e) {
throw new CommandLineException("Failed to open " + patchFile.getAbsolutePath(), e);
} catch (PatchingException e) {
throw new CommandLineException("Failed to resolve parsed patch", e);
} catch (XMLStreamException e) {
throw new CommandLineException("Failed to parse patch.xml", e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
if (patchZip != null) {
try {
patchZip.close();
} catch (IOException e) {
}
}
}
}
Aggregations