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 .
21 import java
.io
.PrintWriter
;
22 import lib
.TestParameters
;
23 import share
.LogWriter
;
27 * This class support you to execute some shell commands in a buld environment. At ervery call of commands
28 * a build environment was created and the commands will be executed.
31 public class BuildEnvTools
{
33 private final TestParameters param
;
34 private final LogWriter log
;
35 private final boolean mDebug
;
36 private final String mPlatform
;
37 private final String mShell
;
38 private boolean mCygwin
;
41 * This constructor creates an instance of BuildEncTools. It is verifying for all neccesarry
42 * parameters in <CODE>TestParameters</CODE> This must be:
44 * <li>OperatingSystem: Fill this parameter with an operating system like unxsols, unxsoli, unxlngi or wntmsci.
46 * <li> Shell: Fill this parameter with a shell f.e '/bin/tcsh'
47 * or 'c:\\myShell\\myShell.exe'
51 * @throws helper.ParameterNotFoundException
53 public BuildEnvTools(TestParameters param
, LogWriter log
) throws ParameterNotFoundException
{
56 mDebug
= param
.getBool(PropertyName
.DEBUG_IS_ACTIVE
);
58 boolean error
= false;
60 String msg
= "\nERROR: the following parameter must be set before executing the test:\n\n";
62 mPlatform
= (String
) param
.get(PropertyName
.OPERATING_SYSTEM
);
64 log
.println("### " + mPlatform
);
66 if (mPlatform
== null){
67 msg
+= PropertyName
.OPERATING_SYSTEM
+ "\nFill this parameter with an operating system like unxsols," +
68 " unxsoli, unxlngi, unxmacxi or wntmsci. \n\n";
71 (!mPlatform
.equalsIgnoreCase(PropertyName
.UNXSOLS
)) &&
72 (!mPlatform
.equalsIgnoreCase(PropertyName
.UNXSOLI
)) &&
73 (!mPlatform
.equalsIgnoreCase(PropertyName
.UNXLNGI
)) &&
74 (!mPlatform
.equalsIgnoreCase(PropertyName
.UNXMACXI
))&&
75 (!mPlatform
.equalsIgnoreCase(PropertyName
.WNTMSCI
)) ){
77 msg
+= PropertyName
.OPERATING_SYSTEM
+ ":" + mPlatform
+ "\nFill this parameter with an operating system like unxsols," +
78 " unxsoli, unxlngi, unxmacxi or wntmsci. \n\n";
82 mShell
= (String
) param
.get(PropertyName
.SHELL
);
84 msg
+= PropertyName
.SHELL
+ "\nFill this parameter with a shell" +
85 "\n\t/bin/tcsh c:\\myShell\\myShell.exe\n\n";
89 mCygwin
= (param
.getBool(PropertyName
.CYGWIN
));
92 throw new ParameterNotFoundException(msg
);
97 * Executes the given commands in OOo-Environment shell.
101 * @return the processHandler of the commands
102 * @see helper.ProcessHandler
104 public ProcessHandler
runCommandsInEnvironmentShell(String
[] commands
, File workDir
, int shortWait
) {
106 final String
[] cmdLines
= getCmdLinesWithCommand(commands
);
107 final ProcessHandler pHdl
= new ProcessHandler(cmdLines
, (PrintWriter
) log
, workDir
, shortWait
, param
);
112 public String
getSrcRoot() {
114 String sSrcRoot
= (String
) param
.get(PropertyName
.SRC_ROOT
);
116 if (sSrcRoot
== null) {
117 String
[] cmdLines
= null;
118 if (mPlatform
.equals(PropertyName
.WNTMSCI
) && ! mCygwin
) {
119 cmdLines
= new String
[]{mShell
, "/C", "echo SRC_ROOT=%SRC_ROOT"};
121 cmdLines
= new String
[]{mShell
, "--login ", "-c ", "echo \"SRC_ROOT=$SRC_ROOT\""};
124 final ProcessHandler procHdl
= new ProcessHandler(cmdLines
, (PrintWriter
) log
, null, 5000, param
);
125 procHdl
.runCommand();
128 log
.println("---> Output of command:");
129 log
.println(procHdl
.getOutputText());
130 log
.println("<--- Output of command:");
131 log
.println("---> Error output of command");
132 log
.println(procHdl
.getErrorText());
133 log
.println("<--- Error output of command");
135 final String output
= procHdl
.getOutputText();
136 final String
[] outs
= output
.split("\n");
138 for (int i
= 0; i
< outs
.length
; i
++) {
139 final String line
= outs
[i
];
140 if (line
.startsWith("SRC_ROOT")) {
141 sSrcRoot
= getEnvValue(line
);
148 private String
[] getCmdLinesWithCommand(String
[] commands
) {
149 String
[] cmdLines
= null;
150 log
.println("prepare command for platform " + mPlatform
);
152 String separator
= "";
153 if (mPlatform
.equals(PropertyName
.WNTMSCI
)) {
154 separator
= mCygwin ?
";" : "^";
160 for (int i
= 0; i
< commands
.length
; i
++) {
162 command
+= separator
;
164 command
+= commands
[i
];
167 if (mPlatform
.equals(PropertyName
.WNTMSCI
)){
169 String srcRoot
= (String
) param
.get(PropertyName
.SRC_ROOT
);
170 String envSet
= "export cyg_src_root=`cygpath '" + srcRoot
.replaceAll("\\\\", "\\\\\\\\")+ "'`; source $cyg_src_root/winenv.set.sh;";
171 command
= envSet
+ command
;
172 cmdLines
= new String
[]{mShell
, "--login", "-c", "\"" + command
+ "\""};
174 cmdLines
= new String
[]{mShell
, "/C", "\"" + command
+ "\""};
177 cmdLines
= new String
[]{mShell
, "-c", command
};
182 private String
getEnvValue(String line
) {
183 final String
[] split
= line
.split("=");