GeezerVison is showing github.com — Issue #18556: updating multifileregexpheader and adding external xml … by ZaheerAhmadDev · Pull Request #18802 · checkstyle/checkstyle
Issue #18556: updating multifileregexpheader and adding external xml …
#18802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.java
(5)
.template
(1)
.xml
(4)
All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -63,16 +63,19 @@ public class Example1 { }
</code></pre></div>
<hr class="example-separator"/>
<p id="Example2-config ">
<p id="Example2-raw ">
To configure the check to use multiple header files:
</p>
<div class="wrapper"><pre class="prettyprint"><code class="language-xml">
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="MultiFileRegexpHeader">
<property name="fileExtensions" value="java"/>
<property name="headerFiles" value="${config.folder}/java.header,
${config.folder}/apache.header"/>
</module>
<module name="MultiFileRegexpHeader">
<property name="fileExtensions" value="java"/>
<property name="headerFiles" value="${config.folder}/java.header, ${config.folder}/apache.header"/>
</module>
</module>
</code></pre></div>
Expand All
@@ -99,17 +102,20 @@ public class Example2 { }
</code></pre></div>
<hr class="example-separator"/>
<p id="Example3-config ">
<p id="Example3-raw ">
To configure the check to verify that each file starts with one of
multiple headers.
</p>
<div class="wrapper"><pre class="prettyprint"><code class="language-xml">
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="MultiFileRegexpHeader">
<property
name="headerFiles" value="${config.folder}/java.header,
${config.folder}/apache.header"/>
</module>
<module name="MultiFileRegexpHeader">
<property name="headerFiles"
value="${config.folder}/java.header, ${config.folder}/apache.header"/>
</module>
</module>
</code></pre></div>
Expand All
@@ -121,10 +127,14 @@ public class Example3 { }
</code></pre></div>
<hr class="example-separator"/>
<p id="Example4-config ">
<p id="Example4-raw ">
For a configuration where any header is accepted:
</p>
<div class="wrapper"><pre class="prettyprint"><code class="language-xml">
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="MultiFileRegexpHeader">
<property
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -46,13 +46,13 @@
</macro>
<hr class="example-separator"/>
<p id="Example2-config ">
<p id="Example2-raw ">
To configure the check to use multiple header files:
</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/checks/header/multifileregexpheader/Example2.java "/>
<param name="type" value="config "/>
value="resources/com/puppycrawl/tools/checkstyle/checks/header/multifileregexpheader/Example2.xml "/>
<param name="type" value="raw "/>
</macro>
<p id="java-raw">content of <code>java.header</code> file:</p>
Expand All
@@ -77,14 +77,14 @@
</macro>
<hr class="example-separator"/>
<p id="Example3-config ">
<p id="Example3-raw ">
To configure the check to verify that each file starts with one of
multiple headers.
</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/checks/header/multifileregexpheader/Example3.java "/>
<param name="type" value="config "/>
value="resources/com/puppycrawl/tools/checkstyle/checks/header/multifileregexpheader/Example3.xml "/>
<param name="type" value="raw "/>
</macro>
<p id="Example3-code">Example3:</p>
Expand All
@@ -95,13 +95,13 @@
</macro>
<hr class="example-separator"/>
<p id="Example4-config ">
<p id="Example4-raw ">
For a configuration where any header is accepted:
</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/checks/header/multifileregexpheader/Example4.java "/>
<param name="type" value="config "/>
value="resources/com/puppycrawl/tools/checkstyle/checks/header/multifileregexpheader/Example4.xml "/>
<param name="type" value="raw "/>
</macro>
<p id="universal-raw">content of <code>universal.header</code> file:</p>
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -256,6 +256,28 @@ protected final void verifyWithInlineXmlConfig(String filePath, String... expect
verify(xmlConfig, filePath, expected);
}
/**
* Performs verification of the file with the given file path using configuration,
* loaded from an external XML resource and the array of expected messages.
*
* @param configPath path to the XML configuration resource.
* @param filePath file path to verify.
* @param expected an array of expected messages.
* @throws Exception if exception occurs during verification process.
*/
protected void verifyWithExternalXmlConfig(
String configPath,
String filePath,
String... expected)
throws Exception {
final Configuration config =
ConfigurationLoader.loadConfiguration(
configPath,
new PropertiesExpander(System.getProperties()),
ConfigurationLoader.IgnoredModulesOptions.EXECUTE);
verify(config, filePath, expected);
}
/**
* Performs verification of the file with the given file path using specified configuration
* and the array expected messages. Also performs verification of the config specified in
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -38,42 +38,47 @@ public void testExample1() throws Exception {
@Test
public void testExample2() throws Exception {
final String[] expected = {
"1: " + getCheckMessage(MultiFileRegexpHeaderCheck.MSG_HEADER_MISMATCH,
"// Checkstyle - Java code style checker."
+ " Copyright (C) 20XX-20XX the authors.",
final String path =
"src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/header/"
+ "multifileregexpheader/java.header, "
+ "src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/header/"
+ "multifileregexpheader/apache.header"),
+ "multifileregexpheader/apache.header";
final String[] expected = {
"1: " + getCheckMessage(MultiFileRegexpHeaderCheck.MSG_HEADER_MISMATCH,
"// Checkstyle - Java code style checker."
+ " Copyright (C) 20XX-20XX the authors.", path),
};
System.setProperty("config.folder", "src/xdocs-examples/resources/" + getPackageLocation());
verifyWithInlineConfigParser(getPath("Example2.java"), expected);
verifyWithExternalXmlConfig(getPath("Example2.xml"),
getPath("Example2.java"),
expected);
}
@Test
public void testExample3() throws Exception {
final String[] expected = {
"1: " + getCheckMessage(MultiFileRegexpHeaderCheck.MSG_HEADER_MISMATCH,
"// Checkstyle - Java code style checker."
+ " Copyright (C) 20XX-20XX the authors.",
final String path =
"src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/header/"
+ "multifileregexpheader/java.header, "
+ "src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/header/"
+ "multifileregexpheader/apache.header"),
+ "multifileregexpheader/apache.header";
final String[] expected = {
"1: " + getCheckMessage(MultiFileRegexpHeaderCheck.MSG_HEADER_MISMATCH,
"// Checkstyle - Java code style checker."
+ " Copyright (C) 20XX-20XX the authors.", path),
};
System.setProperty("config.folder", "src/xdocs-examples/resources/" + getPackageLocation());
verifyWithInlineConfigParser(getPath("Example3.java"), expected);
verifyWithExternalXmlConfig(getPath("Example3.xml"),
getPath("Example3.java"),
expected);
}
@Test
public void testExample4() throws Exception {
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
System.setProperty("config.folder", "src/xdocs-examples/resources/" + getPackageLocation());
verifyWithInlineConfigParser(getPath("Example4.java"), expected);
verifyWithExternalXmlConfig(getPath("Example4.xml"),
getPath("Example4.java"),
expected);
}
}
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,9 @@
/*xml
<module name="Checker">
<module name="MultiFileRegexpHeader">
<property name="fileExtensions" value="java"/>
<property name="headerFiles" value="${config.folder}/java.header,
${config.folder}/apache.header"/>
</module>
</module>
*/
// xdoc section -- start
package com.puppycrawl.tools.checkstyle.checks.header.multifileregexpheader;
/* violation on first line 'Header mismatch, expected line content was' */
// because headerFile is bigger then target java file
public class Example2 { }
// xdoc section -- end
// violation 15 lines above 'Header mismatch, expected line content was'
// violation 8 lines above 'Header mismatch, expected line content was'
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="MultiFileRegexpHeader">
<property name="fileExtensions" value="java"/>
<property name="headerFiles" value="${config.folder}/java.header, ${config.folder}/apache.header"/>
</module>
</module>
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,8 @@
/*xml
<module name="Checker">
<module name="MultiFileRegexpHeader">
<property
name="headerFiles" value="${config.folder}/java.header,
${config.folder}/apache.header"/>
</module>
</module>
*/
// xdoc section -- start
package com.puppycrawl.tools.checkstyle.checks.header.multifileregexpheader;
/* violation on first line 'Header mismatch, expected line content was' */
public class Example3 { }
// xdoc section -- end
// violation 14 lines above 'Header mismatch, expected line content was'
Comment thread
ZaheerAhmadDev marked this conversation as resolved.
Resolved
Uh oh!
There was an error while loading. Please reload this page.
// violation 7 lines above 'Header mismatch, expected line content was'
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="MultiFileRegexpHeader">
<property name="headerFiles"
value="${config.folder}/java.header, ${config.folder}/apache.header"/>
</module>
</module>
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,4 @@
/*xml
<module name="Checker">
<module name="MultiFileRegexpHeader">
<property
name="headerFiles"
value="${config.folder}/universal.header"/>
</module>
</module>
*/
// xdoc section -- start
package com.puppycrawl.tools.checkstyle.checks.header.multifileregexpheader;
Expand Down
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="MultiFileRegexpHeader">
<property
name="headerFiles"
value="${config.folder}/universal.header"/>
</module>
</module>
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.