| 1 |
/* |
| 2 |
* This file is part of the LibreOffice project. |
| 3 |
* |
| 4 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 5 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 7 |
* |
| 8 |
* This file incorporates work covered by the following license notice: |
| 9 |
* |
| 10 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 11 |
* contributor license agreements. See the NOTICE file distributed |
| 12 |
* with this work for additional information regarding copyright |
| 13 |
* ownership. The ASF licenses this file to you under the Apache |
| 14 |
* License, Version 2.0 (the "License"); you may not use this file |
| 15 |
* except in compliance with the License. You may obtain a copy of |
| 16 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 17 |
*/ |
| 18 |
|
| 19 |
package com.sun.star.comp.helper; |
| 20 |
|
| 21 |
import com.sun.star.uno.UnoRuntime; |
| 22 |
import com.sun.star.uno.AnyConverter; |
| 23 |
|
| 24 |
import com.sun.star.uno.XComponentContext; |
| 25 |
import com.sun.star.lang.XComponent; |
| 26 |
import com.sun.star.lang.XMultiServiceFactory; |
| 27 |
|
| 28 |
import java.util.logging.Logger; |
| 29 |
import java.util.logging.Level; |
| 30 |
import java.util.Map; |
| 31 |
|
| 32 |
public class Bootstrap_Test { |
| 33 |
|
| 34 |
private static final Logger logger = Logger.getLogger(Bootstrap_Test.class.getName()); |
| 35 |
|
| 36 |
public static boolean test( String ini_file, Map<String,String> bootstrap_parameters ) |
| 37 |
throws java.lang.Exception |
| 38 |
{ |
| 39 |
boolean passed = false; |
| 40 |
logger.log(Level.INFO, "Bootstrap - doing tests..."); |
| 41 |
|
| 42 |
try { |
| 43 |
XComponentContext xContext = |
| 44 |
com.sun.star.comp.helper.Bootstrap.defaultBootstrap_InitialComponentContext( |
| 45 |
ini_file, bootstrap_parameters ); |
| 46 |
|
| 47 |
if (AnyConverter.isVoid( |
| 48 |
xContext.getValueByName( |
| 49 |
"/singletons/com.sun.star.reflection.theTypeDescriptionManager" ) )) |
| 50 |
{ |
| 51 |
throw new Exception( |
| 52 |
"no /singletons/com.sun.star.reflection.theTypeDescriptionManager!" ); |
| 53 |
} |
| 54 |
|
| 55 |
XMultiServiceFactory msf = UnoRuntime.queryInterface( |
| 56 |
XMultiServiceFactory.class, xContext.getServiceManager() ); |
| 57 |
String services[] = msf.getAvailableServiceNames(); |
| 58 |
logger.log(Level.FINE, "Available services are:"); |
| 59 |
if (services.length == 0) |
| 60 |
logger.log(Level.FINE, "No services available!"); |
| 61 |
|
| 62 |
else |
| 63 |
for ( int i=0; i<services.length; i++ ) |
| 64 |
logger.log(Level.FINE, services[i]); |
| 65 |
|
| 66 |
XComponent xComp = UnoRuntime.queryInterface( |
| 67 |
XComponent.class, xContext ); |
| 68 |
xComp.dispose(); |
| 69 |
|
| 70 |
passed = true; |
| 71 |
} |
| 72 |
catch (Exception e) { |
| 73 |
e.printStackTrace(); |
| 74 |
} |
| 75 |
logger.log(Level.INFO, "Bootstrap test passed? " + passed); |
| 76 |
return passed; |
| 77 |
} |
| 78 |
|
| 79 |
private static void usage() { |
| 80 |
System.out.println(); |
| 81 |
System.out.println("usage:"); |
| 82 |
System.out.println("java com.sun.star.comp.helper.Bootstrap_Test ini-file name=value ..."); |
| 83 |
System.out.println("example:"); |
| 84 |
System.out.println("java com.sun.star.comp.helper.Bootstrap_Test file:///c:/ooo10/program/uno.ini SYSBINDIR=file:///c:/ooo10/program"); |
| 85 |
System.exit( -1 ); |
| 86 |
} |
| 87 |
|
| 88 |
public static void main(String args[]) throws java.lang.Exception { |
| 89 |
if ( args.length == 0 ) |
| 90 |
usage(); |
| 91 |
|
| 92 |
java.util.HashMap<String,String> bootstrap_parameters = new java.util.HashMap<String,String>(); |
| 93 |
for ( int nPos = 1; nPos < args.length; ++nPos ) { |
| 94 |
if (args[nPos].contains("=")) { |
| 95 |
String bootstrap_parameter[] = args[nPos].split("=",2); |
| 96 |
if (bootstrap_parameter[0].length() > 0) { |
| 97 |
bootstrap_parameters.put( bootstrap_parameter[0], bootstrap_parameter[1] ); |
| 98 |
} else { |
| 99 |
System.out.println(); |
| 100 |
System.out.println("The 1st argument in a bootstrap parameter is the key of a HashMap element and can't be null : '" + args[nPos] + "'"); |
| 101 |
usage(); |
| 102 |
} |
| 103 |
} else { |
| 104 |
System.out.println(); |
| 105 |
System.out.println("Missing '=' in bootstrap parameter : '" + args[nPos] + "'"); |
| 106 |
usage(); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
System.exit( test(args[0], bootstrap_parameters) ? 0: -1 ); |
| 111 |
} |
| 112 |
} |
| 113 |
|