-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First step of repository parser code rewrite in preparation for #21 and
- Loading branch information
Showing
20 changed files
with
726 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/lazerycode/selenium/hash/HashTypeAdaptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.lazerycode.selenium.hash; | ||
|
||
import javax.xml.bind.annotation.adapters.XmlAdapter; | ||
|
||
public class HashTypeAdaptor extends XmlAdapter<String, HashType> { | ||
|
||
@Override | ||
public HashType unmarshal(String str) throws Exception { | ||
return HashType.valueOf(str.toUpperCase()); | ||
} | ||
|
||
@Override | ||
public String marshal(HashType hashType) throws Exception { | ||
return hashType.toString().toLowerCase(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/com/lazerycode/selenium/repository/DriverContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.lazerycode.selenium.repository; | ||
|
||
public class DriverContext { | ||
private final BinaryType driverType; | ||
private final SystemArchitecture systemArchitecture; | ||
private final OperatingSystem operatingSystem; | ||
|
||
private DriverContext(BinaryType driverType, OperatingSystem operatingSystem, SystemArchitecture systemArchitecture) { | ||
this.operatingSystem = operatingSystem; | ||
this.driverType = driverType; | ||
this.systemArchitecture = systemArchitecture; | ||
} | ||
|
||
private DriverContext(String driverType, String operatingSystem, SystemArchitecture systemArchitecture) { | ||
this.operatingSystem = OperatingSystem.valueOf(operatingSystem.toUpperCase()); | ||
this.driverType = BinaryType.valueOf(driverType.toUpperCase()); | ||
this.systemArchitecture = systemArchitecture; | ||
} | ||
|
||
public static DriverContext binaryDataFor(BinaryType browserType, OperatingSystem osName, SystemArchitecture architecture) { | ||
return new DriverContext(browserType, osName, architecture); | ||
} | ||
|
||
public static DriverContext binaryDataFor(String browserType, String osName, SystemArchitecture architecture) { | ||
return new DriverContext(browserType, osName, architecture); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
DriverContext that = (DriverContext) o; | ||
|
||
if (driverType != that.driverType) return false; | ||
if (operatingSystem != that.operatingSystem) return false; | ||
if (systemArchitecture != that.systemArchitecture) return false; | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = driverType.hashCode(); | ||
result = 31 * result + systemArchitecture.hashCode(); | ||
result = 31 * result + operatingSystem.hashCode(); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.operatingSystem.getOperatingSystemType() + " - " + this.driverType.toString().toLowerCase() + " - " + this.systemArchitecture.getSystemArchitectureType(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/lazerycode/selenium/repository/DriverDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.lazerycode.selenium.repository; | ||
|
||
import com.lazerycode.selenium.hash.HashType; | ||
import com.lazerycode.selenium.hash.HashTypeAdaptor; | ||
|
||
import javax.xml.bind.annotation.XmlAccessType; | ||
import javax.xml.bind.annotation.XmlAccessorType; | ||
import javax.xml.bind.annotation.XmlElement; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | ||
import java.net.URL; | ||
|
||
@XmlRootElement | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
public class DriverDetails { | ||
|
||
@XmlElement(name = "filelocation") | ||
URL fileLocation; | ||
|
||
@XmlElement() | ||
String hash; | ||
|
||
@XmlElement(name = "hashtype") | ||
@XmlJavaTypeAdapter(HashTypeAdaptor.class) | ||
HashType hashType; | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = fileLocation != null ? fileLocation.hashCode() : 0; | ||
result = 31 * result + (hash != null ? hash.hashCode() : 0); | ||
result = 31 * result + (hashType != null ? hashType.hashCode() : 0); | ||
return result; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/lazerycode/selenium/repository/DriverMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.lazerycode.selenium.repository; | ||
|
||
import java.util.HashMap; | ||
import java.util.NoSuchElementException; | ||
import java.util.TreeMap; | ||
|
||
public class DriverMap { | ||
|
||
protected HashMap<DriverContext, TreeMap<String, DriverDetails>> repository = new HashMap<DriverContext, TreeMap<String, DriverDetails>>(); | ||
|
||
public TreeMap<String, DriverDetails> getMapForDriverContext(DriverContext driverContext) { | ||
if (!repository.containsKey(driverContext)) { | ||
repository.put(driverContext, new TreeMap<String, DriverDetails>()); | ||
} | ||
|
||
return repository.get(driverContext); | ||
} | ||
|
||
public DriverDetails getDetailsForVersionOfDriverContext(DriverContext driverContext, String version) throws IllegalArgumentException { | ||
if (!repository.containsKey(driverContext)) { | ||
throw new IllegalArgumentException("Driver context not found in driver repository"); | ||
} | ||
|
||
TreeMap<String, DriverDetails> driverVersions = repository.get(driverContext); | ||
DriverDetails detailsToReturn = driverVersions.get(driverVersions.lastKey()); | ||
if (detailsToReturn.hashCode() == 0) { | ||
throw new NoSuchElementException("No driver version " + version + " exists for the context " + driverContext.toString()); | ||
} | ||
|
||
return detailsToReturn; | ||
} | ||
|
||
public DriverDetails getDetailsForLatestVersionOfDriverContext(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.get(driverVersions.lastKey()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/com/lazerycode/selenium/repository/FileRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.lazerycode.selenium.repository; | ||
|
||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
import javax.xml.bind.JAXBContext; | ||
import javax.xml.bind.JAXBException; | ||
import javax.xml.bind.Unmarshaller; | ||
import javax.xml.xpath.XPathExpressionException; | ||
import java.net.MalformedURLException; | ||
|
||
import static com.lazerycode.selenium.repository.SystemArchitecture.ARCHITECTURE_32_BIT; | ||
import static com.lazerycode.selenium.repository.SystemArchitecture.ARCHITECTURE_64_BIT; | ||
|
||
public class FileRepository { | ||
|
||
public static DriverMap buildDownloadableFileRepository(NodeList nodesFound) throws MalformedURLException, MojoFailureException, JAXBException, XPathExpressionException { | ||
DriverMap driverMap = new DriverMap(); | ||
Unmarshaller unmarshaller = JAXBContext.newInstance(DriverDetails.class).createUnmarshaller(); | ||
unmarshaller.setEventHandler(new unmarshallingEventHandler()); | ||
for (int nodeNumber = 0; nodeNumber < nodesFound.getLength(); nodeNumber++) { | ||
Node node = nodesFound.item(nodeNumber); | ||
String operatingSystem = node.getParentNode().getParentNode().getParentNode().getNodeName(); | ||
String driver = node.getParentNode().getParentNode().getAttributes().getNamedItem("id").getNodeValue(); | ||
String version = node.getParentNode().getAttributes().getNamedItem("id").getNodeValue(); | ||
boolean thisIs64Bit = false; | ||
boolean thisIs32Bit = false; | ||
if (node.getAttributes().getNamedItem("thirtytwobit") != null) { | ||
if (Boolean.valueOf(node.getAttributes().getNamedItem("thirtytwobit").getNodeValue())) { | ||
thisIs32Bit = true; | ||
} | ||
} | ||
if (node.getAttributes().getNamedItem("sixtyfourbit") != null) { | ||
if (Boolean.valueOf(node.getAttributes().getNamedItem("sixtyfourbit").getNodeValue())) { | ||
thisIs64Bit = true; | ||
} | ||
} | ||
|
||
DriverDetails driverDetails = unmarshaller.unmarshal(node, DriverDetails.class).getValue(); | ||
if (thisIs32Bit) { | ||
driverMap.getMapForDriverContext(DriverContext.binaryDataFor(driver, operatingSystem, ARCHITECTURE_32_BIT)).put(version, driverDetails); | ||
} | ||
if (thisIs64Bit) { | ||
driverMap.getMapForDriverContext(DriverContext.binaryDataFor(driver, operatingSystem, ARCHITECTURE_64_BIT)).put(version, driverDetails); | ||
} | ||
} | ||
|
||
return driverMap; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/lazerycode/selenium/repository/OperatingSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.lazerycode.selenium.repository; | ||
|
||
public enum OperatingSystem { | ||
|
||
WINDOWS("windows"), | ||
OSX("mac"), | ||
LINUX("linux"); | ||
|
||
private String operatingSystemName; | ||
|
||
OperatingSystem(String operatingSystemName) { | ||
this.operatingSystemName = operatingSystemName; | ||
} | ||
|
||
String getOperatingSystemType() { | ||
return operatingSystemName; | ||
} | ||
|
||
static OperatingSystem getOperatingSystem() { | ||
|
||
String name = System.getProperties().getProperty("os.name"); | ||
|
||
for (OperatingSystem operatingSystemName : values()) { | ||
if (name.toLowerCase().contains(operatingSystemName.getOperatingSystemType())) { | ||
return operatingSystemName; | ||
} | ||
} | ||
|
||
throw new IllegalArgumentException("Unrecognised operating system name '" + name + "'"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/com/lazerycode/selenium/repository/SystemArchitecture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.lazerycode.selenium.repository; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public enum SystemArchitecture { | ||
|
||
ARCHITECTURE_64_BIT("64 bit"), | ||
ARCHITECTURE_32_BIT("32 bit"); | ||
|
||
private String systemArchitectureName; | ||
|
||
SystemArchitecture(String systemArchitectureName) { | ||
this.systemArchitectureName = systemArchitectureName; | ||
} | ||
|
||
String getSystemArchitectureType() { | ||
return systemArchitectureName; | ||
} | ||
|
||
public static final SystemArchitecture defaultSystemArchitecture = ARCHITECTURE_32_BIT; | ||
private static List<String> architecture64bitNames = Arrays.asList("amd64", "x86_64"); | ||
|
||
static SystemArchitecture getSystemArchitecture() { | ||
|
||
final String currentArchitecture = System.getProperties().getProperty("os.arch"); | ||
|
||
SystemArchitecture result = defaultSystemArchitecture; | ||
|
||
if (architecture64bitNames.contains(currentArchitecture)) { | ||
result = ARCHITECTURE_64_BIT; | ||
} | ||
|
||
return result; | ||
} | ||
} |
Oops, something went wrong.