1 package org.apache.maven.repository.converter.transaction;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.maven.repository.converter.RepositoryConversionException;
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.Iterator;
25 import java.util.List;
28 * Implement commit/rollback semantics for a set of files.
30 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
32 public class FileTransaction
34 private List events = new ArrayList();
37 throws RepositoryConversionException
39 List toRollback = new ArrayList( events.size() );
41 for ( Iterator i = events.iterator(); i.hasNext(); )
43 TransactionEvent event = (TransactionEvent) i.next();
49 toRollback.add( event );
51 catch ( IOException e )
55 rollback( toRollback );
57 throw new RepositoryConversionException( "Unable to commit file transaction", e );
59 catch ( IOException ioe )
61 throw new RepositoryConversionException(
62 "Unable to commit file transaction, and rollback failed with error: '" + ioe.getMessage() + "'",
69 private void rollback( List toRollback )
72 for ( Iterator i = toRollback.iterator(); i.hasNext(); )
74 TransactionEvent event = (TransactionEvent) i.next();
80 public void copyFile( File source, File destination )
82 events.add( new CopyFileEvent( source, destination ) );
85 public void createFile( String content, File destination )
87 events.add( new CreateFileEvent( content, destination ) );