xref: /AOO41X/main/qadevOOo/runner/helper/CwsDataExchangeImpl.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*
2  *************************************************************************
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org.  If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 package helper;
29 
30 import java.io.FileWriter;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import lib.TestParameters;
34 import share.CwsDataExchange;
35 import share.LogWriter;
36 import util.PropertyName;
37 import util.utils;
38 
39 /**
40  * Implementaion of the interface CwsDataExchange
41  * @see share.CwsDataExchange
42  */
43 public class CwsDataExchangeImpl implements CwsDataExchange
44 {
45 
46     private final String cwsName;
47     private final TestParameters param;
48     private final LogWriter log;
49     private final BuildEnvTools bet;
50     private final boolean mDebug;
51 
52     public CwsDataExchangeImpl(String cwsName, TestParameters param, LogWriter log) throws ParameterNotFoundException
53     {
54         this.cwsName = cwsName;
55         this.param = param;
56         this.log = log;
57         this.bet = new BuildEnvTools(param, log);
58         mDebug = param.getBool(PropertyName.DEBUG_IS_ACTIVE);
59     }
60 
61     public ArrayList getModules()
62     {
63         // the cwstouched command send its version information to StdErr.
64         // A piping from StdErr to SdtOut the tcsh does not support.
65         // To find the output easily the echo command is used
66         final String[] commands =
67         {
68             "echo cwstouched starts here",
69             "cwstouched",
70             "echo cwstouched ends here"
71         };
72 
73         final ProcessHandler procHdl = bet.runCommandsInEnvironmentShell(commands, null, 20000);
74 
75         if (mDebug)
76         {
77             log.println("---> Output of getModules:");
78             log.println(procHdl.getOutputText());
79             log.println("<--- Output of getModules");
80             log.println("---> Error output of getModules");
81             log.println(procHdl.getErrorText());
82             log.println("<--- Error output of getModules");
83         }
84 
85         final String[] outs = procHdl.getOutputText().split("\n");
86 
87         final ArrayList<String> moduleNames = new ArrayList<String>();
88         boolean bStart = false;
89         for (int i = 0; i < outs.length; i++)
90         {
91             final String line = outs[i];
92             if (line.startsWith("cwstouched starts here"))
93             {
94                 bStart = true;
95                 continue;
96             }
97             if (line.startsWith("cwstouched ends here"))
98             {
99                 bStart = false;
100                 continue;
101             }
102             if (bStart && line.length() > 1)
103             {
104                 moduleNames.add(line);
105             }
106         }
107 
108         return moduleNames;
109     }
110 
111     public void setUnoApiCwsStatus(boolean status)
112     {
113 
114         FileWriter out = null;
115         String statusFile = null;
116         try
117         {
118 
119             final String stat = status ? ".PASSED.OK" : ".PASSED.FAILED";
120 
121             statusFile = utils.getUsersTempDir() +
122                     System.getProperty("file.separator") +
123                     "UnoApiCwsStatus." +
124                     (String) param.get(PropertyName.VERSION) +
125                     "_" + param.get(PropertyName.OPERATING_SYSTEM) + stat + ".txt";
126 
127             out = new FileWriter(statusFile);
128 
129             out.write(stat);
130             out.flush();
131             out.close();
132 
133             final String[] commands =
134             {
135                 "cwsattach " + statusFile
136             };
137 
138             bet.runCommandsInEnvironmentShell(commands, null, 5000);
139 
140         }
141         catch (IOException ex)
142         {
143             System.out.println("ERROR: could not attach file '" + statusFile + "' to cws\n" + ex.toString());
144         }
145         finally
146         {
147             try
148             {
149                 out.close();
150             }
151             catch (IOException ex)
152             {
153                 ex.printStackTrace();
154             }
155         }
156     }
157 }
158