Skip to content

Commit

Permalink
Fix paypal#318, geckodriver not extracted (paypal#322)
Browse files Browse the repository at this point in the history
- Fix unarchiving of geckodriver after download.
- Also minor refactoring in FileExtractor/Downloader
  to fix warnings.
  • Loading branch information
Sherif Ebady authored and Doug Simmons committed Sep 9, 2016
1 parent 0260732 commit 0e24ea0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ private static void isValidFileType(String url) {
String fileType = url.substring(url.lastIndexOf('.') + 1);
if (!SUPPORTED_TYPES.contains(fileType)) {
throw new UnsupportedOperationException("Unsupported file format: " + fileType
+ ". Supported file types are .zip, .tar, .msi and bz2");
+ ". Supported file types are " + StringUtils.join(SUPPORTED_TYPES, ","));
}
}

Expand Down
22 changes: 14 additions & 8 deletions server/src/main/java/com/paypal/selion/grid/FileExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.apache.commons.compress.compressors.CompressorException;
import org.apache.commons.compress.compressors.CompressorInputStream;
import org.apache.commons.compress.compressors.CompressorStreamFactory;
import org.apache.commons.compress.compressors.bzip2.BZip2Utils;
import org.apache.commons.compress.compressors.gzip.GzipUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.openqa.selenium.Platform;
Expand All @@ -49,8 +51,7 @@ final class FileExtractor {

static String getFileNameFromPath(String name) {
String[] path = name.split("/");
String s = path[path.length - 1];
return s;
return path[path.length - 1];
}

/**
Expand All @@ -59,14 +60,14 @@ static String getFileNameFromPath(String name) {
* @return {@link List} of {@link String} containing the executable file names.
*/
static List<String> getExecutableNames() {
List<String> executableNames = new ArrayList<String>();
List<String> executableNames = new ArrayList<>();
if (Platform.getCurrent().is(Platform.WINDOWS)) {
Collections.addAll(executableNames, ProcessNames.PHANTOMJS.getWindowsImageName(),
ProcessNames.CHROMEDRIVER.getWindowsImageName(), ProcessNames.IEDRIVER.getWindowsImageName(),
ProcessNames.EDGEDRIVER.getWindowsImageName());
ProcessNames.EDGEDRIVER.getWindowsImageName(), ProcessNames.GECKODRIVER.getWindowsImageName());
} else {
Collections.addAll(executableNames, ProcessNames.PHANTOMJS.getUnixImageName(),
ProcessNames.CHROMEDRIVER.getUnixImageName());
ProcessNames.CHROMEDRIVER.getUnixImageName(), ProcessNames.GECKODRIVER.getUnixImageName());
}
return executableNames;
}
Expand All @@ -80,12 +81,17 @@ static List<String> extractArchive(String archiveFile) {
boolean isCompressedArchive = false;
String compressName = null;
String outputArchiveName = null;
List<String> files = new ArrayList<String>();
List<String> files = new ArrayList<>();

if (archiveFile.endsWith(".bz2")) {
if (BZip2Utils.isCompressedFilename(archiveFile)) {
isCompressedArchive = true;
compressName = CompressorStreamFactory.BZIP2;
outputArchiveName = archiveFile.substring(0, archiveFile.lastIndexOf('.'));
outputArchiveName = BZip2Utils.getUncompressedFilename(archiveFile);
LOGGER.fine("Output archive name: " + outputArchiveName);
} else if (GzipUtils.isCompressedFilename(archiveFile)) {
isCompressedArchive = true;
compressName = CompressorStreamFactory.GZIP;
outputArchiveName = GzipUtils.getUncompressedFilename(archiveFile);
LOGGER.fine("Output archive name: " + outputArchiveName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public enum ProcessNames {
PHANTOMJS("phantomjs.exe", "phantomjs"),
WERFAULT("werfault.exe", "NOTAPPLICABLE"),
MICROSOFTEDGE("MicrosoftEdge.exe", "NOTAPPLICABLE"),
EDGEDRIVER("MicrosoftWebDriver.exe", "NOTAPPLICABLE");
EDGEDRIVER("MicrosoftWebDriver.exe", "NOTAPPLICABLE"),
GECKODRIVER("geckodriver.exe", "geckodriver"),
;

private ProcessNames(String windowsImageName, String unixImageName) {
this.windowsImageName = windowsImageName;
Expand Down

0 comments on commit 0e24ea0

Please sign in to comment.