LCOV - code coverage report
Current view: top level - jvmfwk/plugins/sunmajor/javaenvsetup - javaldx.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 36 67 53.7 %
Date: 2014-04-11 Functions: 4 5 80.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          98 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
      46             : {
      47          49 :     if( hasOption("--help",argc, argv) || hasOption("-h", argc, argv))
      48             :     {
      49           0 :         fprintf(stdout, HELP_TEXT);// default
      50           0 :         return 0;
      51             :     }
      52          49 :     javaFrameworkError errcode = JFW_E_NONE;
      53          49 :     sal_Bool bEnabled = sal_False;
      54          49 :     errcode = jfw_getEnabled( & bEnabled);
      55          49 :     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          49 :     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          49 :     JavaInfo * pInfo = NULL;
      68          49 :     errcode = jfw_getSelectedJRE( & pInfo);
      69             : 
      70          49 :     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          49 :     if (pInfo == NULL)
      77             :     {
      78           0 :         if (false == findAndSelect(&pInfo))
      79           0 :             return -1;
      80             :     }
      81             :     else
      82             :     {
      83             :         //check if the JRE was not uninstalled
      84          49 :         sal_Bool bExist = sal_False;
      85          49 :         errcode = jfw_existJRE(pInfo, &bExist);
      86          49 :         if (errcode == JFW_E_NONE)
      87             :         {
      88          49 :             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          49 :     OUString aVendor( pInfo->sVendor );
      99             :     // Only do something if the sunjavaplugin created this JavaInfo
     100         147 :     if ( aVendor != "Sun Microsystems Inc." &&
     101          49 :          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          49 :          aVendor != "Free Software Foundation, Inc." &&
     108           0 :          aVendor != "The FreeBSD Foundation" )
     109             :     {
     110           0 :         jfw_freeJavaInfo(pInfo);
     111           0 :         return 0;
     112             :     }
     113             : 
     114          98 :     OString sPaths = getLD_LIBRARY_PATH(pInfo->arVendorData);
     115          49 :     fprintf(stdout, "%s\n", sPaths.getStr());
     116          49 :     jfw_freeJavaInfo(pInfo);
     117             : 
     118          98 :     return 0;
     119             : }
     120             : 
     121          49 : OString getLD_LIBRARY_PATH(const rtl::ByteSequence & vendorData)
     122             : {
     123          49 :     const sal_Unicode* chars = (sal_Unicode*) vendorData.getConstArray();
     124          49 :     sal_Int32 len = vendorData.getLength();
     125          49 :     OUString sData(chars, len / 2);
     126             :     //the runtime lib is on the first line
     127          49 :     sal_Int32 index = 0;
     128          98 :     OUString aToken = sData.getToken( 1, '\n', index);
     129             : 
     130             :     OString paths =
     131          49 :         OUStringToOString(aToken, osl_getThreadTextEncoding());
     132          98 :     return paths;
     133             : }
     134             : 
     135          98 : static bool hasOption(char const * szOption, int argc, char** argv)
     136             : {
     137          98 :     bool retVal= false;
     138         396 :     for(sal_Int16 i= 1; i < argc; i++)
     139             :     {
     140         298 :         if( ! strcmp(argv[i], szOption))
     141             :         {
     142           0 :             retVal= true;
     143           0 :             break;
     144             :         }
     145             :     }
     146          98 :     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