1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #if !defined INCLUDED_JFW_PLUGIN_UTIL_HXX 24 #define INCLUDED_JFW_PLUGIN_UTIL_HXX 25 26 #include "rtl/ustring.hxx" 27 #include "rtl/bootstrap.hxx" 28 #include <vector> 29 #include "vendorbase.hxx" 30 31 namespace jfw_plugin 32 { 33 34 class VendorBase; 35 std::vector<rtl::OUString> getVectorFromCharArray(char const * const * ar, int size); 36 37 /* The function uses the relative paths, such as "bin/java.exe" as provided by 38 VendorBase::getJavaExePaths and the provided path to derive the the home directory. 39 The home directory is then used as argument to getJREInfoByPath. For example 40 usBinDir is file:///c:/j2sdk/jre/bin then file:///c:/j2sdk/jre would be derived. 41 */ 42 bool getJREInfoFromBinPath( 43 const rtl::OUString& path, std::vector<rtl::Reference<VendorBase> > & vecInfos); 44 inline rtl::OUString getDirFromFile(const rtl::OUString& usFilePath); 45 void createJavaInfoFromPath(std::vector<rtl::Reference<VendorBase> >& vecInfos); 46 void createJavaInfoFromJavaHome(std::vector<rtl::Reference<VendorBase> > &vecInfos); 47 void createJavaInfoDirScan(std::vector<rtl::Reference<VendorBase> >& vecInfos); 48 #ifdef WNT 49 void createJavaInfoFromWinReg(std::vector<rtl::Reference<VendorBase> >& vecInfos); 50 #endif 51 52 bool makeDriveLetterSame(rtl::OUString * fileURL); 53 54 55 /* for std::find_if 56 Used to find a JavaInfo::Impl object in a std::vector<Impl*> which has a member usJavaHome 57 as the specified string in the constructor. 58 */ 59 struct InfoFindSame 60 { 61 rtl::OUString sJava; InfoFindSamejfw_plugin::InfoFindSame62 InfoFindSame(const rtl::OUString& sJavaHome):sJava(sJavaHome){} 63 operator ()jfw_plugin::InfoFindSame64 bool operator () (const rtl::Reference<VendorBase> & aVendorInfo) 65 { 66 return aVendorInfo->getHome().equals(sJava) == sal_True ? true : false; 67 } 68 }; 69 70 struct SameOrSubDirJREMap 71 { 72 rtl::OUString s1; SameOrSubDirJREMapjfw_plugin::SameOrSubDirJREMap73 SameOrSubDirJREMap(const rtl::OUString& s):s1(s){ 74 } 75 operator ()jfw_plugin::SameOrSubDirJREMap76 bool operator () (const std::pair<const rtl::OUString, rtl::Reference<VendorBase> > & s2) 77 { 78 if (s1 == s2.first) 79 return true; 80 rtl::OUString sSub; 81 sSub = s2.first + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")); 82 if (s1.match(sSub) == sal_True) 83 return true; 84 return false; 85 } 86 }; 87 88 89 /* Creates a VendorBase object if a JRE could be found at the specified path. 90 91 This depends if there is a JRE at all and if it is from a vendor that 92 is supported by this plugin. 93 */ 94 rtl::Reference<VendorBase> getJREInfoByPath(const rtl::OUString& path); 95 96 /* Creates a VendorBase object if a JRE could be found at the specified path. 97 98 The difference to the other getJREInfoByPath is that this function checks 99 first if the path corresponds to one of the VendorBase::getHome path already 100 contained in vecInfo. Only if there is no such entry, then the other 101 getJREInfoByPath is called. Again the created VendorBase is compared to 102 those contained in vecInfos. If it it not in there then it's added. 103 104 @return 105 true a VendorBase was created and added to the end of vecInfos. 106 false - no VendorBase has been created. Either the path did not represent a 107 supported JRE installation or there was already a VendorBase in vecInfos. 108 */ 109 bool getJREInfoByPath(const rtl::OUString& path, 110 std::vector<rtl::Reference<VendorBase> > & vecInfos); 111 112 std::vector<rtl::Reference<VendorBase> > getAllJREInfos(); 113 114 bool getJavaProps( 115 const rtl::OUString & exePath, 116 std::vector<std::pair<rtl::OUString, rtl::OUString> >& props, 117 bool * bProcessRun); 118 119 void createJavaInfoFromWinReg(std::vector<rtl::Reference<VendorBase> > & vecInfos); 120 121 void bubbleSortVersion(std::vector<rtl::Reference<VendorBase> >& vec); 122 123 rtl::Bootstrap* getBootstrap(); 124 } 125 126 #endif 127