Capture Ant output - ant

Can anyone suggest to me the best way to capture the output from an Ant command?
I'm writing some routing tests for sun spot devices. The command itself returns network statistics. I'm trying to write something which will dump all these results into a more visual application.
I'm on Windows Vista.

you could simply use the ant recorder task:
<record name="build.log"> </record>
this has the advantage of having the output written both to the screen and to the log file, which isn't the case when doing output redirection ant debug > build.log or calling ant with the -logfile option.

Use -logfile <file> option to write the output to a file. Like #jespere said, you can get even more control by implementing your own logger or listener.

Simply use the "-verbose" flag and designate a file for the command line output using ">"?
For example:
ant -verbose > output.txt

You can define a custom Ant logger which will receive all Ant output. With that you can do whatever you want with the output.

Related

Get bazel-bin directory easily in the terminal

I have generated some output files using bazel build, but its is a bit tedious to specify the path of the bazel-bin directory everytime I need to access the output.
In deeply nested bazel projects, not only do I need to get the specific repository, /Users/username/repos/organisation/folder/folder/repo, I also need to add the bazel-bin/folder1/folder2/folder3/folder4/binary_i_want. I would prefer to say $output/binary_i_want. Bazel should be able to get the project directory (as it looks up the workspace file), and find the bazel-bin, and then look for the equivalent directory I am in. This is because I might not be running it directly, but instead copying this file to an android device, with adb push.
Is this possible? Thank you
You can use $(bazel info bazel-bin)/binary_i_want for this.
Edit: Getting the complete path to an artifact generate by a rule is a bit more involved. One option using jq could be:
$(bazel info workspace)/$(bazel aquery //:some_path --output jsonproto 2>/dev/null | jq -r ".artifacts[0].execPath")
(Inspired by this answer: Bazel: How do you get the path to a generated file?)

jacaco unit test coverage reports path and file name(as jacaco.exec)

I am running following maven command on jenkins
clean org.jacoco:jacoco-maven-plugin:prepare-agent install
The jacaco exec file created as shown below.
target/coverage-reports/jacoco-int-test.exec
I would like to generate this file under following path, since all other Project use same conventions.
target/jacoco.exec
I could not figureout why it is generated in this way and how to modify it as "target/jacoco.exec"
I will use this report in sonarqube analysis.
I would appriciate your helps, thanks in advance.
As per documentation of prepare-agent - destFile parameter controls location of output file, whose default is ${project.build.directory}/jacoco.exec which is exactly target/jacoco.exe. So check your POMs to find where it is modified to be target/coverage-reports/jacoco-int-test.exec.

Multiple Ant properties files

Ant seems to be ignoring one of my properties files.
<property file="local.properties" />
<property file="build.properties" />
build.properties contains the typical properties my team wants to use. I'm introducing local.properties which contains overrides for my specific workstation. We're using Eclipse for this project (I'm using Kepler), but regardless of whether I build in Eclipse or build via the command line the build fails because it is using some values in build.properties even though local.properties contains overrides.
In my specific case, my version of Java is newer than the other developers/environments. Despite specifying the version I have in local.properties, it still tries to use the compiler for the version in build.properties.
I know the values are fine because if I put my local properties in build.properties everything works.
Eclipse doesn't care about your build.xml or your properties files. That's only with Ant.
Try running ant with the -d flag, and capture STDOUT and STDERR. This will show you whether or not the local.proeprties is being read in and what values are set. It will say whether or not it's attempting to read local.properties, whether it found local.properties, and if so, what properties are being set.
Also remember that properties are set first come/first serve. You didn't say where in your build.xml you're reading in local.properties. It could be that this is being read in a target while other properties are set outside of targets. Even if they appear later in the build.xml file, properties set outside of any target are set first. If these are set, and you read in local.properties, local.properties isn't going to over ride them. I mention this because it was a problem I ran into here. Someone had a bunch of <property/> tasks placed at the end of their build.xml,and they didn't realize that these would be set before any target was run.
Again, try this:
Unix and Mac:
$ ant -d 2>&1 | tee ant.out # Allows you to see and capture the results
Windows
$ ant -d > ant.out 2>&1 # There's no "tee" command in Windows.
The output of ant.out will be thousands of lines long, but it'll help you figure out what's going on. What you post looks correct.

Configuring log4j at runtime

I'm using org.apache.tools.ant.listener.Log4jListener to manage logging with my ant script. The ant script is highly configurable and designed to be run different ways with different parameters and therefore I need to be able to log to files specified at runtime. I have a log4j.properties which specifies a log file to be build.log, and despite my attempts to launch ant redefining properties defined in log4j.properties have been unsuccessful.
The build ignores them and continues to write to build.log. I haven't found much support regarding writing to custom files unless it's in Java with their Logger class.
Perhaps I'm thinking this through wrong. log4j.properties isn't treated in the same way as a property file in an ant script (hence overrideable from the command line)? Is there a way I can do this intelligently without writing a custom task or something?
You setup your log4j.properties file using a system property that you can define dynamically on the command line. The property below is "${logfile.name}". An example log4j configuration would be like this:
# logfile is set to be a RollingFileAppender
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=${logfile.name}
log4j.appender.logfile.MaxFileSize=10MB
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=[%-5p]%d{yyyyMMdd#HH\:mm\:ss,SSS}\:%c - %m%n
The command line option to pass a property, when calling "ant", is "-Dlogfile.name={runtime path/filename of log file}". Replace {runtime path/filename of log file} with your file name. When ant is run this value is set as a system property. That system property is then substituted into the log4j.properties at runtime.
http://ant.apache.org/manual/running.html

Is there a timeout for a batch file?

I am using a bat file on a Windows 2000 SP4 server to copy database files while the database is shut down. Once the bat file hits the xcopy command, it does the copy, but never returns to the bat file to continue with the other commands (start up the database, etc). I should mention that the xcopy takes several hours. Is there some sort of time out or time max with bat files? Is this normal? If so, is there any way around this?
Batch files don't timeout. It sounds like you might be running into a prompt from XCOPY, like an "Are you sure" prompt.
Make sure you've added the necessary command-line switches to XCOPY to make it silent.
The ones I'm aware of are:
-Y to suppress prompts about overwriting files
-C continue even if errors occur
Also, make sure that you are running the XCOPY.EXE app, and not finding an XCOPY.BAT file somewhere on your path. (calling a batch file from a batch file prevent returning, unless you use the CALL command)
And, be sure you are not overwriting the batch file itself during the XCOPY.
Presumably everything looks OK in your backup.log file?
It looks like you are redirecting STDOUT to your log file, but not STDERR - would suggest adding 2>&1 to the end of the command line to ensure you're not missing any error information from the log.
There's no timeout that I'm aware of on .bat or .cmd files. However, there may be on the process that's launching it? How are you launching it?

Resources