| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| JavadocPackageCheck |
|
| 2.5;2.5 |
| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
| 3 | // Copyright (C) 2001-2014 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 com.google.common.collect.Sets; | |
| 22 | import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck; | |
| 23 | import java.io.File; | |
| 24 | import java.util.List; | |
| 25 | import java.util.Set; | |
| 26 | ||
| 27 | /** | |
| 28 | * Checks that all packages have a package documentation. See the documentation | |
| 29 | * for more information. | |
| 30 | * @author Oliver Burn | |
| 31 | */ | |
| 32 | public class JavadocPackageCheck extends AbstractFileSetCheck | |
| 33 | { | |
| 34 | /** Indicates if allow legacy "package.html" file to be used. */ | |
| 35 | private boolean mAllowLegacy; | |
| 36 | /** The directories checked. */ | |
| 37 | 5 | private final Set<File> mDirectoriesChecked = Sets.newHashSet(); |
| 38 | ||
| 39 | /** | |
| 40 | * Creates a new instance. | |
| 41 | */ | |
| 42 | public JavadocPackageCheck() | |
| 43 | 5 | { |
| 44 | // java, not html! | |
| 45 | // The rule is: Every JAVA file should have a package.html sibling | |
| 46 | 5 | setFileExtensions(new String[]{"java"}); |
| 47 | 5 | } |
| 48 | ||
| 49 | @Override | |
| 50 | public void beginProcessing(String aCharset) | |
| 51 | { | |
| 52 | 5 | super.beginProcessing(aCharset); |
| 53 | 5 | mDirectoriesChecked.clear(); |
| 54 | 5 | } |
| 55 | ||
| 56 | @Override | |
| 57 | protected void processFiltered(File aFile, List<String> aLines) | |
| 58 | { | |
| 59 | // Check if already processed directory | |
| 60 | 5 | final File dir = aFile.getParentFile(); |
| 61 | 5 | if (mDirectoriesChecked.contains(dir)) { |
| 62 | 0 | return; |
| 63 | } | |
| 64 | 5 | mDirectoriesChecked.add(dir); |
| 65 | ||
| 66 | // Check for the preferred file. | |
| 67 | 5 | final File packageInfo = new File(dir, "package-info.java"); |
| 68 | 5 | final File packageHtml = new File(dir, "package.html"); |
| 69 | ||
| 70 | 5 | if (packageInfo.exists()) { |
| 71 | 2 | if (packageHtml.exists()) { |
| 72 | 1 | log(0, "javadoc.legacyPackageHtml"); |
| 73 | } | |
| 74 | } | |
| 75 | 3 | else if (!mAllowLegacy || !packageHtml.exists()) { |
| 76 | 2 | log(0, "javadoc.packageInfo"); |
| 77 | } | |
| 78 | 5 | } |
| 79 | ||
| 80 | /** | |
| 81 | * Indicates whether to allow support for the legacy <i>package.html</i> | |
| 82 | * file. | |
| 83 | * @param aAllowLegacy whether to allow support. | |
| 84 | */ | |
| 85 | public void setAllowLegacy(boolean aAllowLegacy) | |
| 86 | { | |
| 87 | 1 | mAllowLegacy = aAllowLegacy; |
| 88 | 1 | } |
| 89 | } |