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
This commit is contained in:
Henri Yandell 2006-12-02 07:57:01 +00:00
parent f2bdf0209d
commit a92dd01b85
7 changed files with 32 additions and 34 deletions

View File

@ -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 );

View File

@ -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
{

View File

@ -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();

View File

@ -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();

View File

@ -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 );
}

View File

@ -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" ) );
}
}

View File

@ -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" ) );
}
}