Clover Coverage Report - Checkstyle
Coverage timestamp: Fri May 9 2008 10:48:13 EST
../../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
20   86   7   6.67
8   43   0.35   3
3     2.33  
1    
 
  PackageHtmlCheck       Line # 34 93.5% 0.9354839
7.01 20 7 7 0.35
 
  (1)
 
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;
22    import java.util.Iterator;
23    import java.util.Set;
24    import java.util.HashSet;
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  1 toggle public PackageHtmlCheck()
40    {
41    // java, not html!
42    // The rule is: Every JAVA file should have a package.html sibling
43  1 setFileExtensions(new String[]{"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  1 toggle public void process(File[] aFiles)
52    {
53  1 final File[] javaFiles = filter(aFiles);
54  1 final Set directories = getParentDirs(javaFiles);
55  2 for (final Iterator it = directories.iterator(); it.hasNext();) {
56  1 final File dir = (File) it.next();
57  1 final File packageHtml = new File(dir, "package.html");
58  1 final MessageDispatcher dispatcher = getMessageDispatcher();
59  1 final String path = packageHtml.getPath();
60  1 dispatcher.fireFileStarted(path);
61  1 if (!packageHtml.exists()) {
62  1 log(0, "javadoc.packageHtml");
63  1 fireErrors(path);
64    }
65  1 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  1 toggle protected final Set getParentDirs(File[] aFiles)
75    {
76  1 final Set directories = new HashSet();
77  2 for (int i = 0; i < aFiles.length; i++) {
78  1 final File f = aFiles[i].getAbsoluteFile();
79  1 if (f.getName().endsWith(".java")) {
80  1 final File dir = f.getParentFile();
81  1 directories.add(dir); // duplicates are handled automatically
82    }
83    }
84  1 return directories;
85    }
86    }