-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathJarTransformFailedException.java
More file actions
69 lines (60 loc) · 2.27 KB
/
Copy pathJarTransformFailedException.java
File metadata and controls
69 lines (60 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.cadixdev.atlas.jar;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* An exception thrown when one or more entries in a jar fail to transform.
*
* @since 0.3.0
*/
public final class JarTransformFailedException extends IOException {
private static final long serialVersionUID = 3971759325502243118L;
private final Map<JarPath, Exception> failedPaths;
/**
* Create a new exception.
*
* @param message the user-visible message
* @param failedPaths a map from failed entry to
*/
public JarTransformFailedException(final String message, final Map<JarPath, Exception> failedPaths) {
super(message);
this.failedPaths = Collections.unmodifiableMap(new HashMap<>(failedPaths));
if (this.failedPaths.size() == 1) {
this.initCause(this.failedPaths.values().iterator().next());
}
}
/**
* Return an unmodifiable snapshot of a map of jar path to the exception
* thrown at the path.
*
* @return the failed paths
*/
public Map<JarPath, Exception> getFailedPaths() {
return this.failedPaths;
}
@Override
public String getMessage() {
final String superMessage = super.getMessage();
if (this.failedPaths.size() == 1) { // details already included in cause
return superMessage + " (in entry " + this.failedPaths.keySet().iterator().next().getName() + " )";
}
final StringBuilder message = new StringBuilder(superMessage == null ? "Failed to transform jar: " : superMessage);
for (final Map.Entry<JarPath, Exception> failure : this.failedPaths.entrySet()) {
message.append(System.lineSeparator())
.append("- ")
.append(failure.getKey().getName());
final String elementMessage = failure.getValue().getMessage();
if (elementMessage != null) {
message.append(": ")
.append(elementMessage);
}
}
return message.toString();
}
}