MCPcopy Create free account
hub / github.com/diffplug/goomph / copyFile

Method copyFile

src/main/java/com/diffplug/gradle/FileMisc.java:241–256  ·  view source on GitHub ↗

Copies from src to dst and performs a simple copy-replace templating operation along the way. ```java copyFile(src, dst, "%username%", "lskywalker" "%firstname%", "Luke", "%lastname%", "Skywalker"); ```

(File srcFile, File dstFile, String... toReplace)

Source from the content-addressed store, hash-verified

239 * ```
240 */
241 public static void copyFile(File srcFile, File dstFile, String... toReplace) throws IOException {
242 // make a map of the keys that we're replacing
243 Preconditions.checkArgument(toReplace.length % 2 == 0);
244 Map<String, String> replaceMap = Maps.newHashMap();
245 for (int i = 0; i < toReplace.length / 2; ++i) {
246 replaceMap.put(toReplace[2 * i], toReplace[2 * i + 1]);
247 }
248 // replace them
249 String content = Joiner.on("\n").join(Files.readLines(srcFile, StandardCharsets.UTF_8));
250 for (Entry<String, String> entry : replaceMap.entrySet()) {
251 content = content.replace(entry.getKey(), entry.getValue());
252 }
253 // write it out
254 mkdirs(dstFile.getParentFile());
255 Files.write(content.getBytes(StandardCharsets.UTF_8), dstFile);
256 }
257
258 /** Modifies the given file in place. */
259 public static void modifyFile(File file, Function<String, String> modifier) throws IOException {

Callers 3

copyMethod · 0.80
copyVersionsOfPluginMethod · 0.80
ideSetupWorkspaceMethod · 0.80

Calls 4

mkdirsMethod · 0.95
readLinesMethod · 0.80
replaceMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected