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/testcases/org/apache/tools/ant/taskdefs FixCrLfTest.java
Date Mon, 06 Aug 2001 12:25:56 GMT
bodewig     01/08/06 05:25:56

  Modified:    src/main/org/apache/tools/ant/taskdefs FixCRLF.java
               src/testcases/org/apache/tools/ant/taskdefs FixCrLfTest.java
  Log:
  Make log messages from System.out calls, remove some code in execute
  that was redundant, remove some tabs, add testcase that checks that
  files don't get overwritten if they'd be identical to the new version.
  
  Revision  Changes    Path
  1.18      +9 -67     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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- FixCRLF.java	2001/08/05 22:17:26	1.17
  +++ FixCRLF.java	2001/08/06 12:25:56	1.18
  @@ -53,20 +53,16 @@
    */
   
   package org.apache.tools.ant.taskdefs;
  -import org.apache.tools.ant.Project;
  +
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.DirectoryScanner;
  +import org.apache.tools.ant.Project;
   import org.apache.tools.ant.types.EnumeratedAttribute;
   
   import java.io.*;
   import java.util.*;
   
   /**
  - * FixCRLF.java
  - *
  - * Based on FixCR.java
  - * by Sam Ruby <a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a>.
  - *
    * Task to convert text source files to local OS formatting conventions, as
    * well as repair text files damaged by misconfigured or misguided editors or
    * file transfer programs.
  @@ -105,7 +101,7 @@
    *
    * @author Sam Ruby <a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a>
    * @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
  - * @version $Revision: 1.17 $ $Name:  $
  + * @version $Revision: 1.18 $ $Name:  $
    */
   
   public class FixCRLF extends MatchingTask {
  @@ -137,7 +133,6 @@
       private StringBuffer linebuf = new StringBuffer(1024);
       private StringBuffer linebuf2 = new StringBuffer(1024);
       private int eol;
  -    private int addcr = UNDEF;
       private String eolstr;
       private int ctrlz;
       private int tabs;
  @@ -317,7 +312,7 @@
        */
       public void execute() throws BuildException {
           // first off, make sure that we've got a srcdir and destdir
  -	
  +        
           if (srcDir == null) {
               throw new BuildException("srcdir attribute must be set!");
           }
  @@ -336,57 +331,6 @@
               }
           }
   
  -	// Set up the correct EOL values
  -	if (eol == UNDEF) {
  -	    if (addcr == UNDEF) {
  -		// Neither eol not addcr has been defined
  -		// go for the system defaults
  -		if (System.getProperty("line.separator").equals("\r")) {
  -		    eol = CR;
  -		} else if (System.getProperty("line.separator").equals("\n")) {
  -		    eol = LF;
  -		} else {
  -		    eol = CRLF;
  -		}
  -		
  -	    } // end of if (addcr == UNDEF)
  -	    else {
  -		// addcr has been defined - translate to eol values
  -		switch (addcr) {
  -		case ADD:
  -		    eol = CRLF;
  -		    break;
  -		    
  -		case REMOVE:
  -		    eol = LF;
  -		    break;
  -		    
  -		case ASIS:
  -		    eol = ASIS;
  -		    break;
  -
  -		} // end of switch (addcr)
  -		
  -	    } // end of if (addcr == UNDEF)else
  -	    
  -	} // end of if (eol == UNDEF)
  -
  -	switch (eol) {
  -	    // set eolstr value unless ASIS
  -	case CR:
  -	    eolstr = new String("\r");
  -	    break;
  -	    
  -	case LF:
  -	    eolstr = new String("\n");
  -	    break;
  -	    
  -	case CRLF:
  -	    eolstr = new String("\r\n");
  -	    break;
  -	    
  -	} // end of switch (eol)
  -	
           // log options used
           log("options:" +
               " eol=" +
  @@ -616,10 +560,9 @@
   
               if (destFile.exists()) {
                   // Compare the destination with the temp file
  -                System.out.println("destFile exists");
  +                log("destFile exists", Project.MSG_DEBUG);
                   if ( ! filesEqual(destFile, tmpFile)) {
  -                    System.out.println("destFile exists: files not equal");
  -                    log(destFile + " is being written", Project.MSG_VERBOSE);
  +                    log(destFile + " is being written", Project.MSG_DEBUG);
                       if (!destFile.delete()) {
                           throw new BuildException("Unable to delete "
                                                    + destFile);
  @@ -633,17 +576,16 @@
                       }
   
                   } else { // destination is equal to temp file
  -                    System.out.println("destFile exists: files equal");
                       log(destFile +
                           " is not written, as the contents are identical",
  -                        Project.MSG_VERBOSE);
  +                        Project.MSG_DEBUG);
                       if (!tmpFile.delete()) {
                           throw new BuildException("Unable to delete "
  -                                                 + destFile);
  +                                                 + tmpFile);
                       }
                   }
               } else { // destFile does not exist - write the temp file
  -                System.out.println("destFile does not exist");
  +                log("destFile does not exist", Project.MSG_DEBUG);
                   if (!tmpFile.renameTo(destFile)) {
                       throw new BuildException(
                               "Failed to transform " + srcFile
  
  
  
  1.2       +29 -0     jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java
  
  Index: FixCrLfTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FixCrLfTest.java	2001/08/03 11:22:22	1.1
  +++ FixCrLfTest.java	2001/08/06 12:25:56	1.2
  @@ -130,6 +130,35 @@
                              new File("src/etc/testcases/taskdefs/fixcrlf/result/Junk9.java"));
       }
       
  +    public void testNoOverwrite() throws IOException {
  +        executeTarget("test1");
  +        File result = 
  +            new File("src/etc/testcases/taskdefs/fixcrlf/result/Junk1.java");
  +        long modTime = result.lastModified();
  +
  +        /*
  +         * Sleep for some time to make sure a newer file would get a
  +         * more recent timestamp according to the file system's
  +         * granularity (should be > 2s to account for Windows FAT).
  +         */
  +        try {
  +            Thread.currentThread().sleep(5000);
  +        } catch (InterruptedException ie) {
  +            fail(ie.getMessage());
  +        } // end of try-catch
  +
  +        /* 
  +         * make sure we get a new Project instance or the target won't get run
  +         * a second time.
  +         */
  +        configureProject("src/etc/testcases/taskdefs/fixcrlf/build.xml");
  +
  +        executeTarget("test1");
  +        result = 
  +            new File("src/etc/testcases/taskdefs/fixcrlf/result/Junk1.java");
  +        assertEquals(modTime, result.lastModified());
  +    }
  +
       public void assertEqualContent(File expect, File result) 
           throws AssertionFailedError, IOException {
           if (!result.exists()) {
  
  
  

Mime
View raw message