1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package helper;
24 
25 import java.io.FileWriter;
26 import java.io.IOException;
27 import java.util.ArrayList;
28 import lib.TestParameters;
29 import share.CwsDataExchange;
30 import share.LogWriter;
31 import util.PropertyName;
32 import util.utils;
33 
34 /**
35  * Implementaion of the interface CwsDataExchange
36  * @see share.CwsDataExchange
37  */
38 public class CwsDataExchangeImpl implements CwsDataExchange
39 {
40 
41     private final String cwsName;
42     private final TestParameters param;
43     private final LogWriter log;
44     private final BuildEnvTools bet;
45     private final boolean mDebug;
46 
CwsDataExchangeImpl(String cwsName, TestParameters param, LogWriter log)47     public CwsDataExchangeImpl(String cwsName, TestParameters param, LogWriter log) throws ParameterNotFoundException
48     {
49         this.cwsName = cwsName;
50         this.param = param;
51         this.log = log;
52         this.bet = new BuildEnvTools(param, log);
53         mDebug = param.getBool(PropertyName.DEBUG_IS_ACTIVE);
54     }
55 
getModules()56     public ArrayList getModules()
57     {
58         // the cwstouched command send its version information to StdErr.
59         // A piping from StdErr to SdtOut the tcsh does not support.
60         // To find the output easily the echo command is used
61         final String[] commands =
62         {
63             "echo cwstouched starts here",
64             "cwstouched",
65             "echo cwstouched ends here"
66         };
67 
68         final ProcessHandler procHdl = bet.runCommandsInEnvironmentShell(commands, null, 20000);
69 
70         if (mDebug)
71         {
72             log.println("---> Output of getModules:");
73             log.println(procHdl.getOutputText());
74             log.println("<--- Output of getModules");
75             log.println("---> Error output of getModules");
76             log.println(procHdl.getErrorText());
77             log.println("<--- Error output of getModules");
78         }
79 
80         final String[] outs = procHdl.getOutputText().split("\n");
81 
82         final ArrayList<String> moduleNames = new ArrayList<String>();
83         boolean bStart = false;
84         for (int i = 0; i < outs.length; i++)
85         {
86             final String line = outs[i];
87             if (line.startsWith("cwstouched starts here"))
88             {
89                 bStart = true;
90                 continue;
91             }
92             if (line.startsWith("cwstouched ends here"))
93             {
94                 bStart = false;
95                 continue;
96             }
97             if (bStart && line.length() > 1)
98             {
99                 moduleNames.add(line);
100             }
101         }
102 
103         return moduleNames;
104     }
105 
setUnoApiCwsStatus(boolean status)106     public void setUnoApiCwsStatus(boolean status)
107     {
108 
109         FileWriter out = null;
110         String statusFile = null;
111         try
112         {
113 
114             final String stat = status ? ".PASSED.OK" : ".PASSED.FAILED";
115 
116             statusFile = utils.getUsersTempDir() +
117                     System.getProperty("file.separator") +
118                     "UnoApiCwsStatus." +
119                     (String) param.get(PropertyName.VERSION) +
120                     "_" + param.get(PropertyName.OPERATING_SYSTEM) + stat + ".txt";
121 
122             out = new FileWriter(statusFile);
123 
124             out.write(stat);
125             out.flush();
126             out.close();
127 
128             final String[] commands =
129             {
130                 "cwsattach " + statusFile
131             };
132 
133             bet.runCommandsInEnvironmentShell(commands, null, 5000);
134 
135         }
136         catch (IOException ex)
137         {
138             System.out.println("ERROR: could not attach file '" + statusFile + "' to cws\n" + ex.toString());
139         }
140         finally
141         {
142             try
143             {
144                 out.close();
145             }
146             catch (IOException ex)
147             {
148                 ex.printStackTrace();
149             }
150         }
151     }
152 }
153