1 package org.apache.maven.archiva.transaction;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Iterator;
26 import java.util.List;
29 * Implement commit/rollback semantics for a set of files.
32 public class FileTransaction
34 private List events = new ArrayList();
37 throws TransactionException
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 TransactionException( "Unable to commit file transaction", e );
59 catch ( IOException ioe )
61 throw new TransactionException(
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();
83 * @param digesters {@link List}<{@link org.codehaus.plexus.digest.Digester}> digesters to use for checksumming
85 public void copyFile( File source, File destination, List digesters )
87 events.add( new CopyFileEvent( source, destination, digesters ) );
93 * @param digesters {@link List}<{@link org.codehaus.plexus.digest.Digester}> digesters to use for checksumming
95 public void createFile( String content, File destination, List digesters )
97 events.add( new CreateFileEvent( content, destination, digesters ) );