View Javadoc

1   package org.apache.maven;
2   
3   /* ====================================================================
4    *   Copyright 2001-2004 The Apache Software Foundation.
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing, software
13   *   distributed under the License is distributed on an "AS IS" BASIS,
14   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *   See the License for the specific language governing permissions and
16   *   limitations under the License.
17   * ====================================================================
18   */
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.apache.maven.project.Project;
24  
25  /**
26   * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
27   * @version $Id: ContentValidator.java 170200 2005-05-15 06:24:19Z brett $
28   */
29  public class ContentValidator
30  {
31    private List notices;
32    private Project project;
33    
34    public ContentValidator()
35    {
36    }
37    
38    /**
39     * @return Project
40     */
41    public Project getProject()
42    {
43      return project;
44    }
45  
46    /**
47     * Sets the project.
48     * @param project The project to set
49     */
50    public void setProject(Project project)
51    {
52      this.project = project;
53    }
54  
55    /**
56     * Adds a single notice to the list
57     * @param notice the notice to add
58     */
59    protected void addNotice(ContentNotice notice)
60    {
61      notices.add(notice);
62    }
63  
64    /**
65     * Adds a single notice to the list
66     * @param level
67     * @param section
68     * @param message
69     */
70    protected void addNotice(String level, String section, String message)
71    {
72      addNotice(new ContentNotice(level, section, message));
73    }
74  
75    /**
76     * Runs the validation routine and returns any notices
77     * @return List
78     */
79    public List execute()
80    {
81      notices = new ArrayList();
82      validateProject();
83      return notices;
84    }
85  
86    /**
87     * Validates the top level project item
88     */
89    protected void validateProject()
90    {
91      if (project.getLogo() == null || project.getLogo().trim().length() == 0)
92      {
93        addNotice(ContentNotice.INFO, "/project/logo", "Element is null or empty.  No logo will be displayed.");
94      }
95  
96      validateLicenses();
97    }
98  
99    /**
100    * Validates the licenses element
101    */
102   protected void validateLicenses()
103   {
104     if (project.getLicenses().size() == 0)
105     {
106       addNotice(
107         ContentNotice.WARN,
108         "/project/licenses",
109         "No licenses defined. Your project has a license and it should be entered into the licenses section.");
110     }
111   }
112 
113   /**
114    * Validates the developers element
115    */
116   protected void validateDevelopers()
117   {
118   }
119 
120 }