Test fixes

This commit is contained in:
dragonmacher 2023-11-24 14:11:43 -05:00
parent 7ee84802b8
commit f4026c2bea
4 changed files with 81 additions and 81 deletions

View file

@ -43,7 +43,7 @@ import utility.application.ApplicationLayout;
* <li>createdOn (format: MM/dd/yyyy)</li>
* <li>version</li>
* </ul>
*
*
* <p>
* Extensions may be installed/uninstalled by users at runtime, using the
* {@link ExtensionTableProvider}. Installation consists of unzipping the extension archive to an
@ -57,7 +57,7 @@ public class ExtensionInstaller {
/**
* Installs the given extension file. This can be either an archive (zip) or a directory that
* contains an extension.properties file.
*
*
* @param file the extension to install
* @return true if the extension was successfully installed
*/
@ -121,8 +121,7 @@ public class ExtensionInstaller {
String archivePath = extension.getArchivePath();
if (archivePath == null) {
log.error(
"Cannot install from archive; extension is missing archive path");
log.error("Cannot install from archive; extension is missing archive path");
return false;
}
@ -143,7 +142,7 @@ public class ExtensionInstaller {
* Compares the given extension version to the current Ghidra version. If they are different,
* then the user will be prompted to confirm the installation. This method will return true
* if the versions match or the user has chosen to install anyway.
*
*
* @param extension the extension
* @return true if the versions match or the user has chosen to install anyway
*/
@ -161,9 +160,7 @@ public class ExtensionInstaller {
String message = "Extension version mismatch.\nName: " + extension.getName() +
"Extension version: " + extVersion + ".\nGhidra version: " + appVersion + ".";
int choice = OptionDialog.showOptionDialogWithCancelAsDefaultButton(null,
"Extension Version Mismatch",
message,
"Install Anyway");
"Extension Version Mismatch", message, "Install Anyway");
if (choice != OptionDialog.OPTION_ONE) {
log.info(removeNewlines(message + " Did not install"));
return false;
@ -201,16 +198,12 @@ public class ExtensionInstaller {
"Installed extension version: " + installedExtension.getVersion() + ".\n\n" +
"To install, click 'Remove Existing', restart Ghidra, then install again.";
int choice = OptionDialog.showOptionDialogWithCancelAsDefaultButton(null,
"Duplicate Extension",
message,
"Remove Existing");
"Duplicate Extension", message, "Remove Existing");
String installPath = installedExtension.getInstallPath();
if (choice != OptionDialog.OPTION_ONE) {
log.info(
removeNewlines(
message + " Skipping installation. Original extension still installed: " +
installPath));
log.info(removeNewlines(message +
" Skipping installation. Original extension still installed: " + installPath));
return true;
}
@ -218,10 +211,9 @@ public class ExtensionInstaller {
// At this point the user would like to replace the existing extension. We cannot delete
// the existing extension, as it may be in use; mark it for removal.
//
log.info(
removeNewlines(
message + " Installing new extension. Existing extension will be removed after " +
"restart: " + installPath));
log.info(removeNewlines(
message + " Installing new extension. Existing extension will be removed after " +
"restart: " + installPath));
installedExtension.markForUninstall();
return true;
}

View file

@ -60,6 +60,9 @@ public class ExtensionInstallerTest extends AbstractDockingTest {
setErrorGUIEnabled(false);
// clear static caching of extensions
ExtensionUtils.clearCache();
appLayout = Application.getApplicationLayout();
FileUtilities.deleteDir(appLayout.getExtensionArchiveDir().getFile(false));
@ -290,7 +293,7 @@ public class ExtensionInstallerTest extends AbstractDockingTest {
//=================================================================================================
// Edge Cases
//=================================================================================================
//=================================================================================================
@Test
public void testInstallingNewExtension_SameName_NewVersion() throws Exception {
@ -317,8 +320,7 @@ public class ExtensionInstallerTest extends AbstractDockingTest {
didInstall.set(ExtensionInstaller.install(extensionFolder2));
});
DialogComponentProvider confirmDialog =
waitForDialogComponent("Duplicate Extension");
DialogComponentProvider confirmDialog = waitForDialogComponent("Duplicate Extension");
pressButtonByText(confirmDialog, "Remove Existing");
waitForSwing();
@ -333,7 +335,7 @@ public class ExtensionInstallerTest extends AbstractDockingTest {
didInstall.set(ExtensionInstaller.install(extensionFolder2));
});
// no longer an installed extension conflict; now we have a version mismatch
// no longer an installed extension conflict; now we have a version mismatch
confirmDialog = waitForDialogComponent("Extension Version Mismatch");
pressButtonByText(confirmDialog, "Install Anyway");
@ -363,8 +365,7 @@ public class ExtensionInstallerTest extends AbstractDockingTest {
didInstall.set(ExtensionInstaller.install(extensionFolder2));
});
DialogComponentProvider confirmDialog =
waitForDialogComponent("Duplicate Extension");
DialogComponentProvider confirmDialog = waitForDialogComponent("Duplicate Extension");
pressButtonByText(confirmDialog, "Cancel");
waitForSwing();
@ -397,8 +398,7 @@ public class ExtensionInstallerTest extends AbstractDockingTest {
didInstall.set(ExtensionInstaller.install(extensionFolder2));
});
DialogComponentProvider confirmDialog =
waitForDialogComponent("Duplicate Extension");
DialogComponentProvider confirmDialog = waitForDialogComponent("Duplicate Extension");
pressButtonByText(confirmDialog, "Remove Existing");
waitForSwing();
@ -426,14 +426,14 @@ public class ExtensionInstallerTest extends AbstractDockingTest {
/*
Create a zip file that looks something like this:
/
{Extension Name 1}/
extension.properties
{Extension Name 2}/
extension.properties
*/
errorsExpected(() -> {
@ -446,9 +446,9 @@ public class ExtensionInstallerTest extends AbstractDockingTest {
public void testInstallThenUninstallThenReinstallWhenExtensionNameDoesntMatchFolder()
throws Exception {
// This tests a previous failure case where an extension could not be reinstalled if its
// This tests a previous failure case where an extension could not be reinstalled if its
// name did not match the folder it was installed into. This could happen because the code
// that installed the extension did not match the code to clear the 'mark for uninstall'
// that installed the extension did not match the code to clear the 'mark for uninstall'
// condition.
String nameProperty = "ExtensionNamedFoo";
@ -493,10 +493,9 @@ public class ExtensionInstallerTest extends AbstractDockingTest {
private void assertExtensionNotInstalled(String name, String version) {
Set<ExtensionDetails> extensions = ExtensionUtils.getInstalledExtensions();
Optional<ExtensionDetails> match =
extensions.stream()
.filter(e -> e.getName().equals(name) && e.getVersion().equals(version))
.findFirst();
Optional<ExtensionDetails> match = extensions.stream()
.filter(e -> e.getName().equals(name) && e.getVersion().equals(version))
.findFirst();
assertFalse("Extension should not be installed: '" + name + "'", match.isPresent());
}
@ -594,8 +593,7 @@ public class ExtensionInstallerTest extends AbstractDockingTest {
}
private File doCreateExternalExtensionInFolder(File externalFolder, String extensionName,
String version)
throws Exception {
String version) throws Exception {
return doCreateExternalExtensionInFolder(externalFolder, extensionName, extensionName,
version);
}
@ -609,9 +607,8 @@ public class ExtensionInstallerTest extends AbstractDockingTest {
version);
}
private File doCreateExternalExtensionInFolder(File externalFolder,
String extensionName, String nameProperty, String version)
throws Exception {
private File doCreateExternalExtensionInFolder(File externalFolder, String extensionName,
String nameProperty, String version) throws Exception {
ResourceFile root = new ResourceFile(new ResourceFile(externalFolder), extensionName);
root.mkdir();