Android: Add path to Qt java bindings to project files

Change-Id: Ia3ee35732bece5870659cac338f26f815e3ce566
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2021-02-23 14:50:01 +01:00
parent 3c80f1bd9d
commit 925c4a3198

View File

@@ -36,6 +36,7 @@
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/projectnodes.h> #include <projectexplorer/projectnodes.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <qtsupport/qtkitinformation.h>
#include <utils/environment.h> #include <utils/environment.h>
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <utils/temporarydirectory.h> #include <utils/temporarydirectory.h>
@@ -238,7 +239,9 @@ void JLSClient::setCurrentProject(ProjectExplorer::Project *project)
this, &JLSClient::updateTarget); this, &JLSClient::updateTarget);
} }
static void generateProjectFile(const FilePath &projectDir, const QString &projectName) static void generateProjectFile(const FilePath &projectDir,
const QString &qtSrc,
const QString &projectName)
{ {
const FilePath projectFilePath = projectDir.pathAppended(".project"); const FilePath projectFilePath = projectDir.pathAppended(".project");
QFile projectFile(projectFilePath.toString()); QFile projectFile(projectFilePath.toString());
@@ -253,6 +256,13 @@ static void generateProjectFile(const FilePath &projectDir, const QString &proje
writer.writeStartElement("natures"); writer.writeStartElement("natures");
writer.writeTextElement("nature", "org.eclipse.jdt.core.javanature"); writer.writeTextElement("nature", "org.eclipse.jdt.core.javanature");
writer.writeEndElement(); // natures writer.writeEndElement(); // natures
writer.writeStartElement("linkedResources");
writer.writeStartElement("link");
writer.writeTextElement("name", "qtSrc");
writer.writeTextElement("type", "2");
writer.writeTextElement("location", qtSrc);
writer.writeEndElement(); // link
writer.writeEndElement(); // linkedResources
writer.writeEndElement(); // projectDescription writer.writeEndElement(); // projectDescription
writer.writeEndDocument(); writer.writeEndDocument();
projectFile.close(); projectFile.close();
@@ -275,6 +285,9 @@ static void generateClassPathFile(const FilePath &projectDir,
writer.writeEmptyElement("classpathentry"); writer.writeEmptyElement("classpathentry");
writer.writeAttribute("kind", "src"); writer.writeAttribute("kind", "src");
writer.writeAttribute("path", sourceDir); writer.writeAttribute("path", sourceDir);
writer.writeEmptyElement("classpathentry");
writer.writeAttribute("kind", "src");
writer.writeAttribute("path", "qtSrc");
for (const QString &lib : libs) { for (const QString &lib : libs) {
writer.writeEmptyElement("classpathentry"); writer.writeEmptyElement("classpathentry");
writer.writeAttribute("kind", "lib"); writer.writeAttribute("kind", "lib");
@@ -296,6 +309,10 @@ void JLSClient::updateProjectFiles()
if (DeviceTypeKitAspect::deviceTypeId(kit) != Android::Constants::ANDROID_DEVICE_TYPE) if (DeviceTypeKitAspect::deviceTypeId(kit) != Android::Constants::ANDROID_DEVICE_TYPE)
return; return;
if (ProjectNode *node = project()->findNodeForBuildKey(target->activeBuildKey())) { if (ProjectNode *node = project()->findNodeForBuildKey(target->activeBuildKey())) {
QtSupport::BaseQtVersion *version = QtSupport::QtKitAspect::qtVersion(kit);
if (!version)
return;
const QString qtSrc = version->prefix().toString() + "/src/android/java/src";
const FilePath &projectDir = project()->rootProjectDirectory(); const FilePath &projectDir = project()->rootProjectDirectory();
if (!projectDir.exists()) if (!projectDir.exists())
return; return;
@@ -313,8 +330,8 @@ void JLSClient::updateProjectFiles()
QDir libDir(packageSourceDir.pathAppended("libs").toString()); QDir libDir(packageSourceDir.pathAppended("libs").toString());
libs << Utils::transform(libDir.entryInfoList({"*.jar"}, QDir::Files), libs << Utils::transform(libDir.entryInfoList({"*.jar"}, QDir::Files),
&QFileInfo::absoluteFilePath); &QFileInfo::absoluteFilePath);
generateProjectFile(projectDir, qtSrc, project()->displayName());
generateClassPathFile(projectDir, sourceDir.toString(), libs); generateClassPathFile(projectDir, sourceDir.toString(), libs);
generateProjectFile(projectDir, project()->displayName());
} }
} }
} }