001: /*
002:
003: Derby - Class org.apache.derbyTesting.functionTests.harness.SysInfoLog
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derbyTesting.functionTests.harness;
023:
024: /***
025: * SysInfoLog
026: * Purpose: For a Suite or Test run, write out the
027: * sysinfo to the suite or test output file
028: *
029: ***/
030:
031: import java.io.*;
032: import java.util.Vector;
033:
034: public class SysInfoLog {
035:
036: public SysInfoLog() {
037: }
038:
039: // Write out sysinfo for a suite or test
040: public void exec(String jvmName, String javaCmd, String classpath,
041: String framework, PrintWriter pw, boolean useprocess)
042: throws Exception {
043: if (useprocess == true) {
044: // Create a process to run sysinfo
045: Process pr = null;
046: jvm javavm = null; // to quiet the compiler
047: try {
048: // Create the command line
049: //System.out.println("jvmName: " + jvmName);
050: if ((jvmName == null) || (jvmName.length() == 0))
051: jvmName = "jdk13";
052: else if (jvmName.startsWith("jdk13"))
053: jvmName = "jdk13";
054:
055: javavm = jvm.getJvm(jvmName);
056: if (javaCmd != null)
057: javavm.setJavaCmd(javaCmd);
058:
059: if (javavm == null)
060: System.out.println("WHOA, javavm is NULL");
061: if (javavm == null)
062: pw.println("WHOA, javavm is NULL");
063:
064: if ((classpath != null) && (classpath.length() > 0)) {
065: javavm.setClasspath(classpath);
066: }
067:
068: Vector v = javavm.getCommandLine();
069: v.addElement("org.apache.derby.tools.sysinfo");
070: // Now convert the vector into a string array
071: String[] sCmd = new String[v.size()];
072: for (int i = 0; i < v.size(); i++) {
073: sCmd[i] = (String) v.elementAt(i);
074: //System.out.println(sCmd[i]);
075: }
076:
077: pr = Runtime.getRuntime().exec(sCmd);
078:
079: // We need the process inputstream to capture into the output file
080: BackgroundStreamDrainer stdout = new BackgroundStreamDrainer(
081: pr.getInputStream(), null);
082: BackgroundStreamDrainer stderr = new BackgroundStreamDrainer(
083: pr.getErrorStream(), null);
084:
085: pr.waitFor();
086: String result = HandleResult.handleResult(pr
087: .exitValue(), stdout.getData(), stderr
088: .getData(), pw);
089: pw.flush();
090:
091: if ((framework != null) && (framework.length() > 0)) {
092: pw.println("Framework: " + framework);
093: }
094:
095: pr.destroy();
096: pr = null;
097: } catch (Throwable t) {
098: if (javavm == null)
099: System.out.println("WHOA, javavm is NULL");
100: if (javavm == null)
101: pw.println("WHOA, javavm is NULL");
102: System.out.println("Process exception: " + t);
103: pw.println("Process exception: " + t);
104: t.printStackTrace(pw);
105: if (pr != null) {
106: pr.destroy();
107: pr = null;
108: }
109: }
110: } else {
111: // For platforms where process exec fails or hangs
112: // useprocess=false and attempt to get some info
113: /*
114: pw.println(org.apache.derby.impl.tools.sysinfo.Main.javaSep);
115: org.apache.derby.impl.tools.sysinfo.Main.reportCloudscape(pw);
116: pw.println(org.apache.derby.impl.tools.sysinfo.Main.jbmsSep);
117: org.apache.derby.impl.tools.sysinfo.Main.reportDerby(pw);
118: pw.println(org.apache.derby.impl.tools.sysinfo.Main.licSep);
119: org.apache.derby.impl.tools.sysinfo.Main.printLicenseFile(pw);
120: */
121: }
122: }
123: }
|