1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import java
.io
.PrintWriter
;
31 import lib
.TestParameters
;
32 import share
.LogWriter
;
36 * This class support you to execute some shell commands in a buld environment. At ervery call of commands
37 * a build environment was created and the commands will be executed.
40 public class BuildEnvTools
{
42 private final TestParameters param
;
43 private final LogWriter log
;
44 private final boolean mDebug
;
45 private final String mPlatform
;
46 private final String mShell
;
47 private boolean mCygwin
;
50 * This constructor creates an instance of BuildEncTools. It is verifying for all neccesarry
51 * parameters in <CODE>TestParameters</CODE> This must be:
53 * <li>OperatingSystem: Fill this parameter with an operating system like unxsols, unxsoli, unxlngi or wntmsci.
55 * <li> Shell: Fill this parameter with a shell f.e '/bin/tcsh'
56 * or 'c:\\myShell\\myShell.exe'
60 * @throws helper.ParameterNotFoundException
62 public BuildEnvTools(TestParameters param
, LogWriter log
) throws ParameterNotFoundException
{
65 mDebug
= param
.getBool(PropertyName
.DEBUG_IS_ACTIVE
);
67 boolean error
= false;
69 String msg
= "\nERROR: the following parameter must be set before executing the test:\n\n";
71 mPlatform
= (String
) param
.get(PropertyName
.OPERATING_SYSTEM
);
73 log
.println("### " + mPlatform
);
75 if (mPlatform
== null){
76 msg
+= PropertyName
.OPERATING_SYSTEM
+ "\nFill this parameter with an operating system like unxsols," +
77 " unxsoli, unxlngi, unxmacxi or wntmsci. \n\n";
80 (!mPlatform
.equalsIgnoreCase(PropertyName
.UNXSOLS
)) &&
81 (!mPlatform
.equalsIgnoreCase(PropertyName
.UNXSOLI
)) &&
82 (!mPlatform
.equalsIgnoreCase(PropertyName
.UNXLNGI
)) &&
83 (!mPlatform
.equalsIgnoreCase(PropertyName
.UNXMACXI
))&&
84 (!mPlatform
.equalsIgnoreCase(PropertyName
.WNTMSCI
)) ){
86 msg
+= PropertyName
.OPERATING_SYSTEM
+ ":" + mPlatform
+ "\nFill this parameter with an operating system like unxsols," +
87 " unxsoli, unxlngi, unxmacxi or wntmsci. \n\n";
91 mShell
= (String
) param
.get(PropertyName
.SHELL
);
93 msg
+= PropertyName
.SHELL
+ "\nFill this parameter with a shell" +
94 "\n\t/bin/tcsh c:\\myShell\\myShell.exe\n\n";
98 mCygwin
= (param
.getBool(PropertyName
.CYGWIN
));
101 throw new ParameterNotFoundException(msg
);
106 * Executes the given commands in OOo-Environment shell.
110 * @return the processHandler of the commands
111 * @see helper.ProcessHandler
113 public ProcessHandler
runCommandsInEnvironmentShell(String
[] commands
, File workDir
, int shortWait
) {
115 final String
[] cmdLines
= getCmdLinesWithCommand(commands
);
116 final ProcessHandler pHdl
= new ProcessHandler(cmdLines
, (PrintWriter
) log
, workDir
, shortWait
, param
);
121 public String
getSrcRoot() {
123 String sSrcRoot
= (String
) param
.get(PropertyName
.SRC_ROOT
);
125 if (sSrcRoot
== null) {
126 String
[] cmdLines
= null;
127 if (mPlatform
.equals(PropertyName
.WNTMSCI
) && ! mCygwin
) {
128 cmdLines
= new String
[]{mShell
, "/C", "echo SRC_ROOT=%SRC_ROOT"};
130 cmdLines
= new String
[]{mShell
, "--login ", "-c ", "echo \"SRC_ROOT=$SRC_ROOT\""};
133 final ProcessHandler procHdl
= new ProcessHandler(cmdLines
, (PrintWriter
) log
, null, 5000, param
);
134 procHdl
.runCommand();
137 log
.println("---> Output of command:");
138 log
.println(procHdl
.getOutputText());
139 log
.println("<--- Output of command:");
140 log
.println("---> Error output of command");
141 log
.println(procHdl
.getErrorText());
142 log
.println("<--- Error output of command");
144 final String output
= procHdl
.getOutputText();
145 final String
[] outs
= output
.split("\n");
147 for (int i
= 0; i
< outs
.length
; i
++) {
148 final String line
= outs
[i
];
149 if (line
.startsWith("SRC_ROOT")) {
150 sSrcRoot
= getEnvValue(line
);
157 private String
[] getCmdLinesWithCommand(String
[] commands
) {
158 String
[] cmdLines
= null;
159 log
.println("prepare command for platform " + mPlatform
);
161 String seperator
= "";
162 if (mPlatform
.equals(PropertyName
.WNTMSCI
)) {
163 seperator
= mCygwin ?
";" : "^";
169 for (int i
= 0; i
< commands
.length
; i
++) {
171 command
+= seperator
;
173 command
+= commands
[i
];
176 if (mPlatform
.equals(PropertyName
.WNTMSCI
)){
178 String srcRoot
= (String
) param
.get(PropertyName
.SRC_ROOT
);
179 String envSet
= "export cyg_src_root=`cygpath '" + srcRoot
.replaceAll("\\\\", "\\\\\\\\")+ "'`; source $cyg_src_root/winenv.set.sh;";
180 command
= envSet
+ command
;
181 cmdLines
= new String
[]{mShell
, "--login", "-c", "\"" + command
+ "\""};
183 cmdLines
= new String
[]{mShell
, "/C", "\"" + command
+ "\""};
186 cmdLines
= new String
[]{mShell
, "-c", command
};
191 private String
getEnvValue(String line
) {
192 final String
[] split
= line
.split("=");