ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject AW: Diff/CVS/Patch/Copying files
Date Thu, 12 Jun 2003 05:23:29 GMT
1) You can call the cvs tool via <exec>.

2) I did a little Bugzilla search. There are some hints on "cvs diff". Some
of them may
do what you want.
http://nagoya.apache.org/bugzilla/buglist.cgi?bug_status=NEW&bug_status=ASSI
GNED&bug_status=REOPENED&email1=&emailtype1=substring&emailassigned_to1=1&em
ail2=&emailtype2=substring&emailreporter2=1&bugidtype=include&bug_id=&change
din=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&product=Ant&short_desc=
&short_desc_type=allwordssubstr&long_desc=diff+cvs&long_desc_type=allwordssu
bstr&bug_file_loc=&bug_file_loc_type=allwordssubstr&keywords=&keywords_type=
anywords&field0-0-0=noop&type0-0-0=noop&value0-0-0=&cmdtype=doit&namedcmd=in
volved+bugs&newqueryname=&order=Reuse+same+sort+as+last+time

3) You can try my Task. I wrote that some weeks ago, but haven´t tested/used
that.
Maybe it works. But without any tests I wouldn´t put it into Bugzilla.


/** Apache license text */
package org.apache.tools.ant.taskdefs;

import java.io.File;
import java.io.IOException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Commandline;

/**
 * Creates a Diff-file (see task 'patch'); requires "diff" to be
 * on the execution path.
 *
 * @author Jan Matèrne
 * @since Ant 1.6
 * @ant.task category="utility"
 */
/* Implementation based on Task 'Patch' by Stefan Bodewig */
public class Diff extends Task {

    /** The file containing the 'older' data. */
    private File oldfile = null;
    public void setOldfile(File oldfile) {
        this.oldfile = oldfile;
    }

    /** The file containing the 'newer' data. */
    private File newfile = null;
    public void setNewfile(File newfile) {
        this.newfile = newfile;
    }

    /** The file to be created containing the diff´s. */
    private File difffile = null;
    public void setDifffile(File difffile) {
        this.difffile = difffile;
    }


    private Commandline cmd = new Commandline();


    /**
     * Create the diff.
     * @throws BuildException when it all goes a bit pear shaped
     */
    public void execute() throws BuildException {
        // Check the prerequisites
        if (oldfile  == null) throw new BuildException("Missing 'oldfile'",
getLocation());
        if (newfile  == null) throw new BuildException("Missing 'newfile'",
getLocation());
        if (difffile == null) throw new BuildException("Missing 'difffile'",
getLocation());
        if (oldfile.isDirectory()) throw
            new BuildException("Directories aren´t supported (oldfile).",
getLocation());
        if (newfile.isDirectory()) throw
            new BuildException("Directories aren´t supported (newfile).",
getLocation());
        if (difffile.isDirectory()) throw
            new BuildException("Directories aren´t supported (difffile).",
getLocation());

        // ----- Do the diff -----
        Commandline toExecute = (Commandline) cmd.clone();

        toExecute.setExecutable("diff");

        toExecute.createArgument().setValue("-u");
        toExecute.createArgument().setFile(oldfile);
        toExecute.createArgument().setFile(newfile);

        try {
            java.io.FileOutputStream out = new
java.io.FileOutputStream(difffile);
            PumpStreamHandler psh = new PumpStreamHandler(out, System.err,
null);

            Execute exe = new Execute(psh, null);
            exe.setCommandline(toExecute.getCommandline());
            exe.setWorkingDirectory(getProject().getBaseDir());

            log(toExecute.describeCommand(), Project.MSG_VERBOSE);

            StringBuffer sb = new StringBuffer();
            String[] cmdLine = exe.getCommandline();
            for (int i=0; i<cmdLine.length; i++) sb.append("-
").append(cmdLine[i]).append(System.getProperty("line.separator"));
            log("EXE: " + System.getProperty("line.separator") +
sb.toString());

            exe.execute();

            log(difffile + " created.");

        } catch (IOException e) {
            throw new BuildException(e, getLocation());
        }
    }
}



If you try that, tell me whether it works :-)


Jan




> -----Ursprüngliche Nachricht-----
> Von: Michael Finger [mailto:mfinger@SVTECHNOLOGY.com]
> Gesendet am: Donnerstag, 12. Juni 2003 01:47
> An: Ant Users List
> Betreff: Diff/CVS/Patch/Copying files
> 
> Hello,
> I'm trying to write a ant file to do a diff between 2 
> different tags in CVS 
> (I can do this already) and create a jar with the files that 
> have changes. 
> I'm really not sure on how to meld these two tasks togeather..
> I noticed that ant has a patch task wich takes a diff? file?
> So I guess I would want to do something like:
> 1. Do a cvstagdiff
> 2.get the output of that file to pas into the path command, 
> 3. have the patch command write into an empty file dir so I 
> only get the files that have changed?? 
> 
> 
> Thanks Mike
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message