Skip to content

Commit 7abd8b6

Browse files
author
Guillaume Boué
committed
[MCHECKSTYLE-338] Add support for 'omitIgnoredModules'
The boolean parameter 'omitIgnoredModules' controls whether modules in a Checkstyle configuration with a severity set to 'ignore' should be omitted or still executed during Checkstyle invocation. This defaults to false to be consistent with the previous behavior of the plugin. IT is done by writing a custom check that does nothing except always logging as an error the name of the file it was invoked on. This is used to verify whether the check was invoked or not depending on the value of 'omitIgnoredModules'. git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1796441 13f79535-47bb-0310-9956-ffa450edef68
1 parent 22c075c commit 7abd8b6

File tree

14 files changed

+398
-6
lines changed

14 files changed

+398
-6
lines changed

src/it/MCHECKSTYLE-338/checkstyle.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
21+
<module name="Checker">
22+
<module name="org.apache.maven.plugins.checkstyle.EmptyLoggingCheck">
23+
<property name="severity" value="ignore" />
24+
</module>
25+
</module>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
<parent>
24+
<groupId>org.apache.maven.plugins.checkstyle</groupId>
25+
<artifactId>MCHECKSTYLE-338</artifactId>
26+
<version>1.0-SNAPSHOT</version>
27+
</parent>
28+
<artifactId>empty-logging-check</artifactId>
29+
<dependencies>
30+
<dependency>
31+
<groupId>com.puppycrawl.tools</groupId>
32+
<artifactId>checkstyle</artifactId>
33+
<version>@checkstyleVersion@</version>
34+
</dependency>
35+
</dependencies>
36+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.apache.maven.plugins.checkstyle;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import java.io.File;
23+
import java.util.List;
24+
25+
import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
26+
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
27+
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
28+
import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
29+
30+
public class EmptyLoggingCheck
31+
extends AbstractFileSetCheck
32+
{
33+
34+
@Override
35+
protected void processFiltered( File file, List<String> lines )
36+
throws CheckstyleException
37+
{
38+
getMessageCollector().add( new LocalizedMessage( 0, 0, getMessageBundle(),
39+
"EmptyLoggingCheck on file " + file.getName(), new Object[0],
40+
SeverityLevel.ERROR, getId(), getClass(), null ) );
41+
}
42+
43+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.goals=clean verify
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
<parent>
24+
<groupId>org.apache.maven.plugins.checkstyle</groupId>
25+
<artifactId>MCHECKSTYLE-338</artifactId>
26+
<version>1.0-SNAPSHOT</version>
27+
</parent>
28+
<artifactId>omitignoredmodules-false</artifactId>
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<artifactId>maven-checkstyle-plugin</artifactId>
33+
<configuration>
34+
<omitIgnoredModules>false</omitIgnoredModules>
35+
<failOnViolation>false</failOnViolation>
36+
</configuration>
37+
</plugin>
38+
</plugins>
39+
</build>
40+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.apache.maven.plugins.checkstyle;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
public class TestFalse
23+
{
24+
25+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
<parent>
24+
<groupId>org.apache.maven.plugins.checkstyle</groupId>
25+
<artifactId>MCHECKSTYLE-338</artifactId>
26+
<version>1.0-SNAPSHOT</version>
27+
</parent>
28+
<artifactId>omitignoredmodules-true</artifactId>
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<artifactId>maven-checkstyle-plugin</artifactId>
33+
<configuration>
34+
<omitIgnoredModules>true</omitIgnoredModules>
35+
</configuration>
36+
</plugin>
37+
</plugins>
38+
</build>
39+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.apache.maven.plugins.checkstyle;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
public class TestTrue
23+
{
24+
25+
}

src/it/MCHECKSTYLE-338/pom.xml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
<groupId>org.apache.maven.plugins.checkstyle</groupId>
24+
<artifactId>MCHECKSTYLE-338</artifactId>
25+
<version>1.0-SNAPSHOT</version>
26+
<packaging>pom</packaging>
27+
<url>https://issues.apache.org/jira/browse/MCHECKSTYLE-338</url>
28+
<properties>
29+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
30+
</properties>
31+
<build>
32+
<pluginManagement>
33+
<plugins>
34+
<plugin>
35+
<artifactId>maven-checkstyle-plugin</artifactId>
36+
<version>@pom.version@</version>
37+
<configuration>
38+
<configLocation>checkstyle.xml</configLocation>
39+
</configuration>
40+
<dependencies>
41+
<dependency>
42+
<groupId>org.apache.maven.plugins.checkstyle</groupId>
43+
<artifactId>empty-logging-check</artifactId>
44+
<version>${project.version}</version>
45+
</dependency>
46+
</dependencies>
47+
<executions>
48+
<execution>
49+
<goals>
50+
<goal>check</goal>
51+
</goals>
52+
</execution>
53+
</executions>
54+
</plugin>
55+
</plugins>
56+
</pluginManagement>
57+
</build>
58+
<modules>
59+
<module>empty-logging-check</module>
60+
<module>omitignoredmodules-false</module>
61+
<module>omitignoredmodules-true</module>
62+
</modules>
63+
</project>

src/it/MCHECKSTYLE-338/verify.groovy

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*/
20+
21+
buildLog = new File( basedir, 'build.log' )
22+
23+
// verify that the "check" goal correctly raised a violation when the ignored module is not omitted
24+
assert buildLog.text.contains( 'EmptyLogging: EmptyLoggingCheck on file TestFalse.java' )
25+
assert !buildLog.text.contains( 'EmptyLogging: EmptyLoggingCheck on file TestTrue.java' )
26+
27+
// verify that the "checkstyle" goal launched by "check" does the same
28+
site = new File( basedir, 'omitignoredmodules-false/target/site/checkstyle.html' )
29+
assert site.text.contains( 'EmptyLoggingCheck on file TestFalse.java' )
30+
site = new File( basedir, 'omitignoredmodules-true/target/site/checkstyle.html' )
31+
assert !site.text.contains( 'EmptyLoggingCheck on file TestTrue.java' )

src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,15 @@ public abstract class AbstractCheckstyleReport
415415
@Parameter
416416
private List<String> treeWalkerNames;
417417

418+
/**
419+
* Specifies whether modules with a configured severity of <code>ignore</code> should be omitted during Checkstyle
420+
* invocation.
421+
*
422+
* @since 3.0.0
423+
*/
424+
@Parameter( defaultValue = "false" )
425+
private boolean omitIgnoredModules;
426+
418427
/**
419428
*/
420429
@Component
@@ -470,7 +479,8 @@ public void executeReport( Locale locale )
470479
try
471480
{
472481
CheckstyleExecutorRequest request = createRequest().setLicenseArtifacts( collectArtifacts( "license" ) )
473-
.setConfigurationArtifacts( collectArtifacts( "configuration" ) );
482+
.setConfigurationArtifacts( collectArtifacts( "configuration" ) )
483+
.setOmitIgnoredModules( omitIgnoredModules );
474484

475485
CheckstyleResults results = checkstyleExecutor.executeCheckstyle( request );
476486

0 commit comments

Comments
 (0)