Ignore javacc code in coverage report (#5241)

Merge pull request #5241 from Monits:ignore-javacc-code
This commit is contained in:
Andreas Dangel 2024-10-03 20:30:41 +02:00
commit b7c4a5e492
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
4 changed files with 38 additions and 7 deletions

View File

@ -37,6 +37,7 @@ The old rule names still work but are deprecated.
### ✨ Merged pull requests
* [#4965](https://github.com/pmd/pmd/pull/4965): \[java] Rename JUnit rules with overly restrictive names - [Juan Martín Sotuyo Dodero](https://github.com/jsotuyod) (@jsotuyod)
* [#5241](https://github.com/pmd/pmd/pull/5241): \Ignore javacc code in coverage report - [Juan Martín Sotuyo Dodero](https://github.com/jsotuyod) (@jsotuyod)
{% endtocmaker %}

View File

@ -224,6 +224,9 @@
<target name="cleanup-parser" unless="jjtreeBuildNotRequired">
<replace token="class ${parser-name}" value='@net.sourceforge.pmd.annotation.Generated("org.javacc.javacc")${line.separator}class ${parser-name}'>
<file name="${parser-file}" />
</replace>
<replace token="new Token()" value="token_source.input_stream.getTokenDocument().open()">
<file name="${parser-file}" />
@ -262,7 +265,8 @@
<replaceregexp>
<regexp pattern="public interface"/>
<substitution expression="interface"/>
<substitution expression='@net.sourceforge.pmd.annotation.Generated("org.javacc.javacc")${line.separator}
interface'/>
<file name="${target-package-dir}/${parser-name}TreeConstants.java" />
</replaceregexp>
@ -272,7 +276,8 @@
<replaceregexp>
<regexp pattern='(public )?class ${tokenmgr-name}' />
<substitution expression='class ${tokenmgr-name} extends ${base-tokenmgr}' />
<substitution expression='@net.sourceforge.pmd.annotation.Generated("org.javacc.javacc")${line.separator}
class ${tokenmgr-name} extends ${base-tokenmgr}' />
<file name="${tokenmgr-file}" />
</replaceregexp>
@ -385,11 +390,12 @@
<replaceregexp>
<regexp pattern="(public )?interface ${constants-itf-name} \{" />
<substitution expression="/** Token kinds ({@link ${ast-impl-package}.JavaccToken#kind}) for this language. */${line.separator}
<substitution expression='/** Token kinds ({@link ${ast-impl-package}.JavaccToken#kind}) for this language. */${line.separator}
@net.sourceforge.pmd.annotation.InternalApi${line.separator}
@net.sourceforge.pmd.annotation.Generated("org.javacc.javacc")${line.separator}
public final class ${token-constants-name} \{${line.separator}
private ${token-constants-name}() { /* Utility class */ }${line.separator}
"/>
'/>
<file name="${token-constants-file}" />
</replaceregexp>
@ -534,8 +540,9 @@ public final class ${token-constants-name} \{${line.separator}
<target name="default-visitor" depends="jjtree" unless="jjtreeBuildNotRequired">
<move file="${target-package-dir}/${gen-visitor-name}.java" tofile="${generic-visitor-interface-file}" />
<replace file="${generic-visitor-interface-file}">
<replacefilter token="${gen-visitor-name}"
value="${generic-visitor-interface-name}&lt;P, R> extends ${ast-api-package}.AstVisitor&lt;P, R>" />
<replacefilter token="public interface ${gen-visitor-name}"
value='@net.sourceforge.pmd.annotation.Generated("org.javacc.javacc")${line.separator}
public interface ${generic-visitor-interface-name}&lt;P, R> extends ${ast-api-package}.AstVisitor&lt;P, R>' />
<replacefilter token="SimpleNode" value="${node-name}" />
<!-- Root method, eg visitJavaNode -->

View File

@ -0,0 +1,23 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Marks a class as generated code, and therefore to be ignored for code coverage purposes.
*
* @since 7.6.0
*/
@Retention(RetentionPolicy.CLASS)
@Documented
public @interface Generated {
/** The generator that produced this code */
String value() default "";
}

View File

@ -611,7 +611,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<version>0.8.12</version>
</plugin>
<plugin>
<groupId>org.cyclonedx</groupId>