Coverage Report - org.apache.maven.archiva.transaction.FileTransaction
 
Classes in this File Line Coverage Branch Coverage Complexity
FileTransaction
0%
0/20
0%
0/4
0
 
 1  
 package org.apache.maven.archiva.transaction;
 2  
 
 3  
 /*
 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
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 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
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.File;
 23  
 import java.io.IOException;
 24  
 import java.util.ArrayList;
 25  
 import java.util.List;
 26  
 
 27  
 import org.codehaus.plexus.digest.Digester;
 28  
 
 29  
 /**
 30  
  * Implement commit/rollback semantics for a set of files.
 31  
  *
 32  
  */
 33  0
 public class FileTransaction
 34  
 {
 35  0
     private List<AbstractTransactionEvent> events = new ArrayList<AbstractTransactionEvent>();
 36  
 
 37  
     public void commit()
 38  
         throws TransactionException
 39  
     {
 40  0
         List<TransactionEvent> toRollback = new ArrayList<TransactionEvent>( events.size() );
 41  
 
 42  0
         for ( TransactionEvent event : events )
 43  
         {
 44  
             try
 45  
             {
 46  0
                 event.commit();
 47  
 
 48  0
                 toRollback.add( event );
 49  
             }
 50  0
             catch ( IOException e )
 51  
             {
 52  
                 try
 53  
                 {
 54  0
                     rollback( toRollback );
 55  
 
 56  0
                     throw new TransactionException( "Unable to commit file transaction", e );
 57  
                 }
 58  0
                 catch ( IOException ioe )
 59  
                 {
 60  0
                     throw new TransactionException(
 61  
                         "Unable to commit file transaction, and rollback failed with error: '" + ioe.getMessage() + "'",
 62  
                         e );
 63  
                 }
 64  0
             }
 65  
         }
 66  0
     }
 67  
 
 68  
     private void rollback( List<TransactionEvent> toRollback )
 69  
         throws IOException
 70  
     {
 71  0
         for ( TransactionEvent event : toRollback )
 72  
         {
 73  0
             event.rollback();
 74  
         }
 75  0
     }
 76  
 
 77  
     /**
 78  
      * @param source
 79  
      * @param destination
 80  
      * @param digesters   {@link List}&lt;{@link org.codehaus.plexus.digest.Digester}> digesters to use for checksumming
 81  
      */
 82  
     public void copyFile( File source, File destination, List<Digester> digesters )
 83  
     {
 84  0
         events.add( new CopyFileEvent( source, destination, digesters ) );
 85  0
     }
 86  
 
 87  
     /**
 88  
      * @param content
 89  
      * @param destination
 90  
      * @param digesters   {@link List}&lt;{@link org.codehaus.plexus.digest.Digester}> digesters to use for checksumming
 91  
      */
 92  
     public void createFile( String content, File destination, List<Digester> digesters )
 93  
     {
 94  0
         events.add( new CreateFileEvent( content, destination, digesters ) );
 95  0
     }
 96  
 }