This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch fix
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git

commit 7efb92fed0d595350f8181f8db22a2c54192d275
Author: Michael Osipov <[email protected]>
AuthorDate: Tue Apr 18 14:00:16 2023 +0200

    [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
---
 src/it/MCHECKSTYLE-432/invoker.properties          | 18 +++++
 src/it/MCHECKSTYLE-432/pom.xml                     | 90 ++++++++++++++++++++++
 .../MCHECKSTYLE-432/src/main/java/org/MyClass.java | 26 +++++++
 .../MCHECKSTYLE-432/src/main/java/org/package.html | 25 ++++++
 .../checkstyle/AbstractCheckstyleReport.java       | 10 ++-
 .../checkstyle/CheckstyleAggregateReport.java      |  2 +-
 .../maven/plugins/checkstyle/CheckstyleReport.java |  2 +-
 .../checkstyle/CheckstyleViolationCheckMojo.java   |  5 +-
 8 files changed, 170 insertions(+), 8 deletions(-)

diff --git a/src/it/MCHECKSTYLE-432/invoker.properties 
b/src/it/MCHECKSTYLE-432/invoker.properties
new file mode 100644
index 0000000..fe48ca1
--- /dev/null
+++ b/src/it/MCHECKSTYLE-432/invoker.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals=clean site
diff --git a/src/it/MCHECKSTYLE-432/pom.xml b/src/it/MCHECKSTYLE-432/pom.xml
new file mode 100644
index 0000000..8afe9a7
--- /dev/null
+++ b/src/it/MCHECKSTYLE-432/pom.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<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/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.checkstyle.its</groupId>
+  <artifactId>MCHECKSTYLE-432</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <url>https://issues.apache.org/jira/browse/MCHECKSTYLE-432</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <checkstyle.consoleOutput>true</checkstyle.consoleOutput>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <checkstyleRules>
+            <module name="Checker">
+              <module name="TreeWalker">
+                <module name="EmptyBlock"/>
+              </module>
+              <module name="FileTabCharacter">
+                <property name="eachLine" value="true" />
+              </module>
+            </module>
+          </checkstyleRules>
+          <includeTestSourceDirectory>true</includeTestSourceDirectory>
+        </configuration>
+        <executions>
+          <execution>
+            <goals>
+              <goal>check</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-site-plugin</artifactId>
+        <version>@sitePluginVersion@</version>
+        <configuration>
+          <locales>default,fr,de</locales>
+        </configuration>
+        <executions>
+          <execution>
+            <goals>
+              <goal>attach-descriptor</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <version>@project.version@</version>
+      </plugin>
+    </plugins>
+  </reporting>
+</project>
diff --git a/src/it/MCHECKSTYLE-432/src/main/java/org/MyClass.java 
b/src/it/MCHECKSTYLE-432/src/main/java/org/MyClass.java
new file mode 100644
index 0000000..84a40d3
--- /dev/null
+++ b/src/it/MCHECKSTYLE-432/src/main/java/org/MyClass.java
@@ -0,0 +1,26 @@
+package org;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Yada yada yada.
+ */
+public class MyClass {
+}
diff --git a/src/it/MCHECKSTYLE-432/src/main/java/org/package.html 
b/src/it/MCHECKSTYLE-432/src/main/java/org/package.html
new file mode 100644
index 0000000..c66f6f2
--- /dev/null
+++ b/src/it/MCHECKSTYLE-432/src/main/java/org/package.html
@@ -0,0 +1,25 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<html>
+       <head>
+               <title></title>
+       </head>
+       <body>
+       </body>
+</html>
diff --git 
a/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java
 
b/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java
index 16721aa..f6e4d66 100644
--- 
a/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java
+++ 
b/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java
@@ -493,6 +493,7 @@ public abstract class AbstractCheckstyleReport
         // locator = new Locator( new MojoLogMonitorAdaptor( getLog() ) );
 
         // locator = new Locator( getLog(), new File( 
project.getBuild().getDirectory() ) );
+        String effectiveConfigLocation = configLocation;
         if ( checkstyleRules != null )
         {
             if ( !DEFAULT_CONFIG_LOCATION.equals( configLocation ) )
@@ -515,7 +516,7 @@ public abstract class AbstractCheckstyleReport
             {
                 throw new MavenReportException( e.getMessage(), e );
             }
-            configLocation = rulesFiles.getAbsolutePath();
+            effectiveConfigLocation = rulesFiles.getAbsolutePath();
         }
         ClassLoader currentClassLoader = 
Thread.currentThread().getContextClassLoader();
 
@@ -523,13 +524,14 @@ public abstract class AbstractCheckstyleReport
         {
             CheckstyleExecutorRequest request = 
createRequest().setLicenseArtifacts( collectArtifacts( "license" ) )
                             .setConfigurationArtifacts( collectArtifacts( 
"configuration" ) )
-                            .setOmitIgnoredModules( omitIgnoredModules );
+                            .setOmitIgnoredModules( omitIgnoredModules )
+                            .setConfigLocation( effectiveConfigLocation );
 
             CheckstyleResults results = checkstyleExecutor.executeCheckstyle( 
request );
 
             ResourceBundle bundle = getBundle( locale );
             generateReportStatics();
-            generateMainReport( results, bundle );
+            generateMainReport( results, bundle, effectiveConfigLocation );
             if ( enableRSS )
             {
                 CheckstyleRssGeneratorRequest checkstyleRssGeneratorRequest =
@@ -725,7 +727,7 @@ public abstract class AbstractCheckstyleReport
         return copyright;
     }
 
-    private void generateMainReport( CheckstyleResults results, ResourceBundle 
bundle )
+    private void generateMainReport( CheckstyleResults results, ResourceBundle 
bundle, String configLocation )
     {
         CheckstyleReportGenerator generator =
             new CheckstyleReportGenerator( getSink(), bundle, 
project.getBasedir(), siteTool, configLocation );
diff --git 
a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleAggregateReport.java
 
b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleAggregateReport.java
index dee6f64..6d9b381 100644
--- 
a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleAggregateReport.java
+++ 
b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleAggregateReport.java
@@ -73,7 +73,7 @@ public class CheckstyleAggregateReport
             .setProject( project ).setSourceDirectories( 
getSourceDirectories() )
             .setResources( resources ).setTestResources( testResources )
             .setStringOutputStream( stringOutputStream 
).setSuppressionsLocation( suppressionsLocation )
-            .setTestSourceDirectories( getTestSourceDirectories() 
).setConfigLocation( configLocation )
+            .setTestSourceDirectories( getTestSourceDirectories() )
             .setPropertyExpansion( propertyExpansion ).setHeaderLocation( 
headerLocation )
             .setCacheFile( cacheFile ).setSuppressionsFileExpression( 
suppressionsFileExpression )
             .setEncoding( getInputEncoding() ).setPropertiesLocation( 
propertiesLocation );
diff --git 
a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java 
b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java
index 0d3af2d..c742421 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java
@@ -66,7 +66,7 @@ public class CheckstyleReport
             .setProject( project ).setSourceDirectories( 
getSourceDirectories() )
             .setResources( resources )
             .setStringOutputStream( stringOutputStream 
).setSuppressionsLocation( suppressionsLocation )
-            .setTestSourceDirectories( getTestSourceDirectories() 
).setConfigLocation( configLocation )
+            .setTestSourceDirectories( getTestSourceDirectories() )
             .setPropertyExpansion( propertyExpansion ).setHeaderLocation( 
headerLocation )
             .setCacheFile( cacheFile ).setSuppressionsFileExpression( 
suppressionsFileExpression )
             .setEncoding( getInputEncoding() ).setPropertiesLocation( 
propertiesLocation );
diff --git 
a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
 
b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
index d2bb6d0..b3e8cc4 100644
--- 
a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
+++ 
b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
@@ -494,6 +494,7 @@ public class CheckstyleViolationCheckMojo
 
         if ( !skipExec )
         {
+            String effectiveConfigLocation = configLocation;
             if ( checkstyleRules != null )
             {
                 if ( !DEFAULT_CONFIG_LOCATION.equals( configLocation ) )
@@ -517,7 +518,7 @@ public class CheckstyleViolationCheckMojo
                 {
                     throw new MojoExecutionException( e.getMessage(), e );
                 }
-                configLocation = rulesFiles.getAbsolutePath();
+                effectiveConfigLocation = rulesFiles.getAbsolutePath();
             }
 
             ClassLoader currentClassLoader = 
Thread.currentThread().getContextClassLoader();
@@ -535,7 +536,7 @@ public class CheckstyleViolationCheckMojo
                     .setProject( project ).setSourceDirectories( 
getSourceDirectories() )
                     .setResources( resources ).setTestResources( testResources 
)
                     .setStringOutputStream( stringOutputStream 
).setSuppressionsLocation( suppressionsLocation )
-                    .setTestSourceDirectories( getTestSourceDirectories() 
).setConfigLocation( configLocation )
+                    .setTestSourceDirectories( getTestSourceDirectories() 
).setConfigLocation( effectiveConfigLocation )
                     .setConfigurationArtifacts( collectArtifacts( "config" ) )
                     .setPropertyExpansion( propertyExpansion )
                     .setHeaderLocation( headerLocation ).setLicenseArtifacts( 
collectArtifacts( "license" ) )

Reply via email to