diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2014-09-10 14:56:25 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-12-15 16:45:51 +0100 |
commit | 40138cee6b6f19a7725f3ce9316f285b86366a06 (patch) | |
tree | 9df7322d3ce91f3c67cd528bf55bc819afc3f478 /jvmfwk/plugins | |
parent | 86910c87c193345e5e36104e21b8e26790d6846d (diff) |
fdo#83753: consider JAVA_HOME and PATH when selecting JRE
adapted algorithm that selects the Java runtime to be used so that
Java installations associated with the JAVA_HOME and PATH
environment variables are preferred over others
Java installations are now analysed in the following order:
* installation that the JAVA_HOME environment
variable refers to (if it is set)
* Java installations in PATH
* other Java installation (algorithm that was used before)
Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
Conflicts:
jvmfwk/source/framework.cxx
Change-Id: I3a3ade25322def0c0432b369848f13a6b82034a1
Diffstat (limited to 'jvmfwk/plugins')
-rw-r--r-- | jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx | 99 | ||||
-rw-r--r-- | jvmfwk/plugins/sunmajor/pluginlib/util.cxx | 24 | ||||
-rw-r--r-- | jvmfwk/plugins/sunmajor/pluginlib/util.hxx | 6 |
3 files changed, 126 insertions, 3 deletions
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx index d0dac260a354..1771bcc018a5 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx @@ -404,6 +404,105 @@ javaPluginError jfw_plugin_getJavaInfoByPath( return errorcode; } +javaPluginError jfw_plugin_getJavaInfoFromJavaHome( + std::vector<pair<OUString, jfw::VersionInfo>> const& vecVendorInfos, + JavaInfo ** ppInfo) +{ + if (!ppInfo) + return JFW_PLUGIN_E_INVALID_ARG; + + rtl::Reference<VendorBase> infoJavaHome = getJavaInfoFromJavaHome(); + + if (!infoJavaHome.is()) + return JFW_PLUGIN_E_NO_JRE; + + //Check if the detected JRE matches the version requirements + typedef std::vector<pair<OUString, jfw::VersionInfo>>::const_iterator ci_pl; + for (ci_pl vendorInfo = vecVendorInfos.begin(); vendorInfo != vecVendorInfos.end(); ++vendorInfo) + { + const OUString& vendor = vendorInfo->first; + jfw::VersionInfo versionInfo = vendorInfo->second; + + if (vendor.equals(infoJavaHome->getVendor())) + { + javaPluginError errorcode = checkJavaVersionRequirements( + infoJavaHome, + versionInfo.sMinVersion, + versionInfo.sMaxVersion, + versionInfo.getExcludeVersions(), + versionInfo.getExcludeVersionSize()); + + if (errorcode == JFW_PLUGIN_E_NONE) + { + *ppInfo = createJavaInfo(infoJavaHome); + return JFW_PLUGIN_E_NONE; + } + } + } + + return JFW_PLUGIN_E_NO_JRE; +} + +javaPluginError jfw_plugin_getJavaInfosFromPath( + std::vector<std::pair<OUString, jfw::VersionInfo>> const& vecVendorInfos, + std::vector<JavaInfo*> & javaInfosFromPath) +{ + // find JREs from PATH + vector<rtl::Reference<VendorBase>> vecInfosFromPath; + createJavaInfoFromPath(vecInfosFromPath); + + vector<rtl::Reference<VendorBase> > vecVerifiedInfos; + + // copy JREs that meet version requirements to vecVerifiedInfos + typedef vector<rtl::Reference<VendorBase> >::iterator it; + for (it i= vecInfosFromPath.begin(); i != vecInfosFromPath.end(); ++i) + { + const rtl::Reference<VendorBase>& cur = *i; + + typedef std::vector<pair<OUString, jfw::VersionInfo>>::const_iterator ci_pl; + for (ci_pl vendorInfo = vecVendorInfos.begin(); vendorInfo != vecVendorInfos.end(); ++vendorInfo) + { + const OUString& vendor = vendorInfo->first; + jfw::VersionInfo versionInfo = vendorInfo->second; + + if (vendor.equals(cur->getVendor())) + { + javaPluginError errorcode = checkJavaVersionRequirements( + cur, + versionInfo.sMinVersion, + versionInfo.sMaxVersion, + versionInfo.getExcludeVersions(), + versionInfo.getExcludeVersionSize()); + + if (errorcode == JFW_PLUGIN_E_NONE) + { + vecVerifiedInfos.push_back(*i); + } + } + } + } + + if (vecVerifiedInfos.empty()) + return JFW_PLUGIN_E_NO_JRE; + + // Now vecVerifiedInfos contains all those JREs which meet the version requirements + // Transfer them into the vector that is passed out. + vector<JavaInfo*> infosFromPath; + + typedef vector<rtl::Reference<VendorBase> >::const_iterator cit; + for (cit ii = vecVerifiedInfos.begin(); ii != vecVerifiedInfos.end(); ++ii) + { + infosFromPath.push_back(createJavaInfo(*ii)); + } + + javaInfosFromPath = infosFromPath; + + return JFW_PLUGIN_E_NONE; +} + + + + #if defined(WNT) // Load msvcr71.dll using an explicit full path from where it is diff --git a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx index a30513962888..8924a5949301 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx @@ -1131,7 +1131,8 @@ void createJavaInfoFromPath(vector<rtl::Reference<VendorBase> >& vecInfos) } } -void createJavaInfoFromJavaHome(vector<rtl::Reference<VendorBase> >& vecInfos) + +rtl::Reference<VendorBase> getJavaInfoFromJavaHome() { // Get Java from JAVA_HOME environment @@ -1142,11 +1143,28 @@ void createJavaInfoFromJavaHome(vector<rtl::Reference<VendorBase> >& vecInfos) char *szJavaHome= getenv("JAVA_HOME"); if(szJavaHome) { - OUString sHome(szJavaHome,strlen(szJavaHome),osl_getThreadTextEncoding()); + OUString sHome(szJavaHome, strlen(szJavaHome), osl_getThreadTextEncoding()); OUString sHomeUrl; if(File::getFileURLFromSystemPath(sHome, sHomeUrl) == File::E_None) { - getJREInfoByPath(sHomeUrl, vecInfos); + return getJREInfoByPath(sHomeUrl); + } + } + + return NULL; +} + +void createJavaInfoFromJavaHome(vector<rtl::Reference<VendorBase> >& vecInfos) +{ + rtl::Reference<VendorBase> aInfo = getJavaInfoFromJavaHome(); + + if (aInfo.is()) + { + vector<rtl::Reference<VendorBase> >::const_iterator it_impl= std::find_if( + vecInfos.begin(),vecInfos.end(), InfoFindSame(aInfo->getHome())); + if(it_impl == vecInfos.end()) + { + vecInfos.push_back(aInfo); } } } diff --git a/jvmfwk/plugins/sunmajor/pluginlib/util.hxx b/jvmfwk/plugins/sunmajor/pluginlib/util.hxx index 0f0bf04f2619..38d3175dacc5 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/util.hxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/util.hxx @@ -39,6 +39,12 @@ bool getJREInfoFromBinPath( const OUString& path, std::vector<rtl::Reference<VendorBase> > & vecInfos); inline OUString getDirFromFile(const OUString& usFilePath); void createJavaInfoFromPath(std::vector<rtl::Reference<VendorBase> >& vecInfos); + +/* Returns a VendorBase object if JAVA_HOME environment variable points + to a JRE. + */ +rtl::Reference<VendorBase> getJavaInfoFromJavaHome(); + void createJavaInfoFromJavaHome(std::vector<rtl::Reference<VendorBase> > &vecInfos); void createJavaInfoDirScan(std::vector<rtl::Reference<VendorBase> >& vecInfos); #ifdef WNT |