ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs CopyTest.java
Date Thu, 27 Mar 2003 16:32:19 GMT
bodewig     2003/03/27 08:32:19

  Modified:    .        WHATSNEW
               docs/manual/CoreTasks copy.html move.html
               src/etc/testcases/taskdefs copy.xml
               src/main/org/apache/tools/ant/taskdefs Copy.java Move.java
                        Sync.java
               src/main/org/apache/tools/ant/util FileUtils.java
               src/testcases/org/apache/tools/ant/taskdefs CopyTest.java
  Added:       src/etc/testcases/taskdefs/copy/expected utf-8
               src/etc/testcases/taskdefs/copy/input iso8859-1
  Log:
  Add outputencoding attribute to <copy> and friends.
  
  PR: 18217
  
  Revision  Changes    Path
  1.375     +3 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.374
  retrieving revision 1.375
  diff -u -r1.374 -r1.375
  --- WHATSNEW	27 Mar 2003 13:14:31 -0000	1.374
  +++ WHATSNEW	27 Mar 2003 16:32:18 -0000	1.375
  @@ -184,6 +184,9 @@
     different separator.  This is useful if you want to run certain
     ported Unix tools.
   
  +* Copy has a new outputencoding attribute that can be used to change
  +  the encoding while copying files.  Bugzilla Report 18217.
  +
   Changes from Ant 1.5.2 to Ant 1.5.3
   ===================================
   
  
  
  
  1.16      +13 -0     ant/docs/manual/CoreTasks/copy.html
  
  Index: copy.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/copy.html,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- copy.html	5 Feb 2003 15:32:26 -0000	1.15
  +++ copy.html	27 Mar 2003 16:32:18 -0000	1.16
  @@ -104,6 +104,19 @@
        <td valign="top">Log the files that are being copied.</td>
        <td valign="top" align="center">No; defaults to false.</td>
     </tr>
  +  <tr>
  +    <td valign="top">encoding</td>
  +    <td valign="top">The encoding to assume when filter-copying the
  +    files. <em>since Ant 1.5</em>.</td>
  +    <td align="center">No - defaults to default JVM encoding</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">outputencoding</td>
  +    <td valign="top">The encoding to use when writing the files.
  +    <em>since Ant 1.6</em>.</td>
  +    <td align="center">No - defaults to the value of the encoding
  +    attribute if given or the default JVM encoding otherwise.</td>
  +  </tr>
   </table>
   <h3>Parameters specified as nested elements</h3>
   
  
  
  
  1.11      +13 -0     ant/docs/manual/CoreTasks/move.html
  
  Index: move.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/move.html,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- move.html	19 Mar 2003 08:33:27 -0000	1.10
  +++ move.html	27 Mar 2003 16:32:18 -0000	1.11
  @@ -89,6 +89,19 @@
        <td valign="top">Log the files that are being moved.</td>
        <td valign="top" align="center">No; defaults to false.</td>
     </tr>
  +  <tr>
  +    <td valign="top">encoding</td>
  +    <td valign="top">The encoding to assume when filter-copying the
  +    files. <em>since Ant 1.5</em>.</td>
  +    <td align="center">No - defaults to default JVM encoding</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">outputencoding</td>
  +    <td valign="top">The encoding to use when writing the files.
  +    <em>since Ant 1.6</em>.</td>
  +    <td align="center">No - defaults to the value of the encoding
  +    attribute if given or the default JVM encoding otherwise.</td>
  +  </tr>
   </table>
   <h3>Parameters specified as nested elements</h3>
   <h4>mapper</h4>
  
  
  
  1.9       +5 -0      ant/src/etc/testcases/taskdefs/copy.xml
  
  Index: copy.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/copy.xml,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- copy.xml	6 Mar 2002 03:25:50 -0000	1.8
  +++ copy.xml	27 Mar 2003 16:32:18 -0000	1.9
  @@ -62,6 +62,11 @@
       </copy>
     </target>
   
  +  <target name="testTranscoding">
  +    <copy file="copy/input/iso8859-1" tofile="copytest1.tmp"
  +          encoding="ISO8859_1" outputencoding="UTF8"/>
  +  </target>
  +
     <target name="cleanup"> 
       <delete file="copytest1.tmp"/>
       <delete file="copytest3.tmp"/>
  
  
  
  1.1                  ant/src/etc/testcases/taskdefs/copy/expected/utf-8
  
  	<<Binary file>>
  
  
  1.1                  ant/src/etc/testcases/taskdefs/copy/input/iso8859-1
  
  	<<Binary file>>
  
  
  1.53      +29 -6     ant/src/main/org/apache/tools/ant/taskdefs/Copy.java
  
  Index: Copy.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Copy.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- Copy.java	7 Mar 2003 11:23:00 -0000	1.52
  +++ Copy.java	27 Mar 2003 16:32:18 -0000	1.53
  @@ -118,7 +118,8 @@
       private Vector filterChains = new Vector();
       private Vector filterSets = new Vector();
       private FileUtils fileUtils;
  -    private String encoding = null;
  +    private String inputEncoding = null;
  +    private String outputEncoding = null;
   
       /**
        * Copy task constructor.
  @@ -291,7 +292,10 @@
        * @since 1.32, Ant 1.5
        */
       public void setEncoding (String encoding) {
  -        this.encoding = encoding;
  +        this.inputEncoding = encoding;
  +        if (outputEncoding == null) {
  +            outputEncoding = encoding;
  +        }
       }
   
       /**
  @@ -300,7 +304,26 @@
        * @since 1.32, Ant 1.5
        */
       public String getEncoding() {
  -        return encoding;
  +        return inputEncoding;
  +    }
  +
  +    /**
  +     * Sets the character encoding for output files.
  +     *
  +     * @since Ant 1.6
  +     */
  +    public void setOutputEncoding(String encoding) {
  +        this.outputEncoding = encoding;
  +    }
  +
  +    /**
  +     * @return the character encoding for output files,
  +     * <code>null</code> if not set.
  +     *
  +     * @since Ant 1.6
  +     */
  +    public String getOutputEncoding() {
  +        return outputEncoding;
       }
   
       /**
  @@ -526,8 +549,8 @@
                       }
                       fileUtils.copyFile(fromFile, toFile, executionFilters,
                                          filterChains, forceOverwrite,
  -                                       preserveLastModified, encoding,
  -                                       getProject());
  +                                       preserveLastModified, inputEncoding,
  +                                       outputEncoding, getProject());
                   } catch (IOException ioe) {
                       String msg = "Failed to copy " + fromFile + " to " + toFile
                           + " due to " + ioe.getMessage();
  
  
  
  1.33      +5 -3      ant/src/main/org/apache/tools/ant/taskdefs/Move.java
  
  Index: Move.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Move.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- Move.java	10 Feb 2003 14:13:36 -0000	1.32
  +++ Move.java	27 Mar 2003 16:32:18 -0000	1.33
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -172,7 +172,9 @@
                                                       getFilterChains(),
                                                       forceOverwrite,
                                                       getPreserveLastModified(),
  -                                                    getEncoding(), getProject());
  +                                                    getEncoding(), 
  +                                                    getOutputEncoding(),
  +                                                    getProject());
   
                               f = new File(fromFile);
                               if (!f.delete()) {
  
  
  
  1.2       +8 -1      ant/src/main/org/apache/tools/ant/taskdefs/Sync.java
  
  Index: Sync.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Sync.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Sync.java	25 Mar 2003 09:30:59 -0000	1.1
  +++ Sync.java	27 Mar 2003 16:32:18 -0000	1.2
  @@ -330,6 +330,13 @@
           _copy.setEncoding(encoding);
       }
   
  +    /**
  +     * Sets the character encoding for output files.
  +     */
  +    public void setOutputEncoding(String encoding) {
  +        _copy.setOutputEncoding(encoding);
  +    }
  +
   
       /**
        * Subclass Copy in order to access it's file/dir maps.
  
  
  
  1.40      +58 -6     ant/src/main/org/apache/tools/ant/util/FileUtils.java
  
  Index: FileUtils.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/FileUtils.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- FileUtils.java	13 Mar 2003 16:15:47 -0000	1.39
  +++ FileUtils.java	27 Mar 2003 16:32:19 -0000	1.40
  @@ -249,6 +249,29 @@
       }
   
       /**
  +     * Convienence method to copy a file from a source to a
  +     * destination specifying if token filtering must be used, if
  +     * filter chains must be used, if source files may overwrite
  +     * newer destination files and the last modified time of
  +     * <code>destFile</code> file should be made equal
  +     * to the last modified time of <code>sourceFile</code>.
  +     *
  +     * @throws IOException
  +     *
  +     * @since Ant 1.6
  +     */
  +    public void copyFile(String sourceFile, String destFile,
  +                         FilterSetCollection filters, Vector filterChains,
  +                         boolean overwrite, boolean preserveLastModified,
  +                         String inputEncoding, String outputEncoding, 
  +                         Project project)
  +        throws IOException {
  +        copyFile(new File(sourceFile), new File(destFile), filters,
  +                 filterChains, overwrite, preserveLastModified,
  +                 inputEncoding, outputEncoding, project);
  +    }
  +
  +    /**
        * Convienence method to copy a file from a source to a destination.
        * No filtering is performed.
        *
  @@ -334,6 +357,28 @@
                            boolean overwrite, boolean preserveLastModified,
                            String encoding, Project project)
           throws IOException {
  +        copyFile(sourceFile, destFile, filters, filterChains,
  +                 overwrite, preserveLastModified, encoding, encoding, project);
  +    }
  +
  +    /**
  +     * Convienence method to copy a file from a source to a
  +     * destination specifying if token filtering must be used, if
  +     * filter chains must be used, if source files may overwrite
  +     * newer destination files and the last modified time of
  +     * <code>destFile</code> file should be made equal
  +     * to the last modified time of <code>sourceFile</code>.
  +     *
  +     * @throws IOException
  +     *
  +     * @since 1.15, Ant 1.6
  +     */
  +    public void copyFile(File sourceFile, File destFile,
  +                         FilterSetCollection filters, Vector filterChains,
  +                         boolean overwrite, boolean preserveLastModified,
  +                         String inputEncoding, String outputEncoding,
  +                         Project project)
  +        throws IOException {
   
           if (overwrite || !destFile.exists() ||
               destFile.lastModified() < sourceFile.lastModified()) {
  @@ -354,23 +399,30 @@
               final boolean filterChainsAvailable = (filterChains != null
                                                      && filterChains.size() >
0);
   
  -            if (filterSetsAvailable || filterChainsAvailable) {
  +            if (filterSetsAvailable || filterChainsAvailable
  +                || (inputEncoding != null 
  +                    && !inputEncoding.equals(outputEncoding))
  +                || (inputEncoding == null && outputEncoding != null)) {
                   BufferedReader in = null;
                   BufferedWriter out = null;
   
                   try {
  -                    if (encoding == null) {
  +                    if (inputEncoding == null) {
                           in = new BufferedReader(new FileReader(sourceFile));
  -                        out = new BufferedWriter(new FileWriter(destFile));
                       } else {
                           in =
                               new BufferedReader(new InputStreamReader(
                                                                        new FileInputStream(sourceFile),
  -                                                                     encoding));
  +                                                                     inputEncoding));
  +                    }
  +
  +                    if (outputEncoding == null) {
  +                        out = new BufferedWriter(new FileWriter(destFile));
  +                    } else {
                           out =
                               new BufferedWriter(new OutputStreamWriter(
                                                                         new FileOutputStream(destFile),
  -                                                                      encoding));
  +                                                                      outputEncoding));
                       }
   
                       if (filterChainsAvailable) {
  
  
  
  1.11      +9 -1      ant/src/testcases/org/apache/tools/ant/taskdefs/CopyTest.java
  
  Index: CopyTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/CopyTest.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- CopyTest.java	10 Feb 2003 14:14:45 -0000	1.10
  +++ CopyTest.java	27 Mar 2003 16:32:19 -0000	1.11
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -149,5 +149,13 @@
           File file  = new File(getProjectDir(),
                                           "copytest_single_file_fileset.tmp");
           assertTrue(file.exists());
  +    }
  +
  +    public void testTranscoding() throws IOException {
  +        executeTarget("testTranscoding");
  +        FileUtils fileUtils = FileUtils.newFileUtils();
  +        File f1 = getProject().resolveFile("copy/expected/utf-8");
  +        File f2 = getProject().resolveFile("copytest1.tmp");
  +        assertTrue(fileUtils.contentEquals(f1, f2));
       }
   }
  
  
  

Mime
View raw message