Check each potential JRE location only once

i.e., after recent "fdo#83753: consider JAVA_HOME and PATH when selecting JRE"
fix, if jfw_findAndSelectJRE found no suitable JRE in
jfw_plugin_getJavaInfoFromJavaHome or jfw_plugin_getJavaInfosFromPath, do not
re-check those locations in jfw_plugin_getAllJavaInfos.

Change-Id: If4e085b4fceff5b2494c7b7b84ac51691dbc78cc
This commit is contained in:
Stephan Bergmann
2014-12-15 16:42:03 +01:00
parent 0136acb836
commit 5e9a2e9b0f
6 changed files with 127 additions and 91 deletions

View File

@@ -22,11 +22,13 @@
#define INCLUDED_JVMFWK_INC_VENDORPLUGIN_HXX
#include <jvmfwk/framework.h>
#include <rtl/ref.hxx>
#include <rtl/ustring.h>
#include "jni.h"
#include <vector>
#include <utility>
#include "../source/elements.hxx"
#include <vendorbase.hxx>
/**
@file
@@ -112,13 +114,15 @@ typedef enum
version strings.
*/
javaPluginError jfw_plugin_getAllJavaInfos(
bool checkJavaHomeAndPath,
OUString const& sVendor,
OUString const& sMinVersion,
OUString const& sMaxVersion,
rtl_uString * * arExcludeList,
sal_Int32 nSizeExcludeList,
JavaInfo*** parJavaInfo,
sal_Int32 *nSizeJavaInfo);
sal_Int32 *nSizeJavaInfo,
std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos);
/** obtains information for a JRE at a given location.
@@ -202,7 +206,8 @@ javaPluginError jfw_plugin_getJavaInfoByPath(
*/
javaPluginError jfw_plugin_getJavaInfoFromJavaHome(
std::vector<std::pair<OUString, jfw::VersionInfo>> const& vecVendorInfos,
JavaInfo ** ppInfo);
JavaInfo ** ppInfo,
std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos);
/** obtains information about installations of Java Runtime Environments (JREs)
@@ -244,7 +249,8 @@ javaPluginError jfw_plugin_getJavaInfoFromJavaHome(
javaPluginError jfw_plugin_getJavaInfosFromPath(
std::vector<std::pair<OUString, jfw::VersionInfo>> const& vecVendorInfos,
std::vector<JavaInfo*> & vecJavaInfosFromPath);
std::vector<JavaInfo*> & vecJavaInfosFromPath,
std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos);
/** starts a Java Virtual Machine.

View File

@@ -299,13 +299,15 @@ javaPluginError checkJavaVersionRequirements(
}
javaPluginError jfw_plugin_getAllJavaInfos(
bool checkJavaHomeAndPath,
OUString const& sVendor,
OUString const& sMinVersion,
OUString const& sMaxVersion,
rtl_uString * *arExcludeList,
sal_Int32 nLenList,
JavaInfo*** parJavaInfo,
sal_Int32 *nLenInfoList)
sal_Int32 *nLenInfoList,
std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos)
{
OSL_ASSERT(parJavaInfo);
OSL_ASSERT(nLenInfoList);
@@ -326,7 +328,7 @@ javaPluginError jfw_plugin_getAllJavaInfos(
//Find all JREs
vector<rtl::Reference<VendorBase> > vecInfos =
getAllJREInfos();
addAllJREInfos(checkJavaHomeAndPath, infos);
vector<rtl::Reference<VendorBase> > vecVerifiedInfos;
typedef vector<rtl::Reference<VendorBase> >::iterator it;
@@ -406,15 +408,17 @@ javaPluginError jfw_plugin_getJavaInfoByPath(
javaPluginError jfw_plugin_getJavaInfoFromJavaHome(
std::vector<pair<OUString, jfw::VersionInfo>> const& vecVendorInfos,
JavaInfo ** ppInfo)
JavaInfo ** ppInfo, std::vector<rtl::Reference<VendorBase>> & infos)
{
if (!ppInfo)
return JFW_PLUGIN_E_INVALID_ARG;
rtl::Reference<VendorBase> infoJavaHome = getJavaInfoFromJavaHome();
std::vector<rtl::Reference<VendorBase>> infoJavaHome;
addJavaInfoFromJavaHome(infos, infoJavaHome);
if (!infoJavaHome.is())
if (infoJavaHome.empty())
return JFW_PLUGIN_E_NO_JRE;
assert(infoJavaHome.size() == 1);
//Check if the detected JRE matches the version requirements
typedef std::vector<pair<OUString, jfw::VersionInfo>>::const_iterator ci_pl;
@@ -423,10 +427,10 @@ javaPluginError jfw_plugin_getJavaInfoFromJavaHome(
const OUString& vendor = vendorInfo->first;
jfw::VersionInfo versionInfo = vendorInfo->second;
if (vendor.equals(infoJavaHome->getVendor()))
if (vendor.equals(infoJavaHome[0]->getVendor()))
{
javaPluginError errorcode = checkJavaVersionRequirements(
infoJavaHome,
infoJavaHome[0],
versionInfo.sMinVersion,
versionInfo.sMaxVersion,
versionInfo.getExcludeVersions(),
@@ -434,7 +438,7 @@ javaPluginError jfw_plugin_getJavaInfoFromJavaHome(
if (errorcode == JFW_PLUGIN_E_NONE)
{
*ppInfo = createJavaInfo(infoJavaHome);
*ppInfo = createJavaInfo(infoJavaHome[0]);
return JFW_PLUGIN_E_NONE;
}
}
@@ -445,11 +449,12 @@ javaPluginError jfw_plugin_getJavaInfoFromJavaHome(
javaPluginError jfw_plugin_getJavaInfosFromPath(
std::vector<std::pair<OUString, jfw::VersionInfo>> const& vecVendorInfos,
std::vector<JavaInfo*> & javaInfosFromPath)
std::vector<JavaInfo*> & javaInfosFromPath,
std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos)
{
// find JREs from PATH
vector<rtl::Reference<VendorBase>> vecInfosFromPath;
createJavaInfoFromPath(vecInfosFromPath);
addJavaInfosFromPath(infos, vecInfosFromPath);
vector<rtl::Reference<VendorBase> > vecVerifiedInfos;

View File

@@ -139,23 +139,35 @@ bool decodeOutput(const OString& s, OUString* out);
namespace
{
bool getAndAddJREInfoByPath(const OUString& path,
std::vector<rtl::Reference<VendorBase> > & vecInfos)
bool addJREInfo(
rtl::Reference<VendorBase> const & info,
std::vector<rtl::Reference<VendorBase>> & infos)
{
bool ret = false;
rtl::Reference<VendorBase> aInfo = getJREInfoByPath(path);
if (aInfo.is())
{
ret = true;
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);
}
auto i(
std::find_if(
infos.begin(), infos.end(), InfoFindSame(info->getHome())));
if (i == infos.end()) {
infos.push_back(info);
return true;
} else {
return false;
}
}
bool getAndAddJREInfoByPath(
const OUString& path,
std::vector<rtl::Reference<VendorBase> > & allInfos,
std::vector<rtl::Reference<VendorBase> > & addedInfos)
{
rtl::Reference<VendorBase> aInfo = getJREInfoByPath(path);
if (aInfo.is()) {
if (addJREInfo(aInfo, allInfos)) {
addedInfos.push_back(aInfo);
}
return true;
} else {
return false;
}
return ret;
}
OUString getLibraryLocation()
@@ -572,7 +584,9 @@ bool decodeOutput(const OString& s, OUString* out)
#if defined WNT
void createJavaInfoFromWinReg(std::vector<rtl::Reference<VendorBase> > & vecInfos)
void addJavaInfoFromWinReg(
std::vector<rtl::Reference<VendorBase> > & allInfos,
std::vector<rtl::Reference<VendorBase> > & addedInfos)
{
// Get Java s from registry
std::vector<OUString> vecJavaHome;
@@ -583,7 +597,7 @@ void createJavaInfoFromWinReg(std::vector<rtl::Reference<VendorBase> > & vecInfo
for(ItHome it_home= vecJavaHome.begin(); it_home != vecJavaHome.end();
it_home++)
{
getAndAddJREInfoByPath(*it_home, vecInfos);
getAndAddJREInfoByPath(*it_home, allInfos, addedInfos);
}
}
@@ -594,7 +608,7 @@ void createJavaInfoFromWinReg(std::vector<rtl::Reference<VendorBase> > & vecInfo
for(ItHome it_home= vecJavaHome.begin(); it_home != vecJavaHome.end();
it_home++)
{
getAndAddJREInfoByPath(*it_home, vecInfos);
getAndAddJREInfoByPath(*it_home, allInfos, addedInfos);
}
}
}
@@ -736,8 +750,9 @@ void bubbleSortVersion(vector<rtl::Reference<VendorBase> >& vec)
}
void getJREInfoFromBinPath(
const OUString& path, vector<rtl::Reference<VendorBase> > & vecInfos)
void addJREInfoFromBinPath(
const OUString& path, vector<rtl::Reference<VendorBase>> & allInfos,
std::vector<rtl::Reference<VendorBase>> & addedInfos)
{
// file:///c:/jre/bin
//map: jre/bin/java.exe
@@ -782,37 +797,41 @@ void getJREInfoFromBinPath(
sHome = sBinPath.copy(index - 1);
}
}
if (!sHome.isEmpty())
if (!sHome.isEmpty()
&& getAndAddJREInfoByPath(path, allInfos, addedInfos))
{
if (getAndAddJREInfoByPath(sHome, vecInfos))
return;
return;
}
}
}
}
vector<Reference<VendorBase> > getAllJREInfos()
vector<Reference<VendorBase> > addAllJREInfos(
bool checkJavaHomeAndPath,
std::vector<rtl::Reference<VendorBase>> & allInfos)
{
vector<Reference<VendorBase> > vecInfos;
vector<Reference<VendorBase> > addedInfos;
#if defined WNT
// Get Javas from the registry
createJavaInfoFromWinReg(vecInfos);
addJavaInfoFromWinReg(allInfos, addedInfos);
#endif // WNT
#ifndef JVM_ONE_PATH_CHECK
createJavaInfoFromJavaHome(vecInfos);
//this function should be called after createJavaInfoDirScan.
//Otherwise in SDKs Java may be started twice
createJavaInfoFromPath(vecInfos);
if (checkJavaHomeAndPath) {
addJavaInfoFromJavaHome(allInfos, addedInfos);
//this function should be called after addJavaInfosDirScan.
//Otherwise in SDKs Java may be started twice
addJavaInfosFromPath(allInfos, addedInfos);
}
#endif
#ifdef UNX
createJavaInfoDirScan(vecInfos);
addJavaInfosDirScan(allInfos, addedInfos);
#endif
bubbleSortVersion(vecInfos);
return vecInfos;
bubbleSortVersion(addedInfos);
return addedInfos;
}
@@ -1080,7 +1099,9 @@ inline OUString getDirFromFile(const OUString& usFilePath)
return usFilePath.copy(0, index);
}
void createJavaInfoFromPath(vector<rtl::Reference<VendorBase> >& vecInfos)
void addJavaInfosFromPath(
std::vector<rtl::Reference<VendorBase>> & allInfos,
std::vector<rtl::Reference<VendorBase>> & addedInfos)
{
// Get Java from PATH environment variable
static const char sCurDir[] = ".";
@@ -1119,7 +1140,7 @@ void createJavaInfoFromPath(vector<rtl::Reference<VendorBase> >& vecInfos)
}
if(!usBin.isEmpty())
{
getJREInfoFromBinPath(usBin, vecInfos);
addJREInfoFromBinPath(usBin, allInfos, addedInfos);
}
}
}
@@ -1129,7 +1150,9 @@ void createJavaInfoFromPath(vector<rtl::Reference<VendorBase> >& vecInfos)
}
rtl::Reference<VendorBase> getJavaInfoFromJavaHome()
void addJavaInfoFromJavaHome(
std::vector<rtl::Reference<VendorBase>> & allInfos,
std::vector<rtl::Reference<VendorBase>> & addedInfos)
{
// Get Java from JAVA_HOME environment
@@ -1144,24 +1167,7 @@ rtl::Reference<VendorBase> getJavaInfoFromJavaHome()
OUString sHomeUrl;
if(File::getFileURLFromSystemPath(sHome, sHomeUrl) == File::E_None)
{
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);
getAndAddJREInfoByPath(sHomeUrl, allInfos, addedInfos);
}
}
}
@@ -1185,25 +1191,31 @@ bool makeDriveLetterSame(OUString * fileURL)
#ifdef UNX
#ifdef SOLARIS
void createJavaInfoDirScan(vector<rtl::Reference<VendorBase> >& vecInfos)
void addJavaInfosDirScan(
std::vector<rtl::Reference<VendorBase>> & allInfos,
std::vector<rtl::Reference<VendorBase>> & addedInfos)
{
JFW_TRACE2("Checking /usr/jdk/latest");
getAndAddJREInfoByPath("file:////usr/jdk/latest", vecInfos);
getAndAddJREInfoByPath("file:////usr/jdk/latest", allInfos, addedInfos);
}
#elif defined MACOSX && defined X86_64
void createJavaInfoDirScan(vector<rtl::Reference<VendorBase> >& vecInfos)
void addJavaInfosDirScan(
std::vector<rtl::Reference<VendorBase>> & allInfos,
std::vector<rtl::Reference<VendorBase>> & addedInfos)
{
// Oracle Java 7
getAndAddJREInfoByPath("file:///Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home", vecInfos);
getAndAddJREInfoByPath("file:///Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home", allInfos, addedInfos);
}
#else
void createJavaInfoDirScan(vector<rtl::Reference<VendorBase> >& vecInfos)
void addJavaInfosDirScan(
std::vector<rtl::Reference<VendorBase>> & allInfos,
std::vector<rtl::Reference<VendorBase>> & addedInfos)
{
OUString excMessage = "[Java framework] sunjavaplugin: "
"Error in function createJavaInfoDirScan in util.cxx.";
"Error in function addJavaInfosDirScan in util.cxx.";
int cJavaNames= sizeof(g_arJavaNames) / sizeof(char*);
boost::scoped_array<OUString> sarJavaNames(new OUString[cJavaNames]);
OUString *arNames = sarJavaNames.get();
@@ -1273,7 +1285,8 @@ void createJavaInfoDirScan(vector<rtl::Reference<VendorBase> >& vecInfos)
}
JFW_TRACE2("Checking if directory: " << aStatus.getFileURL() << " is a Java");
getAndAddJREInfoByPath(aStatus.getFileURL(),vecInfos);
getAndAddJREInfoByPath(
aStatus.getFileURL(), allInfos, addedInfos);
}
JFW_ENSURE(errNext == File::E_None || errNext == File::E_NOENT,
@@ -1305,7 +1318,8 @@ void createJavaInfoDirScan(vector<rtl::Reference<VendorBase> >& vecInfos)
&& (islash
> RTL_CONSTASCII_LENGTH("file://")))
usDir3 = usDir3.copy(0, islash);
getAndAddJREInfoByPath(usDir3,vecInfos);
getAndAddJREInfoByPath(
usDir3, allInfos, addedInfos);
}
}
}

View File

@@ -35,21 +35,25 @@ std::vector<OUString> getVectorFromCharArray(char const * const * ar, int size);
argument to getJREInfoByPath. For example usBinDir is
file:///c:/j2sdk/jre/bin then file:///c:/j2sdk/jre would be derived.
*/
void getJREInfoFromBinPath(
const OUString& path, std::vector<rtl::Reference<VendorBase> > & vecInfos);
void addJREInfoFromBinPath(
const OUString& path,
std::vector<rtl::Reference<VendorBase>> & allInfos,
std::vector<rtl::Reference<VendorBase>> & addedInfos);
inline OUString getDirFromFile(const OUString& usFilePath);
void createJavaInfoFromPath(std::vector<rtl::Reference<VendorBase> >& vecInfos);
void addJavaInfosFromPath(
std::vector<rtl::Reference<VendorBase>> & allInfos,
std::vector<rtl::Reference<VendorBase>> & addedInfos);
/* Returns a VendorBase object if JAVA_HOME environment variable points
to a JRE.
*/
rtl::Reference<VendorBase> getJavaInfoFromJavaHome();
void addJavaInfoFromJavaHome(
std::vector<rtl::Reference<VendorBase>> & allInfos,
std::vector<rtl::Reference<VendorBase>> & addedInfos);
void createJavaInfoFromJavaHome(std::vector<rtl::Reference<VendorBase> > &vecInfos);
void createJavaInfoDirScan(std::vector<rtl::Reference<VendorBase> >& vecInfos);
#ifdef WNT
void createJavaInfoFromWinReg(std::vector<rtl::Reference<VendorBase> >& vecInfos);
#endif
void addJavaInfosDirScan(
std::vector<rtl::Reference<VendorBase>> & allInfos,
std::vector<rtl::Reference<VendorBase>> & addedInfos);
bool makeDriveLetterSame(OUString * fileURL);
@@ -95,7 +99,8 @@ struct SameOrSubDirJREMap
*/
rtl::Reference<VendorBase> getJREInfoByPath(const OUString& path);
std::vector<rtl::Reference<VendorBase> > getAllJREInfos();
std::vector<rtl::Reference<VendorBase> > addAllJREInfos(
bool checkJavaHomeAndPath, std::vector<rtl::Reference<VendorBase>> & infos);
bool getJavaProps(
const OUString & exePath,
@@ -105,8 +110,6 @@ bool getJavaProps(
std::vector<std::pair<OUString, OUString> >& props,
bool * bProcessRun);
void createJavaInfoFromWinReg(std::vector<rtl::Reference<VendorBase> > & vecInfos);
void bubbleSortVersion(std::vector<rtl::Reference<VendorBase> >& vec);
rtl::Bootstrap* getBootstrap();

View File

@@ -86,14 +86,17 @@ javaFrameworkError SAL_CALL jfw_findAllJREs(JavaInfo ***pparInfo, sal_Int32 *pSi
//maxVersion and excludeVersions
sal_Int32 cInfos = 0;
JavaInfo** arInfos = NULL;
std::vector<rtl::Reference<jfw_plugin::VendorBase>> infos;
javaPluginError plerr = jfw_plugin_getAllJavaInfos(
true,
vendor,
versionInfo.sMinVersion,
versionInfo.sMaxVersion,
versionInfo.getExcludeVersions(),
versionInfo.getExcludeVersionSize(),
& arInfos,
& cInfos);
& cInfos,
infos);
if (plerr != JFW_PLUGIN_E_NONE)
return JFW_E_ERROR;
@@ -408,10 +411,12 @@ javaFrameworkError SAL_CALL jfw_findAndSelectJRE(JavaInfo **pInfo)
std::pair<OUString, jfw::VersionInfo>(vendor, versionInfo));
}
std::vector<rtl::Reference<jfw_plugin::VendorBase>> infos;
// first inspect Java installation that the JAVA_HOME
// environment variable points to (if it is set)
JavaInfo* pHomeInfo = NULL;
if (jfw_plugin_getJavaInfoFromJavaHome(versionInfos, &pHomeInfo)
if (jfw_plugin_getJavaInfoFromJavaHome(versionInfos, &pHomeInfo, infos)
== JFW_PLUGIN_E_NONE)
{
aCurrentInfo = pHomeInfo;
@@ -431,7 +436,8 @@ javaFrameworkError SAL_CALL jfw_findAndSelectJRE(JavaInfo **pInfo)
if (!bInfoFound)
{
std::vector<JavaInfo*> vecJavaInfosFromPath;
if (jfw_plugin_getJavaInfosFromPath(versionInfos, vecJavaInfosFromPath)
if (jfw_plugin_getJavaInfosFromPath(
versionInfos, vecJavaInfosFromPath, infos)
== JFW_PLUGIN_E_NONE)
{
std::vector<JavaInfo*>::const_iterator it = vecJavaInfosFromPath.begin();
@@ -482,13 +488,15 @@ javaFrameworkError SAL_CALL jfw_findAndSelectJRE(JavaInfo **pInfo)
sal_Int32 cInfos = 0;
JavaInfo** arInfos = NULL;
javaPluginError plerr = jfw_plugin_getAllJavaInfos(
false,
vendor,
versionInfo.sMinVersion,
versionInfo.sMaxVersion,
versionInfo.getExcludeVersions(),
versionInfo.getExcludeVersionSize(),
& arInfos,
& cInfos);
& cInfos,
infos);
if (plerr != JFW_PLUGIN_E_NONE)
continue;