ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Donald <dona...@apache.org>
Subject Re: [VOTE] Ant 1.3 release plan
Date Tue, 10 Apr 2001 04:31:36 GMT
Thanks - I finally got around to adding this in. I added some basic
documentation - feel free to correct any of the errors I introduced ;)

At 07:31 12/3/01 +0000, Josh Lucas wrote:
>Conor MacNeill wrote:
>> 
>> Henri,
>> 
>> I would see this as writing a Java class so I could have this in my build
>> file
>> <rpm spec="ant.spec" src="blah"/>
>> 
>> I'm not overly familiar with building RPMs so I am not sure what aspects
you
>> would control from the task interface. The easiest way to get this going
>> would be to exec to the rpm command when you are running on Linux. I don't
>> know what it would take to make this pure Java and runnable on Windows.
>> 
>> Conor
>> 
>
>I have attached a first cut at a RPM task. It is very simple now but I
>am able to use it in my rpm building process.
>
>The supported attributes:
>
>specFile = obviously the name of the spec file to be used
>
>topDir = this is the directory which will have the expected
>subdirectories, SPECS, SOURCES, BUILD, SRPMS.  If this isn't specified,
>the baseDir value is used
>
>cleanBuildDir = this will remove the generated files in the BUILD
>directory
>
>removeSpec = this will remove the spec file from SPECS
>
>removeSource = this will remove the sources from SOURCES
>
>command = very similar idea to the cvs task.  the default is "-bb"
>
>output/error = where standard output and error go
>
>I realize that this might not be useful for everyone so I would
>understand if a rpm task wouldn't make it into the 'official' taskdef
>list but I wanted to send this anyway...  
>
>Let me know if you have any questions.
>
>
>josh
>import org.apache.tools.ant.*;
>import org.apache.tools.ant.taskdefs.*;
>import org.apache.tools.ant.types.Commandline;
>import java.io.*;
>
>/**
> *
> *  @author lucas@collab.net
> *
> */
>
>public class Rpm extends Task {
>    
>    /**
>     * the spec file
>     */
>    private String specFile;
>
>    /**
>     * the rpm top dir
>     */
>    private File topDir;
>
>    /**
>     * the rpm command to use
>     */
>    private String command = "-bb";
>
>    /**
>     * clean BUILD directory
>     */
>    private boolean cleanBuildDir = false;
>
>    /**
>     * remove spec file
>     */
>    private boolean removeSpec = false;
>
>    /**
>     * remove sources
>     */
>    private boolean removeSource = false;
>
>    /**
>     * the file to direct standard output from the command
>     */
>    private File output;
>
>    /**
>     * the file to direct standard error from the command
>     */
>    private File error;
>
>    public void execute() throws BuildException {
>        
>        Commandline toExecute = new Commandline();
>
>        toExecute.setExecutable("rpm");
>        if (topDir != null) {
>            toExecute.createArgument().setValue("--define");
>            toExecute.createArgument().setValue("_topdir" + topDir);
>        }
>
>        toExecute.createArgument().setLine(command);
>
>        if (cleanBuildDir) {
>            toExecute.createArgument().setValue("--clean");
>        }
>        if (removeSpec) {
>            toExecute.createArgument().setValue("--rmspec");
>        }
>        if (removeSource) {
>            toExecute.createArgument().setValue("--rmsource");
>        }
>
>        toExecute.createArgument().setValue("SPECS/" + specFile);
>
>        ExecuteStreamHandler streamhandler = null;
>        OutputStream outputstream = null;
>        OutputStream errorstream = null;
>        if (error == null && output == null) {
>            streamhandler = new LogStreamHandler(this, Project.MSG_INFO,
>                                                        Project.MSG_WARN);
>        }
>        else {
>            if (output != null) {
>                try {
>                    outputstream = new PrintStream(new
BufferedOutputStream(new FileOutputStream(output)));
>                } catch (IOException e) {
>                    throw new BuildException(e,location);
>                }
>            }
>            else {
>                outputstream = new LogOutputStream(this,Project.MSG_INFO);
>            }
>            if (error != null) {
>                try {
>                    errorstream = new PrintStream(new
BufferedOutputStream(new FileOutputStream(error)));
>                }  catch (IOException e) {
>                    throw new BuildException(e,location);
>                }
>            }
>            else {
>                errorstream = new LogOutputStream(this, Project.MSG_WARN);
>            }
>            streamhandler = new PumpStreamHandler(outputstream, errorstream);
>        }
>
>        Execute exe = new Execute(streamhandler, null);
>
>        exe.setAntRun(project);
>        if (topDir == null) topDir = project.getBaseDir();
>        exe.setWorkingDirectory(topDir);
>
>        exe.setCommandline(toExecute.getCommandline());
>        try {
>            exe.execute();
>            log("Building the RPM based on the " + specFile + " file");
>        } catch (IOException e) {
>            throw new BuildException(e, location);
>        } finally {
>            if (output != null) {
>                try {
>                    outputstream.close();
>                } catch (IOException e) {}
>            }
>            if (error != null) {
>                try {
>                    errorstream.close();
>                } catch (IOException e) {}
>            }
>        }
>    }
>
>    public void setTopDir(File td) {
>        this.topDir = td;
>    }
>
>    public void setCommand(String c) {
>        this.command = c;
>    }
>
>    public void setSpecFile(String sf) {
>        if ( (sf == null) || (sf.trim().equals(""))) {
>            throw new BuildException("You must specify a spec
file",location);
>        }
>        this.specFile = sf;
>    }
>
>    public void setCleanBuildDir(boolean cbd) {
>        cleanBuildDir = cbd;
>    }
>
>    public void setRemoveSpec(boolean rs) {
>        removeSpec = rs;
>    }
>
>    public void setRemoveSource(boolean rs) {
>        removeSource = rs;
>    }
>
>    public void setOutput(File output) {
>        this.output = output;
>    }
>
>    public void setError(File error) {
>        this.error = error;
>    }
>}
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ant-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: ant-dev-help@jakarta.apache.org
Cheers,

Pete

*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof."                   |
|              - John Kenneth Galbraith               |
*-----------------------------------------------------*


Mime
View raw message