forked from qt-creator/qt-creator
Squish: Support scripted objects map
Change-Id: I3ad0e43dcd7e542ac51eb7be8add0f55ee6e090d Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -27,9 +27,12 @@
|
|||||||
|
|
||||||
#include "objectsmaptreeitem.h"
|
#include "objectsmaptreeitem.h"
|
||||||
#include "squishconstants.h"
|
#include "squishconstants.h"
|
||||||
|
#include "squishplugin.h"
|
||||||
|
#include "squishsettings.h"
|
||||||
#include "squishtr.h"
|
#include "squishtr.h"
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
#include <utils/qtcprocess.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
@@ -206,11 +209,35 @@ Core::IDocument::OpenResult ObjectsMapDocument::openImpl(QString *error,
|
|||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
return OpenResult::CannotHandle;
|
return OpenResult::CannotHandle;
|
||||||
|
|
||||||
|
QString text;
|
||||||
|
if (realFileName.fileName() == "objects.map") {
|
||||||
Utils::FileReader reader;
|
Utils::FileReader reader;
|
||||||
if (!reader.fetch(realFileName, QIODevice::Text, error))
|
if (!reader.fetch(realFileName, QIODevice::Text, error))
|
||||||
return OpenResult::ReadError;
|
return OpenResult::ReadError;
|
||||||
|
|
||||||
const QString text = QString::fromLocal8Bit(reader.data());
|
text = QString::fromLocal8Bit(reader.data());
|
||||||
|
} else {
|
||||||
|
const Utils::FilePath base = SquishPlugin::squishSettings()->squishPath.filePath();
|
||||||
|
if (base.isEmpty()) {
|
||||||
|
if (error)
|
||||||
|
error->append(Tr::tr("Incomplete Squish settings. "
|
||||||
|
"Missing Squish installation path."));
|
||||||
|
return OpenResult::ReadError;
|
||||||
|
}
|
||||||
|
const Utils::FilePath exe = base.pathAppended("lib/exec/objectmaptool").withExecutableSuffix();
|
||||||
|
if (!exe.isExecutableFile()) {
|
||||||
|
if (error)
|
||||||
|
error->append(Tr::tr("objectmaptool not found."));
|
||||||
|
return OpenResult::ReadError;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils::QtcProcess objectMapReader;
|
||||||
|
objectMapReader.setCommand({exe, {"--scriptMap", "--mode", "read",
|
||||||
|
"--scriptedObjectMapPath", realFileName.toUserOutput()}});
|
||||||
|
objectMapReader.start();
|
||||||
|
objectMapReader.waitForFinished();
|
||||||
|
text = objectMapReader.cleanedStdOut();
|
||||||
|
}
|
||||||
if (!setContents(text.toUtf8())) {
|
if (!setContents(text.toUtf8())) {
|
||||||
if (error)
|
if (error)
|
||||||
error->append(Tr::tr("Failure while parsing objects.map content."));
|
error->append(Tr::tr("Failure while parsing objects.map content."));
|
||||||
@@ -221,8 +248,26 @@ Core::IDocument::OpenResult ObjectsMapDocument::openImpl(QString *error,
|
|||||||
|
|
||||||
bool ObjectsMapDocument::writeFile(const Utils::FilePath &fileName) const
|
bool ObjectsMapDocument::writeFile(const Utils::FilePath &fileName) const
|
||||||
{
|
{
|
||||||
|
if (fileName.endsWith("object.map")) {
|
||||||
Utils::FileSaver saver(fileName);
|
Utils::FileSaver saver(fileName);
|
||||||
return saver.write(contents()) && saver.finalize();
|
return saver.write(contents()) && saver.finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise we need the objectmaptool to write the scripted object map again
|
||||||
|
const Utils::FilePath base = SquishPlugin::squishSettings()->squishPath.filePath();
|
||||||
|
if (base.isEmpty())
|
||||||
|
return false;
|
||||||
|
const Utils::FilePath exe = base.pathAppended("lib/exec/objectmaptool").withExecutableSuffix();
|
||||||
|
if (!exe.isExecutableFile())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Utils::QtcProcess objectMapWriter;
|
||||||
|
objectMapWriter.setCommand({exe, {"--scriptMap", "--mode", "write",
|
||||||
|
"--scriptedObjectMapPath", fileName.toUserOutput()}});
|
||||||
|
objectMapWriter.setWriteData(contents());
|
||||||
|
objectMapWriter.start();
|
||||||
|
objectMapWriter.waitForFinished();
|
||||||
|
return objectMapWriter.result() == Utils::ProcessResult::FinishedWithSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ namespace Internal {
|
|||||||
const char squishLanguageKey[] = "LANGUAGE";
|
const char squishLanguageKey[] = "LANGUAGE";
|
||||||
const char squishTestCasesKey[] = "TEST_CASES";
|
const char squishTestCasesKey[] = "TEST_CASES";
|
||||||
const char objectsMapKey[] = "OBJECTMAP";
|
const char objectsMapKey[] = "OBJECTMAP";
|
||||||
|
const char objectMapStyleKey[] = "OBJECTMAPSTYLE";
|
||||||
|
|
||||||
QStringList SquishUtils::validTestCases(const QString &baseDirectory)
|
QStringList SquishUtils::validTestCases(const QString &baseDirectory)
|
||||||
{
|
{
|
||||||
@@ -77,7 +78,15 @@ QString SquishUtils::objectsMapPath(const QString &suitePath)
|
|||||||
{
|
{
|
||||||
const QString suiteDir = QFileInfo(suitePath).absolutePath();
|
const QString suiteDir = QFileInfo(suitePath).absolutePath();
|
||||||
const QSettings suiteConf(suitePath, QSettings::IniFormat);
|
const QSettings suiteConf(suitePath, QSettings::IniFormat);
|
||||||
const QString objMapPath = suiteConf.value(objectsMapKey).toString();
|
|
||||||
|
const QString style = suiteConf.value(objectMapStyleKey).toString();
|
||||||
|
if (style == "script") {
|
||||||
|
const QString language = suiteConf.value(squishLanguageKey).toString();
|
||||||
|
return QFileInfo(suiteDir, "shared/scripts/names" + extensionForLanguage(language))
|
||||||
|
.canonicalFilePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString objMapPath = suiteConf.value(objectsMapKey, "objects.map").toString();
|
||||||
return QFileInfo(suiteDir, objMapPath).canonicalFilePath();
|
return QFileInfo(suiteDir, objMapPath).canonicalFilePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user