2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-06-16 14:12:30 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-06-16 14:12:30 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-06-16 14:12:30 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-06-16 14:12:30 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-06-16 14:12:30 +02:00
|
|
|
|
|
|
|
|
#include "task.h"
|
|
|
|
|
|
2019-02-25 17:45:39 +01:00
|
|
|
#include "fileinsessionfinder.h"
|
2018-04-18 13:39:05 +02:00
|
|
|
#include "projectexplorerconstants.h"
|
|
|
|
|
|
2017-08-29 11:48:48 +02:00
|
|
|
#include <app/app_version.h>
|
2017-07-20 09:18:19 +02:00
|
|
|
#include <texteditor/textmark.h>
|
2018-04-18 13:39:05 +02:00
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
2016-08-03 17:55:54 +02:00
|
|
|
#include <utils/utilsicons.h>
|
2014-04-10 12:44:13 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2019-02-25 17:45:39 +01:00
|
|
|
#include <QFileInfo>
|
2018-04-18 12:15:53 +02:00
|
|
|
#include <QTextStream>
|
|
|
|
|
|
2020-01-15 08:56:11 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
2010-06-16 14:12:30 +02:00
|
|
|
|
2014-09-22 15:49:14 +02:00
|
|
|
static QIcon taskTypeIcon(Task::TaskType t)
|
2013-11-12 21:59:43 +01:00
|
|
|
{
|
2017-02-22 15:09:35 +01:00
|
|
|
static QIcon icons[3] = {QIcon(),
|
|
|
|
|
Utils::Icons::CRITICAL.icon(),
|
|
|
|
|
Utils::Icons::WARNING.icon()};
|
2014-09-22 15:49:14 +02:00
|
|
|
|
|
|
|
|
if (t < 0 || t > 2)
|
|
|
|
|
t = Task::Unknown;
|
|
|
|
|
|
|
|
|
|
return icons[t];
|
2013-11-12 21:59:43 +01:00
|
|
|
}
|
|
|
|
|
|
2010-08-04 14:56:32 +02:00
|
|
|
unsigned int Task::s_nextId = 1;
|
2010-06-30 16:37:07 +02:00
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
|
|
|
|
\class ProjectExplorer::Task
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The Task class represents a build issue (warning or error).
|
2011-04-14 12:58:14 +02:00
|
|
|
\sa ProjectExplorer::TaskHub
|
|
|
|
|
*/
|
|
|
|
|
|
2020-05-12 16:26:34 +02:00
|
|
|
Task::Task(TaskType type_, const QString &description,
|
2019-05-28 13:49:26 +02:00
|
|
|
const Utils::FilePath &file_, int line_, Core::Id category_,
|
2018-05-09 16:02:02 +02:00
|
|
|
const QIcon &icon, Options options) :
|
2020-05-12 16:26:34 +02:00
|
|
|
taskId(s_nextId), type(type_), options(options), summary(description),
|
2019-05-08 00:03:13 +03:00
|
|
|
line(line_), movedLine(line_), category(category_),
|
2018-04-13 14:30:09 +02:00
|
|
|
icon(icon.isNull() ? taskTypeIcon(type_) : icon)
|
2010-06-24 16:14:29 +02:00
|
|
|
{
|
2010-06-30 16:37:07 +02:00
|
|
|
++s_nextId;
|
2019-05-08 00:03:13 +03:00
|
|
|
setFile(file_);
|
2020-05-12 16:26:34 +02:00
|
|
|
QStringList desc = description.split('\n');
|
|
|
|
|
if (desc.length() > 1) {
|
|
|
|
|
summary = desc.first();
|
|
|
|
|
details = desc.mid(1);
|
|
|
|
|
}
|
2010-06-24 16:14:29 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-20 14:32:40 +02:00
|
|
|
Task Task::compilerMissingTask()
|
|
|
|
|
{
|
2020-01-15 08:56:11 +01:00
|
|
|
return BuildSystemTask(Task::Error,
|
|
|
|
|
tr("%1 needs a compiler set up to build. "
|
|
|
|
|
"Configure a compiler in the kit options.")
|
|
|
|
|
.arg(Core::Constants::IDE_DISPLAY_NAME));
|
2014-06-20 14:32:40 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-11 13:27:42 +02:00
|
|
|
void Task::setMark(TextEditor::TextMark *mark)
|
2012-02-03 16:07:13 +01:00
|
|
|
{
|
2016-04-11 13:27:42 +02:00
|
|
|
QTC_ASSERT(mark, return);
|
2014-04-10 12:44:13 +02:00
|
|
|
QTC_ASSERT(m_mark.isNull(), return);
|
2014-07-19 11:27:28 +02:00
|
|
|
m_mark = QSharedPointer<TextEditor::TextMark>(mark);
|
2012-02-03 16:07:13 +01:00
|
|
|
}
|
|
|
|
|
|
2010-08-04 14:56:32 +02:00
|
|
|
bool Task::isNull() const
|
2013-08-01 14:16:10 +02:00
|
|
|
{
|
|
|
|
|
return taskId == 0;
|
|
|
|
|
}
|
2010-08-04 14:56:32 +02:00
|
|
|
|
2013-05-03 15:58:01 +02:00
|
|
|
void Task::clear()
|
|
|
|
|
{
|
|
|
|
|
taskId = 0;
|
2016-04-11 13:25:12 +02:00
|
|
|
type = Task::Unknown;
|
2020-05-12 16:26:34 +02:00
|
|
|
summary.clear();
|
|
|
|
|
details.clear();
|
2019-05-28 13:49:26 +02:00
|
|
|
file = Utils::FilePath();
|
2013-05-03 15:58:01 +02:00
|
|
|
line = -1;
|
|
|
|
|
movedLine = -1;
|
|
|
|
|
category = Core::Id();
|
2013-11-12 21:59:43 +01:00
|
|
|
icon = QIcon();
|
2016-04-11 13:25:12 +02:00
|
|
|
formats.clear();
|
|
|
|
|
m_mark.clear();
|
2013-05-03 15:58:01 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
void Task::setFile(const Utils::FilePath &file_)
|
2019-05-08 00:03:13 +03:00
|
|
|
{
|
|
|
|
|
file = file_;
|
|
|
|
|
if (!file.isEmpty() && !file.toFileInfo().isAbsolute()) {
|
2019-12-17 14:07:53 +01:00
|
|
|
Utils::FilePaths possiblePaths = findFileInSession(file);
|
2019-05-08 00:03:13 +03:00
|
|
|
if (possiblePaths.length() == 1)
|
|
|
|
|
file = possiblePaths.first();
|
|
|
|
|
else
|
|
|
|
|
fileCandidates = possiblePaths;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 16:26:34 +02:00
|
|
|
QString Task::description() const
|
|
|
|
|
{
|
|
|
|
|
QString desc = summary;
|
|
|
|
|
if (!details.isEmpty())
|
|
|
|
|
desc.append('\n').append(details.join('\n'));
|
|
|
|
|
return desc;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-16 14:12:30 +02:00
|
|
|
//
|
|
|
|
|
// functions
|
|
|
|
|
//
|
|
|
|
|
bool operator==(const Task &t1, const Task &t2)
|
|
|
|
|
{
|
2010-06-30 16:37:07 +02:00
|
|
|
return t1.taskId == t2.taskId;
|
2010-06-16 14:12:30 +02:00
|
|
|
}
|
|
|
|
|
|
2011-05-12 11:51:17 +02:00
|
|
|
bool operator<(const Task &a, const Task &b)
|
|
|
|
|
{
|
|
|
|
|
if (a.type != b.type) {
|
2014-10-13 22:37:28 +03:00
|
|
|
if (a.type == Task::Error)
|
2011-05-12 11:51:17 +02:00
|
|
|
return true;
|
2014-10-13 22:37:28 +03:00
|
|
|
if (b.type == Task::Error)
|
2011-05-12 11:51:17 +02:00
|
|
|
return false;
|
2014-10-13 22:37:28 +03:00
|
|
|
if (a.type == Task::Warning)
|
2011-05-12 11:51:17 +02:00
|
|
|
return true;
|
2014-10-13 22:37:28 +03:00
|
|
|
if (b.type == Task::Warning)
|
2011-05-12 11:51:17 +02:00
|
|
|
return false;
|
|
|
|
|
// Can't happen
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
2015-06-19 14:37:17 +02:00
|
|
|
if (a.category < b.category)
|
2011-05-12 11:51:17 +02:00
|
|
|
return true;
|
2015-06-19 14:37:17 +02:00
|
|
|
if (b.category < a.category)
|
2011-05-12 11:51:17 +02:00
|
|
|
return false;
|
|
|
|
|
return a.taskId < b.taskId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-06-16 14:12:30 +02:00
|
|
|
uint qHash(const Task &task)
|
|
|
|
|
{
|
2010-06-30 16:37:07 +02:00
|
|
|
return task.taskId;
|
2010-06-16 14:12:30 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-27 16:09:44 +02:00
|
|
|
QString toHtml(const Tasks &issues)
|
2018-04-18 12:15:53 +02:00
|
|
|
{
|
|
|
|
|
QString result;
|
|
|
|
|
QTextStream str(&result);
|
|
|
|
|
|
|
|
|
|
for (const Task &t : issues) {
|
|
|
|
|
str << "<b>";
|
|
|
|
|
switch (t.type) {
|
|
|
|
|
case Task::Error:
|
|
|
|
|
str << QCoreApplication::translate("ProjectExplorer::Kit", "Error:") << " ";
|
|
|
|
|
break;
|
|
|
|
|
case Task::Warning:
|
|
|
|
|
str << QCoreApplication::translate("ProjectExplorer::Kit", "Warning:") << " ";
|
|
|
|
|
break;
|
|
|
|
|
case Task::Unknown:
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-05-12 16:26:34 +02:00
|
|
|
str << "</b>" << t.description() << "<br>";
|
2018-04-18 12:15:53 +02:00
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-27 16:09:44 +02:00
|
|
|
bool containsType(const Tasks &issues, Task::TaskType type)
|
2018-04-18 13:39:05 +02:00
|
|
|
{
|
|
|
|
|
return Utils::contains(issues, [type](const Task &t) { return t.type == type; });
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-15 08:56:11 +01:00
|
|
|
// CompilerTask
|
|
|
|
|
|
|
|
|
|
CompileTask::CompileTask(TaskType type, const QString &desc, const FilePath &file, int line)
|
|
|
|
|
: Task(type, desc, file, line, ProjectExplorer::Constants::TASK_CATEGORY_COMPILE)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
// BuildSystemTask
|
|
|
|
|
|
|
|
|
|
BuildSystemTask::BuildSystemTask(Task::TaskType type, const QString &desc, const FilePath &file, int line)
|
|
|
|
|
: Task(type, desc, file, line, ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
// DeploymentTask
|
|
|
|
|
|
|
|
|
|
DeploymentTask::DeploymentTask(Task::TaskType type, const QString &desc)
|
|
|
|
|
: Task(type, desc, {}, -1, ProjectExplorer::Constants::TASK_CATEGORY_DEPLOYMENT)
|
|
|
|
|
{}
|
|
|
|
|
|
2010-06-16 14:12:30 +02:00
|
|
|
} // namespace ProjectExplorer
|