You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2022/07/25 14:11:25 UTC

[maven-shared-utils] branch master updated (2bf1e03 -> 5b78029)

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git


    from 2bf1e03  some upgrade and dependabot
     new cbd1acd  [MSHARED-1107] Make copyFile succeed with source file having lastModified() = 0
     new 5b78029  Fix formatting

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/maven/shared/utils/io/FileUtils.java    |  2 +-
 .../maven/shared/utils/io/FileUtilsTest.java       | 46 ++++++++++++++++------
 2 files changed, 36 insertions(+), 12 deletions(-)


[maven-shared-utils] 01/02: [MSHARED-1107] Make copyFile succeed with source file having lastModified() = 0

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git

commit cbd1acd141c7cdc80fe3750ef89a1127c10578bb
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Mon Jul 25 14:56:06 2022 +0200

    [MSHARED-1107] Make copyFile succeed with source file having lastModified() = 0
    
    Also check for existence of destination file before overwriting.
    
    This closes #105
---
 .../apache/maven/shared/utils/io/FileUtils.java    |  2 +-
 .../maven/shared/utils/io/FileUtilsTest.java       | 24 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java b/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java
index 79c96b3..100ad81 100644
--- a/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java
+++ b/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java
@@ -1901,7 +1901,7 @@ public class FileUtils
     {
         if ( wrappers == null || wrappers.length == 0 )
         {
-            if ( overwrite || to.lastModified() < from.lastModified() )
+            if ( overwrite || !to.exists() || to.lastModified() < from.lastModified() )
             {
                 copyFile( from, to );
             }
diff --git a/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
index 4dfa4fa..1f7daba 100644
--- a/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
@@ -439,6 +439,30 @@ public class FileUtilsTest
         assertFileContent( to, "Hello World!" );
     }
 
+    @Test
+    public void copyFileWithNoFiltersAndLastModifiedDateOfZeroAndNoDestination()
+        throws Exception
+    {
+        File from = write(
+            "from.txt",
+            MODIFIED_YESTERDAY,
+            "Hello World!"
+        );
+        File to = new File(
+            tempFolder.getRoot(),
+            "to.txt"
+        );
+
+        from.setLastModified( 0 );
+        FileUtils.copyFile( from, to, null, ( FileUtils.FilterWrapper[] ) null);
+
+        assertTrue(
+            "to.txt did not exist so should have been written",
+            to.lastModified() >= MODIFIED_TODAY
+        );
+        assertFileContent( to, "Hello World!" );
+    }
+
     @Test
     public void copyFileWithNoFiltersAndOutdatedDestination()
             throws Exception


[maven-shared-utils] 02/02: Fix formatting

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git

commit 5b78029657e60b71daa596914ec1cf48057af732
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Mon Jul 25 15:40:09 2022 +0200

    Fix formatting
---
 .../maven/shared/utils/io/FileUtilsTest.java       | 24 +++++++++++-----------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
index 1f7daba..51cfb17 100644
--- a/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
@@ -430,7 +430,7 @@ public class FileUtilsTest
             "to.txt"
         );
 
-        FileUtils.copyFile( from, to, null, ( FileUtils.FilterWrapper[] ) null);
+        FileUtils.copyFile( from, to, null, (FileUtils.FilterWrapper[]) null );
 
         assertTrue(
             "to.txt did not exist so should have been written",
@@ -454,7 +454,7 @@ public class FileUtilsTest
         );
 
         from.setLastModified( 0 );
-        FileUtils.copyFile( from, to, null, ( FileUtils.FilterWrapper[] ) null);
+        FileUtils.copyFile( from, to, null, (FileUtils.FilterWrapper[]) null );
 
         assertTrue(
             "to.txt did not exist so should have been written",
@@ -478,7 +478,7 @@ public class FileUtilsTest
             "Older content"
         );
 
-        FileUtils.copyFile( from, to, null, ( FileUtils.FilterWrapper[] ) null);
+        FileUtils.copyFile( from, to, null, (FileUtils.FilterWrapper[]) null );
 
         assertTrue(
             "to.txt was outdated so should have been overwritten",
@@ -502,7 +502,7 @@ public class FileUtilsTest
             "Older content"
         );
 
-        FileUtils.copyFile( from, to, null, ( FileUtils.FilterWrapper[] ) null);
+        FileUtils.copyFile( from, to, null, (FileUtils.FilterWrapper[]) null );
 
         assertTrue(
             "to.txt was newer so should have been left alone",
@@ -526,7 +526,7 @@ public class FileUtilsTest
             "Older content"
         );
 
-        FileUtils.copyFile( from, to, null, null, true);
+        FileUtils.copyFile( from, to, null, null, true );
 
         assertTrue(
             "to.txt was newer but the overwrite should have been forced",
@@ -695,7 +695,7 @@ public class FileUtilsTest
             };
     }
 
-    private File write( @Nonnull String name, long lastModified, @Nonnull String text) throws IOException
+    private File write( @Nonnull String name, long lastModified, @Nonnull String text ) throws IOException
     {
         final File file = new File( tempFolder.getRoot(), name );
         try ( final Writer writer = new FileWriter( file ) ) {
@@ -744,7 +744,7 @@ public class FileUtilsTest
         assertThat( "Check Exist", destination.exists(), is( false ) );
     }
 
-    @Test(expected = IOException.class)
+    @Test( expected = IOException.class )
     public void deleteFileNofile()
         throws Exception
     {
@@ -1035,7 +1035,7 @@ public class FileUtilsTest
         File file1 = new File( tempFolder.getRoot(), "test.txt" );
         String filename = file1.getAbsolutePath();
 
-        //Create test file on-the-fly (used to be in CVS)
+        //Create test file on-the-fly
         try ( OutputStream out = new java.io.FileOutputStream( file1 ) )
         {
             out.write( "This is a test".getBytes( "UTF-8" ) );
@@ -1571,7 +1571,7 @@ public class FileUtilsTest
     }
 
     @Test
-    @Ignore("Wait until we can run with assembly 2.5 which will support symlinks properly")
+    @Ignore( "Wait until we can run with assembly 2.5 which will support symlinks properly" )
     public void isASymbolicLink()
         throws IOException
     {
@@ -1579,16 +1579,16 @@ public class FileUtilsTest
         assumeFalse( Os.isFamily( Os.FAMILY_WINDOWS ) );
 
         File file = new File( "src/test/resources/symlinks/src/symDir" );
-        assertTrue(FileUtils.isSymbolicLink(file  ));
+        assertTrue( FileUtils.isSymbolicLink( file ) );
     }
 
     @Test
-    @Ignore("Wait until we can run with assembly 2.5 which will support symlinks properly")
+    @Ignore( "Wait until we can run with assembly 2.5 which will support symlinks properly" )
     public void notASymbolicLink()
         throws IOException
     {
         File file = new File( "src/test/resources/symlinks/src/" );
-        assertFalse(FileUtils.isSymbolicLink(file  ));
+        assertFalse( FileUtils.isSymbolicLink( file ) );
     }
 
     @Test