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
23 import java.io.IOException;
24 import java.util.List;
26 import org.apache.commons.io.FileUtils;
27 import org.codehaus.plexus.digest.Digester;
30 * Event to copy a file.
34 public class CopyFileEvent
35 extends AbstractTransactionEvent
37 private final File source;
39 private final File destination;
45 * @param digesters {@link List}<{@link Digester}> digesters to use for checksumming
47 public CopyFileEvent( File source, File destination, List<? extends Digester> digesters )
51 this.destination = destination;
58 createBackup( destination );
60 mkDirs( destination.getParentFile() );
62 FileUtils.copyFile( source, destination );
64 createChecksums( destination, true );
67 copyChecksum( "asc" );
71 * Copy checksums of source file with all digesters if exist
75 private void copyChecksums()
78 for ( Digester digester : getDigesters() )
80 copyChecksum( getDigesterFileExtension( digester ) );
85 * Copy checksum of source file with extension provided if exists
88 * @return whether the checksum exists or not
91 private boolean copyChecksum( String extension )
94 File checksumSource = new File( source.getAbsolutePath() + "." + extension );
95 if ( checksumSource.exists() )
97 File checksumDestination = new File( destination.getAbsolutePath() + "." + extension );
98 FileUtils.copyFile( checksumSource, checksumDestination );
105 public void rollback()
108 destination.delete();
110 revertFilesCreated();