How to prepend String on each line by jline3? - java

I want app to print on each line its name like (shell > ):
shell > --param1 value1 --param2 value2
Is it possible to implement it by jline3?

You can do this using jline3-terminal.
It has support for 'jansi' and 'jna'. Both work near same, but jansi is a bit light weight than jna. Whereas jna is more generic.
You can follow documentation here and the also the terminal documentation here.
Prefer maven project to start with and go ahead with documentation.
Let me know for anything else.

See JLine readLine() javadoc. Add command prompt (shell >) to your CLI app call readLine method as
lineReader.readLine("shell > ", null, null);
If you want to add buffer also the default value for user to edit call readLine method as
lineReader.readLine("shell > ", null, "--param1 value1 --param2 value2");

Related

Automatic `log.info` completion in IntelliJ IDEA?

I am using Java and I log things like:
log.info("createArticle userId={} articleId={} title={} content={}", userId, articleId, title, content);
As you can see, when inputting this line into my IDE, I have to manually write down those characters like "userId={} ". Ideally, I hope I can simply type the userId, and Intellij IDEA will automatically help me fill out both "userId={} " (in the format string) and , userId (in the arguments list).
Question: How can I do that in IntelliJ IDEA? Or, is there any other ways to type such logging lines faster?
Thanks for any suggestions!
It is possible to implement it with Live Templates and groovyScript for one of the variables: take the second segment, split it by comma, concat in something like part=${part}:
groovyScript("_1.split(',').collect { it.trim() + '={}' }.join(' ')", B)
See video

How to show arguments of java function in vim + eclim?

I have configured vim + eclim OK. Now I can use Ctrl+X and Ctrl+U complete functions. But there is no arguments hint. For example,
FileInputStream fins = new FileInputStream(/* what arguments can be used here? eclipse will show those but eclim not */);
how to show arguments hint in vim + eclim?
Resurrecting this old question, since I stumbled on this.
You can use eclim to lookup the java docs of the class and look through the list of constructors that way using the :JavaDocSearch command.
Because the command uses a browser to render the javadocs, you'll need to add to your .vimrc:
let g:EclimBrowser = 'browser-executable-name'
Replacing browser-executable-name with your console-based browser of choice. Example: lynx, links, w3m
Then navigate over FileInputStream with your cursor and run the command :JavaDocSearch and it will pop up the java doc for the class.
Or enter the class name manually: :JavaDocSearch java.io.FileInputStream
You can use the YouCompleteMe (YCM) plugin with options
let g:ycm_add_preview_to_completeopt = 1
let g:ycm_autoclose_preview_window_after_insertion = 1
Note that this does not work for your Constructor invocations. But at least prototypes for method calls will be shown.
Also, if you don't like the auto-popup of YCM, it can be switched off.

How to use NSIS Internet plugin?

I have some code that defines a variable like so:
....
Var IP
...
I have some other code that runs on init
Function .onInit
;Default installation folder
StrCpy $INSTDIR "C:\PTL\${Project}"
Internet::GetLocalHostIP ${IP}
FunctionEnd
When I run the interpreter against the script, I get a warning:
[exec] Variable "IP" not referenced or never set, wasting memory!
I figure this is because im not assigning some constant value to IP, and it doesnt recognize the set operation thats happening with the Internet plugin, but when I run the installer it generates, and check the JVM args which use this value (-Djava.rmi.hostname) I have this value:
-Djava.rmi.server.hostname=
I tried using a value like $8 but it does the same thing, only the value becomes:
-Djava.rmi.server.hostname=0
How do I use this plugin correctly?
In terms of setup, I just dropped the plugin into ./Plugins/x86-ansi
${x} is for !define's, the syntax for variables is $x so in your case $IP but the NSIS plugin API does not allow output into a variable like that.
This plugin has a unusual design, if you take a look at its included .nsh file you see it has some defines where VAR_0 = 0 etc.
This means you have to do something like this:
Internet::GetLocalHostIP 1 ; Tells the plugin to put the result in $1
StrCpy $IP $1 ; Copy into your variable

Using Gradle to generate JavaDoc with newline characters in the "header"

UPDATE: Made a posting on the Gradle forum. Please star this issue so that it gets more attention http://gsfn.us/t/4jedo
I'm in the process of transitioning from a primarily Ant build environment into a Gradle one. One sticking point is injecting Google Analytics and Adsense code into the JavaDoc. This is done by putting java script code into the header or bottom panels. For an example of what I'm currently doing, look at this question CDATA.
The problem with Gradle is that it can't handle newline characters in the string which is to be inserted. If you filter out those characters you break the script. Here is a code sniplet:
task alljavadoc(type: Javadoc) {
source = javadocProjects.collect { project(it).sourceSets.main.allJava }
classpath = files(javadocProjects.collect { project(it).sourceSets.main.compileClasspath })
destinationDir = file("${buildDir}/docs/javadoc")
configure(options) {
header = "this is\na test which should fail"
}
}
The critical part is "header =". If you remove the '\n' character it will work just fine. Otherwise the call to javadoc, which Gradle makes, will fail with the following error:
Successfully started process 'command '/opt/jdk/jdk1.7.0_21/bin/javadoc''
javadoc: error - Illegal package name: ""
javadoc: warning - No source files for package a
javadoc: warning - No source files for package test
javadoc: warning - No source files for package which
javadoc: warning - No source files for package should
javadoc: warning - No source files for package fail
The actual java script that I wish to include is below. Note that I can't hack it by removing new line characters since that will break the script.
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- banner -->
<ins class="adsbygoogle"
style="display:inline-block;width:468px;height:60px"
data-ad-client="ca-pub-xxxxxxxxxxxxxxxxx"
data-ad-slot="xxxxxxxxx"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
As a sanity check I also passed in a string with new line characters directly to javadoc (manual) on the command line and it works just fine.
javadoc foo.java -header "This is a test
and so is this"
The output HTML:
<div class="aboutLanguage"><em>This is a test
and so is this</em></div>
</div>
I have an explanation, but i don't have a solution except for creating a new feature request in Gradle JIRA.
To generate a javadoc Gradle first generates the so-called argfile at build\tmp\javadocTaskName\javadoc.options that contains all individual options and than executes javadoc #full\path\to\build\tmp\javadocTaskName\javadoc.options command.
It is actually quite useful as you can debug the contents of that file by simply invoking javadoc #javadoc.options yourself from the command line.
It is possible to define multi-line values in the argfile by using the \ character at the end of each line inside the multi-line value.
The example header = "this is\na test which should fail" results in
-header 'this is
a test which should fail'
but we need to get
-header 'this is\
a test which should fail'
to tell javadoc that the value continues on the next line.
Now the problem is how to output that \ on each line.
The obvious attempt at header = "this is\\\na test which should fail" does not work, it will result in
-header 'this is\\
a test which should fail'
And even Groovy multi-line or slashy strings will not work and will result in similar double back slashes.
Because Gradle just replaces all single backslashes in the option values. The JavadocOptionFileWriterContext.writeValue(String) method is the culprit, the replaceAll("\\\\", "\\\\\\\\") line in particular (a regex that matches single backslash and replaces it with double backslash ).
This escaping is required for backslashes inside a line, but it should not escape a single backslash followed by the new line character. My regex-fu is not strong enough to write such a pattern, but it is surely possible.
Or even better, the escaping mechanism inside that method should replace newline characters with a single backslash followed by the newline to hide all this stuff and allow users to declare multi-line javadoc options without the need to think or even know that feature.
I would appreciate if somebody can create an issue in Gradle tracker as i can't do so from my current location. This sentence should be replaced with the link to the issue so that people with similar problem can vote and track its progress.
I tried to implement it in Gradle but I couldn't get it to work reliably on windows. If the options file has this:
-header 'this is\
a test which should fail'
It works nicely on linux/mac but fails on windows (tried on win7/java7 and some other windows+java6). I've tried with vanilla javadoc executable (without Gradle).
I'll get the fix into Gradle and it will work out of the box for linux/mac but not quite for windows. If you want to help out with windows support catch us at http://issues.gradle.org/browse/GRADLE-3099

Eclipse - spell checking inside String Quotes ""

When using Eclipse spell check inside comments is enabled, but when entering for example :
String myString = "why isnt this getttting cheackedd";
Eclipse isn't checking spelling inside quotes,
is there a option to set this enable ? or do i have to download a plugin for this matter ?
thanks
You need to disable
"Ignore Java String literals" under eclipse
Preferences->General->Editors->Text Editors->Spelling.

Categories