ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Burton" <bi...@progress.com>
Subject Re: command-line arguments
Date Wed, 04 Apr 2001 19:49:30 GMT
Hello,

Yes, I have been thinking along the same lines.  You don't have to modify
Main to support this.  Write a simple class that parses the command line
arguments setting the result as System properties or generates -D options
for passing to Ant.  Then invoke org.apache.tools.ant.Main with whatever
arguments you desire.  Ant's Main class will invoke System.exit when
complete so your class won't be returned to after you invoke Ant.

Then your platform specific scripts can be very short since they don't
handle arguments themselves.  You need just enough to invoke your Ant
wrapper class plus a classpath including ant.jar and the XML parser of
your choice.

One of the issues you will run into is even with logging set -quiet, Ant
outputs stuff that you don't want when running an application like BUILD
SUCCESSFUL and the build time.  I think this is a bug as -quiet should
really be quiet unless there is an error.  So you will have to write your
own logger class that doesn't output this noise.  Then make your wrapper
always invoke Ant adding the -logger your-logger-class. If I recall
correctly, you also have to add -quiet to get rid of the Build File:
build.xml at the start of the "build."  Here's very simple logger to get
you started:

package com.mycompany.tools.ant;

import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.NoBannerLogger;
import org.apache.tools.ant.Project;

/**
 * Extends NoBannerLogger by changing default level to MSG_WARN (-quiet)
 * and disables the build status messages, i.e. BUILD SUCCESSFUL and
duration
 * output.
 */
public class Logger extends NoBannerLogger {

    public Logger()
    {
        msgOutputLevel = Project.MSG_WARN;
    }

    public void buildFinished(BuildEvent event) {
        Throwable error = event.getException();

        if (error != null) {
            err.println(lSep + "EXECUTION FAILED" + lSep);
            //error.printStackTrace(err);
            err.println(error.getMessage());
        }
    }

}

-Bill

"Halim, Salman" wrote:
> 
> hi,
> 
> i have started using ant quite recently -- we're thinking of using its
> platform independent features to replace batch files and shell scripts (in
> part) rather than as an installation tool.  toward that end, i wanted to
> modify the org.apache.tools.ant.Main class to set all command-line
> parameters following a lone hyphen (-) as properties (of the form 'arg1',
> 'arg2' etc.).
> 
> any thoughts on this?  good idea/bad idea/been done etc.?
> 
> thank you in advance!

Mime
View raw message