|
14 | 14 | import java.io.IOException;
|
15 | 15 | import java.io.InputStream;
|
16 | 16 | import java.net.URL;
|
| 17 | +import java.nio.charset.Charset; |
17 | 18 | import java.nio.file.Files;
|
18 | 19 | import java.util.Arrays;
|
19 | 20 | import java.util.List;
|
| 21 | +import java.util.function.Function; |
20 | 22 | import java.util.regex.Pattern;
|
21 | 23 | import java.util.stream.Collectors;
|
22 | 24 |
|
@@ -143,10 +145,28 @@ private static void copyStreamToFile(InputStream is, File dest) throws MojoExecu
|
143 | 145 | }
|
144 | 146 | }
|
145 | 147 |
|
| 148 | + public static void copyResourceToFile(String resource, File dest, boolean unixStyleNewLines) throws MojoExecutionException { |
| 149 | + copyResourceToFile(resource, dest); |
| 150 | + if (unixStyleNewLines) { |
| 151 | + try { |
| 152 | + processFileContent(dest, c -> c.replaceAll("\\r\\n", "\n").replaceAll("\\r", "\n")); |
| 153 | + } catch (IOException e) { |
| 154 | + throw new MojoExecutionException(e.getMessage(), e); |
| 155 | + } |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | + public static void processFileContent(File dest, Function<String, String> function) throws IOException { |
| 160 | + String content = org.apache.commons.io.FileUtils.readFileToString(dest, Charset.forName("UTF-8")); |
| 161 | + content = function.apply(content); |
| 162 | + org.apache.commons.io.FileUtils.writeStringToFile(dest, content, Charset.forName("UTF-8")); |
| 163 | + } |
| 164 | + |
146 | 165 | public static void copyResourceToFile(String resource, File dest) throws MojoExecutionException {
|
147 | 166 | Logger.info("Copying resource [" + resource + "] to file [" + dest + "]");
|
148 | 167 | copyStreamToFile(FileUtils.class.getResourceAsStream(resource), dest);
|
149 | 168 | }
|
| 169 | + |
150 | 170 |
|
151 | 171 | public static void createSymlink(File link, File target) throws MojoExecutionException {
|
152 | 172 | Logger.info("Creating symbolic link [" + link + "] to [" + target + "]");
|
|
0 commit comments