KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > javadoc > PackageHtmlCheck


1 ////////////////////////////////////////////////////////////////////////////////
2
// checkstyle: Checks Java source code for adherence to a set of rules.
3
// Copyright (C) 2001-2005 Oliver Burn
4
//
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation; either
8
// version 2.1 of the License, or (at your option) any later version.
9
//
10
// This library is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
// Lesser General Public License for more details.
14
//
15
// You should have received a copy of the GNU Lesser General Public
16
// License along with this library; if not, write to the Free Software
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
////////////////////////////////////////////////////////////////////////////////
19
package com.puppycrawl.tools.checkstyle.checks.javadoc;
20
21 import java.io.File JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Set JavaDoc;
24 import java.util.HashSet JavaDoc;
25
26 import com.puppycrawl.tools.checkstyle.api.MessageDispatcher;
27 import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
28
29 /**
30  * Checks that all packages have a package documentation.
31  *
32  * @author lkuehne
33  */

34 public class PackageHtmlCheck extends AbstractFileSetCheck
35 {
36     /**
37      * Creates a new <code>PackageHtmlCheck</code> instance.
38      */

39     public PackageHtmlCheck()
40     {
41         // java, not html!
42
// The rule is: Every JAVA file should have a package.html sibling
43
setFileExtensions(new String JavaDoc[]{"java"});
44     }
45
46     /**
47      * Checks that each java file in the fileset has a package.html sibling
48      * and fires errors for the missing files.
49      * @param aFiles a set of files
50      */

51     public void process(File JavaDoc[] aFiles)
52     {
53         final File JavaDoc[] javaFiles = filter(aFiles);
54         final Set JavaDoc directories = getParentDirs(javaFiles);
55         for (final Iterator JavaDoc it = directories.iterator(); it.hasNext();) {
56             final File JavaDoc dir = (File JavaDoc) it.next();
57             final File JavaDoc packageHtml = new File JavaDoc(dir, "package.html");
58             final MessageDispatcher dispatcher = getMessageDispatcher();
59             final String JavaDoc path = packageHtml.getPath();
60             dispatcher.fireFileStarted(path);
61             if (!packageHtml.exists()) {
62                 log(0, "javadoc.packageHtml");
63                 fireErrors(path);
64             }
65             dispatcher.fireFileFinished(path);
66         }
67     }
68
69     /**
70      * Returns the set of directories for a set of files.
71      * @param aFiles s set of files
72      * @return the set of parent directories of the given files
73      */

74     protected final Set JavaDoc getParentDirs(File JavaDoc[] aFiles)
75     {
76         final Set JavaDoc directories = new HashSet JavaDoc();
77         for (int i = 0; i < aFiles.length; i++) {
78             final File JavaDoc f = aFiles[i].getAbsoluteFile();
79             if (f.getName().endsWith(".java")) {
80                 final File JavaDoc dir = f.getParentFile();
81                 directories.add(dir); // duplicates are handled automatically
82
}
83         }
84         return directories;
85     }
86 }
87
Popular Tags