forked from qt-creator/qt-creator
Android: Detect JAVA_HOME by looking for libs/tools.jar
Task-number: QTCREATORBUG-10241 Change-Id: I8245547f851174314b99bde857f257692ed35bfb Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
This commit is contained in:
@@ -907,6 +907,24 @@ AndroidConfigurations::AndroidConfigurations(QObject *parent)
|
|||||||
this, SLOT(clearDefaultDevices(ProjectExplorer::Project*)));
|
this, SLOT(clearDefaultDevices(ProjectExplorer::Project*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utils::FileName javaHomeForJavac(const QString &location)
|
||||||
|
{
|
||||||
|
QFileInfo fileInfo(location);
|
||||||
|
int tries = 5;
|
||||||
|
while (tries > 0) {
|
||||||
|
QDir dir = fileInfo.dir();
|
||||||
|
dir.cdUp();
|
||||||
|
if (QFileInfo(dir.filePath(QLatin1String("lib/tools.jar"))).exists())
|
||||||
|
return Utils::FileName::fromString(dir.path());
|
||||||
|
if (fileInfo.isSymLink())
|
||||||
|
fileInfo.setFile(fileInfo.symLinkTarget());
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
--tries;
|
||||||
|
}
|
||||||
|
return Utils::FileName();
|
||||||
|
}
|
||||||
|
|
||||||
void AndroidConfigurations::load()
|
void AndroidConfigurations::load()
|
||||||
{
|
{
|
||||||
bool saveSettings = false;
|
bool saveSettings = false;
|
||||||
@@ -925,14 +943,18 @@ void AndroidConfigurations::load()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_config.openJDKLocation.isEmpty()) {
|
if (m_config.openJDKLocation.isEmpty()) {
|
||||||
Environment env = Environment::systemEnvironment();
|
if (HostOsInfo::isLinuxHost()) {
|
||||||
QString location = env.searchInPath(QLatin1String("javac"));
|
Environment env = Environment::systemEnvironment();
|
||||||
QFileInfo fi(location);
|
QString location = env.searchInPath(QLatin1String("javac"));
|
||||||
if (fi.exists() && fi.isExecutable() && !fi.isDir()) {
|
QFileInfo fi(location);
|
||||||
QDir parentDirectory = fi.canonicalPath();
|
if (fi.exists() && fi.isExecutable() && !fi.isDir()) {
|
||||||
parentDirectory.cdUp(); // one up from bin
|
m_config.openJDKLocation = javaHomeForJavac(location);
|
||||||
m_config.openJDKLocation = FileName::fromString(parentDirectory.absolutePath());
|
saveSettings = true;
|
||||||
saveSettings = true;
|
}
|
||||||
|
} else if (HostOsInfo::isMacHost()) {
|
||||||
|
QString javaHome = QLatin1String("/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home");
|
||||||
|
if (QFileInfo(javaHome).exists())
|
||||||
|
m_config.openJDKLocation = Utils::FileName::fromString(javaHome);
|
||||||
} else if (HostOsInfo::isWindowsHost()) {
|
} else if (HostOsInfo::isWindowsHost()) {
|
||||||
QSettings settings(QLatin1String("HKEY_LOCAL_MACHINE\\SOFTWARE\\Javasoft\\Java Development Kit"), QSettings::NativeFormat);
|
QSettings settings(QLatin1String("HKEY_LOCAL_MACHINE\\SOFTWARE\\Javasoft\\Java Development Kit"), QSettings::NativeFormat);
|
||||||
QStringList allVersions = settings.childGroups();
|
QStringList allVersions = settings.childGroups();
|
||||||
|
|||||||
Reference in New Issue
Block a user