Skip to content
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

Add regex for line comparison #243

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

cns-solutions-admin
Copy link

This solves #242 by adding a new optional regex to compare the lines other than the first for multiline headers.

@cns-solutions-admin
Copy link
Author

Also converts a inline header style's name to lower case, otherwise the comparison (and the example in the docs) fails.

* In maven/xml we need xml:space="preserve" to prevent trimming of text values.
* The XML attribute is multiline, not isMultiline.
* inline styles are only available in version 4.2 - we should note this, as the suggested version is 4.1.
* the inline example does only work, if the inline style name is lowercase. code fixed in previous PR.
@mathieucarbou
Copy link
Owner

Hello,
Why changing the header definition didn't work for your use case ?

@mathieucarbou mathieucarbou added in:core MLP core module is:enhancement Enhancement to an existing feature todo Accepted items from the backlog which can be worked on labels Nov 26, 2021
@cns-solutions-admin
Copy link
Author

Changing the header definition did not work, because the detection of header lines was orginally done by comparing lines with startsWith(beforeEachLine.rtrim())
the old " * something" does not start with "**".

By introducing a (optional) RegEx for the header lines, this and most other use cases can be covered.
It also fits with the current configuration, where we already have RegExs for start and end line.

Copy link
Owner

@mathieucarbou mathieucarbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also squash and rebase. Thanks 👍

docs/index.md Outdated
<afterEachLine></afterEachLine>
<!--skipLine></skipLine-->
<firstLineDetectionPattern>(\s|\t)*/\*.*$</firstLineDetectionPattern>
<lastLineDetectionPattern>.*\*/(\s|\t)*$</lastLineDetectionPattern>
<allowBlankLines>false</allowBlankLines>
<isMultiline>true</isMultiline>
<multiline>true</multiline>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove any change regarding multiline: I've correctly fixed in #247

@@ -34,6 +36,7 @@

private Pattern skipLinePattern;
private Pattern firstLineDetectionPattern;
private Pattern otherLineDetectionPattern;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that the name is called middleLineDetectionPattern

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except it is for all lines except the first line - the last line must also pass this pattern (or the beforeEachLine test).
Finding the best name is often the most difficult task ;-)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the last line must also pass this pattern

Why ? There is a pattern for the last line.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the code still checks beforeEachLine. I didn't want to change the logic and the RegEx happens when the startsWith(beforeEachLine) check happens.

@@ -209,6 +257,7 @@ public void validate() {
check("endLine", this.endLine);
check("afterEachLine", this.afterEachLine);
check("firstLineDetectionPattern", this.firstLineDetectionPattern);
// other line detection pattern can be null
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for this comment: it's like beforeEachLine ;-)

final HeaderDefinition headerDefinition = new HeaderDefinition(
"javadoc2_style", "/**", " ** ", " **/", "", null, "^\\s*/\\*.*$", "^\\s*\\*.*$", "^.*\\*/\\s*$", false, true, false);
return new HeaderParser(new FileContent(new File(fileName), System.getProperty("file.encoding")), headerDefinition, new String[]{"copyright"});
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would need also to have a more complete test (like CompleteMojoTest does) to also test the other plugin actions, like really testing the issue you want to fix.

this(type);
this.firstLine = firstLine;
this.beforeEachLine = beforeEachLine;
this.endLine = endLine;
this.afterEachLine = afterEachLine;
this.skipLinePattern = compile(skipLinePattern);
this.firstLineDetectionPattern = compile(firstLineDetectionPattern);
this.otherLineDetectionPattern = compile(otherLineDetectionPattern);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you would need to update setPropertyFromString(...) too for xml header definition.

@mathieucarbou mathieucarbou modified the milestones: 4.3, 4.2 Nov 26, 2021
@mathieucarbou mathieucarbou added is:bug Bugs to fix and removed is:enhancement Enhancement to an existing feature labels Nov 26, 2021
@mathieucarbou mathieucarbou modified the milestones: 4.2, 4.3 Mar 23, 2023
@hazendaz hazendaz modified the milestones: 4.4, 4.5 Jan 20, 2024
@mathieucarbou mathieucarbou removed this from the 4.5 milestone May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in:core MLP core module is:bug Bugs to fix todo Accepted items from the backlog which can be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Header is added instead of being replaced, if formats differ
3 participants