ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Cvs.java Patch.java
Date Mon, 31 Jul 2000 16:22:04 GMT
bodewig     00/07/31 09:22:02

  Modified:    .        WHATSNEW
               docs     index.html
               src/main/org/apache/tools/ant/taskdefs Cvs.java Patch.java
  Log:
  Converted <patch> and <cvs> to new framework.
  
  Revision  Changes    Path
  1.7       +5 -1      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- WHATSNEW	2000/07/31 12:09:25	1.6
  +++ WHATSNEW	2000/07/31 16:21:44	1.7
  @@ -12,6 +12,10 @@
   
   * the class attribute of <java> has been removed.
   
  +* <patch> has lost some of its attributes.
  +
  +* <java> and <cvs> have lost some undocumented attributes.
  +
   Other changes:
   --------------
   
  @@ -48,4 +52,4 @@
   respect to the Project's basedir.
   
   * Project didn't interpret the basedir attribute correctly in all
  -cases.
  \ No newline at end of file
  +cases.
  
  
  
  1.60      +1 -30     jakarta-ant/docs/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/index.html,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- index.html	2000/07/28 09:30:18	1.59
  +++ index.html	2000/07/31 16:21:50	1.60
  @@ -944,7 +944,7 @@
     <tr>
       <td valign="top">dest</td>
       <td valign="top">the directory where the checked out files should be placed.</td>
  -    <td align="center" valign="top">Yes</td>
  +    <td align="center" valign="top">No, default is project's basedir.</td>
     </tr>
     <tr>
       <td valign="top">package</td>
  @@ -971,12 +971,6 @@
       <td valign="top">report only, don't change any files.</td>
       <td align="center" valign="top">No, default &quot;false&quot;</td>
     </tr>
  -  <tr>
  -    <td valign="top">failonerror</td>
  -    <td valign="top">Stop the buildprocess if the command exits with a
  -      returncode other than 0.</td>
  -    <td align="center" valign="top">No</td>
  -  </tr>
   </table>
   <h3>Examples</h3>
   <pre>  &lt;cvs cvsRoot=&quot;:pserver:anoncvs@jakarta.apache.org:/home/cvspublic&quot;
  @@ -2363,23 +2357,6 @@
       <td align="center" valign="top"><b>Required</b></td>
     </tr>
     <tr>
  -    <td valign="top">dir</td>
  -    <td valign="top">the directory in which the command should be executed.</td>
  -    <td align="center" valign="top">Yes</td>
  -  </tr>
  -  <tr>
  -    <td valign="top">os</td>
  -    <td valign="top">list of Operating Systems on which the command may be
  -      executed.</td>
  -    <td align="center" valign="top">No</td>
  -  </tr>
  -  <tr>
  -    <td valign="top">output</td> 
  -    <td valign="top">the file to which the output of the patch command 
  -      should be redirected.</td> 
  -    <td align="center" valign="top">No</td>
  -  </tr>
  -  <tr>
       <td valign="top">patchfile</td> 
       <td valign="top">the file that includes the diff output</td>
       <td align="center" valign="top">Yes</td>
  @@ -2415,12 +2392,6 @@
       <td valign="top">strip</td> 
       <td valign="top">Strip the smallest prefix containing <i>num</i>
leading 
         slashes from filenames.</td>
  -    <td align="center" valign="top">No</td>
  -  </tr>
  -  <tr>
  -    <td valign="top">failonerror</td>
  -    <td valign="top">Stop the buildprocess if the command exits with a
  -      returncode other than 0.</td>
       <td align="center" valign="top">No</td>
     </tr>
   </table>
  
  
  
  1.8       +45 -29    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Cvs.java
  
  Index: Cvs.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Cvs.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Cvs.java	2000/07/11 11:28:25	1.7
  +++ Cvs.java	2000/07/31 16:21:55	1.8
  @@ -55,6 +55,7 @@
   package org.apache.tools.ant.taskdefs;
   
   import org.apache.tools.ant.*;
  +import org.apache.tools.ant.types.Commandline;
   import java.io.*;
   
   /**
  @@ -65,42 +66,58 @@
    * @author Wolfgang Werner <a href="mailto:wwerner@picturesafe.de">wwerner@picturesafe.de</a>
    */
   
  -public class Cvs extends Exec {
  +public class Cvs extends Task {
   
  +    private Commandline cmd = new Commandline();
       private String cvsRoot;
       private String pack;
  -    private String tag;
  -    private String date;
       private String command = "checkout";
       private boolean quiet = false;
       private boolean noexec = false;
  +    private File dest;
       
       public void execute() throws BuildException {
   
   	// XXX: we should use JCVS (www.ice.com/JCVS) instead of command line
   	// execution so that we don't rely on having native CVS stuff around (SM)
  +
  +        // We can't do it ourselves as jCVS is GPLed, a third party task 
  +        // outside of jakarta repositories would be possible though (SB).
   	
  -	StringBuffer sb=new StringBuffer();
  -	sb.append(" cvs ");
  +        Commandline toExecute = new Commandline();
  +
  +        toExecute.setExecutable("cvs");
           if (cvsRoot != null) { 
  -            sb.append("-d ").append(cvsRoot).append(" ");
  +            toExecute.addValue("-d");
  +            toExecute.addValue(cvsRoot);
           }
  -
  -        sb.append(noexec ? "-n " : "")
  -            .append(quiet  ? "-q " : "")
  -            .append(command).append(" ");
  -		
  -	if (tag!=null)
  -            sb.append("-r ").append(tag).append(" ");
  -
  -       if (date!=null)
  -            sb.append("-D ").append(date).append(" ");
  +        if (noexec) {
  +            toExecute.addValue("-n");
  +        }
  +        if (quiet) {
  +            toExecute.addValue("-q");
  +        }
  +        toExecute.addValue(command);
  +        toExecute.addLine(cmd.getCommandline());
   
   	if (pack != null) {
  -            sb.append(pack);
  +            toExecute.addValue(pack);
   	}
   
  -        run(sb.toString());
  +        Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO,
  +                                                       Project.MSG_WARN), 
  +                                  null);
  +
  +        exe.setAntRun(project);
  +        if (dest == null) dest = project.getBaseDir();
  +        exe.setWorkingDirectory(dest);
  +
  +        exe.setCommandline(toExecute.getCommandline());
  +        try {
  +            exe.execute();
  +        } catch (IOException e) {
  +            throw new BuildException(e, location);
  +        }
       }
   
       public void setCvsRoot(String root) {
  @@ -113,8 +130,8 @@
   	this.cvsRoot = root;
       }
   
  -    public void setDest(String dest) {
  -	setDir(dest);
  +    public void setDest(File dest) {
  +        this.dest = dest;
       }
   
       public void setPackage(String p) {
  @@ -123,19 +140,18 @@
   
       public void setTag(String p) { 
           // Check if not real tag => set it to null 
  -        if (p != null) { 
  -            if (p.trim().equals("")) 
  -                p = null; 
  -        } 
  -
  -        this.tag = p; 
  +        if (p != null && p.trim().length() > 0) {
  +            cmd.addValue("-r");
  +            cmd.addValue(p);
  +        }
       } 
   
       
       public void setDate(String p) {
  -       if( p != null && p.trim().length()==0 )
  -               p = null;
  -       this.date = p;
  +        if(p != null && p.trim().length() > 0) {
  +            cmd.addValue("-D");
  +            cmd.addValue(p);
  +        }
       }
   
       public void setCommand(String c) {
  
  
  
  1.4       +39 -48    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Patch.java
  
  Index: Patch.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Patch.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Patch.java	2000/07/12 12:43:00	1.3
  +++ Patch.java	2000/07/31 16:21:56	1.4
  @@ -55,22 +55,20 @@
   package org.apache.tools.ant.taskdefs;
   
   import org.apache.tools.ant.*;
  +import org.apache.tools.ant.types.Commandline;
   import java.io.File;
  +import java.io.IOException;
   
   /**
    * Task as a layer on top of patch. Patch applies a diff file to an original.
    *
  - * @author Stefan Bodewig <a href="mailto:stefan.bodewig@megabit.net">stefan.bodewig@megabit.net</a>
  + * @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a>
    */
  -public class Patch extends Exec {
  +public class Patch extends Task {
   
       private File originalFile;
  -    private File patchFile;
  -    private boolean backup = false;
  -    private boolean ignoreWhitespace = false;
  -    private int strip = -1;
  -    private boolean quiet = false;
  -    private boolean reverse = false;
  +    private boolean havePatchfile = false;
  +    private Commandline cmd = new Commandline();
   
       /**
        * The file to patch.
  @@ -83,21 +81,31 @@
        * The file containing the diff output.
        */
       public void setPatchfile(File file) {
  -        patchFile = file;
  +        if (!file.exists()) {
  +            throw new BuildException("patchfile "+file+" doesn\'t exist", 
  +                                     location);
  +        }
  +        cmd.addValue("-i");
  +        cmd.addValue(file.getAbsolutePath());
  +        havePatchfile = true;
       }
   
       /**
        * Shall patch write backups.
        */
       public void setBackups(boolean backups) {
  -        backup = backups;
  +        if (backups) {
  +            cmd.addValue("-b");
  +        }
       }
   
       /**
        * Ignore whitespace differences.
        */
       public void setIgnorewhitespace(boolean ignore) {
  -        ignoreWhitespace = ignore;
  +        if (ignore) {
  +            cmd.addValue("-l");
  +        }
       }
   
       /**
  @@ -110,65 +118,48 @@
           if (num < 0) {
               throw new BuildException("strip has to be >= 0", location);
           }
  -        strip = num;
  +        cmd.addValue("-p"+num);
       }
   
       /**
        * Work silently unless an error occurs.
        */
       public void setQuiet(boolean q) {
  -        quiet = q;
  +        if (q) {
  +            cmd.addValue("-s");
  +        }
       }
   
       /**
        * Assume patch was created with old and new files swapped.
        */
       public void setReverse(boolean r) {
  -        reverse = r;
  -    }
  -
  -    public final void setCommand(String command) throws BuildException {
  -        throw new BuildException("Cannot set attribute command in patch task",
  -                                 location);
  +        if (r) {
  +            cmd.addValue("-R");
  +        }
       }
   
       public void execute() throws BuildException {
  -        if (patchFile == null) {
  +        if (!havePatchfile) {
               throw new BuildException("patchfile argument is required", 
                                        location);
           } 
  -        if (!patchFile.exists()) {
  -            throw new BuildException("patchfile "+patchFile+" doesn\'t exist", 
  -                                     location);
  -        }
           
  -        StringBuffer command = new StringBuffer("patch -i "+patchFile+" ");
  +        cmd.setExecutable("patch");
   
  -        if (backup) {
  -            command.append("-b ");
  -        }
  -        
  -        if (ignoreWhitespace) {
  -            command.append("-l ");
  -        }
  -        
  -        if (strip >= 0) {
  -            command.append("-p"+strip+" ");
  -        }
  -        
  -        if (quiet) {
  -            command.append("-s ");
  -        }
  -        
  -        if (reverse) {
  -            command.append("-R ");
  -        }
  -        
           if (originalFile != null) {
  -            command.append(originalFile);
  -        } 
  +            cmd.addValue(originalFile.getAbsolutePath());
  +        }
   
  -        run(command.toString());
  +        Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO,
  +                                                       Project.MSG_WARN), 
  +                                  null);
  +        exe.setCommandline(cmd.getCommandline());
  +        try {
  +            exe.execute();
  +        } catch (IOException e) {
  +            throw new BuildException(e, location);
  +        }
       }
   
   }// Patch
  
  
  

Mime
View raw message