diff --git a/pom.xml b/pom.xml
index c11e4245e..8133843ab 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1112,17 +1112,13 @@
.*.checks.coding.SimplifyBooleanReturnCheck83100
.*.checks.coding.VariableDeclarationUsageDistanceCheck9098
-
- .*.checks.header.AbstractHeaderCheck9087
- .*.checks.header.HeaderCheck3150
-
-
.*.checks.javadoc.AbstractJavadocCheck9093
.*.checks.javadoc.AbstractJavadocCheck\$.*5068
.*.checks.javadoc.AtclauseOrderCheck8888
.*.checks.javadoc.JavadocMethodCheck9198
.*.checks.javadoc.WriteTagCheck10091
+ .*.checks.header.AbstractHeaderCheck9087
.*.checks.metrics.AbstractClassCouplingCheck8797
.*.checks.metrics.AbstractClassCouplingCheck\$.*78100
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/header/HeaderCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/header/HeaderCheck.java
index 69674911b..709f3184e 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/header/HeaderCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/header/HeaderCheck.java
@@ -76,7 +76,7 @@ public class HeaderCheck extends AbstractHeaderCheck {
* @param list comma separated list of line numbers to ignore in header.
*/
public void setIgnoreLines(int... list) {
- if (list == null || list.length == 0) {
+ if (list.length == 0) {
ignoreLines = EMPTY_INT_ARRAY;
return;
}
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/header/HeaderCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/header/HeaderCheckTest.java
index e4a2371e9..6dfbc3528 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/header/HeaderCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/header/HeaderCheckTest.java
@@ -23,9 +23,6 @@ import static com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck.MSG_MISM
import static com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck.MSG_MISSING;
import static org.junit.Assert.fail;
-import java.io.File;
-import java.net.URI;
-
import org.junit.Test;
import com.puppycrawl.tools.checkstyle.BaseFileSetCheckTestSupport;
@@ -33,10 +30,11 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
public class HeaderCheckTest extends BaseFileSetCheckTestSupport {
+
@Test
public void testStaticHeader() throws Exception {
final DefaultConfiguration checkConfig =
- createCheckConfig(HeaderCheck.class);
+ createCheckConfig(HeaderCheck.class);
checkConfig.addAttribute("headerFile", getPath("configs/java.header"));
checkConfig.addAttribute("ignoreLines", "");
final String[] expected = {
@@ -45,135 +43,11 @@ public class HeaderCheckTest extends BaseFileSetCheckTestSupport {
verify(checkConfig, getPath("inputHeader.java"), expected);
}
- @Test
- public void testRegexpHeader() throws Exception {
- final DefaultConfiguration checkConfig =
- createCheckConfig(RegexpHeaderCheck.class);
- checkConfig.addAttribute("headerFile", getPath("regexp.header"));
- final String[] expected = {
- "3: " + getCheckMessage(MSG_MISMATCH, "// Created: 2002"),
- };
- verify(checkConfig, getPath("InputScopeAnonInner.java"), expected);
- }
-
- @Test
- public void testRegexpHeaderURL() throws Exception {
- final DefaultConfiguration checkConfig =
- createCheckConfig(RegexpHeaderCheck.class);
- URI uri = new File(getPath("regexp.header")).toURI();
- checkConfig.addAttribute("headerFile", uri.toString());
- final String[] expected = {
- "3: " + getCheckMessage(MSG_MISMATCH, "// Created: 2002"),
- };
- verify(checkConfig, getPath("InputScopeAnonInner.java"), expected);
- }
-
- @Test
- public void testInlineRegexpHeader() throws Exception {
- final DefaultConfiguration checkConfig =
- createCheckConfig(RegexpHeaderCheck.class);
- checkConfig.addAttribute("header", "^/*$\\n// .*\\n// Created: 2002\\n^//.*\\n^//.*");
- final String[] expected = {
- "3: " + getCheckMessage(MSG_MISMATCH, "// Created: 2002"),
- };
- verify(checkConfig, getPath("InputScopeAnonInner.java"), expected);
- }
-
- @Test
- public void testFailureForMultilineRegexp() throws Exception {
- final DefaultConfiguration checkConfig =
- createCheckConfig(RegexpHeaderCheck.class);
- checkConfig.addAttribute("header", "^(.*\\n.*)");
- try {
- createChecker(checkConfig);
- fail("Checker creation should not succeed when regexp spans multiple lines");
- }
- catch (CheckstyleException ex) {
- // expected exception
- }
- }
-
- @Test
- public void testRegexpHeaderIgnore() throws Exception {
- final DefaultConfiguration checkConfig =
- createCheckConfig(RegexpHeaderCheck.class);
- checkConfig.addAttribute("headerFile", getPath("regexp.header1"));
- final String[] expected = {
- };
- verify(checkConfig, getPath("InputScopeAnonInner.java"), expected);
- }
-
- @Test
- public void testRegexpHeaderMulti1() throws Exception {
- final DefaultConfiguration checkConfig =
- createCheckConfig(RegexpHeaderCheck.class);
- checkConfig.addAttribute("headerFile", getPath("regexp.header2"));
- checkConfig.addAttribute("multiLines", "3, 6");
- final String[] expected = {
- };
- verify(checkConfig, getPath("InputRegexpHeader1.java"), expected);
- }
-
- @Test
- public void testRegexpHeaderMulti2() throws Exception {
- final DefaultConfiguration checkConfig =
- createCheckConfig(RegexpHeaderCheck.class);
- checkConfig.addAttribute("headerFile", getPath("regexp.header2"));
- checkConfig.addAttribute("multiLines", "3, 6");
- final String[] expected = {
- };
- verify(checkConfig, getPath("InputRegexpHeader2.java"), expected);
- }
-
- @Test
- public void testRegexpHeaderMulti3() throws Exception {
- final DefaultConfiguration checkConfig =
- createCheckConfig(RegexpHeaderCheck.class);
- checkConfig.addAttribute("headerFile", getPath("regexp.header2"));
- checkConfig.addAttribute("multiLines", "3, 7");
- final String[] expected = {
- };
- verify(checkConfig, getPath("InputRegexpHeader1.java"), expected);
- }
-
- @Test
- public void testRegexpHeaderMulti4() throws Exception {
- final DefaultConfiguration checkConfig =
- createCheckConfig(RegexpHeaderCheck.class);
- checkConfig.addAttribute("headerFile", getPath("regexp.header2"));
- checkConfig.addAttribute("multiLines", "3, 5, 6, 7");
- final String[] expected = {
- };
- verify(checkConfig, getPath("InputRegexpHeader3.java"), expected);
- }
-
- @Test
- public void testRegexpHeaderMulti5() throws Exception {
- final DefaultConfiguration checkConfig =
- createCheckConfig(RegexpHeaderCheck.class);
- checkConfig.addAttribute("headerFile", getPath("regexp.header2"));
- checkConfig.addAttribute("multiLines", "3");
- final String[] expected = {
- "1: " + getCheckMessage(MSG_MISSING),
- };
- verify(checkConfig, getPath("InputRegexpHeader4.java"), expected);
- }
-
- @Test
- public void testRegexpHeaderSmallHeader() throws Exception {
- final DefaultConfiguration checkConfig =
- createCheckConfig(RegexpHeaderCheck.class);
- checkConfig.addAttribute("headerFile", getPath("regexp.header2"));
- checkConfig.addAttribute("multiLines", "3, 6");
- final String[] expected = {
- };
- verify(checkConfig, getPath("InputRegexpSmallHeader.java"), expected);
- }
@Test
public void testNoHeader() throws Exception {
final DefaultConfiguration checkConfig =
- createCheckConfig(HeaderCheck.class);
+ createCheckConfig(HeaderCheck.class);
try {
createChecker(checkConfig);
final String[] expected = {
@@ -189,7 +63,7 @@ public class HeaderCheckTest extends BaseFileSetCheckTestSupport {
@Test
public void testNonExistingHeaderFile() throws Exception {
final DefaultConfiguration checkConfig =
- createCheckConfig(HeaderCheck.class);
+ createCheckConfig(HeaderCheck.class);
checkConfig.addAttribute("headerFile", getPath("nonexisting.file"));
try {
createChecker(checkConfig);
@@ -203,7 +77,7 @@ public class HeaderCheckTest extends BaseFileSetCheckTestSupport {
@Test
public void testInvalidCharset() throws Exception {
final DefaultConfiguration checkConfig =
- createCheckConfig(HeaderCheck.class);
+ createCheckConfig(HeaderCheck.class);
checkConfig.addAttribute("headerFile", getPath("config/java.header"));
checkConfig.addAttribute("charset", "XSO-8859-1");
try {
@@ -218,7 +92,7 @@ public class HeaderCheckTest extends BaseFileSetCheckTestSupport {
@Test
public void testEmptyFilename() throws Exception {
final DefaultConfiguration checkConfig =
- createCheckConfig(HeaderCheck.class);
+ createCheckConfig(HeaderCheck.class);
checkConfig.addAttribute("headerFile", "");
try {
createChecker(checkConfig);
@@ -228,4 +102,29 @@ public class HeaderCheckTest extends BaseFileSetCheckTestSupport {
// expected exception
}
}
+
+ @Test
+ public void testNotMatch() throws Exception {
+ final DefaultConfiguration checkConfig =
+ createCheckConfig(HeaderCheck.class);
+ checkConfig.addAttribute("headerFile", getPath("configs/java.header"));
+ checkConfig.addAttribute("ignoreLines", "");
+ final String[] expected = {
+ "2: " + getCheckMessage(MSG_MISMATCH,
+ "// checkstyle: Checks Java source code for adherence to a set of rules."),
+ };
+ verify(checkConfig, getPath("configs/java2.header"), expected);
+ }
+
+ @Test
+ public void testIgnore() throws Exception {
+ final DefaultConfiguration checkConfig =
+ createCheckConfig(HeaderCheck.class);
+ checkConfig.addAttribute("headerFile", getPath("configs/java.header"));
+ checkConfig.addAttribute("ignoreLines", "2");
+ final String[] expected = {
+ };
+ verify(checkConfig, getPath("configs/java2.header"), expected);
+ }
+
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/configs/java2.header b/src/test/resources/com/puppycrawl/tools/checkstyle/configs/java2.header
new file mode 100644
index 000000000..3c9990e8b
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/configs/java2.header
@@ -0,0 +1,18 @@
+////////////////////////////////////////////////////////////////////////////////
+//testvdfvcheckstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2015 the original author or authors.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////