Squish: Correct handling of global scripts

Global scripts get registered to the server. If we have valid
squish settings we are able to automatically re-open them.

Change-Id: Iaeed2629dac30b786b6e8faf371bc6987a4a5681
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2022-10-12 13:41:17 +02:00
parent fc24f5c26d
commit 39441654d8
7 changed files with 84 additions and 3 deletions

View File

@@ -444,6 +444,24 @@ void SquishFileHandler::addSharedFolder()
emit testTreeItemCreated(item);
}
void SquishFileHandler::setSharedFolders(const Utils::FilePaths &folders)
{
emit clearedSharedFolders();
m_sharedFolders.clear();
for (const Utils::FilePath &folder : folders) {
if (m_sharedFolders.contains(folder))
continue;
m_sharedFolders.append(folder);
SquishTestTreeItem *item = new SquishTestTreeItem(folder.toUserOutput(),
SquishTestTreeItem::SquishSharedFolder);
item->setFilePath(folder);
addAllEntriesRecursively(item);
emit testTreeItemCreated(item);
}
}
bool SquishFileHandler::removeSharedFolder(const Utils::FilePath &folder)
{
if (m_sharedFolders.contains(folder))

View File

@@ -29,11 +29,13 @@ public:
void runTestSuite(const QString &suiteName);
void recordTestCase(const QString &suiteName, const QString &testCaseName);
void addSharedFolder();
void setSharedFolders(const Utils::FilePaths &folders);
bool removeSharedFolder(const Utils::FilePath &folder);
void removeAllSharedFolders();
void openObjectsMap(const QString &suiteName);
signals:
void clearedSharedFolders();
void testTreeItemCreated(SquishTestTreeItem *item);
void suiteTreeItemRemoved(const QString &suiteName);
void suiteTreeItemModified(SquishTestTreeItem *item, const QString &displayName);

View File

@@ -4,7 +4,7 @@
#include "squishplugin.h"
#include "objectsmapeditor.h"
#include "squish/squishwizardpages.h"
#include "squishfilehandler.h"
#include "squishnavigationwidget.h"
#include "squishoutputpane.h"
#include "squishresultmodel.h"
@@ -12,6 +12,7 @@
#include "squishtesttreemodel.h"
#include "squishtools.h"
#include "squishtr.h"
#include "squishwizardpages.h"
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
@@ -21,6 +22,7 @@
#include <projectexplorer/jsonwizard/jsonwizardfactory.h>
#include <utils/algorithm.h>
#include <utils/mimetypes/mimedatabase.h>
#include <utils/qtcassert.h>
@@ -39,6 +41,7 @@ public:
~SquishPluginPrivate();
void initializeMenuEntries();
bool initializeGlobalScripts();
SquishSettings m_squishSettings;
SquishSettingsPage m_settingsPage{&m_squishSettings};
@@ -102,6 +105,27 @@ void SquishPluginPrivate::initializeMenuEntries()
toolsMenu->addMenu(menu);
}
bool SquishPluginPrivate::initializeGlobalScripts()
{
QTC_ASSERT(dd->m_squishTools, return false);
const Utils::FilePath squishserver = dd->m_squishSettings.squishPath.filePath().pathAppended(
Utils::HostOsInfo::withExecutableSuffix("bin/squishserver"));
if (!squishserver.isExecutableFile())
return false;
dd->m_squishTools->queryGlobalScripts([](const QString &output, const QString &error) {
if (output.isEmpty() || !error.isEmpty())
return; // ignore (for now?)
// FIXME? comma, special characters in paths
const Utils::FilePaths globalDirs = Utils::transform(
output.trimmed().split(',', Qt::SkipEmptyParts), &Utils::FilePath::fromString);
SquishFileHandler::instance()->setSharedFolders(globalDirs);
});
return true;
}
bool SquishPlugin::initialize(const QStringList &, QString *)
{
dd = new SquishPluginPrivate;
@@ -109,6 +133,11 @@ bool SquishPlugin::initialize(const QStringList &, QString *)
return true;
}
bool SquishPlugin::delayedInitialize()
{
return dd->initializeGlobalScripts();
}
ExtensionSystem::IPlugin::ShutdownFlag SquishPlugin::aboutToShutdown()
{
if (dd->m_squishTools) {

View File

@@ -23,6 +23,7 @@ public:
static SquishSettings *squishSettings();
bool initialize(const QStringList &arguments, QString *errorString) override;
bool delayedInitialize() override;
ShutdownFlag aboutToShutdown() override;
};

View File

@@ -186,6 +186,9 @@ SquishTestTreeModel::SquishTestTreeModel(QObject *parent)
&SquishFileHandler::suiteTreeItemRemoved,
this,
&SquishTestTreeModel::onSuiteTreeItemRemoved);
connect(m_squishFileHandler,
&SquishFileHandler::clearedSharedFolders,
this, [this]() { m_squishSharedFolders->removeChildren(); });
m_instance = this;
}

View File

@@ -260,11 +260,22 @@ void SquishTools::runTestCases(const FilePath &suitePath,
startSquishServer(RunTestRequested);
}
void SquishTools::queryGlobalScripts(QueryCallback callback)
{
m_queryCallback = callback;
queryServer(GetGlobalScriptDirs);
}
void SquishTools::queryServerSettings(QueryCallback callback)
{
m_queryCallback = callback;
queryServer(ServerInfo);
}
void SquishTools::queryServer(RunnerQuery query)
{
if (m_shutdownInitiated)
return;
m_queryCallback = callback;
if (m_state != Idle) {
QMessageBox::critical(Core::ICore::dialogParent(),
@@ -276,6 +287,7 @@ void SquishTools::queryServerSettings(QueryCallback callback)
}
m_perspective.setPerspectiveMode(SquishPerspective::Querying);
m_fullRunnerOutput.clear();
m_query = query;
startSquishServer(RunnerQueryRequested);
}
@@ -663,7 +675,18 @@ void SquishTools::executeRunnerQuery()
if (!isValidToStartRunner() || !setupRunnerPath())
return;
setupAndStartSquishRunnerProcess({ "--port", QString::number(m_serverPort), "--info", "all"});
QStringList arguments = { "--port", QString::number(m_serverPort) };
switch (m_query) {
case ServerInfo:
arguments << "--info" << "all";
break;
case GetGlobalScriptDirs:
arguments << "--config" << "getGlobalScriptDirs";
break;
default:
QTC_ASSERT(false, return);
}
setupAndStartSquishRunnerProcess(arguments);
}
Environment SquishTools::squishEnvironment()

View File

@@ -68,6 +68,7 @@ public:
const QStringList &testCases = QStringList());
void recordTestCase(const Utils::FilePath &suitePath, const QString &testCaseName,
const SuiteConf &suiteConf);
void queryGlobalScripts(QueryCallback callback);
void queryServerSettings(QueryCallback callback);
void writeServerSettingsChanges(const QList<QStringList> &changes);
void requestExpansion(const QString &name);
@@ -98,6 +99,8 @@ private:
KillOldBeforeQueryRunner
};
enum RunnerQuery { ServerInfo, GetGlobalScriptDirs };
void setState(State state);
void handleSetStateStartAppRunner();
void handleSetStateQueryRunner();
@@ -107,6 +110,7 @@ private:
void startSquishRunner();
void setupAndStartRecorder();
void stopRecorder();
void queryServer(RunnerQuery query);
void executeRunnerQuery();
static Utils::Environment squishEnvironment();
void onServerFinished();
@@ -163,6 +167,7 @@ private:
qint64 m_readResultsCount;
int m_autId = 0;
QueryCallback m_queryCallback;
RunnerQuery m_query = ServerInfo;
bool m_shutdownInitiated = false;
bool m_closeRunnerOnEndRecord = false;
bool m_licenseIssues = false;