ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peterrei...@apache.org
Subject cvs commit: ant WHATSNEW
Date Mon, 31 May 2004 08:24:31 GMT
peterreilly    2004/05/31 01:24:31

  Modified:    src/main/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH
                        Concat.java
               docs/manual/CoreTasks Tag: ANT_16_BRANCH concat.html
               .        Tag: ANT_16_BRANCH WHATSNEW
  Log:
  sync
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.28.2.8  +123 -1    ant/src/main/org/apache/tools/ant/taskdefs/Concat.java
  
  Index: Concat.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Concat.java,v
  retrieving revision 1.28.2.7
  retrieving revision 1.28.2.8
  diff -u -r1.28.2.7 -r1.28.2.8
  --- Concat.java	10 May 2004 09:42:04 -0000	1.28.2.7
  +++ Concat.java	31 May 2004 08:24:30 -0000	1.28.2.8
  @@ -32,6 +32,7 @@
   import java.io.StringReader;
   import java.io.Writer;
   import java.util.Enumeration;
  +import java.util.Iterator;
   import java.util.Vector;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.DirectoryScanner;
  @@ -90,6 +91,9 @@
       /** Stores the output file encoding. */
       private String outputEncoding = null;
   
  +    /** Stores the binary attribute */
  +    private boolean binary = false;
  +    
       // Child elements.
   
       /**
  @@ -233,6 +237,7 @@
           textBuffer.append(text);
       }
   
  +       
       /**
        * Add a header to the concatenated output
        * @param header the header
  @@ -292,6 +297,20 @@
       }
   
       /**
  +     * set the binary attribute.
  +     * if true, concat will concatenate the files
  +     * byte for byte. This mode does not allow
  +     * any filtering, or other modifications
  +     * to the input streams.
  +     * The default value is false.
  +     * @since ant 1.6.2
  +     * @param binary if true, enable binary mode
  +     */
  +    public void setBinary(boolean binary) {
  +        this.binary = binary;
  +    }
  +
  +    /**
        * This method performs the concatenation.
        */
       public void execute() {
  @@ -299,6 +318,36 @@
           // treat empty nested text as no text
           sanitizeText();
   
  +        // if binary check if incompatible attributes are used
  +        if (binary) {
  +            if (destinationFile == null) {
  +                throw new BuildException(
  +                    "DestFile attribute is required for binary concatenation");
  +            }
  +
  +            if (textBuffer != null) {
  +                throw new BuildException(
  +                    "Nested text is incompatible with binary concatenation");
  +            }
  +            if (encoding != null || outputEncoding != null) {
  +                throw new BuildException(
  +                    "Seting input or output encoding is incompatible with binary"
  +                    + " concatenation");
  +            }
  +            if (filterChains != null) {
  +                throw new BuildException(
  +                    "Setting filters is incompatible with binary concatenation");
  +            }
  +            if (fixLastLine) {
  +                throw new BuildException(
  +                    "Setting fixlastline is incompatible with binary concatenation");
  +            }
  +            if (header != null || footer != null) {
  +                throw new BuildException(
  +                    "Nested header or footer is incompatible with binary concatenation");
  +            }
  +        }
  +
           if (destinationFile != null && outputWriter != null) {
               throw new BuildException(
                   "Cannot specify both a destination file and an output writer");
  @@ -366,7 +415,11 @@
               return;
           }
   
  -        cat();
  +        if (binary) {
  +            binaryCat();
  +        } else {
  +            cat();
  +        }
       }
   
       /**
  @@ -400,6 +453,75 @@
                                            + "is the same as the output file.");
               }
               sourceFiles.addElement(file);
  +        }
  +    }
  +
  +    /** perform the binary concatenation */
  +    private void binaryCat() {
  +        log("Binary concatenation of " + sourceFiles.size()
  +            + " files to " + destinationFile);
  +        FileOutputStream out = null;
  +        FileInputStream in = null;
  +        byte[] buffer = new byte[8 * 1024];
  +        try {
  +            try {
  +                out = new FileOutputStream(destinationFile);
  +            } catch (Exception t) {
  +                throw new BuildException(
  +                    "Unable to open " + destinationFile
  +                    + " for writing", t);
  +            }
  +            for (Iterator i = sourceFiles.iterator(); i.hasNext(); ) {
  +                File sourceFile = (File) i.next();
  +                try {
  +                    in = new FileInputStream(sourceFile);
  +                } catch (Exception t) {
  +                    throw new BuildException(
  +                        "Unable to open input file " + sourceFile,
  +                        t);
  +                }
  +                int count = 0;
  +                do {
  +                    try {
  +                        count = in.read(buffer, 0, buffer.length);
  +                    } catch (Exception t) {
  +                        throw new BuildException(
  +                            "Unable to read from " + sourceFile, t);
  +                    }
  +                    try {
  +                        if (count > 0) {
  +                            out.write(buffer, 0, count);
  +                        }
  +                    } catch (Exception t) {
  +                        throw new BuildException(
  +                            "Unable to write to " + destinationFile, t);
  +                    }
  +                } while (count > 0);
  +
  +                try {
  +                    in.close();
  +                } catch (Exception t) {
  +                    throw new BuildException(
  +                        "Unable to close " + sourceFile, t);
  +                }
  +                in = null;
  +            }
  +        } finally {
  +            if (in != null) {
  +                try {
  +                    in.close();
  +                } catch (Throwable t) {
  +                    // Ignore
  +                }
  +            }
  +            if (out != null) {
  +                try {
  +                    out.close();
  +                } catch (Exception ex) {
  +                    throw new BuildException(
  +                        "Unable to close " + destinationFile, ex);
  +                }
  +            }
           }
       }
   
  
  
  
  No                   revision
  No                   revision
  1.9.2.4   +24 -0     ant/docs/manual/CoreTasks/concat.html
  
  Index: concat.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/concat.html,v
  retrieving revision 1.9.2.3
  retrieving revision 1.9.2.4
  diff -u -r1.9.2.3 -r1.9.2.4
  --- concat.html	20 Apr 2004 12:52:20 -0000	1.9.2.3
  +++ concat.html	31 May 2004 08:24:30 -0000	1.9.2.4
  @@ -124,6 +124,22 @@
             </td>
             <td valign="top" align="center">No</td>
           </tr>
  +        <tr>
  +          <td valign="top">binary</td>
  +          <td valign="top">
  +            <em>since ant 1.6.2</em>
  +            If this attribute is set to true, the task concatenates the files
  +            in a byte by byte fashion. If this attribute is false, concat will
  +            not normally work for binary files due to character encoding
  +            issues.
  +            If this option is set to true, the destfile attribute must be
  +            set, and the task cannot used nested text.
  +            Also the attributes encoding, outputencoding, filelastline
  +            cannot be used.
  +            The default is false.
  +          </td>
  +          <td valign="top" align="center">No</td>
  +        </tr>
   
         </table>
   
  @@ -262,6 +278,14 @@
              &lt;contains value="project"/&gt;
            &lt;/linecontains&gt;
         &lt;/filterchain&gt;
  +   &lt;/concat&gt;
  +        </pre>
  +
  +      <p><b>Concatenate a number of binary files.</b></p>
  +        <pre>
  +   &lt;concat destfile="${build.dir}/dist.bin" binary="yes"&gt;
  +     &lt;fileset file="${src.dir}/scripts/dist.sh"&gt;
  +     &lt;fileset file="${build.dir}/dist.tar.bz2"&gt;
      &lt;/concat&gt;
           </pre>
   
  
  
  
  No                   revision
  No                   revision
  1.503.2.93 +2 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.503.2.92
  retrieving revision 1.503.2.93
  diff -u -r1.503.2.92 -r1.503.2.93
  --- WHATSNEW	25 May 2004 11:48:34 -0000	1.503.2.92
  +++ WHATSNEW	31 May 2004 08:24:30 -0000	1.503.2.93
  @@ -155,6 +155,8 @@
     a granularity of two seconds).  The default remains to round up.
     Bugzilla Report 17934.
   
  +* A binary option has been added to <concat>. Bugzilla Report 26312.
  +
   Changes from Ant 1.6.0 to Ant 1.6.1
   =============================================
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message