bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / runner / helper / UnoProvider.java
blobd5d18c38fb72cc82d9c01f3a9afc32262b6c4e88
1 /*
2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
18 package helper;
20 import java.util.HashMap;
22 import lib.TestParameters;
23 import util.PropertyName;
24 import util.utils;
26 import com.sun.star.comp.helper.Bootstrap;
27 import com.sun.star.lang.XMultiComponentFactory;
28 import com.sun.star.lang.XMultiServiceFactory;
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.uno.XComponentContext;
32 /**
33 * Bootstrap UNO from a Java environment.
34 * Needed parameters:
35 * <ol>
36 * <li>
37 * <ul>
38 * <li>UNORC - complete path to the unorc file</li>
39 * </ul>
40 * </li>
41 * <li>
42 * <ul>
43 * <li>AppExecutionCommand - path to the soffice executable</li>
44 * <li>OS - the operating system in case it's Windows, because the
45 * unorc is called uno.ini</li>
46 * </ul>
47 * </li>
48 * </ol>
50 public class UnoProvider implements AppProvider {
52 /**
53 * Close existing office: calls disposeManager()
54 * @param param The test parameters.
55 * @param closeIfPossible Not needed, since UNO is bootstrapped by this
56 * class in every case.
57 * @return True, if bootstrapping worked.
59 public boolean closeExistingOffice(TestParameters param,
60 boolean closeIfPossible) {
61 return disposeManager(param);
64 /**
65 * Dispose the UNO environment: just clears the bootstrapped
66 * MultiServiceFactory
67 * @param param The test parameters.
68 * @return True, if bootstrapping worked.
70 public boolean disposeManager(TestParameters param) {
71 param.remove("ServiceManager");
72 System.gc();
73 util.utils.pause(1000);
74 return true;
77 /**
78 * Bootstrap UNO and return the created MultiServiceFactory.
79 * @param param The test parameters.
80 * @return A created MultiServiceFactory.
82 public Object getManager(TestParameters param) {
83 XMultiServiceFactory xMSF = param.getMSF();
84 if (xMSF == null) {
85 // bootstrap UNO.
86 String unorcName = getUnorcName(param);
87 HashMap<String,String> env = new HashMap<String,String>();
88 env.put("SYSBINDIR", getSysBinDir(param));
90 XComponentContext xContext = null;
91 try {
92 xContext = Bootstrap.defaultBootstrap_InitialComponentContext(
93 unorcName, env);
95 catch(Exception e) {
96 e.printStackTrace();
97 System.out.println("Could not get XComponentContext. Maybe you must add program folder to LD_LIBRARY_PATH");
98 return null;
100 XMultiComponentFactory xMCF = xContext.getServiceManager();
101 xMSF = UnoRuntime.queryInterface(
102 XMultiServiceFactory.class, xMCF);
104 return xMSF;
107 private String getUnorcName(TestParameters param) {
108 String unorcName = (String)param.get("UNORC");
109 if (unorcName == null) {
110 String office = (String)param.get("AppExecutionCommand");
111 // determine unorc name: unorc or uno.ini on windows
112 String opSystem = (String)param.get(PropertyName.OPERATING_SYSTEM);
113 if ( opSystem != null && opSystem.equalsIgnoreCase(PropertyName.WNTMSCI)) {
114 unorcName = "uno.ini";
116 else {
117 unorcName = "unorc";
119 if (office == null)
120 return null;
121 // use '/', because this will be a URL in any case.
122 unorcName = office.substring(0, office.indexOf("program")+7) +
123 "/" + unorcName;
125 unorcName = utils.getFullURL(unorcName);
126 if (param.getBool(PropertyName.DEBUG_IS_ACTIVE)) {
127 System.out.println("UnoUcr: " + unorcName);
129 return unorcName;
132 private String getSysBinDir(TestParameters param) {
133 String base = (String)param.get("AppExecutionCommand");
134 if (base == null)
135 base = (String)param.get("UNORC");
137 if (base == null)
138 return null;
140 String sysbindir = base.substring(0,
141 base.indexOf("program")+7);
143 sysbindir = utils.getFullURL(sysbindir);
144 if (param.getBool(PropertyName.DEBUG_IS_ACTIVE)) {
145 System.out.println("SysBinDir: " + sysbindir);
147 return sysbindir;