final PatchableTarget.TargetInfo identityInfo = identity.loadTargetInfo(); final InstallationModificationImpl.InstallationState state = load(this); return new InstallationModificationImpl(identityInfo, identity.getName(), identity.getVersion(), this.getAllInstalledPatches(), state) {
@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); } }
private static void assertExistsOnDisk(IteratorImpl i, String id) throws NoSuchElementException { final File historyDir = i.mgr.getInstalledImage().getPatchHistoryDir(id); if(!historyDir.exists()) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.noPatchHistory(historyDir.getAbsolutePath())); } // TODO parsed xml can be cached final File rollbackXml = new File(historyDir, "rollback.xml"); if(!rollbackXml.exists()) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.patchIsMissingFile(rollbackXml.getAbsolutePath())); } try { PatchXml.parse(rollbackXml); } catch (Exception e) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.fileIsNotReadable(rollbackXml.getAbsolutePath() + ": " + e.getLocalizedMessage())); } final File patchXml = new File(historyDir, "patch.xml"); if(!patchXml.exists()) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.patchIsMissingFile(patchXml.getAbsolutePath())); } final Patch patchMetaData; try { patchMetaData = PatchXml.parse(patchXml).resolvePatch(i.mgr.getIdentity().getName(), i.mgr.getIdentity().getVersion()); } catch (Exception e) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.fileIsNotReadable(patchXml.getAbsolutePath() + ": " + e.getLocalizedMessage())); } if(i.excludeAgedOut && isAgedOut(i.mgr, patchMetaData)) { throw new NoSuchElementException("Patch " + patchMetaData.getPatchId() + " was aged out"); } }
@Override void handle(ModelNode result, Identity info) throws IOException { result.set(info.loadTargetInfo().getCumulativePatchID()); } });
@Override public List<String> getPatchStreams() throws PatchingException { final List<InstalledIdentity> installedIdentities = manager.getInstalledIdentities(); if(installedIdentities.size() == 1) { return Collections.singletonList(installedIdentities.get(0).getIdentity().getName()); } final List<String> result = new ArrayList<String>(installedIdentities.size()); for(InstalledIdentity ii : installedIdentities) { result.add(ii.getIdentity().getName()); } return result; }
public static void assertPatchHasBeenRolledBack(PatchingResult result, Identity expectedIdentity) throws IOException { assertEquals(expectedIdentity.getVersion(), result.getPatchInfo().getVersion()); assertEquals(expectedIdentity.loadTargetInfo().getCumulativePatchID(), result.getPatchInfo().getCumulativePatchID()); assertEquals(expectedIdentity.loadTargetInfo().getPatchIDs(), result.getPatchInfo().getPatchIDs()); }
@Override void handle(ModelNode result, Identity info) { result.set(info.getVersion()); } });
break; default: dirStructure = originalIdentity.getIdentity().getDirectoryStructure();
private static void assertExistsOnDisk(IteratorImpl i, String id) throws NoSuchElementException { final File historyDir = i.mgr.getInstalledImage().getPatchHistoryDir(id); if(!historyDir.exists()) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.noPatchHistory(historyDir.getAbsolutePath())); } // TODO parsed xml can be cached final File rollbackXml = new File(historyDir, "rollback.xml"); if(!rollbackXml.exists()) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.patchIsMissingFile(rollbackXml.getAbsolutePath())); } try { PatchXml.parse(rollbackXml); } catch (Exception e) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.fileIsNotReadable(rollbackXml.getAbsolutePath() + ": " + e.getLocalizedMessage())); } final File patchXml = new File(historyDir, "patch.xml"); if(!patchXml.exists()) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.patchIsMissingFile(patchXml.getAbsolutePath())); } final Patch patchMetaData; try { patchMetaData = PatchXml.parse(patchXml).resolvePatch(i.mgr.getIdentity().getName(), i.mgr.getIdentity().getVersion()); } catch (Exception e) { throw new NoSuchElementException(PatchLogger.ROOT_LOGGER.fileIsNotReadable(patchXml.getAbsolutePath() + ": " + e.getLocalizedMessage())); } if(i.excludeAgedOut && isAgedOut(i.mgr, patchMetaData)) { throw new NoSuchElementException("Patch " + patchMetaData.getPatchId() + " was aged out"); } }
@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 void handle(ModelNode result, Identity info) throws IOException { result.set(info.loadTargetInfo().getCumulativePatchID()); } });
@Override public List<String> getPatchStreams() throws PatchingException { final List<InstalledIdentity> installedIdentities = manager.getInstalledIdentities(); if(installedIdentities.size() == 1) { return Collections.singletonList(installedIdentities.get(0).getIdentity().getName()); } final List<String> result = new ArrayList<String>(installedIdentities.size()); for(InstalledIdentity ii : installedIdentities) { result.add(ii.getIdentity().getName()); } return result; }
@Override public PatchInfo getPatchInfo(String streamName) throws PatchingException { try { final InstalledIdentity installedIdentity = streamName == null ? manager.getDefaultIdentity() : manager.getInstalledIdentity(streamName, null); final PatchableTarget.TargetInfo info = installedIdentity.getIdentity().loadTargetInfo(); final VerbosePatchInfo.Builder infoBuilder = VerbosePatchInfo.builder() .setVersion(installedIdentity.getIdentity().getVersion()) .setCumulativePatchId(info.getCumulativePatchID()) .setPatchIds(info.getPatchIDs()); for(Layer layer : installedIdentity.getLayers()) { infoBuilder.addLayerInfo(layer.getName(), layer.loadTargetInfo()); } for(AddOn addon : installedIdentity.getAddOns()) { infoBuilder.addAddOnInfo(addon.getName(), addon.loadTargetInfo()); } return infoBuilder.build(); } catch (IOException e) { // why throw a rethrowException(e) ? throw new RuntimeException(e); } }
@Override void handle(ModelNode result, Identity info) { result.set(info.getVersion()); } });
break; default: dirStructure = originalIdentity.getIdentity().getDirectoryStructure();
final PatchableTarget.TargetInfo identityInfo = identity.loadTargetInfo(); final InstallationModificationImpl.InstallationState state = load(this); return new InstallationModificationImpl(identityInfo, identity.getName(), identity.getVersion(), this.getAllInstalledPatches(), state) {
final String defaultIdentityName = defaultIdentity.getIdentity().getName(); if(productName == null) { productName = defaultIdentityName; if(recordedProductVersion != null && !recordedProductVersion.equals(defaultIdentity.getIdentity().getVersion())) { if(productVersion != null && !defaultIdentity.getIdentity().getVersion().equals(productVersion)) { throw new PatchingException(PatchLogger.ROOT_LOGGER.productVersionDidNotMatchInstalled( productName, productVersion, defaultIdentity.getIdentity().getVersion()));
@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 void handle(ModelNode result, Identity info) throws IOException { result.setEmptyList(); for (final String id : info.loadTargetInfo().getPatchIDs()) { result.add(id); } } });
@Override public Set<String> children() { final InstallationManager manager = getInstallationManager(); if (manager == null) { return Collections.emptySet(); } List<InstalledIdentity> installedIdentities; try { installedIdentities = manager.getInstalledIdentities(); } catch (PatchingException e) { throw new IllegalStateException(e); } if(installedIdentities.size() == 1) { return Collections.singleton(installedIdentities.get(0).getIdentity().getName()); } final Set<String> set = new HashSet<String>(installedIdentities.size()); for(InstalledIdentity identity : installedIdentities) { set.add(identity.getIdentity().getName()); } return set; } }