ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs FixCRLF.java
Date Tue, 03 Apr 2001 11:26:26 GMT
bodewig     01/04/03 04:26:26

  Modified:    .        build.xml
               src/main/org/apache/tools/ant/taskdefs FixCRLF.java
  Log:
  <fixcrlf> will only overwrite files if their content is different from
  the original.
  
  Submitted by:	Attila Szegedi <szegedi@scriptum.hu>
  
  Revision  Changes    Path
  1.146     +6 -1      jakarta-ant/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/build.xml,v
  retrieving revision 1.145
  retrieving revision 1.146
  diff -u -r1.145 -r1.146
  --- build.xml	2001/03/19 12:56:17	1.145
  +++ build.xml	2001/04/03 11:26:26	1.146
  @@ -630,13 +630,18 @@
             <exclude name="org/apache/tools/ant/taskdefs/GUnzipTest.java" />
             <exclude name="org/apache/tools/ant/taskdefs/GzipTest.java" />
   
  -          <!-- only run this test if ANTLR is installed -->
  +          <!-- only run these tests if their required libraries are installed -->
             <exclude name="org/apache/tools/ant/taskdefs/optional/ANTLRTest.java" 
                      unless="antlr.present" />
             <exclude name="org/apache/tools/ant/util/regexp/JakartaRegexpMatcherTest.java"

                      unless="jakarta.regexp.present" />
             <exclude name="org/apache/tools/ant/util/regexp/JakartaOroMatcherTest.java"

                      unless="jakarta.oro.present" />
  +          <exclude name="${optional.package}/ide/VAJExportTest.java" unless="vaj.present"
/>
  +                   
  +           <!-- run when you have the environment setup to support them -->
  +          <exclude name="org/apache/tools/ant/taskdefs/optional/net/FtpTest.java" />
  +
           </fileset>
         </batchtest>
   
  
  
  
  1.14      +50 -7     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  
  Index: FixCRLF.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- FixCRLF.java	2001/01/03 14:18:30	1.13
  +++ FixCRLF.java	2001/04/03 11:26:26	1.14
  @@ -238,9 +238,9 @@
   
           // log options used
           log("options:" +
  -            " cr=" + (addcr==-1 ? "add" : addcr==0 ? "asis" : "remove") +
  -            " tab=" + (addtab==-1 ? "add" : addtab==0 ? "asis" : "remove") +
  -            " eof=" + (ctrlz==-1 ? "add" : ctrlz==0 ? "asis" : "remove") +
  +            " cr=" + (addcr==1 ? "add" : addcr==0 ? "asis" : "remove") +
  +            " tab=" + (addtab==1 ? "add" : addtab==0 ? "asis" : "remove") +
  +            " eof=" + (ctrlz==1 ? "add" : ctrlz==0 ? "asis" : "remove") +
               " tablength=" + tablength,
               Project.MSG_VERBOSE);
   
  @@ -363,11 +363,54 @@
   
               // output the data
               try {
  +                // Determine whether it should be written,
  +                // that is if it is different than the potentially already existing file
  +                boolean write = false;
  +                byte[] existingdata = indata;
                   File destFile = srcFile;
  -                if (destDir != null) destFile = new File(destDir, files[i]);
  -                FileOutputStream outStream = new FileOutputStream(destFile);
  -                outStream.write(outdata,0,o);
  -                outStream.close();
  +                if (destDir != null) {
  +                    destFile = new File(destDir, files[i]);
  +                    if(destFile.isFile()) {
  +                        int len = (int)destFile.length();
  +                        if(len != o) {
  +                            write = true;
  +                        } else {
  +                            existingdata = new byte[len];
  +                            try {
  +                                FileInputStream in = new FileInputStream(destFile);
  +                                in.read(existingdata);
  +                                in.close();
  +                            } catch (IOException e) {
  +                                throw new BuildException(e);
  +                            }
  +                        }
  +                    } else {
  +                        write = true;
  +                    }
  +                }
  +
  +                if(!write) {
  +                    if(existingdata.length != o) {
  +                        write = true;
  +                    } else {
  +                        for(int j = 0; j < o; ++j) {
  +                            if(existingdata[j] != outdata[j]) {
  +                                write = true;
  +                                break;
  +                            }
  +                        }
  +                    }
  +                }
  +
  +                if(write) {
  +                    log(destFile + " is being written", Project.MSG_VERBOSE);
  +                    FileOutputStream outStream = new FileOutputStream(destFile);
  +                    outStream.write(outdata,0,o);
  +                    outStream.close();
  +                } else {
  +                    log(destFile + " is not written, as the contents are identical",
  +                        Project.MSG_VERBOSE);
  +                }
               } catch (IOException e) {
                   throw new BuildException(e);
               }
  
  
  

Mime
View raw message