mojohaus / license-maven-plugin

Maven plugin to download and collect license files from project dependencies.
https://www.mojohaus.org/license-maven-plugin/
GNU Lesser General Public License v3.0
106 stars 126 forks source link

Bad hashbang handling on windows #205

Closed ppalaga closed 5 years ago

ppalaga commented 5 years ago

See https://ci.appveyor.com/project/ppalaga/license-maven-plugin-g0x55/builds/21547120/job/k2lp03sc6jror7lr

gevegab commented 5 years ago

The test fails on windows because the "update-file-header" goal applied to a shell file doesn't place the header after the hashbang.

I have pinpointed the problem to this code in file PropertiesFileHeaderTransformer

https://github.com/mojohaus/license-maven-plugin/blob/050acff3338acd3c350ca561a3f75dcb799a8b2f/src/main/java/org/codehaus/mojo/license/header/transformer/PropertiesFileHeaderTransformer.java#L57-L80

The calculation of the end of the prolog (in line 70) uses content.indexOf( getLineSeparator() ) which on windows looks for CR+LF at the end of line. However if the file is encoded with unix EOL (which is common for shell files) it will fail to find the end of prolog.

The problem only happens if you build on a windows machine a shell file that uses unix EOL, so it is restricted to teams with mixed build platforms. I will propose you a fix.

A more general discussion is whether the update file header mojo should use the EOL convention of the building platform or should try to guess the convention used in the file.