Browse Source

Add preservelastmodified attribute to fixcrlf.

PR: 25770
Submitted by: Yuji Yamano


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277778 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 20 years ago
parent
commit
015ec69fd1
5 changed files with 52 additions and 2 deletions
  1. +2
    -0
      WHATSNEW
  2. +7
    -1
      docs/manual/CoreTasks/fixcrlf.html
  3. +24
    -0
      src/etc/testcases/taskdefs/fixcrlf/build.xml
  4. +14
    -0
      src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  5. +5
    -1
      src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java

+ 2
- 0
WHATSNEW View File

@@ -241,6 +241,8 @@ Other changes:
* Pathconvert no longer requires that one of (targetos|pathsep|dirsep) * Pathconvert no longer requires that one of (targetos|pathsep|dirsep)
be set; platform defaults are used when this is the case. be set; platform defaults are used when this is the case.


* Added preservelastmodified attribute to fixcrlf task. Bugzilla 25770.

Fixed bugs: Fixed bugs:
----------- -----------




+ 7
- 1
docs/manual/CoreTasks/fixcrlf.html View File

@@ -231,6 +231,12 @@ supports all attributes of <code>&lt;fileset&gt;</code>
of a processed file. (Since ant 1.6.1)</td> of a processed file. (Since ant 1.6.1)</td>
<td align="center">No - default is <i>true</i></td> <td align="center">No - default is <i>true</i></td>
</tr> </tr>
<tr>
<td valign="top">preservelastmodified</td>
<td valign="top">Whether to preserve the last modified
date of source files. <b>Since ant 1.6.3</b></td>
<td align="center">No; default is <i>false</i></td>
</tr>
</table> </table>
<h3>Examples</h3> <h3>Examples</h3>
<pre> &lt;fixcrlf srcdir=&quot;${src}&quot; <pre> &lt;fixcrlf srcdir=&quot;${src}&quot;
@@ -283,7 +289,7 @@ EOF characters are left alone if run on
DOS systems, and are removed if run on Unix systems. DOS systems, and are removed if run on Unix systems.
You never know what editor a user will use to browse README's.</p> You never know what editor a user will use to browse README's.</p>
<hr> <hr>
<p align="center">Copyright &copy; 2000-2004 The Apache Software Foundation. All rights
<p align="center">Copyright &copy; 2000-2005 The Apache Software Foundation. All rights
Reserved.</p> Reserved.</p>


</body> </body>


+ 24
- 0
src/etc/testcases/taskdefs/fixcrlf/build.xml View File

@@ -170,4 +170,28 @@
<fixcrlf file="input/longlines.crlf" srcdir="input" destdir="result"/> <fixcrlf file="input/longlines.crlf" srcdir="input" destdir="result"/>
</target> </target>


<target name="testPreserveLastModified" depends="init">
<fixcrlf file="input/longlines.crlf" destdir="result"
preservelastmodified="true" />
<fail>
<condition>
<not>
<uptodate srcfile="result/longlines.crlf"
targetfile="input/longlines.crlf" />
</not>
</condition>
</fail>

<touch file="result/longlines.crlf" millis="0" />

<fixcrlf file="result/longlines.crlf" destdir="result" eol="lf"
preservelastmodified="true" />

<fileset id="fs" file="result/longlines.crlf">
<date when="equal" millis="0" />
</fileset>
<property name="fs" refid="fs" />
<fail unless="fs" />
</target>

</project> </project>

+ 14
- 0
src/main/org/apache/tools/ant/taskdefs/FixCRLF.java View File

@@ -118,6 +118,7 @@ public class FixCRLF extends MatchingTask {
private int tabs; private int tabs;
private boolean javafiles = false; private boolean javafiles = false;
private boolean fixlast = true; private boolean fixlast = true;
private boolean preserveLastModified = false;


private File srcDir; private File srcDir;
private File destDir = null; private File destDir = null;
@@ -318,6 +319,14 @@ public class FixCRLF extends MatchingTask {
this.fixlast = fixlast; this.fixlast = fixlast;
} }


/**
* Set to true if keeping the last modified time as the original files.
* @since Ant 1.6.3
*/
public void setPreserveLastModified(boolean preserve) {
preserveLastModified = preserve;
}

/** /**
* Executes the task. * Executes the task.
*/ */
@@ -381,6 +390,7 @@ public class FixCRLF extends MatchingTask {


private void processFile(String file) throws BuildException { private void processFile(String file) throws BuildException {
File srcFile = new File(srcDir, file); File srcFile = new File(srcDir, file);
long lastModified = srcFile.lastModified();
File destD = destDir == null ? srcDir : destDir; File destD = destDir == null ? srcDir : destDir;
File tmpFile = null; File tmpFile = null;
BufferedWriter outWriter; BufferedWriter outWriter;
@@ -557,6 +567,10 @@ public class FixCRLF extends MatchingTask {


if (destIsWrong) { if (destIsWrong) {
FILE_UTILS.rename(tmpFile, destFile); FILE_UTILS.rename(tmpFile, destFile);
if (preserveLastModified) {
log("preserved lastModified", Project.MSG_DEBUG);
FILE_UTILS.setFileLastModified(destFile, lastModified);
}
tmpFile = null; tmpFile = null;
} }




+ 5
- 1
src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2004 The Apache Software Foundation
* Copyright 2001-2005 The Apache Software Foundation
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -197,6 +197,10 @@ public class FixCrLfTest extends BuildFileTest {
executeTarget("createParentDirs"); executeTarget("createParentDirs");
} }


public void testPreserveLastModified() {
executeTarget("testPreserveLastModified");
}

public void assertEqualContent(File expect, File result) public void assertEqualContent(File expect, File result)
throws AssertionFailedError, IOException { throws AssertionFailedError, IOException {
if (!result.exists()) { if (!result.exists()) {


Loading…
Cancel
Save