javaparser.cpp 3.06 KB
Newer Older
1
/****************************************************************************
BogDan Vatra's avatar
BogDan Vatra committed
2
**
3 4
** Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
** Contact: https://www.qt.io/licensing/
BogDan Vatra's avatar
BogDan Vatra committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
BogDan Vatra's avatar
BogDan Vatra committed
7
**
hjk's avatar
hjk committed
8 9 10 11
** 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
12 13 14
** 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.
BogDan Vatra's avatar
BogDan Vatra committed
15
**
16 17 18 19 20 21 22
** 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.
BogDan Vatra's avatar
BogDan Vatra committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
BogDan Vatra's avatar
BogDan Vatra committed
25 26 27 28 29

#include "javaparser.h"

#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/task.h>
30
#include <QFileInfo>
BogDan Vatra's avatar
BogDan Vatra committed
31 32 33 34 35

using namespace Android::Internal;
using namespace ProjectExplorer;

JavaParser::JavaParser() :
hjk's avatar
hjk committed
36
  m_javaRegExp(QLatin1String("^(.*\\[javac\\]\\s)(.*\\.java):(\\d+):(.*)$"))
Tobias Hunger's avatar
Tobias Hunger committed
37
{ }
BogDan Vatra's avatar
BogDan Vatra committed
38 39 40

void JavaParser::stdOutput(const QString &line)
{
Tobias Hunger's avatar
Tobias Hunger committed
41 42
    parse(line);
    IOutputParser::stdOutput(line);
BogDan Vatra's avatar
BogDan Vatra committed
43 44 45
}

void JavaParser::stdError(const QString &line)
Tobias Hunger's avatar
Tobias Hunger committed
46 47 48 49 50 51 52 53 54 55
{
    parse(line);
    IOutputParser::stdError(line);
}

void JavaParser::setProjectFileList(const QStringList &fileList)
{
    m_fileList = fileList;
}

56 57 58 59 60 61 62 63 64 65
void JavaParser::setBuildDirectory(const Utils::FileName &buildDirectory)
{
    m_buildDirectory = buildDirectory;
}

void JavaParser::setSourceDirectory(const Utils::FileName &sourceDirectory)
{
    m_sourceDirectory = sourceDirectory;
}

Tobias Hunger's avatar
Tobias Hunger committed
66
void JavaParser::parse(const QString &line)
BogDan Vatra's avatar
BogDan Vatra committed
67 68 69 70 71 72
{
    if (m_javaRegExp.indexIn(line) > -1) {
        bool ok;
        int lineno = m_javaRegExp.cap(3).toInt(&ok);
        if (!ok)
            lineno = -1;
73 74 75 76 77 78 79 80 81 82 83 84 85 86
        Utils::FileName file = Utils::FileName::fromUserInput(m_javaRegExp.cap(2));
        if (file.isChildOf(m_buildDirectory)) {
            Utils::FileName relativePath = file.relativeChildPath(m_buildDirectory);
            file = m_sourceDirectory;
            file.appendPath(relativePath.toString());
        }

        if (file.toFileInfo().isRelative()) {
            for (int i = 0; i < m_fileList.size(); i++)
                if (m_fileList[i].endsWith(file.toString())) {
                    file = Utils::FileName::fromString(m_fileList[i]);
                    break;
                }
        }
BogDan Vatra's avatar
BogDan Vatra committed
87 88 89

        Task task(Task::Error,
                  m_javaRegExp.cap(4).trimmed(),
90
                  file /* filename */,
BogDan Vatra's avatar
BogDan Vatra committed
91
                  lineno,
hjk's avatar
hjk committed
92
                  Constants::TASK_CATEGORY_COMPILE);
93
        emit addTask(task, 1);
BogDan Vatra's avatar
BogDan Vatra committed
94 95 96 97
        return;
    }

}