public static File newFile(String... items) { File file = newFile(items[0]); for (int i = 1; i < items.length; i++) { file = new File(file, items[i]); } return file; }
public static File newFile(String... items) { File file = newFile(items[0]); for (int i = 1; i < items.length; i++) { file = new File(file, items[i]); } return file; }
public static String getFileAsTextFromWorkingDirOrBaseDir(File baseDir, String fileName, String desc) { File file = newFile(fileName); if (!file.exists()) { file = newFile(baseDir + File.separator + "conf" + File.separator + fileName); } if (!file.exists()) { throw new UncheckedIOException(format("%s [%s] does not exist", desc, file.getAbsolutePath())); } LOGGER.info("Loading " + desc + ": " + file.getAbsolutePath()); return fileAsText(file); }
public static void copyFileToDirectory(File sourceFile, File targetDirectory) { File targetFile = newFile(targetDirectory, sourceFile.getName()); try { Files.copy(sourceFile, targetFile); } catch (IOException e) { throw new UncheckedIOException(format("Error while copying file from %s to %s", sourceFile.getAbsolutePath(), targetFile.getAbsolutePath()), e); } } }
public static File getConfigurationFile(String filename) { File file = new File(filename).getAbsoluteFile(); if (file.exists()) { return file; } else { return newFile(getSimulatorHome(), "conf", filename).getAbsoluteFile(); } } }
public static String getFileAsTextFromWorkingDirOrBaseDir(File baseDir, String fileName, String desc) { File file = newFile(fileName); if (!file.exists()) { file = newFile(baseDir + File.separator + "conf" + File.separator + fileName); } if (!file.exists()) { throw new UncheckedIOException(format("%s [%s] does not exist", desc, file.getAbsolutePath())); } LOGGER.info("Loading " + desc + ": " + file.getAbsolutePath()); return fileAsText(file); }
public static void copyFileToDirectory(File sourceFile, File targetDirectory) { File targetFile = newFile(targetDirectory, sourceFile.getName()); try { Files.copy(sourceFile, targetFile); if (sourceFile.canExecute()) { targetFile.setExecutable(true); } } catch (IOException e) { throw new UncheckedIOException(format("Error while copying file from %s to %s", sourceFile.getAbsolutePath(), targetFile.getAbsolutePath()), e); } }
private void cleanLocal() { File workerHome = newFile(getSimulatorHome(), WORKERS_HOME_NAME); LOGGER.info(format("Cleaning local worker directory %s ...", workerHome.getAbsolutePath())); String workerPath = workerHome.getAbsolutePath(); execute(format("rm -fr %s || true", workerPath)); LOGGER.info("Cleaning local worker directory complete!"); }
private String loadPropertyFromFile(String property) { String path = get(property); File file = newFile(path); if (!file.exists()) { throw new CommandLineExitException(format("File %s for property %s not found", file.getAbsolutePath(), property)); } if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Loading property value for %s from file: %s", property, file.getAbsolutePath())); } return fileAsText(file).trim(); }
private void downloadLocal() { LOGGER.info("Retrieving artifacts of local machine"); File workerHome = newFile(getSimulatorHome(), WORKERS_HOME_NAME); String workerPath = workerHome.getAbsolutePath(); if ("*".equals(sessionId)) { execute(format("cp -r %s/* %s || true", workerPath, outputDirectory.getAbsolutePath())); } else { execute(format("cp -r %s/%s/* %s || true", workerPath, sessionId, outputDirectory.getAbsolutePath())); } execute(format("mv ./agent.err %s/ || true", outputDirectory.getAbsolutePath())); execute(format("mv ./agent.out %s/ || true", outputDirectory.getAbsolutePath())); }
/** * Gets a {@link File} from a defined {@link OptionSpec}. * * @param spec The {@link OptionSpec} which contains the filename. * @param options The {@link OptionSet} which contains the actual options. * @param desc The description of the file. * @return the {@link File} from the defined {@link OptionSpec} * @throws CommandLineExitException if the file cannot be found. */ public static File getFileOrExit(OptionSpec<String> spec, OptionSet options, String desc) { File file = newFile(options.valueOf(spec)); if (!file.exists()) { throw new CommandLineExitException(format("%s [%s] does not exist", desc, file)); } return file; }
/** * Gets a {@link File} from a defined {@link OptionSpec}. * * @param spec The {@link OptionSpec} which contains the filename. * @param options The {@link OptionSet} which contains the actual options. * @param desc The description of the file. * @return the {@link File} from the defined {@link OptionSpec} * @throws CommandLineExitException if the file cannot be found. */ public static File getFileOrExit(OptionSpec<String> spec, OptionSet options, String desc) { File file = newFile(options.valueOf(spec)); if (!file.exists()) { throw new CommandLineExitException(format("%s [%s] does not exist", desc, file)); } return file; }
public SimulatorProperties() { this.propertiesFile = newFile(getSimulatorHome(), "conf", PROPERTIES_FILE_NAME); LOGGER.info(format("Loading default %s: %s", PROPERTIES_FILE_NAME, propertiesFile.getAbsolutePath())); check(propertiesFile); load(propertiesFile); }
static File getPropertiesFile(OptionSet options, OptionSpec<String> propertiesFileSpec) { if (options.has(propertiesFileSpec)) { // a file was explicitly configured return newFile(options.valueOf(propertiesFileSpec)); } else { return null; } } }
private void executeInitScript(String ip) { File initFile = newFile("init-" + newUnsecureUuidString() + ".sh"); writeText(loadInitScript(), initFile); bash.scpToRemote(ip, initFile, "init.sh"); bash.sshTTY(ip, "bash init.sh"); deleteQuiet(initFile); }