
nrockstars.gir-webdriver.2.0.3.source-code.downloader Maven / Gradle / Ivy
The newest version!
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class Downloader {
public static void main(String[] args) throws IOException, URISyntaxException{
Map locations = new HashMap<>();
if (System.getProperty("os.name").toLowerCase().contains("win".toLowerCase()))
locations.put("chromedriver_win32.zip", "http://chromedriver.storage.googleapis.com/2.38/");
locations.put("geckodriver-v0.10.0-win64.zip", "https://github.com/mozilla/geckodriver/releases/download/v0.10.0/");
locations.put("IEDriverServer_Win32_2.53.1.zip","http://selenium-release.storage.googleapis.com/2.53/");
locations.put("IEDriverServer_x64_2.53.1.zip", "http://selenium-release.storage.googleapis.com/2.53/");
locations.put("phantomjs-2.1.1-windows.zip", "https://bitbucket.org/ariya/phantomjs/downloads/");
if (System.getProperty("os.name").toLowerCase().contains("mac".toLowerCase()))
locations.put("phantomjs-2.1.1-macosx.zip", "https://bitbucket.org/ariya/phantomjs/downloads/");
if (System.getProperty("os.name").toLowerCase().contains("nux")){
if (System.getProperty("os.arch").toLowerCase().contains("64".toLowerCase())){
locations.put("phantomjs-2.1.1-linux-x86_64.tar.bz2", "https://bitbucket.org/ariya/phantomjs/downloads/");
locations.put("chromedriver_linux64.zip", "https://chromedriver.storage.googleapis.com/73.0.3683.68/");
}
else {
locations.put("phantomjs-2.1.1-linux-i686.tar.bz2", "https://bitbucket.org/ariya/phantomjs/downloads/");
}
}
for (Map.Entry location : locations.entrySet()){
if (System.getProperty("browser").toLowerCase().equals("all")
|| (location.getKey().toLowerCase().contains(System.getProperty("browser").toLowerCase()))) {
try {
String fileName = location.getKey();
URL website = new URL(location.getValue()+fileName);
System.out.println("Downloading "+ fileName);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
try (FileOutputStream fos = new FileOutputStream(fileName)){
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
}
String downloaded = "jar:" + new File(fileName).getAbsoluteFile().toURI();
Iterable zipped = FileSystems.newFileSystem(new URI(downloaded),Collections.singletonMap("create",false)).getRootDirectories();
for (Path fi : zipped){
try {
Files.walkFileTree(fi, new SimpleFileVisitor(){
@Override
public FileVisitResult visitFile(Path file,BasicFileAttributes attrs) throws IOException {
if (file.toString().endsWith(".exe")){
unzip(file);
}
return FileVisitResult.CONTINUE;
}
/**
* prints out details about the specified path
* such as size and modification time
* @param file
* @throws IOException
*/
private void unzip(Path file) throws IOException{
String out = file.toString().split("/|\\\\")[file.toString().split("/|\\\\").length-1];
System.out.println(out);
Files.copy(file, Paths.get(out),StandardCopyOption.REPLACE_EXISTING);
}
});
} catch (Throwable wh){
wh.printStackTrace();
}
}
} catch (Throwable d){
d.printStackTrace();
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy