PR: 25770 Submitted by: Yuji Yamano git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277778 13f79535-47bb-0310-9956-ffa450edef68master
@@ -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: | ||||
----------- | ----------- | ||||
@@ -231,6 +231,12 @@ supports all attributes of <code><fileset></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> <fixcrlf srcdir="${src}" | <pre> <fixcrlf srcdir="${src}" | ||||
@@ -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 © 2000-2004 The Apache Software Foundation. All rights | |||||
<p align="center">Copyright © 2000-2005 The Apache Software Foundation. All rights | |||||
Reserved.</p> | Reserved.</p> | ||||
</body> | </body> | ||||
@@ -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> |
@@ -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; | ||||
} | } | ||||
@@ -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()) { | ||||