public void testTrimOptionsErrorMsg() { ByteArrayOutputStream out = new ByteArrayOutputStream(); HelpOptionsParser parser = new HelpOptionsParser(new PrintStream(out), new Utils()); Exception expected = null; try { parser.trimToOptions("bogus"); } catch (Exception e) { expected = e; } assertNotNull(expected); String errMsg = new String(out.toByteArray()); assertTrue(errMsg.indexOf("bogus") >= 0); }
public synchronized Map getServerOptions() { if (options.isEmpty()) { options = optionParser.getOptionsFromHelp(getHelp(new HashMap())); options.put(BASEDIR, baseDir.getPath()); options.put(DATADIR, dataDir.getPath()); } return new HashMap(options); }
String trimToOptions(String help) { boolean success = false; try { String trimmedHelp = trimToOptionsInner(help); success = true; return trimmedHelp; } finally { if (!success) { synchronized (err) { printMsg(err, "parsing unseccessful:"); printMsg(err, "===== BEGIN MYSQLD HELP OPTIONS TEXT ====="); err.println(help); printMsg(err, "===== END MYSQLD HELP OPTIONS TEXT ====="); } } } }
public void testOptionParserSupportIssue8601() throws Exception { String text = "support-issue-8601-help-output.txt"; ClassLoader cl = getClass().getClassLoader(); InputStream is = cl.getResourceAsStream(text); String help = new Streams().readString(is); is.close(); HelpOptionsParser parser = new HelpOptionsParser(System.err, new Utils()); Map parsed = parser.getOptionsFromHelp(help); // System.err.println(new ListToString().toString(parsed)); assertEquals("FALSE", parsed.get("allow-suspicious-udfs")); } }
public Map parseHelp(String help) { String trimmed = trimToOptions(help); final Map map = new HashMap(); final BufferedReader reader = new BufferedReader(new StringReader( trimmed)); Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws Exception { while (true) { String line = reader.readLine(); if (line == null) { break; } if (line.indexOf(' ') <= 0) { continue; } String key = line.substring(0, line.indexOf(' ')); String val = line.substring(key.length()).trim(); if (val.equals(NO_DEFAULT_VALUE)) { val = ""; } map.put(key, val); } } }; block.exec(); return map; }
MysqldResource(File baseDir, PrintStream out, PrintStream err, FileUtil fileUtil, Shell.Factory shellFactory, Streams streams, Threads threads, Str str, ClassUtil classUtil) { this.out = out; this.err = err; this.fileUtil = fileUtil; this.shellFactory = shellFactory; this.streams = streams; this.threads = threads; this.str = str; this.classUtil = classUtil; this.optionParser = new HelpOptionsParser(err, threads, classUtil, str); this.versionString = MysqldResourceI.DEFAULT_VERSION; this.killDelay = 30000; if (baseDir.equals(fileUtil.nullFile())) { this.baseDir = new File(fileUtil.tmp(), "mysql-c.mxj"); } else { this.baseDir = baseDir; } this.pidFile = null; this.msgPrefix = "[" + classUtil.shortName(getClass()) + "] "; this.options = new HashMap(); this.setShell(null); setOsAndArch(System.getProperty(Platform.OS_NAME), System .getProperty(Platform.OS_ARCH)); this.trace = new Exception(); this.completionListensers = new ArrayList(); }
public void testOptionParser() throws Exception { String resourceVersionDir = MysqldResourceI.DEFAULT_VERSION.replaceAll( "\\.", "-"); assertEquals("4-1-13", resourceVersionDir); String sampleHelp = resourceVersionDir + "/com/mysql/management/MySQL_Help.txt"; ClassLoader cl = getClass().getClassLoader(); InputStream is = cl.getResourceAsStream(sampleHelp); String help = new Streams().readString(is); is.close(); HelpOptionsParser parser = new HelpOptionsParser(System.err, new Threads(), new ClassUtil(), new Str()); Map parsed = parser.parseHelp(help); assertEquals("/usr/local/mysql/", parsed.get(MysqldResourceI.BASEDIR)); assertEquals("TRUE", parsed.get("bdb")); // assertEquals("(No default value)", parsed.get("time-format")); assertEquals("", parsed.get("time-format")); }
private String trimToOptionsInner(String help) { int dividerPos = help.indexOf(DIVIDER); int start = dividerPos + DIVIDER.length(); int stop = help.indexOf(END_TEXT); if (dividerPos == -1) { synchronized (err) { printMsg(err, "Divider=\"" + DIVIDER + "\""); printMsg(err, "found at: " + dividerPos); printMsg(err, "Start Position:" + start); printMsg(err, "End Text=\"" + END_TEXT + "\""); printMsg(err, "found at: " + stop); printMsg(err, "HELP TEXT BEGIN"); printMsg(err, help); printMsg(err, "HELP TEXT END"); } throw new RuntimeException("could not parse help text"); } if (stop < start) { stop = help.length(); } String options = help.substring(start, stop); return options + System.getProperty("line.separator"); }
public synchronized Map getServerOptions() { if (options.isEmpty()) { options = optionParser.getCurrentOptions(this, new HashMap()); } return new HashMap(options); }
private Map getOptionsFromHelp(MysqldResource mysqldResource, Map params) { Map options; ByteArrayOutputStream bos = new ByteArrayOutputStream(); PrintStream capturedOut = new PrintStream(bos); params.put("help", null); params.put("verbose", null); final Shell s = mysqldResource.exec("getOptions", params, capturedOut, capturedOut, false); new Exceptions.VoidBlock() { protected void inner() throws InterruptedException { s.join(); } }.exec(); threads.pause(100); capturedOut.flush(); capturedOut.close(); // should flush(); options = parseHelp(new String(bos.toByteArray())); options.remove("help"); params.remove("help"); options.remove("verbose"); params.remove("verbose"); return options; }
public void testOptionParser() throws Exception { String resourceVersion = new TestUtil() .getSystemPropertyWithDefaultFromResource( MysqldResourceI.MYSQLD_VERSION, MysqldResourceI.CONNECTOR_MXJ_PROPERTIES, System.err); String resourceVersionDir = resourceVersion.replaceAll("\\.", "-"); String sampleHelp = resourceVersionDir + "/com/mysql/management/MySQL_Help.txt"; ClassLoader cl = getClass().getClassLoader(); InputStream is = cl.getResourceAsStream(sampleHelp); String help = new Streams().readString(is); is.close(); HelpOptionsParser parser = new HelpOptionsParser(System.err, new Utils()); Map parsed = parser.getOptionsFromHelp(help); String optStr = new ListToString().toString(parsed); assertEquals(optStr, "TRUE", parsed.get("auto-rehash")); // assertEquals("/usr/local/mysql/", // parsed.get(MysqldResourceI.BASEDIR)); // assertEquals("FALSE", parsed.get("bdb")); // assertEquals("(No default value)", parsed.get("time-format")); // assertTrue(parsed.containsKey("time_format")); // assertEquals("", parsed.get("time_format")); }
public Map getOptionsFromHelp(String help) { String trimmed = trimToOptions(help); Map map = new LinkedHashMap(); String[] lines = utils.str().splitLines(trimmed); for (int i = 0; i < lines.length; i++) { String line = lines[i]; if (line.indexOf(' ') <= 0) { continue; } String key = line.substring(0, line.indexOf(' ')); String val = line.substring(key.length()).trim(); if (val.equals(NO_DEFAULT_VALUE)) { val = ""; } map.put(key, val); } map.remove("help"); map.remove("verbose"); return map; }
public MysqldResource(File baseDir, File dataDir, String mysqlVersionString, boolean guessArch, PrintStream out, PrintStream err, Utils util, String binDir) { this.out = out; this.err = err; this.utils = util; this.binDir = binDir; this.optionParser = new HelpOptionsParser(err, utils); this.killDelay = 30000; this.baseDir = utils.files().validCononicalDir(baseDir, utils.files().tmp(MYSQL_C_MXJ)); this.dataDir = utils.files().validCononicalDir(dataDir, new File(this.baseDir, DATA)); String className = utils.str().shortClassName(getClass()); this.pidFile = utils.files().cononical( new File(this.dataDir, className + ".pid")); this.portFile = new File(dataDir, "port"); setVersion(false, mysqlVersionString); this.msgPrefix = "[" + utils.str().shortClassName(getClass()) + "] "; this.options = new HashMap(); this.setShell(null); setOsAndArch(System.getProperty(Platform.OS_NAME), guessArch, System .getProperty(Platform.OS_ARCH)); this.completionListensers = new ArrayList(); initTrace(); }
private String trimToOptionsInner(String help) { int dividerPos = help.indexOf(DIVIDER); int start = dividerPos + DIVIDER.length(); int stop = help.indexOf(END_TEXT); if (dividerPos == -1) { synchronized (err) { printMsg(err, "Divider=\"" + DIVIDER + "\""); printMsg(err, "found at: " + dividerPos); printMsg(err, "Start Position:" + start); printMsg(err, "End Text=\"" + END_TEXT + "\""); printMsg(err, "found at: " + stop); printMsg(err, "HELP TEXT BEGIN"); printMsg(err, help); printMsg(err, "HELP TEXT END"); } throw new RuntimeException("could not parse help text"); } if (stop < start) { stop = help.length(); } String options = help.substring(start, stop); return options + System.getProperty("line.separator"); }
options = optionParser.getCurrentOptions(this, mysqldArgs);
public void testTrimOptionsErrorMsg() { ByteArrayOutputStream out = new ByteArrayOutputStream(); HelpOptionsParser parser = new HelpOptionsParser(new PrintStream(out), new Threads(), new ClassUtil(), new Str()); Exception expected = null; try { parser.trimToOptions("bogus"); } catch (Exception e) { expected = e; } assertNotNull(expected); String errMsg = new String(out.toByteArray()); assertTrue(errMsg.indexOf("bogus") >= 0); } }
String trimToOptions(String help) { boolean success = false; try { String trimmedHelp = trimToOptionsInner(help); success = true; return trimmedHelp; } finally { if (!success) { synchronized (err) { printMsg(err, "parsing unseccessful:"); printMsg(err, "===== BEGIN MYSQLD HELP OPTIONS TEXT ====="); err.println(help); printMsg(err, "===== END MYSQLD HELP OPTIONS TEXT ====="); } } } }
public Map getOptionsFromHelp(String help) { String trimmed = trimToOptions(help); Map map = new LinkedHashMap(); String[] lines = utils.str().splitLines(trimmed); for (int i = 0; i < lines.length; i++) { String line = lines[i]; if (line.indexOf(' ') <= 0) { continue; } String key = line.substring(0, line.indexOf(' ')); String val = line.substring(key.length()).trim(); if (val.equals(NO_DEFAULT_VALUE)) { val = ""; } map.put(key, val); } map.remove("help"); map.remove("verbose"); return map; }
MysqldResource(File pBaseDir, File pDataDir, String pMysqlVersionString, PrintStream pOut, PrintStream pErr, Utils pUtils) { this.out = (pOut != null) ? pOut : System.out; this.err = (pErr != null) ? pErr : System.err; this.utils = (pUtils != null) ? pUtils : new Utils(); this.platformProperties = utils.streams().loadProperties( PLATFORM_MAP_PROPERTIES, pErr); this.connectorMxjProperties = utils.streams().loadProperties( CONNECTOR_MXJ_PROPERTIES, pErr); this.baseDir = utils.files().validCononicalDir(pBaseDir, utils.files().tmp(MYSQL_C_MXJ)); this.dataDir = utils.files().validCononicalDir(pDataDir, new File(baseDir, DATA)); this.optionParser = new HelpOptionsParser(err, utils); this.killDelay = getKillDelyFromProperties(connectorMxjProperties); this.windowsKillCommand = getWindowsKillCommand(connectorMxjProperties); String className = utils.str().shortClassName(getClass()); this.pidFile = utils.files().cononical( new File(dataDir, className + ".pid")); this.portFile = new File(dataDir, className + ".port"); setVersion(false, pMysqlVersionString); this.msgPrefix = "[" + className + "] "; this.options = new HashMap(); setShell(null); setOsAndArch(System.getProperty(Platform.OS_NAME), System .getProperty(Platform.OS_ARCH)); this.completionListensers = new ArrayList(); initTrace(); }
@Override public synchronized Map getServerOptions() { if (options.isEmpty()) { options = optionParser.getOptionsFromHelp(getHelp(new HashMap())); } return new HashMap(options); }