warnings in transaction module

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@755305 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2009-03-17 16:24:16 +00:00
parent 76a1d2429f
commit 9e46c25ca2
5 changed files with 31 additions and 38 deletions

View File

@ -40,28 +40,28 @@ import java.util.Map;
public abstract class AbstractTransactionEvent public abstract class AbstractTransactionEvent
implements TransactionEvent implements TransactionEvent
{ {
private Map backups = new HashMap(); private Map<File, File> backups = new HashMap<File, File>();
private List createdDirs = new ArrayList(); private List<File> createdDirs = new ArrayList<File>();
private List createdFiles = new ArrayList(); private List<File> createdFiles = new ArrayList<File>();
/** /**
* {@link List}&lt;{@link Digester}> * {@link List}&lt;{@link Digester}>
*/ */
private List digesters; private List<Digester> digesters;
protected AbstractTransactionEvent() protected AbstractTransactionEvent()
{ {
this( new ArrayList( 0 ) ); this( new ArrayList<Digester>( 0 ) );
} }
protected AbstractTransactionEvent( List digesters ) protected AbstractTransactionEvent( List<Digester> digesters )
{ {
this.digesters = digesters; this.digesters = digesters;
} }
protected List getDigesters() protected List<Digester> getDigesters()
{ {
return digesters; return digesters;
} }
@ -75,7 +75,7 @@ public abstract class AbstractTransactionEvent
protected void mkDirs( File dir ) protected void mkDirs( File dir )
throws IOException throws IOException
{ {
List createDirs = new ArrayList(); List<File> createDirs = new ArrayList<File>();
File parent = dir; File parent = dir;
while ( !parent.exists() || !parent.isDirectory() ) while ( !parent.exists() || !parent.isDirectory() )
@ -127,7 +127,7 @@ public abstract class AbstractTransactionEvent
protected void revertFilesCreated() protected void revertFilesCreated()
throws IOException throws IOException
{ {
Iterator it = createdFiles.iterator(); Iterator<File> it = createdFiles.iterator();
while ( it.hasNext() ) while ( it.hasNext() )
{ {
File file = (File) it.next(); File file = (File) it.next();
@ -154,11 +154,9 @@ public abstract class AbstractTransactionEvent
protected void restoreBackups() protected void restoreBackups()
throws IOException throws IOException
{ {
Iterator it = backups.entrySet().iterator(); for ( Map.Entry<File, File> entry : backups.entrySet() )
while ( it.hasNext() )
{ {
Map.Entry entry = (Map.Entry) it.next(); FileUtils.copyFile( entry.getValue(), entry.getKey() );
FileUtils.copyFile( (File) entry.getValue(), (File) entry.getKey() );
} }
} }
@ -182,10 +180,8 @@ public abstract class AbstractTransactionEvent
protected void createChecksums( File file, boolean force ) protected void createChecksums( File file, boolean force )
throws IOException throws IOException
{ {
Iterator it = getDigesters().iterator(); for ( Digester digester : getDigesters() )
while ( it.hasNext() )
{ {
Digester digester = (Digester) it.next();
File checksumFile = new File( file.getAbsolutePath() + "." + getDigesterFileExtension( digester ) ); File checksumFile = new File( file.getAbsolutePath() + "." + getDigesterFileExtension( digester ) );
if ( checksumFile.exists() ) if ( checksumFile.exists() )
{ {

View File

@ -19,14 +19,13 @@ package org.apache.maven.archiva.transaction;
* under the License. * under the License.
*/ */
import org.apache.commons.io.FileUtils;
import org.codehaus.plexus.digest.Digester;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.apache.commons.io.FileUtils;
import org.codehaus.plexus.digest.Digester;
/** /**
* Event to copy a file. * Event to copy a file.
* *
@ -45,7 +44,7 @@ public class CopyFileEvent
* @param destination * @param destination
* @param digesters {@link List}&lt;{@link Digester}> digesters to use for checksumming * @param digesters {@link List}&lt;{@link Digester}> digesters to use for checksumming
*/ */
public CopyFileEvent( File source, File destination, List digesters ) public CopyFileEvent( File source, File destination, List<Digester> digesters )
{ {
super( digesters ); super( digesters );
this.source = source; this.source = source;
@ -75,10 +74,8 @@ public class CopyFileEvent
private void copyChecksums() private void copyChecksums()
throws IOException throws IOException
{ {
Iterator it = getDigesters().iterator(); for ( Digester digester : getDigesters() )
while ( it.hasNext() )
{ {
Digester digester = (Digester) it.next();
copyChecksum( getDigesterFileExtension( digester ) ); copyChecksum( getDigesterFileExtension( digester ) );
} }
} }

View File

@ -23,6 +23,8 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import org.codehaus.plexus.digest.Digester;
/** /**
* Event for creating a file from a string content. * Event for creating a file from a string content.
* *
@ -41,7 +43,7 @@ public class CreateFileEvent
* @param destination * @param destination
* @param digesters {@link List}&lt;{@link Digester}> digesters to use for checksumming * @param digesters {@link List}&lt;{@link Digester}> digesters to use for checksumming
*/ */
public CreateFileEvent( String content, File destination, List digesters ) public CreateFileEvent( String content, File destination, List<Digester> digesters )
{ {
super( digesters ); super( digesters );
this.content = content; this.content = content;

View File

@ -22,26 +22,25 @@ package org.apache.maven.archiva.transaction;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.codehaus.plexus.digest.Digester;
/** /**
* Implement commit/rollback semantics for a set of files. * Implement commit/rollback semantics for a set of files.
* *
*/ */
public class FileTransaction public class FileTransaction
{ {
private List events = new ArrayList(); private List<AbstractTransactionEvent> events = new ArrayList<AbstractTransactionEvent>();
public void commit() public void commit()
throws TransactionException throws TransactionException
{ {
List toRollback = new ArrayList( events.size() ); List<TransactionEvent> toRollback = new ArrayList<TransactionEvent>( events.size() );
for ( Iterator i = events.iterator(); i.hasNext(); ) for ( TransactionEvent event : events )
{ {
TransactionEvent event = (TransactionEvent) i.next();
try try
{ {
event.commit(); event.commit();
@ -66,13 +65,11 @@ public class FileTransaction
} }
} }
private void rollback( List toRollback ) private void rollback( List<TransactionEvent> toRollback )
throws IOException throws IOException
{ {
for ( Iterator i = toRollback.iterator(); i.hasNext(); ) for ( TransactionEvent event : toRollback )
{ {
TransactionEvent event = (TransactionEvent) i.next();
event.rollback(); event.rollback();
} }
} }
@ -82,7 +79,7 @@ public class FileTransaction
* @param destination * @param destination
* @param digesters {@link List}&lt;{@link org.codehaus.plexus.digest.Digester}> digesters to use for checksumming * @param digesters {@link List}&lt;{@link org.codehaus.plexus.digest.Digester}> digesters to use for checksumming
*/ */
public void copyFile( File source, File destination, List digesters ) public void copyFile( File source, File destination, List<Digester> digesters )
{ {
events.add( new CopyFileEvent( source, destination, digesters ) ); events.add( new CopyFileEvent( source, destination, digesters ) );
} }
@ -92,7 +89,7 @@ public class FileTransaction
* @param destination * @param destination
* @param digesters {@link List}&lt;{@link org.codehaus.plexus.digest.Digester}> digesters to use for checksumming * @param digesters {@link List}&lt;{@link org.codehaus.plexus.digest.Digester}> digesters to use for checksumming
*/ */
public void createFile( String content, File destination, List digesters ) public void createFile( String content, File destination, List<Digester> digesters )
{ {
events.add( new CreateFileEvent( content, destination, digesters ) ); events.add( new CreateFileEvent( content, destination, digesters ) );
} }

View File

@ -35,8 +35,9 @@ import java.util.List;
public abstract class AbstractFileEventTest public abstract class AbstractFileEventTest
extends PlexusInSpringTestCase extends PlexusInSpringTestCase
{ {
protected List digesters; protected List<Digester> digesters;
@SuppressWarnings("unchecked")
public void setUp() public void setUp()
throws Exception throws Exception
{ {