I have an ant buildfile that is often run from vastly different environments. By default, I'm looking for the same behavior as using:
ant -q
However, since some team member's configurations vary, specifying the -q option in each person's environment is not easily accomplished in a uniform way (some people run ant from eclipse, some from the command line, some from debugging/profiling tools, etc. Each with a different method for specifying ant arguments like -q)
So I'm seeking a way for the ant file to call itself quietly...
Something like the following would be ideal:
<target name="default">
<antcall quiet="yes" target="build" /> <!-- doesn't work -->
</target>
Can anyone think of anyway to accomplish something like this? All I'm after is for the build to run quietly whenever the default target is ran, regardless of whether -q is set.
To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.
Message events are logged according to their Ant logging level, mapping directly to a corresponding Log4j level. To use Log4j you will need the Log4j JAR file and a log4j. properties configuration file. Both should be placed somewhere in your Ant classpath.
The setproxy task can be used to explicitly set a proxy in a build file. This manipulates the many proxy configuration properties of a JVM, and controls the proxy settings for all network operations in the same JVM from that moment.
This task is used to delete a single file, directory or subdirectories. We can also delete set of files by specifying set of files. It does not remove empty directory by default, we need to use includeEmptyDirs attribute to remove that directory.
Based on other answers:
<macrodef name="quiet">
<element name="body" implicit="yes"/>
<sequential>
<script language="javascript">
project.getBuildListeners().firstElement().setMessageOutputLevel(0);
</script>
<body/>
<script language="javascript">
// TODO: restore last log level
project.getBuildListeners().firstElement().setMessageOutputLevel(2);
</script>
</sequential>
</macrodef>
<target name="test-quiet">
<quiet>
<echoproperties/>
</quiet>
</target>
One option might be to set the logging level from within the target.
You can access loggers by means of a short script task. Something like:
<target ... >
<script language="javascript">
var logger = project.getBuildListeners( ).firstElement( );
logger.setMessageOutputLevel( 0 );
</script>
...
</target>
I'm not familiar with how Eclipse calls Ant, but it might be necessary to iterate over all the build listeners to get 'silence' all round.
Suggest that how ever you end up doing this, you make it easy to switch back to verbose running.
Edit - response to comment: You can access project properties from within the script using project.getProperty()
:
<property name="verboseFlag" value="1" />
<script language="javascript">
var logger = project.getBuildListeners().firstElement();
var verboseMode = project.getProperty( "verboseFlag" )
if ( ! "1".equals( verboseMode ) )
logger.setMessageOutputLevel( 0 );
</script>
(Somewhat old) API docs are here, including for the project
class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With