How to execute user exit status in my jruby java program?

I am working on a generalized validation utility database that I want to distribute as a JAR and automate with Ant. Using only Java, I can do something like

... int validationResults = this.validate(); System.exit(validationResults) // via Ant: 1 = "BUILD FAILED", 0 = "BUILD SUCCESSFUL" ... 

Use validation in planned assemblies using CI systems.

However, I write this in jRuby instead of Java (for learning). I tried the following methods, but they do not run "BUILD FALSE" in Ant.

 java.lang.System.exit(1) # using "require 'java'" at the the top of the file Kernel.exit 1 exit 1 

I saw tickets to the jRuby tracker about this (e.g. JRUBY-1650 ), but I could not find a solution to my problem.

I am running jRuby v1.6.6 and Warbler v1.3.2. The Ant target is as follows:

 <target name="validate"> <java jar="./validator.jar" fork="true" /> </target> 

Am I not doing it right, or does jRuby not support it (yet)?

+4
source share
2 answers

I assume that you will run your jRuby code from java Ant task .

In order to get Ant to fail in case of non-zero exit code from the jRuby process, you must set the failonerror attribute of the java task to true .

+2
source

Here's the kludge that I use to trigger a build failure when ant cannot otherwise recognize the exit code. This requires ant-contrib .

In ant:

 <delete file="${java.io.tmpdir}/build-executable-error"/> <exec executable= ... /> <if> <resourceexists> <file file="${java.io.tmpdir}/build-executable-error"/> </resourceexists> <then> <loadfile srcfile="${java.io.tmpdir}/build-executable-error" property="build.failure.message"/> <fail message="${build.failure.message}"/> </then> </if> 

Then the executable file is responsible for creating and filling the ${java.io.tmpdir}/build-executable-error file in any error scenario.

+1
source

Source: https://habr.com/ru/post/1400984/


All Articles