1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <osl/diagnose.h>
22 #include <osl/file.hxx>
24 #include <vendorbase.hxx>
33 MalformedVersionException::~MalformedVersionException() = default;
35 VendorBase::VendorBase()
39 bool VendorBase::initialize(const std::vector
<std::pair
<OUString
, OUString
> >& props
)
41 //get java.vendor, java.version, java.home
42 //from system properties
44 bool bVersion
= false;
49 for (auto const& prop
: props
)
51 if(! bVendor
&& prop
.first
== "java.vendor")
53 m_sVendor
= prop
.second
;
56 else if (!bVersion
&& prop
.first
== "java.version")
58 m_sVersion
= prop
.second
;
61 else if (!bHome
&& prop
.first
== "java.home")
63 #ifndef JVM_ONE_PATH_CHECK
65 if (osl_getFileURLFromSystemPath(prop
.second
.pData
,& fileURL
.pData
) ==
68 //make sure that the drive letter have all the same case
69 //otherwise file:///c:/jre and file:///C:/jre produce two
70 //different objects!!!
71 if (makeDriveLetterSame( & fileURL
))
78 m_sHome
= prop
.second
;
82 else if (!bArch
&& prop
.first
== "os.arch")
84 m_sArch
= prop
.second
;
87 if (bVendor
&& bVersion
&& bHome
&& bArch
) {
91 if (!bVersion
|| !bVendor
|| !bHome
|| !bArch
)
94 // init m_sRuntimeLibrary
95 OSL_ASSERT(!m_sHome
.isEmpty());
96 //call virtual function to get the possible paths to the runtime library.
99 char const* const* arRtPaths
= getRuntimePaths( & size
);
100 std::vector
<OUString
> libpaths
= getVectorFromCharArray(arRtPaths
, size
);
103 for (auto const& libpath
: libpaths
)
105 //Construct an absolute path to the possible runtime
106 OUString usRt
= m_sHome
+ libpath
;
108 if(DirectoryItem::get(usRt
, item
) == File::E_None
)
111 m_sRuntimeLibrary
= usRt
;
119 // init m_sLD_LIBRARY_PATH
120 OSL_ASSERT(!m_sHome
.isEmpty());
122 char const * const * arLDPaths
= getLibraryPaths( & size
);
123 std::vector
<OUString
> ld_paths
= getVectorFromCharArray(arLDPaths
, size
);
127 for (auto const& ld_path
: ld_paths
)
129 OUString usAbsUrl
= m_sHome
+ ld_path
;
130 // convert to system path
132 if(File::getSystemPathFromFileURL(usAbsUrl
, usSysPath
) == File::E_None
)
136 m_sLD_LIBRARY_PATH
+= OUStringChar(SAL_PATHSEPARATOR
);
137 m_sLD_LIBRARY_PATH
+= usSysPath
;
149 const OUString
& VendorBase::getVendor() const
153 const OUString
& VendorBase::getVersion() const
158 const OUString
& VendorBase::getHome() const
163 const OUString
& VendorBase::getLibraryPath() const
165 return m_sLD_LIBRARY_PATH
;
168 const OUString
& VendorBase::getRuntimeLibrary() const
170 return m_sRuntimeLibrary
;
173 bool VendorBase::isValidArch() const
175 // Warning: These values come from the "os.arch" property.
176 // It is not defined what the exact values are.
177 // Oracle JRE 8 has "x86" and "amd64", the others were found at http://lopica.sourceforge.net/os.html .
178 // There might still be missing some options; we need to extend the check once we find out.
179 #if defined _WIN64 || defined MACOSX
180 #if defined __x86_64__ || defined _M_AMD64
181 return m_sArch
== "amd64" || m_sArch
== "x86_64";
182 #elif defined __aarch64__ || defined _M_ARM64
183 return m_sArch
== "aarch64";
185 #error neither arm64 nor amd64 for win64/mac? Sounds fishy.
188 return m_sArch
== "x86" || m_sArch
== "i386" || m_sArch
== "i686";
195 bool VendorBase::needsRestart() const
197 return !getLibraryPath().isEmpty();
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */