diff --git a/.travis.yml b/.travis.yml
index 949e94b8..13f6528e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,6 @@
language: java
jdk:
- - oraclejdk7
+ - openjdk7
- oraclejdk8
# No need for preliminary install step.
diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java
index 6b910b29..3dc0af41 100644
--- a/src/main/java/org/codehaus/plexus/util/FileUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java
@@ -1164,7 +1164,7 @@ private static void doCopyFileUsingNewIO( File source, File destination )
public static boolean copyFileIfModified( final File source, final File destination )
throws IOException
{
- if ( destination.lastModified() < source.lastModified() )
+ if ( isSourceNewerThanDestination( source, destination ) )
{
copyFile( source, destination );
@@ -2289,7 +2289,8 @@ public static File createTempFile( String prefix, String suffix, File parentDir
}
/**
- * If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified()
+ * If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified(),
+ * if the files were both created on 1970-01-01 : 0000.00
*
* @param from the file to copy
* @param to the destination file
@@ -2309,8 +2310,8 @@ public static abstract class FilterWrapper
}
/**
- * If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified() or if
- * overwrite is true
+ * If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified(),
+ * if the files were both created on 1970-01-01 : 0000.00 or if overwrite is true
*
* @param from the file to copy
* @param to the destination file
@@ -2367,13 +2368,17 @@ public static void copyFile( File from, File to, String encoding, FilterWrapper[
}
else
{
- if ( to.lastModified() < from.lastModified() || overwrite )
+ if ( isSourceNewerThanDestination( from, to ) || overwrite )
{
copyFile( from, to );
}
}
}
+ private static boolean isSourceNewerThanDestination( File source, File destination ) {
+ return ( destination.lastModified() == 0L && source.lastModified() == 0L ) || destination.lastModified() < source.lastModified();
+ }
+
/**
* Note: the file content is read with platform encoding
*
diff --git a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java
index 2ba6682b..d6851feb 100644
--- a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java
+++ b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java
@@ -439,6 +439,23 @@ public void testCopyIfModifiedWhenSourceIsOlder()
assertFalse( "Source file should not have been copied.", FileUtils.copyFileIfModified( source, destination ) );
}
+ public void testCopyIfModifiedWhenSourceHasZeroDate()
+ throws Exception
+ {
+ FileUtils.forceMkdir( new File( getTestDirectory() + "/temp" ) );
+
+ // Source modified on 1970-1-1 0000.0
+ File source = new File( getTestDirectory(), "copy1.txt" );
+ FileUtils.copyFile( testFile1, source );
+ source.setLastModified( 0L );
+
+ // A non existing destination
+ File destination = new File( getTestDirectory(), "/temp/copy1.txt" );
+
+ // Should copy the source to the non existing destination.
+ assertTrue( "Source file should have been copied.", FileUtils.copyFileIfModified( source, destination ) );
+ }
+
// forceDelete
public void testForceDeleteAFile1()