1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.toolchain.building;
20
21 import java.io.PrintWriter;
22 import java.io.StringWriter;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.apache.maven.building.Problem;
27
28
29
30
31 public class ToolchainsBuildingException extends Exception {
32
33 private final List<Problem> problems;
34
35
36
37
38
39
40 public ToolchainsBuildingException(List<Problem> problems) {
41 super(toMessage(problems));
42
43 this.problems = new ArrayList<>();
44 if (problems != null) {
45 this.problems.addAll(problems);
46 }
47 }
48
49
50
51
52
53
54 public List<Problem> getProblems() {
55 return problems;
56 }
57
58 private static String toMessage(List<Problem> problems) {
59 StringWriter buffer = new StringWriter(1024);
60
61 PrintWriter writer = new PrintWriter(buffer);
62
63 writer.print(problems.size());
64 writer.print((problems.size() == 1) ? " problem was " : " problems were ");
65 writer.print("encountered while building the effective toolchains");
66 writer.println();
67
68 for (Problem problem : problems) {
69 writer.print("[");
70 writer.print(problem.getSeverity());
71 writer.print("] ");
72 writer.print(problem.getMessage());
73 String location = problem.getLocation();
74 if (!location.isEmpty()) {
75 writer.print(" @ ");
76 writer.print(location);
77 }
78 writer.println();
79 }
80
81 return buffer.toString();
82 }
83 }