diff options
author | kh1 <karsten.heimrich@digia.com> | 2014-04-03 15:02:00 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@digia.com> | 2014-04-04 11:09:07 +0200 |
commit | ea25dca5eae415c2a555865efe7176b07f7bf109 (patch) | |
tree | 36aa9a7cdd58bcc1564184d1ca101c0d25934224 | |
parent | 09c3bf53a53368642780b63de64cb8cfe73f0e17 (diff) |
Fix strange error message.
Task-number: QTIFW-309
If a component script file is empty or misses the component class
constructor, bail out during binary create or installer execution.
Change-Id: I422c64186652a52122d54b5b042139803c24ba10
Reviewed-by: Niels Weber <niels.weber@digia.com>
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
-rw-r--r-- | src/libs/installer/scriptengine.cpp | 20 | ||||
-rw-r--r-- | tools/common/repositorygen.cpp | 19 |
2 files changed, 24 insertions, 15 deletions
diff --git a/src/libs/installer/scriptengine.cpp b/src/libs/installer/scriptengine.cpp index 87faa2cee..d46805ade 100644 --- a/src/libs/installer/scriptengine.cpp +++ b/src/libs/installer/scriptengine.cpp @@ -41,6 +41,7 @@ #include "scriptengine.h" #include "component.h" +#include "globals.h" #include "packagemanagercore.h" #include "messageboxhandler.h" #include "errors.h" @@ -248,16 +249,17 @@ QScriptValue ScriptEngine::loadInConext(const QString &context, const QString &f fileName, file.errorString())); } - // create inside closure in one line to keep linenumber in the right order - // which is used as a debug output in an exception case - // scriptContent will be added as the last arg command to prevent wrong - // replacements of %1, %2 or %3 inside the scriptContent + // Create a closure. Put the content in the first line to keep line number order in case of an + // exception. Script content will be added as the last argument to the command to prevent wrong + // replacements of %1, %2 or %3 inside the javascript code. QString scriptContent = QString::fromLatin1( - "(function() { %1 %3 ; return new %2; })();"); - - // merging everything together and as last we are adding the file content to prevent wrong - // replacements of %1 %2 or %3 inside the javascript code - scriptContent = scriptContent.arg(scriptInjection, context, QLatin1String(file.readAll())); + "(function() {" + " %1 %3 ;" + " if (typeof %2 != \"undefined\")" + " return new %2;" + " else" + " throw \"Missing Component constructor. Please check your script.\";" + "})();").arg(scriptInjection, context, QLatin1String(file.readAll())); QScriptValue scriptContext = evaluate(scriptContent, fileName); if (hasUncaughtException()) { diff --git a/tools/common/repositorygen.cpp b/tools/common/repositorygen.cpp index 77ce8eb6f..11063e789 100644 --- a/tools/common/repositorygen.cpp +++ b/tools/common/repositorygen.cpp @@ -293,13 +293,19 @@ void QInstallerTools::copyMetaData(const QString &_targetDir, const QString &met // copy script file const QString script = package.firstChildElement(QLatin1String("Script")).text(); if (!script.isEmpty()) { - QString scriptContent; QFile scriptFile(QString::fromLatin1("%1/meta/%2").arg(info.directory, script)); - if (scriptFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream in(&scriptFile); - scriptContent = in.readAll(); + if (!scriptFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + throw QInstaller::Error(QString::fromLatin1("Could not open component script: '%1'") + .arg(scriptFile.fileName())); } + QString scriptContent = QString::fromLatin1( + "(function() {" + " %1;" + " if (typeof Component == \"undefined\")" + " throw \"Missing Component constructor. Please check your script.\";" + "})();").arg(QTextStream(&scriptFile).readAll()); + // if the user isn't aware of the downloadable archives value we will add it automatically later foundDownloadableArchives |= scriptContent.contains(QLatin1String("addDownloadableArchive")) || scriptContent.contains(QLatin1String("removeDownloadableArchive")); @@ -307,8 +313,9 @@ void QInstallerTools::copyMetaData(const QString &_targetDir, const QString &met static QScriptEngine testScriptEngine; testScriptEngine.evaluate(scriptContent, scriptFile.fileName()); if (testScriptEngine.hasUncaughtException()) { - throw QInstaller::Error(QString::fromLatin1("Exception while loading component script: '%1'") - .arg(QInstaller::uncaughtExceptionString(&testScriptEngine, scriptFile.fileName()))); + throw QInstaller::Error(QString::fromLatin1("Exception while loading component " + "script: '%1'").arg(QInstaller::uncaughtExceptionString(&testScriptEngine, + scriptFile.fileName()))); } // add RequiresAdminRights tag to xml if addElevatedOperation is used somewhere |