~ubuntu-branches/ubuntu/trusty/qtcreator-plugin-ubuntu/trusty

« back to all changes in this revision

Viewing changes to src/ubuntu/ubuntuprojectguesser.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Benjamin Zeller
  • Date: 2014-04-10 16:54:54 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20140410165454-j9syoh0jx6azy7g1
Tags: 3.0.1+14.04.20140410.1-0ubuntu1
[ Benjamin Zeller ]
Added Toolchains and Kit support to automatically.   detect a
available click chroot Added Devicesupport, connected Ubuntu devices
are.   automatically registered in QtCreator and can be set   for
different kits Added Deploysupport(CMake), the projects contents are
uploaded.   automatically using SSH after running make install on a
local   directory Added Run and Debugsupport: the command that
should be run.   on the device is read from the desktop file in the
deployed   directory. This means C+and QML debugging work as well
as QML Profiling Dynamically forward ports, depending on adb
forward --list.   output. Adb Server is not restarted by default
anymore, only a press.   on the refresh button will trigger the
restart. That will fix   problems with failing adb scripts Added
local run support for Ubuntu projects .

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2014 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License as published by
 
6
 * the Free Software Foundation; version 2.1.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Author: Benjamin Zeller <benjamin.zeller@canonical.com>
 
17
 */
 
18
#include "ubuntuprojectguesser.h"
 
19
 
 
20
#include <projectexplorer/project.h>
 
21
#include <projectexplorer/target.h>
 
22
#include <projectexplorer/buildconfiguration.h>
 
23
#include <cmakeprojectmanager/cmakeproject.h>
 
24
#include <QDebug>
 
25
 
 
26
#include <QFile>
 
27
#include <QTextStream>
 
28
#include <QRegularExpression>
 
29
 
 
30
 
 
31
namespace Ubuntu {
 
32
namespace Internal {
 
33
 
 
34
const char SCOPES_TYPE_CACHE_PROPERTY[]    = "__ubuntu_sdk_is_scopes_project_property";
 
35
const char SCOPES_INIFILE_CACHE_PROPERTY[] = "__ubuntu_sdk_scopes_project_inifile_property";
 
36
const char CLICK_TYPE_CACHE_PROPERTY[]     = "__ubuntu_sdk_is_click_project_property";
 
37
 
 
38
UbuntuProjectGuesser::UbuntuProjectGuesser()
 
39
{
 
40
}
 
41
 
 
42
bool UbuntuProjectGuesser::isScopesProject(ProjectExplorer::Project *project, QString *iniFileName)
 
43
{
 
44
    //query the project type from CMakeCache always, only fall back on searching the directory
 
45
    QString type = projectTypeFromCacheOrProject(project);
 
46
    qDebug()<<"Project type from CMake "<<type;
 
47
    if (!type.isEmpty()) {
 
48
        return QString::compare(type, QLatin1String("Scope") , Qt::CaseInsensitive) == 0;
 
49
    }
 
50
 
 
51
    QVariant cachedResult = project->property(SCOPES_TYPE_CACHE_PROPERTY);
 
52
    if(cachedResult.isValid()) {
 
53
        if(!cachedResult.toBool())
 
54
            return false;
 
55
 
 
56
        if(iniFileName) {
 
57
            QVariant cachedIni = project->property(SCOPES_INIFILE_CACHE_PROPERTY);
 
58
            *iniFileName = cachedIni.toString();
 
59
        }
 
60
        return true;
 
61
    }
 
62
 
 
63
    if(!qobject_cast<CMakeProjectManager::CMakeProject*>(project))
 
64
        return false;
 
65
 
 
66
    Utils::FileName iniFile = findScopesIniRecursive(Utils::FileName::fromString(project->projectDirectory()));
 
67
    QFileInfo info = iniFile.toFileInfo();
 
68
    if (iniFileName && info.exists()) {
 
69
        *iniFileName = info.absolutePath();
 
70
    }
 
71
 
 
72
    if(info.exists()){
 
73
        project->setProperty(SCOPES_TYPE_CACHE_PROPERTY,true);
 
74
        project->setProperty(SCOPES_INIFILE_CACHE_PROPERTY,iniFile.toString());
 
75
    }
 
76
 
 
77
    return info.exists();
 
78
}
 
79
 
 
80
bool UbuntuProjectGuesser::isClickAppProject(ProjectExplorer::Project *project)
 
81
{
 
82
    //query the project type from CMakeCache always, only fall back on searching the directory
 
83
    QString type = projectTypeFromCacheOrProject(project);
 
84
    qDebug()<<"Project type from CMake "<<type;
 
85
    if (!type.isEmpty()) {
 
86
        return QString::compare(type, QLatin1String("ClickApp") , Qt::CaseInsensitive) == 0;
 
87
    }
 
88
 
 
89
    QVariant cachedResult = project->property(CLICK_TYPE_CACHE_PROPERTY);
 
90
    if(cachedResult.isValid()) {
 
91
        return cachedResult.toBool();
 
92
    }
 
93
 
 
94
    if(!qobject_cast<CMakeProjectManager::CMakeProject*>(project))
 
95
        return false;
 
96
 
 
97
    QFile projectFile(project->projectFilePath());
 
98
    if (!projectFile.open(QIODevice::ReadOnly))
 
99
        return false;
 
100
 
 
101
    bool usesClick = false;
 
102
    QRegularExpression regExp(QLatin1String("include\\(Click\\)|CLICK_MODE"));
 
103
    QTextStream in(&projectFile);
 
104
    while (!in.atEnd()) {
 
105
        QString contents = in.readLine();
 
106
        QRegularExpressionMatch m = regExp.match(contents);
 
107
        if(m.hasMatch()) {
 
108
            usesClick = true;
 
109
            break;
 
110
        }
 
111
    }
 
112
 
 
113
    if(usesClick) {
 
114
        Utils::FileName iniFile = findFileRecursive(Utils::FileName::fromString(project->projectDirectory()),
 
115
                                                     QLatin1String("^.*desktop.in.*$"));
 
116
        QFileInfo info = iniFile.toFileInfo();
 
117
        if(info.exists()) {
 
118
            project->setProperty(CLICK_TYPE_CACHE_PROPERTY,true);
 
119
            return true;
 
120
        }
 
121
 
 
122
        iniFile = findFileRecursive(Utils::FileName::fromString(project->projectDirectory()),
 
123
                                                     QLatin1String("^.*desktop.*$"));
 
124
        info = iniFile.toFileInfo();
 
125
        if(info.exists()) {
 
126
            project->setProperty(CLICK_TYPE_CACHE_PROPERTY,true);
 
127
            return true;
 
128
        }
 
129
    }
 
130
 
 
131
    project->setProperty(CLICK_TYPE_CACHE_PROPERTY,false);
 
132
    return false;
 
133
}
 
134
 
 
135
Utils::FileName UbuntuProjectGuesser::findScopesIniRecursive(const Utils::FileName &searchdir)
 
136
{
 
137
    return findFileRecursive(searchdir,QLatin1String("^.*-scope.ini.*$"));
 
138
}
 
139
 
 
140
Utils::FileName UbuntuProjectGuesser::findFileRecursive(const Utils::FileName &searchdir, const QString &regexp)
 
141
{
 
142
    QRegularExpression regex(regexp);
 
143
    return findFileRecursive(searchdir,regex);
 
144
}
 
145
 
 
146
Utils::FileName UbuntuProjectGuesser::findFileRecursive(const Utils::FileName &searchdir, const QRegularExpression &regexp)
 
147
{
 
148
    QFileInfo dirInfo = searchdir.toFileInfo();
 
149
    if(!dirInfo.exists())
 
150
        return Utils::FileName();
 
151
 
 
152
    if(!dirInfo.isDir())
 
153
        return Utils::FileName();
 
154
 
 
155
    QDir dir(dirInfo.absoluteFilePath());
 
156
    QStringList entries = dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files);
 
157
 
 
158
    foreach (const QString& entry, entries) {
 
159
        QFileInfo info(dir.absoluteFilePath(entry));
 
160
        if(info.isDir()) {
 
161
            Utils::FileName f = findFileRecursive(Utils::FileName::fromString(dir.absoluteFilePath(entry)),regexp);
 
162
            if(!f.isEmpty())
 
163
                return f;
 
164
 
 
165
            continue;
 
166
        }
 
167
 
 
168
        QRegularExpressionMatch match = regexp.match(entry);
 
169
        if(match.hasMatch()) {
 
170
            return Utils::FileName(info);
 
171
        }
 
172
    }
 
173
 
 
174
    return Utils::FileName();
 
175
}
 
176
 
 
177
QString UbuntuProjectGuesser::projectTypeFromCacheOrProject(ProjectExplorer::Project *project)
 
178
{
 
179
    //First try to get the variable from the Cache file
 
180
    if(project->activeTarget()
 
181
            && project->activeTarget()->activeBuildConfiguration())
 
182
    {
 
183
        QFile cache(project->activeTarget()->activeBuildConfiguration()->buildDirectory().toString()
 
184
                    + QDir::separator()
 
185
                    + QLatin1String("CMakeCache.txt"));
 
186
 
 
187
        if(cache.exists() && cache.open(QIODevice::ReadOnly)) {
 
188
            QRegularExpression regExp(QLatin1String("^UBUNTU_PROJECT_TYPE:(.*)=\\s*(\\S*)\\s*$"));
 
189
            QTextStream in(&cache);
 
190
            while (!in.atEnd()) {
 
191
                QString contents = in.readLine();
 
192
                QRegularExpressionMatch m = regExp.match(contents);
 
193
                if(m.hasMatch()) {
 
194
                    return m.captured(2);
 
195
                }
 
196
            }
 
197
        }
 
198
    }
 
199
 
 
200
    QFile projectFile(project->projectFilePath());
 
201
    if (!projectFile.exists() || !projectFile.open(QIODevice::ReadOnly)) {
 
202
        QRegularExpression regExp(QLatin1String("^\\s*SET\\s*\\(\\s*UBUNTU_PROJECT_TYPE\\s*\"?(\\S*)\"?"));
 
203
        QTextStream in(&projectFile);
 
204
        while (!in.atEnd()) {
 
205
            QString contents = in.readLine();
 
206
            QRegularExpressionMatch m = regExp.match(contents);
 
207
            if(m.hasMatch()) {
 
208
                return m.captured(1);
 
209
            }
 
210
        }
 
211
    }
 
212
    return QString();
 
213
}
 
214
 
 
215
} // namespace Internal
 
216
} // namespace Ubuntu