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 .
19 package org
.openoffice
;
21 import helper
.ClParser
;
23 import java
.util
.ArrayList
;
24 import java
.util
.jar
.JarEntry
;
26 import lib
.TestParameters
;
27 import share
.LogWriter
;
28 import stats
.InternalLogWriter
;
29 import util
.DynamicClassLoader
;
30 import util
.PropertyName
;
33 import com
.sun
.star
.beans
.NamedValue
;
34 import com
.sun
.star
.beans
.PropertyValue
;
35 import com
.sun
.star
.beans
.XPropertyAccess
;
36 import com
.sun
.star
.comp
.loader
.FactoryHelper
;
37 import com
.sun
.star
.lang
.XMultiServiceFactory
;
38 import com
.sun
.star
.lang
.XServiceInfo
;
39 import com
.sun
.star
.lang
.XSingleServiceFactory
;
40 import com
.sun
.star
.lang
.XTypeProvider
;
41 import com
.sun
.star
.registry
.XRegistryKey
;
42 import com
.sun
.star
.task
.XJob
;
43 import com
.sun
.star
.uno
.Type
;
44 import com
.sun
.star
.uno
.XInterface
;
47 * The main class, will call ClParser and CfgParser to <br>
48 * fill the TestParameters.<br>
49 * Will then call the appropriate Testbase to run the tests.
51 public class RunnerService
implements XJob
, XServiceInfo
,
52 XTypeProvider
, XPropertyAccess
{
54 static public final String __serviceName
= "org.openoffice.Runner";
55 static public final String __implName
= "org.openoffice.RunnerService";
56 static private XMultiServiceFactory xMSF
= null;
58 public Object
execute(NamedValue
[] args
) {
59 // construct valid arguments from the given stuff
60 int arg_length
=args
.length
;
61 String
[] arguments
= new String
[arg_length
*2];
62 for ( int i
=0; i
< arg_length
; i
++ ) {
63 arguments
[i
*2] = args
[i
].Name
;
64 Object o
= args
[i
].Value
;
65 arguments
[i
*2+1] = o
.toString();
68 TestParameters param
= new TestParameters();
69 DynamicClassLoader dcl
= new DynamicClassLoader();
72 // take the standard log writer
73 String standardLogWriter
= (String
) param
.get(PropertyName
.LOG_WRITER
);
74 String standardOutProducer
= (String
) param
.get(PropertyName
.OUT_PRODUCER
);
76 ClParser cli
= new ClParser();
78 //parse the commandline arguments
79 cli
.getCommandLineParameter(param
,arguments
);
81 // now compare the standard log writer with the parameters:
82 // if we have a new one, use the new, else use the internal
84 if (((String
)param
.get("LogWriter")).equals(standardLogWriter
))
85 param
.put("LogWriter", "stats.InternalLogWriter");
86 if (((String
)param
.get("OutProducer")).equals(standardOutProducer
))
87 param
.put("OutProducer", "stats.InternalLogWriter");
88 LogWriter log
= (LogWriter
) dcl
.getInstance(
89 (String
)param
.get("LogWriter"));
91 param
.put("ServiceFactory", xMSF
);
93 log
.println("TestJob: "+param
.get("TestJob"));
95 TestBase toExecute
= (TestBase
)dcl
.getInstance("base.java_fat_service");
97 boolean worked
= toExecute
.executeTest(param
);
99 log
.println("Test did not execute correctly.");
101 String returnString
= "";
102 if (log
instanceof InternalLogWriter
)
103 returnString
= ((InternalLogWriter
)log
).getLog();
108 * This function provides the service name
109 * @return the service name
111 public String
getServiceName() {
112 return __serviceName
;
116 * Get all implemented types of this class.
117 * @return An array of implemented interface types.
118 * @see com.sun.star.lang.XTypeProvider
120 public Type
[] getTypes() {
121 Type
[] type
= new Type
[5];
122 type
[0] = new Type(XInterface
.class);
123 type
[1] = new Type(XTypeProvider
.class);
124 type
[2] = new Type(XJob
.class);
125 type
[3] = new Type(XServiceInfo
.class);
126 type
[4] = new Type(XPropertyAccess
.class);
131 * Get the implementation id.
132 * @return An empty implementation id.
133 * @see com.sun.star.lang.XTypeProvider
135 public byte[] getImplementationId() {
139 * Function for reading the implementation name.
141 * @return the implementation name
142 * @see com.sun.star.lang.XServiceInfo
144 public String
getImplementationName() {
149 * Does the implementation support this service?
151 * @param serviceName The name of the service in question
152 * @return true, if service is supported, false otherwise
153 * @see com.sun.star.lang.XServiceInfo
155 public boolean supportsService(String serviceName
) {
156 return serviceName
.equals(__serviceName
);
160 * Function for reading all supported services
162 * @return An aaray with all supported service names
163 * @see com.sun.star.lang.XServiceInfo
165 public String
[] getSupportedServiceNames() {
166 String
[] supServiceNames
= {__serviceName
};
167 return supServiceNames
;
171 * Return all valid testcases from the object descriptions
172 * @return The valid testcases as property values
174 public PropertyValue
[] getPropertyValues() {
175 PropertyValue
[] pVal
= null;
176 java
.net
.URL url
= this.getClass().getResource("/objdsc");
178 pVal
= new PropertyValue
[1];
179 pVal
[0] = new PropertyValue();
180 pVal
[0].Name
= "Error";
181 pVal
[0].Value
= "OOoRunner.jar file doesn't contain object " +
182 "descriptions: don't know what to test.";
186 ArrayList
<String
> v
= new ArrayList
<String
>(600);
188 // open connection to Jar
189 java
.net
.JarURLConnection con
=
190 (java
.net
.JarURLConnection
)url
.openConnection();
191 // get Jar file from connection
192 java
.util
.jar
.JarFile f
= con
.getJarFile();
193 // Enumerate over all entries
194 java
.util
.Enumeration
<JarEntry
> aEnum
= f
.entries();
196 while (aEnum
.hasMoreElements()) {
197 String entry
= aEnum
.nextElement().toString();
198 if (entry
.endsWith(".csv")) {
200 String module
= null;
201 String object
= null;
203 int startIndex
= entry
.indexOf("objdsc/") + 7;
204 int endIndex
= entry
.lastIndexOf('/');
205 module
= entry
.substring(startIndex
, endIndex
);
208 if (entry
.indexOf("/file/") != -1 || entry
.indexOf("/xmloff/") != -1) {
209 endIndex
= entry
.indexOf(".csv");
210 object
= entry
.substring(0, endIndex
);
211 endIndex
= object
.lastIndexOf('.');
212 startIndex
= object
.indexOf('.');
213 while (startIndex
!= endIndex
) {
214 object
= object
.substring(startIndex
+1);
215 startIndex
= object
.indexOf('.');
216 endIndex
= object
.lastIndexOf('.');
221 endIndex
= entry
.indexOf(".csv");
222 object
= entry
.substring(startIndex
, endIndex
);
223 startIndex
= object
.lastIndexOf('.');
224 object
= object
.substring(startIndex
+1);
226 v
.add(module
+"."+object
);
230 catch(java
.io
.IOException e
) {
236 String
[] sTestCases
= new String
[size
];
237 v
.toArray(sTestCases
);
238 java
.util
.Arrays
.sort(sTestCases
);
240 pVal
= new PropertyValue
[size
];
241 for (int i
=0; i
<size
; i
++) {
242 pVal
[i
] = new PropertyValue();
243 pVal
[i
].Name
= "TestCase"+i
;
244 pVal
[i
].Value
= sTestCases
[i
];
252 * Gives a factory for creating the service.
253 * This method is called by the <code>JavaLoader</code>
255 * @return returns a <code>XSingleServiceFactory</code> for creating the component
256 * @param implName the name of the implementation for which a service is desired
257 * @param multiFactory the service manager to be used if needed
258 * @param regKey the registryKey
259 * @see com.sun.star.comp.loader.JavaLoader
261 public static XSingleServiceFactory
__getServiceFactory(String implName
,
262 XMultiServiceFactory multiFactory
, XRegistryKey regKey
)
264 XSingleServiceFactory xSingleServiceFactory
= null;
266 if (implName
.equals(RunnerService
.class.getName()))
267 xSingleServiceFactory
= FactoryHelper
.getServiceFactory(
268 RunnerService
.class, __serviceName
, multiFactory
, regKey
);
270 return xSingleServiceFactory
;
274 * Writes the service information into the given registry key.
275 * This method is called by the <code>JavaLoader</code>
277 * @return returns true if the operation succeeded
278 * @param regKey the registryKey
279 * @see com.sun.star.comp.loader.JavaLoader
281 public static boolean __writeRegistryServiceInfo(XRegistryKey regKey
) {
282 return FactoryHelper
.writeRegistryServiceInfo(RunnerService
.class.getName(),
283 __serviceName
, regKey
);
287 * empty: not needed here.
289 public void setPropertyValues(PropertyValue
[] propertyValue
)
290 throws com
.sun
.star
.beans
.UnknownPropertyException
,
291 com
.sun
.star
.beans
.PropertyVetoException
,
292 com
.sun
.star
.lang
.IllegalArgumentException
,
293 com
.sun
.star
.lang
.WrappedTargetException
{
294 // empty implementation