You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Petar Tahchiev <pa...@gmail.com> on 2018/11/24 09:00:13 UTC

Maven and TTY terminal

Hi guys,

my setup is Ubuntu Linux and Java8. I'm trying to use JLine from Maven to
get a TerminalBuild and determine the size of the command line. So JLine
has this code inside TerminalBuilder;

Pty pty = load(JansiSupport.class).current();

private <S> S load(Class<S> clazz) {
    return ServiceLoader.load(clazz, clazz.getClassLoader()).iterator().next();
}

When I call JBuilder from one of my annotation processors during
compilation, then Pty is successfully created and so I get a
TerminalBuilder and it all works fine. However, when I call it from one of
my JUnit tests the code throws this exception when .current() is invoked:

java.io.IOException: Not a tty
    at
org.jline.terminal.impl.jansi.linux.LinuxNativePty.current(LinuxNativePty.java:29)
    at
org.jline.terminal.impl.jansi.JansiSupportImpl.current(JansiSupportImpl.java:54)
    at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:340)

JLine can also use JNA, but when I added the JNA dependency the story is
the same - when running it from surefire plugin the exception is:

com.sun.jna.LastErrorException: [25] Inappropriate ioctl for device
    at com.sun.jna.Native.invokeVoid(Native Method)
    at com.sun.jna.Function.invoke(Function.java:414)
    at com.sun.jna.Function.invoke(Function.java:360)

Do you know why this happens? Is there any setting that I can set on the
surefire plugin to avoid these types of error?
-- 
Regards, Petar!
Karlovo, Bulgaria.
---
Public PGP Key at:
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x19658550C3110611
Key Fingerprint: A369 A7EE 61BC 93A3 CDFF  55A5 1965 8550 C311 0611

Re: Maven and TTY terminal

Posted by Olaf Flebbe <ap...@oflebbe.de>.
Hi,

I do not know the implementation of maven surefire plugin. However, what you are trying to achieve is not safe. you cannot assume you have an PTY , for instance if the output is consumed by something like — a testing framework. AFAIK java does not provide an API for this.

If you absolutly need this, it is your duty to fire up a program like screen, tmux or expect to provide you with a terminal emulation and connect your testing instance with it. That might be very tricky , so I advise you to fail jline initialization gracefully and continue instead. This is what I did way in the past for similar problems.

Best,
Olaf Flebbe

> Am 24.11.2018 um 10:00 schrieb Petar Tahchiev <pa...@gmail.com>:
> 
> Hi guys,
> 
> my setup is Ubuntu Linux and Java8. I'm trying to use JLine from Maven to
> get a TerminalBuild and determine the size of the command line. So JLine
> has this code inside TerminalBuilder;
> 
> Pty pty = load(JansiSupport.class).current();
> 
> private <S> S load(Class<S> clazz) {
>    return ServiceLoader.load(clazz, clazz.getClassLoader()).iterator().next();
> }
> 
> When I call JBuilder from one of my annotation processors during
> compilation, then Pty is successfully created and so I get a
> TerminalBuilder and it all works fine. However, when I call it from one of
> my JUnit tests the code throws this exception when .current() is invoked:
> 
> java.io.IOException: Not a tty
>    at
> org.jline.terminal.impl.jansi.linux.LinuxNativePty.current(LinuxNativePty.java:29)
>    at
> org.jline.terminal.impl.jansi.JansiSupportImpl.current(JansiSupportImpl.java:54)
>    at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:340)
> 
> JLine can also use JNA, but when I added the JNA dependency the story is
> the same - when running it from surefire plugin the exception is:
> 
> com.sun.jna.LastErrorException: [25] Inappropriate ioctl for device
>    at com.sun.jna.Native.invokeVoid(Native Method)
>    at com.sun.jna.Function.invoke(Function.java:414)
>    at com.sun.jna.Function.invoke(Function.java:360)
> 
> Do you know why this happens? Is there any setting that I can set on the
> surefire plugin to avoid these types of error?
> -- 
> Regards, Petar!
> Karlovo, Bulgaria.
> ---
> Public PGP Key at:
> http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x19658550C3110611
> Key Fingerprint: A369 A7EE 61BC 93A3 CDFF  55A5 1965 8550 C311 0611

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