From 97786f1312c165fc61e1c5c4172607ab48daea0a Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sun, 14 Feb 2021 09:32:13 -0500 Subject: [PATCH 1/9] Unignore copyDirectory tests and fix broken behavior that caused them to be ignored. Deprecate these methods in favor of better maintained and documented Apache Commons IO methods from which they were copied and pasted 10+ years ago. --- .../maven/shared/utils/io/FileUtils.java | 31 +++++++++--- .../maven/shared/utils/io/FileUtilsTest.java | 50 +++++++------------ 2 files changed, 41 insertions(+), 40 deletions(-) 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 f1947827..e4e52266 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 @@ -1,5 +1,7 @@ package org.apache.maven.shared.utils.io; +import org.apache.commons.io.IOUtils; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -52,6 +54,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Random; /** @@ -633,7 +636,7 @@ public static boolean contentEquals( @Nonnull final File file1, @Nonnull final F try ( InputStream input1 = new FileInputStream( file1 ); InputStream input2 = new FileInputStream( file2 ) ) { - return IOUtil.contentEquals( input1, input2 ); + return IOUtils.contentEquals( input1, input2 ); } } @@ -750,7 +753,7 @@ public static void copyFileToDirectory( @Nonnull final File source, @Nonnull fin { if ( destinationDirectory.exists() && !destinationDirectory.isDirectory() ) { - throw new IllegalArgumentException( "Destination is not a directory" ); + throw new IOException( "Destination is not a directory" ); } copyFile( source, new File( destinationDirectory, source.getName() ) ); @@ -1022,9 +1025,9 @@ private static void copyStreamToFile( @Nonnull @WillClose final InputStream sour } /** - * Resolve a file filename to it's canonical form. If filename is - * relative (doesn't start with /), it will be resolved relative to - * baseFile, otherwise it is treated as a normal root-relative path. + * Resolve a file filename to its canonical form. If filename is + * relative (doesn't start with /), it is resolved relative to + * baseFile. Otherwise it is treated as a normal root-relative path. * * @param baseFile where to resolve filename from, if filename is relative * @param filename absolute or relative file path to resolve @@ -1605,13 +1608,20 @@ public static List getFiles( @Nonnull File directory, @Nullable String inc /** * Copy the contents of a directory into another one. * - * @param sourceDirectory the source directory + * @param sourceDirectory the source directory. If the source does not exist, + * the method simply returns. * @param destinationDirectory the target directory * @throws IOException if any + * @deprecated use {@code org.apache.commons.io.FileUtils.copyDirectory()} */ + @Deprecated public static void copyDirectory( @Nonnull File sourceDirectory, @Nonnull File destinationDirectory ) throws IOException { + Objects.requireNonNull( destinationDirectory ); + if ( destinationDirectory.equals( sourceDirectory ) ) { + throw new IOException( "Can't copy directory " + sourceDirectory + " to itself." ); + } copyDirectory( sourceDirectory, destinationDirectory, "**", null ); } @@ -1622,9 +1632,11 @@ public static void copyDirectory( @Nonnull File sourceDirectory, @Nonnull File d * @param destinationDirectory the target directory * @param includes Ant include pattern * @param excludes Ant exclude pattern - * @throws IOException if any + * @throws IOException if the source is a file or cannot be copied * @see #getFiles(File, String, String) + * @deprecated use {@code org.apache.commons.io.FileUtils.copyDirectory()} */ + @Deprecated public static void copyDirectory( @Nonnull File sourceDirectory, @Nonnull File destinationDirectory, @Nullable String includes, @Nullable String excludes ) throws IOException @@ -1633,6 +1645,9 @@ public static void copyDirectory( @Nonnull File sourceDirectory, @Nonnull File d { return; } + else if ( !sourceDirectory.isDirectory() ) { + throw new IOException( sourceDirectory + " is not a directory." ); + } List files = getFiles( sourceDirectory, includes, excludes ); @@ -1686,7 +1701,7 @@ private static void copyDirectoryStructure( @Nonnull File sourceDirectory, @Nonn if ( !sourceDirectory.exists() ) { - throw new IOException( "Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ")." ); + throw new IOException( "Source directory doesn't exist (" + sourceDirectory.getAbsolutePath() + ")." ); } File[] files = sourceDirectory.listFiles(); 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 9fa7c85e..c3950729 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 @@ -655,7 +655,7 @@ public void copyFileWithFilteringAndNewerDestinationAndMatchingContent() private FileUtils.FilterWrapper[] wrappers( String key, String value ) { - final Map map = new HashMap<>(); + final Map map = new HashMap<>(); map.put( key, value ); return new FileUtils.FilterWrapper[] { @@ -912,19 +912,6 @@ public void copyDirectoryToGrandChild() assertThat( FileUtils.sizeOfDirectory( grandParentDir ), is( expectedSize ) ); } - /** - * Test for IO-217 FileUtils.copyDirectoryToDirectory makes infinite loops - */ - @Test - public void copyDirectoryToItself() - throws Exception - { - File dir = new File( tempFolder.getRoot(), "itself" ); - dir.mkdirs(); - FileUtils.copyDirectory( dir, dir ); - assertThat( FileUtils.getFileAndDirectoryNames( dir, null, null, true, true, true, true ).size(), is( 1 ) ); - } - private void createFilesForTestCopyDirectory( File grandParentDir, File parentDir, File childDir ) throws Exception { @@ -949,29 +936,36 @@ private void createFilesForTestCopyDirectory( File grandParentDir, File parentDi } @Test - @Ignore( "Commons test case that is failing for plexus" ) - public void copyDirectoryErrors() - throws Exception - { + public void copyDirectoryErrors_nullDestination() throws IOException { try { - FileUtils.copyDirectory( null, null ); + FileUtils.copyDirectory( new File( "a" ), null ); fail(); } catch ( NullPointerException ex ) { } + } + + @Test + public void copyDirectoryErrors_copyToSelf() { try { - FileUtils.copyDirectory( new File( "a" ), null ); + FileUtils.copyDirectory( tempFolder.getRoot(), tempFolder.getRoot() ); fail(); } - catch ( NullPointerException ex ) + catch ( IOException ex ) { } + } + + @Test + public void copyDirectoryErrors() + throws IOException + { try { - FileUtils.copyDirectory( null, new File( "a" ) ); + FileUtils.copyDirectory( null, null ); fail(); } catch ( NullPointerException ex ) @@ -979,10 +973,10 @@ public void copyDirectoryErrors() } try { - FileUtils.copyDirectory( new File( "doesnt-exist" ), new File( "a" ) ); + FileUtils.copyDirectory( null, new File( "a" ) ); fail(); } - catch ( IOException ex ) + catch ( NullPointerException ex ) { } try @@ -1001,14 +995,6 @@ public void copyDirectoryErrors() catch ( IOException ex ) { } - try - { - FileUtils.copyDirectory( tempFolder.getRoot(), tempFolder.getRoot() ); - fail(); - } - catch ( IOException ex ) - { - } } // forceDelete From 3175dee457534f841f6807d18db7d894efefe829 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sun, 14 Feb 2021 09:53:03 -0500 Subject: [PATCH 2/9] unignore more tests --- .../maven/shared/utils/io/FileUtils.java | 10 ++-- .../maven/shared/utils/io/FileUtilsTest.java | 46 ++++++++++--------- 2 files changed, 31 insertions(+), 25 deletions(-) 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 e4e52266..8bd0097e 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 @@ -1618,11 +1618,15 @@ public static List getFiles( @Nonnull File directory, @Nullable String inc public static void copyDirectory( @Nonnull File sourceDirectory, @Nonnull File destinationDirectory ) throws IOException { + Objects.requireNonNull( sourceDirectory ); Objects.requireNonNull( destinationDirectory ); if ( destinationDirectory.equals( sourceDirectory ) ) { throw new IOException( "Can't copy directory " + sourceDirectory + " to itself." ); } - copyDirectory( sourceDirectory, destinationDirectory, "**", null ); + else if ( !destinationDirectory.exists() ) { + throw new IOException( "Can't copy directory " + sourceDirectory + " to non-existing " + destinationDirectory ); + } + copyDirectoryStructure( sourceDirectory, destinationDirectory ); } /** @@ -1666,8 +1670,8 @@ else if ( !sourceDirectory.isDirectory() ) { *
  • The sourceDirectory must exist. * * - * @param sourceDirectory the source dir - * @param destinationDirectory the target dir + * @param sourceDirectory the existing directory to be copied + * @param destinationDirectory the new directory to be created * @throws IOException if any * @deprecated use {@code org.apache.commons.io.FileUtils.copyDirectory()} */ 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 c3950729..8529afec 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 @@ -121,7 +121,7 @@ public void setUp() createFile( testFile2, testFile2Size ); } - void createFile( File file, long size ) + private static void createFile( File file, long size ) throws IOException { if ( !file.getParentFile().exists() ) @@ -139,7 +139,7 @@ void createFile( File file, long size ) /** * Assert that the content of a file is equal to that in a byte[]. */ - void assertEqualContent( byte[] b0, File file ) + private void assertEqualContent( byte[] b0, File file ) throws IOException { int count = 0, numRead = 0; @@ -154,16 +154,16 @@ void assertEqualContent( byte[] b0, File file ) assertThat( "Different number of bytes: ", count, is( b0.length ) ); for ( int i = 0; i < count; i++ ) { - assertThat( "byte " + i + " differs", b1[i], is( b0[i] ) ); + assertEquals( "byte " + i + " differs", b1[i], b0[i] ); } } } - void deleteFile( File file ) + private void deleteFile( File file ) { if ( file.exists() ) { - assertThat( "Couldn't delete file: " + file, file.delete(), is( true ) ); + assertTrue( "Couldn't delete file: " + file, file.delete() ); } } @@ -844,25 +844,23 @@ public void copyDirectoryToNonExistingDest() } @Test - @Ignore( "Commons test case that is failing for plexus" ) - public void copyDirectoryToExistingDest() - throws Exception + public void copyDirectoryToExistingDest() throws IOException { createFile( testFile1, 1234 ); createFile( testFile2, 4321 ); File srcDir = tempFolder.getRoot(); File subDir = new File( srcDir, "sub" ); - subDir.mkdir(); + assertTrue( subDir.mkdir() ); File subFile = new File( subDir, "A.txt" ); FileUtils.fileWrite( subFile, "UTF8", "HELLO WORLD" ); File destDir = new File( System.getProperty( "java.io.tmpdir" ), "tmp-FileUtilsTestCase" ); FileUtils.deleteDirectory( destDir ); - destDir.mkdirs(); + assertTrue ( destDir.mkdirs() ); FileUtils.copyDirectory( srcDir, destDir ); - assertThat( FileUtils.sizeOfDirectory( destDir ), is( FileUtils.sizeOfDirectory( srcDir ) ) ); - assertThat( new File( destDir, "sub/A.txt" ).exists(), is( true ) ); + assertEquals( FileUtils.sizeOfDirectory( destDir ), FileUtils.sizeOfDirectory( srcDir ) ); + assertTrue( new File( destDir, "sub/A.txt" ).exists() ); } /** @@ -958,6 +956,18 @@ public void copyDirectoryErrors_copyToSelf() { { } } + + @Test + public void copyDirectoryErrors_destDoesNotExist() { + try + { + FileUtils.copyDirectory( testFile1, new File( "a" ) ); + fail(); + } + catch ( IOException ex ) + { + } + } @Test public void copyDirectoryErrors() @@ -980,14 +990,6 @@ public void copyDirectoryErrors() { } try - { - FileUtils.copyDirectory( testFile1, new File( "a" ) ); - fail(); - } - catch ( IOException ex ) - { - } - try { FileUtils.copyDirectory( tempFolder.getRoot(), testFile1 ); fail(); @@ -1005,9 +1007,9 @@ public void forceDeleteAFile1() { File destination = new File( tempFolder.getRoot(), "copy1.txt" ); destination.createNewFile(); - assertThat( "Copy1.txt doesn't exist to delete", destination.exists(), is( true ) ); + assertTrue( "Copy1.txt doesn't exist to delete", destination.exists() ); FileUtils.forceDelete( destination ); - assertThat( "Check No Exist", !destination.exists(), is( true ) ); + assertFalse( destination.exists() ); } @Test From 98467364940a3750813b6c1910903ea2ca0138ca Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sun, 14 Feb 2021 09:54:39 -0500 Subject: [PATCH 3/9] unignore more tests --- .../java/org/apache/maven/shared/utils/io/FileUtilsTest.java | 5 +---- 1 file changed, 1 insertion(+), 4 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 8529afec..24a4698e 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 @@ -783,9 +783,7 @@ public void copyFile2() } @Test - @Ignore( "Commons test case that is failing for plexus" ) - public void copyToSelf() - throws Exception + public void copyToSelf() throws IOException { File destination = new File( tempFolder.getRoot(), "copy3.txt" ); //Prepare a test file @@ -795,7 +793,6 @@ public void copyToSelf() } @Test - @Ignore( "Commons test case that is failing for plexus" ) public void copyDirectoryToDirectory_NonExistingDest() throws Exception { From c36acea5ca9230df21f9fc36ea0976e89ba3c8d2 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sun, 14 Feb 2021 10:29:18 -0500 Subject: [PATCH 4/9] fix two contradictory ignored tests --- .../maven/shared/utils/io/FileUtils.java | 6 ++- .../maven/shared/utils/io/FileUtilsTest.java | 44 ++----------------- 2 files changed, 7 insertions(+), 43 deletions(-) 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 8bd0097e..c0a6784c 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 @@ -1610,7 +1610,7 @@ public static List getFiles( @Nonnull File directory, @Nullable String inc * * @param sourceDirectory the source directory. If the source does not exist, * the method simply returns. - * @param destinationDirectory the target directory + * @param destinationDirectory the target directory; will be created if it doesn't exist * @throws IOException if any * @deprecated use {@code org.apache.commons.io.FileUtils.copyDirectory()} */ @@ -1624,7 +1624,9 @@ public static void copyDirectory( @Nonnull File sourceDirectory, @Nonnull File d throw new IOException( "Can't copy directory " + sourceDirectory + " to itself." ); } else if ( !destinationDirectory.exists() ) { - throw new IOException( "Can't copy directory " + sourceDirectory + " to non-existing " + destinationDirectory ); + if ( !destinationDirectory.mkdirs() ) { + throw new IOException( "Can't create directory " + destinationDirectory ); + } } copyDirectoryStructure( sourceDirectory, destinationDirectory ); } 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 24a4698e..a497d3c9 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 @@ -793,32 +793,6 @@ public void copyToSelf() throws IOException } @Test - public void copyDirectoryToDirectory_NonExistingDest() - throws Exception - { - createFile( testFile1, 1234 ); - createFile( testFile2, 4321 ); - File srcDir = tempFolder.getRoot(); - File subDir = new File( srcDir, "sub" ); - subDir.mkdir(); - File subFile = new File( subDir, "A.txt" ); - FileUtils.fileWrite( subFile, "UTF8", "HELLO WORLD" ); - File destDir = new File( System.getProperty( "java.io.tmpdir" ), "tmp-FileUtilsTestCase" ); - FileUtils.deleteDirectory( destDir ); - File actualDestDir = new File( destDir, srcDir.getName() ); - - FileUtils.copyDirectory( srcDir, destDir ); - - assertThat( "Check exists", destDir.exists(), is( true ) ); - assertThat( "Check exists", actualDestDir.exists(), is( true ) ); - assertThat( "Check size", FileUtils.sizeOfDirectory( actualDestDir ), - is( FileUtils.sizeOfDirectory( srcDir ) ) ); - assertThat( new File( actualDestDir, "sub/A.txt" ).exists(), is( true ) ); - FileUtils.deleteDirectory( destDir ); - } - - @Test - @Ignore( "Commons test case that is failing for plexus" ) public void copyDirectoryToNonExistingDest() throws Exception { @@ -834,9 +808,9 @@ public void copyDirectoryToNonExistingDest() FileUtils.copyDirectory( srcDir, destDir ); - assertThat( "Check exists", destDir.exists(), is( true ) ); - assertThat( "Check size", FileUtils.sizeOfDirectory( destDir ), is( FileUtils.sizeOfDirectory( srcDir ) ) ); - assertThat( new File( destDir, "sub/A.txt" ).exists(), is( true ) ); + assertTrue( destDir.exists() ); + assertEquals( FileUtils.sizeOfDirectory( destDir ), FileUtils.sizeOfDirectory( srcDir ) ); + assertTrue( new File( destDir, "sub/A.txt" ).exists() ); FileUtils.deleteDirectory( destDir ); } @@ -953,18 +927,6 @@ public void copyDirectoryErrors_copyToSelf() { { } } - - @Test - public void copyDirectoryErrors_destDoesNotExist() { - try - { - FileUtils.copyDirectory( testFile1, new File( "a" ) ); - fail(); - } - catch ( IOException ex ) - { - } - } @Test public void copyDirectoryErrors() From 85aba624b4233cc2ffdaa1a6973fe3b129792910 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sun, 14 Feb 2021 10:31:53 -0500 Subject: [PATCH 5/9] remove copy pasta ignored tests --- .../maven/shared/utils/io/FileUtilsTest.java | 70 ------------------- 1 file changed, 70 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 a497d3c9..5b7de14b 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 @@ -834,76 +834,6 @@ public void copyDirectoryToExistingDest() throws IOException assertTrue( new File( destDir, "sub/A.txt" ).exists() ); } - /** - * Test for IO-141 - */ - @Test - @Ignore( "Commons test case that is failing for plexus" ) - public void copyDirectoryToChild() - throws Exception - { - File grandParentDir = new File( tempFolder.getRoot(), "grandparent" ); - File parentDir = new File( grandParentDir, "parent" ); - File childDir = new File( parentDir, "child" ); - createFilesForTestCopyDirectory( grandParentDir, parentDir, childDir ); - - long expectedCount = - FileUtils.getFileAndDirectoryNames( grandParentDir, null, null, true, true, true, true ).size() - + FileUtils.getFileAndDirectoryNames( parentDir, null, null, true, true, true, true ).size(); - long expectedSize = FileUtils.sizeOfDirectory( grandParentDir ) + FileUtils.sizeOfDirectory( parentDir ); - FileUtils.copyDirectory( parentDir, childDir ); - assertThat( - 1L * FileUtils.getFileAndDirectoryNames( grandParentDir, null, null, true, true, true, true ).size(), - is( expectedCount ) ); - assertThat( FileUtils.sizeOfDirectory( grandParentDir ), is( expectedSize ) ); - } - - /** - * Test for IO-141 - */ - @Test - @Ignore( "Commons test case that is failing for plexus" ) - public void copyDirectoryToGrandChild() - throws Exception - { - File grandParentDir = new File( tempFolder.getRoot(), "grandparent" ); - File parentDir = new File( grandParentDir, "parent" ); - File childDir = new File( parentDir, "child" ); - createFilesForTestCopyDirectory( grandParentDir, parentDir, childDir ); - - long expectedCount = - ( FileUtils.getFileAndDirectoryNames( grandParentDir, null, null, true, true, true, true ).size() * 2 ); - long expectedSize = ( FileUtils.sizeOfDirectory( grandParentDir ) * 2 ); - FileUtils.copyDirectory( grandParentDir, childDir ); - assertThat( - 1L * FileUtils.getFileAndDirectoryNames( grandParentDir, null, null, true, true, true, true ).size(), - is( expectedCount ) ); - assertThat( FileUtils.sizeOfDirectory( grandParentDir ), is( expectedSize ) ); - } - - private void createFilesForTestCopyDirectory( File grandParentDir, File parentDir, File childDir ) - throws Exception - { - File childDir2 = new File( parentDir, "child2" ); - File grandChildDir = new File( childDir, "grandChild" ); - File grandChild2Dir = new File( childDir2, "grandChild2" ); - File file1 = new File( grandParentDir, "file1.txt" ); - File file2 = new File( parentDir, "file2.txt" ); - File file3 = new File( childDir, "file3.txt" ); - File file4 = new File( childDir2, "file4.txt" ); - File file5 = new File( grandChildDir, "file5.txt" ); - File file6 = new File( grandChild2Dir, "file6.txt" ); - FileUtils.deleteDirectory( grandParentDir ); - grandChildDir.mkdirs(); - grandChild2Dir.mkdirs(); - FileUtils.fileWrite( file1, "UTF8", "File 1 in grandparent" ); - FileUtils.fileWrite( file2, "UTF8", "File 2 in parent" ); - FileUtils.fileWrite( file3, "UTF8", "File 3 in child" ); - FileUtils.fileWrite( file4, "UTF8", "File 4 in child2" ); - FileUtils.fileWrite( file5, "UTF8", "File 5 in grandChild" ); - FileUtils.fileWrite( file6, "UTF8", "File 6 in grandChild2" ); - } - @Test public void copyDirectoryErrors_nullDestination() throws IOException { try From d1dd2148e555bd4ed6e3e4151dc4e0ba4376d598 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sun, 14 Feb 2021 10:33:00 -0500 Subject: [PATCH 6/9] organize imports --- src/main/java/org/apache/maven/shared/utils/io/FileUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 c0a6784c..7ee81526 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 @@ -1,7 +1,5 @@ package org.apache.maven.shared.utils.io; -import org.apache.commons.io.IOUtils; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -21,6 +19,7 @@ * under the License. */ +import org.apache.commons.io.IOUtils; import org.apache.maven.shared.utils.Os; import org.apache.maven.shared.utils.StringUtils; From 43709c71bf42098af9d2d41ebf1108b116650337 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sun, 14 Feb 2021 10:34:31 -0500 Subject: [PATCH 7/9] clean markup --- .../java/org/apache/maven/shared/utils/io/FileUtils.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 7ee81526..7c98ba1b 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 @@ -58,9 +58,9 @@ /** * This class provides basic facilities for manipulating files and file paths. - *

    + * *

    Path-related methods

    - *

    + * *

    Methods exist to retrieve the components of a typical file path. For example * /www/hosted/mysite/index.html, can be broken into: *

      @@ -70,13 +70,12 @@ *

      *

      *

      File-related methods

      - *

      + * * There are methods to create a {@link #toFile File from a URL}, copy a * {@link #copyFile File to another File}, * copy a {@link #copyURLToFile URL's contents to a File}, * as well as methods to {@link #deleteDirectory(File) delete} and {@link #cleanDirectory(File) * clean} a directory. - *

      *

      * Common {@link java.io.File} manipulation routines. *

      @@ -91,7 +90,6 @@ * @author Christoph.Reck * @author Peter Donald * @author Jeff Turner - * */ public class FileUtils { From fd2889bcf568a41b57fa13efbca53c03a91b6be1 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sun, 14 Feb 2021 10:35:14 -0500 Subject: [PATCH 8/9] spelling --- src/main/java/org/apache/maven/shared/utils/io/FileUtils.java | 2 +- 1 file changed, 1 insertion(+), 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 7c98ba1b..9cb6aa3c 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 @@ -2141,7 +2141,7 @@ public static boolean isSymbolicLinkForSure( @Nonnull final File file ) * @return the linked file * @throws IOException in case of an error * @see {@code java.nio.file.Files.createSymbolicLink(Path)} which creates a new - * symbolic link but does not replace exsiting symbolic links + * symbolic link but does not replace existing symbolic links */ @Nonnull public static File createSymbolicLink( @Nonnull File symlink, @Nonnull File target ) throws IOException From 784ff96021c5a873b0620f182a373e05cbb7b339 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Fri, 26 Feb 2021 08:30:38 -0500 Subject: [PATCH 9/9] format --- .../org/apache/maven/shared/utils/io/FileUtils.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 9cb6aa3c..4612b37f 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 @@ -1617,11 +1617,14 @@ public static void copyDirectory( @Nonnull File sourceDirectory, @Nonnull File d { Objects.requireNonNull( sourceDirectory ); Objects.requireNonNull( destinationDirectory ); - if ( destinationDirectory.equals( sourceDirectory ) ) { + if ( destinationDirectory.equals( sourceDirectory ) ) + { throw new IOException( "Can't copy directory " + sourceDirectory + " to itself." ); } - else if ( !destinationDirectory.exists() ) { - if ( !destinationDirectory.mkdirs() ) { + else if ( !destinationDirectory.exists() ) + { + if ( !destinationDirectory.mkdirs() ) + { throw new IOException( "Can't create directory " + destinationDirectory ); } } @@ -1648,7 +1651,8 @@ public static void copyDirectory( @Nonnull File sourceDirectory, @Nonnull File d { return; } - else if ( !sourceDirectory.isDirectory() ) { + else if ( !sourceDirectory.isDirectory() ) + { throw new IOException( sourceDirectory + " is not a directory." ); }