Skip to content

Commit 7efb92f

Browse files
committed
[MCHECKSTYLE-432] Inline configuration does not work when creating site reports with multiple locales
Co-authored-by: Peter Lamby <[email protected]> This closes #112 and closes #113
1 parent 997f1e4 commit 7efb92f

File tree

8 files changed

+170
-8
lines changed

8 files changed

+170
-8
lines changed
+18
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 site

src/it/MCHECKSTYLE-432/pom.xml

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<groupId>org.apache.maven.plugins.checkstyle.its</groupId>
27+
<artifactId>MCHECKSTYLE-432</artifactId>
28+
<version>1.0-SNAPSHOT</version>
29+
30+
<url>https://issues.apache.org/jira/browse/MCHECKSTYLE-432</url>
31+
32+
<properties>
33+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34+
<checkstyle.consoleOutput>true</checkstyle.consoleOutput>
35+
</properties>
36+
37+
<build>
38+
<plugins>
39+
<plugin>
40+
<groupId>org.apache.maven.plugins</groupId>
41+
<artifactId>maven-checkstyle-plugin</artifactId>
42+
<version>@project.version@</version>
43+
<configuration>
44+
<checkstyleRules>
45+
<module name="Checker">
46+
<module name="TreeWalker">
47+
<module name="EmptyBlock"/>
48+
</module>
49+
<module name="FileTabCharacter">
50+
<property name="eachLine" value="true" />
51+
</module>
52+
</module>
53+
</checkstyleRules>
54+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
55+
</configuration>
56+
<executions>
57+
<execution>
58+
<goals>
59+
<goal>check</goal>
60+
</goals>
61+
</execution>
62+
</executions>
63+
</plugin>
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-site-plugin</artifactId>
67+
<version>@sitePluginVersion@</version>
68+
<configuration>
69+
<locales>default,fr,de</locales>
70+
</configuration>
71+
<executions>
72+
<execution>
73+
<goals>
74+
<goal>attach-descriptor</goal>
75+
</goals>
76+
</execution>
77+
</executions>
78+
</plugin>
79+
</plugins>
80+
</build>
81+
<reporting>
82+
<plugins>
83+
<plugin>
84+
<groupId>org.apache.maven.plugins</groupId>
85+
<artifactId>maven-checkstyle-plugin</artifactId>
86+
<version>@project.version@</version>
87+
</plugin>
88+
</plugins>
89+
</reporting>
90+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org;
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+
/**
23+
* Yada yada yada.
24+
*/
25+
public class MyClass {
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
<html>
20+
<head>
21+
<title></title>
22+
</head>
23+
<body>
24+
</body>
25+
</html>

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ public void executeReport( Locale locale )
493493
// locator = new Locator( new MojoLogMonitorAdaptor( getLog() ) );
494494

495495
// locator = new Locator( getLog(), new File( project.getBuild().getDirectory() ) );
496+
String effectiveConfigLocation = configLocation;
496497
if ( checkstyleRules != null )
497498
{
498499
if ( !DEFAULT_CONFIG_LOCATION.equals( configLocation ) )
@@ -515,21 +516,22 @@ public void executeReport( Locale locale )
515516
{
516517
throw new MavenReportException( e.getMessage(), e );
517518
}
518-
configLocation = rulesFiles.getAbsolutePath();
519+
effectiveConfigLocation = rulesFiles.getAbsolutePath();
519520
}
520521
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
521522

522523
try
523524
{
524525
CheckstyleExecutorRequest request = createRequest().setLicenseArtifacts( collectArtifacts( "license" ) )
525526
.setConfigurationArtifacts( collectArtifacts( "configuration" ) )
526-
.setOmitIgnoredModules( omitIgnoredModules );
527+
.setOmitIgnoredModules( omitIgnoredModules )
528+
.setConfigLocation( effectiveConfigLocation );
527529

528530
CheckstyleResults results = checkstyleExecutor.executeCheckstyle( request );
529531

530532
ResourceBundle bundle = getBundle( locale );
531533
generateReportStatics();
532-
generateMainReport( results, bundle );
534+
generateMainReport( results, bundle, effectiveConfigLocation );
533535
if ( enableRSS )
534536
{
535537
CheckstyleRssGeneratorRequest checkstyleRssGeneratorRequest =
@@ -725,7 +727,7 @@ private String getCopyright()
725727
return copyright;
726728
}
727729

728-
private void generateMainReport( CheckstyleResults results, ResourceBundle bundle )
730+
private void generateMainReport( CheckstyleResults results, ResourceBundle bundle, String configLocation )
729731
{
730732
CheckstyleReportGenerator generator =
731733
new CheckstyleReportGenerator( getSink(), bundle, project.getBasedir(), siteTool, configLocation );

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected CheckstyleExecutorRequest createRequest()
7373
.setProject( project ).setSourceDirectories( getSourceDirectories() )
7474
.setResources( resources ).setTestResources( testResources )
7575
.setStringOutputStream( stringOutputStream ).setSuppressionsLocation( suppressionsLocation )
76-
.setTestSourceDirectories( getTestSourceDirectories() ).setConfigLocation( configLocation )
76+
.setTestSourceDirectories( getTestSourceDirectories() )
7777
.setPropertyExpansion( propertyExpansion ).setHeaderLocation( headerLocation )
7878
.setCacheFile( cacheFile ).setSuppressionsFileExpression( suppressionsFileExpression )
7979
.setEncoding( getInputEncoding() ).setPropertiesLocation( propertiesLocation );

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected CheckstyleExecutorRequest createRequest()
6666
.setProject( project ).setSourceDirectories( getSourceDirectories() )
6767
.setResources( resources )
6868
.setStringOutputStream( stringOutputStream ).setSuppressionsLocation( suppressionsLocation )
69-
.setTestSourceDirectories( getTestSourceDirectories() ).setConfigLocation( configLocation )
69+
.setTestSourceDirectories( getTestSourceDirectories() )
7070
.setPropertyExpansion( propertyExpansion ).setHeaderLocation( headerLocation )
7171
.setCacheFile( cacheFile ).setSuppressionsFileExpression( suppressionsFileExpression )
7272
.setEncoding( getInputEncoding() ).setPropertiesLocation( propertiesLocation );

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ public void execute()
494494

495495
if ( !skipExec )
496496
{
497+
String effectiveConfigLocation = configLocation;
497498
if ( checkstyleRules != null )
498499
{
499500
if ( !DEFAULT_CONFIG_LOCATION.equals( configLocation ) )
@@ -517,7 +518,7 @@ public void execute()
517518
{
518519
throw new MojoExecutionException( e.getMessage(), e );
519520
}
520-
configLocation = rulesFiles.getAbsolutePath();
521+
effectiveConfigLocation = rulesFiles.getAbsolutePath();
521522
}
522523

523524
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
@@ -535,7 +536,7 @@ public void execute()
535536
.setProject( project ).setSourceDirectories( getSourceDirectories() )
536537
.setResources( resources ).setTestResources( testResources )
537538
.setStringOutputStream( stringOutputStream ).setSuppressionsLocation( suppressionsLocation )
538-
.setTestSourceDirectories( getTestSourceDirectories() ).setConfigLocation( configLocation )
539+
.setTestSourceDirectories( getTestSourceDirectories() ).setConfigLocation( effectiveConfigLocation )
539540
.setConfigurationArtifacts( collectArtifacts( "config" ) )
540541
.setPropertyExpansion( propertyExpansion )
541542
.setHeaderLocation( headerLocation ).setLicenseArtifacts( collectArtifacts( "license" ) )

0 commit comments

Comments
 (0)