Commit 2bd789ae authored by Daniel Teske's avatar Daniel Teske
Browse files

Android: Detect JAVA_HOME by looking for libs/tools.jar



Task-number: QTCREATORBUG-10241
Change-Id: I8245547f851174314b99bde857f257692ed35bfb
Reviewed-by: default avatarEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
parent ad69558b
......@@ -907,6 +907,24 @@ AndroidConfigurations::AndroidConfigurations(QObject *parent)
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()
{
bool saveSettings = false;
......@@ -925,14 +943,18 @@ void AndroidConfigurations::load()
}
if (m_config.openJDKLocation.isEmpty()) {
Environment env = Environment::systemEnvironment();
QString location = env.searchInPath(QLatin1String("javac"));
QFileInfo fi(location);
if (fi.exists() && fi.isExecutable() && !fi.isDir()) {
QDir parentDirectory = fi.canonicalPath();
parentDirectory.cdUp(); // one up from bin
m_config.openJDKLocation = FileName::fromString(parentDirectory.absolutePath());
saveSettings = true;
if (HostOsInfo::isLinuxHost()) {
Environment env = Environment::systemEnvironment();
QString location = env.searchInPath(QLatin1String("javac"));
QFileInfo fi(location);
if (fi.exists() && fi.isExecutable() && !fi.isDir()) {
m_config.openJDKLocation = javaHomeForJavac(location);
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()) {
QSettings settings(QLatin1String("HKEY_LOCAL_MACHINE\\SOFTWARE\\Javasoft\\Java Development Kit"), QSettings::NativeFormat);
QStringList allVersions = settings.childGroups();
......
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