<< Your Java Is Being End-Of-Life'd | Home | Question: Concurrent Programming On Dual-Core Machines >>

Your jirb, groovysh and clj Commands Doesn't Work In Cygwin

This is another one of those making things work in Cygwin posts. You can safely skip this post if you are not married to Cygwin, or have not followed my Ten Steps To Higher Cygwin Productivity.

The issue this time is with a little library called JLine, which is a BSD licensed library that brings GNU readline style command line editing to Java. I first learned about it through the Clojure programming language (a LISP with immutable variables and software transactional memory (STM)).

And of course, it doesn't work in my Cygwin xterm window. A little Googling landed me at JLine issue-1822900. A little looking around in the JLine source and some experiments later, I had a partial workaround, which I added as a comment to the issue.

While doing the Google search, I also noticed that both Groovy and JRuby use JLine to some extend (in jirb and groovysh). Sure enough, the same issue showed up in the Groovy JIRA as GROOVY-2584, to which I added the workaround.

A fresh download of the just released JRuby 1.1 showed the same symptom. The JLine workaround can be applied directly to the jruby script, which, thankfully, does contain infrastructure for Cygwin support.

There are other issues with JLine on a Cygwin xterm. But the workaround at least makes the repls workable.

The part that makes me uncomfortable is that I don't see how this workaround can be incorporated into a patch for JLine. In that regard, I concede Cygwin is a somewhat hacky platform. (Jonathan and Adam, if you are still reading...)



Re: Your jirb, groovysh and clj Commands Doesn't Work In Cygwin

I'm still reading!
Does cygwin qualify as a "platfrom" or is it just plain hacky? :-)
I think it would be an interesting project to see how (and why) bash scripts are used on these Java projects and come up with a more platform-neutral solution, or use some other adaptation like a bash.exe that's native-Windows (not Cygwin).

Re: Your jirb, groovysh and clj Commands Doesn't Work In Cygwin

OK. A hacky POSIX (and others) portability library for Windows.

To be fair, the projects did provide .bat files for Windows. No bash.exe is needed.

Trying to make the shell scripts Cygwin friendly is just a futile attempt on my part to prolong Cygwin's life.

Hi, my name is Weiqi Gao, and I'm a Cygwin addict.

Re: Your jirb, groovysh and clj Commands Doesn't Work In Cygwin

Nice, thanks for the tips. I'd probably try to adjust jirb in JRuby distribution to correct this problem, but Cygwin *IS* VERY problematic, especially for Java-based projects, since from Java point of view, we are still on Windows...

Re: Your jirb, groovysh and clj Commands Doesn't Work In Cygwin

Here's the tail end of my modified jruby script:

if $cygwin; then
  JAVA_HOME=`cygpath --mixed "$JAVA_HOME"`
  JRUBY_HOME=`cygpath --mixed "$JRUBY_HOME"`
  JRUBY_SHELL=`cygpath --mixed "$JRUBY_SHELL"`
  
  if [[ ( "${1:0:1}" = "/" ) && ( ( -f "$1" ) || ( -d "$1" )) ]]; then
    win_arg=`cygpath -w "$1"`
    shift
    win_args=("$win_arg" "$@")
    set -- "${win_args[@]}"
  fi

  JAVA_OPTS="$JAVA_OPTS -Djline.terminal=jline.UnixTerminal"
  stty -icanon min 1 -echo
fi

if $cygwin; then
  "$JAVA_CMD" $JAVA_OPTS -classpath "$CP" \
    "-Djruby.home=$JRUBY_HOME" \
    "-Djruby.lib=$JRUBY_HOME/lib" -Djruby.script=jruby \
    "-Djruby.shell=$JRUBY_SHELL" \
    org.jruby.Main $JRUBY_OPTS "$@"
  stty icanon echo
  echo
else
  exec "$JAVA_CMD" $JAVA_OPTS -classpath "$CP" \
    "-Djruby.home=$JRUBY_HOME" \
    "-Djruby.lib=$JRUBY_HOME/lib" -Djruby.script=jruby \
    "-Djruby.shell=$JRUBY_SHELL" \
    org.jruby.Main $JRUBY_OPTS "$@"
fi

It worked on my machine. :)

Cygwin is not the easiest environment to deal with.

Re: Your jirb, groovysh and clj Commands Doesn't Work In Cygwin

Thanks! The only remaining problem is to detect where are we currently running, inside CMD or inside xterm! :)

Re: Your jirb, groovysh and clj Commands Doesn't Work In Cygwin

By default, when Cygwin bash is run directly (from either a CMD prompt or File Explorer), it sets the $TERM environment variable to "cygwin".

Within an xterm or an rxvt window, the $TERM environment variable is set to "xterm"


Add a comment Send a TrackBack