public synchronized String download(URL url, String version, String driverName) throws IOException, InterruptedException { File targetFile = getTarget(version, url); Optional<File> binary = checkBinary(driverName, targetFile); if (!binary.isPresent()) { binary = downloadAndExtract(url, targetFile); } return binary.get().toString(); }
private File extract(File compressedFile) throws IOException, InterruptedException { String fileName = compressedFile.getName().toLowerCase(); boolean extractFile = !fileName.endsWith("exe") && !fileName.endsWith("jar"); if (extractFile) { log.info("Extracting binary from compressed file {}", fileName); } if (fileName.endsWith("tar.bz2")) { unBZip2(compressedFile); } else if (fileName.endsWith("tar.gz")) { unTarGz(compressedFile); } else if (fileName.endsWith("gz")) { unGzip(compressedFile); } else if (fileName.endsWith("msi")) { extractMsi(compressedFile); } else if (fileName.endsWith("zip")) { unZip(compressedFile); } if (extractFile) { deleteFile(compressedFile); } File result = WebDriverManager.getInstance(driverManagerType) .postDownload(compressedFile).getAbsoluteFile(); log.trace("Resulting binary file {}", result); return result; }
private Optional<File> downloadAndExtract(URL url, File targetFile) throws IOException, InterruptedException { log.info("Downloading {}", url); File targetFolder = targetFile.getParentFile(); File tempDir = createTempDirectory("").toFile(); File temporaryFile = new File(tempDir, targetFile.getName()); log.trace("Target folder {} ... using temporal file {}", targetFolder, temporaryFile); copyInputStreamToFile(httpClient.execute(httpClient.createHttpGet(url)) .getEntity().getContent(), temporaryFile); File extractedFile = extract(temporaryFile); File resultingBinary = new File(targetFolder, extractedFile.getName()); boolean binaryExists = resultingBinary.exists(); if (!binaryExists || config.isOverride()) { if (binaryExists) { log.info("Overriding former binary {}", resultingBinary); deleteFile(resultingBinary); } moveFileToDirectory(extractedFile, targetFolder, true); } if (!config.isExecutable(resultingBinary)) { setFileExecutable(resultingBinary); } deleteFolder(tempDir); log.trace("Binary driver after extraction {}", resultingBinary); return of(resultingBinary); }
@Override protected File postDownload(File archive) { log.trace("PhantomJS package name: {}", archive); File extractFolder = archive.getParentFile() .listFiles(getFolderFilter())[0]; log.trace("PhantomJS extract folder (to be deleted): {}", extractFolder); File binFolder = new File( extractFolder.getAbsoluteFile() + separator + "bin"); // Exception for older version of PhantomJS int binaryIndex = 0; if (!binFolder.exists()) { binFolder = extractFolder; binaryIndex = 3; } log.trace("PhantomJS bin folder: {} (index {})", binFolder, binaryIndex); File phantomjs = binFolder.listFiles()[binaryIndex]; log.trace("PhantomJS binary: {}", phantomjs); File target = new File(archive.getParentFile().getAbsolutePath(), phantomjs.getName()); log.trace("PhantomJS target: {}", target); downloader.renameFile(phantomjs, target); downloader.deleteFolder(extractFolder); return target; }
protected List<File> getFilesInCache() { return (List<File>) listFiles(new File(downloader.getTargetPath()), null, true); }
protected void renameFile(File from, File to) { log.trace("Renaming file from {} to {}", from, to); if (to.exists()) { deleteFile(to); } if (!from.renameTo(to)) { log.warn("Error renaming file from {} to {}", from, to); } }
protected void downloadCandidateUrls(List<URL> candidateUrls) throws IOException, InterruptedException { URL url = candidateUrls.iterator().next(); String exportValue = downloader.download(url, versionToDownload, getDriverName()); exportDriver(exportValue); downloadedVersion = versionToDownload; }
private void extractMsi(File msi) throws IOException, InterruptedException { File tmpMsi = new File( createTempDirectory("").toFile().getAbsoluteFile() + separator + msi.getName()); move(msi.toPath(), tmpMsi.toPath()); log.trace("Temporal msi file: {}", tmpMsi); Process process = getRuntime().exec(new String[] { "msiexec", "/a", tmpMsi.toString(), "/qb", "TARGETDIR=" + msi.getParent() }); try { process.waitFor(); } finally { process.destroy(); } deleteFolder(tmpMsi.getParentFile()); }
protected void manage(Architecture arch, String version) { httpClient = new HttpClient(config()); try (HttpClient wdmHttpClient = httpClient) { downloader = new Downloader(getDriverManagerType()); urlFilter = new UrlFilter();
log.trace("Operadriver target: {}", target); downloader.renameFile(operadriver, target); } finally { downloader.deleteFolder(extractFolder);
public File getTarget(String version, URL url) { log.trace("getTarget {} {}", version, url); String zip = url.getFile().substring(url.getFile().lastIndexOf('/')); int iFirst = zip.indexOf('_'); int iSecond = zip.indexOf('-'); int iLast = zip.length(); if (iFirst != zip.lastIndexOf('_')) { iLast = zip.lastIndexOf('_'); } else if (iSecond != -1) { iLast = iSecond; } String folder = zip.substring(0, iLast).replace(".zip", "") .replace(".tar.bz2", "").replace(".tar.gz", "") .replace(".msi", "").replace(".exe", "") .replace("_", separator); String path = config.isAvoidOutputTree() ? getTargetPath() + zip : getTargetPath() + folder + separator + version + zip; String target = WebDriverManager.getInstance(driverManagerType) .preDownload(path, version); log.trace("Target file for URL {} version {} = {}", url, version, target); return new File(target); }
protected void renameFile(File from, File to) { log.trace("Renaming file from {} to {}", from, to); if (to.exists()) { deleteFile(to); } if (!from.renameTo(to)) { log.warn("Error renaming file from {} to {}", from, to); } }
protected void downloadCandidateUrls(List<URL> candidateUrls) throws IOException, InterruptedException { URL url = candidateUrls.iterator().next(); String exportValue = downloader.download(url, versionToDownload, getDriverName()); exportDriver(exportValue); downloadedVersion = versionToDownload; }
private void extractMsi(File msi) throws IOException, InterruptedException { File tmpMsi = new File( createTempDirectory("").toFile().getAbsoluteFile() + separator + msi.getName()); move(msi.toPath(), tmpMsi.toPath()); log.trace("Temporal msi file: {}", tmpMsi); Process process = getRuntime().exec(new String[] { "msiexec", "/a", tmpMsi.toString(), "/qb", "TARGETDIR=" + msi.getParent() }); try { process.waitFor(); } finally { process.destroy(); } deleteFolder(tmpMsi.getParentFile()); }
protected void manage(Architecture arch, String version) { httpClient = new HttpClient(config()); try (HttpClient wdmHttpClient = httpClient) { downloader = new Downloader(getDriverManagerType()); urlFilter = new UrlFilter();
private File extract(File compressedFile) throws IOException, InterruptedException { String fileName = compressedFile.getName().toLowerCase(); boolean extractFile = !fileName.endsWith("exe") && !fileName.endsWith("jar"); if (extractFile) { log.info("Extracting binary from compressed file {}", fileName); } if (fileName.endsWith("tar.bz2")) { unBZip2(compressedFile); } else if (fileName.endsWith("tar.gz")) { unTarGz(compressedFile); } else if (fileName.endsWith("gz")) { unGzip(compressedFile); } else if (fileName.endsWith("msi")) { extractMsi(compressedFile); } else if (fileName.endsWith("zip")) { unZip(compressedFile); } if (extractFile) { deleteFile(compressedFile); } File result = WebDriverManager.getInstance(driverManagerType) .postDownload(compressedFile).getAbsoluteFile(); log.trace("Resulting binary file {}", result); return result; }
private Optional<File> downloadAndExtract(URL url, File targetFile) throws IOException, InterruptedException { log.info("Downloading {}", url); File targetFolder = targetFile.getParentFile(); File tempDir = createTempDirectory("").toFile(); File temporaryFile = new File(tempDir, targetFile.getName()); log.trace("Target folder {} ... using temporal file {}", targetFolder, temporaryFile); copyInputStreamToFile(httpClient.execute(httpClient.createHttpGet(url)) .getEntity().getContent(), temporaryFile); File extractedFile = extract(temporaryFile); File resultingBinary = new File(targetFolder, extractedFile.getName()); boolean binaryExists = resultingBinary.exists(); if (!binaryExists || config.isOverride()) { if (binaryExists) { log.info("Overriding former binary {}", resultingBinary); deleteFile(resultingBinary); } moveFileToDirectory(extractedFile, targetFolder, true); } if (!config.isExecutable(resultingBinary)) { setFileExecutable(resultingBinary); } deleteFolder(tempDir); log.trace("Binary driver after extraction {}", resultingBinary); return of(resultingBinary); }
public synchronized String download(URL url, String version, String driverName) throws IOException, InterruptedException { File targetFile = getTarget(version, url); Optional<File> binary = checkBinary(driverName, targetFile); if (!binary.isPresent()) { binary = downloadAndExtract(url, targetFile); } return binary.get().toString(); }
@Override protected File postDownload(File archive) { log.trace("PhantomJS package name: {}", archive); File extractFolder = archive.getParentFile() .listFiles(getFolderFilter())[0]; log.trace("PhantomJS extract folder (to be deleted): {}", extractFolder); File binFolder = new File( extractFolder.getAbsoluteFile() + separator + "bin"); // Exception for older version of PhantomJS int binaryIndex = 0; if (!binFolder.exists()) { binFolder = extractFolder; binaryIndex = 3; } log.trace("PhantomJS bin folder: {} (index {})", binFolder, binaryIndex); File phantomjs = binFolder.listFiles()[binaryIndex]; log.trace("PhantomJS binary: {}", phantomjs); File target = new File(archive.getParentFile().getAbsolutePath(), phantomjs.getName()); log.trace("PhantomJS target: {}", target); downloader.renameFile(phantomjs, target); downloader.deleteFolder(extractFolder); return target; }
protected List<File> getFilesInCache() { return (List<File>) listFiles(new File(downloader.getTargetPath()), null, true); }