Skip to content

Commit

Permalink
Include version number in extracted path
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- committed Jan 27, 2018
1 parent c141765 commit 4ba4442
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ public DriverMap ensureStandaloneExecutableFilesExist() throws MojoFailureExcept
for (final DriverContext driverContext : filesToDownload.getKeys()) {
if (onlyGetLatestVersions) {
DriverDetails driverDetails = filesToDownload.getDetailsForLatestVersionOfDriverContext(driverContext);
downloadAndExtractExecutableFiles(driverContext, driverDetails);
downloadAndExtractExecutableFiles(driverContext, driverDetails, filesToDownload.getLatestVersionOfDriverContext(driverContext));
} else {
for (String version : filesToDownload.getAvailableVersionsForDriverContext(driverContext)) {
DriverDetails driverDetails = filesToDownload.getDetailsForVersionOfDriverContext(driverContext, version);
downloadAndExtractExecutableFiles(driverContext, driverDetails);
downloadAndExtractExecutableFiles(driverContext, driverDetails, version);
}
}
}

return filesToDownload;
}

private void downloadAndExtractExecutableFiles(DriverContext driverContext, DriverDetails driverDetails) throws IOException, MojoExecutionException, URISyntaxException, MojoFailureException {
private void downloadAndExtractExecutableFiles(DriverContext driverContext, DriverDetails driverDetails, String version) throws IOException, MojoExecutionException, URISyntaxException, MojoFailureException {
String localZipFileAbsolutePath = this.downloadedZipFileDirectory + File.separator + FilenameUtils.getName(driverDetails.fileLocation.getFile());
File localZipFile = new File(localZipFileAbsolutePath);
boolean fileNeedsToBeDownloaded = true;
Expand All @@ -122,7 +122,7 @@ private void downloadAndExtractExecutableFiles(DriverContext driverContext, Driv
localZipFile = downloadFile(driverDetails, checkFileHash);
}

String extractedFileLocation = this.rootStandaloneServerDirectory.getAbsolutePath() + File.separator + driverContext.buildExtractionPathFromDriverContext();
String extractedFileLocation = this.rootStandaloneServerDirectory.getAbsolutePath() + File.separator + driverContext.buildExtractionPathFromDriverContext(version);
FileExtractor fileExtractor = new FileExtractor(this.overwriteFilesThatExist);
driverDetails.extractedLocation = fileExtractor.extractFileFromArchive(localZipFile, extractedFileLocation, driverContext.getBinaryTypeForContext());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public static DriverContext binaryDataFor(String osName, String browserType, Sys
return new DriverContext(browserType, osName, architecture);
}

public String buildExtractionPathFromDriverContext() {
return operatingSystem.toString().toLowerCase() + File.separator + driverType.getBinaryTypeAsString() + File.separator + systemArchitecture.getSystemArchitectureType() + File.separator;
public String buildExtractionPathFromDriverContext(String version) {
return operatingSystem.toString().toLowerCase() + File.separator + driverType.getBinaryTypeAsString() + File.separator + version.toLowerCase() + File.separator + systemArchitecture.getSystemArchitectureType() + File.separator;
}

public BinaryType getBinaryTypeForContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public DriverDetails getDetailsForLatestVersionOfDriverContext(DriverContext dri
return driverVersions.get(driverVersions.lastKey());
}

public String getLatestVersionOfDriverContext(DriverContext driverContext) {
if (!repository.containsKey(driverContext)) {
throw new IllegalArgumentException("Driver context not found in driver repository");
}

TreeMap<String, DriverDetails> driverVersions = repository.get(driverContext);
return driverVersions.lastKey();
}

public Set<DriverContext> getKeys() {
return repository.keySet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ public void filesAreExtractedIntoTheCorrectStandaloneServerPathAndCanBeOverwritt
fileDetails.hash = validSHA1Hash;
DriverContext driverContext = binaryDataFor(OSX, PHANTOMJS, ARCHITECTURE_64_BIT);
DriverMap driverMap = new DriverMap();
driverMap.getMapForDriverContext(driverContext).put("2.13", fileDetails);
File expectedDownloadedFile = new File(rootStandaloneServerDirectoryPath + File.separator + "osx" + File.separator + "phantomjs" + File.separator + "64bit" + File.separator + "phantomjs");
String version = "2.13";
driverMap.getMapForDriverContext(driverContext).put(version, fileDetails);
File expectedDownloadedFile = new File(rootStandaloneServerDirectoryPath + File.separator + "osx" + File.separator + "phantomjs" + File.separator + version + File.separator + "64bit" + File.separator + "phantomjs");

assertThat(expectedDownloadedFile.exists(), is(equalTo(false)));

Expand All @@ -161,8 +162,9 @@ public void fileCanBeDownloadedIfThereIsNoHashInFileDownloadListFileDetails() th
fileDetails.hashType = null;
fileDetails.hash = null;
DriverMap driverMap = new DriverMap();
driverMap.getMapForDriverContext(binaryDataFor(OSX, PHANTOMJS, ARCHITECTURE_64_BIT)).put("2.13", fileDetails);
File expectedDownloadedFile = new File(rootStandaloneServerDirectoryPath + File.separator + "osx" + File.separator + "phantomjs" + File.separator + "64bit" + File.separator + "phantomjs");
String version = "2.13";
driverMap.getMapForDriverContext(binaryDataFor(OSX, PHANTOMJS, ARCHITECTURE_64_BIT)).put(version, fileDetails);
File expectedDownloadedFile = new File(rootStandaloneServerDirectoryPath + File.separator + "osx" + File.separator + "phantomjs" + File.separator + version + File.separator + "64bit" + File.separator + "phantomjs");

assertThat(expectedDownloadedFile.exists(), is(equalTo(false)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public void driverContextWithStringsMapsTpDriverContextWithEnums() {

@Test
public void driverContextCreatesAStringThatCanBeUsedAsAFilePath() {
String expectedFilepath = "osx" + File.separator + "googlechrome" + File.separator + "64bit" + File.separator;
String filePath = binaryDataFor(OSX, GOOGLECHROME, ARCHITECTURE_64_BIT).buildExtractionPathFromDriverContext();
String expectedFilepath = "osx" + File.separator + "googlechrome" + File.separator + "1.2.3" + File.separator + "64bit" + File.separator;
String filePath = binaryDataFor(OSX, GOOGLECHROME, ARCHITECTURE_64_BIT).buildExtractionPathFromDriverContext("1.2.3");

assertThat(filePath,
is(equalTo(expectedFilepath)));
Expand Down

0 comments on commit 4ba4442

Please sign in to comment.