From a92dd01b853b8a7e7eab75893990683c5dbff66b Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Sat, 2 Dec 2006 07:57:01 +0000 Subject: [PATCH] Moved to Commons IO FileUtils. Generally improves things, though you have to pass a null parameter to readStringFromFile and writeStringToFile to imply the default encoding should be used. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@481517 13f79535-47bb-0310-9956-ffa450edef68 --- .../converter/DefaultRepositoryConverter.java | 8 +++--- .../transaction/AbstractTransactionEvent.java | 4 +-- .../converter/transaction/CopyFileEvent.java | 4 +-- .../transaction/CreateFileEvent.java | 6 ++--- .../converter/RepositoryConverterTest.java | 6 ++--- .../transaction/CopyFileEventTest.java | 25 +++++++++---------- .../transaction/CreateFileEventTest.java | 13 +++++----- 7 files changed, 32 insertions(+), 34 deletions(-) diff --git a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java index 3ee6b54e1..cbc3b4ab5 100644 --- a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java +++ b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java @@ -41,7 +41,7 @@ import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader; import org.codehaus.plexus.digest.Digester; import org.codehaus.plexus.digest.DigesterException; import org.codehaus.plexus.i18n.I18N; -import org.codehaus.plexus.util.FileUtils; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @@ -432,7 +432,7 @@ public class DefaultRepositoryConverter } // Even if the checksums for the POM are invalid we should still convert the POM - contents = FileUtils.fileRead( file ); + contents = FileUtils.readFileToString( file, null ); } catch ( IOException e ) { @@ -447,7 +447,7 @@ public class DefaultRepositoryConverter boolean matching = false; if ( !force && targetFile.exists() ) { - String targetContents = FileUtils.fileRead( targetFile ); + String targetContents = FileUtils.readFileToString( targetFile, null ); matching = targetContents.equals( contents ); } if ( force || !matching ) @@ -650,7 +650,7 @@ public class DefaultRepositoryConverter File checksumFile = new File( file.getParentFile(), fileName ); if ( checksumFile.exists() ) { - String checksum = FileUtils.fileRead( checksumFile ); + String checksum = FileUtils.readFileToString( checksumFile, null ); try { digester.verify( file, checksum ); diff --git a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/transaction/AbstractTransactionEvent.java b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/transaction/AbstractTransactionEvent.java index 540cde6a2..077a16cf3 100644 --- a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/transaction/AbstractTransactionEvent.java +++ b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/transaction/AbstractTransactionEvent.java @@ -16,7 +16,7 @@ package org.apache.maven.archiva.converter.transaction; * limitations under the License. */ -import org.codehaus.plexus.util.FileUtils; +import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; @@ -85,7 +85,7 @@ public abstract class AbstractTransactionEvent if ( dir.isDirectory() && dir.list().length == 0 ) { - FileUtils.deleteDirectory( dir.getAbsolutePath() ); + FileUtils.deleteDirectory( dir ); } else { diff --git a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/transaction/CopyFileEvent.java b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/transaction/CopyFileEvent.java index 8b4c8a45a..871fc1f9a 100644 --- a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/transaction/CopyFileEvent.java +++ b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/transaction/CopyFileEvent.java @@ -16,7 +16,7 @@ package org.apache.maven.archiva.converter.transaction; * limitations under the License. */ -import org.codehaus.plexus.util.FileUtils; +import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; @@ -52,7 +52,7 @@ public class CopyFileEvent public void rollback() throws IOException { - FileUtils.fileDelete( destination.getAbsolutePath() ); + destination.delete(); revertMkDirs(); diff --git a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/transaction/CreateFileEvent.java b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/transaction/CreateFileEvent.java index d9e7325b5..14b732525 100644 --- a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/transaction/CreateFileEvent.java +++ b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/transaction/CreateFileEvent.java @@ -16,7 +16,7 @@ package org.apache.maven.archiva.converter.transaction; * limitations under the License. */ -import org.codehaus.plexus.util.FileUtils; +import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; @@ -51,13 +51,13 @@ public class CreateFileEvent throw new IOException( "Unable to create new file" ); } - FileUtils.fileWrite( destination.getAbsolutePath(), content ); + FileUtils.writeStringToFile( destination, content, null ); } public void rollback() throws IOException { - FileUtils.fileDelete( destination.getAbsolutePath() ); + destination.delete(); revertMkDirs(); diff --git a/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java index 8f19216d6..dc0828501 100644 --- a/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java +++ b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java @@ -30,7 +30,7 @@ import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.i18n.I18N; -import org.codehaus.plexus.util.FileUtils; +import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; @@ -920,8 +920,8 @@ public class RepositoryConverterTest private static void compareFiles( File expectedPomFile, File pomFile ) throws IOException { - String expectedContent = normalizeString( FileUtils.fileRead( expectedPomFile ) ); - String targetContent = normalizeString( FileUtils.fileRead( pomFile ) ); + String expectedContent = normalizeString( FileUtils.readFileToString( expectedPomFile, null ) ); + String targetContent = normalizeString( FileUtils.readFileToString( pomFile, null ) ); assertEquals( "Check file match between " + expectedPomFile + " and " + pomFile, expectedContent, targetContent ); } diff --git a/archiva-converter/src/test/java/org/apache/maven/archiva/converter/transaction/CopyFileEventTest.java b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/transaction/CopyFileEventTest.java index 7b81fd269..7ead8f625 100644 --- a/archiva-converter/src/test/java/org/apache/maven/archiva/converter/transaction/CopyFileEventTest.java +++ b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/transaction/CopyFileEventTest.java @@ -17,7 +17,7 @@ package org.apache.maven.archiva.converter.transaction; */ import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.util.FileUtils; +import org.apache.commons.io.FileUtils; import java.io.File; @@ -42,7 +42,7 @@ public class CopyFileEventTest testSource.createNewFile(); - FileUtils.fileWrite( testSource.getAbsolutePath(), "source contents" ); + FileUtils.writeStringToFile( testSource, "source contents", null ); } public void testCopyCommitRollback() @@ -50,7 +50,7 @@ public class CopyFileEventTest { assertTrue( "Test if the source exists", testSource.exists() ); - String source = FileUtils.fileRead( testSource.getAbsolutePath() ); + String source = FileUtils.readFileToString( testSource, null ); CopyFileEvent event = new CopyFileEvent( testSource, testDest ); @@ -60,7 +60,7 @@ public class CopyFileEventTest assertTrue( "Test that the destination is created", testDest.exists() ); - String target = FileUtils.fileRead( testDest.getAbsolutePath() ); + String target = FileUtils.readFileToString( testDest, null ); assertTrue( "Test that the destination contents are copied correctly", source.equals( target ) ); @@ -74,31 +74,31 @@ public class CopyFileEventTest { assertTrue( "Test if the source exists", testSource.exists() ); - String source = FileUtils.fileRead( testSource.getAbsolutePath() ); + String source = FileUtils.readFileToString( testSource, null ); testDest.getParentFile().mkdirs(); testDest.createNewFile(); - FileUtils.fileWrite( testDest.getAbsolutePath(), "overwritten contents" ); + FileUtils.writeStringToFile( testDest, "overwritten contents", null ); assertTrue( "Test that the destination exists", testDest.exists() ); CopyFileEvent event = new CopyFileEvent( testSource, testDest ); - String target = FileUtils.fileRead( testDest.getAbsolutePath() ); + String target = FileUtils.readFileToString( testDest, null ); assertTrue( "Test that the destination contents have not changed", target.equals( "overwritten contents" ) ); event.commit(); - target = FileUtils.fileRead( testDest.getAbsolutePath() ); + target = FileUtils.readFileToString( testDest, null ); assertTrue( "Test that the destination contents are copied correctly", source.equals( target ) ); event.rollback(); - target = FileUtils.fileRead( testDest.getAbsolutePath() ); + target = FileUtils.readFileToString( testDest, null ); assertTrue( "Test the destination file contents have been restored", target.equals( "overwritten contents" ) ); } @@ -108,7 +108,7 @@ public class CopyFileEventTest { assertTrue( "Test if the source exists", testSource.exists() ); - String source = FileUtils.fileRead( testSource.getAbsolutePath() ); + String source = FileUtils.readFileToString( testSource, null ); CopyFileEvent event = new CopyFileEvent( testSource, testDest ); @@ -122,7 +122,7 @@ public class CopyFileEventTest assertTrue( "Test that the destination is created", testDest.exists() ); - String target = FileUtils.fileRead( testDest.getAbsolutePath() ); + String target = FileUtils.readFileToString( testDest, null ); assertTrue( "Test that the destination contents are copied correctly", source.equals( target ) ); } @@ -132,7 +132,6 @@ public class CopyFileEventTest { super.tearDown(); - FileUtils.deleteDirectory( - new File( PlexusTestCase.getBasedir(), "target/transaction-tests" ).getAbsolutePath() ); + FileUtils.deleteDirectory( new File( PlexusTestCase.getBasedir(), "target/transaction-tests" ) ); } } diff --git a/archiva-converter/src/test/java/org/apache/maven/archiva/converter/transaction/CreateFileEventTest.java b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/transaction/CreateFileEventTest.java index 3436383d0..b2594cd4d 100644 --- a/archiva-converter/src/test/java/org/apache/maven/archiva/converter/transaction/CreateFileEventTest.java +++ b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/transaction/CreateFileEventTest.java @@ -17,7 +17,7 @@ package org.apache.maven.archiva.converter.transaction; */ import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.util.FileUtils; +import org.apache.commons.io.FileUtils; import java.io.File; @@ -58,23 +58,23 @@ public class CreateFileEventTest testFile.createNewFile(); - FileUtils.fileWrite( testFile.getAbsolutePath(), "original contents" ); + FileUtils.writeStringToFile( testFile, "original contents", null ); CreateFileEvent event = new CreateFileEvent( "modified contents", testFile ); - String contents = FileUtils.fileRead( testFile.getAbsolutePath() ); + String contents = FileUtils.readFileToString( testFile, null ); assertEquals( "Test contents have not changed", "original contents", contents ); event.commit(); - contents = FileUtils.fileRead( testFile.getAbsolutePath() ); + contents = FileUtils.readFileToString( testFile, null ); assertEquals( "Test contents have not changed", "modified contents", contents ); event.rollback(); - contents = FileUtils.fileRead( testFile.getAbsolutePath() ); + contents = FileUtils.readFileToString( testFile, null ); assertEquals( "Test contents have not changed", "original contents", contents ); } @@ -102,7 +102,6 @@ public class CreateFileEventTest { super.tearDown(); - FileUtils.deleteDirectory( - new File( PlexusTestCase.getBasedir(), "target/transaction-tests" ).getAbsolutePath() ); + FileUtils.deleteDirectory( new File( PlexusTestCase.getBasedir(), "target/transaction-tests" ) ); } } -- 2.39.5