LCOV - code coverage report
Current view: top level - jvmfwk/plugins/sunmajor/javaenvsetup - javaldx.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 42 67 62.7 %
Date: 2014-04-14 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          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             : 
      32             : static bool hasOption(char const * szOption, int argc, char** argv);
      33             : static OString getLD_LIBRARY_PATH(const rtl::ByteSequence & vendorData);
      34             : static bool findAndSelect(JavaInfo**);
      35             : 
      36             : #define HELP_TEXT    \
      37             : "\njavaldx is necessary to make Java work on some UNIX platforms." \
      38             : "It prints a string to std out that consists of directories which " \
      39             : "have to be included into the LD_LIBRARY_PATH variable.The setting of " \
      40             : "the variable usually occurs in a shell script that runs javaldx.\n" \
      41             : "The directories are from the chosen java installation. \n" \
      42             : "Options are: \n"\
      43             : "--help or -h\n"
      44             : 
      45       85010 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
      46             : {
      47       42505 :     if( hasOption("--help",argc, argv) || hasOption("-h", argc, argv))
      48             :     {
      49           0 :         fprintf(stdout, HELP_TEXT);// default
      50           0 :         return 0;
      51             :     }
      52       42505 :     javaFrameworkError errcode = JFW_E_NONE;
      53       42505 :     sal_Bool bEnabled = sal_False;
      54       42505 :     errcode = jfw_getEnabled( & bEnabled);
      55       42505 :     if (errcode == JFW_E_NONE && bEnabled == sal_False)
      56             :     {
      57             :             //Do not do any preparation because that may only slow startup time.
      58           0 :         return 0;
      59             :     }
      60       42505 :     else if (errcode != JFW_E_NONE && errcode != JFW_E_DIRECT_MODE)
      61             :     {
      62           0 :         fprintf(stderr,"javaldx failed!\n");
      63           0 :         return -1;
      64             :     }
      65             : 
      66             : 
      67       42505 :     JavaInfo * pInfo = NULL;
      68       42505 :     errcode = jfw_getSelectedJRE( & pInfo);
      69             : 
      70       42505 :     if (errcode != JFW_E_NONE && errcode != JFW_E_INVALID_SETTINGS)
      71             :     {
      72           0 :         fprintf(stderr,"javaldx failed!\n");
      73           0 :         return -1;
      74             :     }
      75             : 
      76       42505 :     if (pInfo == NULL)
      77             :     {
      78           1 :         if (false == findAndSelect(&pInfo))
      79           0 :             return -1;
      80             :     }
      81             :     else
      82             :     {
      83             :         //check if the JRE was not uninstalled
      84       42504 :         sal_Bool bExist = sal_False;
      85       42504 :         errcode = jfw_existJRE(pInfo, &bExist);
      86       42504 :         if (errcode == JFW_E_NONE)
      87             :         {
      88       42504 :             if (!bExist && !findAndSelect(&pInfo))
      89           0 :                 return -1;
      90             :         }
      91             :         else
      92             :         {
      93           0 :             fprintf(stderr, "javaldx: Could not determine if JRE still exist\n");
      94           0 :             return -1;
      95             :         }
      96             :     }
      97             : 
      98       42505 :     OUString aVendor( pInfo->sVendor );
      99             :     // Only do something if the sunjavaplugin created this JavaInfo
     100      127515 :     if ( aVendor != "Sun Microsystems Inc." &&
     101       42505 :          aVendor != "Oracle Corporation" &&
     102           0 :          aVendor != "IBM Corporation" &&
     103           0 :          aVendor != "Blackdown Java-Linux Team" &&
     104           0 :          aVendor != "Apple Inc." &&
     105           0 :          aVendor != "Apple Computer, Inc." &&
     106           0 :          aVendor != "BEA Systems, Inc." &&
     107       42505 :          aVendor != "Free Software Foundation, Inc." &&
     108           0 :          aVendor != "The FreeBSD Foundation" )
     109             :     {
     110           0 :         jfw_freeJavaInfo(pInfo);
     111           0 :         return 0;
     112             :     }
     113             : 
     114       85010 :     OString sPaths = getLD_LIBRARY_PATH(pInfo->arVendorData);
     115       42505 :     fprintf(stdout, "%s\n", sPaths.getStr());
     116       42505 :     jfw_freeJavaInfo(pInfo);
     117             : 
     118       85010 :     return 0;
     119             : }
     120             : 
     121       42505 : OString getLD_LIBRARY_PATH(const rtl::ByteSequence & vendorData)
     122             : {
     123       42505 :     const sal_Unicode* chars = (sal_Unicode*) vendorData.getConstArray();
     124       42505 :     sal_Int32 len = vendorData.getLength();
     125       42505 :     OUString sData(chars, len / 2);
     126             :     //the runtime lib is on the first line
     127       42505 :     sal_Int32 index = 0;
     128       85010 :     OUString aToken = sData.getToken( 1, '\n', index);
     129             : 
     130             :     OString paths =
     131       42505 :         OUStringToOString(aToken, osl_getThreadTextEncoding());
     132       85010 :     return paths;
     133             : }
     134             : 
     135       85010 : static bool hasOption(char const * szOption, int argc, char** argv)
     136             : {
     137       85010 :     bool retVal= false;
     138      170034 :     for(sal_Int16 i= 1; i < argc; i++)
     139             :     {
     140       85024 :         if( ! strcmp(argv[i], szOption))
     141             :         {
     142           0 :             retVal= true;
     143           0 :             break;
     144             :         }
     145             :     }
     146       85010 :     return retVal;
     147             : }
     148             : 
     149           1 : static bool findAndSelect(JavaInfo ** ppInfo)
     150             : {
     151           1 :     javaFrameworkError errcode = jfw_findAndSelectJRE(ppInfo);
     152           1 :     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           1 :     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           1 :     return true;
     163             : }
     164             : 
     165             : 
     166             : 
     167             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10