LCOV - code coverage report
Current view: top level - jvmfwk/plugins/sunmajor/javaenvsetup - javaldx.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 36 66 54.5 %
Date: 2012-08-25 Functions: 4 5 80.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 28 88 31.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : 
      21                 :            : #include <stdio.h>
      22                 :            : #include <stdlib.h>
      23                 :            : #include <string.h>
      24                 :            : #include "sal/main.h"
      25                 :            : #include "sal/types.h"
      26                 :            : #include "osl/thread.h"
      27                 :            : #include "rtl/ustring.hxx"
      28                 :            : #include "rtl/byteseq.hxx"
      29                 :            : #include "jvmfwk/framework.h"
      30                 :            : 
      31                 :            : using ::rtl::OUString;
      32                 :            : using ::rtl::OUStringToOString;
      33                 :            : using ::rtl::OString;
      34                 :            : 
      35                 :            : static sal_Bool hasOption(char const * szOption, int argc, char** argv);
      36                 :            : static rtl::OString getLD_LIBRARY_PATH(const rtl::ByteSequence & vendorData);
      37                 :            : static bool findAndSelect(JavaInfo**);
      38                 :            : 
      39                 :            : #define HELP_TEXT    \
      40                 :            : "\njavaldx is necessary to make Java work on some UNIX platforms." \
      41                 :            : "It prints a string to std out that consists of directories which " \
      42                 :            : "have to be included into the LD_LIBRARY_PATH variable.The setting of " \
      43                 :            : "the variable usually occurs in a shell script that runs javaldx.\n" \
      44                 :            : "The directories are from the chosen java installation. \n" \
      45                 :            : "Options are: \n"\
      46                 :            : "--help or -h\n"
      47                 :            : 
      48                 :        101 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
      49                 :            : {
      50 [ +  - ][ -  + ]:        101 :     if( hasOption("--help",argc, argv) || hasOption("-h", argc, argv))
                 [ -  + ]
      51                 :            :     {
      52         [ #  # ]:          0 :         fprintf(stdout, HELP_TEXT);// default
      53                 :          0 :         return 0;
      54                 :            :     }
      55                 :        101 :     javaFrameworkError errcode = JFW_E_NONE;
      56                 :        101 :     sal_Bool bEnabled = sal_False;
      57         [ +  - ]:        101 :     errcode = jfw_getEnabled( & bEnabled);
      58 [ +  + ][ -  + ]:        101 :     if (errcode == JFW_E_NONE && bEnabled == sal_False)
      59                 :            :     {
      60                 :            :             //Do not do any preparation because that may only slow startup time.
      61                 :          0 :         return 0;
      62                 :            :     }
      63 [ +  + ][ -  + ]:        101 :     else if (errcode != JFW_E_NONE && errcode != JFW_E_DIRECT_MODE)
      64                 :            :     {
      65         [ #  # ]:          0 :         fprintf(stderr,"javaldx failed! \n");
      66                 :          0 :         return -1;
      67                 :            :     }
      68                 :            : 
      69                 :            : 
      70                 :        101 :     JavaInfo * pInfo = NULL;
      71         [ +  - ]:        101 :     errcode = jfw_getSelectedJRE( & pInfo);
      72                 :            : 
      73 [ -  + ][ #  # ]:        101 :     if (errcode != JFW_E_NONE && errcode != JFW_E_INVALID_SETTINGS)
      74                 :            :     {
      75         [ #  # ]:          0 :         fprintf(stderr,"javaldx failed! \n");
      76                 :          0 :         return -1;
      77                 :            :     }
      78                 :            : 
      79         [ -  + ]:        101 :     if (pInfo == NULL)
      80                 :            :     {
      81 [ #  # ][ #  # ]:          0 :         if (false == findAndSelect(&pInfo))
      82                 :          0 :             return -1;
      83                 :            :     }
      84                 :            :     else
      85                 :            :     {
      86                 :            :         //check if the JRE was not uninstalled
      87                 :        101 :         sal_Bool bExist = sal_False;
      88         [ +  - ]:        101 :         errcode = jfw_existJRE(pInfo, &bExist);
      89         [ +  - ]:        101 :         if (errcode == JFW_E_NONE)
      90                 :            :         {
      91 [ -  + ][ #  # ]:        101 :             if (!bExist && !findAndSelect(&pInfo))
         [ #  # ][ -  + ]
      92                 :          0 :                 return -1;
      93                 :            :         }
      94                 :            :         else
      95                 :            :         {
      96         [ #  # ]:          0 :             fprintf(stderr, "javaldx: Could not determine if JRE still exist\n");
      97                 :        101 :             return -1;
      98                 :            :         }
      99                 :            :     }
     100                 :            : 
     101                 :        101 :     rtl::OUString aVendor( pInfo->sVendor );
     102                 :            :     // Only do something if the sunjavaplugin created this JavaInfo
     103 [ -  + ][ +  -  :        202 :     if ( aVendor != "Sun Microsystems Inc." &&
          -  +  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                      # ]
     104                 :        101 :          aVendor != "Oracle Corporation" &&
     105                 :          0 :          aVendor != "IBM Corporation" &&
     106                 :          0 :          aVendor != "Blackdown Java-Linux Team" &&
     107                 :          0 :          aVendor != "Apple Inc." &&
     108                 :          0 :          aVendor != "Apple Computer, Inc." &&
     109                 :          0 :          aVendor != "BEA Systems, Inc." &&
     110                 :          0 :          aVendor != "Free Software Foundation, Inc." &&
     111                 :          0 :          aVendor != "The FreeBSD Foundation" )
     112                 :          0 :         return 0;
     113                 :            : 
     114         [ +  - ]:        101 :     rtl::OString sPaths = getLD_LIBRARY_PATH(pInfo->arVendorData);
     115         [ +  - ]:        101 :     fprintf(stdout, "%s\n", sPaths.getStr());
     116         [ +  - ]:        101 :     jfw_freeJavaInfo(pInfo);
     117                 :            : 
     118                 :        101 :     return 0;
     119                 :            : }
     120                 :            : 
     121                 :        101 : rtl::OString getLD_LIBRARY_PATH(const rtl::ByteSequence & vendorData)
     122                 :            : {
     123                 :        101 :     const sal_Unicode* chars = (sal_Unicode*) vendorData.getConstArray();
     124                 :        101 :     sal_Int32 len = vendorData.getLength();
     125                 :        101 :     rtl::OUString sData(chars, len / 2);
     126                 :            :     //the runtime lib is on the first line
     127                 :        101 :     sal_Int32 index = 0;
     128                 :        101 :     rtl::OUString aToken = sData.getToken( 1, '\n', index);
     129                 :            : 
     130                 :            :     rtl::OString paths =
     131 [ +  - ][ +  - ]:        101 :         rtl::OUStringToOString(aToken, osl_getThreadTextEncoding());
     132                 :        101 :     return paths;
     133                 :            : }
     134                 :            : 
     135                 :        202 : static sal_Bool hasOption(char const * szOption, int argc, char** argv)
     136                 :            : {
     137                 :        202 :     sal_Bool retVal= sal_False;
     138         [ +  + ]:        218 :     for(sal_Int16 i= 1; i < argc; i++)
     139                 :            :     {
     140         [ -  + ]:         16 :         if( ! strcmp(argv[i], szOption))
     141                 :            :         {
     142                 :          0 :             retVal= sal_True;
     143                 :          0 :             break;
     144                 :            :         }
     145                 :            :     }
     146                 :        202 :     return retVal;
     147                 :            : }
     148                 :            : 
     149                 :          0 : static bool findAndSelect(JavaInfo ** ppInfo)
     150                 :            : {
     151                 :          0 :     javaFrameworkError errcode = jfw_findAndSelectJRE(ppInfo);
     152         [ #  # ]:          0 :     if (errcode == JFW_E_NO_JAVA_FOUND)
     153                 :            :     {
     154                 :          0 :         fprintf(stderr,"javaldx: Could not find a Java Runtime Environment! \n");
     155                 :          0 :         return false;
     156                 :            :     }
     157 [ #  # ][ #  # ]:          0 :     else if (errcode != JFW_E_NONE && errcode != JFW_E_DIRECT_MODE)
     158                 :            :     {
     159                 :          0 :         fprintf(stderr,"javaldx failed!\n");
     160                 :          0 :         return false;
     161                 :            :     }
     162                 :          0 :     return true;
     163                 :            : }
     164                 :            : 
     165                 :            : 
     166                 :            : 
     167                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10