static PatchingException rethrowException(final Exception e) { if (e instanceof PatchingException) { return (PatchingException) e; } else { return new PatchingException(e); } }
private static void copyFile(File source, File target) throws PatchingException { try { Files.copy(source.toPath(), target.toPath()); } catch (IOException e1) { throw new PatchingException("Failed to copy " + source.getAbsolutePath() + " to " + target.getAbsolutePath()); } }
protected static void copyDir(File src, File trg) throws PatchingException { try { IoUtils.copyFile(src, trg); } catch (IOException e) { throw new PatchingException("Failed to copy modification content from " + src.getAbsolutePath() + " to " + trg.getAbsolutePath(), e); } }
static void assertExists(final File file) throws PatchingException { if (!file.exists()) { throw new PatchingException(PatchLogger.ROOT_LOGGER.fileDoesNotExist(file.getAbsolutePath())); } }
private static void assertUpgrade(final PatchType patchType) throws PatchingException { if (!PatchType.CUMULATIVE.equals(patchType)) { throw new PatchingException("Merging one-off patches is not supported at this point."); } }
static File createTempDir(final File parent) throws PatchingException { File workDir = null; int count = 0; while (workDir == null || workDir.exists()) { count++; workDir = new File(parent == null ? TEMP_DIR : parent, DIRECTORY_PREFIX + count); } if (!workDir.mkdirs()) { throw new PatchingException(PatchLogger.ROOT_LOGGER.cannotCreateDirectory(workDir.getAbsolutePath())); } return workDir; }
private String getAppliedAt(File patchDir) throws PatchingException { File timestampFile = new File(patchDir, Constants.TIMESTAMP); try { return timestampFile.exists() ? PatchUtils.readRef(timestampFile) : null; } catch (IOException e) { throw new PatchingException(PatchLogger.ROOT_LOGGER.fileIsNotReadable(timestampFile.getAbsolutePath())); } }
private String getAppliedAt(File patchDir) throws PatchingException { File timestampFile = new File(patchDir, Constants.TIMESTAMP); try { return timestampFile.exists() ? PatchUtils.readRef(timestampFile) : null; } catch (IOException e) { throw new PatchingException(PatchLogger.ROOT_LOGGER.fileIsNotReadable(timestampFile.getAbsolutePath())); } }
protected ModelNode executeOp(Operation operation) throws PatchingException { try { return client.execute(operation); } catch (IOException e) { throw new PatchingException("Failed to execute operation " + operation.getOperation(), e); } } }
@Override public final PatchingException doesNotApply(final String appliesTo, final String version) { final PatchingException result = new PatchingException(String.format(getLoggingLocale(), doesNotApply$str(), appliesTo, version)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String failedToDelete = "WFLYPAT0004: Failed to delete (%s)";
@Override public final PatchingException cannotCopyFilesToTempDir(final String tempDir, final String reason, final Throwable cause) { final PatchingException result = new PatchingException(String.format(getLoggingLocale(), cannotCopyFilesToTempDir$str(), tempDir, reason), cause); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String cannotCopyFiles = "WFLYPAT0047: Cannot copy files from %s to %s: %s";
@Override public final PatchingException alreadyApplied(final String patchId) { final PatchingException result = new PatchingException(String.format(getLoggingLocale(), alreadyApplied$str(), patchId)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String noSuchLayer = "WFLYPAT0013: There is no layer called %s installed";
@Override public final PatchingException noSuchLayer(final String name) { final PatchingException result = new PatchingException(String.format(getLoggingLocale(), noSuchLayer$str(), name)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String failedToResolvePatch = "WFLYPAT0014: Failed to resolve a valid patch descriptor for %s %s";
@Override public final PatchingException failedToResolvePatch(final String product, final String version) { final PatchingException result = new PatchingException(String.format(getLoggingLocale(), failedToResolvePatch$str(), product, version)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String requiresPatch = "WFLYPAT0015: Requires patch '%s'";
@Override public final PatchingException cannotRollbackPatch(final String id) { final PatchingException result = new PatchingException(String.format(getLoggingLocale(), cannotRollbackPatch$str(), id)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String alreadyApplied = "WFLYPAT0012: Patch '%s' already applied";
@Override public final PatchingException alreadyApplied(final String patchId) { final PatchingException result = new PatchingException(String.format(getLoggingLocale(), alreadyApplied$str(), patchId)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String noSuchLayer = "WFLYPAT0013: There is no layer called %s installed";
private InstalledIdentity loadIdentity(String productName, String productVersion) throws PatchingException { try { return LayersFactory.load(installedImage, new ProductConfig(productName, productVersion == null ? Constants.UNKNOWN : productVersion, null), moduleRoots, bundleRoots); } catch (IOException e) { throw new PatchingException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(productName), e); } }
@Override public Iterator iterator(boolean excludeAgedOut) throws PatchingException { try { return iterator(installedIdentity.getIdentity().loadTargetInfo(), excludeAgedOut); } catch (IOException e) { throw new PatchingException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(installedIdentity.getIdentity().getName()), e); } }
@Override public ModelNode getHistory(boolean excludeAgedOut) throws PatchingException { try { return getHistory(installedIdentity.getIdentity().loadTargetInfo(), excludeAgedOut); } catch (IOException e) { throw new PatchingException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(installedIdentity.getIdentity().getName()), e); } }
@Override public Iterator iterator(boolean excludeAgedOut) throws PatchingException { try { return iterator(installedIdentity.getIdentity().loadTargetInfo(), excludeAgedOut); } catch (IOException e) { throw new PatchingException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(installedIdentity.getIdentity().getName()), e); } }