Codesniffer to exit after identiying error before proceeding any further - jenkins

I want codesniffer to produce error output in CLI and exit before proceeding any further to avoid running other tests like behat, phpmd, phpcpd so that comes after.
Current code (as shown below) creates a XML report with errors listed in but it won't terminate the process. How should I modify the code in order to have a XML report, CLI error output and terminate the process in case of an error?
CURRENT CODE in PHING:
<target name="codesniffer-phpcs">
<echo msg="Checking coding standards ..." />
<tstamp />
<phpcodesniffer standard="PSR2" showWarnings="true" format="full">
<fileset refid="sourcecode" />
<formatter type="checkstyle" outfile="phing/phpcs/psr2_${DSTAMP}-${TSTAMP}.xml" />
</phpcodesniffer>
</target>
This is what I would like to see in CLI as well as having XML file:
FOUND 4 ERROR(S) AFFECTING 4 LINE(S)
--------------------------------------------------------------------------------
69 | ERROR | There must not be more than one property declared per statement
108 | ERROR | The abstract declaration must precede the visibility
657 | ERROR | Expected 1 space after comma in function call; 2 found
812 | ERROR | A cast statement must be followed by a single space
--------------------------------------------------------------------------------

I think the attribute "haltonerror" inside the task will be your friend here.
http://www.phing.info/docs/guide/stable/apcs48.html

Related

FSL (preprocessing BedPostX) Error: Error in logfile. What does this mean?

When I do BedpostX FSL preprocessing I get this message:
----- Bedpostx Monitor -----
1 slices processed out of 62
2 slices processed out of 62
.
.
.
59 slices processed out of 62
60 slices processed out of 62
An error ocurred. Please check file /Users/...../bedpostx.bedpostX/logs/bpx_postproc.e68944
/Users/..../bedpostx.bedpostX/monitor: line 15: kill: (9187) - No such process
logout
[Process completed]
So I checked the log file:
Error in logfile: *File "/Applications/FSL/bin/imglob", line 78
print "Usage: $0 [-extension/extensions] <list of names>"
^
SyntaxError: Missing parentheses in call to 'print'
File "/Applications/FSL/bin/imglob", line 78
print "Usage: $0 [-extension/extensions] <list of names>"
^
SyntaxError: Missing parentheses in call to 'print'
File "/Applications/FSL/bin/imglob", line 78
print "Usage: $0 [-extension/extensions] <list of names>"
^
SyntaxError: Missing parentheses in call to 'print'
File "/Applications/FSL/bin/imglob", line 78
print "Usage: $0 [-extension/extensions] <list of names>"
^
SyntaxError: Missing parentheses in call to 'print'*
But I dont know really what it means. It is really strange cause the process was almost done (see above at 61 it stopped). I got almost every outputs. So my questions are:
What does the error mean?
Is the process still completed? (see above there it is said)
If not what can I do to fix the problem?
Here is another screenshot:
So finally I got a tip from another forum. the bedpostx command is a shell script which uses sometimes python environment itself. Due to the fact that I on my system python 3.5 was installed the error occurs. So I just started the bedpostx command again but this time in a python 2.7 environment terminal.
cheers
manun

Running an executable from a different working directory using ant

Is it possible to run an executable from ant using a working directory other than the one which contains the executable? This small ant project demonstrates what I'm trying to achieve.
Folder structure
ant test
| build.xml
| bin
| | debug
| | | program.exe
| | release
| | | program.exe
| | inputs
| | | ...
| | outputs
| | | ...
build.xml
<project name="test" basedir="./">
<target name="run">
<exec executable="${configuration}\program.exe" dir="bin"/>
</target>
</project>
${configuration} is set to release.
bin needs to be the working directory so the executable can reference files in inputs and outputs correctly, so I want to be able to run the executable contained in bin/release from the bin directory. However, ant fails to find the executable:
BUILD FAILED
D:\ant test\build.xml:6: Execute failed: java.io.IOException: Cannot run program "release\program.exe" (in directory "D:\ant test\bin"): CreateProcess error=2, The system cannot find the file specified
I am able to work around this on windows by launching cmd.exe in the bin directory and then passing it the parameter release\program.exe, but I need to be able to use the ant file on multiple platforms, so I was hoping to find a consistent syntax.
One option I considered was using conditional tasks and having separate syntaxes for windows and unix. However, in the actual project, the exec statement occurs inside a macro, and the target calls the macro a large number of times. Since conditions can only affect things at the target level, I would have to duplicate the long list of macro calls for each syntax I wanted to target, e.g.
<target name="runAll" depends="runAll-win,runAll-unix"/>
<target name"runAll-win" if="win">
<myMacro-win .../>
<!-- Huge list of macro calls -->
...
<myMacro-win .../>
</target>
<target name"runAll-unix" if="unix">
<myMacro-unix .../>
<!-- Huge list of macro calls -->
...
<myMacro-unix .../>
</target>
The dir attribute specifies the working directory but the executable path is resolved against the project basedir. Hence the task will search for the executable D:\ant test\release\program.exe.
A simple solution is to add resolveexecutable="true" to the task call:
<target name="run">
<exec executable="${configuration}\program.exe" dir="bin" resolveexecutable="true" />
</target>
From the exec task documentation:
When this attribute is true, the name of the executable is resolved firstly against the project basedir and if that does not exist, against the execution directory if specified. On Unix systems, if you only want to allow execution of commands in the user's path, set this to false. since Ant 1.6

nant script to execute sqlplus , does not return error code

My nant script to execute sqlplus.exe looks like following
exec program="sqlplus.bat"
basedir="${base.dir}"
workingdir="${base.dir}" output="log.txt" failonerror="false" resultproperty="execresult"
arg line="${app.sqlplus} ${db.username} ${db.password} ${db.schema} ${var.exec.file} ${db.username} ${db.password}"
end exec
SqlPlus.bat has following contents
echo exit | %1 %2/%3#%4 #%5 %6 %7
I would ideally want to check the "execresult" which is the error code from exec command and show the respective message.
I have tried using the following statement in my SQL file but it did not help.
WHENEVER SQLERROR EXIT SQL.SQLCODE
Could you please point out the problem and possible solution ?
Easiest answer is to remove the output and failonerror on your exec task because then NAnt will naturally show the message as it fails the build. I'm guessing you've avoided that because you want to handle some non-zero exit codes as warnings or success because you want to handle some non-zero exit codes as warnings or success. In that case:
<loadfile file="log.txt" property="execoutput" />
<fail if="${int::parse(execresult)>8" message="${execoutput}" />

ant p4changes type="submitted" errors out

I have a directory structure managed by perforce checked out to my local system.
In my ant build targets of my java code. I want surf down into some subdirectory "Subdirectory_Start_here" I want to know what the highest change list information for all files under that directory.
-depot
|
|-Directory A
| |
| |-directory A.1
| |-directory A.2
| | |-Subdirectory_Start_here
| | |
| |-directory A.3
|
|-Directory B
My ant build.xml target
<target name="snapshot" depends="fully_configured,set_revision_slot">
.......
<echo>************************************^^^^^^^^^^^^^^^^^^${env.LOCAL_FS_PATH_TO_P4_MANAGED_DIRECTORY}</echo>
<taskdef resource="com/perforce/p4java/ant/tasks/P4Tasks.properties" classpath="../../../lib/p4ant-2010.1.293250.jar:../../../lib/p4java-2010.1.269249.jar" />
<p4jchanges maxmostrecent="1" client="peterc_peterc-ml" property="platformVersion" longdesc="true" type="submitted" files="${env.LOCAL_FS_PATH_TO_P4_MANAGED_DIRECTORY}/Directory A/directory A.2/Subdirectory_Start_Here/*"/>
<echo>************************************PLATFORM VERSION^^^^^^^^^^^^^^^^^^ ${platformVersion}</echo>
<exec executable="${NF}" dir="${COMMANDLINE_DIR}" failonerror="true">
<arg line="platformVersion:${platformVersion}"/>
</exec>
</target>
According to http://www.perforce.com/perforce/doc.current/manuals/p4ant/p4tasks.html#p4jchanges a type of "submitted" should be allowed. Submitted works on the standalone p4 command. But I am getting.
'submitted' is not a permitted value for com.perforce.p4java.core.IChangelist$Type
If I take type out. The echo does contain a changelist number that is different than if I don't have a files property. So it appears that I get the latest pending or submitted change info from "Subdirectory_Start_Here" and down.
Any thoughts?????
Thanks for any help?
It's a bit daft, but try 'SUBMITTED'.
<p4jchanges maxmostrecent="1" longdesc="true" type="SUBMITTED" />

How can I ensure all output from Ant's exec task goes to stdout?

The Ant exec task has an output property which can be used to tell Ant where the output goes. I've used it to redirect the output to a file. The thing is, if I don't do something with the output, the stuff that Ant prints isn't that much of a help - it's not complete.
Is there someway of setting the output property to System.out?
When executing a batch file with ant's apply or exec tasks on Windows, I found there are special cases where some of the stdout and stderr is not captured by ant. (For example: if you call a batch file that in turn calls other commands (like node.exe), then the stdout and stderror from the child node.exe process is lost.)
I spent a long time trying to debug this! It seems that the batch file's stdout and stderr is captured, however commands called by the batch file are somehow not seen by ant. (perhaps because they are separate child processes). Using the output and error attributes as suggested above doesn't help because only some of the stdout and/or stderr is captured.
The solution I came up with (a hack) is to add these arguments at the end of the command:
<!--Next arg: forces node's stderror and stdout to a temporary file-->
<arg line=" > _tempfile.out 2<&1"/>
<!--Next arg: If command exits with an error, then output the temporary file to stdout, -->
<!--delete the temporary file and finally exit with error level 1 so that -->
<!--the apply task can catch the error if #failonerror="true" -->
<arg line=" || (type _tempfile.out & del _tempfile.out & exit /b 1)"/>
<!--Next arg: Otherwise, just type the temporary file and delete it-->
<arg line=" & type _tempfile.out & del _tempfile.out &"/>
Because this hack only applies to windows, remember to add #osfamily="windows" to the apply or exec task. And create similar task(s) for `#osfamily="unix", etc but without these extra arguments.
The output of exec does go to standard out unless you specify the output attribute.
If you want to output to System.out, then simply do not specify the "output" attribute. If you would like to redirect to a file AND print it to System.out, you can use the tee command, which will redirect output to a given file and also echo it to standard out... I do not know if Windows supports "tee" or an equivalent.
Maybe you want to look at the error, logError, and errorproperty attributes of the exec task too. These deal with the handling of the standard error stream from the exec'd process. There may be useful information there that is going awol for some reason - which might account for the incompleteness you see.
But, if the exec'd process decides to close stdout or stderr and send them elsewhere - there's little you can do.
I have faced similar problem: the output of command execution was suppressed. Perhaps that is the side effect when running cmd under WinXP (I an using maven-antrun-plugin). Anyway setting output="con" worked out perfectly:
<configuration>
<target>
<exec executable="cmd" output="con">
<arg value="/c" />
<arg value="..." />
</exec>
</target>
</configuration>
Working with Ant and Gruntjs:
For anyone trying to get this to work using Gruntjs. I was able to get it working by doing the following (in combination with darcyparker's answer).
In my Ant Build File:
<target description="run grunt js tasks" name="grunt">
<exec dir="/path/to/grunt" executable="cmd" failonerror="true">
<arg value="/c"/>
<arg value="jshint.bat"/> // I broke each task into it's own exec
<arg line=" > jshint.log 2<&1"/>
<arg line=" || (type jshint.log & del jshint.log & exit /b 1)"/>
<arg line=" & type jshint.log & del jshint.log &"/>
</exec>
<exec dir="/path/to/grunt" executable="cmd" failonerror="true">
// another grunt task (IE: uglify, cssmin, ect..)
</exec>
</target>
jshint.bat
#echo off
pushd "C:\path\to\grunt\"
#ECHO _____________________________________________
#ECHO GRUNT JSHINT
#ECHO _____________________________________________
grunt jshint --stack >>jshint.log
NOTE: Path to grunt would be where your Gruntfile.js is located. Also note, I had to initially create the log file (to get it to work with darcyparker's answer) which would output the stack trace from that particular task. This would then give me the grunt task stack output from wherever I call my ant target.
Finally note that pushd "C:\path\to\grunt\" won't be necissary if your bat files are in the same directory as your Gruntfile.js.
I was experiencing this same kind of issue trying to get the build process to fail in Ant after Karma tests intentionally failed, and executing them with "grunt test".
Just added /c before "grunt test", and it worked like a charm
<target name="unittest">
<echo>*** KARMA UNIT TESTING ***</echo>
<exec dir="api_ui" executable="cmd" osfamily="windows" logError="yes" failonerror="true">
<arg value="/c grunt test"/>
</exec>
</target>

Resources