forked from qt-creator/qt-creator
Implement an external tool container + xml parsing.
This commit is contained in:
@@ -107,4 +107,5 @@ tests/auto/qml/qmldesigner/bauhaustests/tst_bauhaus
|
||||
tests/auto/qml/qmldesigner/coretests/tst_qmldesigner_core
|
||||
tests/auto/qml/qmldesigner/propertyeditortests/tst_propertyeditor
|
||||
tests/auto/profilewriter/tst_profilewriter
|
||||
tests/auto/externaltool/tst_externaltool
|
||||
|
||||
|
||||
+4
-2
@@ -124,11 +124,13 @@ macx {
|
||||
|
||||
INCLUDEPATH += \
|
||||
$$IDE_SOURCE_TREE/src/libs \
|
||||
$$IDE_SOURCE_TREE/tools
|
||||
$$IDE_SOURCE_TREE/tools \
|
||||
$$IDE_SOURCE_TREE/src/plugins
|
||||
|
||||
DEPENDPATH += \
|
||||
$$IDE_SOURCE_TREE/src/libs \
|
||||
$$IDE_SOURCE_TREE/tools
|
||||
$$IDE_SOURCE_TREE/tools \
|
||||
$$IDE_SOURCE_TREE/src/plugins
|
||||
|
||||
LIBS += -L$$IDE_LIBRARY_PATH
|
||||
|
||||
|
||||
@@ -87,7 +87,8 @@ SOURCES += mainwindow.cpp \
|
||||
outputpanemanager.cpp \
|
||||
navigationsubwidget.cpp \
|
||||
sidebarwidget.cpp \
|
||||
rssfetcher.cpp
|
||||
rssfetcher.cpp \
|
||||
externaltool.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
editmode.h \
|
||||
@@ -172,7 +173,8 @@ HEADERS += mainwindow.h \
|
||||
outputpanemanager.h \
|
||||
navigationsubwidget.h \
|
||||
sidebarwidget.h \
|
||||
rssfetcher.h
|
||||
rssfetcher.h \
|
||||
externaltool.h
|
||||
|
||||
FORMS += dialogs/newdialog.ui \
|
||||
actionmanager/commandmappings.ui \
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "externaltool.h"
|
||||
|
||||
#include <QtCore/QXmlStreamReader>
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
using namespace Core::Internal;
|
||||
|
||||
namespace {
|
||||
const char * const kExternalTool = "externaltool";
|
||||
const char * const kDescription = "description";
|
||||
const char * const kDisplayName = "displayname";
|
||||
const char * const kCategory = "category";
|
||||
const char * const kOrder = "order";
|
||||
const char * const kExecutable = "executable";
|
||||
const char * const kPath = "path";
|
||||
const char * const kArguments = "arguments";
|
||||
const char * const kWorkingDirectory = "workingdirectory";
|
||||
|
||||
const char * const kXmlLang = "xml:lang";
|
||||
const char * const kOutput = "output";
|
||||
const char * const kOutputShowInPane = "showinpane";
|
||||
const char * const kOutputReplaceSelection = "replaceselection";
|
||||
const char * const kOutputReloadDocument = "reloaddocument";
|
||||
}
|
||||
|
||||
ExternalTool::ExternalTool() :
|
||||
m_order(-1),
|
||||
m_outputHandling(ShowInPane)
|
||||
{
|
||||
}
|
||||
|
||||
QString ExternalTool::description() const
|
||||
{
|
||||
return m_description;
|
||||
}
|
||||
|
||||
QString ExternalTool::displayName() const
|
||||
{
|
||||
return m_displayName;
|
||||
}
|
||||
|
||||
QString ExternalTool::displayCategory() const
|
||||
{
|
||||
return m_displayCategory;
|
||||
}
|
||||
|
||||
int ExternalTool::order() const
|
||||
{
|
||||
return m_order;
|
||||
}
|
||||
|
||||
QStringList ExternalTool::executables() const
|
||||
{
|
||||
return m_executables;
|
||||
}
|
||||
|
||||
QString ExternalTool::arguments() const
|
||||
{
|
||||
return m_arguments;
|
||||
}
|
||||
|
||||
QString ExternalTool::workingDirectory() const
|
||||
{
|
||||
return m_workingDirectory;
|
||||
}
|
||||
|
||||
ExternalTool::OutputHandling ExternalTool::outputHandling() const
|
||||
{
|
||||
return m_outputHandling;
|
||||
}
|
||||
|
||||
ExternalTool * ExternalTool::createFromXml(const QString &xml, QString *errorMessage)
|
||||
{
|
||||
ExternalTool *tool = new ExternalTool;
|
||||
QXmlStreamReader reader(xml);
|
||||
if (!reader.readNextStartElement() || reader.name() != QLatin1String(kExternalTool))
|
||||
reader.raiseError(QLatin1String("Missing start element <externaltool>"));
|
||||
while (reader.readNextStartElement()) {
|
||||
if (reader.name() == QLatin1String(kDescription)) {
|
||||
// TODO locale check
|
||||
if (!reader.attributes().hasAttribute(QLatin1String(kXmlLang))
|
||||
&& tool->m_description.isEmpty()) {
|
||||
tool->m_description = reader.readElementText();
|
||||
} else {
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
} else if (reader.name() == QLatin1String(kDisplayName)) {
|
||||
// TODO locale check
|
||||
if (!reader.attributes().hasAttribute(QLatin1String(kXmlLang))
|
||||
&& tool->m_displayName.isEmpty()) {
|
||||
tool->m_displayName = reader.readElementText();
|
||||
} else {
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
} else if (reader.name() == QLatin1String(kCategory)) {
|
||||
// TODO locale check
|
||||
if (!reader.attributes().hasAttribute(QLatin1String(kXmlLang))
|
||||
&& tool->m_displayCategory.isEmpty()) {
|
||||
tool->m_displayCategory = reader.readElementText();
|
||||
} else {
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
} else if (reader.name() == QLatin1String(kOrder)) {
|
||||
if (tool->m_order >= 0) {
|
||||
reader.raiseError(QLatin1String("only one <order> element allowed"));
|
||||
break;
|
||||
}
|
||||
bool ok;
|
||||
tool->m_order = reader.readElementText().toInt(&ok);
|
||||
if (!ok || tool->m_order < 0)
|
||||
reader.raiseError(QLatin1String("<order> element requires non-negative integer value"));
|
||||
} else if (reader.name() == QLatin1String(kExecutable)) {
|
||||
if (reader.attributes().hasAttribute(QLatin1String(kOutput))) {
|
||||
const QString output = reader.attributes().value(QLatin1String(kOutput)).toString();
|
||||
if (output == QLatin1String(kOutputShowInPane)) {
|
||||
tool->m_outputHandling = ExternalTool::ShowInPane;
|
||||
} else if (output == QLatin1String(kOutputReplaceSelection)) {
|
||||
tool->m_outputHandling = ExternalTool::ReplaceSelection;
|
||||
} else if (output == QLatin1String(kOutputReloadDocument)) {
|
||||
tool->m_outputHandling = ExternalTool::ReloadDocument;
|
||||
} else {
|
||||
reader.raiseError(QLatin1String("Allowed values for output attribute are 'showinpane','replaceselection','reloaddocument'"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (reader.readNextStartElement()) {
|
||||
if (reader.name() == QLatin1String(kPath)) {
|
||||
tool->m_executables.append(reader.readElementText());
|
||||
} else if (reader.name() == QLatin1String(kArguments)) {
|
||||
if (!tool->m_arguments.isEmpty()) {
|
||||
reader.raiseError(QLatin1String("only one <arguments> element allowed"));
|
||||
break;
|
||||
}
|
||||
tool->m_arguments = reader.readElementText();
|
||||
} else if (reader.name() == QLatin1String(kWorkingDirectory)) {
|
||||
if (!tool->m_workingDirectory.isEmpty()) {
|
||||
reader.raiseError(QLatin1String("only one <workingdirectory> element allowed"));
|
||||
break;
|
||||
}
|
||||
tool->m_workingDirectory = reader.readElementText();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reader.raiseError(QString::fromLatin1("Unknown element <%1>").arg(reader.qualifiedName().toString()));
|
||||
}
|
||||
}
|
||||
if (reader.hasError()) {
|
||||
if (errorMessage)
|
||||
*errorMessage = reader.errorString();
|
||||
qDebug() << reader.errorString();
|
||||
delete tool;
|
||||
return 0;
|
||||
}
|
||||
return tool;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef EXTERNALTOOL_H
|
||||
#define EXTERNALTOOL_H
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
namespace Core {
|
||||
namespace Internal {
|
||||
|
||||
class ExternalTool
|
||||
{
|
||||
public:
|
||||
enum OutputHandling {
|
||||
ShowInPane,
|
||||
ReplaceSelection,
|
||||
ReloadDocument
|
||||
};
|
||||
|
||||
ExternalTool();
|
||||
|
||||
QString description() const;
|
||||
QString displayName() const;
|
||||
QString displayCategory() const;
|
||||
int order() const;
|
||||
OutputHandling outputHandling() const;
|
||||
|
||||
QStringList executables() const;
|
||||
QString arguments() const;
|
||||
QString workingDirectory() const;
|
||||
|
||||
static ExternalTool *createFromXml(const QString &xml, QString *errorMessage = 0);
|
||||
|
||||
private:
|
||||
QString m_description;
|
||||
QString m_displayName;
|
||||
QString m_displayCategory;
|
||||
int m_order;
|
||||
QStringList m_executables;
|
||||
QString m_arguments;
|
||||
QString m_workingDirectory;
|
||||
OutputHandling m_outputHandling;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
} // Core
|
||||
|
||||
#endif // EXTERNALTOOL_H
|
||||
@@ -9,8 +9,6 @@ isEmpty(PROVIDER) {
|
||||
|
||||
DESTDIR = $$IDE_PLUGIN_PATH/$$PROVIDER
|
||||
LIBS += -L$$DESTDIR
|
||||
INCLUDEPATH += $$IDE_SOURCE_TREE/src/plugins
|
||||
DEPENDPATH += $$IDE_SOURCE_TREE/src/plugins
|
||||
|
||||
# copy the plugin spec
|
||||
isEmpty(TARGET) {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
include(../qttest.pri)
|
||||
|
||||
SOURCES += tst_externaltooltest.cpp \
|
||||
$$IDE_SOURCE_TREE/src/plugins/coreplugin/externaltool.cpp
|
||||
HEADERS += $$IDE_SOURCE_TREE/src/plugins/coreplugin/externaltool.h
|
||||
@@ -0,0 +1,120 @@
|
||||
#include <QtCore/QString>
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
#include <coreplugin/externaltool.h>
|
||||
|
||||
using namespace Core::Internal;
|
||||
|
||||
static const char * const TEST_XML1 =
|
||||
"<externaltool>"
|
||||
" <description>Synchronizes translator's ts files with the program code</description>"
|
||||
" <description xml:lang=\"de\">Synchronisiert die ts-Übersetzungsdateien mit dem Programmcode</description>"
|
||||
" <displayname>Update translations (lupdate)</displayname>"
|
||||
" <displayname xml:lang=\"de\">Übersetzungen aktualisieren (lupdate)</displayname>"
|
||||
" <category>Linguist</category>"
|
||||
" <category xml:lang=\"de\">Linguist</category>"
|
||||
" <order>1</order>"
|
||||
" <executable>"
|
||||
" <path>%{QT_INSTALL_BINS}/lupdate</path>"
|
||||
" <path>lupdate</path>"
|
||||
" <arguments>%{CurrentProjectFilePath}</arguments>"
|
||||
" <workingdirectory>%{CurrentProjectPath}</workingdirectory>"
|
||||
" </executable>"
|
||||
"</externaltool>"
|
||||
;
|
||||
|
||||
static const char * const TEST_XML2 =
|
||||
"<externaltool>"
|
||||
" <description>Sorts the selected text</description>"
|
||||
" <description xml:lang=\"de\">Sortiert den ausgewählten Text</description>"
|
||||
" <displayname>Sort</displayname>"
|
||||
" <displayname xml:lang=\"de\">Sortieren</displayname>"
|
||||
" <category>Text</category>"
|
||||
" <category xml:lang=\"de\">Text</category>"
|
||||
" <executable output=\"replaceselection\">"
|
||||
" <path>sort</path>"
|
||||
" <arguments>%{CurrentSelectionFilePath}</arguments>"
|
||||
" <workingdirectory>%{CurrentPath}</workingdirectory>"
|
||||
" </executable>"
|
||||
"</externaltool>";
|
||||
|
||||
static const char * const TEST_XML3 =
|
||||
"<externaltool>"
|
||||
" <description>Opens the current file in vi</description>"
|
||||
" <description xml:lang=\"de\">Öffnet die aktuelle Datei in vi</description>"
|
||||
" <displayname>Edit with vi</displayname>"
|
||||
" <displayname xml:lang=\"de\">In vi öffnen</displayname>"
|
||||
" <category>Text</category>"
|
||||
" <category xml:lang=\"de\">Text</category>"
|
||||
" <executable output=\"reloaddocument\">"
|
||||
" <path>xterm</path>"
|
||||
" <arguments>-geom %{EditorCharWidth}x%{EditorCharHeight}+%{EditorXPos}+%{EditorYPos} -e vi %{CurrentFilePath} +%{EditorLine} +\"normal %{EditorColumn}|\"</arguments>"
|
||||
" <workingdirectory>%{CurrentPath}</workingdirectory>"
|
||||
" </executable>"
|
||||
"</externaltool>";
|
||||
|
||||
class ExternaltoolTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
void testRead1();
|
||||
void testRead2();
|
||||
void testRead3();
|
||||
};
|
||||
|
||||
void ExternaltoolTest::testRead1()
|
||||
{
|
||||
QString error;
|
||||
ExternalTool *tool = ExternalTool::createFromXml(QLatin1String(TEST_XML1), &error);
|
||||
QVERIFY(tool != 0);
|
||||
QVERIFY(error.isEmpty());
|
||||
QVERIFY(tool->description().startsWith(QLatin1String("Synchronizes tran")));
|
||||
QCOMPARE(tool->displayName(), QString::fromLatin1("Update translations (lupdate)"));
|
||||
QCOMPARE(tool->displayCategory(), QString::fromLatin1("Linguist"));
|
||||
QCOMPARE(tool->order(), 1);
|
||||
QCOMPARE(tool->executables().size(), 2);
|
||||
QCOMPARE(tool->executables().at(0), QString::fromLatin1("%{QT_INSTALL_BINS}/lupdate"));
|
||||
QCOMPARE(tool->executables().at(1), QString::fromLatin1("lupdate"));
|
||||
QCOMPARE(tool->arguments(), QString::fromLatin1("%{CurrentProjectFilePath}"));
|
||||
QCOMPARE(tool->workingDirectory(), QString::fromLatin1("%{CurrentProjectPath}"));
|
||||
QCOMPARE(tool->outputHandling(), ExternalTool::ShowInPane);
|
||||
}
|
||||
|
||||
void ExternaltoolTest::testRead2()
|
||||
{
|
||||
QString error;
|
||||
ExternalTool *tool = ExternalTool::createFromXml(QLatin1String(TEST_XML2), &error);
|
||||
QVERIFY(tool != 0);
|
||||
QVERIFY(error.isEmpty());
|
||||
QVERIFY(tool->description().startsWith(QLatin1String("Sorts the")));
|
||||
QCOMPARE(tool->displayName(), QString::fromLatin1("Sort"));
|
||||
QCOMPARE(tool->displayCategory(), QString::fromLatin1("Text"));
|
||||
QCOMPARE(tool->order(), -1);
|
||||
QCOMPARE(tool->executables().size(), 1);
|
||||
QCOMPARE(tool->executables().at(0), QString::fromLatin1("sort"));
|
||||
QCOMPARE(tool->arguments(), QString::fromLatin1("%{CurrentSelectionFilePath}"));
|
||||
QCOMPARE(tool->workingDirectory(), QString::fromLatin1("%{CurrentPath}"));
|
||||
QCOMPARE(tool->outputHandling(), ExternalTool::ReplaceSelection);
|
||||
}
|
||||
|
||||
void ExternaltoolTest::testRead3()
|
||||
{
|
||||
QString error;
|
||||
ExternalTool *tool = ExternalTool::createFromXml(QLatin1String(TEST_XML3), &error);
|
||||
QVERIFY(tool != 0);
|
||||
QVERIFY(error.isEmpty());
|
||||
QVERIFY(tool->description().startsWith(QLatin1String("Opens the")));
|
||||
QCOMPARE(tool->displayName(), QString::fromLatin1("Edit with vi"));
|
||||
QCOMPARE(tool->displayCategory(), QString::fromLatin1("Text"));
|
||||
QCOMPARE(tool->order(), -1);
|
||||
QCOMPARE(tool->executables().size(), 1);
|
||||
QCOMPARE(tool->executables().at(0), QString::fromLatin1("xterm"));
|
||||
QVERIFY(tool->arguments().startsWith(QLatin1String("-geom %{")));
|
||||
QCOMPARE(tool->workingDirectory(), QString::fromLatin1("%{CurrentPath}"));
|
||||
QCOMPARE(tool->outputHandling(), ExternalTool::ReloadDocument);
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(ExternaltoolTest);
|
||||
|
||||
#include "tst_externaltooltest.moc"
|
||||
Reference in New Issue
Block a user