diff options
| author | Jake Petroules <jake.petroules@petroules.com> | 2015-07-25 15:35:54 -0700 |
|---|---|---|
| committer | Jake Petroules <jake.petroules@petroules.com> | 2015-07-28 18:04:34 +0000 |
| commit | bac0864bf14a5b99ba33d9a8b54c768c4ba514d4 (patch) | |
| tree | f21b5c33452744305554e87b33679eb83c661de3 | |
| parent | a9f8369a395f59ebaa5ced6aee58d82975edadb2 (diff) | |
| download | qbs-bac0864bf14a5b99ba33d9a8b54c768c4ba514d4.tar.gz | |
Introduce the TemporaryDir JS extension.
Essentially a mirror of the QTemporaryDir API.
Change-Id: Iaf436ba67cddc4c62027da4dabd3c7bb3442a6f4
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
| -rw-r--r-- | doc/reference/jsextensions/jsextension-temporarydir.qdoc | 71 | ||||
| -rw-r--r-- | src/lib/corelib/corelib.qbs | 2 | ||||
| -rw-r--r-- | src/lib/corelib/jsextensions/jsextensions.cpp | 2 | ||||
| -rw-r--r-- | src/lib/corelib/jsextensions/jsextensions.pri | 2 | ||||
| -rw-r--r-- | src/lib/corelib/jsextensions/temporarydir.cpp | 76 | ||||
| -rw-r--r-- | src/lib/corelib/jsextensions/temporarydir.h | 60 | ||||
| -rw-r--r-- | tests/auto/blackbox/testdata/jsextensions-temporarydir/jsextensions-temporarydir.qbs | 28 | ||||
| -rw-r--r-- | tests/auto/blackbox/tst_blackbox.cpp | 7 | ||||
| -rw-r--r-- | tests/auto/blackbox/tst_blackbox.h | 1 |
9 files changed, 249 insertions, 0 deletions
diff --git a/doc/reference/jsextensions/jsextension-temporarydir.qdoc b/doc/reference/jsextensions/jsextension-temporarydir.qdoc new file mode 100644 index 000000000..5f4831187 --- /dev/null +++ b/doc/reference/jsextensions/jsextension-temporarydir.qdoc @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Jake Petroules. +** Contact: http://www.qt.io/licensing +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** 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 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +/*! + \contentspage index.html + \page jsextension-temporarydir.html + \ingroup list-of-builtin-services + + \title TemporaryDir Service + \brief Creates a unique directory for temporary use. + + The \c PropertyList service creates a unique directory for temporary use. + + \section1 Available Operations + + \section2 Constructor + \code + TemporaryDir() + \endcode + Allocates and returns a new TemporaryDir object. + This method creates the temporary directory. + + \section2 isValid + \code + isValid(): boolean + \endcode + Returns \c true if the temporary directory was created successfully. + + \section2 path + \code + path(): string + \endcode + Returns the path to the temporary directory. + Empty if the temporary directory could not be created. + + \section2 remove + \code + remove(): boolean + \endcode + Removes the temporary directory, including all its contents. + Returns \c true if removing was successful. + It is recommended to always call this function as soon as you are finished with the temporary + directory. +*/ diff --git a/src/lib/corelib/corelib.qbs b/src/lib/corelib/corelib.qbs index ead8c5f5a..c2a524d19 100644 --- a/src/lib/corelib/corelib.qbs +++ b/src/lib/corelib/corelib.qbs @@ -175,6 +175,8 @@ QbsLibrary { "moduleproperties.h", "process.cpp", "process.h", + "temporarydir.cpp", + "temporarydir.h", "textfile.cpp", "textfile.h", "domxml.cpp", diff --git a/src/lib/corelib/jsextensions/jsextensions.cpp b/src/lib/corelib/jsextensions/jsextensions.cpp index f0ff91007..317ce67fb 100644 --- a/src/lib/corelib/jsextensions/jsextensions.cpp +++ b/src/lib/corelib/jsextensions/jsextensions.cpp @@ -34,6 +34,7 @@ #include "file.h" #include "process.h" #include "propertylist.h" +#include "temporarydir.h" #include "textfile.h" #include <QScriptEngine> @@ -68,6 +69,7 @@ JsExtensions::InitializerMap JsExtensions::initializers() m_initializers.insert(QLatin1String("File"), &initializeJsExtensionFile); m_initializers.insert(QLatin1String("Process"), &initializeJsExtensionProcess); m_initializers.insert(QLatin1String("Xml"), &initializeJsExtensionXml); + m_initializers.insert(QLatin1String("TemporaryDir"), &initializeJsExtensionTemporaryDir); m_initializers.insert(QLatin1String("TextFile"), &initializeJsExtensionTextFile); m_initializers.insert(QLatin1String("PropertyList"), &initializeJsExtensionPropertyList); } diff --git a/src/lib/corelib/jsextensions/jsextensions.pri b/src/lib/corelib/jsextensions/jsextensions.pri index 228675e8d..e32f01111 100644 --- a/src/lib/corelib/jsextensions/jsextensions.pri +++ b/src/lib/corelib/jsextensions/jsextensions.pri @@ -2,6 +2,7 @@ QT += xml HEADERS += \ $$PWD/file.h \ + $$PWD/temporarydir.h \ $$PWD/textfile.h \ $$PWD/process.h \ $$PWD/moduleproperties.h \ @@ -10,6 +11,7 @@ HEADERS += \ SOURCES += \ $$PWD/file.cpp \ + $$PWD/temporarydir.cpp \ $$PWD/textfile.cpp \ $$PWD/process.cpp \ $$PWD/moduleproperties.cpp \ diff --git a/src/lib/corelib/jsextensions/temporarydir.cpp b/src/lib/corelib/jsextensions/temporarydir.cpp new file mode 100644 index 000000000..e01796eac --- /dev/null +++ b/src/lib/corelib/jsextensions/temporarydir.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Jake Petroules. +** Contact: http://www.qt.io/licensing +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** 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 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "temporarydir.h" + +#include <QScriptEngine> +#include <QScriptValue> +#include <QTemporaryDir> + +namespace qbs { +namespace Internal { + +void initializeJsExtensionTemporaryDir(QScriptValue extensionObject) +{ + QScriptEngine *engine = extensionObject.engine(); + QScriptValue obj = engine->newQMetaObject(&TemporaryDir::staticMetaObject, + engine->newFunction(&TemporaryDir::ctor)); + extensionObject.setProperty(QLatin1String("TemporaryDir"), obj); +} + +QScriptValue TemporaryDir::ctor(QScriptContext *context, QScriptEngine *engine) +{ + TemporaryDir *t = new TemporaryDir(context); + QScriptValue obj = engine->newQObject(t, QScriptEngine::ScriptOwnership); + return obj; +} + +TemporaryDir::TemporaryDir(QScriptContext *context) +{ + Q_UNUSED(context); +} + +bool TemporaryDir::isValid() const +{ + return dir.isValid(); +} + +QString TemporaryDir::path() const +{ + return dir.path(); +} + +bool TemporaryDir::remove() +{ + return dir.remove(); +} + +} // namespace Internal +} // namespace qbs diff --git a/src/lib/corelib/jsextensions/temporarydir.h b/src/lib/corelib/jsextensions/temporarydir.h new file mode 100644 index 000000000..b2ab71cc8 --- /dev/null +++ b/src/lib/corelib/jsextensions/temporarydir.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Jake Petroules. +** Contact: http://www.qt.io/licensing +** +** This file is part of the Qt Build Suite. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** 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 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef QBS_TEMPORARYDIR_H +#define QBS_TEMPORARYDIR_H + +#include <QObject> +#include <QScriptable> +#include <QTemporaryDir> +#include <QVariant> + +namespace qbs { +namespace Internal { + +void initializeJsExtensionTemporaryDir(QScriptValue extensionObject); + +class TemporaryDir : public QObject, public QScriptable +{ + Q_OBJECT +public: + static QScriptValue ctor(QScriptContext *context, QScriptEngine *engine); + TemporaryDir(QScriptContext *context); + Q_INVOKABLE bool isValid() const; + Q_INVOKABLE QString path() const; + Q_INVOKABLE bool remove(); +private: + QTemporaryDir dir; +}; + +} // namespace Internal +} // namespace qbs + +#endif // QBS_TEMPORARYDIR_H diff --git a/tests/auto/blackbox/testdata/jsextensions-temporarydir/jsextensions-temporarydir.qbs b/tests/auto/blackbox/testdata/jsextensions-temporarydir/jsextensions-temporarydir.qbs new file mode 100644 index 000000000..fb54a45ec --- /dev/null +++ b/tests/auto/blackbox/testdata/jsextensions-temporarydir/jsextensions-temporarydir.qbs @@ -0,0 +1,28 @@ +import qbs +import qbs.File +import qbs.TemporaryDir + +Product { + targetName: { + var dir; + var dirPath; + try { + dir = new TemporaryDir(); + dirPath = dir.path(); + if (!dirPath) + throw "path is empty"; + + if (!dir.isValid()) + throw "dir is not valid"; + + if (!File.exists(dirPath)) + throw "dir does not exist"; + } finally { + if (!dir.remove()) + throw "could not remove"; + } + + if (File.exists(dirPath)) + throw "dir was not removed"; + } +} diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index 7f0b0f5de..3079ee741 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -1715,6 +1715,13 @@ void TestBlackbox::jsExtensionsPropertyList() QVERIFY(file1Contents != file5.readAll()); } +void TestBlackbox::jsExtensionsTemporaryDir() +{ + QDir::setCurrent(testDataDir + "/jsextensions-temporarydir"); + QbsRunParameters params; + QCOMPARE(runQbs(params), 0); +} + void TestBlackbox::jsExtensionsTextFile() { QDir::setCurrent(testDataDir + "/jsextensions-textfile"); diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h index c9ac29cde..0b8245386 100644 --- a/tests/auto/blackbox/tst_blackbox.h +++ b/tests/auto/blackbox/tst_blackbox.h @@ -121,6 +121,7 @@ private slots: void jsExtensionsFileInfo(); void jsExtensionsProcess(); void jsExtensionsPropertyList(); + void jsExtensionsTemporaryDir(); void jsExtensionsTextFile(); void listPropertiesWithOuter(); void listPropertyOrder(); |
