[ 
https://jira.codehaus.org/browse/MCHECKSTYLE-163?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Herve Boutemy updated MCHECKSTYLE-163:
--------------------------------------

    Description: 
When includeTestSourceDirectory=true is set for maven-checkstyle-plugin, the 
full test classpath should be made available to checkstyle.  Patch included to 
resolve issue by setting @requiresDependencyResolution to test.

In DefaultCheckstyleExecutor.java the checker.setClassLoader() is configured 
using the classpath string from request.getProject().getTestClasspathElements() 
(see DefaultCheckstyleExecutor line 114).

However, the CheckstyleViolationCheckMojo only has 
@requiresDependencyResolution compile which means that pom dependencies which 
have been declared as <scope>test</scope> are not returned by 
project.getTestClasspathElements().

This is a particular issue for the checkstyle RedundantThrows check 
(http://checkstyle.sourceforge.net/config_coding.html#RedundantThrows) as it 
requires all Exceptions to be available on it's classpath.

If code throws an Exception which has been imported from a maven 
<scope>test</scope> dependency, the exception will not be available on the 
classpath and this checkstyle check will fail.

Example:

Include junit as a test scope dependency in the project POM:
{code:xml}<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>${junit.version}</version>
  <scope>test</scope>
</dependency>{code}

Throw any junit exception within project test code, e.g.:
{code:java}public class MyCustomTestRunner extends BlockJUnit4ClassRunner {
        public MyCustomTestRunner(final Class<?> klass) throws 
InitializationError {
{code}
If RedundantThrows check is enabled, the following error will be thrown:
{noformat}[INFO] --- maven-checkstyle-plugin:2.7-SNAPSHOT:check 
(checkstyle-verify) @ sample-project ---
[INFO] Starting audit...
C:\Working\hg\sample-project\src\test\java\com\sample\support\junit\MyCustomTestRunner.java:28:72:
 warning: Unable to get class information for InitializationError.
Audit done.

[ERROR] MyCustomTestRunner.java[28:72] Unable to get class information for 
InitializationError.{noformat}



  was:
When includeTestSourceDirectory=true is set for maven-checkstyle-plugin, the 
full test classpath should be made available to checkstyle.  Patch included to 
resolve issue by setting @requiresDependencyResolution to test.

In DefaultCheckstyleExecutor.java the checker.setClassLoader() is configured 
using the classpath string from request.getProject().getTestClasspathElements() 
(see DefaultCheckstyleExecutor line 114).

However, the CheckstyleViolationCheckMojo only has 
@requiresDependencyResolution compile which means that pom dependencies which 
have been declared as <scope>test</scope> are not returned by 
project.getTestClasspathElements().

This is a particular issue for the checkstyle RedundantThrows check 
(http://checkstyle.sourceforge.net/config_coding.html#RedundantThrows) as it 
requires all Exceptions to be available on it's classpath.

If code throws an Exception which has been imported from a maven 
<scope>test</scope> dependency, the exception will not be available on the 
classpath and this checkstyle check will fail.

Example:

Include junit as a test scope dependency in the project POM:
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>${junit.version}</version>
  <scope>test</scope>
</dependency>

Throw any junit exception within project test code, e.g.:
public class MyCustomTestRunner extends BlockJUnit4ClassRunner {
        public MyCustomTestRunner(final Class<?> klass) throws 
InitializationError {

If RedundantThrows check is enabled, the following error will be thrown:
[INFO] --- maven-checkstyle-plugin:2.7-SNAPSHOT:check (checkstyle-verify) @ 
sample-project ---
[INFO] Starting audit...
C:\Working\hg\sample-project\src\test\java\com\sample\support\junit\MyCustomTestRunner.java:28:72:
 warning: Unable to get class information for InitializationError.
Audit done.

[ERROR] MyCustomTestRunner.java[28:72] Unable to get class information for 
InitializationError.




> Test classpath resolution fails in mvn check:check when 
> includeTestSourceDirectory = true
> -----------------------------------------------------------------------------------------
>
>                 Key: MCHECKSTYLE-163
>                 URL: https://jira.codehaus.org/browse/MCHECKSTYLE-163
>             Project: Maven Checkstyle Plugin
>          Issue Type: Bug
>    Affects Versions: 2.6
>            Reporter: Chris Whelan
>            Assignee: Olivier Lamy
>             Fix For: 2.7
>
>         Attachments: MCHECKSTYLE-163.zip, resolveTestClasspath.patch
>
>
> When includeTestSourceDirectory=true is set for maven-checkstyle-plugin, the 
> full test classpath should be made available to checkstyle.  Patch included 
> to resolve issue by setting @requiresDependencyResolution to test.
> In DefaultCheckstyleExecutor.java the checker.setClassLoader() is configured 
> using the classpath string from 
> request.getProject().getTestClasspathElements() (see 
> DefaultCheckstyleExecutor line 114).
> However, the CheckstyleViolationCheckMojo only has 
> @requiresDependencyResolution compile which means that pom dependencies which 
> have been declared as <scope>test</scope> are not returned by 
> project.getTestClasspathElements().
> This is a particular issue for the checkstyle RedundantThrows check 
> (http://checkstyle.sourceforge.net/config_coding.html#RedundantThrows) as it 
> requires all Exceptions to be available on it's classpath.
> If code throws an Exception which has been imported from a maven 
> <scope>test</scope> dependency, the exception will not be available on the 
> classpath and this checkstyle check will fail.
> Example:
> Include junit as a test scope dependency in the project POM:
> {code:xml}<dependency>
>   <groupId>junit</groupId>
>   <artifactId>junit</artifactId>
>   <version>${junit.version}</version>
>   <scope>test</scope>
> </dependency>{code}
> Throw any junit exception within project test code, e.g.:
> {code:java}public class MyCustomTestRunner extends BlockJUnit4ClassRunner {
>       public MyCustomTestRunner(final Class<?> klass) throws 
> InitializationError {
> {code}
> If RedundantThrows check is enabled, the following error will be thrown:
> {noformat}[INFO] --- maven-checkstyle-plugin:2.7-SNAPSHOT:check 
> (checkstyle-verify) @ sample-project ---
> [INFO] Starting audit...
> C:\Working\hg\sample-project\src\test\java\com\sample\support\junit\MyCustomTestRunner.java:28:72:
>  warning: Unable to get class information for InitializationError.
> Audit done.
> [ERROR] MyCustomTestRunner.java[28:72] Unable to get class information for 
> InitializationError.{noformat}



--
This message was sent by Atlassian JIRA
(v6.1.6#6162)

Reply via email to