001: /*
002: Copyright (C) 2005-2006 MySQL AB
003:
004: This program is free software; you can redistribute it and/or modify
005: it under the terms of version 2 of the GNU General Public License as
006: published by the Free Software Foundation.
007:
008: There are special exceptions to the terms and conditions of the GPL
009: as it is applied to this software. View the full text of the
010: exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
011: software distribution.
012:
013: This program is distributed in the hope that it will be useful,
014: but WITHOUT ANY WARRANTY; without even the implied warranty of
015: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: GNU General Public License for more details.
017:
018: You should have received a copy of the GNU General Public License
019: along with this program; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: */
022:
023: package com.mysql.jdbc.util;
024:
025: import java.io.File;
026: import java.io.FileOutputStream;
027: import java.sql.Connection;
028: import java.sql.ResultSet;
029: import java.util.Properties;
030:
031: import com.mysql.jdbc.NonRegisteringDriver;
032:
033: /**
034: * Creates output directory structure for multi-jvm, multi-url
035: * unit, regression and compliance tests.
036: */
037: public class VersionFSHierarchyMaker {
038:
039: /**
040: * @param args
041: */
042: public static void main(String[] args) throws Exception {
043: if (args.length < 3) {
044: usage();
045: System.exit(1);
046: }
047:
048: String jdbcUrl = null;
049:
050: String jvmVersion = removeWhitespaceChars(System
051: .getProperty("java.version"));
052: String jvmVendor = removeWhitespaceChars(System
053: .getProperty("java.vendor"));
054: String osName = removeWhitespaceChars(System
055: .getProperty("os.name"));
056: String osArch = removeWhitespaceChars(System
057: .getProperty("os.arch"));
058: String osVersion = removeWhitespaceChars(System
059: .getProperty("os.version"));
060:
061: jdbcUrl = System.getProperty("com.mysql.jdbc.testsuite.url");
062:
063: String mysqlVersion = "not-available";
064:
065: try {
066: Connection conn = new NonRegisteringDriver().connect(
067: jdbcUrl, null);
068:
069: ResultSet rs = conn.createStatement().executeQuery(
070: "SELECT VERSION()");
071: rs.next();
072: mysqlVersion = removeWhitespaceChars(rs.getString(1));
073: } catch (Throwable t) {
074: mysqlVersion = "no-server-running-on-"
075: + removeWhitespaceChars(jdbcUrl);
076: }
077:
078: String jvmSubdirName = jvmVendor + "-" + jvmVersion;
079: String osSubdirName = osName + "-" + osArch + "-" + osVersion;
080:
081: File baseDir = new File(args[1]);
082: File mysqlVersionDir = new File(baseDir, mysqlVersion);
083: File osVersionDir = new File(mysqlVersionDir, osSubdirName);
084: File jvmVersionDir = new File(osVersionDir, jvmSubdirName);
085:
086: jvmVersionDir.mkdirs();
087:
088: FileOutputStream pathOut = null;
089:
090: try {
091: String propsOutputPath = args[2];
092: pathOut = new FileOutputStream(propsOutputPath);
093: String baseDirStr = baseDir.getAbsolutePath();
094: String jvmVersionDirStr = jvmVersionDir.getAbsolutePath();
095:
096: if (jvmVersionDirStr.startsWith(baseDirStr)) {
097: jvmVersionDirStr = jvmVersionDirStr
098: .substring(baseDirStr.length() + 1);
099: }
100:
101: pathOut.write(jvmVersionDirStr.getBytes());
102: } finally {
103: if (pathOut != null) {
104: pathOut.flush();
105: pathOut.close();
106: }
107: }
108: }
109:
110: public static String removeWhitespaceChars(String input) {
111: if (input == null) {
112: return input;
113: }
114:
115: int strLen = input.length();
116:
117: StringBuffer output = new StringBuffer(strLen);
118:
119: for (int i = 0; i < strLen; i++) {
120: char c = input.charAt(i);
121: if (!Character.isDigit(c) && !Character.isLetter(c)) {
122: if (Character.isWhitespace(c)) {
123: output.append("_");
124: } else {
125: output.append(".");
126: }
127: } else {
128: output.append(c);
129: }
130: }
131:
132: return output.toString();
133: }
134:
135: private static void usage() {
136: System.err
137: .println("Creates a fs hierarchy representing MySQL version, OS version and JVM version.");
138: System.err
139: .println("Stores the full path as 'outputDirectory' property in file 'directoryPropPath'");
140: System.err.println();
141: System.err
142: .println("Usage: java VersionFSHierarchyMaker unit|compliance baseDirectory directoryPropPath");
143: }
144: }
|