1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 Andre Hartmann. 4 ** Contact: aha_1980@gmx.de 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include "ioutputparser.h" 29 #include "projectconfiguration.h" 30 31 #include <projectexplorer/task.h> 32 #include <utils/detailswidget.h> 33 34 #include <QRegularExpression> 35 #include <QVariantMap> 36 37 namespace ProjectExplorer { 38 class Target; 39 40 class PROJECTEXPLORER_EXPORT CustomParserExpression 41 { 42 public: 43 enum CustomParserChannel { 44 ParseNoChannel = 0, 45 ParseStdErrChannel = 1, 46 ParseStdOutChannel = 2, 47 ParseBothChannels = 3 48 }; 49 50 bool operator ==(const CustomParserExpression &other) const; 51 52 QString pattern() const; 53 void setPattern(const QString &pattern); match(const QString & line)54 QRegularExpressionMatch match(const QString &line) const { return m_regExp.match(line); } 55 56 CustomParserExpression::CustomParserChannel channel() const; 57 void setChannel(CustomParserExpression::CustomParserChannel channel); 58 59 QString example() const; 60 void setExample(const QString &example); 61 62 int fileNameCap() const; 63 void setFileNameCap(int fileNameCap); 64 int lineNumberCap() const; 65 void setLineNumberCap(int lineNumberCap); 66 int messageCap() const; 67 void setMessageCap(int messageCap); 68 69 QVariantMap toMap() const; 70 void fromMap(const QVariantMap &map); 71 72 private: 73 QRegularExpression m_regExp; 74 CustomParserExpression::CustomParserChannel m_channel = ParseBothChannels; 75 QString m_example; 76 int m_fileNameCap = 1; 77 int m_lineNumberCap = 2; 78 int m_messageCap = 3; 79 }; 80 81 class PROJECTEXPLORER_EXPORT CustomParserSettings 82 { 83 public: 84 bool operator ==(const CustomParserSettings &other) const; 85 bool operator !=(const CustomParserSettings &other) const { return !operator==(other); } 86 87 QVariantMap toMap() const; 88 void fromMap(const QVariantMap &map); 89 90 Utils::Id id; 91 QString displayName; 92 CustomParserExpression error; 93 CustomParserExpression warning; 94 }; 95 96 class PROJECTEXPLORER_EXPORT CustomParsersAspect : public Utils::BaseAspect 97 { 98 Q_OBJECT 99 public: 100 CustomParsersAspect(Target *target); 101 setParsers(const QList<Utils::Id> & parsers)102 void setParsers(const QList<Utils::Id> &parsers) { m_parsers = parsers; } parsers()103 const QList<Utils::Id> parsers() const { return m_parsers; } 104 105 private: 106 void fromMap(const QVariantMap &map) override; 107 void toMap(QVariantMap &map) const override; 108 109 QList<Utils::Id> m_parsers; 110 }; 111 112 namespace Internal { 113 114 class CustomParser : public ProjectExplorer::OutputTaskParser 115 { 116 public: 117 CustomParser(const CustomParserSettings &settings = CustomParserSettings()); 118 119 void setSettings(const CustomParserSettings &settings); 120 121 static CustomParser *createFromId(Utils::Id id); 122 static Utils::Id id(); 123 124 private: 125 Result handleLine(const QString &line, Utils::OutputFormat type) override; 126 127 Result hasMatch(const QString &line, CustomParserExpression::CustomParserChannel channel, 128 const CustomParserExpression &expression, Task::TaskType taskType); 129 Result parseLine(const QString &rawLine, CustomParserExpression::CustomParserChannel channel); 130 131 CustomParserExpression m_error; 132 CustomParserExpression m_warning; 133 }; 134 135 class CustomParsersSelectionWidget : public Utils::DetailsWidget 136 { 137 Q_OBJECT 138 public: 139 CustomParsersSelectionWidget(QWidget *parent = nullptr); 140 141 void setSelectedParsers(const QList<Utils::Id> &parsers); 142 QList<Utils::Id> selectedParsers() const; 143 144 signals: 145 void selectionChanged(); 146 147 private: 148 void updateSummary(); 149 }; 150 151 } // namespace Internal 152 } // namespace ProjectExplorer 153 154 Q_DECLARE_METATYPE(ProjectExplorer::CustomParserExpression::CustomParserChannel); 155