bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / runner / helper / UnoProvider.java
blobe3628de63a0a9cdbfb6c1841217ccb7a3484894d
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 public UnoProvider(){
56 /**
57 * Close existing office: calls disposeManager()
58 * @param param The test parameters.
59 * @param closeIfPossible Not needed, since UNO is bootstrapped by this
60 * class in every case.
61 * @return True, if bootstrapping worked.
63 public boolean closeExistingOffice(TestParameters param,
64 boolean closeIfPossible) {
65 return disposeManager(param);
68 /**
69 * Dispose the UNO environment: just clears the bootstrapped
70 * MultiServiceFactory
71 * @param param The test parameters.
72 * @return True, if bootstrapping worked.
74 public boolean disposeManager(TestParameters param) {
75 param.remove("ServiceManager");
76 System.gc();
77 try {
78 Thread.sleep(1000);
80 catch(java.lang.InterruptedException e) {}
81 return true;
84 /**
85 * Bootstrap UNO and return the created MultiServiceFactory.
86 * @param param The test parameters.
87 * @return A created MultiServiceFactory.
89 public Object getManager(TestParameters param) {
90 XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF();
91 if (xMSF == null) {
92 // bootstrap UNO.
93 String unorcName = getUnorcName(param);
94 HashMap<String,String> env = new HashMap<String,String>();
95 env.put("SYSBINDIR", getSysBinDir(param));
97 XComponentContext xContext = null;
98 try {
99 xContext = Bootstrap.defaultBootstrap_InitialComponentContext(
100 unorcName, env);
102 catch(Exception e) {
103 e.printStackTrace();
104 System.out.println("Could not get XComponentContext. Maybe you must add program folder to LD_LIBRARY_PATH");
105 return null;
107 XMultiComponentFactory xMCF = xContext.getServiceManager();
108 xMSF = UnoRuntime.queryInterface(
109 XMultiServiceFactory.class, xMCF);
111 return xMSF;
114 private String getUnorcName(TestParameters param) {
115 String unorcName = (String)param.get("UNORC");
116 if (unorcName == null) {
117 String office = (String)param.get("AppExecutionCommand");
118 // determine unorc name: unorc or uno.ini on windows
119 String opSystem = (String)param.get(PropertyName.OPERATING_SYSTEM);
120 if ( opSystem != null && opSystem.equalsIgnoreCase(PropertyName.WNTMSCI)) {
121 unorcName = "uno.ini";
123 else {
124 unorcName = "unorc";
126 if (office == null)
127 return null;
128 // use '/', because this will be a URL in any case.
129 unorcName = office.substring(0, office.indexOf("program")+7) +
130 "/" + unorcName;
132 unorcName = utils.getFullURL(unorcName);
133 if (param.DebugIsActive) {
134 System.out.println("UnoUcr: " + unorcName);
136 return unorcName;
139 private String getSysBinDir(TestParameters param) {
140 String base = (String)param.get("AppExecutionCommand");
141 if (base == null)
142 base = (String)param.get("UNORC");
144 if (base == null)
145 return null;
147 String sysbindir = base.substring(0,
148 base.indexOf("program")+7);
150 sysbindir = utils.getFullURL(sysbindir);
151 if (param.DebugIsActive) {
152 System.out.println("SysBinDir: " + sysbindir);
154 return sysbindir;