.classpath | 2 .settings/org.eclipse.jdt.ui.prefs | 4 modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentInputReader.java | 62 +++++ modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentInputReaderFactory.java | 115 ++++++++++ modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java | 70 ++---- modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentNativePromptInfo.java | 91 ------- modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentPromptInfo.java | 59 +++++ modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentUpdateThread.java | 14 + modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JLineAgentInputReader.java | 90 +++++++ modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JavaAgentInputReader.java | 60 +++++ modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/SigarAgentInputReader.java | 73 ++++++ modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java | 7 modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/SetupPromptCommand.java | 7 13 files changed, 511 insertions(+), 143 deletions(-)
New commits: commit 9556c7d579d83d84d1cc2ffd6af210b18603dea8 Merge: ae1b4ae... e01ac13... Author: Jason Dobies jason.dobies@redhat.com Date: Wed Feb 3 08:23:56 2010 -0500
Merge branch 'master' into content
commit e01ac1302020282dfa2f0583c30ff859089143ea Author: John Mazzitelli mazz@redhat.com Date: Wed Feb 3 02:56:02 2010 -0500
refactor the jline integration to fix problems and enhance it. this commit will allow the user to select the implementation to use; you can now use the command line option --console (-e) to say if you want the console input to be read by "java" (pure Java implementation), "sigar" (this was the original native console way we had before) or "jline" (which is the new native console way). This allows a user to select a non-native way to read input in case they are running on a platform that doesn't support the native library (jline's native lib or sigar's native lib) or in case the native library has a bug and is causing the agent to crash. If you use "sigar", and you disable the native system API (native --disable), this will cause the console to fallback to the "java" console impl. If user is using "jline", there is no fallback to - if jline is giving problems, you must exit the agent, and specify a --console argument to override the console to use. The default is "jline".
diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentInputReader.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentInputReader.java index dc6644b..4f00ab1 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentInputReader.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentInputReader.java @@ -28,24 +28,32 @@ import java.io.IOException; */ public interface AgentInputReader { /** + * Indicates if the input is coming from a console (i.e. keyboard) or if its coming from + * a file. + * + * @return <code>true</code> if console is the source of the input; <code>false</code> if file is the source + */ + boolean isConsole(); + + /** * Reads a line from the input console. * * @return the line * @throws IOException */ String readLine() throws IOException; - + /** - * Reads a line from the input console, echoing out the 'mask' character as opposed to the character - * typed by the user. If the console implementation does not support mask echoes, either the - * user-entered character is masked or some other masking is performed in an implementation specific way. + * Read a line of input, but do not echo back to the user what is being typed. This is used mainly when asking for + * things like passwords. + * If the console implementation does not support no-echo input, the input will be + * output as the user typed it. * - * @param mask character to echo back to the user when the user types in the line. * @return the line typed by the user * @throws IOException */ - String readLine(char mask) throws IOException; - + String readLineNoEcho() throws IOException; + /** * Close the reader. * @throws IOException diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentInputReaderFactory.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentInputReaderFactory.java index e3ebe4c..71f0e4f 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentInputReaderFactory.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentInputReaderFactory.java @@ -18,19 +18,98 @@ */ package org.rhq.enterprise.agent;
+import java.io.File; import java.io.FileInputStream; +import java.io.FileReader; import java.io.IOException;
+import mazz.i18n.Logger; + +import org.rhq.enterprise.agent.i18n.AgentI18NFactory; +import org.rhq.enterprise.agent.i18n.AgentI18NResourceKeys; + /** * Creates implementations of the input reader depending on the need for a native console library. * * @author John Mazzitelli */ public class AgentInputReaderFactory { - public static AgentInputReader create() throws IOException { - return new JlineAgentInputReader(); + private static final Logger LOG = AgentI18NFactory.getLogger(AgentInputReaderFactory.class); + + public static enum ConsoleType { + java, sigar, jline + } + + private static ConsoleType consoleType = ConsoleType.jline; + + public static AgentInputReader create(AgentMain agent) throws IOException { + AgentInputReader input = null; + + try { + switch (consoleType) { + case java: + input = new JavaAgentInputReader(); + break; + case sigar: + input = new SigarAgentInputReader(agent); + break; + case jline: + input = new JLineAgentInputReader(agent); + break; + } + } catch (Exception e) { + input = null; + LOG.warn(e, AgentI18NResourceKeys.AGENT_INPUT_READER_FACTORY_ERROR, consoleType); + } + + if (input == null) { + input = new JavaAgentInputReader(); + } + + return input; } - public static AgentInputReader create(FileInputStream fis) throws IOException { - return new JlineAgentInputReader(fis); + + public static AgentInputReader create(AgentMain agent, File file) throws IOException { + AgentInputReader input = null; + + try { + switch (consoleType) { + case java: + input = new JavaAgentInputReader(new FileReader(file)); + break; + case sigar: + input = new SigarAgentInputReader(agent, new FileReader(file)); + break; + case jline: + input = new JLineAgentInputReader(agent, new FileInputStream(file)); + break; + } + } catch (Exception e) { + input = null; + LOG.warn(e, AgentI18NResourceKeys.AGENT_INPUT_READER_FACTORY_ERROR, consoleType); + } + + if (input == null) { + input = new JavaAgentInputReader(new FileReader(file)); + } + + return input; + } + + public static ConsoleType getConsoleType() { + return consoleType; + } + + public static void setConsoleType(ConsoleType type) { + consoleType = type; + } + + public static void setConsoleType(String typeStr) { + try { + setConsoleType(ConsoleType.valueOf(typeStr)); + } catch (Exception e) { + throw new IllegalArgumentException(LOG.getMsgString( + AgentI18NResourceKeys.AGENT_INPUT_READER_FACTORY_BAD_TYPE, typeStr)); + } } } diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java index aba4eb5..2baf5f5 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java @@ -89,7 +89,6 @@ import org.rhq.core.pc.PluginContainer; import org.rhq.core.pc.PluginContainerConfiguration; import org.rhq.core.pc.ServerServices; import org.rhq.core.pc.plugin.FileSystemPluginFinder; -import org.rhq.core.system.SystemInfo; import org.rhq.core.system.SystemInfoFactory; import org.rhq.core.util.ObjectNameFactory; import org.rhq.core.util.exception.ThrowableUtil; @@ -152,7 +151,6 @@ import org.rhq.enterprise.communications.command.server.CommandListener; import org.rhq.enterprise.communications.command.server.IncomingCommandTrace; import org.rhq.enterprise.communications.util.CommandTraceUtil; import org.rhq.enterprise.communications.util.SecurityUtil; -import org.rhq.enterprise.communications.util.prefs.PromptInput;
/** * The main class of the agent runtime container. @@ -387,12 +385,13 @@ public class AgentMain { if (agent.m_forcedSetup || (!agent.m_daemonMode && !agent.m_configuration.isAgentConfigurationSetup())) { SetupPromptCommand setup_cmd = new SetupPromptCommand();
+ AgentPromptInfo in = new AgentPromptInfo(agent); + AgentPrintWriter out = agent.getOut(); + Preferences prefs = agent.m_configuration.getPreferences(); if (agent.m_advancedSetup) { - setup_cmd.performAdvancedSetup(agent.m_configuration.getPreferences(), agent.getNativeIn(), - agent.getOut()); + setup_cmd.performAdvancedSetup(prefs, in, out); } else { - setup_cmd.performBasicSetup(agent.m_configuration.getPreferences(), agent.getNativeIn(), agent - .getOut()); + setup_cmd.performBasicSetup(prefs, in, out); } }
@@ -459,7 +458,7 @@ public class AgentMain {
m_agentHomeDirectory = null; m_daemonMode = false; - m_input = AgentInputReaderFactory.create(); + m_input = null; m_output = new AgentPrintWriter(System.out, true); m_stdinInput = true; m_configuration = null; @@ -477,6 +476,9 @@ public class AgentMain {
m_commandLineArgs = args; processArguments(m_commandLineArgs); + if (m_input == null) { + m_input = AgentInputReaderFactory.create(this); + }
m_promptCommands = new HashMap<String, Class<? extends AgentPromptCommand>>(); setupPromptCommandsMap(m_promptCommands); @@ -805,32 +807,6 @@ public class AgentMain { }
/** - * In some cases, we want to read console input in a native way (that is, using the native system to read the - * keyboard input). This is mainly useful when you want to read in prompt answers which include passwords and you do - * not want to echo what the user typed. - * - * @return object that can be used to read input with the typed data being echoed or not - */ - public PromptInput getNativeIn() { - SystemInfo sysinfo = null; - - // if we are not in daemon mode, we are running in a console and thus we can try to use - // the native library to get its input. - // If we are in daemon mode, we aren't running in a console so we need to pass null - // in for sysinfo thus causing the prompt info implementation to use our fallback buffered - // reader (which is either empty or is contents of an input file that was piped in via --input. - if (!m_daemonMode) { - // just in case the native stuff has a bug in the console stuff (JBNATIVE-42 as an example), - // be able to configure the agent to ignore the native console - if (Boolean.getBoolean("rhq.agent.do-not-use-native-console") == false) { - sysinfo = SystemInfoFactory.createSystemInfo(); - } - } - - return new AgentNativePromptInfo(sysinfo, this); - } - - /** * Returns the object that can be used to obtain I18N messages from the agent's resource bundle in the user's * locale. * @@ -1097,10 +1073,10 @@ public class AgentMain { // if we are not in daemon mode, let's now start processing prompt commands coming in via stdin if (!m_daemonMode) { try { - m_input = AgentInputReaderFactory.create(); + m_input = AgentInputReaderFactory.create(this); } catch (IOException e1) { m_input = null; - } + } m_stdinInput = true; input_string = ""; } else { @@ -2691,12 +2667,13 @@ public class AgentMain { * @throws HelpException if help was requested and the agent should not be created */ private void processArguments(String[] args) throws Exception { - String sopts = "-:hdlasntuD:i:o:c:p:"; + String sopts = "-:hdlasntuD:i:o:c:p:e:"; LongOpt[] lopts = { new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h'), new LongOpt("input", LongOpt.REQUIRED_ARGUMENT, null, 'i'), new LongOpt("output", LongOpt.REQUIRED_ARGUMENT, null, 'o'), new LongOpt("config", LongOpt.REQUIRED_ARGUMENT, null, 'c'), new LongOpt("pref", LongOpt.REQUIRED_ARGUMENT, null, 'p'), + new LongOpt("console", LongOpt.REQUIRED_ARGUMENT, null, 'e'), new LongOpt("daemon", LongOpt.NO_ARGUMENT, null, 'd'), new LongOpt("cleanconfig", LongOpt.NO_ARGUMENT, null, 'l'), new LongOpt("advanced", LongOpt.NO_ARGUMENT, null, 'a'), @@ -2789,6 +2766,11 @@ public class AgentMain { break; }
+ case 'e': { + AgentInputReaderFactory.setConsoleType(getopt.getOptarg()); + break; + } + case 'd': { m_daemonMode = true; break; @@ -2798,7 +2780,7 @@ public class AgentMain { File script = new File(getopt.getOptarg());
try { - m_input = AgentInputReaderFactory.create(new FileInputStream(script)); + m_input = AgentInputReaderFactory.create(this, script); m_stdinInput = false; } catch (Exception e) { throw new IllegalArgumentException(MSG.getMsg(AgentI18NResourceKeys.BAD_INPUT_FILE, script, e)); diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentNativePromptInfo.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentNativePromptInfo.java deleted file mode 100644 index 287421d..0000000 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentNativePromptInfo.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * RHQ Management Platform - * Copyright (C) 2005-2008 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -package org.rhq.enterprise.agent; - -import java.io.IOException; -import org.rhq.core.system.SystemInfo; -import org.rhq.enterprise.agent.i18n.AgentI18NResourceKeys; -import org.rhq.enterprise.communications.util.prefs.PromptInput; - -/** - * Provides a {@link PromptInput} implementation that the agent can use to obtain input from the native system. Note - * that if the native libraries are not available or have been disabled, this will effectively fallback to using the - * Java-only mechanism to read input and will therefore always echo the input (i.e. calling {@link #readLineNoEcho()} - * will do the same as {@link #readLine()}). - * - * @author John Mazzitelli - */ -public class AgentNativePromptInfo implements PromptInput { - private final SystemInfo systemInfo; - private final AgentMain agent; - - /** - * Constructor for {@link AgentNativePromptInfo} that is given the system info used to obtain the console input - * natively. The agent is provided so it can give us a fallback stream where input can be read in case either <code> - * sysinfo</code> is <code>null</code> or it is not a native implementation (as will be the case if the platform - * where this object is running does not have native libraries for it). - * - * @param sysinfo the object where native console input can be read (may be <code>null</code>) - * @param agent the agent that will be doing the prompting and will provide us with a fallback input stream if - * <code>sysinfo</code> is <code>null</code> or not a native implementation - */ - public AgentNativePromptInfo(SystemInfo sysinfo, AgentMain agent) { - this.systemInfo = sysinfo; - this.agent = agent; - } - - public String readLine() throws IOException { - String input; - - if ((systemInfo == null) || !systemInfo.isNative()) { - input = agent.getIn().readLine(); - } else { - input = systemInfo.readLineFromConsole(false); - } - - return input; - } - - public String readLineNoEcho() throws IOException { - String input = null; - - if ((systemInfo == null) || !systemInfo.isNative()) { - input = agent.getIn().readLine(); - } else { - while (true) { - // get the answer the first time - input = systemInfo.readLineFromConsole(true); - - // get the answer a second time - systemInfo.writeLineToConsole(agent.getI18NMsg().getMsg(AgentI18NResourceKeys.PROMPT_CONFIRM)); - String confirmation = systemInfo.readLineFromConsole(true); - systemInfo.writeLineToConsole("\n"); - - // make sure the first and second answers match; otherwise, ask again - if (input.equals(confirmation)) { - break; - } - - systemInfo.writeLineToConsole(agent.getI18NMsg().getMsg(AgentI18NResourceKeys.PROMPT_CONFIRM_FAILED)); - } - } - - return input; - } -} \ No newline at end of file diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentPromptInfo.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentPromptInfo.java new file mode 100644 index 0000000..9984626 --- /dev/null +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentPromptInfo.java @@ -0,0 +1,59 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.agent; + +import java.io.IOException; +import org.rhq.core.system.SystemInfo; +import org.rhq.enterprise.agent.i18n.AgentI18NResourceKeys; +import org.rhq.enterprise.communications.util.prefs.PromptInput; + +/** + * Provides a {@link PromptInput} implementation that the agent can use to obtain input from the native system. Note + * that if the native libraries are not available or have been disabled, this will effectively fallback to using the + * Java-only mechanism to read input and will therefore always echo the input (i.e. calling {@link #readLineNoEcho()} + * will do the same as {@link #readLine()}). + * + * @author John Mazzitelli + */ +public class AgentPromptInfo implements PromptInput { + + private final AgentMain agent; + + public AgentPromptInfo(AgentMain agent) { + this.agent = agent; + } + + public String readLine() throws IOException { + AgentInputReader input = this.agent.getIn(); + if (input != null) { + return input.readLine(); + } else { + throw new IOException("Agent not accepting input"); + } + } + + public String readLineNoEcho() throws IOException { + AgentInputReader input = this.agent.getIn(); + if (input != null) { + return input.readLineNoEcho(); + } else { + throw new IOException("Agent not accepting input"); + } + } +} \ No newline at end of file diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentUpdateThread.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentUpdateThread.java index 4d691c2..70e8e84 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentUpdateThread.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentUpdateThread.java @@ -174,7 +174,19 @@ public class AgentUpdateThread extends Thread { if (results.getError() != null) { throw results.getError(); } - tryAgain = false; + + // update has started! if this agent is running in non-daemon mode, kill + // the input stream so the input thread knows to shutdown now + try { + AgentInputReader in = this.agent.getIn(); + if (in != null) { + System.in.close(); // we must ensure we close this directly! + in.close(); + } + } catch (Throwable t) { + } finally { + tryAgain = false; + } } catch (Throwable t) { showErrorMessage(AgentI18NResourceKeys.UPDATE_THREAD_EXCEPTION, ThrowableUtil.getAllMessages(t));
diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JLineAgentInputReader.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JLineAgentInputReader.java new file mode 100644 index 0000000..15a3a89 --- /dev/null +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JLineAgentInputReader.java @@ -0,0 +1,90 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2009 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.agent; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.rhq.enterprise.agent.i18n.AgentI18NResourceKeys; + +import jline.ConsoleReader; + +public class JLineAgentInputReader implements AgentInputReader { + + private final ConsoleReader jline; + private final AgentMain agent; + private final boolean consoleInput; + + public JLineAgentInputReader(AgentMain agent) throws IOException { + this.jline = new ConsoleReader(); + this.agent = agent; + this.consoleInput = true; + } + + public JLineAgentInputReader(AgentMain agent, FileInputStream fis) throws IOException { + this.jline = new ConsoleReader(fis, agent.getOut()); + this.agent = agent; + this.consoleInput = false; + } + + public boolean isConsole() { + return this.consoleInput; + } + + public String readLine() throws IOException { + return this.jline.readLine(); + } + + public String readLineNoEcho() throws IOException { + String input = null; + + while (true) { + // get the answer the first time - the '*' is echoed back to the user + input = jline.readLine(Character.valueOf('*')); + + if (!isConsole()) { + break; // not reading input from a console, so we don't ask for confirmation + } + + // get the answer a second time + this.agent.getOut().write(this.agent.getI18NMsg().getMsg(AgentI18NResourceKeys.PROMPT_CONFIRM)); + this.agent.getOut().println(); + String confirmation = jline.readLine(Character.valueOf('*')); + this.agent.getOut().println(); + + // make sure the first and second answers match; otherwise, ask again + if (input.equals(confirmation)) { + break; + } + + this.agent.getOut().write(this.agent.getI18NMsg().getMsg(AgentI18NResourceKeys.PROMPT_CONFIRM_FAILED)); + this.agent.getOut().println(); + } + + return input; + } + + public void close() throws IOException { + InputStream input = jline.getInput(); + if (input != null) { + input.close(); + } + } +} diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JavaAgentInputReader.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JavaAgentInputReader.java new file mode 100644 index 0000000..7003457 --- /dev/null +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JavaAgentInputReader.java @@ -0,0 +1,60 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2009 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.agent; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; + +import jline.ConsoleReader; + +public class JavaAgentInputReader implements AgentInputReader { + + private final BufferedReader reader; + private final boolean consoleInput; + + public JavaAgentInputReader() throws IOException { + this.reader = new BufferedReader(new InputStreamReader(System.in)); + this.consoleInput = true; + } + + public JavaAgentInputReader(FileReader fr) throws IOException { + this.reader = new BufferedReader(fr); + this.consoleInput = false; + } + + public boolean isConsole() { + return this.consoleInput; + } + + public String readLine() throws IOException { + return this.reader.readLine(); + } + + public String readLineNoEcho() throws IOException { + return this.reader.readLine(); // can't mask the input with this Java API + } + + public void close() throws IOException { + this.reader.close(); + } +} diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JlineAgentInputReader.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JlineAgentInputReader.java deleted file mode 100644 index 3de70f4..0000000 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JlineAgentInputReader.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * RHQ Management Platform - * Copyright (C) 2005-2009 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -package org.rhq.enterprise.agent; - -import java.io.FileInputStream; -import java.io.IOException; - -import jline.ConsoleReader; - -public class JlineAgentInputReader implements AgentInputReader { - - private ConsoleReader jline; - - public JlineAgentInputReader() throws IOException { - jline = new ConsoleReader(); - } - - public JlineAgentInputReader(FileInputStream fis) throws IOException { - jline = new ConsoleReader(fis, null); - } - - public String readLine() throws IOException { - return jline.readLine(); - } - - public String readLine(char mask) throws IOException { - return jline.readLine(Character.valueOf(mask)); - } - - public void close() throws IOException { - jline.getInput().close(); - } -} diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JlinePromptInfo.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JlinePromptInfo.java deleted file mode 100644 index b1c4db6..0000000 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JlinePromptInfo.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * RHQ Management Platform - * Copyright (C) 2005-2008 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -package org.rhq.enterprise.agent; - -import java.io.IOException; - -import org.rhq.enterprise.agent.i18n.AgentI18NResourceKeys; -import org.rhq.enterprise.communications.util.prefs.PromptInput; - -/** - * Provides a {@link PromptInput} implementation that the agent can use to obtain input from the jline - * command prompt in the agent. - */ -public class JlinePromptInfo implements PromptInput { - private final AgentMain agent; - - /** - * Constructor for {@link AgentNativePromptInfo} that is given the agent main to retrieve - * the jline command prompt from. - */ - public JlinePromptInfo(AgentMain agent) { - this.agent = agent; - } - - public String readLine() throws IOException { - - return agent.getIn().readLine(); - } - - public String readLineNoEcho() throws IOException { - String input = null; - - while (true) { - // get the answer the first time - // A (char)0 will blank it out. I like stars - input = agent.getIn().readLine('*'); - - // get the answer a second time - agent.getOut().write(agent.getI18NMsg().getMsg(AgentI18NResourceKeys.PROMPT_CONFIRM)); - agent.getOut().println(); - String confirmation = agent.getIn().readLine('*'); - agent.getOut().println(); - - // make sure the first and second answers match; otherwise, ask again - if (input.equals(confirmation)) { - break; - } - - agent.getOut().write(agent.getI18NMsg().getMsg(AgentI18NResourceKeys.PROMPT_CONFIRM_FAILED)); - agent.getOut().println(); - } - - return input; - } -} diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/SigarAgentInputReader.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/SigarAgentInputReader.java new file mode 100644 index 0000000..f3b29ce --- /dev/null +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/SigarAgentInputReader.java @@ -0,0 +1,73 @@ +package org.rhq.enterprise.agent; + +import java.io.FileReader; +import java.io.IOException; + +import org.rhq.core.system.SystemInfo; +import org.rhq.core.system.SystemInfoFactory; +import org.rhq.enterprise.agent.i18n.AgentI18NResourceKeys; + +/** + * Uses the SIGAR API when appropriate to read in console input. + * This falls back to the Java-only superclass implementation if + * the native SIGAR API is not available. + * + * @author John Mazzitelli + */ +public class SigarAgentInputReader extends JavaAgentInputReader { + + private final AgentMain agent; + + public SigarAgentInputReader(AgentMain agent) throws IOException { + super(); + this.agent = agent; + } + + public SigarAgentInputReader(AgentMain agent, FileReader fr) throws IOException { + super(fr); + this.agent = agent; + } + + @Override + public String readLine() throws IOException { + String input; + + SystemInfo systemInfo = SystemInfoFactory.createSystemInfo(); + if ((systemInfo == null) || !systemInfo.isNative() || !isConsole()) { + input = super.readLine(); + } else { + input = systemInfo.readLineFromConsole(false); + } + + return input; + } + + @Override + public String readLineNoEcho() throws IOException { + String input = null; + + SystemInfo systemInfo = SystemInfoFactory.createSystemInfo(); + if ((systemInfo == null) || !systemInfo.isNative() || !isConsole()) { + input = super.readLine(); + } else { + while (true) { + // get the answer the first time + input = systemInfo.readLineFromConsole(true); + + // get the answer a second time + systemInfo.writeLineToConsole(agent.getI18NMsg().getMsg(AgentI18NResourceKeys.PROMPT_CONFIRM)); + String confirmation = systemInfo.readLineFromConsole(true); + systemInfo.writeLineToConsole("\n"); + + // make sure the first and second answers match; otherwise, ask again + if (input.equals(confirmation)) { + break; + } + + systemInfo.writeLineToConsole(agent.getI18NMsg().getMsg(AgentI18NResourceKeys.PROMPT_CONFIRM_FAILED)); + } + } + + return input; + } +} diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java index d2aa065..68da9a6 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java @@ -28,6 +28,12 @@ import mazz.i18n.annotation.I18NResourceBundle; */ @I18NResourceBundle(baseName = "agent-messages", defaultLocale = "en") public interface AgentI18NResourceKeys { + @I18NMessage("Specified bad console type [{0}]") + String AGENT_INPUT_READER_FACTORY_BAD_TYPE = "AgentMain.input-reader-factory-bad-type"; + + @I18NMessage("Failed to create console input reader of type [{0}]") + String AGENT_INPUT_READER_FACTORY_ERROR = "AgentMain.input-reader-factory-error"; + @I18NMessage("!!! This agent is registering under the loopback address [{0}] - this should only be done for testing " + "or demo purposes - this agent will only be able to interact with a server running on the same host as this agent") String REGISTERING_WITH_LOOPBACK = "AgentMain.registering-with-loopback"; @@ -549,6 +555,7 @@ public interface AgentI18NResourceKeys { + "\ -c, --config=<filename> Specifies an agent configuration preferences file (on filesystem or classpath)\n\\n" + "\ -d, --daemon Agent runs in daemon mode - will not read from stdin for commands\n\\n" + "\ -D<name>[=<value>] Overrides an agent configuration preference and sets a system property\n\\n" + + "\ -e, --console=<type> Specifies the implementation to use when reading console input: jline, sigar, java\n\\n" + "\ -h, --help Shows this help message (default)\n\\n" + "\ -i, --input=<filename> Specifies a script file to be used for input\n\\n" + "\ -l, --cleanconfig Clears out any existing configuration and data files so the agent starts with a totally clean slate\n\\n" diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/SetupPromptCommand.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/SetupPromptCommand.java index 57add17..4c9226a 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/SetupPromptCommand.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/SetupPromptCommand.java @@ -31,6 +31,7 @@ import org.jboss.remoting.security.SSLSocketBuilder; import org.rhq.enterprise.agent.AgentConfiguration; import org.rhq.enterprise.agent.AgentConfigurationConstants; import org.rhq.enterprise.agent.AgentMain; +import org.rhq.enterprise.agent.AgentPromptInfo; import org.rhq.enterprise.agent.i18n.AgentI18NFactory; import org.rhq.enterprise.agent.i18n.AgentI18NResourceKeys; import org.rhq.enterprise.agent.i18n.AgentSetupInstructions; @@ -78,11 +79,11 @@ public class SetupPromptCommand implements AgentPromptCommand { agent.getOut().println(MSG.getMsg(AgentI18NResourceKeys.SETUP_MUST_BE_STOPPED)); } else { if (args.length == 1) { - performBasicSetup(agent.getConfiguration().getPreferences(), agent.getNativeIn(), agent.getOut()); + performBasicSetup(agent.getConfiguration().getPreferences(), new AgentPromptInfo(agent), agent.getOut()); } else if ((args.length == 2) && args[1].equals(MSG.getMsg(AgentI18NResourceKeys.SETUP_ADVANCED))) { - performAdvancedSetup(agent.getConfiguration().getPreferences(), agent.getNativeIn(), agent.getOut()); + performAdvancedSetup(agent.getConfiguration().getPreferences(), new AgentPromptInfo(agent), agent.getOut()); } else if ((args.length == 2) && args[1].equals(MSG.getMsg(AgentI18NResourceKeys.SETUP_ALL))) { - performAllSetup(agent.getConfiguration().getPreferences(), agent.getNativeIn(), agent.getOut()); + performAllSetup(agent.getConfiguration().getPreferences(), new AgentPromptInfo(agent), agent.getOut()); } else { agent.getOut().println(MSG.getMsg(AgentI18NResourceKeys.HELP_SYNTAX_LABEL, getSyntax())); }
commit 1f3d5356a7d1257f86effa4e3f83b604d9bed87c Author: John Mazzitelli mazz@redhat.com Date: Tue Feb 2 23:44:13 2010 -0500
start abstracting out the input reader
diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentInputReader.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentInputReader.java new file mode 100644 index 0000000..dc6644b --- /dev/null +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentInputReader.java @@ -0,0 +1,54 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2009 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +package org.rhq.enterprise.agent; + +import java.io.IOException; + +/** + * Abstracts out the console input to allow us to use either a native console or a Java based console. + * + * @author John Mazzitelli + */ +public interface AgentInputReader { + /** + * Reads a line from the input console. + * + * @return the line + * @throws IOException + */ + String readLine() throws IOException; + + /** + * Reads a line from the input console, echoing out the 'mask' character as opposed to the character + * typed by the user. If the console implementation does not support mask echoes, either the + * user-entered character is masked or some other masking is performed in an implementation specific way. + * + * @param mask character to echo back to the user when the user types in the line. + * @return the line typed by the user + * @throws IOException + */ + String readLine(char mask) throws IOException; + + /** + * Close the reader. + * @throws IOException + */ + void close() throws IOException; +} diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentInputReaderFactory.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentInputReaderFactory.java new file mode 100644 index 0000000..e3ebe4c --- /dev/null +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentInputReaderFactory.java @@ -0,0 +1,36 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2009 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.agent; + +import java.io.FileInputStream; +import java.io.IOException; + +/** + * Creates implementations of the input reader depending on the need for a native console library. + * + * @author John Mazzitelli + */ +public class AgentInputReaderFactory { + public static AgentInputReader create() throws IOException { + return new JlineAgentInputReader(); + } + public static AgentInputReader create(FileInputStream fis) throws IOException { + return new JlineAgentInputReader(fis); + } +} diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java index d75cb7d..aba4eb5 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java @@ -21,14 +21,12 @@ package org.rhq.enterprise.agent; import gnu.getopt.Getopt; import gnu.getopt.LongOpt;
-import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.FileReader; import java.io.FileWriter; import java.io.FilenameFilter; import java.io.IOException; @@ -58,8 +56,6 @@ import java.util.prefs.Preferences; import javax.management.MBeanServer; import javax.management.ObjectName;
-import jline.ConsoleReader; - import mazz.i18n.Logger; import mazz.i18n.Msg;
@@ -208,7 +204,7 @@ public class AgentMain { /** * The stream where the commands are input. */ - private ConsoleReader m_input; + private AgentInputReader m_input;
/** * Will be <code>true</code> if the input is coming directly from stdin; <code>false</code> if an input script file @@ -463,7 +459,7 @@ public class AgentMain {
m_agentHomeDirectory = null; m_daemonMode = false; - m_input = new ConsoleReader() ; + m_input = AgentInputReaderFactory.create(); m_output = new AgentPrintWriter(System.out, true); m_stdinInput = true; m_configuration = null; @@ -804,7 +800,7 @@ public class AgentMain { * * @return the input stream or <code>null</code> if the agent is not currently accepting input */ - public ConsoleReader getIn() { + public AgentInputReader getIn() { return m_input; }
@@ -1093,13 +1089,17 @@ public class AgentMain { } } else if (!m_stdinInput) { // if we are processing a script, we hit the EOF, so close the input stream - + try { + m_input.close(); + } catch (IOException e1) { + }
// if we are not in daemon mode, let's now start processing prompt commands coming in via stdin if (!m_daemonMode) { try { - m_input = new ConsoleReader() ; + m_input = AgentInputReaderFactory.create(); } catch (IOException e1) { + m_input = null; } m_stdinInput = true; input_string = ""; @@ -2798,7 +2798,7 @@ public class AgentMain { File script = new File(getopt.getOptarg());
try { - m_input = new ConsoleReader(new FileInputStream(script), null); + m_input = AgentInputReaderFactory.create(new FileInputStream(script)); m_stdinInput = false; } catch (Exception e) { throw new IllegalArgumentException(MSG.getMsg(AgentI18NResourceKeys.BAD_INPUT_FILE, script, e)); diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JlineAgentInputReader.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JlineAgentInputReader.java new file mode 100644 index 0000000..3de70f4 --- /dev/null +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JlineAgentInputReader.java @@ -0,0 +1,49 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2009 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.agent; + +import java.io.FileInputStream; +import java.io.IOException; + +import jline.ConsoleReader; + +public class JlineAgentInputReader implements AgentInputReader { + + private ConsoleReader jline; + + public JlineAgentInputReader() throws IOException { + jline = new ConsoleReader(); + } + + public JlineAgentInputReader(FileInputStream fis) throws IOException { + jline = new ConsoleReader(fis, null); + } + + public String readLine() throws IOException { + return jline.readLine(); + } + + public String readLine(char mask) throws IOException { + return jline.readLine(Character.valueOf(mask)); + } + + public void close() throws IOException { + jline.getInput().close(); + } +}
commit bd631f0dda01d2f6e594fe1c1f2df92155f4c893 Author: Joseph Marques joseph@redhat.com Date: Tue Feb 2 22:55:14 2010 -0500
fix eclipse settings so that code gets auto-reformatted on save
diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs index 10d36a9..e7120a1 100644 --- a/.settings/org.eclipse.jdt.ui.prefs +++ b/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,4 @@ -#Thu Jan 14 12:59:22 EST 2010 +#Tue Feb 02 22:50:09 EST 2010 cleanup.add_default_serial_version_id=true cleanup.add_generated_serial_version_id=false cleanup.add_missing_annotations=true @@ -52,7 +52,7 @@ cleanup.use_this_for_non_static_method_access_only_if_necessary=true cleanup_profile=_RHQ cleanup_settings_version=2 eclipse.preferences.version=1 -editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=false +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_RHQ formatter_settings_version=11 org.eclipse.jdt.ui.exception.name=e
commit 95511f633370a76ab42b2b4b8eabe4259fff3903 Author: John Mazzitelli mazz@redhat.com Date: Tue Feb 2 22:30:36 2010 -0500
put this back in the agent
diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JlinePromptInfo.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JlinePromptInfo.java new file mode 100644 index 0000000..b1c4db6 --- /dev/null +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JlinePromptInfo.java @@ -0,0 +1,71 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.agent; + +import java.io.IOException; + +import org.rhq.enterprise.agent.i18n.AgentI18NResourceKeys; +import org.rhq.enterprise.communications.util.prefs.PromptInput; + +/** + * Provides a {@link PromptInput} implementation that the agent can use to obtain input from the jline + * command prompt in the agent. + */ +public class JlinePromptInfo implements PromptInput { + private final AgentMain agent; + + /** + * Constructor for {@link AgentNativePromptInfo} that is given the agent main to retrieve + * the jline command prompt from. + */ + public JlinePromptInfo(AgentMain agent) { + this.agent = agent; + } + + public String readLine() throws IOException { + + return agent.getIn().readLine(); + } + + public String readLineNoEcho() throws IOException { + String input = null; + + while (true) { + // get the answer the first time + // A (char)0 will blank it out. I like stars + input = agent.getIn().readLine('*'); + + // get the answer a second time + agent.getOut().write(agent.getI18NMsg().getMsg(AgentI18NResourceKeys.PROMPT_CONFIRM)); + agent.getOut().println(); + String confirmation = agent.getIn().readLine('*'); + agent.getOut().println(); + + // make sure the first and second answers match; otherwise, ask again + if (input.equals(confirmation)) { + break; + } + + agent.getOut().write(agent.getI18NMsg().getMsg(AgentI18NResourceKeys.PROMPT_CONFIRM_FAILED)); + agent.getOut().println(); + } + + return input; + } +}
commit 10a1c32a5aee2174b29a02eb70cf3a05b9a1f724 Author: John Mazzitelli mazz@redhat.com Date: Tue Feb 2 22:30:20 2010 -0500
opps. this should not be here
diff --git a/modules/common/jboss-as/src/main/java/org/rhq/enterprise/agent/JlinePromptInfo.java b/modules/common/jboss-as/src/main/java/org/rhq/enterprise/agent/JlinePromptInfo.java deleted file mode 100644 index b1c4db6..0000000 --- a/modules/common/jboss-as/src/main/java/org/rhq/enterprise/agent/JlinePromptInfo.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * RHQ Management Platform - * Copyright (C) 2005-2008 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -package org.rhq.enterprise.agent; - -import java.io.IOException; - -import org.rhq.enterprise.agent.i18n.AgentI18NResourceKeys; -import org.rhq.enterprise.communications.util.prefs.PromptInput; - -/** - * Provides a {@link PromptInput} implementation that the agent can use to obtain input from the jline - * command prompt in the agent. - */ -public class JlinePromptInfo implements PromptInput { - private final AgentMain agent; - - /** - * Constructor for {@link AgentNativePromptInfo} that is given the agent main to retrieve - * the jline command prompt from. - */ - public JlinePromptInfo(AgentMain agent) { - this.agent = agent; - } - - public String readLine() throws IOException { - - return agent.getIn().readLine(); - } - - public String readLineNoEcho() throws IOException { - String input = null; - - while (true) { - // get the answer the first time - // A (char)0 will blank it out. I like stars - input = agent.getIn().readLine('*'); - - // get the answer a second time - agent.getOut().write(agent.getI18NMsg().getMsg(AgentI18NResourceKeys.PROMPT_CONFIRM)); - agent.getOut().println(); - String confirmation = agent.getIn().readLine('*'); - agent.getOut().println(); - - // make sure the first and second answers match; otherwise, ask again - if (input.equals(confirmation)) { - break; - } - - agent.getOut().write(agent.getI18NMsg().getMsg(AgentI18NResourceKeys.PROMPT_CONFIRM_FAILED)); - agent.getOut().println(); - } - - return input; - } -}
commit 86270a451083b341baa3710355c9ae4c02292a89 Author: John Mazzitelli mazz@redhat.com Date: Tue Feb 2 22:14:33 2010 -0500
put this back, but don't integrate it yet
diff --git a/modules/common/jboss-as/src/main/java/org/rhq/enterprise/agent/JlinePromptInfo.java b/modules/common/jboss-as/src/main/java/org/rhq/enterprise/agent/JlinePromptInfo.java new file mode 100644 index 0000000..b1c4db6 --- /dev/null +++ b/modules/common/jboss-as/src/main/java/org/rhq/enterprise/agent/JlinePromptInfo.java @@ -0,0 +1,71 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.agent; + +import java.io.IOException; + +import org.rhq.enterprise.agent.i18n.AgentI18NResourceKeys; +import org.rhq.enterprise.communications.util.prefs.PromptInput; + +/** + * Provides a {@link PromptInput} implementation that the agent can use to obtain input from the jline + * command prompt in the agent. + */ +public class JlinePromptInfo implements PromptInput { + private final AgentMain agent; + + /** + * Constructor for {@link AgentNativePromptInfo} that is given the agent main to retrieve + * the jline command prompt from. + */ + public JlinePromptInfo(AgentMain agent) { + this.agent = agent; + } + + public String readLine() throws IOException { + + return agent.getIn().readLine(); + } + + public String readLineNoEcho() throws IOException { + String input = null; + + while (true) { + // get the answer the first time + // A (char)0 will blank it out. I like stars + input = agent.getIn().readLine('*'); + + // get the answer a second time + agent.getOut().write(agent.getI18NMsg().getMsg(AgentI18NResourceKeys.PROMPT_CONFIRM)); + agent.getOut().println(); + String confirmation = agent.getIn().readLine('*'); + agent.getOut().println(); + + // make sure the first and second answers match; otherwise, ask again + if (input.equals(confirmation)) { + break; + } + + agent.getOut().write(agent.getI18NMsg().getMsg(AgentI18NResourceKeys.PROMPT_CONFIRM_FAILED)); + agent.getOut().println(); + } + + return input; + } +}
commit 80bf4075b6d4c3a84e1b9c788730faa191769657 Author: John Mazzitelli mazz@redhat.com Date: Tue Feb 2 21:26:27 2010 -0500
fixing .classpath (again)
diff --git a/.classpath b/.classpath index 9658f94..3b948dd 100644 --- a/.classpath +++ b/.classpath @@ -112,7 +112,6 @@ <classpathentry kind="src" path="modules/plugins/cobbler/src/main/java"/> <classpathentry kind="src" path="modules/plugins/cobbler/src/test/java"/> <classpathentry kind="src" path="modules/plugins/virt/src/main/java"/> - <classpathentry kind="src" path="modules/plugins/virt/src/test/java"/> <classpathentry kind="src" path="modules/plugins/kickstart/src/main/java"/> <classpathentry kind="src" path="modules/plugins/aliases/src/main/java"/> <classpathentry kind="src" path="modules/plugins/aliases/src/test/java"/>
commit 1b160377f367eda9254a2bf73d1ec0ec89e5b85c Author: John Mazzitelli mazz@redhat.com Date: Tue Feb 2 21:09:57 2010 -0500
why does antlr-config keep showing up in .classpath?
diff --git a/.classpath b/.classpath index ae63f80..9658f94 100644 --- a/.classpath +++ b/.classpath @@ -121,7 +121,6 @@ <classpathentry kind="src" path="modules/plugins/byteman/src/main/java"/> <classpathentry kind="src" path="modules/plugins/lsof/src/main/java"/> <classpathentry kind="src" path="modules/plugins/jdbctrace/src/main/java"/> - <classpathentry kind="src" path="modules/plugins/antlr-config/src/main/antlr3"/> <classpathentry kind="src" path="modules/plugins/augeas/src/main/java"/> <classpathentry kind="src" path="modules/plugins/augeas/src/test/java"/> <classpathentry kind="src" path="modules/helpers/rtfilter/src/main/java"/>
rhq-commits@lists.fedorahosted.org