Skip to content

Issue #11816: Added windows cmd script for git-diff validation#13696

Merged
nrmancuso merged 1 commit into
checkstyle:masterfrom
kalpadiptyaroy:windows-cmd-validations-script
Oct 28, 2023
Merged

Issue #11816: Added windows cmd script for git-diff validation#13696
nrmancuso merged 1 commit into
checkstyle:masterfrom
kalpadiptyaroy:windows-cmd-validations-script

Conversation

@kalpadiptyaroy

@kalpadiptyaroy kalpadiptyaroy commented Sep 4, 2023

Copy link
Copy Markdown
Contributor

Issue #11816: Added cmd script for git-diff validation for windows environment

@kalpadiptyaroy kalpadiptyaroy force-pushed the windows-cmd-validations-script branch from 1b02881 to b3d1666 Compare September 4, 2023 18:49

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For testing , create second commit for same PR where you remove any ord at


It should trigger git diff after mvn test

Items to improve:

Comment thread appveyor.yml Outdated
Comment thread .ci/validation.cmd Outdated
@kalpadiptyaroy kalpadiptyaroy force-pushed the windows-cmd-validations-script branch from b3d1666 to 45b3c57 Compare September 5, 2023 18:24
@kalpadiptyaroy

Copy link
Copy Markdown
Contributor Author

For testing , create second commit for same PR where you remove any ord at

It should trigger git diff after mvn test
Items to improve:

Done

Comment thread appveyor.yml Outdated
@romani

romani commented Sep 6, 2023

Copy link
Copy Markdown
Member

CI does not like your update https://ci.appveyor.com/project/Checkstyle/checkstyle/builds/47962839

please show textual copy of terminal output from your local to show how it works, you can change any file you want (without commit) and run a script. Two outputs are required with error and without error. Please also show that in case of diff script return error code to let CI fail.

@kalpadiptyaroy kalpadiptyaroy force-pushed the windows-cmd-validations-script branch from aa0bb09 to 043454b Compare September 6, 2023 17:35
@kalpadiptyaroy

Copy link
Copy Markdown
Contributor Author

CI does not like your update https://ci.appveyor.com/project/Checkstyle/checkstyle/builds/47962839

please show textual copy of terminal output from your local to show how it works, you can change any file you want (without commit) and run a script. Two outputs are required with error and without error. Please also show that in case of diff script return error code to let CI fail.

I am trying out something. If it doesn't work. I will do as per your suggestion

@kalpadiptyaroy kalpadiptyaroy force-pushed the windows-cmd-validations-script branch 2 times, most recently from 328c45a to 53fb91f Compare September 7, 2023 15:51
@kalpadiptyaroy

Copy link
Copy Markdown
Contributor Author

@romani. This is the output you asked for.

D:\opensource\project-checkstyle\checkstyle>".ci/validation.cmd" git_diff
Please clean up or update .gitattributes file.
Git status output:    
Top 300 lines of diff:
[1]diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/ArrayTypeStyleCheck.xml b/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/ArrayTypeStyleCheck.xml
[2]index 124bf3c13..5698bd438 100644
[3]--- a/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/ArrayTypeStyleCheck.xml
[4]+++ b/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/ArrayTypeStyleCheck.xml
[5]@@ -5,7 +5,7 @@
[6]              name="ArrayTypeStyle"
[7]              parent="com.puppycrawl.tools.checkstyle.TreeWalker">
[8]          <description>&lt;p&gt;
[9]- Checks the style of array type definitions for test.
[10]+ Checks the style of array type definitions.
[11]  Some like Java style: {@code public static void main(String[] args)}
[12]  and some like C style: {@code public static void main(String args[])}.
[13]  &lt;/p&gt;
validation failed with error code #-1.

D:\opensource\project-checkstyle\checkstyle>git status
On branch windows-cmd-validations-script
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/ArrayTypeStyleCheck.xml

no changes added to commit (use "git add" and/or "git commit -a")

D:\opensource\project-checkstyle\checkstyle>git checkout -- .

D:\opensource\project-checkstyle\checkstyle>git status
On branch windows-cmd-validations-script
nothing to commit, working tree clean

D:\opensource\project-checkstyle\checkstyle>".ci/validation.cmd" git_diff
Please clean up or update .gitattributes file.
Git status output:
Top 300 lines of diff:
validation failed with error code #-1.

D:\opensource\project-checkstyle\checkstyle>

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Items

Comment thread appveyor.yml Outdated
@kalpadiptyaroy kalpadiptyaroy force-pushed the windows-cmd-validations-script branch 2 times, most recently from 22fb982 to 557833b Compare September 9, 2023 15:12
@romani

romani commented Sep 9, 2023

Copy link
Copy Markdown
Member

https://ci.appveyor.com/project/Checkstyle/checkstyle/builds/47995477/job/k9s9pby4sq58vbfl#L339

[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:55 min
[INFO] Finished at: 2023-09-09T15:18:55Z
[INFO] ------------------------------------------------------------------------
CMD exited with exit code 0
./.ci/validation.cmd git_diff
validation failed with error code #1.
Command exited with code 1

lets improve error message to make it clear for any new contributor on what is wrong and what should be fixed.

please make it something like this:

./.ci/validation.cmd git_diff
There is git changes after execution of job:
<print whole diff as is> 
There should be no changes in git repository after any CI job/task
validation failed with error code #1.

@kalpadiptyaroy

Copy link
Copy Markdown
Contributor Author

https://ci.appveyor.com/project/Checkstyle/checkstyle/builds/47995477/job/k9s9pby4sq58vbfl#L339

[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:55 min
[INFO] Finished at: 2023-09-09T15:18:55Z
[INFO] ------------------------------------------------------------------------
CMD exited with exit code 0
./.ci/validation.cmd git_diff
validation failed with error code #1.
Command exited with code 1

lets improve error message to make it clear for any new contributor on what is wrong and what should be fixed.

please make it something like this:

./.ci/validation.cmd git_diff
There is git changes after execution of job:
<print whole diff as is> 
There should be no changes in git repository after any CI job/task
validation failed with error code #1.

Sure. On it. Will be pushing changes soon!

@kalpadiptyaroy kalpadiptyaroy force-pushed the windows-cmd-validations-script branch 4 times, most recently from 4d3b72d to 88b382e Compare September 10, 2023 08:37

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it should be failed on first job - https://ci.appveyor.com/project/Checkstyle/checkstyle/builds/47997876/job/d8kr55f48af3um3j#L344 , but it is not failed. it is not validation that is not chaning files - all good.

Items

Comment thread appveyor.yml Outdated
@kalpadiptyaroy kalpadiptyaroy force-pushed the windows-cmd-validations-script branch 2 times, most recently from fdac749 to 044e832 Compare September 10, 2023 13:25
@kalpadiptyaroy

Copy link
Copy Markdown
Contributor Author

it should be failed on first job - https://ci.appveyor.com/project/Checkstyle/checkstyle/builds/47997876/job/d8kr55f48af3um3j#L344 , but it is not failed.

Items

@romani
https://ci.appveyor.com/project/Checkstyle/checkstyle/builds/47998600/job/32id656n29ij6ip3

Have a look. I made some changes and now its failing in appveyor. Kindly check if it meets the expectations.

@romani

romani commented Sep 10, 2023

Copy link
Copy Markdown
Member

https://ci.appveyor.com/project/Checkstyle/checkstyle/builds/47998600/job/32id656n29ij6ip3#L1862 this is supper scary failure that is hard to understand even for me.

can we avoid this warning on line ends?

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

item

Comment thread .ci/validation.cmd
@kalpadiptyaroy

kalpadiptyaroy commented Sep 10, 2023

Copy link
Copy Markdown
Contributor Author

https://ci.appveyor.com/project/Checkstyle/checkstyle/builds/47998600/job/32id656n29ij6ip3#L1862 this is supper scary failure that is hard to understand even for me.

can we avoid this warning on line ends?

Actually, these warnings are generated because the mvn build OR git is somehow modifying the EOF characters from CRLF to LF. I am not sure, how to handle these warnings as of now.

But I feel that something similar to issue #8884 is happening here!

If you can provide me some hints and clues. I might try them out!

@kalpadiptyaroy kalpadiptyaroy force-pushed the windows-cmd-validations-script branch 2 times, most recently from 147da08 to 3a36615 Compare September 10, 2023 14:28
@kalpadiptyaroy kalpadiptyaroy force-pushed the windows-cmd-validations-script branch from 8c39cfe to a0d7c33 Compare October 8, 2023 18:15
@kalpadiptyaroy

Copy link
Copy Markdown
Contributor Author

Done

@rnveach rnveach left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PR is blocked by CI until #13774 .

@romani

romani commented Oct 23, 2023

Copy link
Copy Markdown
Member

@kalpadiptyaroy, please remove second commit and rebase, we are very close to finish line.

@kalpadiptyaroy kalpadiptyaroy force-pushed the windows-cmd-validations-script branch 2 times, most recently from a0d7c33 to d9e9461 Compare October 23, 2023 13:40
@romani

romani commented Oct 23, 2023

Copy link
Copy Markdown
Member

Hmm, we still have problems with line endings
https://ci.appveyor.com/project/Checkstyle/checkstyle/builds/48344118/job/kpdxe2nvufjol2dv#L1866

Did we missed something ?

@kalpadiptyaroy

kalpadiptyaroy commented Oct 23, 2023

Copy link
Copy Markdown
Contributor Author

@romani - Yes, we did miss!

I debugged the entire process once again and the findings are following.

See the XdocTemplateSink class calls the writeEOL func. as shown below.

public void body() {
write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>");
writeEOL();
}

Going into writeEOL we can see a chain of calls to the write(String) func. that bottoms out to:
https://github.com/apache/maven-doxia/blob/e2ae1195cc28d70f6f74c5aed5384b031dc92933/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSink.java#L2006-L2014

Now the write(String) func that is taking the unified EOL string is finally implemented as: https://github.com/openjdk/jdk/blob/8d9a4b43f4fff30fd217dab2c224e641cb913c18/src/java.base/share/classes/java/io/PrintWriter.java#L634-L636
AND
https://github.com/openjdk/jdk/blob/8d9a4b43f4fff30fd217dab2c224e641cb913c18/src/java.base/share/classes/java/io/PrintWriter.java#L602-L616

So final conclusion is we should have overriden write(String) func of PrintWriter as follows rather than the println() func. because println is never used in this case.

@Override
public void write(String x) {
      ...... // use replace func or another logic to convert all \r\n and \r to \n
}

@kalpadiptyaroy

kalpadiptyaroy commented Oct 23, 2023

Copy link
Copy Markdown
Contributor Author

Also, I am quite surprised that Apache Doxia is only using write func to do everything and it is not utilizing the other Writer functions such as println or print.

Now we have to come to concrete decision. Since we are left with 2 ways.

  1. Re-open issue Enforce Linux Style End-of-Line (LF instead of CRLF) in all XML files for windows environment. #13770 and override write func. in CustomPrintWriter. OR
  2. We have to ask Doxia community to change their entire code structure to utilize the respective functions of Writer in a systematic way.

Let me know your thoughts!

I know option 1 is the easiest as of now - but still other maintainers' opinion also matters!

@romani

romani commented Oct 23, 2023

Copy link
Copy Markdown
Member

Issue is reopened on our side.
Let's do what we need now to make it work and do not wait for doxia to change code.

We can share feedback at https://issues.apache.org/jira/browse/DOXIA-707 for them to improve.

@kalpadiptyaroy

Copy link
Copy Markdown
Contributor Author

Issue is reopened on our side. Let's do what we need now to make it work and do not wait for doxia to change code.

Cool

@kalpadiptyaroy

Copy link
Copy Markdown
Contributor Author

@romani - Its working after cherry picking the #13947 commit here.

@romani

romani commented Oct 24, 2023

Copy link
Copy Markdown
Member

All CIs are green, confirmed.
https://ci.appveyor.com/project/Checkstyle/checkstyle/builds/48355264

Please remove commit.

@kalpadiptyaroy kalpadiptyaroy force-pushed the windows-cmd-validations-script branch 3 times, most recently from 5c674df to 937f27f Compare October 25, 2023 13:42
@kalpadiptyaroy

Copy link
Copy Markdown
Contributor Author

Appveyor Test is passed. We are good to merge.

Only closed issue reference check has failed. I don't know why.
@romani - can this be ignored?

@romani romani force-pushed the windows-cmd-validations-script branch from 1e42650 to 284bd1d Compare October 25, 2023 15:40
@romani

romani commented Oct 25, 2023

Copy link
Copy Markdown
Member

@rnveach , please finalize review

@romani romani removed the blocked label Oct 25, 2023
Comment thread .ci/validation.cmd
)

if "%OPTION%" == "git_diff" (
for /f "delims=" %%a in ('git status ^| findstr /c:"Changes not staged"') do set output=%%a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just pointing out that this command relies on the english locale.

@kalpadiptyaroy kalpadiptyaroy Oct 26, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So is there any locale compliance that I haven't complied with?

I have tried to keep it at par with

https://github.com/checkstyle/checkstyle/blob/master/.ci/validation.sh#L1078-L1086

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have a lot of scripts that rely on English locale. We can presume for now that CI will be English only for next few years for sure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok. Let's merge then.

@rnveach rnveach assigned nrmancuso and unassigned rnveach Oct 26, 2023
@nrmancuso nrmancuso merged commit 281fd0e into checkstyle:master Oct 28, 2023
@nrmancuso

Copy link
Copy Markdown
Contributor

@kalpadiptyaroy thanks for all your work on this, it is a big win for windows users.

@kalpadiptyaroy

Copy link
Copy Markdown
Contributor Author

@kalpadiptyaroy thanks for all your work on this, it is a big win for windows users.

Welcome Nick. This appreciation is a great motivation for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants