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