1 package org.apache.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
22 import org.codehaus.plexus.digest.Digester;
24 import java.io.IOException;
25 import java.nio.file.Path;
26 import java.util.ArrayList;
27 import java.util.List;
30 * Implement commit/rollback semantics for a set of files.
33 public class FileTransaction
35 private List<AbstractTransactionEvent> events = new ArrayList<>();
38 throws TransactionException
40 List<TransactionEvent> toRollback = new ArrayList<TransactionEvent>( events.size() );
42 for ( TransactionEvent event : events )
48 toRollback.add( event );
50 catch ( IOException e )
54 rollback( toRollback );
56 throw new TransactionException( "Unable to commit file transaction", e );
58 catch ( IOException ioe )
60 throw new TransactionException(
61 "Unable to commit file transaction, and rollback failed with error: '" + ioe.getMessage() + "'",
68 private void rollback( List<TransactionEvent> toRollback )
71 for ( TransactionEvent event : toRollback )
80 * @param digesters {@link List}<{@link org.codehaus.plexus.digest.Digester}> digesters to use for checksumming
82 public void copyFile(Path source, Path destination, List<? extends Digester> digesters )
84 events.add( new CopyFileEvent( source, destination, digesters ) );
90 * @param digesters {@link List}<{@link org.codehaus.plexus.digest.Digester}> digesters to use for checksumming
92 public void createFile( String content, Path destination, List<? extends Digester> digesters )
94 events.add( new CreateFileEvent( content, destination, digesters ) );