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