From 3a4876f3ddcecb2b2d46c0c661ec8c34fc50d3ea Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Thu, 4 Jan 2024 13:02:48 -0500 Subject: [PATCH] Updated loosely informative error message --- .../util/extensions/ExtensionUtils.java | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/extensions/ExtensionUtils.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/extensions/ExtensionUtils.java index 8ba9a32cd5..3096d0e395 100644 --- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/extensions/ExtensionUtils.java +++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/extensions/ExtensionUtils.java @@ -23,6 +23,7 @@ import java.util.*; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipFile; import org.apache.commons.compress.utils.IOUtils; +import org.apache.commons.io.FilenameUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -287,15 +288,36 @@ public class ExtensionUtils { continue; } - if (results.contains(extension)) { - log.error("Skipping extension \"" + extension.getName() + "\" found at " + - extension.getInstallPath() + - ".\nArchived extension by that name already found."); + ExtensionDetails existingExtension = get(results, extension); + if (existingExtension == null) { + results.add(existingExtension); + continue; } - results.add(extension); + + // + // The extension was already found; report the conflict. This situation can easily + // happen if users add multiple builds of the same extension to the extensions dir. + // + String name = extension.getName(); + String newZip = FilenameUtils.getBaseName(extension.getArchivePath()); + String existingZip = FilenameUtils.getBaseName(existingExtension.getArchivePath()); + ResourceFile dir = file.getParentFile(); + + log.error(""" + Skipping extension '%s' found in zip '%s'. \ + Extension by that name already found in zip '%s'. \ + Archive dir %s + """.formatted(name, newZip, existingZip, dir)); } } + private static ExtensionDetails get(Set set, ExtensionDetails extension) { + if (set.contains(extension)) { + return set.stream().filter(e -> e.equals(extension)).findFirst().get(); + } + return null; + } + private static void findExtensionsInFolder(File dir, Set results) { List propFiles = findExtensionPropertyFiles(dir); for (File propFile : propFiles) {