1 package org.apache.maven.toolchain.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 import org.apache.maven.building.Problem;
28
29
30
31
32
33 public class ToolchainsBuildingException
34 extends Exception
35 {
36
37 private final List<Problem> problems;
38
39
40
41
42
43
44 public ToolchainsBuildingException( List<Problem> problems )
45 {
46 super( toMessage( problems ) );
47
48 this.problems = new ArrayList<Problem>();
49 if ( problems != null )
50 {
51 this.problems.addAll( problems );
52 }
53 }
54
55
56
57
58
59
60 public List<Problem> getProblems()
61 {
62 return problems;
63 }
64
65 private static String toMessage( List<Problem> problems )
66 {
67 StringWriter buffer = new StringWriter( 1024 );
68
69 PrintWriter writer = new PrintWriter( buffer );
70
71 writer.print( problems.size() );
72 writer.print( ( problems.size() == 1 ) ? " problem was " : " problems were " );
73 writer.print( "encountered while building the effective toolchains" );
74 writer.println();
75
76 for ( Problem problem : problems )
77 {
78 writer.print( "[" );
79 writer.print( problem.getSeverity() );
80 writer.print( "] " );
81 writer.print( problem.getMessage() );
82 String location = problem.getLocation();
83 if ( !location.isEmpty() )
84 {
85 writer.print( " @ " );
86 writer.print( location );
87 }
88 writer.println();
89 }
90
91 return buffer.toString();
92 }
93 }