001    package org.apache.maven.project.validation;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *  http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import java.util.ArrayList;
023    import java.util.Collections;
024    import java.util.List;
025    
026    /**
027     * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
028     */
029    public class ModelValidationResult
030    {
031    
032        /** */
033        private static final String NEWLINE = System.getProperty( "line.separator" );
034    
035        /** */
036        private List<String> messages;
037    
038        public ModelValidationResult()
039        {
040            messages = new ArrayList<String>();
041        }
042    
043        public int getMessageCount()
044        {
045            return messages.size();
046        }
047    
048        public String getMessage( int i )
049        {
050            return messages.get( i );
051        }
052    
053        public List<String> getMessages()
054        {
055            return Collections.unmodifiableList( messages );
056        }
057    
058        public void addMessage( String message )
059        {
060            messages.add( message );
061        }
062    
063        public String toString()
064        {
065            return render( "" );
066        }
067    
068        public String render( String indentation )
069        {
070            if ( messages.size() == 0 )
071            {
072                return indentation + "There were no validation errors.";
073            }
074    
075            StringBuilder message = new StringBuilder();
076    
077    //        if ( messages.size() == 1 )
078    //        {
079    //            message.append( "There was 1 validation error: " );
080    //        }
081    //        else
082    //        {
083    //            message.append( "There was " + messages.size() + " validation errors: " + NEWLINE );
084    //        }
085    //
086            for ( int i = 0; i < messages.size(); i++ )
087            {
088                message.append( indentation + "[" + i + "]  " + messages.get( i ).toString() + NEWLINE );
089            }
090    
091            return message.toString();
092        }
093    
094    }