Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the easiest way convert line endings to unix style when creating tar file in Gradle?

Tags:

newline

gradle

At work we use a mixture of Windows and Linux workstations during development. For deployment we always deploy to Unix machines. I'd like to ensure that the line endings are always in Unix format. What is the easiest way in Gradle to achieve this? I was thinking it might be possible to use a FilterReader but I didn't manage to find a ready made one. Would this be the best option?

like image 498
Glen Avatar asked May 11 '11 02:05

Glen


Video Answer


2 Answers

Editing this entry to use a Copy task instead. Initial version of this was using a Tar task but I noticed that while it was stripping the CRLF when run in Linux but on Windows it was failing to work correctly. Since they're both copyspecs AFAIK I would have expected Tar tasks to work the same but sadly this is not the case (gradle 1.0-milestone-3).

Looks like I've figured it out myself. The FilterReader required is FixCrLfFilter. The following snippet shows how you might use it:

import org.apache.tools.ant.filters.*;

task archiveit(type: Copy) {
  from "conf"
  into "targetdir"
  filter(FixCrLfFilter.class,
         eol:FixCrLfFilter.CrLf.newInstance("lf"))
}
like image 124
Glen Avatar answered Oct 25 '22 20:10

Glen


The answer by Glen did not work for me, so I came up with even simpler solution:

task archiveit(type: Copy) {
  from "conf"
  into "targetdir"
  filter { line -> line.replaceAll('\r\n', '\n') }
}

Should work with all tasks that support filters, including Tar task.

like image 21
Neeme Praks Avatar answered Oct 25 '22 20:10

Neeme Praks