Skip to content

Skip file overwrite if output is identical #1

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

Closed
vlsi opened this issue Nov 28, 2015 · 20 comments
Closed

Skip file overwrite if output is identical #1

vlsi opened this issue Nov 28, 2015 · 20 comments
Assignees
Milestone

Comments

@vlsi
Copy link
Contributor

vlsi commented Nov 28, 2015

Currently java-comment-preprocessor always overwrites files, so java compiler always recompiles all the files.

Can JCP doublecheck if output is good enough and avoid file overwrites?

@raydac raydac self-assigned this Nov 28, 2015
@raydac
Copy link
Owner

raydac commented Nov 28, 2015

I think it is possible to implement such feature

@raydac raydac added this to the 6.0.1 milestone Nov 28, 2015
@vlsi
Copy link
Contributor Author

vlsi commented Nov 28, 2015

"maven-source-plugin" Invokes the execution of the lifecycle phase generate-sources prior to executing itself, thus if using maven-source-plugin and java-comment-preprocessor at the same time it forces maven to recompile the project twice.

@vlsi
Copy link
Contributor Author

vlsi commented Nov 28, 2015

By the way: I like how smooth JCP integration is.

I use it to support multiple JDK versions for PostgreSQL JDBC driver: pgjdbc/pgjdbc#435.
It's just very basic "comment out java.sql.SQLType usage for JDK<1.8" stuff, and I like how JCP keeps line numbers intact.

@raydac
Copy link
Owner

raydac commented Nov 28, 2015

I have added --z parameter into CLI and compareDestination into MAVEN and ANT f63d1ad
you can try the snapshot, now if into MAVEN add <compareDestination>true</compareDestination> then it will check content and will rewrite only if content is not the same

@vlsi
Copy link
Contributor Author

vlsi commented Nov 28, 2015

Do you mean snapshot version is deployed somewhere?
Or should I build it from the sources?

@raydac
Copy link
Owner

raydac commented Nov 28, 2015

you can build from sources or use brebuilt version https://drive.google.com/file/d/0BxHnNp97IgMRX05LZXNtbEVhZEE/view?usp=sharing

@vlsi
Copy link
Contributor Author

vlsi commented Nov 28, 2015

Thanks for the quick fix.
f63d1ad works for me.

[INFO] Preprocess sources : /Users/vladimirsitnikov/Documents/code/pgjdbc2/core/src/main/java
[INFO] Preprocess destination : /Users/vladimirsitnikov/Documents/code/pgjdbc2/core/target/gen-src
[INFO] -----------------------------------------------------------------
[INFO] Completed, preprocessed 158 files, copied 0 files, elapsed time 403ms
[INFO] A Compile source root has been removed from the root list [/Users/vladimirsitnikov/Documents/code/pgjdbc2/core/src/main/java]
[INFO] The New compile source root has been added into the list [/Users/vladimirsitnikov/Documents/code/pgjdbc2/core/target/gen-src]
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ postgresql ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 16 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ postgresql ---
[INFO] Nothing to compile - all classes are up to date

FYI: build without -DskipTests fails for me as follows:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.igormaznitsa.jcp.it.ant.ITAntTask
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.218 sec - in com.igormaznitsa.jcp.it.ant.ITAntTask
Running com.igormaznitsa.jcp.it.maven.ITPreprocessorMojo
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.073 sec <<< FAILURE! - in com.igormaznitsa.jcp.it.maven.ITPreprocessorMojo
com.igormaznitsa.jcp.it.maven.ITPreprocessorMojo  Time elapsed: 0.072 sec  <<< ERROR!
org.apache.maven.it.VerificationException:
Failed to execute Maven: Failed to run Maven: Error while executing process.
/Users/vladimirsitnikov/Programs/apache-maven-3.3.9/bin/mvn -Dfile=/Users/vladimirsitnikov/Documents/work/java-comment-preprocessor/target/jcp-6.0.1-SNAPSHOT.jar -DpomFile=/Users/vladimirsitnikov/Documents/work/java-comment-preprocessor/pom.xml -e --batch-mode -Dmaven.repo.local=/Users/vladimirsitnikov/.m2/repository org.apache.maven.plugins:maven-clean-plugin:clean install:install-file
    at com.igormaznitsa.jcp.it.maven.ITPreprocessorMojo.setUpBeforeClass(ITPreprocessorMojo.java:65)
Caused by: org.apache.maven.it.LauncherException:
Failed to run Maven: Error while executing process.
/Users/vladimirsitnikov/Programs/apache-maven-3.3.9/bin/mvn -Dfile=/Users/vladimirsitnikov/Documents/work/java-comment-preprocessor/target/jcp-6.0.1-SNAPSHOT.jar -DpomFile=/Users/vladimirsitnikov/Documents/work/java-comment-preprocessor/pom.xml -e --batch-mode -Dmaven.repo.local=/Users/vladimirsitnikov/.m2/repository org.apache.maven.plugins:maven-clean-plugin:clean install:install-file
    at com.igormaznitsa.jcp.it.maven.ITPreprocessorMojo.setUpBeforeClass(ITPreprocessorMojo.java:65)
Caused by: org.apache.maven.it.util.cli.CommandLineException: Error while executing process.
    at com.igormaznitsa.jcp.it.maven.ITPreprocessorMojo.setUpBeforeClass(ITPreprocessorMojo.java:65)
Caused by: java.io.IOException: Cannot run program "/Users/vladimirsitnikov/Programs/apache-maven-3.3.9/bin/mvn" (in directory "/Users/vladimirsitnikov/Documents/work/java-comment-preprocessor/target/test-classes/com/igormaznitsa/jcp/it/maven/dummy_maven_project"): error=2, No such file or directory
    at com.igormaznitsa.jcp.it.maven.ITPreprocessorMojo.setUpBeforeClass(ITPreprocessorMojo.java:65)
Caused by: java.io.IOException: error=2, No such file or directory
    at com.igormaznitsa.jcp.it.maven.ITPreprocessorMojo.setUpBeforeClass(ITPreprocessorMojo.java:65)


Results :

Tests in error:
  ITPreprocessorMojo.setUpBeforeClass:65 » Verification Failed to execute Maven:...

@raydac
Copy link
Owner

raydac commented Nov 28, 2015

the plug-in has a bit bizarre build process and you should have maven distributive on your machine and the way to the distributive should be directly placed into maven.home property in the pom.xml, it starts maven during integration tests
if for some time there are not new issues then I will publish the plugin in the maven central

@vlsi
Copy link
Contributor Author

vlsi commented Nov 28, 2015

I see.

I just did a test via jitpack.io just for fun and it does not work:
https://jitpack.io/#raydac/java-comment-preprocessor/4238e69afd

Downloading: https://jitpack.io/com/github/raydac/java-comment-preprocessor/4238e69afd/java-comment-preprocessor-4238e69afd.pom
Downloaded: https://jitpack.io/com/github/raydac/java-comment-preprocessor/4238e69afd/java-comment-preprocessor-4238e69afd.pom (13 KB at 0.3 KB/sec)
Downloading: https://jitpack.io/com/github/raydac/java-comment-preprocessor/4238e69afd/java-comment-preprocessor-4238e69afd.jar
Downloaded: https://jitpack.io/com/github/raydac/java-comment-preprocessor/4238e69afd/java-comment-preprocessor-4238e69afd.jar (848 KB at 1002.8 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 43.995 s
[INFO] Finished at: 2015-11-29T00:29:50+03:00
[INFO] Final Memory: 11M/205M
[INFO] ------------------------------------------------------------------------
[ERROR] Invalid plugin descriptor for com.github.raydac:java-comment-preprocessor:4238e69afd (/Users/vladimirsitnikov/.m2/repository/com/github/raydac/java-comment-preprocessor/4238e69afd/java-comment-preprocessor-4238e69afd.jar), Plugin's descriptor contains the wrong group ID: com.igormaznitsa, Plugin's descriptor contains the wrong artifact ID: jcp, Plugin's descriptor contains the wrong version: 6.0.1-SNAPSHOT -> [Help 1]

@jitpack-io
Copy link

Hi @vlsi

Probably the issue is that JitPack rewrites groupId/artifactId to match the GitHub repository. Guessing that the original groupId is specified in the plugin descriptor.

@vlsi
Copy link
Contributor Author

vlsi commented Dec 6, 2015

@raydac , would you mind releasing 6.0.1?

@raydac
Copy link
Owner

raydac commented Dec 6, 2015

@vlsi it works well?

@vlsi
Copy link
Contributor Author

vlsi commented Dec 6, 2015

it does as in log above: #1 (comment)

@raydac
Copy link
Owner

raydac commented Dec 7, 2015

I have moved integration tests into special profile and at present anyone should not have problems to build version locally

@vlsi
Copy link
Contributor Author

vlsi commented Dec 7, 2015

JFY: that solves mvn install for me:

[INFO] --- maven-install-plugin:2.4:install (default-install) @ jcp ---
[INFO] Installing /.../java-comment-preprocessor/target/jcp-6.0.1-SNAPSHOT.jar to /.../.m2/repository/com/igormaznitsa/jcp/6.0.1-SNAPSHOT/jcp-6.0.1-SNAPSHOT.jar
[INFO] Installing /.../java-comment-preprocessor/dependency-reduced-pom.xml to /.../.m2/repository/com/igormaznitsa/jcp/6.0.1-SNAPSHOT/jcp-6.0.1-SNAPSHOT.pom
[INFO] Installing /.../java-comment-preprocessor/target/jcp-6.0.1-SNAPSHOT-sources.jar to /.../.m2/repository/com/igormaznitsa/jcp/6.0.1-SNAPSHOT/jcp-6.0.1-SNAPSHOT-sources.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.246 s
[INFO] Finished at: 2015-12-07T13:32:43+03:00
[INFO] Final Memory: 43M/1022M

@raydac
Copy link
Owner

raydac commented Dec 7, 2015

@vlsi so how is your opinion? is it ready to be released as 6.0.1 in current state?

@vlsi
Copy link
Contributor Author

vlsi commented Dec 7, 2015

@raydac , it looks like it does not work.
Previously I only tested that "subsequent processing" do not update files, however now I see that if I delete target/gen-src, then jcp is not healing the files.

Here's what i get with <verbose>true</verbose> (it would be better to set verbose=true when mvn -X detected).

Just "Content was not saved " with no explanation.

[INFO] Start search global definitions in '/Users/vladimirsitnikov/Documents/code/pgjdbc-all/pgjdbc/pgjdbc/src/main/java/org/postgresql/ssl/NonValidatingFactory.java'
[INFO] Global search completed for file '/Users/vladimirsitnikov/Documents/code/pgjdbc-all/pgjdbc/pgjdbc/src/main/java/org/postgresql/ssl/NonValidatingFactory.java', elapsed time 0ms.
[INFO] Start search global definitions in '/Users/vladimirsitnikov/Documents/code/pgjdbc-all/pgjdbc/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java'
[INFO] Global search completed for file '/Users/vladimirsitnikov/Documents/code/pgjdbc-all/pgjdbc/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java', elapsed time 4ms.
[INFO] Start search global definitions in '/Users/vladimirsitnikov/Documents/code/pgjdbc-all/pgjdbc/pgjdbc/src/main/java/org/postgresql/core/v3/ConnectionFactoryImpl.java'
[INFO] Global search completed for file '/Users/vladimirsitnikov/Documents/code/pgjdbc-all/pgjdbc/pgjdbc/src/main/java/org/postgresql/core/v3/ConnectionFactoryImpl.java', elapsed time 1ms.
[INFO] Start preprocessing '/Users/vladimirsitnikov/Documents/code/pgjdbc-all/pgjdbc/pgjdbc/src/main/java/org/postgresql/core/TypeInfo.java'
[INFO] Content was not saved into file '/Users/vladimirsitnikov/Documents/code/pgjdbc-all/pgjdbc/pgjdbc/target/gen-src/org/postgresql/core/TypeInfo.java'.
[INFO] File preprocessing completed  '/Users/vladimirsitnikov/Documents/code/pgjdbc-all/pgjdbc/pgjdbc/src/main/java/org/postgresql/core/TypeInfo.java', elapsed time 5ms.
[INFO] Start preprocessing '/Users/vladimirsitnikov/Documents/code/pgjdbc-all/pgjdbc/pgjdbc/src/main/java/org/postgresql/jdbc/TimestampUtils.java'
[INFO] Content was not saved into file '/Users/vladimirsitnikov/Documents/code/pgjdbc-all/pgjdbc/pgjdbc/target/gen-src/org/postgresql/jdbc/TimestampUtils.java'.
[INFO] File preprocessing completed  '/Users/vladimirsitnikov/Documents/code/pgjdbc-all/pgjdbc/pgjdbc/src/main/java/org/postgresql/jdbc/TimestampUtils.java', elapsed time 6ms.
[INFO] Start preprocessing '/Users/vladimirsitnikov/Documents/code/pgjdbc-all/pgjdbc/pgjdbc/src/main/java/org/postgresql/util/PGTimestamp.java'

@vlsi
Copy link
Contributor Author

vlsi commented Dec 7, 2015

I believe, the fix is #5

@raydac
Copy link
Owner

raydac commented Dec 7, 2015

@vlsi I have merged the fix and also I have improved logging for debugging, now it will be written into debug log if the file content was not rewritten because its content was not changed, also verbose level is activated automatically if maven debug level is active

@vlsi
Copy link
Contributor Author

vlsi commented Dec 8, 2015

@raydac , it works fine for me

@raydac raydac closed this as completed Dec 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants