modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java | 17 -- modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentNativePromptInfo.java | 2 modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/JlinePromptInfo.java | 71 ++++++++++ 3 files changed, 74 insertions(+), 16 deletions(-)
New commits: commit d19bacd67e857e52428144ab28af5a0c44956df3 Author: Bryan Kearney bkearney@redhat.com Date: Mon Feb 1 10:52:57 2010 -0500
Fix the native cleanup so that it will not echo password and will use jline
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 0d900d4..e2c6440 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 @@ -816,22 +816,7 @@ public class AgentMain { * @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); + return new JlinePromptInfo(this) ; }
/** 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 index 287421d..b1cc009 100644 --- 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 @@ -30,7 +30,9 @@ import org.rhq.enterprise.communications.util.prefs.PromptInput; * will do the same as {@link #readLine()}). * * @author John Mazzitelli + * @deprecated */ +@Deprecated public class AgentNativePromptInfo implements PromptInput { private final SystemInfo systemInfo; private final AgentMain 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..5dadd14 --- /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.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 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 + input = agent.getIn().readLine('0'); + + // get the answer a second time + agent.getOut().write(agent.getI18NMsg().getMsg(AgentI18NResourceKeys.PROMPT_CONFIRM)) ; + agent.getOut().println() ; + String confirmation = agent.getIn().readLine('0'); + agent.getOut().println() ; + 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; + } +} \ No newline at end of file
rhq-commits@lists.fedorahosted.org