Revert "tdf#158280 Replace usage of InputDialog with SvxNameDialog"
[LibreOffice.git] / jvmfwk / plugins / sunmajor / pluginlib / vendorbase.cxx
blobc2650c85f35dd27f74a34c26c5345d2c5dc585d8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 #include "util.hxx"
27 using namespace osl;
30 namespace jfw_plugin
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;
45 bool bVendor = false;
46 bool bHome = false;
47 bool bArch = false;
49 for (auto const& prop : props)
51 if(! bVendor && prop.first == "java.vendor")
53 m_sVendor = prop.second;
54 bVendor = true;
56 else if (!bVersion && prop.first == "java.version")
58 m_sVersion = prop.second;
59 bVersion = true;
61 else if (!bHome && prop.first == "java.home")
63 #ifndef JVM_ONE_PATH_CHECK
64 OUString fileURL;
65 if (osl_getFileURLFromSystemPath(prop.second.pData,& fileURL.pData) ==
66 osl_File_E_None)
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))
73 m_sHome = fileURL;
74 bHome = true;
77 #else
78 m_sHome = prop.second;
79 bHome = true;
80 #endif
82 else if (!bArch && prop.first == "os.arch")
84 m_sArch = prop.second;
85 bArch = true;
87 if (bVendor && bVersion && bHome && bArch) {
88 break;
91 if (!bVersion || !bVendor || !bHome || !bArch)
92 return false;
94 // init m_sRuntimeLibrary
95 OSL_ASSERT(!m_sHome.isEmpty());
96 //call virtual function to get the possible paths to the runtime library.
98 int size = 0;
99 char const* const* arRtPaths = getRuntimePaths( & size);
100 std::vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size);
102 bool bRt = false;
103 for (auto const& libpath : libpaths)
105 //Construct an absolute path to the possible runtime
106 OUString usRt= m_sHome + libpath;
107 DirectoryItem item;
108 if(DirectoryItem::get(usRt, item) == File::E_None)
110 //found runtime lib
111 m_sRuntimeLibrary = usRt;
112 bRt = true;
113 break;
116 if (!bRt)
117 return false;
119 // init m_sLD_LIBRARY_PATH
120 OSL_ASSERT(!m_sHome.isEmpty());
121 size = 0;
122 char const * const * arLDPaths = getLibraryPaths( & size);
123 std::vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size);
125 bool bLdPath = true;
126 int c = 0;
127 for (auto const& ld_path : ld_paths)
129 OUString usAbsUrl= m_sHome + ld_path;
130 // convert to system path
131 OUString usSysPath;
132 if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None)
135 if(c > 0)
136 m_sLD_LIBRARY_PATH+= OUStringChar(SAL_PATHSEPARATOR);
137 m_sLD_LIBRARY_PATH+= usSysPath;
139 else
141 bLdPath = false;
142 break;
144 ++c;
146 return bLdPath;
149 const OUString & VendorBase::getVendor() const
151 return m_sVendor;
153 const OUString & VendorBase::getVersion() const
155 return m_sVersion;
158 const OUString & VendorBase::getHome() const
160 return m_sHome;
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";
184 #else
185 #error neither arm64 nor amd64 for win64/mac? Sounds fishy.
186 #endif
187 #elif defined _WIN32
188 return m_sArch == "x86" || m_sArch == "i386" || m_sArch == "i686";
189 #else
190 (void)this;
191 return true;
192 #endif
195 bool VendorBase::needsRestart() const
197 return !getLibraryPath().isEmpty();
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */