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   */
29  public class ModelValidationResult
30  {
31  
32      /** */
33      private static final String NEWLINE = System.getProperty( "line.separator" );
34  
35      /** */
36      private List<String> messages;
37  
38      public ModelValidationResult()
39      {
40          messages = new ArrayList<String>();
41      }
42  
43      public int getMessageCount()
44      {
45          return messages.size();
46      }
47  
48      public String getMessage( int i )
49      {
50          return messages.get( i );
51      }
52  
53      public List<String> getMessages()
54      {
55          return Collections.unmodifiableList( messages );
56      }
57  
58      public void addMessage( String message )
59      {
60          messages.add( message );
61      }
62  
63      public String toString()
64      {
65          return render( "" );
66      }
67  
68      public String render( String indentation )
69      {
70          if ( messages.size() == 0 )
71          {
72              return indentation + "There were no validation errors.";
73          }
74  
75          StringBuilder message = new StringBuilder();
76  
77  //        if ( messages.size() == 1 )
78  //        {
79  //            message.append( "There was 1 validation error: " );
80  //        }
81  //        else
82  //        {
83  //            message.append( "There was " + messages.size() + " validation errors: " + NEWLINE );
84  //        }
85  //
86          for ( int i = 0; i < messages.size(); i++ )
87          {
88              message.append( indentation + "[" + i + "]  " + messages.get( i ) + NEWLINE );
89          }
90  
91          return message.toString();
92      }
93  
94  }