Skip to content

Commit

Permalink
Merge pull request #41 from jason-edstrom/custom-driver-filename
Browse files Browse the repository at this point in the history
resolves #42
  • Loading branch information
andidev authored Jun 2, 2019
2 parents 8d3bf50 + d172e60 commit b2d915c
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 9 deletions.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,32 @@ To skip the installation you can add `<skip>true</skip>` in the configuration ta
</plugin>
```

### Setting the driver filename
To set a custom file name for the specified driver configuration.
```xml
<plugin>
<groupId>com.github.webdriverextensions</groupId>
<artifactId>webdriverextensions-maven-plugin</artifactId>
<version>3.1.3</version>
<executions>
<execution>
<goals>
<goal>install-drivers</goal>
</goals>
</execution>
</executions>
<configuration>
<drivers>
<driver>
<name>chromedriver</name>
<platform>linux</platform>
<customFileName>chrome-linux-custom</customFileName>
</driver>
</drivers>
</configuration>
</plugin>
```

### Further Configurations
For more details on how to further configure this plugin please see the
[plugin goal documentation](http://webdriverextensions.github.io/webdriverextensions-maven-plugin/install-drivers-mojo.html).
Expand Down Expand Up @@ -403,7 +429,7 @@ For more details on how to further configure this plugin please see the
#### 1.0.0 (2014 June 6)
- Initial release!

## License
## License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this work except in compliance with the License.
Expand Down
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
<name>lkwg82</name>
<url>https://github.com/lkwg82</url>
</contributor>
<contributor>
<name>jason-edstrom</name>
<url>https://github.com/jason-edstrom</url>
</contributor>
</contributors>

<issueManagement>
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/com/github/webdriverextensions/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ public class Driver {
private String version;
private String url;
private String fileMatchInside;
private String customFileName;

public String getId() {
return name
+ (platform != null ? "-" + platform : "")
+ (bit != null ? "-" + bit + "bit" : "");

if (customFileName!= null)
{
if (!customFileName.isEmpty()) {
return customFileName;
}
}

return name + (platform != null ? "-" + platform : "") + (bit != null ? "-" + bit + "bit" : "");
}

public String getDriverDownloadDirectoryName() {
Expand All @@ -39,6 +46,14 @@ public String getPlatform() {
return platform;
}

public String getCustomFileName() {
return customFileName;
}

public void setCustomFileName(String customFileName) {
this.customFileName = customFileName;
}

public void setPlatform(String platform) {
this.platform = platform;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import static com.github.webdriverextensions.Utils.quote;
Expand Down Expand Up @@ -62,7 +61,7 @@ public Path downloadFile(Driver driver, Path downloadDirectory) throws MojoExecu
HttpEntity remoteFileStream = fileDownloadResponse.getEntity();
copyInputStreamToFile(remoteFileStream.getContent(), downloadFilePath.toFile());
if (driverFileIsCorrupt(downloadFilePath)) {
printXmlFileContetIfPresentInDonwloadedFile(downloadFilePath);
printXmlFileContentIfPresentInDownloadedFile(downloadFilePath);
cleanupDriverDownloadDirectory(downloadDirectory);
throw new InstallDriversMojoExecutionException("Failed to download a non corrupt driver", mojo, driver);
}
Expand All @@ -77,7 +76,7 @@ public Path downloadFile(Driver driver, Path downloadDirectory) throws MojoExecu
return downloadFilePath;
}

private void printXmlFileContetIfPresentInDonwloadedFile(Path downloadFilePath) {
private void printXmlFileContentIfPresentInDownloadedFile(Path downloadFilePath) {
try {
List<String> fileContent = Files.readAllLines(downloadFilePath, StandardCharsets.UTF_8);
if (fileContent.get(0).startsWith("<?xml")) {
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/com/github/webdriverextensions/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,22 @@ Driver enrichDriver(Driver driver) throws MojoExecutionException {
// Could not find any driver for the current platform/bit/version in repo
return null;
}
return filterLatestDriver(drivers);
return transferCustomFileName(driver,filterLatestDriver(drivers));
}
return null;
}
return drivers.get(0);

return transferCustomFileName(driver, drivers.get(0));
}

private Driver transferCustomFileName(Driver driver, Driver foundDriver) {

if (isNotBlank(driver.getCustomFileName()))
{
foundDriver.setCustomFileName(driver.getCustomFileName());
}

return foundDriver;
}

List<Driver> getLatestDrivers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,49 @@ public void test_that_driver_configuration_with_no_version_downloads_latest_driv
assertDriverIsInstalled("operadriver-linux-64bit");
assertNumberOfInstalledDriverIs(19);
}

public void test_that_driver_file_is_named_to_custom_filename() throws Exception
{
// Given
InstallDriversMojo mojo = getMojo("src/test/resources/custom_filename_pom.xml");

// When
mojo.execute();

// Then
assertDriverIsInstalled("chrome-linux-custom");
assertDriverIsInstalled("chrome-mac-custom");
assertDriverIsInstalled("chrome-windows-custom.exe");
assertNumberOfInstalledDriverIs(3);
}

public void test_that_driver_file_is_named_to_custom_filename_with_version() throws Exception
{
// Given
InstallDriversMojo mojo = getMojo("src/test/resources/custom_filename_pom_add_version_pom.xml");

// When
mojo.execute();

// Then
assertDriverIsInstalled("chrome-linux-custom");
assertDriverIsInstalled("chrome-mac-custom");
assertDriverIsInstalled("chrome-windows-custom.exe");
assertNumberOfInstalledDriverIs(3);
}

public void test_that_driver_file_is_named_to_custom_filename_with_version_and_bit() throws Exception
{
// Given
InstallDriversMojo mojo = getMojo("src/test/resources/custom_filename_pom_add_version_and_bit_pom.xml");

// When
mojo.execute();

// Then
assertDriverIsInstalled("chrome-linux-custom");
assertDriverIsInstalled("chrome-mac-custom");
assertDriverIsInstalled("chrome-windows-custom.exe");
assertNumberOfInstalledDriverIs(3);
}
}
41 changes: 41 additions & 0 deletions src/test/resources/custom_filename_pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.webdriverextensions</groupId>
<artifactId>test-install-drivers-mojo</artifactId>
<packaging>war</packaging>
<version>2.0.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>com.github.webdriverextensions</groupId>
<artifactId>webdriverextensions-maven-plugin</artifactId>
<configuration>
<drivers>
<driver>
<name>chromedriver</name>
<platform>linux</platform>
<bit>32</bit>
<version>2.9.0</version>
<customFileName>chrome-linux-custom</customFileName>
</driver>
<driver>
<name>chromedriver</name>
<platform>mac</platform>
<bit>32</bit>
<version>2.9.0</version>
<customFileName>chrome-mac-custom</customFileName>
</driver>
<driver>
<name>chromedriver</name>
<platform>windows</platform>
<bit>32</bit>
<version>2.9.0</version>
<customFileName>chrome-windows-custom</customFileName>
</driver>
</drivers>
</configuration>
</plugin>
</plugins>
</build>
</project>
41 changes: 41 additions & 0 deletions src/test/resources/custom_filename_pom_add_version_and_bit_pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.webdriverextensions</groupId>
<artifactId>test-install-drivers-mojo</artifactId>
<packaging>war</packaging>
<version>2.0.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>com.github.webdriverextensions</groupId>
<artifactId>webdriverextensions-maven-plugin</artifactId>
<configuration>
<drivers>
<driver>
<name>chromedriver</name>
<platform>linux</platform>
<bit>32</bit>
<version>2.9.0</version>
<customFileName>chrome-linux-custom</customFileName>
</driver>
<driver>
<name>chromedriver</name>
<platform>mac</platform>
<bit>32</bit>
<version>2.9.0</version>
<customFileName>chrome-mac-custom</customFileName>
</driver>
<driver>
<name>chromedriver</name>
<platform>windows</platform>
<bit>32</bit>
<version>2.9.0</version>
<customFileName>chrome-windows-custom</customFileName>
</driver>
</drivers>
</configuration>
</plugin>
</plugins>
</build>
</project>
38 changes: 38 additions & 0 deletions src/test/resources/custom_filename_pom_add_version_pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.webdriverextensions</groupId>
<artifactId>test-install-drivers-mojo</artifactId>
<packaging>war</packaging>
<version>2.0.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>com.github.webdriverextensions</groupId>
<artifactId>webdriverextensions-maven-plugin</artifactId>
<configuration>
<drivers>
<driver>
<name>chromedriver</name>
<platform>linux</platform>
<version>2.9.0</version>
<customFileName>chrome-linux-custom</customFileName>
</driver>
<driver>
<name>chromedriver</name>
<platform>mac</platform>
<version>2.9.0</version>
<customFileName>chrome-mac-custom</customFileName>
</driver>
<driver>
<name>chromedriver</name>
<platform>windows</platform>
<version>2.9.0</version>
<customFileName>chrome-windows-custom</customFileName>
</driver>
</drivers>
</configuration>
</plugin>
</plugins>
</build>
</project>

0 comments on commit b2d915c

Please sign in to comment.