1 /*
2 * Copyright (C) 2011, GitHub Inc. and others
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Distribution License v. 1.0 which is available at
6 * https://www.eclipse.org/org/documents/edl-v10.php.
7 *
8 * SPDX-License-Identifier: BSD-3-Clause
9 */
10 package org.eclipse.jgit.errors;
11
12 import java.io.File;
13 import java.io.IOException;
14 import java.text.MessageFormat;
15
16 import org.eclipse.jgit.internal.JGitText;
17
18 /**
19 * An exception occurring when a file cannot be locked
20 */
21 public class LockFailedException extends IOException {
22 private static final long serialVersionUID = 1L;
23
24 private File file;
25
26 /**
27 * Constructor for LockFailedException
28 *
29 * @param file
30 * file that could not be locked
31 * @param message
32 * exception message
33 * @param cause
34 * cause, for later retrieval by
35 * {@link java.lang.Throwable#getCause()}
36 * @since 4.1
37 */
38 public LockFailedException(File file, String message, Throwable cause) {
39 super(message, cause);
40 this.file = file;
41 }
42
43 /**
44 * Construct a CannotLockException for the given file and message
45 *
46 * @param file
47 * file that could not be locked
48 * @param message
49 * exception message
50 */
51 public LockFailedException(File file, String message) {
52 super(message);
53 this.file = file;
54 }
55
56 /**
57 * Construct a CannotLockException for the given file
58 *
59 * @param file
60 * file that could not be locked
61 */
62 public LockFailedException(File file) {
63 this(file, MessageFormat.format(JGitText.get().cannotLock, file));
64 }
65
66 /**
67 * Get the file that could not be locked
68 *
69 * @return file
70 */
71 public File getFile() {
72 return file;
73 }
74 }