You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by po...@apache.org on 2005/01/28 23:29:10 UTC

svn commit: r148941 - in jakarta/commons/proper/jelly/trunk/jelly-tags/interaction: . src/java/org/apache/commons/jelly/tags/interaction src/test/org/apache/commons/jelly/tags/interaction

Author: polx
Date: Fri Jan 28 14:29:09 2005
New Revision: 148941

URL: http://svn.apache.org/viewcvs?view=rev&rev=148941
Log:
Applying Ryan Christianson's patch... thanks for this Ryan.
Now... as you point out.... we have no test for this.
It's not really unit testable but a demo should be possible.
There was a file sample.jelly which I somewhat populated... (without experience
with the interaction tag).
I then tried to get this running as maven demo but... weird errors occur.
The same command issued on the command-line works somewhat...

Either a maven expert could provide a thought or someone could further investiga
te or try...
paul

PS: added several dependencies so that one can run with jelly command-line

Modified:
   jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/maven.xml
   jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/project.xml
   jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/src/java/org/apache/commons/jelly/tags/interaction/AskTag.java
   jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/src/test/org/apache/commons/jelly/tags/interaction/sample.jelly

Modified: jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/maven.xml
Url: http://svn.apache.org/viewcvs/jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/maven.xml?view=diff&rev=148941&p1=jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/maven.xml&r1=148940&p2=jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/maven.xml&r2=148941
==============================================================================
--- jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/maven.xml	(original)
+++ jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/maven.xml	Fri Jan 28 14:29:09 2005
@@ -13,6 +13,17 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-<project default="java:jar">
+<project default="jar:jar">
+
+  
+  <goal name="demo" prereqs=""
+			description="Non-functioning demo yet.">
+		<echo>Using classpath:</echo>
+    <echo>${pom.getDependencyClasspath()}:target/${pom.name}-${pom.currentVersion}.jar</echo>
+    <java classpath="${pom.getDependencyClasspath()}:target/${pom.name}-${pom.currentVersion}.jar"
+      classname="org.apache.commons.jelly.Jelly" fork="true">
+      <arg file="src/test/org/apache/commons/jelly/tags/interaction/sample.jelly"/>
+      </java>
+    </goal>
 
 </project>

Modified: jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/project.xml
Url: http://svn.apache.org/viewcvs/jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/project.xml?view=diff&rev=148941&p1=jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/project.xml&r1=148940&p2=jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/project.xml&r2=148941
==============================================================================
--- jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/project.xml	(original)
+++ jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/project.xml	Fri Jan 28 14:29:09 2005
@@ -20,7 +20,7 @@
   <extend>${basedir}/../tag-project.xml</extend>
   <id>commons-jelly-tags-interaction</id>
   <name>commons-jelly-tags-interaction</name>
-  <currentVersion>1.0</currentVersion>
+  <currentVersion>1.1</currentVersion>
   <package>org.apache.commons.jelly.tags.interaction</package>
   <description>This is a Jelly interface to the user.</description>
   <shortDescription>Commons Jelly Interaction Tag Library</shortDescription>
@@ -31,5 +31,32 @@
       <tag>COMMONS-JELLY-INTERACTION-1_0</tag>
     </version>
   </versions>
+
+  <dependencies>
+		<dependency>
+		 <groupId>jline</groupId>
+		 <artifactId>jline</artifactId>
+		 <version>0.9.0</version>
+		 <type>jar</type>
+		</dependency> 
+    <dependency>
+      <id>commons-cli</id>
+      <version>1.0</version>
+    </dependency>
+
+    <!-- this is brought in by the commons-cli dependency -->
+    <dependency>
+      <id>commons-lang</id>
+      <version>2.0</version>
+      <properties>
+        <gump.runtime>true</gump.runtime>
+      </properties>
+    </dependency>
+    <dependency>
+      <id>commons-discovery</id>
+      <version>20030211.213356</version>
+    </dependency>
+		
+	</dependencies>
 
 </project>

Modified: jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/src/java/org/apache/commons/jelly/tags/interaction/AskTag.java
Url: http://svn.apache.org/viewcvs/jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/src/java/org/apache/commons/jelly/tags/interaction/AskTag.java?view=diff&rev=148941&p1=jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/src/java/org/apache/commons/jelly/tags/interaction/AskTag.java&r1=148940&p2=jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/src/java/org/apache/commons/jelly/tags/interaction/AskTag.java&r2=148941
==============================================================================
--- jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/src/java/org/apache/commons/jelly/tags/interaction/AskTag.java	(original)
+++ jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/src/java/org/apache/commons/jelly/tags/interaction/AskTag.java	Fri Jan 28 14:29:09 2005
@@ -15,21 +15,31 @@
  */
 package org.apache.commons.jelly.tags.interaction;
 
-import java.io.InputStreamReader;
 import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
+
+import jline.ConsoleReader;
+import jline.History;
+import jline.SimpleCompletor;
 
 import org.apache.commons.jelly.TagSupport;
 import org.apache.commons.jelly.XMLOutput;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
-/**
- * Jelly Tag that asks the user a question, and puts his answer into
- * a variable, with the attribute "answer".
- * This variable may be reused further as any other Jelly variable.
- * @author <a href="mailto:smor@hasgard.net">St�phane Mor</a>
- */
+  /**
+  * Jelly Tag that asks the user a question, and puts his answer into a variable,
+  * with the attribute "answer". This variable may be reused further as any other
+  * Jelly variable.
+  * 
+  * @author <a href="mailto:smor@hasgard.net">Stéphane Mor </a>
+   */
 public class AskTag extends TagSupport
 {
+
+    private static Log logger = LogFactory.getLog(AskTag.class);
+
     /** The question to ask to the user */
     private String question;
 
@@ -48,60 +58,62 @@
     /** The prompt to display before the user input */
     private String prompt = ">";
 
+    private static History consoleHistory = new History();
+
     /**
-     * Sets the question to ask to the user. If a "default" attribute
-     * is present, it will appear inside [].
-     * @param question The question to ask to the user
+     * Sets the question to ask to the user. If a "default" attribute is
+     * present, it will appear inside [].
+     * 
+     * @param question
+     *            The question to ask to the user
      */
-    public void setQuestion(String question)
-    {
+    public void setQuestion(String question) {
         this.question = question;
     }
 
     /**
-     * Sets the name of the variable that will hold the answer
-     * This defaults to "interact.answer".
-     * @param answer the name of the variable that will hold the answer
+     * Sets the name of the variable that will hold the answer This defaults to
+     * "interact.answer".
+     * 
+     * @param answer
+     *            the name of the variable that will hold the answer
      */
-    public void setAnswer(String answer)
-    {
+    public void setAnswer(String answer) {
         this.answer = answer;
     }
 
     /**
-     * Sets the default answer to the question.
-     * If it is present, it will appear inside [].
-     * @param default the default answer to the question
+     * Sets the default answer to the question. If it is present, it will appear
+     * inside [].
+     * 
+     * @param default
+     *            the default answer to the question
      */
-    public void setDefault(String defaultInput)
-    {
+    public void setDefault(String defaultInput) {
         this.defaultInput = defaultInput;
     }
 
     /**
      * Sets the prompt that will be displayed before the user's input.
-     * @param promt the prompt that will be displayed before the user's input.
+     * 
+     * @param promt
+     *            the prompt that will be displayed before the user's input.
      */
-    public void setPrompt(String prompt)
-    {
+    public void setPrompt(String prompt) {
         this.prompt = prompt;
     }
 
-
     /**
      * Perform functionality provided by the tag
-     * @param output the place to write output
-     */
-    public void doTag(XMLOutput output)
-    {
-        if (question != null)
-        {
-            if (defaultInput != null)
-            {
+     * 
+     * @param output
+     *            the place to write output
+     */
+    public void doTag(XMLOutput output) {
+        if (question != null) {
+            if (defaultInput != null) {
                 System.out.println(question + " [" + defaultInput + "]");
-            }
-            else
-            {
+            } else {
                 System.out.println(question);
             }
             // The prompt should be just before the user's input,
@@ -109,16 +121,54 @@
             //System.out.print(prompt + " ");
         }
 
-        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+        ConsoleReader consoleReader;
 
         try {
-            input = br.readLine();
-            if (defaultInput != null && input.trim().equals(""))
-            {
-                input = defaultInput;
+            consoleReader = new ConsoleReader();
+        } catch (IOException e) {
+            logger.warn("couldnt create console reader", e);
+            consoleReader = null;
+        }
+
+        String disableJlineProp = System.getProperty("ask.jline.disable");
+        boolean disableJline = (disableJlineProp != null && disableJlineProp
+                .equals("true"));
+
+        try {
+            if (consoleReader != null
+                    && consoleReader.getTerminal().isSupported()) {
+
+                // resue the static history, so our commands are remeberered
+                consoleReader.setHistory(consoleHistory);
+
+                // hate the bell!
+                consoleReader.setBellEnabled(false);
+
+                // add old commands as tab completion history
+                String[] oldCommands = new String[consoleHistory
+                        .getHistoryList().size()];
+                consoleHistory.getHistoryList().toArray(oldCommands);
+                consoleReader.addCompletor(new SimpleCompletor(oldCommands));
+
+                // read the input!
+                input = consoleReader.readLine();
+                
+                // trim the input for tab completion
+                input = input.trim();
+
+                if (defaultInput != null && input.trim().equals("")) {
+                    input = defaultInput;
+                }
+            } else {
+                BufferedReader reader = new BufferedReader(
+                        new InputStreamReader(System.in));
+                input = reader.readLine();
             }
-        } catch (IOException ioe) {
+
+        } catch (IOException ex) {
+            logger.warn("error setting up the console reader", ex);
         }
+
         context.setVariable(answer, input);
     }
-}
+}
\ No newline at end of file

Modified: jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/src/test/org/apache/commons/jelly/tags/interaction/sample.jelly
Url: http://svn.apache.org/viewcvs/jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/src/test/org/apache/commons/jelly/tags/interaction/sample.jelly?view=diff&rev=148941&p1=jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/src/test/org/apache/commons/jelly/tags/interaction/sample.jelly&r1=148940&p2=jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/src/test/org/apache/commons/jelly/tags/interaction/sample.jelly&r2=148941
==============================================================================
--- jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/src/test/org/apache/commons/jelly/tags/interaction/sample.jelly	(original)
+++ jakarta/commons/proper/jelly/trunk/jelly-tags/interaction/src/test/org/apache/commons/jelly/tags/interaction/sample.jelly	Fri Jan 28 14:29:09 2005
@@ -19,4 +19,10 @@
 
     <!-- some sample scripts would be a good idea -->
 
-</jelly>
\ No newline at end of file
+    BLOP
+    
+    <interaction:ask question="Say something: " answer="answer"/>
+    
+    ${answer}
+    
+</j:jelly>
\ No newline at end of file

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org