/** * Copy the source {@link File} to the target {@link File}. */ public static void copy(File source, File target) throws IOException { if (!source.exists()) { throw new FileNotFoundException("Source file not found:" + source.getAbsolutePath()); } if (!target.exists() && !target.getParentFile().exists() && !target.getParentFile().mkdirs()) { throw new IOException("Can't create target directory:" + target.getParentFile().getAbsolutePath()); } FileInputStream is = new FileInputStream(source); FileOutputStream os = new FileOutputStream(target); copy(is, os); }
/** * Copies any local configuration files into the app directory */ private void copyAppConfigFiles(File appBuildDir, File appConfigDir) throws IOException { File[] files = appConfigDir.listFiles(); if (files != null) { appBuildDir.mkdirs(); for (File file : files) { File outFile = new File(appBuildDir, file.getName()); if (file.isDirectory()) { copyAppConfigFiles(outFile, file); } else { Files.copy(file, outFile); } } } }
/** * Copy the source {@link File} to the target {@link File}. * * // TODO DELETEME when fabric8-utils released with this method */ public static void copy(File source, File target) throws IOException { if (!source.exists()) { throw new FileNotFoundException("Source file not found:" + source.getAbsolutePath()); } if (!target.exists() && !target.getParentFile().exists() && !target.getParentFile().mkdirs()) { throw new IOException("Can't create target directory:" + target.getParentFile().getAbsolutePath()); } if (source.isDirectory()) { target.mkdirs(); File[] files = source.listFiles(); if (files != null) { for (File child : files) { copy(child, new File(target, child.getName())); } } } else { FileInputStream is = new FileInputStream(source); FileOutputStream os = new FileOutputStream(target); io.fabric8.utils.Files.copy(is, os); } } }
protected void copyFile(File src, File dest, Replacement replaceFn, boolean isSource) throws IOException { if (replaceFn != null && isSource) { String original = IOHelpers.readFully(src); String escapedContent = original; if (original.contains("${")) { String replaced = escapedContent.replaceAll(Pattern.quote("${"), "\\${D}{"); // add Velocity expression at the beginning of the result file. // Velocity is used by mvn archetype:generate escapedContent = "#set( $D = '$' )\n" + replaced; } if (original.contains("##")) { String replaced = escapedContent.replaceAll(Pattern.quote("##"), "\\${H}"); // add Velocity expression at the beginning of the result file. // Velocity is used by mvn archetype:generate escapedContent = "#set( $H = '##' )\n" + replaced; } // do additional replacement String text = replaceFn.replace(escapedContent); IOHelpers.writeFully(dest, text); } else { if (LOG.isDebugEnabled()) { LOG.warn("Not a source dir as the extension is {}", Files.getExtension(src.getName())); } Files.copy(src, dest); } }
@Override public void install(InstallContext installContext, ProcessConfig config, String id, File installDir) throws Exception { File baseDir = ProcessUtils.findInstallDir(installDir); Set<Map.Entry<String, String>> entries = localPathToURLMap.entrySet(); for (Map.Entry<String, String> entry : entries) { String localPath = entry.getKey(); String urlText = entry.getValue(); if (Strings.isNotBlank(urlText)) { URL url = null; try { url = new URL(urlText); } catch (MalformedURLException e) { LOG.warn("Ignoring invalid URL '" + urlText + "' for overlay resource " + localPath + ". " + e, e); } if (url != null) { File newFile = new File(baseDir, localPath); FileChangeInfo changeInfo = installContext.createChangeInfo(newFile); newFile.getParentFile().mkdirs(); InputStream stream = url.openStream(); if (stream != null) { Files.copy(stream, new BufferedOutputStream(new FileOutputStream(newFile))); installContext.onFileWrite(newFile, changeInfo); } } } } }
File to = destDir.getCanonicalFile(); LOG.info("Copying git checkout from " + from + " to " + to); Files.copy(from, to);
String fileName = "icon." + Files.getFileExtension(iconRef); File outFile = new File(appBuildDir, fileName); Files.copy(in, new FileOutputStream(outFile)); log.info("Generated icon file " + outFile + " from icon reference: " + iconRef); return outFile;
configuration.info(LOG, "Adding Jenkinsfile " + Strings.trimAllPrefix(relativePath, "/")); File dir = context.getDir(); Files.copy(jenkinsfile, new File(dir, "Jenkinsfile")); return true;
configuration.info(LOG, "Adding Jenkinsfile " + Strings.trimAllPrefix(relativePath, "/")); File dir = context.getDir(); Files.copy(jenkinsfile, new File(dir, "Jenkinsfile")); return true;