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
22 import org.codehaus.plexus.digest.Digester;
23 import org.codehaus.plexus.util.FileUtils;
26 import java.io.IOException;
27 import java.util.Iterator;
28 import java.util.List;
31 * Event to copy a file.
33 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
34 * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
37 public class CopyFileEvent
38 extends AbstractTransactionEvent
40 private final File source;
42 private final File destination;
48 * @param digesters {@link List}<{@link Digester}> digesters to use for checksumming
50 public CopyFileEvent( File source, File destination, List digesters )
54 this.destination = destination;
60 createBackup( destination );
62 mkDirs( destination.getParentFile() );
64 FileUtils.copyFile( source, destination );
66 createChecksums( destination, true );
69 copyChecksum( "asc" );
73 * Copy checksums of source file with all digesters if exist
77 private void copyChecksums()
80 Iterator it = getDigesters().iterator();
81 while ( it.hasNext() )
83 Digester digester = (Digester) it.next();
84 copyChecksum( getDigesterFileExtension( digester ) );
89 * Copy checksum of source file with extension provided if exists
92 * @return whether the checksum exists or not
95 private boolean copyChecksum( String extension )
98 File checksumSource = new File( source.getAbsolutePath() + "." + extension );
99 if ( checksumSource.exists() )
101 File checksumDestination = new File( destination.getAbsolutePath() + "." + extension );
102 FileUtils.copyFile( checksumSource, checksumDestination );
108 public void rollback()
111 destination.delete();
113 revertFilesCreated();