Skip to content

Commit e6c332c

Browse files
committed
#38 Add in support for Edge Driver
1 parent aa96ea9 commit e6c332c

File tree

10 files changed

+81
-38
lines changed

10 files changed

+81
-38
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ ___Below is an example RepositoryMap.xml that I will endeavour to keep up to dat
137137
</bitrate>
138138
</version>
139139
</driver>
140+
<driver id="edgedriver">
141+
<version id="3.14393">
142+
<bitrate sixtyfourbit="true" thirtytwobit="true">
143+
<filelocation>https://download.microsoft.com/download/3/2/D/32D3E464-F2EF-490F-841B-05D53C848D15/MicrosoftWebDriver.exe</filelocation>
144+
<hash>6f9e81e5f60fa3e8dccba15a3715ba20d44d0775</hash>
145+
<hashtype>sha1</hashtype>
146+
</bitrate>
147+
</version>
148+
</driver>
140149
<driver id="googlechrome">
141150
<version id="2.23">
142151
<bitrate thirtytwobit="true" sixtyfourbit="true">
@@ -296,4 +305,4 @@ ___Below is an example RepositoryMap.xml that I will endeavour to keep up to dat
296305
</version>
297306
</driver>
298307
</osx>
299-
</root>
308+
</root>

src/main/java/com/lazerycode/selenium/extract/ArchiveType.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/main/java/com/lazerycode/selenium/extract/CompressedFile.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@
1111
import java.io.IOException;
1212
import java.io.InputStream;
1313

14-
import static com.lazerycode.selenium.extract.ArchiveType.BZ2;
15-
import static com.lazerycode.selenium.extract.ArchiveType.GZ;
14+
import static com.lazerycode.selenium.extract.DownloadableFileType.BZ2;
15+
import static com.lazerycode.selenium.extract.DownloadableFileType.GZ;
1616

17-
public class CompressedFile {
17+
class CompressedFile {
1818

1919
private static final Logger LOG = Logger.getLogger(FileExtractor.class);
20-
File compressedFile;
21-
String decompressedFilename;
22-
ArchiveType filetype = null;
20+
private File compressedFile;
21+
private String decompressedFilename;
22+
private DownloadableFileType filetype = null;
2323

2424
/**
2525
* A class that will take a compressed file.
2626
*
2727
* @param compressedFile A compressed file of type .gz or .bz2
28-
* @throws InvalidFileTypeException
28+
* @throws InvalidFileTypeException InvalidFileTypeException
2929
*/
30-
public CompressedFile(File compressedFile) throws InvalidFileTypeException {
31-
filetype = ArchiveType.valueOf(FilenameUtils.getExtension(compressedFile.getName()).toUpperCase());
30+
CompressedFile(File compressedFile) throws InvalidFileTypeException {
31+
filetype = DownloadableFileType.valueOf(FilenameUtils.getExtension(compressedFile.getName()).toUpperCase());
3232
if (filetype != GZ && filetype != BZ2) {
3333
throw new InvalidFileTypeException(compressedFile.getName() + " is an archive, not a known compressed file type");
3434
}
@@ -41,17 +41,17 @@ public CompressedFile(File compressedFile) throws InvalidFileTypeException {
4141
*
4242
* @return The decompressed filename as a String.
4343
*/
44-
public String getDecompressedFilename() {
44+
String getDecompressedFilename() {
4545
return decompressedFilename;
4646
}
4747

4848
/**
4949
* Get an InputStream for the decompressed file.
5050
*
5151
* @return An InputStream, the type could be BZip2CompressorInputStream, or GzipCompressorInputStream depending on what type of file was initially supplied
52-
* @throws IOException
52+
* @throws IOException IOException
5353
*/
54-
public InputStream getInputStream() throws IOException {
54+
InputStream getInputStream() throws IOException {
5555
switch (filetype) {
5656
case GZ:
5757
LOG.debug("Decompressing .gz file");
@@ -68,9 +68,9 @@ public InputStream getInputStream() throws IOException {
6868
*
6969
* @return ArchiveType.TAR if a tar, or null if not an archive
7070
*/
71-
public ArchiveType getArchiveType() {
71+
DownloadableFileType getArchiveType() {
7272
try {
73-
return ArchiveType.valueOf(FilenameUtils.getExtension(decompressedFilename).toUpperCase());
73+
return DownloadableFileType.valueOf(FilenameUtils.getExtension(decompressedFilename).toUpperCase());
7474
} catch (IllegalArgumentException e) {
7575
LOG.debug("Not a recognised Archive type");
7676
return null;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.lazerycode.selenium.extract;
2+
3+
enum DownloadableFileType {
4+
GZ("gz"),
5+
BZ2("bz2"),
6+
ZIP("zip"),
7+
TAR("tar"),
8+
EXE("exe");
9+
10+
private final String downloadableFileFileExtension;
11+
12+
DownloadableFileType(String downloadableFileFileExtension) {
13+
this.downloadableFileFileExtension = downloadableFileFileExtension;
14+
}
15+
}

src/main/java/com/lazerycode/selenium/extract/FileExtractor.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
import org.apache.maven.plugin.MojoFailureException;
1414

1515
import java.io.File;
16+
import java.io.FileInputStream;
1617
import java.io.IOException;
1718
import java.io.InputStream;
1819
import java.util.ArrayList;
1920
import java.util.Enumeration;
2021

21-
import static com.lazerycode.selenium.extract.ArchiveType.TAR;
22+
import static com.lazerycode.selenium.extract.DownloadableFileType.TAR;
2223

2324
public class FileExtractor {
2425

@@ -44,7 +45,7 @@ public FileExtractor(boolean overwriteFilesThatExist) {
4445
* @throws MojoFailureException Error running plugin
4546
*/
4647
public String extractFileFromArchive(File downloadedCompressedFile, String extractedToFilePath, BinaryType possibleFilenames) throws IOException, IllegalArgumentException, MojoFailureException {
47-
ArchiveType fileType = ArchiveType.valueOf(FilenameUtils.getExtension(downloadedCompressedFile.getName()).toUpperCase());
48+
DownloadableFileType fileType = DownloadableFileType.valueOf(FilenameUtils.getExtension(downloadedCompressedFile.getName()).toUpperCase());
4849
LOG.debug("Determined archive type: " + fileType);
4950
LOG.debug("Overwrite files that exist: " + overwriteFilesThatExist);
5051

@@ -59,6 +60,10 @@ public String extractFileFromArchive(File downloadedCompressedFile, String extra
5960
}
6061
case ZIP:
6162
return unzipFile(downloadedCompressedFile, extractedToFilePath, possibleFilenames);
63+
case EXE:
64+
if(possibleFilenames.getBinaryFilenames().contains(downloadedCompressedFile.getName())) {
65+
return copyFileToDisk(new FileInputStream(downloadedCompressedFile), extractedToFilePath, downloadedCompressedFile.getName());
66+
}
6267
default:
6368
throw new IllegalArgumentException("." + fileType + " is an unsupported archive type");
6469
}
@@ -71,10 +76,10 @@ public String extractFileFromArchive(File downloadedCompressedFile, String extra
7176
* @param extractedToFilePath Path to extracted file
7277
* @param possibleFilenames Names of the files we want to extract
7378
* @return boolean
74-
* @throws IOException
79+
* @throws IOException IOException
7580
*/
7681

77-
protected String unzipFile(File downloadedCompressedFile, String extractedToFilePath, BinaryType possibleFilenames) throws IOException, ExpectedFileNotFoundException {
82+
String unzipFile(File downloadedCompressedFile, String extractedToFilePath, BinaryType possibleFilenames) throws IOException, ExpectedFileNotFoundException {
7883
LOG.debug("Attempting to extract binary from .zip file...");
7984
ArrayList<String> filenamesWeAreSearchingFor = possibleFilenames.getBinaryFilenames();
8085
ZipFile zip = new ZipFile(downloadedCompressedFile);
@@ -106,7 +111,7 @@ protected String unzipFile(File downloadedCompressedFile, String extractedToFile
106111
* @throws IOException MojoFailureException
107112
*/
108113

109-
protected String untarFile(InputStream compressedFileInputStream, String extractedToFilePath, BinaryType possibleFilenames) throws IOException, ExpectedFileNotFoundException {
114+
private String untarFile(InputStream compressedFileInputStream, String extractedToFilePath, BinaryType possibleFilenames) throws IOException, ExpectedFileNotFoundException {
110115
LOG.debug("Attempting to extract binary from a .tar file...");
111116
ArchiveEntry currentFile;
112117
ArrayList<String> filenamesWeAreSearchingFor = possibleFilenames.getBinaryFilenames();
@@ -134,9 +139,9 @@ protected String untarFile(InputStream compressedFileInputStream, String extract
134139
* @param pathToExtractTo Path of the file we want to create
135140
* @param filename Filename of the file we want to create
136141
* @return Absolute path of the newly created file (Or existing file if overwriteFilesThatExist is set to false)
137-
* @throws IOException
142+
* @throws IOException IOException
138143
*/
139-
protected String copyFileToDisk(InputStream inputStream, String pathToExtractTo, String filename) throws IOException {
144+
private String copyFileToDisk(InputStream inputStream, String pathToExtractTo, String filename) throws IOException {
140145
if (!overwriteFilesThatExist) {
141146
File[] existingFiles = new File(pathToExtractTo).listFiles();
142147
if (null != existingFiles && existingFiles.length > 0) {

src/main/java/com/lazerycode/selenium/repository/BinaryType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ public enum BinaryType {
3333
add("geckodriver");
3434
add("geckodriver.exe");
3535
}},
36-
"webdriver.gecko.driver");
36+
"webdriver.gecko.driver"),
37+
EDGE(
38+
new ArrayList<String>() {{
39+
add("MicrosoftWebDriver.exe");
40+
}},
41+
"webdriver.edge.driver");
3742

3843
private final ArrayList<String> binaryFilenames;
3944
private final String driverSystemProperty;

src/main/resources/RepositoryMap.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
</bitrate>
1616
</version>
1717
</driver>
18+
<driver id="edgedriver">
19+
<version id="3.14393">
20+
<bitrate sixtyfourbit="true" thirtytwobit="true">
21+
<filelocation>https://download.microsoft.com/download/3/2/D/32D3E464-F2EF-490F-841B-05D53C848D15/MicrosoftWebDriver.exe</filelocation>
22+
<hash>6f9e81e5f60fa3e8dccba15a3715ba20d44d0775</hash>
23+
<hashtype>sha1</hashtype>
24+
</bitrate>
25+
</version>
26+
</driver>
1827
<driver id="googlechrome">
1928
<version id="2.23">
2029
<bitrate thirtytwobit="true" sixtyfourbit="true">

src/test/java/com/lazerycode/selenium/extract/CompressedFileTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.io.File;
77
import java.io.IOException;
88

9-
import static com.lazerycode.selenium.extract.ArchiveType.TAR;
9+
import static com.lazerycode.selenium.extract.DownloadableFileType.TAR;
1010
import static org.hamcrest.core.Is.is;
1111
import static org.hamcrest.core.IsEqual.equalTo;
1212
import static org.junit.Assert.assertThat;

src/test/java/com/lazerycode/selenium/extract/FileExtractorTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ public class FileExtractorTest {
2020
private static final boolean OVERWRITE_EXISTING_FILES = true;
2121
private static final boolean DO_NOT_OVERWRITE_EXISTING_FILES = false;
2222
private static final String VALID_HASH = "add36bb347a987b56e533c2034fd37b1";
23+
private static final String VALID_HASH_FOR_EXE = "0a263b6c69c81e137d74240350e293bc0ca604a3";
2324
private final URL test7ZipFile = this.getClass().getResource("/jetty/files/download.7z");
2425
private final URL testZipFile = this.getClass().getResource("/jetty/files/download.zip");
2526
private final URL testTarGZFile = this.getClass().getResource("/jetty/files/download.tar.gz");
2627
private final URL testTarBZ2File = this.getClass().getResource("/jetty/files/download.tar.bz2");
28+
private final URL textExeFile = this.getClass().getResource("/jetty/files/MicrosoftWebDriver.exe");
2729
private static File phantomJSTestFile;
2830
private static String tempDir;
2931

@@ -172,4 +174,15 @@ public void tryAndExtractFromAnUnsupportedArchive() throws Exception {
172174
FileExtractor fileExtractor = new FileExtractor(DO_NOT_OVERWRITE_EXISTING_FILES);
173175
fileExtractor.extractFileFromArchive(new File(test7ZipFile.getFile()), tempDir, BinaryType.PHANTOMJS);
174176
}
177+
178+
@Test
179+
public void successfullyDownloadAnEXEFile() throws Exception {
180+
FileExtractor fileExtractor = new FileExtractor(OVERWRITE_EXISTING_FILES);
181+
String extractedFile = fileExtractor.extractFileFromArchive(new File(textExeFile.getFile()), tempDir, BinaryType.EDGE);
182+
FileInputStream fileToCheck = new FileInputStream(extractedFile);
183+
String downloadedFileHash = DigestUtils.sha1Hex(fileToCheck);
184+
fileToCheck.close();
185+
186+
assertThat(downloadedFileHash, is(equalTo(VALID_HASH_FOR_EXE)));
187+
}
175188
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Test exe file

0 commit comments

Comments
 (0)