KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > harness > SysInfoLog


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.harness.SysInfoLog
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derbyTesting.functionTests.harness;
23
24 /***
25  * SysInfoLog
26  * Purpose: For a Suite or Test run, write out the
27  * sysinfo to the suite or test output file
28  *
29  ***/

30
31 import java.io.*;
32 import java.util.Vector JavaDoc;
33
34 public class SysInfoLog
35 {
36
37     public SysInfoLog()
38     {
39     }
40
41     // Write out sysinfo for a suite or test
42
public void exec(String JavaDoc jvmName, String JavaDoc javaCmd, String JavaDoc classpath,
43         String JavaDoc framework, PrintWriter pw, boolean useprocess)
44         throws Exception JavaDoc
45     {
46         if ( useprocess == true )
47         {
48             // Create a process to run sysinfo
49
Process JavaDoc pr = null;
50             jvm javavm = null; // to quiet the compiler
51
try
52             {
53                 // Create the command line
54
//System.out.println("jvmName: " + jvmName);
55
if ( (jvmName == null) || (jvmName.length()==0) )
56                     jvmName = "jdk13";
57                 else if (jvmName.startsWith("jdk13"))
58                     jvmName = "jdk13";
59
60                 javavm = jvm.getJvm(jvmName);
61                 if (javaCmd != null)
62                     javavm.setJavaCmd(javaCmd);
63                 
64                 if (javavm == null) System.out.println("WHOA, javavm is NULL");
65                 if (javavm == null) pw.println("WHOA, javavm is NULL");
66
67                 if ( (classpath != null) && (classpath.length()>0) )
68                 {
69                     javavm.setClasspath(classpath);
70                 }
71
72                 Vector JavaDoc v = javavm.getCommandLine();
73                 v.addElement("org.apache.derby.tools.sysinfo");
74                 // Now convert the vector into a string array
75
String JavaDoc[] sCmd = new String JavaDoc[v.size()];
76                 for (int i = 0; i < v.size(); i++)
77                 {
78                     sCmd[i] = (String JavaDoc)v.elementAt(i);
79                     //System.out.println(sCmd[i]);
80
}
81                 
82                 pr = Runtime.getRuntime().exec(sCmd);
83
84                 // We need the process inputstream to capture into the output file
85
BackgroundStreamDrainer stdout =
86                     new BackgroundStreamDrainer(pr.getInputStream(), null);
87                 BackgroundStreamDrainer stderr =
88                     new BackgroundStreamDrainer(pr.getErrorStream(), null);
89
90                 pr.waitFor();
91                 String JavaDoc result = HandleResult.handleResult(pr.exitValue(),
92                     stdout.getData(), stderr.getData(), pw);
93                 pw.flush();
94
95                 if ( (framework != null) && (framework.length()>0) )
96                 {
97                     pw.println("Framework: " + framework);
98                 }
99
100                 pr.destroy();
101                 pr = null;
102             }
103             catch(Throwable JavaDoc t)
104             {
105                 if (javavm == null) System.out.println("WHOA, javavm is NULL");
106                 if (javavm == null) pw.println("WHOA, javavm is NULL");
107                 System.out.println("Process exception: " + t);
108                 pw.println("Process exception: " + t);
109                 t.printStackTrace(pw);
110                 if (pr != null)
111                 {
112                     pr.destroy();
113                     pr = null;
114                 }
115             }
116         }
117         else
118         {
119             // For platforms where process exec fails or hangs
120
// useprocess=false and attempt to get some info
121
/*
122             pw.println(org.apache.derby.impl.tools.sysinfo.Main.javaSep);
123             org.apache.derby.impl.tools.sysinfo.Main.reportCloudscape(pw);
124             pw.println(org.apache.derby.impl.tools.sysinfo.Main.jbmsSep);
125             org.apache.derby.impl.tools.sysinfo.Main.reportDerby(pw);
126             pw.println(org.apache.derby.impl.tools.sysinfo.Main.licSep);
127             org.apache.derby.impl.tools.sysinfo.Main.printLicenseFile(pw);
128             */

129         }
130     }
131 }
132
133
Popular Tags