Package romanemperorsscraper.run
Class OsUtils
- java.lang.Object
-
- romanemperorsscraper.run.OsUtils
-
public class OsUtils extends java.lang.Object
Utility class providing methods that should exhibit a different behavior depending on the Operating System the program is running in, like setting and getting a WebDriver session for scraping or the OS detection itself.- Author:
- Matteo Collica
- See Also:
UnsupportedOsException
,NoSupportedBrowsersException
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OsUtils.SupportedBrowser
static class
OsUtils.SupportedOs
-
Field Summary
Fields Modifier and Type Field Description private static OsUtils.SupportedBrowser
BROWSER
private static java.lang.String
DRIVERS_BASE_PATH
private static java.lang.String
OS
private static OsUtils.SupportedOs
OSTYPE
private static java.lang.String
TEMP_FILES_PATH
-
Constructor Summary
Constructors Modifier Constructor Description private
OsUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
copyFile(java.io.InputStream source, java.lang.String destination)
Write input data to a specific destination file and set it as executablestatic org.openqa.selenium.WebDriver
getWebDriver()
Create and get a new WebDriver instance based on the user's first supported browser found, with a Firefox > Chrome > Edge > (Safari / IE) priority;
Set the drivers' path if they're needed and were not already set.static void
initializeOs()
Detect and store the user's Operating System type needed for the OsUtils class' methodsstatic boolean
isMac()
static boolean
isUnix()
static boolean
isWindows()
static void
setWebDriverSystemPath(OsUtils.SupportedBrowser TARGET_BROWSER)
Given a browser, set the corresponding driver path System Property (required by Selenium to get the WebDriver's instances working) differently based on the user's Operating System
-
-
-
Field Detail
-
TEMP_FILES_PATH
private static final java.lang.String TEMP_FILES_PATH
-
DRIVERS_BASE_PATH
private static final java.lang.String DRIVERS_BASE_PATH
- See Also:
- Constant Field Values
-
OS
private static final java.lang.String OS
-
OSTYPE
private static OsUtils.SupportedOs OSTYPE
-
BROWSER
private static OsUtils.SupportedBrowser BROWSER
-
-
Method Detail
-
getWebDriver
public static org.openqa.selenium.WebDriver getWebDriver() throws NoSupportedBrowsersException
Create and get a new WebDriver instance based on the user's first supported browser found, with a Firefox > Chrome > Edge > (Safari / IE) priority;
Set the drivers' path if they're needed and were not already set.- Returns:
- the newly created WebDriver instance.
- Throws:
NoSupportedBrowsersException
- if no supported browser is installed or functioning with Selenium in the user's operating system.
-
setWebDriverSystemPath
public static void setWebDriverSystemPath(OsUtils.SupportedBrowser TARGET_BROWSER)
Given a browser, set the corresponding driver path System Property (required by Selenium to get the WebDriver's instances working) differently based on the user's Operating System- Parameters:
TARGET_BROWSER
- the browser the driver path should be set for
-
copyFile
public static void copyFile(java.io.InputStream source, java.lang.String destination)
Write input data to a specific destination file and set it as executable- Parameters:
source
- the input datadestination
- the destination path of the file the input data should be written into
-
initializeOs
public static void initializeOs() throws UnsupportedOsException
Detect and store the user's Operating System type needed for the OsUtils class' methods- Throws:
UnsupportedOsException
- if the Operating System the user is running this program in isn't Windows, macOS or Unix-based.
-
isWindows
public static boolean isWindows()
- Returns:
- true if the Operating System name stored in the OS class field implies a Windows-based one, false otherwise
-
isMac
public static boolean isMac()
- Returns:
- true if the Operating System name stored in the OS class field implies a macOS-based one, false otherwise
-
isUnix
public static boolean isUnix()
- Returns:
- true if the Operating System name stored in the OS class field implies a Unix-based one, false otherwise
-
-