LCOV - code coverage report
Current view: top level - jvmfwk/plugins/sunmajor/javaenvsetup - javaldx.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 32 58 55.2 %
Date: 2014-11-03 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         196 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
      46             : {
      47          98 :     if( hasOption("--help",argc, argv) || hasOption("-h", argc, argv))
      48             :     {
      49           0 :         fprintf(stdout, HELP_TEXT);// default
      50           0 :         return 0;
      51             :     }
      52          98 :     javaFrameworkError errcode = JFW_E_NONE;
      53          98 :     sal_Bool bEnabled = sal_False;
      54          98 :     errcode = jfw_getEnabled( & bEnabled);
      55          98 :     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          98 :     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          98 :     JavaInfo * pInfo = NULL;
      68             : 
      69             :     try
      70             :     {
      71          98 :         errcode = jfw_getSelectedJRE( & pInfo);
      72             :     }
      73           0 :     catch (const std::exception&)
      74             :     {
      75           0 :         fprintf(stderr,"javaldx failed!\n");
      76           0 :         return -1;
      77             :     }
      78             : 
      79          98 :     if (errcode != JFW_E_NONE && errcode != JFW_E_INVALID_SETTINGS)
      80             :     {
      81           0 :         fprintf(stderr,"javaldx failed!\n");
      82           0 :         return -1;
      83             :     }
      84             : 
      85          98 :     if (pInfo == NULL)
      86             :     {
      87           0 :         if (false == findAndSelect(&pInfo))
      88           0 :             return -1;
      89             :     }
      90             :     else
      91             :     {
      92             :         //check if the JRE was not uninstalled
      93          98 :         sal_Bool bExist = sal_False;
      94          98 :         errcode = jfw_existJRE(pInfo, &bExist);
      95          98 :         if (errcode == JFW_E_NONE)
      96             :         {
      97          98 :             if (!bExist && !findAndSelect(&pInfo))
      98           0 :                 return -1;
      99             :         }
     100             :         else
     101             :         {
     102           0 :             fprintf(stderr, "javaldx: Could not determine if JRE still exist\n");
     103           0 :             return -1;
     104             :         }
     105             :     }
     106             : 
     107          98 :     OString sPaths = getLD_LIBRARY_PATH(pInfo->arVendorData);
     108          98 :     fprintf(stdout, "%s\n", sPaths.getStr());
     109          98 :     jfw_freeJavaInfo(pInfo);
     110             : 
     111          98 :     return 0;
     112             : }
     113             : 
     114          98 : OString getLD_LIBRARY_PATH(const rtl::ByteSequence & vendorData)
     115             : {
     116          98 :     const sal_Unicode* chars = (sal_Unicode*) vendorData.getConstArray();
     117          98 :     sal_Int32 len = vendorData.getLength();
     118          98 :     OUString sData(chars, len / 2);
     119             :     //the runtime lib is on the first line
     120          98 :     sal_Int32 index = 0;
     121         196 :     OUString aToken = sData.getToken( 1, '\n', index);
     122             : 
     123             :     OString paths =
     124          98 :         OUStringToOString(aToken, osl_getThreadTextEncoding());
     125         196 :     return paths;
     126             : }
     127             : 
     128         196 : static bool hasOption(char const * szOption, int argc, char** argv)
     129             : {
     130         196 :     bool retVal= false;
     131         792 :     for(sal_Int16 i= 1; i < argc; i++)
     132             :     {
     133         596 :         if( ! strcmp(argv[i], szOption))
     134             :         {
     135           0 :             retVal= true;
     136           0 :             break;
     137             :         }
     138             :     }
     139         196 :     return retVal;
     140             : }
     141             : 
     142           0 : static bool findAndSelect(JavaInfo ** ppInfo)
     143             : {
     144           0 :     javaFrameworkError errcode = jfw_findAndSelectJRE(ppInfo);
     145           0 :     if (errcode == JFW_E_NO_JAVA_FOUND)
     146             :     {
     147           0 :         fprintf(stderr,"javaldx: Could not find a Java Runtime Environment!\n");
     148           0 :         return false;
     149             :     }
     150           0 :     else if (errcode != JFW_E_NONE && errcode != JFW_E_DIRECT_MODE)
     151             :     {
     152           0 :         fprintf(stderr,"javaldx failed!\n");
     153           0 :         return false;
     154             :     }
     155           0 :     return true;
     156             : }
     157             : 
     158             : 
     159             : 
     160             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10