raydac / java-comment-preprocessor

preprocessor for computer languages with C-like comment format (C/C++/Java/Go)
Apache License 2.0
172 stars 27 forks source link

jcp removes comments even if /r is not specified #24

Closed ndw closed 3 years ago

ndw commented 3 years ago

I've been upgrading some code in a project. It had been using jcp 5.3.2 and when I upgraded to 7.0.3, I discovered that comments were being stripped out even though the "r" option was not specified.

I tried a few versions up to 6.1.4 and confirmed that this behavior first appears in 7.0.0.

raydac commented 3 years ago

could you provide example of comments which were removed? do you use jcp directly or as a plugin for ant/maven/gradle process?

ndw commented 3 years ago

I want to have more than one preprocess step and that doesn't appear (from my position of relative gradle ignorance) to be possible, so I'm just running it directly as a JavaExec step.

I put the attached file (renamed to .txt to make GitHub uploading happy) in /tmp/x/src and run this command:

$ java -jar ~/.gradle/caches/modules-2/files-2.1/com.igormaznitsa/jcp/6.1.4/3cfbec66a0d86bc5b62a8b02e65c6a388c5ed3fc/jcp-6.1.4.jar /c /i:/tmp/x/src /o:/tmp/x/out /p:TEST=false
Java Comment Preprocessor v 6.1.4
Project page: https://github.com/raydac/java-comment-preprocessor
2003-2017 Author: Igor A. Maznitsa (igor.maznitsa@igormaznitsa.com)
[JCP.INFO] -----------------------------------------------------------------
[JCP.INFO] Completed, preprocessed 1 files, copied 0 files, elapsed time 34ms

The resulting file in /tmp/x/out has comments. If I run the same command with version 7:

$ java -jar ~/.gradle/caches/modules-2/files-2.1/com.igormaznitsa/jcp/7.0.3/a23fece25fb6b6764a4e71cdab77b646d73565db/jcp-7.0.3.jar /c /i:/tmp/x/src /o:/tmp/x/out /p:TEST=false
Java Comment Preprocessor v7.0.3a
Project page: https://github.com/raydac/java-comment-preprocessor
Copyright (C) 2002-2020 Igor A. Maznitsa (https://www.igormaznitsa.com)
Base directory: /Users/ndw/.gradle/caches/modules-2/files-2.1/com.igormaznitsa/jcp/7.0.3/a23fece25fb6b6764a4e71cdab77b646d73565db/jcp-7.0.3.jar
[JCP.INFO] File extensions: [htm, txt, java, html] excluded [xml]
[JCP.INFO] -----------------------------------------------------------------
[JCP.INFO] Preprocessed 1 files, copied 0 files, ignored 0 files, elapsed time 29 ms

the resulting file in /tmp/x/out does not have any comments.

SampleClass.txt

raydac commented 3 years ago

yes, you're right, I will fix

raydac commented 3 years ago

thanks for the report, exactly the keep comments flag in the pre-processor context was false by default you can try fixed pre-built version https://github.com/raydac/java-comment-preprocessor/releases/tag/7.0.4-S

ndw commented 3 years ago

👍 works for me

raydac commented 3 years ago

I made maintenance release 7.0.4 with the fix