Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CreateFileEvent |
|
| 0.0;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.List; | |
25 | ||
26 | import org.codehaus.plexus.digest.Digester; | |
27 | ||
28 | /** | |
29 | * Event for creating a file from a string content. | |
30 | * | |
31 | * @version $Id: CreateFileEvent.java 755305 2009-03-17 16:24:16Z brett $ | |
32 | */ | |
33 | public class CreateFileEvent | |
34 | extends AbstractTransactionEvent | |
35 | { | |
36 | private final File destination; | |
37 | ||
38 | private final String content; | |
39 | ||
40 | /** | |
41 | * | |
42 | * @param content | |
43 | * @param destination | |
44 | * @param digesters {@link List}<{@link Digester}> digesters to use for checksumming | |
45 | */ | |
46 | public CreateFileEvent( String content, File destination, List<Digester> digesters ) | |
47 | { | |
48 | 0 | super( digesters ); |
49 | 0 | this.content = content; |
50 | 0 | this.destination = destination; |
51 | 0 | } |
52 | ||
53 | public void commit() | |
54 | throws IOException | |
55 | { | |
56 | 0 | createBackup( destination ); |
57 | ||
58 | 0 | mkDirs( destination.getParentFile() ); |
59 | ||
60 | 0 | if ( !destination.exists() && !destination.createNewFile() ) |
61 | { | |
62 | 0 | throw new IOException( "Unable to create new file" ); |
63 | } | |
64 | ||
65 | 0 | writeStringToFile( destination, content ); |
66 | ||
67 | 0 | createChecksums( destination, true ); |
68 | 0 | } |
69 | ||
70 | public void rollback() | |
71 | throws IOException | |
72 | { | |
73 | 0 | destination.delete(); |
74 | ||
75 | 0 | revertFilesCreated(); |
76 | ||
77 | 0 | revertMkDirs(); |
78 | ||
79 | 0 | restoreBackups(); |
80 | 0 | } |
81 | } |