Display :make compiler output for a Java compiled program - java

I am trying to get NeoVim to compile a simple Java program. The program itself has no ideas but I am not able to exactly output the compiled program.
I have this in my config:
autocmd Filetype java set makeprg=javac\ %
set errorformat=%A%f:%l:\ %m,%-Z%p^,%-C%.%#
map <F9> :make<Return>:copen<Return>
map <F10> :cprevious<Return>
map <F11> :cnext<Return>
I am able to see errors and compile but don't know how to see the output directly in NeoVim. Any way I can do so because I couldn't figure it out nor could find any useful information online.

In Neovim you have 2 options:
suspend the editor (Ctrl+Z), run your program and then return to editor with fg command
use build-in terminal
In Vim you would also have 3rd option: to use :!, but in Neovim it doesn't support input yet (see issue #1496)
If you choose option 2 then you simply use command :term java %<
But you would probably want it in a new window (in Neovim :term takes over the current one).
In such case you would need to use command: :new term://java %<
So in conclusion you would need to add to your init.nvim the following:
autocmd Filetype java nnoremap <F8> :new term://java %<<CR>

Related

How do you log all the compiler options being used by Gradle?

I'm using Gradle 7.4.2. I'm trying to see what it uses for generatedSourceOutputDirectory (among other CompileOptions.
I've tried:
tasks.compileJava {
println(options.generatedSourceOutputDirectory.toString())
}
but this prints an unhelpful:
task ':lib:compileJava' property 'options.generatedSourceOutputDirectory'
Sleuthing around the code itself on Github, I see that's its defaults are (seemingly) mangaged via XML code here.
How can I see what the current compile options are?
The option generatedSourceOutputDirectory is of type DirectoryProperty; therefore, to get the value that it holds, you need to call get().

How to execute bash script using karate and fail if script fails

I'm trying to execute bash script using karate. I'm able to execute the script from karate-config.js and also from .feature file. I'm also able to pass the arguments to the script.
The problem is, that if the script fails (exits with something else than 0) the test execution continues and finishes as succesfull.
I found out that when the script echo-es something then i can access it as a result of the script so I could possibly echo the exit value and do assertion on it (in some re-usable feature), but this seems like a workaround rather than a valid clean solution. Is there some clean way of accessing the exit code without echo-ing it? Am I missing on something?
script
#!/bin/bash
#possible solution
#echo 3
exit 3;
karate-config.js
var result = karate.exec('script.sh arg1')
feture file
def result = karate.exec('script.sh arg1')
Great timing. We very recently did some work for CLI testing which I am sure you can use effectively. Here is a thread on Twitter: https://twitter.com/maxandersen/status/1276431309276151814
And we have just released version 0.9.6.RC4 and new we have a new karate.fork() option that returns an instance of Command on which you can call exitCode
Here's an example:
* def proc = karate.fork('script.sh arg1')
* proc.waitSync()
* match proc.exitCode == 0
You can get more ideas here: https://github.com/intuit/karate/issues/1191#issuecomment-650087023
Note that the argument to karate.fork() can take multiple forms. If you are using karate.exec() (which will block until the process completes) the same arguments work.
string - full command line as seen above
string array - e.g. ['script.sh', 'arg1']
json where the keys can be
line - string (OR)
args - string array
env - optional environment properties (as JSON)
redirectErrorStream - boolean, true by default which means Sys.err appears in Sys.out
workingDir - working directory
useShell - default false, auto-prepend cmd /c or sh -c depending on OS
And since karate.fork() is async, you need to call waitSync() if needed as in the example above.
Do provide feedback and we can tweak further if needed.
EDIT: here's a very advanced example that shows how to listen to the process output / log, collect the log, and conditionally exit: fork-listener.feature
Another answer which can be a useful reference: Conditional match based on OS
And here's how to use cURL for advanced HTTP tests ! https://stackoverflow.com/a/73230200/143475
In case you need to do a lot of local file manipulation, you can use the karate.toJavaFile() utility so you can convert a relative path or a "prefixed" path to an absolute path.
* def file = karate.toJavaFile('classpath:some/file.txt')
* def path = file.getPath()

Parametrized JBehave tests

I have a story with parameters:
Given save in the <fileName> the data from <sqlQuery>
Then...
Examples:
fileName |sqlQuery
file.txt |query1
I run my test on particular environment with maven -Denvironment=DEV.
Now I would like to run this test on UAT using -Denvironment=UAT but the problem is that the sqlQuery is different then. How to indicate in the java code that if -Denvironment=DEV then use query1 but if -Denvironment=UAT then use query2 using JBEHAVE stories?
Does anyone cen help me with that?
In my opinion the easiest and clanest way is to provide different parameters for each environment directly in the story/scenario,
and pick a proper parameter in the java code depending on the environment.
We are using this method for 3 test environments: DEV, UAT, PRE and it work for us very well.
When the story failed then you do not neet to dig into logs or implementation to find which value of the parameter was used, everything is visible in JBehave report.Also changing parameters is easier, the tester just changes the story, he does not need to look into the implemetation in code.
Given save in the <fileName> the data from the query:
- DEV:<DevSqlQuery> UAT:<UatSqlQuert> PREPROD:<PreSqlQuery>
Then...
Examples:
|fileName |DevSqlQuery|UatSqlQuery|PreSqlQuery|
|file.txt |query1 |query2 |query3 |

imageJ plugin argument

Hello I am trying to pass arguments to my ImageJ PlugIn. However it seems no matter what I pass, argument string will be considered as empty by the program. I couldn't find any documentation on the internet about THAT issue.
My Java plugIn looks like this, and compiles fine.
import ij.plugin.PlugIn;
public class Test implements PlugIn {
public void run(String args) {
IJ.log("Starting plugin Test");
IJ.log("args: ." + args + ".");
}
}
I compile, make a .jar file and put it into the ImageJ plugins folder.
I can call it with the ImageJ userInterface (Plugin>Segmentation>Test) and the macro recorder will put the command used:
run("Test");
Then my code is executed, the log window pops-up as expected:
Starting plugin Test
args: ..
I can manually run the same command in a .ijm file, and get the same result.
However, when I run the following macro command:
run("Test", "my_string");
I get the same results in the log window:
Starting plugin Test
args: .. // <- I would like to get "my_string" passed there
Where it should have displayed (at least what I expect it to do)
Starting plugin Test
args: .my_string.
So my question is: how can I pass parameters to PlugIn and especially how to access them?
Many thanks
EDIT
Hey I found a way to bypass that:
Using the Macro.getOptions() : this method will retrieve the string passed in argument to the plugin.
However, I still can't find a way to pass more than 1 string argument. I tried overloading the PlugIn.run() method but it doesn't work at all.
My quick fix is to put all my arguments in 1 string, and separating them by a space. Then I split this string:
String [] arguments = Macro.getOptions().split(" ");
I don't see a more convenient way to get around that. I can't believe how stupid this situation is.
Please, if you have a better solution, feel free to share! Thanks
You are confusing the run(String arg) method in ij.plugin.Plugin with the ImageJ macro command run("command"\[, "options"\]), which calls IJ.run(String command, String options).
In the documentation for ij.plugin.Plugin#run(String arg), it says:
This method is called when the plugin is loaded. 'arg', which may be blank, is the argument specified for this plugin in IJ_Props.txt.
So, arg is an optional argument that you can use in IJ_Props.txt or in the plugins.config file of your plugin to assign different menu commands to different functions of your plugin (see also the excellent documentation on the Fiji wiki).
To make use of the options parameter when running your plugin from macro code, you should use a GenericDialog to get the options, or (as you apparently learned the hard way) use the helper function Macro.getOptions().

execute commands of another program from a tidesdk program

I'm testing tidesdk.
I have a java program that reads from standard input.
I run the program through the console console
java -cp MyProgram.jar package.MyMainClass
And then execute commands and get results.
there any way to do with tidesdk?
Edit:
The problem was that calls the java program with a list of one element (which contained the command separated by spaces)
It solved with passing every word to a item of list (and removing the spaces).
Right now I have porblemas to write standard input. This is what I'm trying.
var input = Ti.Process.createPipe();
var process = Ti.Process.createProcess({
args:['java', '-cp', 'C:/.../MyProgram.jar', 'package.MyMainClass'],
stdin: input
});
//process.setOnReadLine(function(line) { alert(line) });
process.launch();
input.write("comand parameter1 parameter2\n"); //This line does not work
The java program starts. But never gets a command.
Checkout Documentation of Ti.Process.createProcess. That is exactly what you are looking for:
http://tidesdk.multipart.net/docs/user-dev/generated/#!/api/Ti.Process

Categories

Resources