1 package org.apache.maven.plugin;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.codehaus.plexus.compiler.CompilerError;
23
24 import java.util.Iterator;
25 import java.util.List;
26
27 /**
28 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
29 * @version $Id: CompilationFailureException.html 816611 2012-05-08 13:04:26Z hboutemy $
30 * @since 2.0
31 */
32 public class CompilationFailureException
33 extends MojoFailureException
34 {
35 private static final String LS = System.getProperty( "line.separator" );
36
37 public CompilationFailureException( List messages )
38 {
39 super( null, shortMessage( messages ), longMessage( messages ) );
40 }
41
42 public static String longMessage( List messages )
43 {
44 StringBuffer sb = new StringBuffer();
45
46 for ( Iterator it = messages.iterator(); it.hasNext(); )
47 {
48 CompilerError compilerError = (CompilerError) it.next();
49
50 sb.append( compilerError ).append( LS );
51 }
52 return sb.toString();
53 }
54
55 /**
56 * Short message will have the error message if there's only one, useful for errors forking the compiler
57 *
58 * @param messages
59 * @return the short error message
60 * @since 2.0.2
61 */
62 public static String shortMessage( List messages )
63 {
64 StringBuffer sb = new StringBuffer();
65
66 sb.append( "Compilation failure" );
67
68 if ( messages.size() == 1 )
69 {
70 sb.append( LS );
71
72 CompilerError compilerError = (CompilerError) messages.get( 0 );
73
74 sb.append( compilerError ).append( LS );
75 }
76
77 return sb.toString();
78 }
79 }