diff options
Diffstat (limited to 'jvmfwk/plugins')
22 files changed, 4536 insertions, 0 deletions
diff --git a/jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx b/jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx new file mode 100755 index 000000000000..3b73f88f7963 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx @@ -0,0 +1,188 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_jvmfwk.hxx" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "sal/main.h" +#include "sal/types.h" +#include "osl/thread.h" +#include "rtl/ustring.hxx" +#include "rtl/byteseq.hxx" +#include "jvmfwk/framework.h" + +using namespace rtl; + +#define OUSTR(x) OUString(RTL_CONSTASCII_USTRINGPARAM( x )) + +static sal_Bool hasOption(char const * szOption, int argc, char** argv); +static rtl::OString getLD_LIBRARY_PATH(const rtl::ByteSequence & vendorData); +static bool findAndSelect(JavaInfo**); +//static sal_Bool printPaths(const OUString& sPathFile); + +#define HELP_TEXT \ +"\njavaldx is necessary to make Java work on some UNIX platforms." \ +"It prints a string to std out that consists of directories which " \ +"have to be included into the LD_LIBRARY_PATH variable.The setting of " \ +"the variable usually occurs in a shell script that runs javaldx.\n" \ +"The directories are from the chosen java installation. \n" \ +"Options are: \n"\ +"--help or -h\n" + +SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) +{ + if( hasOption("--help",argc, argv) || hasOption("-h", argc, argv)) + { + fprintf(stdout, HELP_TEXT);// default + return 0; + } + javaFrameworkError errcode = JFW_E_NONE; + sal_Bool bEnabled = sal_False; + errcode = jfw_getEnabled( & bEnabled); + if (errcode == JFW_E_NONE && bEnabled == sal_False) + { + //Do not do any preparation because that may only slow startup time. + return 0; + } + else if (errcode != JFW_E_NONE && errcode != JFW_E_DIRECT_MODE) + { + fprintf(stderr,"javaldx failed! \n"); + return -1; + } + + + JavaInfo * pInfo = NULL; + errcode = jfw_getSelectedJRE( & pInfo); + + if (errcode == JFW_E_INVALID_SETTINGS) + { + fprintf(stderr,"javaldx failed. User must select a JRE from options dialog!"); + return -1; + } + else if (errcode != JFW_E_NONE) + { + fprintf(stderr,"javaldx failed! \n"); + return -1; + } + + if (pInfo == NULL) + { + if (false == findAndSelect(&pInfo)) + return -1; + } + else + { + //check if the JRE was not uninstalled + sal_Bool bExist = sal_False; + errcode = jfw_existJRE(pInfo, &bExist); + if (errcode == JFW_E_NONE) + { + if (!bExist && !findAndSelect(&pInfo)) + return -1; + } + else + { + fprintf(stderr, "javaldx: Could not determine if JRE still exist\n"); + return -1; + } + } + + //Only do something if the sunjavaplugin created this JavaInfo + rtl::OUString sVendor1(RTL_CONSTASCII_USTRINGPARAM("Sun Microsystems Inc.")); + rtl::OUString sVendor2(RTL_CONSTASCII_USTRINGPARAM("IBM Corporation")); + rtl::OUString sVendor3(RTL_CONSTASCII_USTRINGPARAM("Blackdown Java-Linux Team")); + rtl::OUString sVendor4(RTL_CONSTASCII_USTRINGPARAM("Apple Inc.")); + rtl::OUString sVendor5(RTL_CONSTASCII_USTRINGPARAM("Apple Computer, Inc.")); + rtl::OUString sVendor6(RTL_CONSTASCII_USTRINGPARAM("BEA Systems, Inc.")); + rtl::OUString sVendor7(RTL_CONSTASCII_USTRINGPARAM("Free Software Foundation, Inc.")); + rtl::OUString sVendor8(RTL_CONSTASCII_USTRINGPARAM("The FreeBSD Foundation")); + if ( ! (sVendor1.equals(pInfo->sVendor) == sal_True + || sVendor2.equals(pInfo->sVendor) == sal_True + || sVendor3.equals(pInfo->sVendor) == sal_True + || sVendor4.equals(pInfo->sVendor) == sal_True + || sVendor5.equals(pInfo->sVendor) == sal_True + || sVendor6.equals(pInfo->sVendor) == sal_True + || sVendor7.equals(pInfo->sVendor) == sal_True + || sVendor8.equals(pInfo->sVendor) == sal_True)) + return 0; + + rtl::OString sPaths = getLD_LIBRARY_PATH(pInfo->arVendorData); + fprintf(stdout, "%s\n", sPaths.getStr()); + jfw_freeJavaInfo(pInfo); + + return 0; +} + +rtl::OString getLD_LIBRARY_PATH(const rtl::ByteSequence & vendorData) +{ + const sal_Unicode* chars = (sal_Unicode*) vendorData.getConstArray(); + sal_Int32 len = vendorData.getLength(); + rtl::OUString sData(chars, len / 2); + //the runtime lib is on the first line + sal_Int32 index = 0; + rtl::OUString aToken = sData.getToken( 1, '\n', index); + + rtl::OString paths = + rtl::OUStringToOString(aToken, osl_getThreadTextEncoding()); + return paths; +} + +static sal_Bool hasOption(char const * szOption, int argc, char** argv) +{ + sal_Bool retVal= sal_False; + for(sal_Int16 i= 1; i < argc; i++) + { + if( ! strcmp(argv[i], szOption)) + { + retVal= sal_True; + break; + } + } + return retVal; +} + +static bool findAndSelect(JavaInfo ** ppInfo) +{ + javaFrameworkError errcode = jfw_findAndSelectJRE(ppInfo); + if (errcode == JFW_E_NO_JAVA_FOUND) + { + fprintf(stderr,"javaldx: Could not find a Java Runtime Environment! \n"); + return false; + } + else if (errcode != JFW_E_NONE && errcode != JFW_E_DIRECT_MODE) + { + fprintf(stderr,"javaldx failed!\n"); + return false; + } + return true; +} + + + diff --git a/jvmfwk/plugins/sunmajor/javaenvsetup/makefile.mk b/jvmfwk/plugins/sunmajor/javaenvsetup/makefile.mk new file mode 100755 index 000000000000..8e4a79581327 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/javaenvsetup/makefile.mk @@ -0,0 +1,56 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=javaldx +TARGET=javaldx +TARGETTYPE=CUI +NO_DEFAULT_STL=TRUE +LIBTARGET=NO +ENABLE_EXCEPTIONS=true + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +.IF "$(OS)" != "MACOSX" && "$(SOLAR_JAVA)" != "" + +OBJFILES=$(OBJ)$/javaldx.obj + +APP1TARGET=javaldx +APP1OBJS=$(OBJFILES) +APP1STDLIBS=$(SALLIB) $(JVMFWKLIB) +APP1RPATH=UREBIN + +.ENDIF + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/jvmfwk/plugins/sunmajor/pluginlib/JREProperties.java b/jvmfwk/plugins/sunmajor/pluginlib/JREProperties.java new file mode 100644 index 000000000000..b0930e1c93f3 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/JREProperties.java @@ -0,0 +1,85 @@ +import java.util.*; +import java.awt.*; + +/** This class prints out the system properties. + + We cannot print the strings directly because of encoding issues. Since + about 1.3.1 one can start java with the option -Dfile.encoding=UTF-8, but + unfortunately this works only with later update - versions (for example, + 1.3.1_07). Therefore we use this scheme. The property string has this form: + name=value + + Every character is cast to an integer which value is printed, followed by a + space. If all characters of the string are printed, then a new line is printed. +*/ +public class JREProperties +{ + static public void main(String[] args) + { + try + { + boolean bNoAccess = false; + if(args.length > 0) + { + if (args[0].equals("noaccessibility")) + bNoAccess = true; + } + + //Find out on what operation system we are running. On Windows 98 + //we must not call getDefaultToolkit, because the office may freeze + //#i44608. + boolean bW98 = false; + String os = System.getProperty("os.name"); + + if (os != null) + { + os = os.trim(); + if (os.equalsIgnoreCase("Windows 98") || + os.indexOf("Windows 98") != -1) + bW98 = true; + } + + //We need to be able to switch this part off because + //it causes an exception if the DISPLAY variable has + //a false value. Setting the noaccessibility argument + //can be done by providing a sunjavaplugin.ini with + //the bootstrap parameter JFW_PLUGIN_NO_NOT_CHECK_ACCESSIBILITY + //set to "1" + if (bNoAccess == false && ! bW98) + { + try{ + //This line is needed to get the accessibility properties + Toolkit tk = java.awt.Toolkit.getDefaultToolkit(); + } + catch(Throwable e) + { + System.err.println(e); + } + } + + + Properties p = System.getProperties(); + Enumeration e = p.propertyNames(); + for (; e.hasMoreElements() ;) { + String sProp = (String) e.nextElement(); + String sCompleteProp = sProp + "=" + p.getProperty(sProp); + char[] arChars = new char[sCompleteProp.length()]; + sCompleteProp.getChars(0, sCompleteProp.length(), arChars, 0); + for (int c = 0; c < arChars.length; c++) { + System.out.print(String.valueOf((int) arChars[c])); + System.out.print(" "); + } + System.out.print("\n"); + } + } + catch(Exception e) + { + System.err.println(e); + } + + System.exit(0); + } + + + +} diff --git a/jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h b/jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h new file mode 100644 index 000000000000..47b6504ee6e2 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h @@ -0,0 +1,120 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#if !defined INCLUDED_JFW_PLUGIN_DIAGNOSTICS_HXX +#define INCLUDED_JFW_PLUGIN_DIAGNOSTICS_HXX +#include "osl/diagnose.h" +#include "rtl/ustring.hxx" +#include <stdio.h> + +#if OSL_DEBUG_LEVEL >= 1 +#define JFW_ENSURE(c, m) _JFW_ENSURE(c, OSL_THIS_FILE, __LINE__, m) +#else +#define JFW_ENSURE(c, m) ((void) 0) +#endif + +#if OSL_DEBUG_LEVEL >= 2 +#define JFW_WARNING2(c, m) _JFW_WARNING2(c, OSL_THIS_FILE, __LINE__, m) +#else +#define JFW_WARNING2(c, m) ((void) 0) +#endif + + +#if OSL_DEBUG_LEVEL >= 0 +#define JFW_TRACE0(m) jfw_trace(m) +#else +#define JFW_TRACE0(m) ((void) 0) +#endif + +#if OSL_DEBUG_LEVEL >= 1 +#define JFW_TRACE1(m) jfw_trace(m) +#else +#define JFW_TRACE1(m) ((void) 0) +#endif + +#if OSL_DEBUG_LEVEL >= 2 +#define JFW_TRACE2(m) jfw_trace(m) +#else +#define JFW_TRACE2(m) ((void) 0) +#endif + + + +#define _JFW_ENSURE(c, f, l, m) jfw_ensure(c, f, l, m) +#define _JFW_WARNING(c, f, l, m) jfw_warning2(c, f, l, m); + + +namespace jfw_plugin +{ + +inline void jfw_ensure(bool + #if OSL_DEBUG_LEVEL > 0 /* prevent warning in pro version */ + condition + #endif + , const sal_Char * + #if OSL_DEBUG_LEVEL > 0 /* prevent warning in pro version */ + pzFile + #endif + , sal_Int32 + #if OSL_DEBUG_LEVEL > 0 /* prevent warning in pro version */ + line + #endif + , const rtl::OUString& message ) +{ + rtl::OString oMsg = rtl::OUStringToOString(message, osl_getThreadTextEncoding()); + _OSL_ENSURE(condition, pzFile, line, oMsg.getStr()); +} + +inline void jfw_warning2(bool condition, const sal_Char * pzFile, sal_Int32 line, + sal_Char * pzMessage) +{ + if (! condition) + fprintf( + stderr, "%s\n File: %s\n Line: %ld", pzMessage, pzFile, + sal::static_int_cast< unsigned long >(line)); +} + +inline void jfw_trace(rtl::OUString message) +{ + rtl::OString oMsg = rtl::OUStringToOString(message, osl_getThreadTextEncoding()); + fprintf(stderr,"%s", oMsg.getStr()); +} + +inline void jfw_trace(const sal_Char * pzMessage) +{ + if (pzMessage) + fprintf(stderr,"%s", pzMessage); +} + +inline void jfw_trace(const rtl::OString& message) +{ + if (message.getLength() > 0) + fprintf(stderr,"%s", message.getStr()); +} + +} + +#endif diff --git a/jvmfwk/plugins/sunmajor/pluginlib/gnujre.cxx b/jvmfwk/plugins/sunmajor/pluginlib/gnujre.cxx new file mode 100644 index 000000000000..41ba8b2e27a8 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/gnujre.cxx @@ -0,0 +1,287 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_jvmfwk.hxx" + +#include "osl/file.hxx" +#include "osl/thread.h" +#include "gnujre.hxx" +#include "util.hxx" + +using namespace rtl; +using namespace std; +using namespace osl; + +namespace jfw_plugin +{ + +Reference<VendorBase> GnuInfo::createInstance() +{ + return new GnuInfo; +} + +char const* const* GnuInfo::getJavaExePaths(int * size) +{ + static char const * ar[] = { + "gij", + "bin/gij", + }; + *size = sizeof (ar) / sizeof (char*); + return ar; +} + +#if defined(MIPS) && defined(OSL_LITENDIAN) +#define GCJ_JFW_PLUGIN_ARCH "mipsel" +#else +#define GCJ_JFW_PLUGIN_ARCH JFW_PLUGIN_ARCH +#endif + +char const* const* GnuInfo::getRuntimePaths(int * size) +{ + static char const* ar[]= { + "/libjvm.so", + "/lib/" GCJ_JFW_PLUGIN_ARCH "/client/libjvm.so", + "/gcj-4.1.1/libjvm.so", + "/libgcj.so.7", + "/libgcj.so.6" + }; + *size = sizeof(ar) / sizeof (char*); + return ar; +} + +bool GnuInfo::initialize(vector<pair<OUString, OUString> > props) +{ + //get java.vendor, java.version, java.home, + //javax.accessibility.assistive_technologies from system properties + + OUString sVendor; + OUString sJavaLibraryPath; + typedef vector<pair<OUString, OUString> >::const_iterator it_prop; + OUString sVendorProperty( + RTL_CONSTASCII_USTRINGPARAM("java.vendor")); + OUString sVersionProperty( + RTL_CONSTASCII_USTRINGPARAM("java.version")); + OUString sJavaHomeProperty( + RTL_CONSTASCII_USTRINGPARAM("java.home")); + OUString sJavaLibraryPathProperty( + RTL_CONSTASCII_USTRINGPARAM("java.library.path")); + OUString sGNUHomeProperty( + RTL_CONSTASCII_USTRINGPARAM("gnu.classpath.home.url")); + OUString sAccessProperty( + RTL_CONSTASCII_USTRINGPARAM("javax.accessibility.assistive_technologies")); + + bool bVersion = false; + bool bVendor = false; + bool bHome = false; + bool bJavaHome = false; + bool bJavaLibraryPath = false; + bool bAccess = false; + + typedef vector<pair<OUString, OUString> >::const_iterator it_prop; + for (it_prop i = props.begin(); i != props.end(); i++) + { + if(! bVendor && sVendorProperty.equals(i->first)) + { + m_sVendor = i->second; + bVendor = true; + } + else if (!bVersion && sVersionProperty.equals(i->first)) + { + m_sVersion = i->second; + bVersion = true; + } + else if (!bHome && sGNUHomeProperty.equals(i->first)) + { + m_sHome = i->second; + bHome = true; + } + else if (!bJavaHome && sJavaHomeProperty.equals(i->first)) + { + OUString fileURL; + if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) == + osl_File_E_None) + { + //make sure that the drive letter have all the same case + //otherwise file:///c:/jre and file:///C:/jre produce two + //different objects!!! + if (makeDriveLetterSame( & fileURL)) + { + m_sJavaHome = fileURL; + bJavaHome = true; + } + } + } + else if (!bJavaLibraryPath && sJavaLibraryPathProperty.equals(i->first)) + { + sal_Int32 nIndex = 0; + osl_getFileURLFromSystemPath(i->second.getToken(0, ':', nIndex).pData, &sJavaLibraryPath.pData); + bJavaLibraryPath = true; + } + else if (!bAccess && sAccessProperty.equals(i->first)) + { + if (i->second.getLength() > 0) + { + m_bAccessibility = true; + bAccess = true; + } + } + // the javax.accessibility.xxx property may not be set. Therefore we + //must search through all properties. + + } + if (!bVersion || !bVendor || !bHome) + return false; + + if (!m_sJavaHome.getLength()) + m_sJavaHome = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///usr/lib")); + + // init m_sRuntimeLibrary + OSL_ASSERT(m_sHome.getLength()); + //call virtual function to get the possible paths to the runtime library. + + int size = 0; + char const* const* arRtPaths = getRuntimePaths( & size); + vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size); + + bool bRt = false; + typedef vector<OUString>::const_iterator i_path; + for(i_path ip = libpaths.begin(); ip != libpaths.end(); ip++) + { + //Construct an absolute path to the possible runtime + OUString usRt= m_sHome + *ip; + DirectoryItem item; + if(DirectoryItem::get(usRt, item) == File::E_None) + { + //found runtime lib + m_sRuntimeLibrary = usRt; + bRt = true; + break; + } + } + + if (!bRt) + { + m_sHome = m_sJavaHome; + for(i_path ip = libpaths.begin(); ip != libpaths.end(); ip++) + { + //Construct an absolute path to the possible runtime + OUString usRt= m_sHome + *ip; + DirectoryItem item; + if(DirectoryItem::get(usRt, item) == File::E_None) + { + //found runtime lib + m_sRuntimeLibrary = usRt; + bRt = true; + break; + } + } + } + + // try to find it by the java.library.path property + if (!bRt && m_sJavaHome != sJavaLibraryPath) + { + m_sHome = sJavaLibraryPath; + for(i_path ip = libpaths.begin(); ip != libpaths.end(); ip++) + { + //Construct an absolute path to the possible runtime + OUString usRt= m_sHome + *ip; + DirectoryItem item; + if(DirectoryItem::get(usRt, item) == File::E_None) + { + //found runtime lib + m_sRuntimeLibrary = usRt; + bRt = true; + break; + } + } + } + +#ifdef X86_64 + //Make one last final legacy attempt on x86_64 in case the distro placed it in lib64 instead + if (!bRt && m_sJavaHome != rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///usr/lib"))) + { + m_sHome = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:///usr/lib64")); + for(i_path ip = libpaths.begin(); ip != libpaths.end(); ip++) + { + //Construct an absolute path to the possible runtime + OUString usRt= m_sHome + *ip; + DirectoryItem item; + if(DirectoryItem::get(usRt, item) == File::E_None) + { + //found runtime lib + m_sRuntimeLibrary = usRt; + bRt = true; + break; + } + } + } +#endif + + if (!bRt) + return false; + + // init m_sLD_LIBRARY_PATH + OSL_ASSERT(m_sHome.getLength()); + size = 0; + char const * const * arLDPaths = getLibraryPaths( & size); + vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size); + + char arSep[]= {SAL_PATHSEPARATOR, 0}; + OUString sPathSep= OUString::createFromAscii(arSep); + bool bLdPath = true; + int c = 0; + for(i_path il = ld_paths.begin(); il != ld_paths.end(); il ++, c++) + { + OUString usAbsUrl= m_sHome + *il; + // convert to system path + OUString usSysPath; + if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None) + { + + if(c > 0) + m_sLD_LIBRARY_PATH+= sPathSep; + m_sLD_LIBRARY_PATH+= usSysPath; + } + else + { + bLdPath = false; + break; + } + } + if (bLdPath == false) + return false; + + return true; +} + +int GnuInfo::compareVersions(const rtl::OUString&) const +{ + return 0; +} + +} diff --git a/jvmfwk/plugins/sunmajor/pluginlib/gnujre.hxx b/jvmfwk/plugins/sunmajor/pluginlib/gnujre.hxx new file mode 100644 index 000000000000..687be19d771f --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/gnujre.hxx @@ -0,0 +1,55 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#if !defined INCLUDED_JFW_PLUGIN_GNUJRE_HXX +#define INCLUDED_JFW_PLUGIN_GNUJRE_HXX + +#include "vendorbase.hxx" +#include "vendorlist.hxx" + +namespace jfw_plugin +{ + +class GnuInfo: public VendorBase +{ +private: + rtl::OUString m_sJavaHome; +public: + static char const* const* getJavaExePaths(int * size); + + static rtl::Reference<VendorBase> createInstance(); + + virtual char const* const* getRuntimePaths(int * size); + + virtual bool initialize( + std::vector<std::pair<rtl::OUString, rtl::OUString> > props); + virtual int compareVersions(const rtl::OUString& sSecond) const; + +}; + +} +#endif diff --git a/jvmfwk/plugins/sunmajor/pluginlib/makefile.mk b/jvmfwk/plugins/sunmajor/pluginlib/makefile.mk new file mode 100644 index 000000000000..25ff106973ec --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/makefile.mk @@ -0,0 +1,117 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/..$/.. + +PRJNAME= jvmfwk + +TARGET = plugin + +ENABLE_EXCEPTIONS=TRUE + +LIBTARGET=NO + +UNOCOMPONENT1=sunjavaplugin + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +DLLPRE = + +# ------------------------------------------------------------------ + +#.INCLUDE : ..$/cppumaker.mk +.IF "$(SOLAR_JAVA)"!="" + +SLOFILES= \ + $(SLO)$/sunversion.obj \ + $(SLO)$/sunjavaplugin.obj \ + $(SLO)$/vendorbase.obj \ + $(SLO)$/util.obj \ + $(SLO)$/sunjre.obj \ + $(SLO)$/gnujre.obj \ + $(SLO)$/vendorlist.obj \ + $(SLO)$/otherjre.obj + +LIB1OBJFILES= $(SLOFILES) + + + +LIB1TARGET=$(SLB)$/$(UNOCOMPONENT1).lib + +SHL1TARGET= $(UNOCOMPONENT1) + + +SHL1STDLIBS= \ + $(CPPULIB) \ + $(CPPUHELPER) \ + $(SALLIB) \ + $(SALHELPERLIB) + + +.IF "$(GUI)" == "WNT" +.IF "$(COM)"!="GCC" +SHL1STDLIBS += uwinapi.lib advapi32.lib +.ELSE +SHL1STDLIBS += -luwinapi -ladvapi32 +.ENDIF # GCC +.ENDIF #WNT + +SHL1VERSIONMAP = sunjavaplugin.map +SHL1DEPN= +SHL1IMPLIB= i$(UNOCOMPONENT1) +SHL1LIBS= $(LIB1TARGET) +SHL1DEF= $(MISC)$/$(SHL1TARGET).def +DEF1NAME= $(SHL1TARGET) +SHL1RPATH= URELIB + +JAVACLASSFILES= \ + $(CLASSDIR)$/JREProperties.class + +JAVAFILES = $(subst,$(CLASSDIR)$/, $(subst,.class,.java $(JAVACLASSFILES))) + +.ENDIF # SOLAR_JAVA + + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +.IF "$(GUI)"=="WNT" +BOOTSTRAPFILE=$(BIN)$/sunjavaplugin.ini +.ELSE +BOOTSTRAPFILE=$(BIN)$/sunjavapluginrc +.ENDIF + + +$(BOOTSTRAPFILE): sunjavapluginrc + -$(COPY) $< $@ + + +ALLTAR: \ + $(BOOTSTRAPFILE) + diff --git a/jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx b/jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx new file mode 100644 index 000000000000..3ae1c0f16b92 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx @@ -0,0 +1,130 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_jvmfwk.hxx" + +#include "osl/thread.h" +#include "otherjre.hxx" + +using namespace rtl; +using namespace std; + + +namespace jfw_plugin +{ + +Reference<VendorBase> OtherInfo::createInstance() +{ + return new OtherInfo; +} + + +char const* const* OtherInfo::getJavaExePaths(int * size) +{ + static char const * ar[] = { +#if defined(WNT) || defined(OS2) + "bin/java.exe", + "jre/bin/java.exe" +#elif UNX + "bin/java", + "jre/bin/java" +#endif + }; + *size = sizeof (ar) / sizeof (char*); + return ar; +} + +char const* const* OtherInfo::getRuntimePaths(int * size) +{ + static char const* ar[]= { +#if defined(WNT) + "/bin/client/jvm.dll", + "/bin/hotspot/jvm.dll", + "/bin/classic/jvm.dll", + "/bin/jrockit/jvm.dll" +#elif defined(OS2) + "/bin/classic/jvm.dll", + "/bin/client/jvm.dll", + "/bin/hotspot/jvm.dll" +#elif UNX +#ifdef MACOSX + "/../../../../../Frameworks/JavaVM.framework/JavaVM" //as of 1.6.0_22 +#else + "/lib/" JFW_PLUGIN_ARCH "/client/libjvm.so", // for Blackdown PPC + "/lib/" JFW_PLUGIN_ARCH "/server/libjvm.so", // for Blackdown AMD64 + "/lib/" JFW_PLUGIN_ARCH "/classic/libjvm.so", // for Blackdown PPC + "/lib/" JFW_PLUGIN_ARCH "/jrockit/libjvm.so", // for Java of BEA Systems + "/bin/classic/libjvm.so", // fallback for older for IBM Java + "/jre/bin/classic/libjvm.so" // fallback for older for IBM Java +#endif +#endif + + }; + *size = sizeof(ar) / sizeof (char*); + return ar; +} + +char const* const* OtherInfo::getLibraryPaths(int* size) +{ + +#ifdef UNX + static char const * ar[] = { +#ifdef MACOSX + //mac version does not have a ld library path anymore +#else + "/bin", + "/jre/bin", + "/bin/classic", + "/jre/bin/classic", + "/lib/" JFW_PLUGIN_ARCH "/client", + "/lib/" JFW_PLUGIN_ARCH "/server", + "/lib/" JFW_PLUGIN_ARCH "/classic", + "/lib/" JFW_PLUGIN_ARCH "/jrockit", + "/lib/" JFW_PLUGIN_ARCH "/native_threads", + "/lib/" JFW_PLUGIN_ARCH +#endif + }; + + *size = sizeof(ar) / sizeof (char*); + return ar; +#else + size = 0; + return NULL; +#endif +} + +int OtherInfo::compareVersions(const rtl::OUString& /*sSecond*/) const +{ + //Need to provide an own algorithm for comparing version. + //Because this function returns always 0, which means the version of + //this JRE and the provided version "sSecond" are equal, one cannot put + //any excludeVersion entries in the javavendors.xml file. + return 0; +} + +} diff --git a/jvmfwk/plugins/sunmajor/pluginlib/otherjre.hxx b/jvmfwk/plugins/sunmajor/pluginlib/otherjre.hxx new file mode 100644 index 000000000000..2a09681eb63c --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/otherjre.hxx @@ -0,0 +1,53 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#if !defined INCLUDED_JFW_PLUGIN_OTHERJRE_HXX +#define INCLUDED_JFW_PLUGIN_OTHERJRE_HXX + +#include "vendorbase.hxx" +#include "vendorlist.hxx" + +namespace jfw_plugin +{ +/* Do not forget to put this class in the vendor map in vendorlist.cxx + */ +class OtherInfo: public VendorBase +{ +public: + static char const* const* getJavaExePaths(int * size); + + static rtl::Reference<VendorBase> createInstance(); + + using VendorBase::getLibraryPaths; + virtual char const* const* getRuntimePaths(int * size); + virtual char const* const* getLibraryPaths(int* size); + virtual int compareVersions(const rtl::OUString& sSecond) const; + +}; + +} +#endif diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx new file mode 100644 index 000000000000..b43edf53b3bc --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx @@ -0,0 +1,676 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_jvmfwk.hxx" +#if OSL_DEBUG_LEVEL > 0 +#include <stdio.h> +#endif +#include <string.h> + +#include "boost/scoped_array.hpp" +#include "osl/diagnose.h" +#include "rtl/ustring.hxx" +#include "rtl/ustrbuf.hxx" +#include "osl/module.hxx" +#include "osl/mutex.hxx" +#include "osl/thread.hxx" +#include "osl/file.hxx" +#include "rtl/instance.hxx" +#include "osl/getglobalmutex.hxx" +#include <setjmp.h> +#include <signal.h> +#include <stack> + +#include "jni.h" +#include "rtl/byteseq.hxx" +#include "jvmfwk/vendorplugin.h" +#include "util.hxx" +#include "sunversion.hxx" +#include "vendorlist.hxx" +#include "diagnostics.h" + +#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) +#define SUN_MICRO "Sun Microsystems Inc." + +using namespace osl; +using namespace rtl; +using namespace std; +using namespace jfw_plugin; + +namespace { + +struct PluginMutex: public ::rtl::Static<osl::Mutex, PluginMutex> {}; + +#if defined UNX +OString getPluginJarPath( + const OUString & sVendor, + const OUString& sLocation, + const OUString& sVersion) +{ + OString ret; + OUString sName1(RTL_CONSTASCII_USTRINGPARAM("javaplugin.jar")); + OUString sName2(RTL_CONSTASCII_USTRINGPARAM("plugin.jar")); + OUString sPath; + if (sVendor.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SUN_MICRO)))) + { + SunVersion ver142("1.4.2-ea"); + SunVersion ver150("1.5.0-ea"); + SunVersion ver(sVersion); + OSL_ASSERT(ver142 && ver150 && ver); + + OUString sName; + if (ver < ver142) + { + sName = sName1; + } + else if (ver < ver150) + {//this will cause ea, beta etc. to have plugin.jar in path. + //but this does not harm. 1.5.0-beta < 1.5.0 + sName = sName2; + } + if (sName.getLength()) + { + sName = sLocation + OUSTR("/lib/") + sName; + OSL_VERIFY( + osl_getSystemPathFromFileURL(sName.pData, & sPath.pData) + == osl_File_E_None); + } + } + else + { + char sep[] = {SAL_PATHSEPARATOR, 0}; + OUString sName(sLocation + OUSTR("/lib/") + sName1); + OUString sPath1; + OUString sPath2; + if (osl_getSystemPathFromFileURL(sName.pData, & sPath1.pData) + == osl_File_E_None) + { + sName = sLocation + OUSTR("/lib/") + sName2; + if (osl_getSystemPathFromFileURL(sName.pData, & sPath2.pData) + == osl_File_E_None) + { + sPath = sPath1 + OUString::createFromAscii(sep) + sPath2; + } + } + OSL_ASSERT(sPath.getLength()); + } + ret = rtl::OUStringToOString(sPath, osl_getThreadTextEncoding()); + + return ret; +} +#endif // UNX + + +JavaInfo* createJavaInfo(const rtl::Reference<VendorBase> & info) +{ + JavaInfo* pInfo = (JavaInfo*) rtl_allocateMemory(sizeof(JavaInfo)); + if (pInfo == NULL) + return NULL; + rtl::OUString sVendor = info->getVendor(); + pInfo->sVendor = sVendor.pData; + rtl_uString_acquire(sVendor.pData); + rtl::OUString sHome = info->getHome(); + pInfo->sLocation = sHome.pData; + rtl_uString_acquire(pInfo->sLocation); + rtl::OUString sVersion = info->getVersion(); + pInfo->sVersion = sVersion.pData; + rtl_uString_acquire(pInfo->sVersion); + pInfo->nFeatures = info->supportsAccessibility() ? 1 : 0; + pInfo->nRequirements = info->needsRestart() ? JFW_REQUIRE_NEEDRESTART : 0; + rtl::OUStringBuffer buf(1024); + buf.append(info->getRuntimeLibrary()); + if (info->getLibraryPaths().getLength() > 0) + { + buf.appendAscii("\n"); + buf.append(info->getLibraryPaths()); + buf.appendAscii("\n"); + } + + rtl::OUString sVendorData = buf.makeStringAndClear(); + rtl::ByteSequence byteSeq( (sal_Int8*) sVendorData.pData->buffer, + sVendorData.getLength() * sizeof(sal_Unicode)); + pInfo->arVendorData = byteSeq.get(); + rtl_byte_sequence_acquire(pInfo->arVendorData); + + return pInfo; +} + +rtl::OUString getRuntimeLib(const rtl::ByteSequence & data) +{ + const sal_Unicode* chars = (sal_Unicode*) data.getConstArray(); + sal_Int32 len = data.getLength(); + rtl::OUString sData(chars, len / 2); + //the runtime lib is on the first line + sal_Int32 index = 0; + rtl::OUString aToken = sData.getToken( 0, '\n', index); + + return aToken; +} + +jmp_buf jmp_jvm_abort; +sig_atomic_t g_bInGetJavaVM = 0; + +extern "C" void JNICALL abort_handler() +{ + // If we are within JNI_CreateJavaVM then we jump back into getJavaVM + if( g_bInGetJavaVM != 0 ) + { + fprintf( stderr, "JavaVM: JNI_CreateJavaVM called _exit, caught by abort_handler in javavm.cxx\n"); + longjmp( jmp_jvm_abort, 0); + } +} + +} + +extern "C" +javaPluginError jfw_plugin_getAllJavaInfos( + rtl_uString *sVendor, + rtl_uString *sMinVersion, + rtl_uString *sMaxVersion, + rtl_uString * *arExcludeList, + sal_Int32 nLenList, + JavaInfo*** parJavaInfo, + sal_Int32 *nLenInfoList) +{ + OSL_ASSERT(sVendor); + OSL_ASSERT(sMinVersion); + OSL_ASSERT(sMaxVersion); + OSL_ASSERT(parJavaInfo); + OSL_ASSERT(parJavaInfo); + OSL_ASSERT(nLenInfoList); + if (!sVendor || !sMinVersion || !sMaxVersion || !parJavaInfo || !nLenInfoList) + return JFW_PLUGIN_E_INVALID_ARG; + + //nLenlist contains the number of element in arExcludeList. + //If no exclude list is provided then nLenList must be 0 + OSL_ASSERT( ! (arExcludeList == NULL && nLenList > 0)); + if (arExcludeList == NULL && nLenList > 0) + return JFW_PLUGIN_E_INVALID_ARG; + + OUString ouVendor(sVendor); + OUString ouMinVer(sMinVersion); + OUString ouMaxVer(sMaxVersion); + + OSL_ASSERT(ouVendor.getLength() > 0); + if (ouVendor.getLength() == 0) + return JFW_PLUGIN_E_INVALID_ARG; + + JavaInfo** arInfo = NULL; + + //Find all JREs + vector<rtl::Reference<VendorBase> > vecInfos = + getAllJREInfos(); + vector<rtl::Reference<VendorBase> > vecVerifiedInfos; + + typedef vector<rtl::Reference<VendorBase> >::iterator it; + for (it i= vecInfos.begin(); i != vecInfos.end(); i++) + { + const rtl::Reference<VendorBase>& cur = *i; + + if (ouVendor.equals(cur->getVendor()) == sal_False) + continue; + + if (ouMinVer.getLength() > 0) + { + try + { + if (cur->compareVersions(sMinVersion) == -1) + continue; + } + catch (MalformedVersionException&) + { + //The minVersion was not recognized as valid for this vendor. + JFW_ENSURE( + 0,OUSTR("[Java framework]sunjavaplugin does not know version: ") + + ouMinVer + OUSTR(" for vendor: ") + cur->getVendor() + + OUSTR(" .Check minimum Version.") ); + return JFW_PLUGIN_E_WRONG_VERSION_FORMAT; + } + } + + if (ouMaxVer.getLength() > 0) + { + try + { + if (cur->compareVersions(sMaxVersion) == 1) + continue; + } + catch (MalformedVersionException&) + { + //The maxVersion was not recognized as valid for this vendor. + JFW_ENSURE( + 0,OUSTR("[Java framework]sunjavaplugin does not know version: ") + + ouMaxVer + OUSTR(" for vendor: ") + cur->getVendor() + + OUSTR(" .Check maximum Version.") ); + return JFW_PLUGIN_E_WRONG_VERSION_FORMAT; + } + } + + if (arExcludeList > 0) + { + bool bExclude = false; + for (int j = 0; j < nLenList; j++) + { + rtl::OUString sExVer(arExcludeList[j]); + try + { + if (cur->compareVersions(sExVer) == 0) + { + bExclude = true; + break; + } + } + catch (MalformedVersionException&) + { + //The excluded version was not recognized as valid for this vendor. + JFW_ENSURE( + 0,OUSTR("[Java framework]sunjavaplugin does not know version: ") + + sExVer + OUSTR(" for vendor: ") + cur->getVendor() + + OUSTR(" .Check excluded versions.") ); + return JFW_PLUGIN_E_WRONG_VERSION_FORMAT; + } + } + if (bExclude == true) + continue; + } + vecVerifiedInfos.push_back(*i); + } + //Now vecVerifiedInfos contains all those JREs which meet the version requirements + //Transfer them into the array that is passed out. + arInfo = (JavaInfo**) rtl_allocateMemory(vecVerifiedInfos.size() * sizeof (JavaInfo*)); + int j = 0; + typedef vector<rtl::Reference<VendorBase> >::const_iterator cit; + for (cit ii = vecVerifiedInfos.begin(); ii != vecVerifiedInfos.end(); ii++, j++) + { + arInfo[j] = createJavaInfo(*ii); + } + *nLenInfoList = vecVerifiedInfos.size(); + + + *parJavaInfo = arInfo; + return JFW_PLUGIN_E_NONE; +} + +extern "C" +javaPluginError jfw_plugin_getJavaInfoByPath( + rtl_uString *path, + rtl_uString *sVendor, + rtl_uString *sMinVersion, + rtl_uString *sMaxVersion, + rtl_uString * *arExcludeList, + sal_Int32 nLenList, + JavaInfo ** ppInfo) +{ + javaPluginError errcode = JFW_PLUGIN_E_NONE; + + OSL_ASSERT(path); + OSL_ASSERT(sVendor); + OSL_ASSERT(sMinVersion); + OSL_ASSERT(sMaxVersion); + if (!path || !sVendor || !sMinVersion || !sMaxVersion || !ppInfo) + return JFW_PLUGIN_E_INVALID_ARG; + OUString ouPath(path); + OSL_ASSERT(ouPath.getLength() > 0); + if (ouPath.getLength() == 0) + return JFW_PLUGIN_E_INVALID_ARG; + + //nLenlist contains the number of element in arExcludeList. + //If no exclude list is provided then nLenList must be 0 + OSL_ASSERT( ! (arExcludeList == NULL && nLenList > 0)); + if (arExcludeList == NULL && nLenList > 0) + return JFW_PLUGIN_E_INVALID_ARG; + + OUString ouVendor(sVendor); + OUString ouMinVer(sMinVersion); + OUString ouMaxVer(sMaxVersion); + + OSL_ASSERT(ouVendor.getLength() > 0); + if (ouVendor.getLength() == 0) + return JFW_PLUGIN_E_INVALID_ARG; + + rtl::Reference<VendorBase> aVendorInfo = getJREInfoByPath(ouPath); + if (aVendorInfo.is() == sal_False) + return JFW_PLUGIN_E_NO_JRE; + + //Check if the detected JRE matches the version requirements + if (ouVendor.equals(aVendorInfo->getVendor()) == sal_False) + return JFW_PLUGIN_E_NO_JRE; + + if (ouMinVer.getLength() > 0) + { + int nRes = 0; + try + { + nRes = aVendorInfo->compareVersions(ouMinVer); + } + catch (MalformedVersionException&) + { + //The minVersion was not recognized as valid for this vendor. + JFW_ENSURE( + 0,OUSTR("[Java framework]sunjavaplugin does not know version: ") + + ouMinVer + OUSTR(" for vendor: ") + aVendorInfo->getVendor() + + OUSTR(" .Check minimum Version.") ); + return JFW_PLUGIN_E_WRONG_VERSION_FORMAT; + } + if (nRes < 0) + return JFW_PLUGIN_E_FAILED_VERSION; + } + + if (ouMaxVer.getLength() > 0) + { + int nRes = 0; + try + { + nRes = aVendorInfo->compareVersions(ouMaxVer); + } + catch (MalformedVersionException&) + { + //The maxVersion was not recognized as valid for this vendor. + JFW_ENSURE( + 0,OUSTR("[Java framework]sunjavaplugin does not know version: ") + + ouMaxVer + OUSTR(" for vendor: ") + aVendorInfo->getVendor() + + OUSTR(" .Check maximum Version.") ); + return JFW_PLUGIN_E_WRONG_VERSION_FORMAT; + } + if (nRes > 0) + return JFW_PLUGIN_E_FAILED_VERSION; + } + + if (arExcludeList > 0) + { + for (int i = 0; i < nLenList; i++) + { + rtl::OUString sExVer(arExcludeList[i]); + int nRes = 0; + try + { + nRes = aVendorInfo->compareVersions(sExVer); + } + catch (MalformedVersionException&) + { + //The excluded version was not recognized as valid for this vendor. + JFW_ENSURE( + 0,OUSTR("[Java framework]sunjavaplugin does not know version: ") + + sExVer + OUSTR(" for vendor: ") + aVendorInfo->getVendor() + + OUSTR(" .Check excluded versions.") ); + return JFW_PLUGIN_E_WRONG_VERSION_FORMAT; + } + if (nRes == 0) + return JFW_PLUGIN_E_FAILED_VERSION; + } + } + *ppInfo = createJavaInfo(aVendorInfo); + + return errcode; +} + +/** starts a Java Virtual Machine. + <p> + The function shall ensure, that the VM does not abort the process + during instantiation. + </p> + */ +extern "C" +javaPluginError jfw_plugin_startJavaVirtualMachine( + const JavaInfo *pInfo, + const JavaVMOption* arOptions, + sal_Int32 cOptions, + JavaVM ** ppVm, + JNIEnv ** ppEnv) +{ + // unless guard is volatile the following warning occurs on gcc: + // warning: variable 't' might be clobbered by `longjmp' or `vfork' + volatile osl::MutexGuard guard(PluginMutex::get()); + // unless errcode is volatile the following warning occurs on gcc: + // warning: variable 'errcode' might be clobbered by `longjmp' or `vfork' + volatile javaPluginError errcode = JFW_PLUGIN_E_NONE; + if ( pInfo == NULL || ppVm == NULL || ppEnv == NULL) + return JFW_PLUGIN_E_INVALID_ARG; + //Check if the Vendor (pInfo->sVendor) is supported by this plugin + if ( ! isVendorSupported(pInfo->sVendor)) + return JFW_PLUGIN_E_WRONG_VENDOR; + rtl::OUString sRuntimeLib = getRuntimeLib(pInfo->arVendorData); + JFW_TRACE2(OUSTR("[Java framework] Using Java runtime library: ") + + sRuntimeLib + OUSTR(".\n")); + // On linux we load jvm with RTLD_GLOBAL. This is necessary for debugging, because + // libjdwp.so need a symbol (fork1) from libjvm which it only gets if the jvm is loaded + // witd RTLD_GLOBAL. On Solaris libjdwp.so is correctly linked with libjvm.so + oslModule moduleRt = 0; +#if defined(LINUX) + if ((moduleRt = osl_loadModule(sRuntimeLib.pData, + SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_NOW)) == 0 ) +#else + if ((moduleRt = osl_loadModule(sRuntimeLib.pData, SAL_LOADMODULE_DEFAULT)) == 0) +#endif + { + JFW_ENSURE(0, OUSTR("[Java framework]sunjavaplugin" SAL_DLLEXTENSION + " could not load Java runtime library: \n") + + sRuntimeLib + OUSTR("\n")); + JFW_TRACE0(OUSTR("[Java framework]sunjavaplugin" SAL_DLLEXTENSION + " could not load Java runtime library: \n") + + sRuntimeLib + OUSTR("\n")); + return JFW_PLUGIN_E_VM_CREATION_FAILED; + } + +#ifdef UNX + //Setting the JAVA_HOME is needed for awt + rtl::OUString javaHome(RTL_CONSTASCII_USTRINGPARAM("JAVA_HOME=")); + rtl::OUString sPathLocation; + osl_getSystemPathFromFileURL(pInfo->sLocation, & sPathLocation.pData); + javaHome += sPathLocation; + rtl::OString osJavaHome = rtl::OUStringToOString( + javaHome, osl_getThreadTextEncoding()); + putenv(strdup(osJavaHome.getStr())); +#endif + + typedef jint JNICALL JNI_InitArgs_Type(void *); + typedef jint JNICALL JNI_CreateVM_Type(JavaVM **, JNIEnv **, void *); + rtl::OUString sSymbolCreateJava( + RTL_CONSTASCII_USTRINGPARAM("JNI_CreateJavaVM")); + + JNI_CreateVM_Type * pCreateJavaVM = (JNI_CreateVM_Type *) osl_getFunctionSymbol( + moduleRt, sSymbolCreateJava.pData); + if (!pCreateJavaVM) + { + OSL_ASSERT(0); + rtl::OString sLib = rtl::OUStringToOString( + sRuntimeLib, osl_getThreadTextEncoding()); + rtl::OString sSymbol = rtl::OUStringToOString( + sSymbolCreateJava, osl_getThreadTextEncoding()); + fprintf(stderr,"[Java framework]sunjavaplugin"SAL_DLLEXTENSION + "Java runtime library: %s does not export symbol %s !\n", + sLib.getStr(), sSymbol.getStr()); + return JFW_PLUGIN_E_VM_CREATION_FAILED; + } + + // Some testing with Java 1.4 showed that JavaVMOption.optionString has to + // be encoded with the system encoding (i.e., osl_getThreadTextEncoding): + JavaVMInitArgs vm_args; + + boost::scoped_array<JavaVMOption> sarOptions( + new JavaVMOption[cOptions + 1]); + JavaVMOption * options = sarOptions.get(); + + // We set an abort handler which is called when the VM calls _exit during + // JNI_CreateJavaVM. This happens when the LD_LIBRARY_PATH does not contain + // all some directories of the Java installation. This is necessary for + // all versions below 1.5.1 + options[0].optionString= (char *) "abort"; + options[0].extraInfo= (void* )(sal_IntPtr)abort_handler; + rtl::OString sClassPathProp("-Djava.class.path="); + rtl::OString sClassPathOption; + for (int i = 0; i < cOptions; i++) + { +#ifdef UNX + // Until java 1.5 we need to put a plugin.jar or javaplugin.jar (<1.4.2) + // in the class path in order to have applet support. + rtl::OString sClassPath = arOptions[i].optionString; + if (sClassPath.match(sClassPathProp, 0) == sal_True) + { + char sep[] = {SAL_PATHSEPARATOR, 0}; + OString sAddPath = getPluginJarPath(pInfo->sVendor, pInfo->sLocation,pInfo->sVersion); + if (sAddPath.getLength()) + sClassPathOption = sClassPath + rtl::OString(sep) + sAddPath; + else + sClassPathOption = sClassPath; + options[i+1].optionString = (char *) sClassPathOption.getStr(); + options[i+1].extraInfo = arOptions[i].extraInfo; + } + else + { +#endif + options[i+1].optionString = arOptions[i].optionString; + options[i+1].extraInfo = arOptions[i].extraInfo; +#ifdef UNX + } +#endif +#if OSL_DEBUG_LEVEL >= 2 + JFW_TRACE2(OString("VM option: ") + OString(options[i+1].optionString) + + OString("\n")); +#endif + } + +#ifdef MACOSX + vm_args.version= JNI_VERSION_1_4; // issue 88987 +#else + vm_args.version= JNI_VERSION_1_2; +#endif + vm_args.options= options; + vm_args.nOptions= cOptions + 1; + vm_args.ignoreUnrecognized= JNI_TRUE; + + /* We set a global flag which is used by the abort handler in order to + determine whether it is should use longjmp to get back into this function. + That is, the abort handler determines if it is on the same stack as this function + and then jumps back into this function. + */ + g_bInGetJavaVM = 1; + jint err; + JavaVM * pJavaVM = 0; + memset( jmp_jvm_abort, 0, sizeof(jmp_jvm_abort)); + int jmpval= setjmp( jmp_jvm_abort ); + /* If jmpval is not "0" then this point was reached by a longjmp in the + abort_handler, which was called indirectly by JNI_CreateVM. + */ + if( jmpval == 0) + { + //returns negative number on failure + err= pCreateJavaVM(&pJavaVM, ppEnv, &vm_args); + g_bInGetJavaVM = 0; + } + else + // set err to a positive number, so as or recognize that an abort (longjmp) + //occurred + err= 1; + + if(err != 0) + { + rtl::OUString message; + if( err < 0) + { + fprintf(stderr,"[Java framework] sunjavaplugin"SAL_DLLEXTENSION + "Can not create Java Virtual Machine\n"); + errcode = JFW_PLUGIN_E_VM_CREATION_FAILED; + } + else if( err > 0) + { + fprintf(stderr,"[Java framework] sunjavaplugin"SAL_DLLEXTENSION + "Can not create JavaVirtualMachine, abort handler was called.\n"); + errcode = JFW_PLUGIN_E_VM_CREATION_FAILED; + } + } + else + { + *ppVm = pJavaVM; + JFW_TRACE2("[Java framework] sunjavaplugin"SAL_DLLEXTENSION " has created a VM.\n"); + } + + + return errcode; +} + +extern "C" +javaPluginError jfw_plugin_existJRE(const JavaInfo *pInfo, sal_Bool *exist) +{ + javaPluginError ret = JFW_PLUGIN_E_NONE; + if (!pInfo || !exist) + return JFW_PLUGIN_E_INVALID_ARG; + ::rtl::OUString sLocation(pInfo->sLocation); + + if (sLocation.getLength() == 0) + return JFW_PLUGIN_E_INVALID_ARG; + ::osl::DirectoryItem item; + ::osl::File::RC rc_item = ::osl::DirectoryItem::get(sLocation, item); + if (::osl::File::E_None == rc_item) + { + *exist = sal_True; + } + else if (::osl::File::E_NOENT == rc_item) + { + *exist = sal_False; + } + else + { + ret = JFW_PLUGIN_E_ERROR; + } +#ifdef MACOSX + //We can have the situation that the JavaVM runtime library is not + //contained within JAVA_HOME. Then the check for JAVA_HOME would return + //true although the runtime library may not be loadable. + if (ret == JFW_PLUGIN_E_NONE && *exist == sal_True) + { + rtl::OUString sRuntimeLib = getRuntimeLib(pInfo->arVendorData); + JFW_TRACE2(OUSTR("[Java framework] Checking existence of Java runtime library.\n")); + + ::osl::DirectoryItem itemRt; + ::osl::File::RC rc_itemRt = ::osl::DirectoryItem::get(sRuntimeLib, itemRt); + if (::osl::File::E_None == rc_itemRt) + { + *exist = sal_True; + JFW_TRACE2(OUSTR("[Java framework] Java runtime library exist: ") + + sRuntimeLib + OUSTR("\n")); + + } + else if (::osl::File::E_NOENT == rc_itemRt) + { + *exist = sal_False; + JFW_TRACE2(OUSTR("[Java framework] Java runtime library does not exist: ") + + sRuntimeLib + OUSTR("\n")); + } + else + { + ret = JFW_PLUGIN_E_ERROR; + JFW_TRACE2(OUSTR("[Java framework] Error while looking for Java runtime library: ") + + sRuntimeLib + OUSTR(" \n")); + } + } +#endif + return ret; +} + + diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.map b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.map new file mode 100644 index 000000000000..901867f0a43d --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.map @@ -0,0 +1,13 @@ +UDK_3_0_0 { + global: + jfw_plugin_getAllJavaInfos; + jfw_plugin_getJavaInfoByPath; + jfw_plugin_startJavaVirtualMachine; + local: + *; +}; + +UDK_3.1 { # OOo 3.3 + global: + jfw_plugin_existJRE; +} UDK_3_0_0; diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavapluginrc b/jvmfwk/plugins/sunmajor/pluginlib/sunjavapluginrc new file mode 100755 index 000000000000..0f2fb31eef90 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavapluginrc @@ -0,0 +1,2 @@ +[Bootstrap] +JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY=1
\ No newline at end of file diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx new file mode 100644 index 000000000000..4fd74df90723 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx @@ -0,0 +1,124 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_jvmfwk.hxx" + +#include "osl/thread.h" +#include "sunjre.hxx" +#include "sunversion.hxx" +#include "diagnostics.h" + +using namespace rtl; +using namespace std; + +#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) +namespace jfw_plugin +{ + +Reference<VendorBase> SunInfo::createInstance() +{ + return new SunInfo; +} + +char const* const* SunInfo::getJavaExePaths(int * size) +{ + static char const * ar[] = { +#if defined(WNT) || defined(OS2) + "java.exe", + "bin/java.exe", + "jre/bin/java.exe" +#elif UNX + "java", + "bin/java", + "jre/bin/java" +#endif + }; + *size = sizeof (ar) / sizeof (char*); + return ar; +} + +char const* const* SunInfo::getRuntimePaths(int * size) +{ + static char const* ar[]= { +#if defined(WNT) + "/bin/client/jvm.dll", + "/bin/hotspot/jvm.dll", + "/bin/classic/jvm.dll" +#elif defined(OS2) + "/bin/classic/jvm.dll", +#elif UNX + "/lib/" JFW_PLUGIN_ARCH "/client/libjvm.so", + "/lib/" JFW_PLUGIN_ARCH "/server/libjvm.so", + "/lib/" JFW_PLUGIN_ARCH "/classic/libjvm.so" +#endif + + }; + *size = sizeof(ar) / sizeof (char*); + return ar; +} + +char const* const* SunInfo::getLibraryPaths(int* size) +{ +#ifdef UNX + static char const * ar[] = { + + "/lib/" JFW_PLUGIN_ARCH "/client", + "/lib/" JFW_PLUGIN_ARCH "/native_threads", + "/lib/" JFW_PLUGIN_ARCH + + }; + *size = sizeof(ar) / sizeof (char*); + return ar; +#else + size = 0; + return NULL; +#endif +} + +int SunInfo::compareVersions(const rtl::OUString& sSecond) const +{ + OUString sFirst = getVersion(); + + SunVersion version1(sFirst); + JFW_ENSURE(version1, OUSTR("[Java framework] sunjavaplugin"SAL_DLLEXTENSION + " does not know the version: ") + + sFirst + OUSTR(" as valid for a SUN JRE.")); + SunVersion version2(sSecond); + if ( ! version2) + throw MalformedVersionException(); + + if(version1 == version2) + return 0; + if(version1 > version2) + return 1; + else + return -1; +} + + +} diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjre.hxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjre.hxx new file mode 100644 index 000000000000..54c1d5b8829a --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjre.hxx @@ -0,0 +1,52 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#if !defined INCLUDED_JFW_PLUGIN_SUNJRE_HXX +#define INCLUDED_JFW_PLUGIN_SUNJRE_HXX + +#include "vendorbase.hxx" +#include "vendorlist.hxx" + +namespace jfw_plugin +{ + +class SunInfo: public VendorBase +{ +public: + static char const* const* getJavaExePaths(int * size); + + static rtl::Reference<VendorBase> createInstance(); + + using VendorBase::getLibraryPaths; + virtual char const* const* getRuntimePaths(int * size); + virtual char const* const* getLibraryPaths(int* size); + + virtual int compareVersions(const rtl::OUString& sSecond) const; +}; + +} +#endif diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunversion.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunversion.cxx new file mode 100644 index 000000000000..5d52046c705e --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/sunversion.cxx @@ -0,0 +1,427 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_jvmfwk.hxx" + +#include "sunversion.hxx" +#include "osl/thread.h" +#include "osl/process.h" +#include "osl/security.hxx" +#include <string.h> +#include <ctype.h> +#include "diagnostics.h" +using namespace rtl; +using namespace osl; +namespace jfw_plugin { //stoc_javadetect + + +//extern OUString ::Impl::usPathDelim(); +#define OUSTR( x ) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( x )) + +#if OSL_DEBUG_LEVEL >= 2 +class SelfTest +{ +public: + SelfTest(); +} test; +#endif + +SunVersion::SunVersion(const rtl::OUString &usVer): + m_nUpdateSpecial(0), m_preRelease(Rel_NONE), + usVersion(usVer) +{ + memset(m_arVersionParts, 0, sizeof(m_arVersionParts)); + rtl::OString sVersion= rtl::OUStringToOString(usVer, osl_getThreadTextEncoding()); + m_bValid = init(sVersion.getStr()); +} +SunVersion::SunVersion(const char * szVer): + m_nUpdateSpecial(0), m_preRelease(Rel_NONE) +{ + memset(m_arVersionParts, 0, sizeof(m_arVersionParts)); + m_bValid = init(szVer); + usVersion= rtl::OUString(szVer,strlen(szVer),osl_getThreadTextEncoding()); +} + + +/**Format major.minor.maintainance_update + */ +bool SunVersion::init(const char *szVersion) +{ + if ( ! szVersion || strlen(szVersion) == 0) + return false; + + //first get the major,minor,maintainance + const char * pLast = szVersion; + const char * pCur = szVersion; + //pEnd point to the position after the last character + const char * pEnd = szVersion + strlen(szVersion); + // 0 = major, 1 = minor, 2 = maintainance, 3 = update + int nPart = 0; + // position within part beginning with 0 + int nPartPos = 0; + char buf[128]; + + //char must me a number 0 - 999 and no leading + while (1) + { + if (pCur < pEnd && isdigit(*pCur)) + { + if (pCur < pEnd) + pCur ++; + nPartPos ++; + } + //if correct separator then form integer + else if ( + ! (nPartPos == 0) // prevents: ".4.1", "..1", part must start with digit + && ( + //seperators after maintainance (1.4.1_01, 1.4.1-beta, or1.4.1 + ((pCur == pEnd || *pCur == '_' || *pCur == '-') && (nPart == 2 )) + || + //separators between major-minor and minor-maintainance + (nPart < 2 && *pCur == '.') ) + && ( + //prevent 1.4.0. 1.4.0- + pCur + 1 == pEnd ? isdigit(*(pCur)) : 1) ) + { + int len = pCur - pLast; + if (len >= 127) + return false; + + strncpy(buf, pLast, len); + buf[len] = 0; + pCur ++; + pLast = pCur; + + m_arVersionParts[nPart] = atoi(buf); + nPart ++; + nPartPos = 0; + if (nPart == 3) + break; + + //check next character + if (! ( (pCur < pEnd) + && ( (nPart < 3) && isdigit(*pCur)))) //(*pCur >= 48 && *pCur <=57)))) + return false; + } + else + { + return false; + } + } + if (pCur >= pEnd) + return true; + //We have now 1.4.1. This can be followed by _01, -beta, etc. + // _01 (update) According to docu must not be followed by any other + //characters, but on Solaris 9 we have a 1.4.1_01a!! + if (* (pCur - 1) == '_') + {// _01, _02 + // update is the last part _01, _01a, part 0 is the digits parts and 1 the trailing alpha + while (1) + { + if (pCur <= pEnd) + { + if ( ! isdigit(*pCur)) + { + //1.4.1_01-, 1.4.1_01a, the numerical part may only be 2 chars. + int len = pCur - pLast; + if (len > 2) + return false; + //we've got the update: 01, 02 etc + strncpy(buf, pLast, len); + buf[len] = 0; + m_arVersionParts[nPart] = atoi(buf); + if (pCur == pEnd) + { + break; + } + if (*pCur == 'a' && (pCur + 1) == pEnd) + { + //check if it s followed by a simple "a" (not specified) + m_nUpdateSpecial = *pCur; + break; + } + else if (*pCur == '-' && pCur < pEnd) + { + //check 1.5.0_01-ea + PreRelease pr = getPreRelease(++pCur); + if (pr == Rel_NONE) + return false; + //just ignore -ea because its no official release + break; + } + else + { + return false; + } + } + if (pCur < pEnd) + pCur ++; + else + break; + } + } + } + // 1.4.1-ea + else if (*(pCur - 1) == '-') + { + m_preRelease = getPreRelease(pCur); + if (m_preRelease == Rel_NONE) + return false; +#if defined(FREEBSD) + if (m_preRelease == Rel_FreeBSD) + { + pCur++; //elemnate `p' + if (pCur < pEnd && isdigit(*pCur)) + pCur ++; + int len = pCur - pLast -1; //elemenate `p' + if (len >= 127) + return false; + strncpy(buf, (pLast+1), len); //elemenate `p' + buf[len] = 0; + m_nUpdateSpecial = atoi(buf)+100; //hack for FBSD #i56953# + return true; + } +#endif + } + else + { + return false; + } + return true; +} + +SunVersion::PreRelease SunVersion::getPreRelease(const char *szRelease) +{ + if (szRelease == NULL) + return Rel_NONE; + if( ! strcmp(szRelease,"ea")) + return Rel_EA; + else if( ! strcmp(szRelease,"ea1")) + return Rel_EA1; + else if( ! strcmp(szRelease,"ea2")) + return Rel_EA2; + else if( ! strcmp(szRelease,"ea3")) + return Rel_EA3; + else if ( ! strcmp(szRelease,"beta")) + return Rel_BETA; + else if ( ! strcmp(szRelease,"beta1")) + return Rel_BETA1; + else if ( ! strcmp(szRelease,"beta2")) + return Rel_BETA2; + else if ( ! strcmp(szRelease,"beta3")) + return Rel_BETA3; + else if (! strcmp(szRelease, "rc")) + return Rel_RC; + else if (! strcmp(szRelease, "rc1")) + return Rel_RC1; + else if (! strcmp(szRelease, "rc2")) + return Rel_RC2; + else if (! strcmp(szRelease, "rc3")) + return Rel_RC3; +#if defined (FREEBSD) + else if (! strncmp(szRelease, "p", 1)) + return Rel_FreeBSD; +#endif + else + return Rel_NONE; +} + +SunVersion::~SunVersion() +{ + +} + +/* Examples: + a) 1.0 < 1.1 + b) 1.0 < 1.0.0 + c) 1.0 < 1.0_00 + + returns false if both values are equal +*/ +bool SunVersion::operator > (const SunVersion& ver) const +{ + if( &ver == this) + return false; + + //compare major.minor.maintainance + for( int i= 0; i < 4; i ++) + { + // 1.4 > 1.3 + if(m_arVersionParts[i] > ver.m_arVersionParts[i]) + { + return true; + } + else if (m_arVersionParts[i] < ver.m_arVersionParts[i]) + { + return false; + } + } + //major.minor.maintainance_update are equal. test for a trailing char + if (m_nUpdateSpecial > ver.m_nUpdateSpecial) + { + return true; + } + + //Until here the versions are equal + //compare pre -release values + if ((m_preRelease == Rel_NONE && ver.m_preRelease == Rel_NONE) + || + (m_preRelease != Rel_NONE && ver.m_preRelease == Rel_NONE)) + return false; + else if (m_preRelease == Rel_NONE && ver.m_preRelease != Rel_NONE) + return true; + else if (m_preRelease > ver.m_preRelease) + return true; + + return false; +} + +bool SunVersion::operator < (const SunVersion& ver) const +{ + return (! operator > (ver)) && (! operator == (ver)); +} + +bool SunVersion::operator == (const SunVersion& ver) const +{ + bool bRet= true; + for(int i= 0; i < 4; i++) + { + if( m_arVersionParts[i] != ver.m_arVersionParts[i]) + { + bRet= false; + break; + } + } + bRet = m_nUpdateSpecial == ver.m_nUpdateSpecial && bRet; + bRet = m_preRelease == ver.m_preRelease && bRet; + return bRet; +} + +SunVersion::operator bool() +{ + return m_bValid; +} + +#if OSL_DEBUG_LEVEL >= 2 +SelfTest::SelfTest() +{ + bool bRet = true; + + char const * versions[] = {"1.4.0", "1.4.1", "1.0.0", "10.0.0", "10.10.0", + "10.2.2", "10.10.0", "10.10.10", "111.0.999", + "1.4.1_01", "9.90.99_09", "1.4.1_99", + "1.4.1_00a", + "1.4.1-ea", "1.4.1-beta", "1.4.1-rc1", + "1.5.0_01-ea", "1.5.0_01-rc2"}; + char const * badVersions[] = {".4.0", "..1", "", "10.0", "10.10.0.", "10.10.0-", "10.10.0.", + "10.2-2", "10_10.0", "10..10","10.10", "a.0.999", + "1.4b.1_01", "9.90.-99_09", "1.4.1_99-", + "1.4.1_00a2", "1.4.0_z01z", "1.4.1__99A", + "1.4.1-1ea", "1.5.0_010", "1.5.0._01-", "1.5.0_01-eac"}; + char const * orderedVer[] = { "1.3.1-ea", "1.3.1-beta", "1.3.1-rc1", + "1.3.1", "1.3.1_00a", "1.3.1_01", "1.3.1_01a", + "1.3.2", "1.4.0", "1.5.0_01-ea", "2.0.0"}; + + int num = sizeof (versions) / sizeof(char*); + int numBad = sizeof (badVersions) / sizeof(char*); + int numOrdered = sizeof (orderedVer) / sizeof(char*); + //parsing test (positive) + for (int i = 0; i < num; i++) + { + SunVersion ver(versions[i]); + if ( ! ver) + { + bRet = false; + break; + } + } + OSL_ENSURE(bRet, "SunVersion selftest failed"); + //Parsing test (negative) + for ( int i = 0; i < numBad; i++) + { + SunVersion ver(badVersions[i]); + if (ver) + { + bRet = false; + break; + } + } + OSL_ENSURE(bRet, "SunVersion selftest failed"); + + // Ordering test + bRet = true; + int j = 0; + for (int i = 0; i < numOrdered; i ++) + { + SunVersion curVer(orderedVer[i]); + if ( ! curVer) + { + bRet = false; + break; + } + for (j = 0; j < numOrdered; j++) + { + SunVersion compVer(orderedVer[j]); + if (i < j) + { + if ( !(curVer < compVer)) + { + bRet = false; + break; + } + } + else if ( i == j) + { + if (! (curVer == compVer + && ! (curVer > compVer) + && ! (curVer < compVer))) + { + bRet = false; + break; + } + } + else if (i > j) + { + if ( !(curVer > compVer)) + { + bRet = false; + break; + } + } + } + if ( ! bRet) + break; + } + if (bRet) + JFW_TRACE2("[Java framework] sunjavaplugin: Testing class SunVersion succeeded.\n"); + else + OSL_ENSURE(bRet, "[Java framework] sunjavaplugin: SunVersion self test failed.\n"); +} +#endif + +} diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunversion.hxx b/jvmfwk/plugins/sunmajor/pluginlib/sunversion.hxx new file mode 100644 index 000000000000..61d5da488a7e --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/sunversion.hxx @@ -0,0 +1,127 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#if !defined INCLUDED_JVMACCESS_SUNVERSION_HXX +#define INCLUDED_JVMACCESS_SUNVERSION_HXX + +#include "rtl/ustring.hxx" + +namespace jfw_plugin { +// Define OSL_DEBUG_LEVEL >= 2 to run a test when this lib is loaded + +/* SunVersion is used to compare java versions based on a string, as taken + from the registry. The strings look like "1.3", "1.3.1", "1.3.1_02" etc. + Versions such as "1.4.1_01a" are allowed although this is not specified. + 1.4.1_01 < 1.4.1_01a < 1.4.1_01b < 1.4.1_02 + Pre - release versions, such as 1.4.1-ea, 1.4.1-beta, 1.4.1-rc are recognized, + but are treated as minor to release versions: + 1.4.0 > 1.4.2-beta + Pre releases relate this way + 1.4.1-ea < 1.4.1-beta < 1.4.1-rc1 + + This class supports also a FreeBSD Java. This is currently necessary because + it also has the vendor string "Sun Microsystems Inc.". + + An object acts as holder for the version string. That string may be present + even if the version could not be parsed. Then the version may not be compatible + to a SUN Java version. + + An invalid object, that is, operator bool returns false, will always be + the lower version in a comparison. If two invalid objects are compared + then they are considered equal. + + To test if the version is ok, that is this object can be compared to others, + use the bool conversion operator. + */ +class SunVersion +{ +protected: + + enum PreRelease + { + Rel_NONE, + Rel_EA, + Rel_EA1, + Rel_EA2, + Rel_EA3, + Rel_BETA, + Rel_BETA1, + Rel_BETA2, + Rel_BETA3, + Rel_RC, + Rel_RC1, + Rel_RC2, + Rel_RC3 +#if defined(FREEBSD) + , + Rel_FreeBSD +#endif + }; + + //contains major,minor,micro,update + int m_arVersionParts[4]; + // The update can be followed by a char, e.g. 1.4.1_01a + char m_nUpdateSpecial; + + PreRelease m_preRelease; +public: + SunVersion(const char * szVer); + SunVersion(const rtl::OUString& usVer); + ~SunVersion(); + + /** + Pre-release versions are taken into account. + 1.5.0-beta > 1.5.0-ea > 1.4.2 + */ + bool operator > (const SunVersion& ver) const; + bool operator < (const SunVersion& ver) const; + bool operator == (const SunVersion& ver) const; + + /** Test if the version is compatible tu SUN's versioning scheme + */ + operator bool (); + + /** Will always contain a value if the object has been constructed with + a version string. + */ + rtl::OUString usVersion; + +protected: + bool init(const char * szVer); + + bool m_bValid; + + /* Determines if a string constitutes a pre release. For example, if + "ea" is passed then Rel_EA is returned. If the string is no pre release + then Rel_NONE is returned. + */ + PreRelease getPreRelease(const char *szRel); +}; + +} + +#endif // INCLUDED_JVMACCESS_SUNVERSION_HXX diff --git a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx new file mode 100644 index 000000000000..fc2a5b98215a --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx @@ -0,0 +1,1267 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_jvmfwk.hxx" + +#include "util.hxx" + +#include "osl/process.h" +#include "osl/security.hxx" +#include "osl/thread.hxx" +#include "osl/file.hxx" +#include "osl/module.hxx" +#include "rtl/byteseq.hxx" +#include "rtl/ustrbuf.hxx" +#include "rtl/instance.hxx" +#include "boost/scoped_array.hpp" +#include "com/sun/star/uno/Sequence.hxx" +#include <utility> +#include <algorithm> +#include <map> + +#if defined WNT +#if defined _MSC_VER +#pragma warning(push, 1) +#endif +#include <windows.h> +#if defined _MSC_VER +#pragma warning(pop) +#endif +#endif +#include <string.h> + +#include "sunjre.hxx" +#include "vendorlist.hxx" +#include "diagnostics.h" +using namespace rtl; +using namespace osl; +using namespace std; + +#define CHAR_POINTER(oustr) ::rtl::OUStringToOString(oustr,RTL_TEXTENCODING_UTF8).pData->buffer +#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) +#ifdef WNT +#define HKEY_SUN_JRE L"Software\\JavaSoft\\Java Runtime Environment" +#define HKEY_SUN_SDK L"Software\\JavaSoft\\Java Development Kit" +#endif + +#ifdef UNX +namespace { +char const *g_arJavaNames[] = { + "", + "j2re", + "j2se", + "j2sdk", + "jdk", + "jre", + "java", + "Home", + "IBMJava2-ppc-142" +}; +/* These are directory names which could contain multiple java installations. + */ +char const *g_arCollectDirs[] = { + "", + "j2re/", + "j2se/", + "j2sdk/", + "jdk/", + "jre/", + "java/", + "jvm/" +}; + +/* These are directories in which a java installation is + looked for. +*/ +char const *g_arSearchPaths[] = { +#ifdef MACOSX + "", + "System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/" +#else + "", + "usr/", + "usr/local/", + "usr/local/IBMJava2-ppc-142", + "usr/local/j2sdk1.3.1", +#ifdef X86_64 + "usr/lib64/", +#endif + "usr/lib/", + "usr/bin/" +#endif +}; +} +#endif // UNX + +namespace jfw_plugin +{ +extern VendorSupportMapEntry gVendorMap[]; + +bool getSDKInfoFromRegistry(vector<OUString> & vecHome); +bool getJREInfoFromRegistry(vector<OUString>& vecJavaHome); +bool decodeOutput(const rtl::OString& s, rtl::OUString* out); + + + +namespace +{ + rtl::OUString getLibraryLocation() + { + rtl::OUString libraryFileUrl; + OSL_VERIFY(osl::Module::getUrlFromAddress((void *)(sal_IntPtr)getLibraryLocation, libraryFileUrl)); + return getDirFromFile(libraryFileUrl); + } + + struct InitBootstrap + { + rtl::Bootstrap * operator()(const OUString& sIni) + { + static rtl::Bootstrap aInstance(sIni); + return & aInstance; + + } + }; + + struct InitBootstrapData + { + OUString const & operator()() + { + // osl::Guard<osl::Mutex> g(osl::GetGlobalMutex()); + static OUString sIni; + rtl::OUStringBuffer buf( 255); + buf.append( getLibraryLocation()); + buf.appendAscii( SAL_CONFIGFILE("/sunjavaplugin") ); + sIni = buf.makeStringAndClear(); + JFW_TRACE2(OUSTR("[Java framework] sunjavaplugin: " + "Using configuration file \n") + sIni); + return sIni; + } + }; +} + +rtl::Bootstrap * getBootstrap() +{ + return rtl_Instance< rtl::Bootstrap, InitBootstrap, + ::osl::MutexGuard, ::osl::GetGlobalMutex, + OUString, InitBootstrapData >::create( + InitBootstrap(), ::osl::GetGlobalMutex(), InitBootstrapData()); +} + + + + +class FileHandleGuard +{ +public: + inline FileHandleGuard(oslFileHandle & rHandle) SAL_THROW(()): + m_rHandle(rHandle) {} + + inline ~FileHandleGuard() SAL_THROW(()); + + inline oslFileHandle & getHandle() SAL_THROW(()) { return m_rHandle; } + +private: + oslFileHandle & m_rHandle; + + FileHandleGuard(FileHandleGuard &); // not implemented + void operator =(FileHandleGuard); // not implemented +}; + +inline FileHandleGuard::~FileHandleGuard() SAL_THROW(()) +{ + if (m_rHandle != 0) + { + if (osl_closeFile(m_rHandle) != osl_File_E_None) + { + OSL_ENSURE(false, "unexpected situation"); + } + } +} + + +class FileHandleReader +{ +public: + enum Result + { + RESULT_OK, + RESULT_EOF, + RESULT_ERROR + }; + + inline FileHandleReader(oslFileHandle & rHandle) SAL_THROW(()): + m_aGuard(rHandle), m_nSize(0), m_nIndex(0), m_bLf(false) {} + + Result readLine(rtl::OString * pLine) SAL_THROW(()); + +private: + enum { BUFFER_SIZE = 1024 }; + + sal_Char m_aBuffer[BUFFER_SIZE]; + FileHandleGuard m_aGuard; + int m_nSize; + int m_nIndex; + bool m_bLf; +}; + +FileHandleReader::Result +FileHandleReader::readLine(rtl::OString * pLine) + SAL_THROW(()) +{ + OSL_ENSURE(pLine, "specification violation"); + + for (bool bEof = true;; bEof = false) + { + if (m_nIndex == m_nSize) + { + sal_uInt64 nRead = 0; + switch (osl_readFile( + m_aGuard.getHandle(), m_aBuffer, sizeof(m_aBuffer), &nRead)) + { + case osl_File_E_PIPE: //HACK! for windows + nRead = 0; + case osl_File_E_None: + if (nRead == 0) + { + m_bLf = false; + return bEof ? RESULT_EOF : RESULT_OK; + } + m_nIndex = 0; + m_nSize = static_cast< int >(nRead); + break; + case osl_File_E_INTR: + continue; + + default: + return RESULT_ERROR; + } + } + + if (m_bLf && m_aBuffer[m_nIndex] == 0x0A) + ++m_nIndex; + m_bLf = false; + + int nStart = m_nIndex; + while (m_nIndex != m_nSize) + switch (m_aBuffer[m_nIndex++]) + { + case 0x0D: + m_bLf = true; + case 0x0A: + *pLine += rtl::OString(m_aBuffer + nStart, + m_nIndex - 1 - nStart); + //TODO! check for overflow, and not very efficient + return RESULT_OK; + } + + *pLine += rtl::OString(m_aBuffer + nStart, m_nIndex - nStart); + //TODO! check for overflow, and not very efficient + } +} + +class AsynchReader: public Thread +{ + size_t m_nDataSize; + boost::scoped_array<sal_Char> m_arData; + + bool m_bError; + bool m_bDone; + FileHandleGuard m_aGuard; + + void SAL_CALL run(); +public: + + AsynchReader(oslFileHandle & rHandle); +#if OSL_DEBUG_LEVEL >= 2 + /** only call this function after this thread has finished. + + That is, call join on this instance and then call getData. + + */ + OString getData(); +#endif +}; + +AsynchReader::AsynchReader(oslFileHandle & rHandle): + m_nDataSize(0), m_bError(false), m_bDone(false), m_aGuard(rHandle) +{ +} + +#if OSL_DEBUG_LEVEL >= 2 +OString AsynchReader::getData() +{ + OSL_ASSERT(isRunning() == sal_False ); + return OString(m_arData.get(), m_nDataSize); +} +#endif + +void AsynchReader::run() +{ + const sal_uInt64 BUFFER_SIZE = 4096; + sal_Char aBuffer[BUFFER_SIZE]; + while (true) + { + sal_uInt64 nRead; + //the function blocks until something could be read or the pipe closed. + switch (osl_readFile( + m_aGuard.getHandle(), aBuffer, BUFFER_SIZE, &nRead)) + { + case osl_File_E_PIPE: //HACK! for windows + nRead = 0; + case osl_File_E_None: + break; + default: + m_bError = true; + return; + } + + if (nRead == 0) + { + m_bDone = true; + break; + } + else if (nRead <= BUFFER_SIZE) + { + //Save the data we have in m_arData into a temporary array + boost::scoped_array<sal_Char> arTmp( new sal_Char[m_nDataSize]); + memcpy(arTmp.get(), m_arData.get(), m_nDataSize); + //Enlarge m_arData to hold the newly read data + m_arData.reset(new sal_Char[(size_t)(m_nDataSize + nRead)]); + //Copy back the data that was already in m_arData + memcpy(m_arData.get(), arTmp.get(), m_nDataSize); + //Add the newly read data to m_arData + memcpy(m_arData.get() + m_nDataSize, aBuffer, (size_t) nRead); + m_nDataSize += (size_t) nRead; + } + } +} + + +bool getJavaProps(const OUString & exePath, + std::vector<std::pair<rtl::OUString, rtl::OUString> >& props, + bool * bProcessRun) +{ + bool ret = false; + + OSL_ASSERT( exePath.getLength() > 0); + OUString usStartDir; + //We need to set the CLASSPATH in case the office is started from + //a different directory. The JREProperties.class is expected to reside + //next to the plugin. + rtl::OUString sThisLib; + if (osl_getModuleURLFromAddress((void *) (sal_IntPtr)& getJavaProps, + & sThisLib.pData) == sal_False) + return false; + sThisLib = getDirFromFile(sThisLib); + OUString sClassPath; + if (osl_getSystemPathFromFileURL(sThisLib.pData, & sClassPath.pData) + != osl_File_E_None) + return false; + + //check if we shall examine a Java for accessibility support + //If the bootstrap variable is "1" then we pass the argument + //"noaccessibility" to JREProperties.class. This will prevent + //that it calls java.awt.Toolkit.getDefaultToolkit(); + OUString sValue; + getBootstrap()->getFrom(OUSTR("JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY"), sValue); + + //prepare the arguments + sal_Int32 cArgs = 3; + OUString arg1 = OUString(RTL_CONSTASCII_USTRINGPARAM("-classpath"));// + sClassPath; + OUString arg2 = sClassPath; + OUString arg3(RTL_CONSTASCII_USTRINGPARAM("JREProperties")); + OUString arg4 = OUSTR("noaccessibility"); + rtl_uString *args[4] = {arg1.pData, arg2.pData, arg3.pData}; + + // Only add the fourth param if the bootstrap parameter is set. + if (sValue.equals(OUString::valueOf((sal_Int32) 1))) + { + args[3] = arg4.pData; + cArgs = 4; + } + + oslProcess javaProcess= 0; + oslFileHandle fileOut= 0; + oslFileHandle fileErr= 0; + + FileHandleReader stdoutReader(fileOut); + AsynchReader stderrReader(fileErr); + + JFW_TRACE2(OUSTR("\n[Java framework] Executing: ") + exePath + OUSTR(".\n")); + oslProcessError procErr = + osl_executeProcess_WithRedirectedIO( exePath.pData,//usExe.pData, + args, + cArgs, //sal_uInt32 nArguments, + osl_Process_HIDDEN, //oslProcessOption Options, + NULL, //oslSecurity Security, + usStartDir.pData,//usStartDir.pData,//usWorkDir.pData, //rtl_uString *strWorkDir, + NULL, //rtl_uString *strEnvironment[], + 0, // sal_uInt32 nEnvironmentVars, + &javaProcess, //oslProcess *pProcess, + NULL,//oslFileHandle *pChildInputWrite, + &fileOut,//oslFileHandle *pChildOutputRead, + &fileErr);//oslFileHandle *pChildErrorRead); + + if( procErr != osl_Process_E_None) + { + JFW_TRACE2("[Java framework] Execution failed. \n"); + *bProcessRun = false; + return ret; + } + else + { + JFW_TRACE2("[Java framework] Java executed successfully.\n"); + *bProcessRun = true; + } + + //Start asynchronous reading (different thread) of error stream + stderrReader.create(); + + //Use this thread to read output stream + FileHandleReader::Result rs = FileHandleReader::RESULT_OK; + while (1) + { + OString aLine; + rs = stdoutReader.readLine( & aLine); + if (rs != FileHandleReader::RESULT_OK) + break; +// JFW_TRACE2(OString("[Java framework] line:\" ") +// + aLine + OString(" \".\n")); + OUString sLine; + if (!decodeOutput(aLine, &sLine)) + continue; + JFW_TRACE2(OString("[Java framework]:\" ") + + OString( CHAR_POINTER(sLine)) + OString(" \".\n")); + sLine = sLine.trim(); + if (sLine.getLength() == 0) + continue; + //The JREProperties class writes key value pairs, separated by '=' + sal_Int32 index = sLine.indexOf('=', 0); + OSL_ASSERT(index != -1); + OUString sKey = sLine.copy(0, index); + OUString sVal = sLine.copy(index + 1); + + props.push_back(std::make_pair(sKey, sVal)); + } + + if (rs != FileHandleReader::RESULT_ERROR && props.size()>0) + ret = true; + + //process error stream data + stderrReader.join(); + JFW_TRACE2(OString("[Java framework] Java wrote to stderr:\" ") + + stderrReader.getData() + OString(" \".\n")); + + TimeValue waitMax= {5 ,0}; + procErr = osl_joinProcessWithTimeout(javaProcess, &waitMax); + OSL_ASSERT(procErr == osl_Process_E_None); + osl_freeProcessHandle(javaProcess); + return ret; +} + +/* converts the properties printed by JREProperties.class into + readable strings. The strings are encoded as integer values separated + by spaces. + */ +bool decodeOutput(const rtl::OString& s, rtl::OUString* out) +{ + OSL_ASSERT(out != 0); + OUStringBuffer buff(512); + sal_Int32 nIndex = 0; + do + { + OString aToken = s.getToken( 0, ' ', nIndex ); + if (aToken.getLength()) + { + for (sal_Int32 i = 0; i < aToken.getLength(); ++i) + { + if (aToken[i] < '0' || aToken[i] > '9') + return false; + } + sal_Unicode value = (sal_Unicode)(aToken.toInt32()); + buff.append(value); + } + } while (nIndex >= 0); + + *out = buff.makeStringAndClear(); +// JFW_TRACE2(*out); + return true; +} + + +#if defined WNT +void createJavaInfoFromWinReg(std::vector<rtl::Reference<VendorBase> > & vecInfos) +{ + // Get Java s from registry + std::vector<OUString> vecJavaHome; + if(getSDKInfoFromRegistry(vecJavaHome)) + { + // create impl objects + typedef std::vector<OUString>::iterator ItHome; + for(ItHome it_home= vecJavaHome.begin(); it_home != vecJavaHome.end(); + it_home++) + { + getJREInfoByPath(*it_home, vecInfos); + } + } + + vecJavaHome.clear(); + if(getJREInfoFromRegistry(vecJavaHome)) + { + typedef std::vector<OUString>::iterator ItHome; + for(ItHome it_home= vecJavaHome.begin(); it_home != vecJavaHome.end(); + it_home++) + { + getJREInfoByPath(*it_home, vecInfos); + } + } +} + + +bool getJavaInfoFromRegistry(const wchar_t* szRegKey, + vector<OUString>& vecJavaHome) +{ + HKEY hRoot; + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_ENUMERATE_SUB_KEYS, &hRoot) + == ERROR_SUCCESS) + { + DWORD dwIndex = 0; + const DWORD BUFFSIZE = 1024; + wchar_t bufVersion[BUFFSIZE]; +// char bufVersion[BUFFSIZE]; + DWORD nNameLen = BUFFSIZE; + FILETIME fileTime; + nNameLen = sizeof(bufVersion); + + // Iterate over all subkeys of HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment + while (RegEnumKeyExW(hRoot, dwIndex, bufVersion, &nNameLen, NULL, NULL, NULL, &fileTime) != ERROR_NO_MORE_ITEMS) + { + HKEY hKey; + // Open a Java Runtime Environment sub key, e.g. "1.4.0" + if (RegOpenKeyExW(hRoot, bufVersion, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) + { + DWORD dwType; + DWORD dwTmpPathLen= 0; + // Get the path to the JavaHome every JRE entry + // Find out how long the string for JavaHome is and allocate memory to hold the path + if( RegQueryValueExW(hKey, L"JavaHome", 0, &dwType, NULL, &dwTmpPathLen)== ERROR_SUCCESS) + { + char* szTmpPath= (char *) malloc( dwTmpPathLen); + // Get the path for the runtime lib + if(RegQueryValueExW(hKey, L"JavaHome", 0, &dwType, (unsigned char*) szTmpPath, &dwTmpPathLen) == ERROR_SUCCESS) + { + // There can be several version entries refering with the same JavaHome,e.g 1.4 and 1.4.1 + OUString usHome((sal_Unicode*) szTmpPath); + // check if there is already an entry with the same JavaHomeruntime lib + // if so, we use the one with the more accurate version + bool bAppend= true; + OUString usHomeUrl; + if (osl_getFileURLFromSystemPath(usHome.pData, & usHomeUrl.pData) == + osl_File_E_None) + { + //iterate over the vector with java home strings + typedef vector<OUString>::iterator ItHome; + for(ItHome itHome= vecJavaHome.begin(); + itHome != vecJavaHome.end(); itHome++) + { + if(usHomeUrl.equals(*itHome)) + { + bAppend= false; + break; + } + } + // Save the home dir + if(bAppend) + { + vecJavaHome.push_back(usHomeUrl); + } + } + } + free( szTmpPath); + RegCloseKey(hKey); + } + } + dwIndex ++; + nNameLen = BUFFSIZE; + } + RegCloseKey(hRoot); + } + return true; +} + + + +bool getSDKInfoFromRegistry(vector<OUString> & vecHome) +{ + return getJavaInfoFromRegistry(HKEY_SUN_SDK, vecHome); +} + +bool getJREInfoFromRegistry(vector<OUString>& vecJavaHome) +{ + return getJavaInfoFromRegistry(HKEY_SUN_JRE, vecJavaHome); +} + +#endif // WNT + +void bubbleSortVersion(vector<rtl::Reference<VendorBase> >& vec) +{ + if(vec.size() == 0) + return; + int size= vec.size() - 1; + int cIter= 0; + // sort for version + for(int i= 0; i < size; i++) + { + for(int j= size; j > 0 + cIter; j--) + { + rtl::Reference<VendorBase>& cur= vec.at(j); + rtl::Reference<VendorBase>& next= vec.at(j-1); + + int nCmp = 0; + // comparing invalid SunVersion s is possible, they will be less than a + // valid version + + //check if version of current is recognized, by comparing it with itself + try + { + cur->compareVersions(cur->getVersion()); + } + catch (MalformedVersionException &) + { + nCmp = -1; // current < next + } + //The version of cur is valid, now compare with the second version + if (nCmp == 0) + { + try + { + nCmp = cur->compareVersions(next->getVersion()); + } + catch (MalformedVersionException & ) + { + //The second version is invalid, therefor it is regardes less. + nCmp = 1; + } + } + if(nCmp == 1) // cur > next + { + rtl::Reference<VendorBase> less = next; + vec.at(j-1)= cur; + vec.at(j)= less; + } + } + cIter++; + } +} + + +bool getJREInfoFromBinPath( + const rtl::OUString& path, vector<rtl::Reference<VendorBase> > & vecInfos) +{ + // file:///c:/jre/bin + //map: jre/bin/java.exe + bool ret = false; + vector<pair<OUString, OUString> > props; + + for ( sal_Int32 pos = 0; + gVendorMap[pos].sVendorName != NULL; ++pos ) + { + vector<OUString> vecPaths; + getJavaExePaths_func pFunc = gVendorMap[pos].getJavaFunc; + + int size = 0; + char const* const* arExePaths = (*pFunc)(&size); + vecPaths = getVectorFromCharArray(arExePaths, size); + + //make sure argument path does not end with '/' + OUString sBinPath = path; + if (path.lastIndexOf('/') == (path.getLength() - 1)) + sBinPath = path.copy(0, path.getLength() - 1); + + typedef vector<OUString>::const_iterator c_it; + for (c_it i = vecPaths.begin(); i != vecPaths.end(); i++) + { + //the map contains e.g. jre/bin/java.exe + //get the directory where the executable is contained + OUString sHome; + sal_Int32 index = i->lastIndexOf('/'); + if (index == -1) + { + //map contained only : "java.exe, then the argument + //path is already the home directory + sHome = sBinPath; + } + else + { + // jre/bin/jre -> jre/bin + OUString sMapPath(i->getStr(), index); + index = sBinPath.lastIndexOf(sMapPath); + if (index != -1 + && (index + sMapPath.getLength() == sBinPath.getLength()) + && sBinPath[index - 1] == '/') + { + sHome = OUString(sBinPath.getStr(), index - 1); + } + } + if (sHome.getLength() > 0) + { + ret = getJREInfoByPath(sHome, vecInfos); + if (ret) + break; + } + } + if (ret) + break; + } + return ret; +} + +vector<Reference<VendorBase> > getAllJREInfos() +{ + vector<Reference<VendorBase> > vecInfos; + +#if defined WNT + // Get Javas from the registry + createJavaInfoFromWinReg(vecInfos); +#endif // WNT + + createJavaInfoFromJavaHome(vecInfos); + //this function should be called after createJavaInfoDirScan. + //Otherwise in SDKs Java may be started twice + createJavaInfoFromPath(vecInfos); + +#ifdef UNX + createJavaInfoDirScan(vecInfos); +#endif + + bubbleSortVersion(vecInfos); + return vecInfos; +} + + +vector<OUString> getVectorFromCharArray(char const * const * ar, int size) +{ + vector<OUString> vec; + for( int i = 0; i < size; i++) + { + OUString s(ar[i], strlen(ar[i]), RTL_TEXTENCODING_UTF8); + vec.push_back(s); + } + return vec; +} +bool getJREInfoByPath(const rtl::OUString& path, + std::vector<rtl::Reference<VendorBase> > & vecInfos) +{ + 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); + } + } + return ret; +} + +/** Checks if the path is a directory. Links are resolved. + In case of an error the returned string has the length 0. + Otherwise the returned string is the "resolved" file URL. + */ +OUString resolveDirPath(const OUString & path) +{ + OUString ret; + OUString sResolved; + //getAbsoluteFileURL also resolves links + if (File::getAbsoluteFileURL( + OUSTR("file:///"), path, sResolved) != File::E_None) + return OUString(); + + //check if this is a valid path and if it is a directory + DirectoryItem item; + if (DirectoryItem::get(sResolved, item) == File::E_None) + { + FileStatus status(FileStatusMask_Type | + FileStatusMask_LinkTargetURL | + FileStatusMask_FileURL); + + if (item.getFileStatus(status) == File::E_None + && status.getFileType() == FileStatus::Directory) + { + ret = sResolved; + } + } + else + return OUString(); + return ret; +} +/** Checks if the path is a file. If it is a link to a file than + it is resolved. + */ +OUString resolveFilePath(const OUString & path) +{ + OUString ret; + OUString sResolved; + + if (File::getAbsoluteFileURL( + OUSTR("file:///"), path, sResolved) != File::E_None) + return OUString(); + + //check if this is a valid path to a file or and if it is a link + DirectoryItem item; + if (DirectoryItem::get(sResolved, item) == File::E_None) + { + FileStatus status(FileStatusMask_Type | + FileStatusMask_LinkTargetURL | + FileStatusMask_FileURL); + if (item.getFileStatus(status) == File::E_None + && status.getFileType() == FileStatus::Regular) + { + ret = sResolved; + } + } + else + return OUString(); + + return ret; +} + +rtl::Reference<VendorBase> getJREInfoByPath( + const OUString& path) +{ + rtl::Reference<VendorBase> ret; + static vector<OUString> vecBadPaths; + + static map<OUString, rtl::Reference<VendorBase> > mapJREs; + typedef map<OUString, rtl::Reference<VendorBase> >::const_iterator MapIt; + typedef map<OUString, rtl::Reference<VendorBase> > MAPJRE; + OUString sFilePath; + typedef vector<OUString>::const_iterator cit_path; + vector<pair<OUString, OUString> > props; + + OUString sResolvedDir = resolveDirPath(path); + // If this path is invalid then there is no chance to find a JRE here + if (sResolvedDir.getLength() == 0) + return 0; + + //check if the directory path is good, that is a JRE was already recognized. + //Then we need not detect it again + //For example, a sun JKD contains <jdk>/bin/java and <jdk>/jre/bin/java. + //When <jdk>/bin/java has been found then we need not find <jdk>/jre/bin/java. + //Otherwise we would execute java two times for evers JDK found. + MapIt entry2 = find_if(mapJREs.begin(), mapJREs.end(), + SameOrSubDirJREMap(sResolvedDir)); + if (entry2 != mapJREs.end()) + { + JFW_TRACE2(OUSTR("[Java framework] sunjavaplugin"SAL_DLLEXTENSION ": ") + + OUSTR("JRE found again (detected before): ") + sResolvedDir + + OUSTR(".\n")); + return entry2->second; + } + + for ( sal_Int32 pos = 0; + gVendorMap[pos].sVendorName != NULL; ++pos ) + { + vector<OUString> vecPaths; + getJavaExePaths_func pFunc = gVendorMap[pos].getJavaFunc; + + int size = 0; + char const* const* arExePaths = (*pFunc)(&size); + vecPaths = getVectorFromCharArray(arExePaths, size); + + bool bBreak = false; + typedef vector<OUString>::const_iterator c_it; + for (c_it i = vecPaths.begin(); i != vecPaths.end(); i++) + { + //if the path is a link, then resolve it + //check if the executable exists at all + + //path can be only "file:///". Then do not append a '/' + //sizeof counts the terminating 0 + OUString sFullPath; + if (path.getLength() == sizeof("file:///") - 1) + sFullPath = sResolvedDir + (*i); + else + sFullPath = sResolvedDir + + OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + (*i); + + + sFilePath = resolveFilePath(sFullPath); + + if (sFilePath.getLength() == 0) + { + //The file path (to java exe) is not valid + cit_path ifull = find(vecBadPaths.begin(), vecBadPaths.end(), sFullPath); + if (ifull == vecBadPaths.end()) + vecBadPaths.push_back(sFullPath); + continue; + } + + cit_path ifile = find(vecBadPaths.begin(), vecBadPaths.end(), sFilePath); + if (ifile != vecBadPaths.end()) + continue; + + MapIt entry = mapJREs.find(sFilePath); + if (entry != mapJREs.end()) + { + JFW_TRACE2(OUSTR("[Java framework] sunjavaplugin"SAL_DLLEXTENSION ": ") + + OUSTR("JRE found again (detected before): ") + sFilePath + + OUSTR(".\n")); + + return entry->second; + } + + bool bProcessRun= false; + if (getJavaProps(sFilePath, props, & bProcessRun) == false) + { + //The java executable could not be run or the system properties + //could not be retrieved. We can assume that this java is corrupt. + vecBadPaths.push_back(sFilePath); + //If there was a java executable, that could be run but we did not get + //the system properties, then we also assume that the whole Java installation + //does not work. In a jdk there are two executables. One in jdk/bin and the other + //in jdk/jre/bin. We do not search any further, because we assume that if one java + //does not work then the other does not work as well. This saves us to run java + //again which is quite costly. + if (bProcessRun == true) + { + // 1.3.1 special treatment: jdk/bin/java and /jdk/jre/bin/java are links to + //a script, named .java_wrapper. The script starts jdk/bin/sparc/native_threads/java + //or jdk/jre/bin/sparc/native_threads/java. The script uses the name with which it was + //invoked to build the path to the executable. It we start the script directy as .java_wrapper + //then it tries to start a jdk/.../native_threads/.java_wrapper. Therefore the link, which + //is named java, must be used to start the script. + getJavaProps(sFullPath, props, & bProcessRun); + // Either we found a working 1.3.1 + //Or the java is broken. In both cases we stop searchin under this "root" directory + bBreak = true; + break; + } + //sFilePath is no working java executable. We continue with another possible + //path. + else + { + continue; + } + } + //sFilePath is a java and we could get the system properties. We proceed with this + //java. + else + { + bBreak = true; + break; + } + } + if (bBreak) + break; + } + + if (props.size() == 0) + return rtl::Reference<VendorBase>(); + + //find java.vendor property + typedef vector<pair<OUString, OUString> >::const_iterator c_ip; + OUString sVendor(RTL_CONSTASCII_USTRINGPARAM("java.vendor")); + OUString sVendorName; + + for (c_ip i = props.begin(); i != props.end(); i++) + { + if (sVendor.equals(i->first)) + { + sVendorName = i->second; + break; + } + } + + if (sVendorName.getLength() > 0) + { + //find the creator func for the respective vendor name + for ( sal_Int32 c = 0; + gVendorMap[c].sVendorName != NULL; ++c ) + { + OUString sNameMap(gVendorMap[c].sVendorName, strlen(gVendorMap[c].sVendorName), + RTL_TEXTENCODING_ASCII_US); + if (sNameMap.equals(sVendorName)) + { + ret = createInstance(gVendorMap[c].createFunc, props); + break; + } + } + } + if (ret.is() == false) + vecBadPaths.push_back(sFilePath); + else + { + JFW_TRACE2(OUSTR("[Java framework] sunjavaplugin"SAL_DLLEXTENSION ": ") + + OUSTR("Found JRE: ") + sResolvedDir + + OUSTR(" \n at: ") + path + OUSTR(".\n")); + + mapJREs.insert(MAPJRE::value_type(sResolvedDir, ret)); + mapJREs.insert(MAPJRE::value_type(sFilePath, ret)); + } + + return ret; +} + +Reference<VendorBase> createInstance(createInstance_func pFunc, + vector<pair<OUString, OUString> > properties) +{ + + Reference<VendorBase> aBase = (*pFunc)(); + if (aBase.is()) + { + if (aBase->initialize(properties) == false) + aBase = 0; + } + return aBase; +} + +inline OUString getDirFromFile(const OUString& usFilePath) +{ + sal_Int32 index= usFilePath.lastIndexOf('/'); + return OUString(usFilePath.getStr(), index); +} + +void createJavaInfoFromPath(vector<rtl::Reference<VendorBase> >& vecInfos) +{ +// Get Java from PATH environment variable + static OUString sCurDir(RTL_CONSTASCII_USTRINGPARAM(".")); + static OUString sParentDir(RTL_CONSTASCII_USTRINGPARAM("..")); + char *szPath= getenv("PATH"); + if(szPath) + { + OUString usAllPath(szPath, strlen(szPath), osl_getThreadTextEncoding()); + sal_Int32 nIndex = 0; + do + { + OUString usToken = usAllPath.getToken( 0, SAL_PATHSEPARATOR, nIndex ); + OUString usTokenUrl; + if(File::getFileURLFromSystemPath(usToken, usTokenUrl) == File::E_None) + { + if(usTokenUrl.getLength()) + { + OUString usBin; + // "." + if(usTokenUrl.equals(sCurDir)) + { + OUString usWorkDirUrl; + if(osl_Process_E_None == osl_getProcessWorkingDir(&usWorkDirUrl.pData)) + usBin= usWorkDirUrl; + } + // ".." + else if(usTokenUrl.equals(sParentDir)) + { + OUString usWorkDir; + if(osl_Process_E_None == osl_getProcessWorkingDir(&usWorkDir.pData)) + usBin= getDirFromFile(usWorkDir); + } + else + { + usBin = usTokenUrl; + } + if(usBin.getLength()) + { + getJREInfoFromBinPath(usBin, vecInfos); + } + } + } + } + while ( nIndex >= 0 ); + } +} + +void createJavaInfoFromJavaHome(vector<rtl::Reference<VendorBase> >& vecInfos) +{ + // Get Java from JAVA_HOME environment + char *szJavaHome= getenv("JAVA_HOME"); + if(szJavaHome) + { + OUString sHome(szJavaHome,strlen(szJavaHome),osl_getThreadTextEncoding()); + OUString sHomeUrl; + if(File::getFileURLFromSystemPath(sHome, sHomeUrl) == File::E_None) + { + getJREInfoByPath(sHomeUrl, vecInfos); + } + } +} + +bool makeDriveLetterSame(OUString * fileURL) +{ + bool ret = false; + DirectoryItem item; + if (DirectoryItem::get(*fileURL, item) == File::E_None) + { + FileStatus status(FileStatusMask_FileURL); + if (item.getFileStatus(status) == File::E_None) + { + *fileURL = status.getFileURL(); + ret = true; + } + } + return ret; +} + +#ifdef UNX +#ifdef SOLARIS + +void createJavaInfoDirScan(vector<rtl::Reference<VendorBase> >& vecInfos) +{ + JFW_TRACE2(OUSTR("\n[Java framework] Checking \"/usr/jdk/latest\"\n")); + getJREInfoByPath(OUSTR("file:////usr/jdk/latest"), vecInfos); +} + +#else +void createJavaInfoDirScan(vector<rtl::Reference<VendorBase> >& vecInfos) +{ + OUString excMessage = OUSTR("[Java framework] sunjavaplugin: " + "Error in function createJavaInfoDirScan in util.cxx."); + int cJavaNames= sizeof(g_arJavaNames) / sizeof(char*); + boost::scoped_array<OUString> sarJavaNames(new OUString[cJavaNames]); + OUString *arNames = sarJavaNames.get(); + for(int i= 0; i < cJavaNames; i++) + arNames[i] = OUString(g_arJavaNames[i], strlen(g_arJavaNames[i]), + RTL_TEXTENCODING_UTF8); + + int cSearchPaths= sizeof(g_arSearchPaths) / sizeof(char*); + boost::scoped_array<OUString> sarPathNames(new OUString[cSearchPaths]); + OUString *arPaths = sarPathNames.get(); + for(int c = 0; c < cSearchPaths; c++) + arPaths[c] = OUString(g_arSearchPaths[c], strlen(g_arSearchPaths[c]), + RTL_TEXTENCODING_UTF8); + + int cCollectDirs = sizeof(g_arCollectDirs) / sizeof(char*); + boost::scoped_array<OUString> sarCollectDirs(new OUString[cCollectDirs]); + OUString *arCollectDirs = sarCollectDirs.get(); + for(int d = 0; d < cCollectDirs; d++) + arCollectDirs[d] = OUString(g_arCollectDirs[d], strlen(g_arCollectDirs[d]), + RTL_TEXTENCODING_UTF8); + + + + OUString usFile(RTL_CONSTASCII_USTRINGPARAM("file:///")); + for( int ii = 0; ii < cSearchPaths; ii ++) + { + OUString usDir1(usFile + arPaths[ii]); + DirectoryItem item; + if(DirectoryItem::get(usDir1, item) == File::E_None) + { + for(int j= 0; j < cCollectDirs; j++) + { + OUString usDir2(usDir1 + arCollectDirs[j]); + // prevent that we scan the whole /usr, /usr/lib, etc directories + if (arCollectDirs[j] != OUString()) + { + //usr/java/xxx + //Examin every subdirectory + Directory aCollectionDir(usDir2); + + Directory::RC openErr = aCollectionDir.open(); + switch (openErr) + { + case File::E_None: + break; + case File::E_NOENT: + case File::E_NOTDIR: + continue; + case File::E_ACCES: + JFW_TRACE2(OUSTR("[Java framework] sunjavaplugin: " + "Could not read directory ") + usDir2 + + OUSTR(" because of missing access rights.")); + continue; + default: + JFW_TRACE2(OUSTR("[Java framework] sunjavaplugin: " + "Could not read directory ") + + usDir2 + OUSTR(". Osl file error: ") + + OUString::valueOf((sal_Int32) openErr)); + continue; + } + + DirectoryItem curIt; + File::RC errNext = File::E_None; + while( (errNext = aCollectionDir.getNextItem(curIt)) == File::E_None) + { + FileStatus aStatus(FileStatusMask_FileURL); + File::RC errStatus = File::E_None; + if ((errStatus = curIt.getFileStatus(aStatus)) != File::E_None) + { + JFW_TRACE2(excMessage + OUSTR("getFileStatus failed with error ") + + OUString::valueOf((sal_Int32) errStatus)); + continue; + } + JFW_TRACE2(OUSTR("[Java framework] sunjavaplugin: " + "Checking if directory: ") + aStatus.getFileURL() + + OUSTR(" is a Java. \n")); + + getJREInfoByPath(aStatus.getFileURL(),vecInfos); + } + + JFW_ENSURE(errNext == File::E_None || errNext == File::E_NOENT, + OUSTR("[Java framework] sunjavaplugin: " + "Error while iterating over contens of ") + + usDir2 + OUSTR(". Osl file error: ") + + OUString::valueOf((sal_Int32) openErr)); + } + else + { + //usr/java + //When we look directly into a dir like /usr, /usr/lib, etc. then we only + //look for certain java directories, such as jre, jdk, etc. Whe do not want + //to examine the whole directory because of performance reasons. + DirectoryItem item2; + if(DirectoryItem::get(usDir2, item2) == File::E_None) + { + for( int k= 0; k < cJavaNames; k++) + { + // /usr/java/j2re1.4.0 + OUString usDir3(usDir2 + arNames[k]); + + DirectoryItem item3; + if(DirectoryItem::get(usDir3, item) == File::E_None) + { + //remove trailing '/' + sal_Int32 islash = usDir3.lastIndexOf('/'); + if (islash == usDir3.getLength() - 1 + && (islash + > RTL_CONSTASCII_LENGTH("file://"))) + usDir3 = usDir3.copy(0, islash); + getJREInfoByPath(usDir3,vecInfos); + } + } + } + } + } + } + } +} +#endif // ifdef SOLARIS +#endif // ifdef UNX +} diff --git a/jvmfwk/plugins/sunmajor/pluginlib/util.hxx b/jvmfwk/plugins/sunmajor/pluginlib/util.hxx new file mode 100644 index 000000000000..c312372e5fa2 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/util.hxx @@ -0,0 +1,130 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#if !defined INCLUDED_JFW_PLUGIN_UTIL_HXX +#define INCLUDED_JFW_PLUGIN_UTIL_HXX + +#include "rtl/ustring.hxx" +#include "rtl/bootstrap.hxx" +#include <vector> +#include "vendorbase.hxx" + +namespace jfw_plugin +{ + +class VendorBase; +std::vector<rtl::OUString> getVectorFromCharArray(char const * const * ar, int size); + +/* The function uses the relative paths, such as "bin/java.exe" as provided by + VendorBase::getJavaExePaths and the provided path to derive the the home directory. + The home directory is then used as argument to getJREInfoByPath. For example + usBinDir is file:///c:/j2sdk/jre/bin then file:///c:/j2sdk/jre would be derived. + */ +bool getJREInfoFromBinPath( + const rtl::OUString& path, std::vector<rtl::Reference<VendorBase> > & vecInfos); +inline rtl::OUString getDirFromFile(const rtl::OUString& usFilePath); +void createJavaInfoFromPath(std::vector<rtl::Reference<VendorBase> >& vecInfos); +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 + +bool makeDriveLetterSame(rtl::OUString * fileURL); + + +/* for std::find_if + Used to find a JavaInfo::Impl object in a std::vector<Impl*> which has a member usJavaHome + as the specified string in the constructor. +*/ +struct InfoFindSame +{ + rtl::OUString sJava; + InfoFindSame(const rtl::OUString& sJavaHome):sJava(sJavaHome){} + + bool operator () (const rtl::Reference<VendorBase> & aVendorInfo) + { + return aVendorInfo->getHome().equals(sJava) == sal_True ? true : false; + } +}; + +struct SameOrSubDirJREMap +{ + rtl::OUString s1; + SameOrSubDirJREMap(const rtl::OUString& s):s1(s){ + } + + bool operator () (const std::pair<const rtl::OUString, rtl::Reference<VendorBase> > & s2) + { + if (s1 == s2.first) + return true; + rtl::OUString sSub; + sSub = s2.first + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")); + if (s1.match(sSub) == sal_True) + return true; + return false; + } +}; + + +/* Creates a VendorBase object if a JRE could be found at the specified path. + + This depends if there is a JRE at all and if it is from a vendor that + is supported by this plugin. + */ +rtl::Reference<VendorBase> getJREInfoByPath(const rtl::OUString& path); + +/* Creates a VendorBase object if a JRE could be found at the specified path. + + The difference to the other getJREInfoByPath is that this function checks + first if the path corresponds to one of the VendorBase::getHome path already + contained in vecInfo. Only if there is no such entry, then the other + getJREInfoByPath is called. Again the created VendorBase is compared to + those contained in vecInfos. If it it not in there then it's added. + + @return + true a VendorBase was created and added to the end of vecInfos. + false - no VendorBase has been created. Either the path did not represent a + supported JRE installation or there was already a VendorBase in vecInfos. + */ +bool getJREInfoByPath(const rtl::OUString& path, + std::vector<rtl::Reference<VendorBase> > & vecInfos); + +std::vector<rtl::Reference<VendorBase> > getAllJREInfos(); + +bool getJavaProps( + const rtl::OUString & exePath, + std::vector<std::pair<rtl::OUString, rtl::OUString> >& props, + bool * bProcessRun); + +void createJavaInfoFromWinReg(std::vector<rtl::Reference<VendorBase> > & vecInfos); + +void bubbleSortVersion(std::vector<rtl::Reference<VendorBase> >& vec); + +rtl::Bootstrap* getBootstrap(); +} + +#endif diff --git a/jvmfwk/plugins/sunmajor/pluginlib/vendorbase.cxx b/jvmfwk/plugins/sunmajor/pluginlib/vendorbase.cxx new file mode 100644 index 000000000000..0106981a0a32 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/vendorbase.cxx @@ -0,0 +1,276 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_jvmfwk.hxx" + +#include "osl/file.hxx" + +#include "vendorbase.hxx" +#include "util.hxx" +#include "sunjre.hxx" + +using namespace std; +using namespace rtl; +using namespace osl; + +namespace jfw_plugin +{ +rtl::Reference<VendorBase> createInstance(createInstance_func pFunc, + vector<pair<OUString, OUString> > properties); + + + + + + + +//############################################################################## + +MalformedVersionException::MalformedVersionException() +{} +MalformedVersionException::MalformedVersionException( + const MalformedVersionException & ) +{} +MalformedVersionException::~MalformedVersionException() +{} +MalformedVersionException & +MalformedVersionException::operator =( + const MalformedVersionException &) +{ + return *this; +} +//############################################################################## + + +VendorBase::VendorBase(): m_bAccessibility(false) +{ +} + +char const* const * VendorBase::getJavaExePaths(int* size) +{ + static char const * ar[] = { +#if defined(WNT) || defined(OS2) + "java.exe", + "bin/java.exe" +#elif UNX + "java", + "bin/java" +#endif + }; + *size = sizeof(ar) / sizeof(char*); + return ar; +} + + +rtl::Reference<VendorBase> VendorBase::createInstance() +{ + VendorBase *pBase = new VendorBase(); + return rtl::Reference<VendorBase>(pBase); +} + +bool VendorBase::initialize(vector<pair<OUString, OUString> > props) +{ + //get java.vendor, java.version, java.home, + //javax.accessibility.assistive_technologies from system properties + + OUString sVendor; + typedef vector<pair<OUString, OUString> >::const_iterator it_prop; + OUString sVendorProperty( + RTL_CONSTASCII_USTRINGPARAM("java.vendor")); + OUString sVersionProperty( + RTL_CONSTASCII_USTRINGPARAM("java.version")); + OUString sHomeProperty( + RTL_CONSTASCII_USTRINGPARAM("java.home")); + OUString sAccessProperty( + RTL_CONSTASCII_USTRINGPARAM("javax.accessibility.assistive_technologies")); + + bool bVersion = false; + bool bVendor = false; + bool bHome = false; + bool bAccess = false; + + typedef vector<pair<OUString, OUString> >::const_iterator it_prop; + for (it_prop i = props.begin(); i != props.end(); i++) + { + if(! bVendor && sVendorProperty.equals(i->first)) + { + m_sVendor = i->second; + bVendor = true; + } + else if (!bVersion && sVersionProperty.equals(i->first)) + { + m_sVersion = i->second; + bVersion = true; + } + else if (!bHome && sHomeProperty.equals(i->first)) + { + OUString fileURL; + if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) == + osl_File_E_None) + { + //make sure that the drive letter have all the same case + //otherwise file:///c:/jre and file:///C:/jre produce two + //different objects!!! + if (makeDriveLetterSame( & fileURL)) + { + m_sHome = fileURL; + bHome = true; + } + } + } + else if (!bAccess && sAccessProperty.equals(i->first)) + { + if (i->second.getLength() > 0) + { + m_bAccessibility = true; + bAccess = true; + } + } + // the javax.accessibility.xxx property may not be set. Therefore we + //must search through all properties. + + } + if (!bVersion || !bVendor || !bHome) + return false; + + // init m_sRuntimeLibrary + OSL_ASSERT(m_sHome.getLength()); + //call virtual function to get the possible paths to the runtime library. + + int size = 0; + char const* const* arRtPaths = getRuntimePaths( & size); + vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size); + + bool bRt = false; + typedef vector<OUString>::const_iterator i_path; + for(i_path ip = libpaths.begin(); ip != libpaths.end(); ip++) + { + //Construct an absolute path to the possible runtime + OUString usRt= m_sHome + *ip; + DirectoryItem item; + if(DirectoryItem::get(usRt, item) == File::E_None) + { + //found runtime lib + m_sRuntimeLibrary = usRt; + bRt = true; + break; + } + } + if (!bRt) + return false; + + // init m_sLD_LIBRARY_PATH + OSL_ASSERT(m_sHome.getLength()); + size = 0; + char const * const * arLDPaths = getLibraryPaths( & size); + vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size); + + char arSep[]= {SAL_PATHSEPARATOR, 0}; + OUString sPathSep= OUString::createFromAscii(arSep); + bool bLdPath = true; + int c = 0; + for(i_path il = ld_paths.begin(); il != ld_paths.end(); il ++, c++) + { + OUString usAbsUrl= m_sHome + *il; + // convert to system path + OUString usSysPath; + if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None) + { + + if(c > 0) + m_sLD_LIBRARY_PATH+= sPathSep; + m_sLD_LIBRARY_PATH+= usSysPath; + } + else + { + bLdPath = false; + break; + } + } + if (bLdPath == false) + return false; + + return true; +} + +char const* const* VendorBase::getRuntimePaths(int* /*size*/) +{ + return NULL; +} + +char const* const* VendorBase::getLibraryPaths(int* /*size*/) +{ + return NULL; +} + +const OUString & VendorBase::getVendor() const +{ + return m_sVendor; +} +const OUString & VendorBase::getVersion() const +{ + return m_sVersion; +} + +const OUString & VendorBase::getHome() const +{ + return m_sHome; +} + +const OUString & VendorBase::getLibraryPaths() const +{ + return m_sLD_LIBRARY_PATH; +} + +const OUString & VendorBase::getRuntimeLibrary() const +{ + return m_sRuntimeLibrary; +} +bool VendorBase::supportsAccessibility() const +{ + return m_bAccessibility; +} + +bool VendorBase::needsRestart() const +{ + if (getLibraryPaths().getLength() > 0) + return true; + return false; +} + +int VendorBase::compareVersions(const rtl::OUString& /*sSecond*/) const +{ + OSL_ENSURE(0, "[Java framework] VendorBase::compareVersions must be " + "overridden in derived class."); + return 0; +} + + + + +} diff --git a/jvmfwk/plugins/sunmajor/pluginlib/vendorbase.hxx b/jvmfwk/plugins/sunmajor/pluginlib/vendorbase.hxx new file mode 100644 index 000000000000..3302fe42e90c --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/vendorbase.hxx @@ -0,0 +1,185 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#if !defined INCLUDED_JFW_PLUGIN_VENDORBASE_HXX +#define INCLUDED_JFW_PLUGIN_VENDORBASE_HXX + +#include "rtl/ustring.hxx" +#include "rtl/ref.hxx" +#include "osl/endian.h" +#include "salhelper/simplereferenceobject.hxx" +#include <vector> + +namespace jfw_plugin +{ + + +//Used by subclasses of VendorBase to build paths to Java runtime +#if defined(__sparcv9) +#define JFW_PLUGIN_ARCH "sparcv9" +#elif defined SPARC +#define JFW_PLUGIN_ARCH "sparc" +#elif defined X86_64 +#define JFW_PLUGIN_ARCH "amd64" +#elif defined INTEL +#define JFW_PLUGIN_ARCH "i386" +#elif defined POWERPC64 +#define JFW_PLUGIN_ARCH "ppc64" +#elif defined POWERPC +#define JFW_PLUGIN_ARCH "ppc" +#elif defined MIPS +#ifdef OSL_BIGENDIAN +# define JFW_PLUGIN_ARCH "mips" +#else +# define JFW_PLUGIN_ARCH "mips32" +#endif +#elif defined S390X +#define JFW_PLUGIN_ARCH "s390x" +#elif defined S390 +#define JFW_PLUGIN_ARCH "s390" +#elif defined ARM +#define JFW_PLUGIN_ARCH "arm" +#elif defined IA64 +#define JFW_PLUGIN_ARCH "ia64" +#elif defined M68K +#define JFW_PLUGIN_ARCH "m68k" +#elif defined HPPA +#define JFW_PLUGIN_ARCH "parisc" +#elif defined AXP +#define JFW_PLUGIN_ARCH "alpha" +#else // SPARC, INTEL, POWERPC, MIPS, ARM, IA64, M68K, HPPA, ALPHA +#error unknown plattform +#endif // SPARC, INTEL, POWERPC, MIPS, ARM, IA64, M68K, HPPA, ALPHA + + +class MalformedVersionException +{ +public: + MalformedVersionException(); + + MalformedVersionException(const MalformedVersionException &); + + virtual ~MalformedVersionException(); + + MalformedVersionException & operator =(const MalformedVersionException &); +}; + +class VendorBase: public salhelper::SimpleReferenceObject +{ +public: + VendorBase(); + /* returns relativ paths to the java executable as + file URLs. + + For example "bin/java.exe". You need + to implement this function in a derived class, if + the paths differ. this implmentation provides for + Windows "bin/java.exe" and for Unix "bin/java". + The paths are relative file URLs. That is, they always + contain '/' even on windows. The paths are relative + to the installation directory of a JRE. + + + The signature of this function must correspond to + getJavaExePaths_func. + */ + static char const* const * getJavaExePaths(int* size); + + /* creates an instance of this class. MUST be overridden + in a derived class. + #################################################### + OVERRIDE in derived class + ################################################### + @param + Key - value pairs of the system properties of the JRE. + */ + static rtl::Reference<VendorBase> createInstance(); + + /* called automatically on the instance created by createInstance. + + @return + true - the object could completely initialize. + false - the object could not completly initialize. In this case + it will be discarded by the caller. + */ + virtual bool initialize( + std::vector<std::pair<rtl::OUString, rtl::OUString> > props); + + /* returns relative file URLs to the runtime library. + For example "/bin/client/jvm.dll" + */ + virtual char const* const* getRuntimePaths(int* size); + + virtual char const* const* getLibraryPaths(int* size); + + virtual const rtl::OUString & getVendor() const; + virtual const rtl::OUString & getVersion() const; + virtual const rtl::OUString & getHome() const; + virtual const rtl::OUString & getRuntimeLibrary() const; + virtual const rtl::OUString & getLibraryPaths() const; + virtual bool supportsAccessibility() const; + /* determines if prior to running java something has to be done, + like setting the LD_LIBRARY_PATH. This implementation checks + if an LD_LIBRARY_PATH (getLD_LIBRARY_PATH) needs to be set and + if so, needsRestart returns true. + */ + virtual bool needsRestart() const; + + /* compares versions of this vendor. MUST be overridden + in a derived class. + #################################################### + OVERRIDE in derived class + ################################################### + @return + 0 this.version == sSecond + 1 this.version > sSecond + -1 this.version < sSEcond + + @throw + MalformedVersionException if the version string was not recognized. + */ + virtual int compareVersions(const rtl::OUString& sSecond) const; + +protected: + + rtl::OUString m_sVendor; + rtl::OUString m_sVersion; + rtl::OUString m_sHome; + rtl::OUString m_sRuntimeLibrary; + rtl::OUString m_sLD_LIBRARY_PATH; + bool m_bAccessibility; + + + typedef rtl::Reference<VendorBase> (* createInstance_func) (); + friend rtl::Reference<VendorBase> createInstance( + createInstance_func pFunc, + std::vector<std::pair<rtl::OUString, rtl::OUString> > properties); +}; + +} + +#endif diff --git a/jvmfwk/plugins/sunmajor/pluginlib/vendorlist.cxx b/jvmfwk/plugins/sunmajor/pluginlib/vendorlist.cxx new file mode 100644 index 000000000000..1ff82db205d4 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/vendorlist.cxx @@ -0,0 +1,91 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_jvmfwk.hxx" + +#include "vendorlist.hxx" +#include "gnujre.hxx" +#include "sunjre.hxx" +#include "otherjre.hxx" +#include "osl/thread.h" +#include <stdio.h> + +using namespace com::sun::star::uno; +using namespace rtl; + +namespace jfw_plugin +{ + +/* Note: The vendor strings must be UTF-8. For example, if + the string contains an a umlaut then it must be expressed + by "\xXX\xXX" + */ +BEGIN_VENDOR_MAP() + VENDOR_MAP_ENTRY("Sun Microsystems Inc.", SunInfo) + VENDOR_MAP_ENTRY("IBM Corporation", OtherInfo) + VENDOR_MAP_ENTRY("Blackdown Java-Linux Team", OtherInfo) + VENDOR_MAP_ENTRY("Apple Inc.", OtherInfo) + VENDOR_MAP_ENTRY("Apple Computer, Inc.", OtherInfo) + VENDOR_MAP_ENTRY("BEA Systems, Inc.", OtherInfo) + VENDOR_MAP_ENTRY("Free Software Foundation, Inc.", GnuInfo) + VENDOR_MAP_ENTRY("The FreeBSD Foundation", OtherInfo) +END_VENDOR_MAP() + + +Sequence<OUString> getVendorNames() +{ + const size_t count = sizeof(gVendorMap) / sizeof (VendorSupportMapEntry) - 1; + OUString arNames[count]; + for ( size_t pos = 0; pos < count; ++pos ) + { + OString sVendor(gVendorMap[pos].sVendorName); + arNames[pos] = OStringToOUString(sVendor, RTL_TEXTENCODING_UTF8); + } + return Sequence<OUString>(arNames, count); +} + +bool isVendorSupported(const rtl::OUString& sVendor) +{ + Sequence<OUString> seqNames = getVendorNames(); + const OUString * arNames = seqNames.getConstArray(); + sal_Int32 count = seqNames.getLength(); + + for (int i = 0; i < count; i++) + { + if (sVendor.equals(arNames[i])) + return true; + } +#if OSL_DEBUG_LEVEL >= 2 + OString sVendorName = OUStringToOString(sVendor, osl_getThreadTextEncoding()); + fprintf(stderr, "[Java frameworksunjavaplugin.so]sunjavaplugin does not support vendor: %s.\n", + sVendorName.getStr()); +#endif + return false; +} + +} diff --git a/jvmfwk/plugins/sunmajor/pluginlib/vendorlist.hxx b/jvmfwk/plugins/sunmajor/pluginlib/vendorlist.hxx new file mode 100644 index 000000000000..7cc00fd1787b --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/vendorlist.hxx @@ -0,0 +1,75 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#if !defined INCLUDED_JFW_PLUGIN_VENDORLIST_HXX +#define INCLUDED_JFW_PLUGIN_VENDORLIST_HXX + +#include "rtl/ref.hxx" +#include "vendorbase.hxx" +#include "com/sun/star/uno/Sequence.hxx" + +namespace jfw_plugin +{ + +//extern VendorSupportMapEntry gVendorMap[]; + +typedef char const * const * (* getJavaExePaths_func)(int*); +typedef rtl::Reference<VendorBase> (* createInstance_func) (); + +// struct Blas +// { +// char const * sVendorName; +// getJavaExePaths_func getJavaFunc; +// createInstance_func createFunc; +// }; + +struct VendorSupportMapEntry +{ + char const * sVendorName; + getJavaExePaths_func getJavaFunc; + createInstance_func createFunc; +}; + +#define BEGIN_VENDOR_MAP() \ +VendorSupportMapEntry gVendorMap[] ={ + +#define VENDOR_MAP_ENTRY(x,y) \ + {x, & y::getJavaExePaths, & y::createInstance}, + +#define END_VENDOR_MAP() \ + {NULL, NULL, NULL} }; + + +com::sun::star::uno::Sequence<rtl::OUString> getVendorNames(); + +/* Examines if the vendor supplied in parameter sVendor is part of the + list of supported vendors. That is the arry of VendorSupportMapEntry + is search for an respective entry. +*/ +bool isVendorSupported(const rtl::OUString & sVendor); +} + +#endif |