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