public abstract class AbstractTransactionEvent
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}<{@link Digester}>
*/
- private List digesters;
+ private List<Digester> digesters;
protected AbstractTransactionEvent()
{
- this( new ArrayList( 0 ) );
+ this( new ArrayList<Digester>( 0 ) );
}
- protected AbstractTransactionEvent( List digesters )
+ protected AbstractTransactionEvent( List<Digester> digesters )
{
this.digesters = digesters;
}
- protected List getDigesters()
+ protected List<Digester> getDigesters()
{
return digesters;
}
protected void mkDirs( File dir )
throws IOException
{
- List createDirs = new ArrayList();
+ List<File> createDirs = new ArrayList<File>();
File parent = dir;
while ( !parent.exists() || !parent.isDirectory() )
protected void revertFilesCreated()
throws IOException
{
- Iterator it = createdFiles.iterator();
+ Iterator<File> it = createdFiles.iterator();
while ( it.hasNext() )
{
File file = (File) it.next();
protected void restoreBackups()
throws IOException
{
- Iterator it = backups.entrySet().iterator();
- while ( it.hasNext() )
+ for ( Map.Entry<File, File> entry : backups.entrySet() )
{
- Map.Entry entry = (Map.Entry) it.next();
- FileUtils.copyFile( (File) entry.getValue(), (File) entry.getKey() );
+ FileUtils.copyFile( entry.getValue(), entry.getKey() );
}
}
protected void createChecksums( File file, boolean force )
throws IOException
{
- Iterator it = getDigesters().iterator();
- while ( it.hasNext() )
+ for ( Digester digester : getDigesters() )
{
- Digester digester = (Digester) it.next();
File checksumFile = new File( file.getAbsolutePath() + "." + getDigesterFileExtension( digester ) );
if ( checksumFile.exists() )
{
* under the License.
*/
-import org.apache.commons.io.FileUtils;
-import org.codehaus.plexus.digest.Digester;
-
import java.io.File;
import java.io.IOException;
-import java.util.Iterator;
import java.util.List;
+import org.apache.commons.io.FileUtils;
+import org.codehaus.plexus.digest.Digester;
+
/**
* Event to copy a file.
*
* @param destination
* @param digesters {@link List}<{@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 );
this.source = source;
private void copyChecksums()
throws IOException
{
- Iterator it = getDigesters().iterator();
- while ( it.hasNext() )
+ for ( Digester digester : getDigesters() )
{
- Digester digester = (Digester) it.next();
copyChecksum( getDigesterFileExtension( digester ) );
}
}
import java.io.IOException;
import java.util.List;
+import org.codehaus.plexus.digest.Digester;
+
/**
* Event for creating a file from a string content.
*
* @param destination
* @param digesters {@link List}<{@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 );
this.content = content;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
+import org.codehaus.plexus.digest.Digester;
+
/**
* Implement commit/rollback semantics for a set of files.
*
*/
public class FileTransaction
{
- private List events = new ArrayList();
+ private List<AbstractTransactionEvent> events = new ArrayList<AbstractTransactionEvent>();
public void commit()
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
{
event.commit();
}
}
- private void rollback( List toRollback )
+ private void rollback( List<TransactionEvent> toRollback )
throws IOException
{
- for ( Iterator i = toRollback.iterator(); i.hasNext(); )
+ for ( TransactionEvent event : toRollback )
{
- TransactionEvent event = (TransactionEvent) i.next();
-
event.rollback();
}
}
* @param destination
* @param digesters {@link List}<{@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 ) );
}
* @param destination
* @param digesters {@link List}<{@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 ) );
}
public abstract class AbstractFileEventTest
extends PlexusInSpringTestCase
{
- protected List digesters;
+ protected List<Digester> digesters;
+ @SuppressWarnings("unchecked")
public void setUp()
throws Exception
{