Commit 498d1981 authored by Daniel Teske's avatar Daniel Teske

Android: JavaParser, adjust paths from build to source directory

Since we copy the java files to the build directory, we need to adjust
the path that the java compiler emits for error messages.

For that the JavaParser needs to know the source directory, which is
the android package source dir and the build directory. The
AndroidDeployQtStep thus needs more information then just the
input json file and now stores the path to the .pro file to both
retrieve the input file and the android package source directory.

Task-number: QTCREATORBUG-10904
Change-Id: Ib5141b35b610bc2eee568a096fc5e930f9eb2e47
Reviewed-by: default avatarEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
parent 02314e24
......@@ -61,6 +61,7 @@ const QLatin1String SignPackageKey("SignPackage");
const QLatin1String BuildTargetSdkKey("BuildTargetSdk");
const QLatin1String VerboseOutputKey("VerboseOutput");
const QLatin1String InputFile("InputFile");
const QLatin1String ProFilePathForInputFile("ProFilePathForInputFile");
const Core::Id AndroidDeployQtStep::Id("Qt4ProjectManager.AndroidDeployQtStep");
//////////////////
......@@ -213,9 +214,9 @@ bool AndroidDeployQtStep::init()
if (!version)
return false;
ProjectExplorer::Project *project = target()->project();
QmakeProjectManager::QmakeProject *pro = static_cast<QmakeProjectManager::QmakeProject *>(project());
JavaParser *parser = new JavaParser;
parser->setProjectFileList(project->files(ProjectExplorer::Project::AllFiles));
parser->setProjectFileList(pro->files(ProjectExplorer::Project::AllFiles));
setOutputParser(parser);
QString command = version->qmakeProperty("QT_HOST_BINS");
......@@ -234,10 +235,21 @@ bool AndroidDeployQtStep::init()
deploymentMethod = QLatin1String("bundled");
QString outputDir = bc->buildDirectory().appendPath(QLatin1String(Constants::ANDROID_BUILDDIRECTORY)).toString();
const QmakeProjectManager::QmakeProFileNode *node = pro->rootQmakeProjectNode()->findProFileFor(m_proFilePathForInputFile);
if (!node) { // should never happen
emit addOutput(tr("Internal Error: Could not find .pro file."), BuildStep::ErrorMessageOutput);
return false;
}
QString inputFile = node->singleVariableValue(QmakeProjectManager::AndroidDeploySettingsFile);
if (inputFile.isEmpty()) { // should never happen
emit addOutput(tr("Internal Error: Unknown android deployment json file location"), BuildStep::ErrorMessageOutput);
return false;
}
QStringList arguments;
arguments << QLatin1String("--input")
<< m_inputFile
<< inputFile
<< QLatin1String("--output")
<< outputDir
<< QLatin1String("--deployment")
......@@ -250,6 +262,9 @@ bool AndroidDeployQtStep::init()
<< QLatin1String("--jdk")
<< AndroidConfigurations::instance().openJDKPath().toString();
parser->setSourceDirectory(Utils::FileName::fromString(node->singleVariableValue(QmakeProjectManager::AndroidPackageSourceDir)));
parser->setBuildDirectory(Utils::FileName::fromString(outputDir));
if (m_verbose)
arguments << QLatin1String("--verbose");
if (m_avdName.isEmpty())
......@@ -347,17 +362,12 @@ void AndroidDeployQtStep::updateInputFile()
QmakeProjectManager::QmakeProject *pro = static_cast<QmakeProjectManager::QmakeProject *>(project());
QList<QmakeProjectManager::QmakeProFileNode *> nodes = pro->applicationProFiles();
QStringList inputFiles;
foreach (QmakeProjectManager::QmakeProFileNode *node, nodes)
inputFiles << node->singleVariableValue(QmakeProjectManager::AndroidDeploySettingsFile);
if (!inputFiles.contains(m_inputFile))
m_inputFile.clear();
if (m_inputFile.isEmpty()) {
// not yet selected one or no longer exists
if (!inputFiles.isEmpty())
m_inputFile = inputFiles.first();
const QmakeProjectManager::QmakeProFileNode *node = pro->rootQmakeProjectNode()->findProFileFor(m_proFilePathForInputFile);
if (!nodes.contains(const_cast<QmakeProjectManager::QmakeProFileNode *>(node))) {
if (!nodes.isEmpty())
m_proFilePathForInputFile = nodes.first()->path();
else
m_proFilePathForInputFile.clear();
}
emit inputFileChanged();
......@@ -388,7 +398,7 @@ bool AndroidDeployQtStep::fromMap(const QVariantMap &map)
m_signPackage = false; // don't restore this
m_buildTargetSdk = map.value(BuildTargetSdkKey).toString();
m_verbose = map.value(VerboseOutputKey).toBool();
m_inputFile = map.value(InputFile).toString();
m_proFilePathForInputFile = map.value(ProFilePathForInputFile).toString();
return ProjectExplorer::BuildStep::fromMap(map);
}
......@@ -400,7 +410,7 @@ QVariantMap AndroidDeployQtStep::toMap() const
map.insert(SignPackageKey, m_signPackage);
map.insert(BuildTargetSdkKey, m_buildTargetSdk);
map.insert(VerboseOutputKey, m_verbose);
map.insert(InputFile, m_inputFile);
map.insert(ProFilePathForInputFile, m_proFilePathForInputFile);
return map;
}
......@@ -481,14 +491,14 @@ void AndroidDeployQtStep::setVerboseOutput(bool verbose)
m_verbose = verbose;
}
QString AndroidDeployQtStep::inputFile() const
QString AndroidDeployQtStep::proFilePathForInputFile() const
{
return m_inputFile;
return m_proFilePathForInputFile;
}
void AndroidDeployQtStep::setInputFile(const QString &file)
void AndroidDeployQtStep::setProFilePathForInputFile(const QString &path)
{
m_inputFile = file;
m_proFilePathForInputFile = path;
}
bool AndroidDeployQtStep::runInGuiThread() const
......
......@@ -104,8 +104,8 @@ public:
bool verboseOutput() const;
void setVerboseOutput(bool verbose);
QString inputFile() const;
void setInputFile(const QString &file);
QString proFilePathForInputFile() const;
void setProFilePathForInputFile(const QString &path);
bool runInGuiThread() const;
......@@ -150,7 +150,7 @@ private:
QString m_avdName;
QString m_apkPath;
QString m_targetArch;
QString m_inputFile;
QString m_proFilePathForInputFile;
int m_deviceAPILevel;
static const Core::Id Id;
......
......@@ -187,12 +187,10 @@ void AndroidDeployQtWidget::updateInputFileUi()
m_ui->inputFileComboBox->setVisible(true);
m_ui->inputFileComboBox->clear();
foreach (QmakeProjectManager::QmakeProFileNode *node, nodes) {
QString file = node->singleVariableValue(QmakeProjectManager::AndroidDeploySettingsFile);
m_ui->inputFileComboBox->addItem(node->displayName(), file);
}
foreach (QmakeProjectManager::QmakeProFileNode *node, nodes)
m_ui->inputFileComboBox->addItem(node->displayName(), node->path());
int index = m_ui->inputFileComboBox->findData(m_step->inputFile());
int index = m_ui->inputFileComboBox->findData(m_step->proFilePathForInputFile());
m_ui->inputFileComboBox->setCurrentIndex(index);
m_ignoreChange = false;
}
......@@ -202,8 +200,8 @@ void AndroidDeployQtWidget::inputFileComboBoxIndexChanged()
{
if (m_ignoreChange)
return;
QString text = m_ui->inputFileComboBox->itemData(m_ui->inputFileComboBox->currentIndex()).toString();
m_step->setInputFile(text);
QString proFilePath = m_ui->inputFileComboBox->itemData(m_ui->inputFileComboBox->currentIndex()).toString();
m_step->setProFilePathForInputFile(proFilePath);
}
QString AndroidDeployQtWidget::displayName() const
......
......@@ -31,6 +31,7 @@
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/task.h>
#include <QFileInfo>
using namespace Android::Internal;
using namespace ProjectExplorer;
......@@ -56,6 +57,16 @@ void JavaParser::setProjectFileList(const QStringList &fileList)
m_fileList = fileList;
}
void JavaParser::setBuildDirectory(const Utils::FileName &buildDirectory)
{
m_buildDirectory = buildDirectory;
}
void JavaParser::setSourceDirectory(const Utils::FileName &sourceDirectory)
{
m_sourceDirectory = sourceDirectory;
}
void JavaParser::parse(const QString &line)
{
if (m_javaRegExp.indexIn(line) > -1) {
......@@ -63,16 +74,24 @@ void JavaParser::parse(const QString &line)
int lineno = m_javaRegExp.cap(3).toInt(&ok);
if (!ok)
lineno = -1;
QString file = m_javaRegExp.cap(2);
for (int i = 0; i < m_fileList.size(); i++)
if (m_fileList[i].endsWith(file)) {
file = m_fileList[i];
break;
}
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;
}
}
Task task(Task::Error,
m_javaRegExp.cap(4).trimmed(),
Utils::FileName::fromString(file) /* filename */,
file /* filename */,
lineno,
Constants::TASK_CATEGORY_COMPILE);
emit addTask(task);
......
......@@ -31,6 +31,7 @@
#define JAVAPARSER_H
#include <projectexplorer/ioutputparser.h>
#include <utils/fileutils.h>
namespace Android {
namespace Internal {
......@@ -45,11 +46,16 @@ public:
void stdError(const QString &line);
void setProjectFileList(const QStringList &fileList);
void setBuildDirectory(const Utils::FileName &buildDirectory);
void setSourceDirectory(const Utils::FileName &sourceDirectory);
private:
void parse(const QString &line);
QRegExp m_javaRegExp;
QStringList m_fileList;
Utils::FileName m_sourceDirectory;
Utils::FileName m_buildDirectory;
};
} // namespace Internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment