public static byte[] getAbsentModuleContent(final ModuleItem item) { final StringBuilder builder = new StringBuilder(128); builder.append("<?xml version='1.0' encoding='UTF-8'?>\n<module-absent xmlns=\"urn:jboss:module:1.2\""); builder.append(" name=\"").append(item.getName()).append("\""); builder.append(" slot=\"").append(item.getSlot()).append("\""); builder.append(" />\n"); return builder.toString().getBytes(StandardCharsets.UTF_8); }
public static byte[] getAbsentModuleContent(final ModuleItem item) { final StringBuilder builder = new StringBuilder(128); builder.append("<?xml version='1.0' encoding='UTF-8'?>\n<module-absent xmlns=\"urn:jboss:module:1.2\""); builder.append(" name=\"").append(item.getName()).append("\""); builder.append(" slot=\"").append(item.getSlot()).append("\""); builder.append(" />\n"); return builder.toString().getBytes(StandardCharsets.UTF_8); }
public static File getModulePath(File root, ModuleItem item) { return getModulePath(root, item.getName(), item.getSlot()); }
void disableBaseModule(final ModuleItem item) throws IOException { if(modulesToDisable.isEmpty()) { modulesToDisable = new ArrayList<File>(); } final File modulePath = PatchContentLoader.getModulePath(getDirectoryStructure().getModuleRoot(), item.getName(), ((ModuleItem)item).getSlot()); final List<File> files = listFiles(modulePath); if (files != null && files.size() > 0) { for (final File file : files) { modulesToDisable.add(file); } } }
public static File getModulePath(File root, ModuleItem item) { return getModulePath(root, item.getName(), item.getSlot()); }
void disableBaseModule(final ModuleItem item) throws IOException { if(modulesToDisable.isEmpty()) { modulesToDisable = new ArrayList<File>(); } final File modulePath = PatchContentLoader.getModulePath(getDirectoryStructure().getModuleRoot(), item.getName(), ((ModuleItem)item).getSlot()); final List<File> files = listFiles(modulePath); if (files != null && files.size() > 0) { for (final File file : files) { modulesToDisable.add(file); } } }
void reenableBaseModule(final ModuleItem item) throws IOException { if(modulesToReenable.isEmpty()) { modulesToReenable = new ArrayList<File>(); } final File modulePath = PatchContentLoader.getModulePath(getDirectoryStructure().getModuleRoot(), item.getName(), ((ModuleItem)item).getSlot()); final List<File> files = listFiles(modulePath); if (files != null && files.size() > 0) { for (final File file : files) { modulesToReenable.add(file); } } }
static ModuleItem createContentItem(final ModuleItem original, final byte[] contentHash) { final ContentType type = original.getContentType(); if(type == ContentType.BUNDLE) { return new BundleItem(original.getName(), original.getSlot(), contentHash); } else { return new ModuleItem(original.getName(), original.getSlot(), contentHash); } }
void reenableBaseModule(final ModuleItem item) throws IOException { if(modulesToReenable.isEmpty()) { modulesToReenable = new ArrayList<File>(); } final File modulePath = PatchContentLoader.getModulePath(getDirectoryStructure().getModuleRoot(), item.getName(), ((ModuleItem)item).getSlot()); final List<File> files = listFiles(modulePath); if (files != null && files.size() > 0) { for (final File file : files) { modulesToReenable.add(file); } } }
static ModuleItem createContentItem(final ModuleItem original, final byte[] contentHash) { final ContentType type = original.getContentType(); if(type == ContentType.BUNDLE) { return new BundleItem(original.getName(), original.getSlot(), contentHash); } else { return new ModuleItem(original.getName(), original.getSlot(), contentHash); } }
@Override byte[] backup(PatchingTaskContext context) throws IOException { final File[] repoRoots = context.getTargetModulePath(); final String moduleName = contentItem.getName(); final String slot = contentItem.getSlot(); for(final File path : repoRoots) { // Find the first module and calculate the hash final File modulePath = PatchContentLoader.getModulePath(path, moduleName, slot); final File moduleXml = new File(modulePath, MODULE_XML); if(moduleXml.exists()) { PatchLogger.ROOT_LOGGER.debugf("found in path (%s)", moduleXml.getAbsolutePath()); context.invalidateRoot(modulePath); return HashUtils.hashFile(modulePath); } } return notFound(contentItem); }
@Override byte[] backup(PatchingTaskContext context) throws IOException { final File[] repoRoots = context.getTargetModulePath(); final String moduleName = contentItem.getName(); final String slot = contentItem.getSlot(); for(final File path : repoRoots) { // Find the first module and calculate the hash final File modulePath = PatchContentLoader.getModulePath(path, moduleName, slot); final File moduleXml = new File(modulePath, MODULE_XML); if(moduleXml.exists()) { PatchLogger.ROOT_LOGGER.debugf("found in path (%s)", moduleXml.getAbsolutePath()); context.invalidateRoot(modulePath); return HashUtils.hashFile(modulePath); } } return notFound(contentItem); }
modSrcDir = new File(modSrcDir, Constants.MODULES); modTrgDir = new File(modTrgDir, Constants.MODULES); slot = ((ModuleItem)mod.getItem()).getSlot(); } else if (contentType.equals(ContentType.BUNDLE)) { modSrcDir = new File(modSrcDir, Constants.BUNDLES);
static int hashCode(final ContentItem item) { final ContentType type = item.getContentType(); switch (type) { case MODULE: case BUNDLE: final ModuleItem module = (ModuleItem) item; final String[] path = module.getName().split("\\."); return hashCode(type.toString(), module.getSlot(), path); case MISC: final MiscContentItem misc = (MiscContentItem) item; return hashCode(type.toString(), misc.getName(), misc.getPath()); default: throw new IllegalStateException(); } }
static int hashCode(final ContentItem item) { final ContentType type = item.getContentType(); switch (type) { case MODULE: case BUNDLE: final ModuleItem module = (ModuleItem) item; final String[] path = module.getName().split("\\."); return hashCode(type.toString(), module.getSlot(), path); case MISC: final MiscContentItem misc = (MiscContentItem) item; return hashCode(type.toString(), misc.getName(), misc.getPath()); default: throw new IllegalStateException(); } }
@Override protected ContentModification getOriginalModification(byte[] targetHash, byte[] itemHash) { final ModuleItem original = getContentItem(); final ModuleItem item = new ModuleItem(original.getName(), original.getSlot(), targetHash); return new ContentModification(item, description.getModification().getTargetHash(), ModificationType.MODIFY, description.getModification().getCondition()); }
@Override protected ContentModification getOriginalModification(byte[] targetHash, byte[] itemHash) { final ModuleItem original = getContentItem(); final ModuleItem item = new ModuleItem(original.getName(), original.getSlot(), targetHash); return new ContentModification(item, description.getModification().getTargetHash(), ModificationType.MODIFY, description.getModification().getCondition()); }
protected static void writeSlottedItem(final XMLExtendedStreamWriter writer, Element element, ContentModification modification) throws XMLStreamException { writer.writeEmptyElement(element.name); final ModuleItem item = (ModuleItem) modification.getItem(); final ModificationType type = modification.getType(); writer.writeAttribute(Attribute.NAME.name, item.getName()); if (!MAIN_SLOT.equals(item.getSlot())) { writer.writeAttribute(Attribute.SLOT.name, item.getSlot()); } byte[] hash = item.getContentHash(); if (hash.length > 0 && type != ModificationType.REMOVE) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(hash)); } if(type == ModificationType.REMOVE) { final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(existingHash)); } } else if(type == ModificationType.MODIFY) { final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.NEW_HASH.name, bytesToHexString(existingHash)); } } }
protected static void writeSlottedItem(final XMLExtendedStreamWriter writer, Element element, ContentModification modification) throws XMLStreamException { writer.writeEmptyElement(element.name); final ModuleItem item = (ModuleItem) modification.getItem(); final ModificationType type = modification.getType(); writer.writeAttribute(Attribute.NAME.name, item.getName()); if (!MAIN_SLOT.equals(item.getSlot())) { writer.writeAttribute(Attribute.SLOT.name, item.getSlot()); } byte[] hash = item.getContentHash(); if (hash.length > 0 && type != ModificationType.REMOVE) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(hash)); } if(type == ModificationType.REMOVE) { final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.HASH.name, bytesToHexString(existingHash)); } } else if(type == ModificationType.MODIFY) { final byte[] existingHash = modification.getTargetHash(); if (existingHash.length > 0) { writer.writeAttribute(Attribute.NEW_HASH.name, bytesToHexString(existingHash)); } } }