From 1a6580900825dc98f406cd8a1818a5a0fa35c1f5 Mon Sep 17 00:00:00 2001
From: con <qtc-committer@nokia.com>
Date: Tue, 22 Mar 2011 13:37:19 +0100
Subject: [PATCH] Add error reporting if executable is not found for external
 tool.

---
 src/plugins/coreplugin/externaltool.cpp | 37 +++++++++++++++++++++----
 src/plugins/coreplugin/externaltool.h   |  5 ++++
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/src/plugins/coreplugin/externaltool.cpp b/src/plugins/coreplugin/externaltool.cpp
index a61bd038bf3..16fd9edcbdf 100644
--- a/src/plugins/coreplugin/externaltool.cpp
+++ b/src/plugins/coreplugin/externaltool.cpp
@@ -529,7 +529,8 @@ bool ExternalTool::operator==(const ExternalTool &other) const
 ExternalToolRunner::ExternalToolRunner(const ExternalTool *tool)
     : m_tool(new ExternalTool(tool)),
       m_process(0),
-      m_outputCodec(QTextCodec::codecForLocale())
+      m_outputCodec(QTextCodec::codecForLocale()),
+      m_hasError(false)
 {
     run();
 }
@@ -540,6 +541,16 @@ ExternalToolRunner::~ExternalToolRunner()
         delete m_tool;
 }
 
+bool ExternalToolRunner::hasError() const
+{
+    return m_hasError;
+}
+
+QString ExternalToolRunner::errorString() const
+{
+    return m_errorString;
+}
+
 bool ExternalToolRunner::resolve()
 {
     if (!m_tool)
@@ -548,14 +559,27 @@ bool ExternalToolRunner::resolve()
     m_resolvedArguments.clear();
     m_resolvedWorkingDirectory.clear();
     { // executable
+        QStringList expandedExecutables; /* for error message */
         foreach (const QString &executable, m_tool->executables()) {
-            QString resolved = Utils::expandMacros(executable,
+            QString expanded = Utils::expandMacros(executable,
                                                    Core::VariableManager::instance()->macroExpander());
+            expandedExecutables << expanded;
             m_resolvedExecutable =
-                    Utils::Environment::systemEnvironment().searchInPath(resolved);
+                    Utils::Environment::systemEnvironment().searchInPath(expanded);
+            if (!m_resolvedExecutable.isEmpty())
+                break;
         }
-        if (m_resolvedExecutable.isEmpty())
+        if (m_resolvedExecutable.isEmpty()) {
+            m_hasError = true;
+            for (int i = 0; i < expandedExecutables.size(); ++i) {
+                m_errorString += tr("Could not find executable for '%1' (expanded '%2')\n")
+                        .arg(m_tool->executables().at(i))
+                        .arg(expandedExecutables.at(i));
+            }
+            if (!m_errorString.isEmpty())
+                m_errorString.chop(1);
             return false;
+        }
     }
     { // arguments
         m_resolvedArguments = Utils::QtcProcess::expandMacros(m_tool->arguments(),
@@ -759,7 +783,10 @@ void ExternalToolManager::menuActivated()
     QTC_ASSERT(action, return);
     ExternalTool *tool = m_tools.value(action->data().toString());
     QTC_ASSERT(tool, return);
-    new ExternalToolRunner(tool);
+    ExternalToolRunner *runner = new ExternalToolRunner(tool);
+    if (runner->hasError()) {
+        ICore::instance()->messageManager()->printToOutputPane(runner->errorString(), true);
+    }
 }
 
 QMap<QString, QList<Internal::ExternalTool *> > ExternalToolManager::toolsByCategory() const
diff --git a/src/plugins/coreplugin/externaltool.h b/src/plugins/coreplugin/externaltool.h
index 8edeefd3761..80c8e8a6f6e 100644
--- a/src/plugins/coreplugin/externaltool.h
+++ b/src/plugins/coreplugin/externaltool.h
@@ -135,6 +135,9 @@ public:
     ExternalToolRunner(const ExternalTool *tool);
     ~ExternalToolRunner();
 
+    bool hasError() const;
+    QString errorString() const;
+
 private slots:
     void started();
     void finished(int exitCode, QProcess::ExitStatus status);
@@ -157,6 +160,8 @@ private:
     QTextCodec::ConverterState m_errorCodecState;
     QString m_processOutput;
     QString m_expectedFileName;
+    bool m_hasError;
+    QString m_errorString;
 };
 
 } // Internal
-- 
GitLab