Antibrumm / copy-maven-plugin

Maven plugin for file copy / move and replacing content
12 stars 3 forks source link

Allow replacing by empty string #13

Open dhendriks opened 11 months ago

dhendriks commented 11 months ago

Thanks for the great Maven plugin! I have a small issue though. If I have something like this as a replacement:

<replace>
    <from>some_text</from>
    <to>${some.var}</to>
</replace>

And if then some.var is empty, I get the following error during execution:

15:14:50  [ERROR] Failed to execute goal ch.mfrey.maven.plugin:copy-maven-plugin:1.0.0:copy (some-execution-id) on project some.proj.name: Execution some-execution-id of goal ch.mfrey.maven.plugin:copy-maven-plugin:1.0.0:copy failed: Cannot invoke "java.lang.CharSequence.toString()" because "replacement" is null -> [Help 1]

The longer stack trace is:

Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.toString()" because "replacement" is null
    java.lang.String.replace (String.java:2961)
    ch.mfrey.maven.plugin.copy.CopyMojo.copyFile (CopyMojo.java:76)
    ch.mfrey.maven.plugin.copy.CopyMojo.execute (CopyMojo.java:126)
    org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    ...

The crash happens here. The 2nd argument to String.replace is null. It appears that Maven provides null for empty to rather than an empty string.

It would be great to be able to replace by an empty string. I think it would be easy to fix: just check for null, and use an empty string instead.