View Javadoc

1   package org.apache.maven.project.validation;
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 java.util.ArrayList;
23  import java.util.Collections;
24  import java.util.List;
25  
26  /**
27   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
28   * @version $Id: ModelValidationResult.java 958295 2010-06-26 23:16:18Z hboutemy $
29   */
30  public class ModelValidationResult
31  {
32  
33      /** */
34      private static final String NEWLINE = System.getProperty( "line.separator" );
35  
36      /** */
37      private List<String> messages;
38  
39      public ModelValidationResult()
40      {
41          messages = new ArrayList<String>();
42      }
43  
44      public int getMessageCount()
45      {
46          return messages.size();
47      }
48  
49      public String getMessage( int i )
50      {
51          return messages.get( i );
52      }
53  
54      public List<String> getMessages()
55      {
56          return Collections.unmodifiableList( messages );
57      }
58  
59      public void addMessage( String message )
60      {
61          messages.add( message );
62      }
63  
64      public String toString()
65      {
66          return render( "" );
67      }
68  
69      public String render( String indentation )
70      {
71          if ( messages.size() == 0 )
72          {
73              return indentation + "There were no validation errors.";
74          }
75  
76          StringBuilder message = new StringBuilder();
77  
78  //        if ( messages.size() == 1 )
79  //        {
80  //            message.append( "There was 1 validation error: " );
81  //        }
82  //        else
83  //        {
84  //            message.append( "There was " + messages.size() + " validation errors: " + NEWLINE );
85  //        }
86  //
87          for ( int i = 0; i < messages.size(); i++ )
88          {
89              message.append( indentation + "[" + i + "]  " + messages.get( i ).toString() + NEWLINE );
90          }
91  
92          return message.toString();
93      }
94  
95  }