Skip to content

Commit

Permalink
[MCHECKSTYLE-432] Inline configuration does not work when creating si…
Browse files Browse the repository at this point in the history
…te reports with multiple locales

Co-authored-by: Peter Lamby <dev@peterlamby.de>

This closes #112 and closes #113
  • Loading branch information
michael-o committed Apr 18, 2023
1 parent 997f1e4 commit 7efb92f
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 8 deletions.
18 changes: 18 additions & 0 deletions src/it/MCHECKSTYLE-432/invoker.properties
Original file line number Diff line number Diff line change
@@ -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
90 changes: 90 additions & 0 deletions src/it/MCHECKSTYLE-432/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
26 changes: 26 additions & 0 deletions src/it/MCHECKSTYLE-432/src/main/java/org/MyClass.java
Original file line number Diff line number Diff line change
@@ -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 {
}
25 changes: 25 additions & 0 deletions src/it/MCHECKSTYLE-432/src/main/java/org/package.html
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ public void executeReport( Locale locale )
// 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 ) )
Expand All @@ -515,21 +516,22 @@ public void executeReport( Locale locale )
{
throw new MavenReportException( e.getMessage(), e );
}
configLocation = rulesFiles.getAbsolutePath();
effectiveConfigLocation = rulesFiles.getAbsolutePath();
}
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();

try
{
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 =
Expand Down Expand Up @@ -725,7 +727,7 @@ private String getCopyright()
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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected CheckstyleExecutorRequest createRequest()
.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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected CheckstyleExecutorRequest createRequest()
.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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ public void execute()

if ( !skipExec )
{
String effectiveConfigLocation = configLocation;
if ( checkstyleRules != null )
{
if ( !DEFAULT_CONFIG_LOCATION.equals( configLocation ) )
Expand All @@ -517,7 +518,7 @@ public void execute()
{
throw new MojoExecutionException( e.getMessage(), e );
}
configLocation = rulesFiles.getAbsolutePath();
effectiveConfigLocation = rulesFiles.getAbsolutePath();
}

ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
Expand All @@ -535,7 +536,7 @@ public void execute()
.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" ) )
Expand Down

0 comments on commit 7efb92f

Please sign in to comment.