From 015ec69fd10eda4f947c101cb73fd9edf1ed7cf0 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Thu, 3 Mar 2005 16:24:26 +0000 Subject: [PATCH] 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 --- WHATSNEW | 2 ++ docs/manual/CoreTasks/fixcrlf.html | 8 ++++++- src/etc/testcases/taskdefs/fixcrlf/build.xml | 24 +++++++++++++++++++ .../apache/tools/ant/taskdefs/FixCRLF.java | 14 +++++++++++ .../tools/ant/taskdefs/FixCrLfTest.java | 6 ++++- 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 8a86a74ac..0fbf10cbf 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -241,6 +241,8 @@ Other changes: * Pathconvert no longer requires that one of (targetos|pathsep|dirsep) be set; platform defaults are used when this is the case. +* Added preservelastmodified attribute to fixcrlf task. Bugzilla 25770. + Fixed bugs: ----------- diff --git a/docs/manual/CoreTasks/fixcrlf.html b/docs/manual/CoreTasks/fixcrlf.html index 78ff157dd..a33166497 100644 --- a/docs/manual/CoreTasks/fixcrlf.html +++ b/docs/manual/CoreTasks/fixcrlf.html @@ -231,6 +231,12 @@ supports all attributes of <fileset> of a processed file. (Since ant 1.6.1) No - default is true + + preservelastmodified + Whether to preserve the last modified + date of source files. Since ant 1.6.3 + No; default is false +

Examples

  <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.
 You never know what editor a user will use to browse README's.


-

Copyright © 2000-2004 The Apache Software Foundation. All rights +

Copyright © 2000-2005 The Apache Software Foundation. All rights Reserved.

diff --git a/src/etc/testcases/taskdefs/fixcrlf/build.xml b/src/etc/testcases/taskdefs/fixcrlf/build.xml index 823e58557..8fdf45795 100644 --- a/src/etc/testcases/taskdefs/fixcrlf/build.xml +++ b/src/etc/testcases/taskdefs/fixcrlf/build.xml @@ -170,4 +170,28 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java b/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java index eaeb77adf..db6df3fdd 100644 --- a/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java +++ b/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java @@ -118,6 +118,7 @@ public class FixCRLF extends MatchingTask { private int tabs; private boolean javafiles = false; private boolean fixlast = true; + private boolean preserveLastModified = false; private File srcDir; private File destDir = null; @@ -318,6 +319,14 @@ public class FixCRLF extends MatchingTask { 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. */ @@ -381,6 +390,7 @@ public class FixCRLF extends MatchingTask { private void processFile(String file) throws BuildException { File srcFile = new File(srcDir, file); + long lastModified = srcFile.lastModified(); File destD = destDir == null ? srcDir : destDir; File tmpFile = null; BufferedWriter outWriter; @@ -557,6 +567,10 @@ public class FixCRLF extends MatchingTask { if (destIsWrong) { FILE_UTILS.rename(tmpFile, destFile); + if (preserveLastModified) { + log("preserved lastModified", Project.MSG_DEBUG); + FILE_UTILS.setFileLastModified(destFile, lastModified); + } tmpFile = null; } diff --git a/src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java b/src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java index cc110918d..2653bbedf 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/FixCrLfTest.java @@ -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"); * you may not use this file except in compliance with the License. @@ -197,6 +197,10 @@ public class FixCrLfTest extends BuildFileTest { executeTarget("createParentDirs"); } + public void testPreserveLastModified() { + executeTarget("testPreserveLastModified"); + } + public void assertEqualContent(File expect, File result) throws AssertionFailedError, IOException { if (!result.exists()) {