private void deleteTempFiles(ForkCommand forkCommand) { FileUtils.deleteQuietly(forkCommand.jarFile); FileUtils.deleteQuietly(forkCommand.propertiesFile); }
public File extractToTemp(String filenameWithoutSuffix) { String filename = filenameWithoutSuffix + ".jar"; URL url = getClass().getResource("/" + filename); try { File copy = File.createTempFile(filenameWithoutSuffix, ".jar"); FileUtils.copyURLToFile(url, copy); return copy; } catch (Exception e) { throw new IllegalStateException("Fail to extract " + filename, e); } } }
void clean() { long cutoff = System.currentTimeMillis() - ONE_DAY_IN_MILLISECONDS; Collection<File> files = FileUtils.listFiles(tempDir, new AndFileFilter( new PrefixFileFilter("sonar-runner-batch"), new AgeFileFilter(cutoff) ), null); for (File file : files) { FileUtils.deleteQuietly(file); } } }
void clean() { logger.debug("Start temp cleaning..."); long cutoff = System.currentTimeMillis() - ONE_DAY_IN_MILLISECONDS; Collection<File> files = FileUtils.listFiles(tempDir, new AndFileFilter( new PrefixFileFilter("sonar-runner-batch"), new AgeFileFilter(cutoff)), null); for (File file : files) { FileUtils.deleteQuietly(file); } logger.debug("Temp cleaning done"); } }
private void initProjectDirs(Runner runner) { String path = runner.property(ScanProperties.PROJECT_BASEDIR, "."); File projectDir = new File(path); if (!projectDir.isDirectory()) { throw new IllegalStateException("Project home must be an existing directory: " + path); } runner.setProperty(ScanProperties.PROJECT_BASEDIR, projectDir.getAbsolutePath()); File workDir; path = runner.property(RunnerProperties.WORK_DIR, ""); if ("".equals(path.trim())) { workDir = new File(projectDir, ".sonar"); } else { workDir = new File(path); if (!workDir.isAbsolute()) { workDir = new File(projectDir, path); } } FileUtils.deleteQuietly(workDir); runner.setProperty(RunnerProperties.WORK_DIR, workDir.getAbsolutePath()); Logs.info("Work directory: " + workDir.getAbsolutePath()); }
public File extractToTemp(String filenameWithoutSuffix) { String filename = filenameWithoutSuffix + ".jar"; URL url = getClass().getResource("/" + filename); try { File copy = File.createTempFile(filenameWithoutSuffix, ".jar"); FileUtils.copyURLToFile(url, copy); return copy; } catch (Exception e) { throw new IllegalStateException("Fail to extract " + filename, e); } } }
void download(String path, File toFile) { String fullUrl = serverUrl + path; try { Logs.debug("Download " + fullUrl + " to " + toFile.getAbsolutePath()); HttpRequest httpRequest = newHttpRequest(new URL(fullUrl)); if (!httpRequest.ok()) { throw new IOException(MessageFormat.format(STATUS_RETURNED_BY_URL_IS_INVALID, fullUrl, httpRequest.code())); } httpRequest.receive(toFile); } catch (Exception e) { if (e.getCause() instanceof ConnectException || e.getCause() instanceof UnknownHostException) { Logs.error(MessageFormat.format(SONAR_SERVER_CAN_NOT_BE_REACHED, serverUrl)); } FileUtils.deleteQuietly(toFile); throw new IllegalStateException("Fail to download: " + fullUrl, e); } }
/** * Download file, without any caching mechanism. * * @param urlPath path starting with slash, for instance {@code "/batch/index"} * @param toFile the target file * @throws IOException if connectivity problem or timeout (network) or IO error (when writing to file) * @throws IllegalStateException if HTTP response code is different than 2xx */ public void downloadFile(String urlPath, File toFile) throws IOException { if (!urlPath.startsWith("/")) { throw new IllegalArgumentException(format("URL path must start with slash: %s", urlPath)); } String url = baseUrlWithoutTrailingSlash + urlPath; logger.debug(format("Download %s to %s", url, toFile.getAbsolutePath())); ResponseBody responseBody = callUrl(url); try (OutputStream fileOutput = new FileOutputStream(toFile)) { IOUtils.copyLarge(responseBody.byteStream(), fileOutput); } catch (IOException | RuntimeException e) { FileUtils.deleteQuietly(toFile); throw e; } }