This patch lets you specify an attribute 'justwarn' to the <fixcrlf> task. If set (default off of course) then whenever the task would normally have replaced a file with some changes, it instead just prints a warning message alerting you to the fact that the file is not in the desired form.

Handy e.g. if you want to see if people have been using CVS incorrectly (copy Win working dir to Unix & commit) without necessarily changing anything.

Is there a more standard idiom for this (e.g. attribute name) that could be followed instead?

-Jesse

--
Jesse Glick   <mailto:[EMAIL PROTECTED]>
NetBeans, Open APIs  <http://www.netbeans.org/>
tel (+4202) 3300-9161 Sun Micro x49161 Praha CR
Index: WHATSNEW
===================================================================
RCS file: /home/cvspublic/jakarta-ant/WHATSNEW,v
retrieving revision 1.115
diff -u -t -r1.115 WHATSNEW
--- WHATSNEW    2001/06/22 07:45:15     1.115
+++ WHATSNEW    2001/06/27 15:51:58
@@ -41,7 +41,7 @@
 * <fail> supports nested text
 
 * <fixcrlf> won't override files that are already in the correct
-   format.
+   format; with justwarn attribute, only warns about noncompliant files
 
 * <sql> now supports REM comments as well as // and --
 
Index: docs/manual/CoreTasks/fixcrlf.html
===================================================================
RCS file: /home/cvspublic/jakarta-ant/docs/manual/CoreTasks/fixcrlf.html,v
retrieving revision 1.2
diff -u -t -r1.2 fixcrlf.html
--- docs/manual/CoreTasks/fixcrlf.html  2001/02/13 12:31:51     1.2
+++ docs/manual/CoreTasks/fixcrlf.html  2001/06/27 15:51:59
@@ -127,6 +127,14 @@
       </td>
     <td valign="top" align="center">No</td>
   </tr>
+  <tr>
+    <td valign="top">justwarn</td>
+    <td valign="top">If set to true, do not actually change anything;
+    only warn that the file needs to be changed. By default false,
+    meaning change the files where needed. Of course this may
+    not be given in conjunction with <code>destdir</code>.</td>
+    <td valign="top" align="center">No</td>
+  </tr>
 </table>
 <h3>Examples</h3>
 <pre>  &lt;fixcrlf srcdir=&quot;${src}&quot;
Index: src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java,v
retrieving revision 1.14
diff -u -t -r1.14 FixCRLF.java
--- src/main/org/apache/tools/ant/taskdefs/FixCRLF.java 2001/04/03 11:26:26     
1.14
+++ src/main/org/apache/tools/ant/taskdefs/FixCRLF.java 2001/06/27 15:52:01
@@ -77,6 +77,7 @@
  * <li>cr
  * <li>tab
  * <li>eof
+ * <li>justwarn
  * </ul>
  * Of these arguments, only <b>sourcedir</b> is required.
  * <p>
@@ -103,6 +104,8 @@
     private File srcDir;
     private File destDir = null;
 
+    private boolean justwarn = false;
+
     /**
      * Defaults the properties based on the system type.
      * <ul><li>Unix: cr="remove" tab="asis" eof="remove"
@@ -213,6 +216,14 @@
     }
 
     /**
+     * If true, only warn about files that would be changed, do not really do 
it.
+     * @param jw true to only warn and make no change
+     */
+    public void setJustwarn(boolean jw) {
+        justwarn = jw;
+    }
+
+    /**
      * Executes the task.
      */
     public void execute() throws BuildException {
@@ -234,6 +245,9 @@
             if (!destDir.isDirectory()) {
                 throw new BuildException("destdir is not a directory!");
             }
+            if (justwarn) {
+                throw new BuildException("cannot set both justwarn and 
destdir");
+            }
         }
 
         // log options used
@@ -403,10 +417,16 @@
                 }
 
                 if(write) {
-                    log(destFile + " is being written", Project.MSG_VERBOSE);
-                    FileOutputStream outStream = new 
FileOutputStream(destFile);
-                    outStream.write(outdata,0,o);
-                    outStream.close();
+                    if (justwarn) {
+                        // ":1" to ensure this is treated as an error message
+                        // by e.g. Emacs so it may be hyperlinked
+                        log(destFile + ":1: incorrect line endings or tabs", 
Project.MSG_WARN);
+                    } else {
+                        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);

Reply via email to