diff --git a/.editorconfig b/.editorconfig index 318a84fae..969b3204f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,7 +9,7 @@ insert_final_newline = true indent_style = space indent_size = 4 -[*.{feature, yml}] +[*.{feature,yml}] indent_style = space indent_size = 2 diff --git a/selcukes-collections/src/main/java/io/github/selcukes/collections/DataTable.java b/selcukes-collections/src/main/java/io/github/selcukes/collections/DataTable.java index 82c74eaac..1b11ffcd3 100644 --- a/selcukes-collections/src/main/java/io/github/selcukes/collections/DataTable.java +++ b/selcukes-collections/src/main/java/io/github/selcukes/collections/DataTable.java @@ -455,7 +455,7 @@ public Map aggregateByColumn(@NonNull K columnName, @NonNull K groupColumn /** * Returns a string representation of a {@link DataTable}. The output table - * is formatted to align columns and provide a separator line between the + * is formatted to align columns and provides a separator line between the * header and data rows. The width of each column is determined by the * length of the longest data value for that column. * @@ -489,4 +489,19 @@ public String toString() { forEach(row -> table.add(row.values().toString())); return table.toString(); } + + /** + * Converts the {@link DataTable} to a CSV format. + *

+ * This method uses the {@link TextTable} utility class to format the CSV + * output. The resulting CSV string represents the DataTable in a + * standardized format with aligned columns and a separator line between the + * header and data rows. The width of each column is determined by the + * length of the longest data value for that column. + * + * @return a string representing the DataTable in CSV format + */ + public String toCSV() { + return TextTable.of(this).printCSV(); + } } diff --git a/selcukes-collections/src/main/java/io/github/selcukes/collections/Resources.java b/selcukes-collections/src/main/java/io/github/selcukes/collections/Resources.java index ba5e1157a..46afb78b1 100644 --- a/selcukes-collections/src/main/java/io/github/selcukes/collections/Resources.java +++ b/selcukes-collections/src/main/java/io/github/selcukes/collections/Resources.java @@ -25,9 +25,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.net.MalformedURLException; import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; @@ -95,15 +93,15 @@ public String createFile(final Path filePath) { * Writes the provided content to a file at the specified path using UTF-8 * encoding. * - * @param fileContent The content to be written to the file. * @param filePath The path of the file to which the content * will be written. + * @param fileContent The content to be written to the file. * @return The path of the file where the content was * successfully written. * @throws DataStreamException If an I/O error occurs while writing the * content to the file. */ - public Path writeToFile(final @NonNull String fileContent, final Path filePath) { + public Path writeToFile(final Path filePath, final @NonNull String fileContent) { try { return Files.write(filePath, fileContent.getBytes(UTF_8)); } catch (IOException e) { @@ -111,6 +109,26 @@ public Path writeToFile(final @NonNull String fileContent, final Path filePath) } } + /** + * Writes the provided content to a file at the specified path using UTF-8 + * encoding. + * + * @param filePath The path of the file to which the content + * will be written. + * @param fileContent The content to be written to the file. + * @return The path of the file where the content was + * successfully written. + * @throws DataStreamException If an I/O error occurs while writing the + * content to the file. + */ + public Path writeToFile(final Path filePath, final @NonNull Iterable fileContent) { + try { + return Files.write(filePath, fileContent, UTF_8); + } catch (IOException e) { + throw new DataStreamException("Failed to write content to file: " + filePath.toAbsolutePath(), e); + } + } + /** * Copies a file from the source path to the destination path. * @@ -246,11 +264,8 @@ public static OutputStream newOutputStream(Path filePath) { * be parsed */ public URL toURL(String urlStr) { - try { - return new URL(urlStr); - } catch (MalformedURLException e) { - throw new IllegalArgumentException("Invalid URL string: " + urlStr, e); - } + return tryURL(urlStr) + .orElseThrow(() -> new IllegalArgumentException("Invalid URL string: " + urlStr)); } /** @@ -264,27 +279,9 @@ public URL toURL(String urlStr) { */ public Optional tryURL(String urlStr) { try { - return Optional.of(new URL(urlStr)); - } catch (MalformedURLException e) { + return Optional.of(new URI(urlStr).toURL()); + } catch (Exception e) { return Optional.empty(); } } - - /** - * Returns a new URI object by parsing the given URI string. - * - * @param uriStr the URI string to be parsed into a URI - * object - * @return the URI object representing the parsed - * URI string - * @throws IllegalArgumentException if the URI string is invalid and cannot - * be parsed - */ - public URI toURI(String uriStr) { - try { - return new URI(uriStr); - } catch (URISyntaxException e) { - throw new IllegalArgumentException("Invalid URI string: " + uriStr, e); - } - } } diff --git a/selcukes-collections/src/main/java/io/github/selcukes/collections/Streams.java b/selcukes-collections/src/main/java/io/github/selcukes/collections/Streams.java index 6208501b9..40e2e02ac 100644 --- a/selcukes-collections/src/main/java/io/github/selcukes/collections/Streams.java +++ b/selcukes-collections/src/main/java/io/github/selcukes/collections/Streams.java @@ -45,6 +45,17 @@ public Stream of(final Iterator iterator) { .stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false); } + /** + * Converts an Iterable to a Stream. + * + * @param iterable The iterable to convert to a stream. + * @param The type of elements in the iterable. + * @return A stream of the iterable. + */ + public static Stream of(final Iterable iterable) { + return StreamSupport.stream(iterable.spliterator(), false); + } + /** * Returns an OptionalInt that contains the index of the first element in * the list that matches the given predicate, or an empty OptionalInt if no diff --git a/selcukes-collections/src/main/java/io/github/selcukes/collections/TextTable.java b/selcukes-collections/src/main/java/io/github/selcukes/collections/TextTable.java index cc884f579..9663a4c49 100644 --- a/selcukes-collections/src/main/java/io/github/selcukes/collections/TextTable.java +++ b/selcukes-collections/src/main/java/io/github/selcukes/collections/TextTable.java @@ -19,6 +19,7 @@ import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; +import java.util.stream.Stream; class TextTable { private final DataTable table; @@ -66,6 +67,27 @@ public String printTable() { return separator + "\n" + header + "|\n" + separator + "\n" + rows + "\n" + separator + "\n"; } + public String printCSV() { + return Stream.concat( + Stream.of(getCSVRow(table.getColumns())), + table.stream().map(row -> getCSVRow(row.values()))) + .collect(Collectors.joining("\n")); + } + + private String getCSVRow(Iterable values) { + return Streams.of(values) + .map(Object::toString) + .map(this::escapeCsvValue) + .collect(Collectors.joining(",")); + } + + private String escapeCsvValue(String value) { + if (value.contains(",") || value.contains("\"") || value.contains("\n")) { + return "\"" + value.replace("\"", "\"\"") + "\""; + } + return value; + } + public String printHtmlTable() { var htmlTable = new HtmlTable(); return htmlTable.buildTable(table); @@ -74,13 +96,11 @@ public String printHtmlTable() { private static class HtmlTable { public String buildTable(DataTable table) { - StringBuilder sb = new StringBuilder(); - sb.append("\n"); - sb.append(buildHeaderRow(table.getFirst())); - sb.append(buildDataRows(table)); - sb.append("
"); - return sb.toString(); + return "\n" + + buildHeaderRow(table.getFirst()) + + buildDataRows(table) + + "
"; } private String buildHeaderRow(Map row) { diff --git a/selcukes-collections/src/main/java/io/github/selcukes/collections/Try.java b/selcukes-collections/src/main/java/io/github/selcukes/collections/Try.java index 4969b5d61..f40cf4c51 100644 --- a/selcukes-collections/src/main/java/io/github/selcukes/collections/Try.java +++ b/selcukes-collections/src/main/java/io/github/selcukes/collections/Try.java @@ -16,6 +16,8 @@ package io.github.selcukes.collections; +import lombok.Getter; + import java.util.Optional; import java.util.function.Function; import java.util.function.Supplier; @@ -30,6 +32,8 @@ */ public class Try { private final T result; + + @Getter private final Exception exception; /** @@ -168,16 +172,6 @@ public Optional getResult() { return Optional.ofNullable(result); } - /** - * Returns the cause of the failure represented by this Try object. - * - * @return the cause of the failure represented by this Try object, or null - * if this Try object represents a success - */ - public Exception getException() { - return exception; - } - /** * Applies the given function to the result of this Try, which produces a * new Try. If this Try contains an exception, a new Try containing the diff --git a/selcukes-commons/src/main/java/io/github/selcukes/commons/Await.java b/selcukes-commons/src/main/java/io/github/selcukes/commons/Await.java index cab66b9c6..318828886 100644 --- a/selcukes-commons/src/main/java/io/github/selcukes/commons/Await.java +++ b/selcukes-commons/src/main/java/io/github/selcukes/commons/Await.java @@ -83,14 +83,11 @@ public boolean until(Callable conditionEvaluator) { stopwatch += pollTimeout; } catch (InterruptedException e) { Thread.currentThread().interrupt(); - logger.error(e, () -> "Interrupted while waiting for condition"); return false; } catch (Exception e) { - logger.error(e, () -> "Error while evaluating condition"); return false; } } - logger.error(() -> "Condition not met within the given time"); return false; } } diff --git a/selcukes-commons/src/main/java/io/github/selcukes/commons/exec/Shell.java b/selcukes-commons/src/main/java/io/github/selcukes/commons/exec/Shell.java index de2321c1e..bdb418e61 100644 --- a/selcukes-commons/src/main/java/io/github/selcukes/commons/exec/Shell.java +++ b/selcukes-commons/src/main/java/io/github/selcukes/commons/exec/Shell.java @@ -84,7 +84,6 @@ private ExecResults interactWithProcess(final Process process) { // Wait for all the tasks to complete. Await.until(1); } - return new ExecResults(output.getContent(), error.getContent(), process.exitValue()); } diff --git a/selcukes-commons/src/main/java/io/github/selcukes/commons/helper/FileHelper.java b/selcukes-commons/src/main/java/io/github/selcukes/commons/helper/FileHelper.java index 0f3eb75ce..cf67d52d5 100644 --- a/selcukes-commons/src/main/java/io/github/selcukes/commons/helper/FileHelper.java +++ b/selcukes-commons/src/main/java/io/github/selcukes/commons/helper/FileHelper.java @@ -16,6 +16,7 @@ package io.github.selcukes.commons.helper; +import io.github.selcukes.collections.Resources; import io.github.selcukes.commons.exception.ConfigurationException; import lombok.SneakyThrows; import lombok.experimental.UtilityClass; @@ -358,7 +359,7 @@ public String downloadToUsersFolder(final String url) { if (file.exists()) { return file.getPath(); } - download(new URL(url), file); + download(Resources.toURL(url), file); return file.getPath(); } @@ -369,8 +370,8 @@ public String downloadToUsersFolder(final String url) { * @return The content of the file. */ public String readContent(final String filePath) { - try { - return new String(loadResourceFromJar(filePath).readAllBytes(), StandardCharsets.UTF_8); + try (var inputStream = loadResourceFromJar(filePath)) { + return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); } catch (Exception e) { throw new ConfigurationException(String.format("Cannot load [%s] from classpath", filePath)); } diff --git a/selcukes-commons/src/main/java/io/github/selcukes/commons/http/WebClient.java b/selcukes-commons/src/main/java/io/github/selcukes/commons/http/WebClient.java index de22f848b..c1a128117 100644 --- a/selcukes-commons/src/main/java/io/github/selcukes/commons/http/WebClient.java +++ b/selcukes-commons/src/main/java/io/github/selcukes/commons/http/WebClient.java @@ -315,6 +315,6 @@ private String encode(String value) { private URI buildUri() { var joiner = new StringJoiner("&"); queryParams.forEach((key, value) -> joiner.add(encode(key) + "=" + encode(value))); - return Resources.toURI(baseUri + endpoint + (baseUri.contains("?") ? "&" : "?") + joiner); + return URI.create(baseUri + endpoint + (baseUri.contains("?") ? "&" : "?") + joiner); } } diff --git a/selcukes-commons/src/main/java/io/github/selcukes/commons/http/WebResponse.java b/selcukes-commons/src/main/java/io/github/selcukes/commons/http/WebResponse.java index d0be70af8..ec8ecc0c3 100644 --- a/selcukes-commons/src/main/java/io/github/selcukes/commons/http/WebResponse.java +++ b/selcukes-commons/src/main/java/io/github/selcukes/commons/http/WebResponse.java @@ -36,8 +36,8 @@ * It takes the HTTP response and provides a number of methods to access the * response body, headers, and status code */ +@Getter public class WebResponse { - @Getter private final HttpResponse httpResponse; public WebResponse(final HttpResponse httpResponse) { diff --git a/selcukes-commons/src/main/java/io/github/selcukes/commons/os/Architecture.java b/selcukes-commons/src/main/java/io/github/selcukes/commons/os/Architecture.java index f8fa78f4a..4c5aa7fcb 100644 --- a/selcukes-commons/src/main/java/io/github/selcukes/commons/os/Architecture.java +++ b/selcukes-commons/src/main/java/io/github/selcukes/commons/os/Architecture.java @@ -19,11 +19,11 @@ import lombok.AllArgsConstructor; import lombok.Getter; +@Getter @AllArgsConstructor public enum Architecture { X32(32), X64(64); - @Getter final int value; } diff --git a/selcukes-core/src/main/java/io/github/selcukes/core/grid/SeleniumService.java b/selcukes-core/src/main/java/io/github/selcukes/core/grid/SeleniumService.java index cccb0fe7c..61c2fbf9c 100644 --- a/selcukes-core/src/main/java/io/github/selcukes/core/grid/SeleniumService.java +++ b/selcukes-core/src/main/java/io/github/selcukes/core/grid/SeleniumService.java @@ -29,7 +29,6 @@ import org.openqa.selenium.os.ExternalProcess; import java.io.File; -import java.net.MalformedURLException; import java.net.URL; import java.util.LinkedList; import java.util.List; @@ -89,7 +88,7 @@ public SeleniumService start(String mode, String... extraFlags) { process = builder.start(); try { - var url = new URL(baseUrl + "/status"); + var url = Resources.toURL(baseUrl + "/status"); new UrlChecker().waitUntilAvailable(10, SECONDS, url); logger.info(() -> "Selenium Server is ready..."); } catch (UrlChecker.TimeoutException e) { @@ -97,7 +96,7 @@ public SeleniumService start(String mode, String... extraFlags) { process.shutdown(); process = null; throw new DriverConnectionException(e); - } catch (MalformedURLException e) { + } catch (Exception e) { throw new DriverConnectionException(e); } @@ -123,7 +122,7 @@ public void stop() { */ @SneakyThrows public URL getServiceUrl() { - return new URL(baseUrl); + return Resources.toURL(baseUrl); } /** @@ -135,10 +134,10 @@ public URL getServiceUrl() { @SneakyThrows public String getServerJar() { var seleniumServerJar = ConfigFactory.getConfig().getWeb().getServerJar(); - var serverJarUrl = new URL(seleniumServerJar); - var reportsPath = ofNullable(ConfigFactory.getConfig().getReports()) + var serverJarUrl = Resources.toURL(seleniumServerJar); + var reportPath = ofNullable(ConfigFactory.getConfig().getReports()) .map(reports -> reports.get("path")).orElse("target"); - var serverJarPath = Resources.of(reportsPath + "/selenium-server.jar"); + var serverJarPath = Resources.of(reportPath + "/selenium-server.jar"); FileHelper.download(serverJarUrl, serverJarPath.toFile()); return serverJarPath.toAbsolutePath().toString(); } diff --git a/selcukes-core/src/main/java/io/github/selcukes/core/page/ui/Dropdown.java b/selcukes-core/src/main/java/io/github/selcukes/core/page/ui/Dropdown.java index 67fec7f4e..c4f3d7f79 100644 --- a/selcukes-core/src/main/java/io/github/selcukes/core/page/ui/Dropdown.java +++ b/selcukes-core/src/main/java/io/github/selcukes/core/page/ui/Dropdown.java @@ -48,15 +48,14 @@ public Object selected(Select select, String optionLocator) { return type.getRetriever().apply(select); } + @Getter @AllArgsConstructor enum SelectionType { LABEL(Select::selectByVisibleText, select -> select.getFirstSelectedOption().getText()), VALUE(Select::selectByValue, select -> select.getFirstSelectedOption().getAttribute(ATTRIBUTE)), INDEX((select, value) -> select.selectByIndex(parseInt(value)), select -> select.getOptions().indexOf(select.getFirstSelectedOption())); - @Getter private final BiConsumer selector; - @Getter private final Function retriever; } diff --git a/selcukes-databind/src/main/java/io/github/selcukes/databind/csv/CsvMapper.java b/selcukes-databind/src/main/java/io/github/selcukes/databind/csv/CsvMapper.java index 0f315d2ff..70af32c3e 100644 --- a/selcukes-databind/src/main/java/io/github/selcukes/databind/csv/CsvMapper.java +++ b/selcukes-databind/src/main/java/io/github/selcukes/databind/csv/CsvMapper.java @@ -18,6 +18,7 @@ import io.github.selcukes.collections.DataTable; import io.github.selcukes.collections.Lists; +import io.github.selcukes.collections.Resources; import io.github.selcukes.collections.Streams; import io.github.selcukes.databind.exception.DataMapperException; import lombok.experimental.UtilityClass; @@ -64,4 +65,30 @@ public DataTable parse(Path filePath, String regex) { public DataTable parse(Path filePath) { return parse(filePath, CSV_REGEX); } + + /** + * Writes a DataTable to a CSV file at the specified path. + * + * @param filePath the path to the CSV file + * @param dataTable the data to be written to the CSV file + * @throws DataMapperException if an error occurs while writing to the file + */ + public void write(Path filePath, DataTable dataTable) { + write(filePath, dataTable.toCSV()); + } + + /** + * Writes a string of CSV data to a CSV file at the specified path. + * + * @param filePath the path to the CSV file + * @param data the CSV data to be written + * @throws DataMapperException if an error occurs while writing to the file + */ + public void write(Path filePath, String data) { + try { + Resources.writeToFile(filePath, Arrays.asList(data.split("\n"))); + } catch (Exception e) { + throw new DataMapperException("Failed writing to CSV File: ", e); + } + } } diff --git a/selcukes-databind/src/test/java/io/github/selcukes/databind/tests/CsvTest.java b/selcukes-databind/src/test/java/io/github/selcukes/databind/tests/CsvTest.java index 0b5eca3a1..5f6f074a7 100644 --- a/selcukes-databind/src/test/java/io/github/selcukes/databind/tests/CsvTest.java +++ b/selcukes-databind/src/test/java/io/github/selcukes/databind/tests/CsvTest.java @@ -23,6 +23,9 @@ import java.util.Map; import static io.github.selcukes.databind.csv.CsvMapper.CSV_STRIP_REGEX; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; public class CsvTest { @@ -30,9 +33,11 @@ public class CsvTest { public void csvDataReaderTest() { var filePath = Resources.ofTest("employee.csv"); var table = CsvMapper.parse(filePath, CSV_STRIP_REGEX); + assertFalse(table.isEmpty(), "Table should not be empty"); Map keyMapping = Map.of("Name", "FullName"); table.renameColumn(keyMapping); + assertTrue(table.getColumns().contains("FullName"), "Column 'FullName' should be present"); table.updateRows(row -> { // Update ID Column values @@ -41,7 +46,14 @@ public void csvDataReaderTest() { } return row; }); - table.forEach(System.out::println); + assertFalse(table.getColumnEntries("ID").stream().anyMatch(String::isEmpty), "ID column should not be empty"); + + var filePath1 = Resources.ofTest("employee1.csv"); + CsvMapper.write(filePath1, table); + var table1 = CsvMapper.parse(filePath1, CSV_STRIP_REGEX); + + assertFalse(table1.isEmpty(), "Written table should not be empty"); + assertEquals(table1, table, "Written table should be the same as the original table"); } private String updateID(String phone, String country) { @@ -49,5 +61,4 @@ private String updateID(String phone, String country) { var lastFourDigits = phone.substring(phone.length() - 4); return countryCode + "_DDA_" + lastFourDigits; } - } diff --git a/selcukes-extent-reports/src/main/java/io/github/selcukes/extent/report/ExtentService.java b/selcukes-extent-reports/src/main/java/io/github/selcukes/extent/report/ExtentService.java index 2ba88f19a..829de5950 100644 --- a/selcukes-extent-reports/src/main/java/io/github/selcukes/extent/report/ExtentService.java +++ b/selcukes-extent-reports/src/main/java/io/github/selcukes/extent/report/ExtentService.java @@ -28,6 +28,7 @@ import io.github.selcukes.collections.Resources; import io.github.selcukes.collections.StringHelper; import io.github.selcukes.databind.properties.PropertiesMapper; +import lombok.Getter; import java.io.IOException; import java.util.Arrays; @@ -51,6 +52,7 @@ public class ExtentService { private static final String VIEW_ORDER_SPARK_KEY = "extent.reporter.spark.vieworder"; private static final String REPORT_NAME = "Automation Report"; private static final String REPORT_TITLE = "Automation Report"; + @Getter private final ExtentReports extentReports; private final Map propertiesMap; @@ -63,10 +65,6 @@ public ExtentService(ExtentReports extentReports) { addSystemInfo(); } - public ExtentReports getExtentReports() { - return extentReports; - } - private Map initProperties() { try { return PropertiesMapper.parse(Resources.ofTest("extent.properties")); diff --git a/selcukes-extent-reports/src/main/java/io/github/selcukes/extent/report/TestSourcesModel.java b/selcukes-extent-reports/src/main/java/io/github/selcukes/extent/report/TestSourcesModel.java index 66aa1ad0e..366ed3c41 100644 --- a/selcukes-extent-reports/src/main/java/io/github/selcukes/extent/report/TestSourcesModel.java +++ b/selcukes-extent-reports/src/main/java/io/github/selcukes/extent/report/TestSourcesModel.java @@ -41,6 +41,7 @@ import java.util.Optional; import java.util.stream.Stream; +@SuppressWarnings("OptionalGetWithoutIsPresent") public final class TestSourcesModel { private final Map pathToReadEventMap = new HashMap<>(); diff --git a/selcukes-notifier/src/main/java/io/github/selcukes/notifier/enums/NotifierEnum.java b/selcukes-notifier/src/main/java/io/github/selcukes/notifier/enums/NotifierEnum.java index 8d351466c..9de80ce7a 100644 --- a/selcukes-notifier/src/main/java/io/github/selcukes/notifier/enums/NotifierEnum.java +++ b/selcukes-notifier/src/main/java/io/github/selcukes/notifier/enums/NotifierEnum.java @@ -21,6 +21,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; +@Getter @AllArgsConstructor public enum NotifierEnum { PRETEXT("Selcukes Automation Report"), @@ -37,6 +38,5 @@ public enum NotifierEnum { MESSAGE_CARD("MessageCard"), TIME_STAMP("Time Stamp"), EXCEPTION("Exception"); - @Getter final String value; } diff --git a/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/ChromeBinary.java b/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/ChromeBinary.java index 7ec81dc11..101b496ad 100644 --- a/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/ChromeBinary.java +++ b/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/ChromeBinary.java @@ -16,6 +16,7 @@ package io.github.selcukes.wdb.core; +import io.github.selcukes.collections.Resources; import io.github.selcukes.commons.exception.WebDriverBinaryException; import io.github.selcukes.commons.os.Architecture; import io.github.selcukes.commons.os.OsType; @@ -23,7 +24,6 @@ import io.github.selcukes.wdb.enums.DriverType; import io.github.selcukes.wdb.util.UrlHelper; -import java.net.MalformedURLException; import java.net.URL; import java.util.Objects; @@ -35,14 +35,14 @@ public class ChromeBinary extends AbstractBinary { @Override public URL getDownloadURL() { try { - return new URL(String.format( + return Resources.toURL(String.format( BINARY_DOWNLOAD_URL_PATTERN, UrlHelper.CHROMEDRIVER_URL, getBinaryVersion(), getBinaryEnvironment().getOsNameAndArch(), getBinaryEnvironment().getOsNameAndArch())); - } catch (MalformedURLException e) { + } catch (Exception e) { throw new WebDriverBinaryException(e); } } diff --git a/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/EdgeBinary.java b/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/EdgeBinary.java index 74e16d795..830b367b6 100644 --- a/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/EdgeBinary.java +++ b/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/EdgeBinary.java @@ -16,11 +16,11 @@ package io.github.selcukes.wdb.core; +import io.github.selcukes.collections.Resources; import io.github.selcukes.commons.exception.WebDriverBinaryException; import io.github.selcukes.wdb.enums.DriverType; import io.github.selcukes.wdb.util.UrlHelper; -import java.net.MalformedURLException; import java.net.URL; public class EdgeBinary extends AbstractBinary { @@ -29,13 +29,13 @@ public class EdgeBinary extends AbstractBinary { @Override public URL getDownloadURL() { try { - return new URL(String.format( + return Resources.toURL(String.format( BINARY_DOWNLOAD_URL_PATTERN, UrlHelper.EDGE_DRIVER_URL, getBinaryVersion(), getBinaryEnvironment().getOsNameAndArch())); - } catch (MalformedURLException e) { + } catch (Exception e) { throw new WebDriverBinaryException(e); } } diff --git a/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/FirefoxBinary.java b/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/FirefoxBinary.java index 92ef2d2a8..6557a6158 100644 --- a/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/FirefoxBinary.java +++ b/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/FirefoxBinary.java @@ -16,13 +16,13 @@ package io.github.selcukes.wdb.core; +import io.github.selcukes.collections.Resources; import io.github.selcukes.commons.exception.WebDriverBinaryException; import io.github.selcukes.commons.os.OsType; import io.github.selcukes.wdb.enums.DownloaderType; import io.github.selcukes.wdb.enums.DriverType; import io.github.selcukes.wdb.util.UrlHelper; -import java.net.MalformedURLException; import java.net.URL; import java.util.Objects; @@ -32,7 +32,7 @@ public class FirefoxBinary extends AbstractBinary { @Override public URL getDownloadURL() { try { - return new URL(String.format( + return Resources.toURL(String.format( BINARY_DOWNLOAD_URL_PATTERN, UrlHelper.GECKODRIVER_URL, getBinaryVersion(), @@ -40,7 +40,7 @@ public URL getDownloadURL() { getBinaryEnvironment().getOsNameAndArch(), getCompressedBinaryType().getName())); - } catch (MalformedURLException e) { + } catch (Exception e) { throw new WebDriverBinaryException(e); } } diff --git a/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/IExplorerBinary.java b/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/IExplorerBinary.java index f67791b70..a380c4493 100644 --- a/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/IExplorerBinary.java +++ b/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/IExplorerBinary.java @@ -16,13 +16,13 @@ package io.github.selcukes.wdb.core; +import io.github.selcukes.collections.Resources; import io.github.selcukes.commons.exception.WebDriverBinaryException; import io.github.selcukes.wdb.enums.DriverType; import io.github.selcukes.wdb.util.UrlHelper; import io.github.selcukes.wdb.util.VersionHelper; import io.github.selcukes.wdb.version.VersionComparator; -import java.net.MalformedURLException; import java.net.URL; import java.util.Map; import java.util.Optional; @@ -33,9 +33,9 @@ public class IExplorerBinary extends AbstractBinary { @Override public URL getDownloadURL() { try { - return new URL(UrlHelper.IEDRIVER_URL + "/" + latestVersionUrl); + return Resources.toURL(UrlHelper.IEDRIVER_URL + "/" + latestVersionUrl); - } catch (MalformedURLException e) { + } catch (Exception e) { throw new WebDriverBinaryException(e); } } diff --git a/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/OperaBinary.java b/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/OperaBinary.java index 4239f26b9..738c47d31 100644 --- a/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/OperaBinary.java +++ b/webdriver-binaries/src/main/java/io/github/selcukes/wdb/core/OperaBinary.java @@ -16,11 +16,11 @@ package io.github.selcukes.wdb.core; +import io.github.selcukes.collections.Resources; import io.github.selcukes.commons.exception.WebDriverBinaryException; import io.github.selcukes.wdb.enums.DriverType; import io.github.selcukes.wdb.util.UrlHelper; -import java.net.MalformedURLException; import java.net.URL; public class OperaBinary extends AbstractBinary { @@ -29,13 +29,13 @@ public class OperaBinary extends AbstractBinary { @Override public URL getDownloadURL() { try { - return new URL(String.format( + return Resources.toURL(String.format( BINARY_DOWNLOAD_URL_PATTERN, UrlHelper.OPERA_DRIVER_URL, getBinaryVersion(), getBinaryEnvironment().getOsNameAndArch(), getCompressedBinaryType().getName())); - } catch (MalformedURLException e) { + } catch (Exception e) { throw new WebDriverBinaryException(e); } } diff --git a/webdriver-binaries/src/main/java/io/github/selcukes/wdb/util/FileExtractUtil.java b/webdriver-binaries/src/main/java/io/github/selcukes/wdb/util/FileExtractUtil.java index b1bdc4f84..56b4cbc4e 100644 --- a/webdriver-binaries/src/main/java/io/github/selcukes/wdb/util/FileExtractUtil.java +++ b/webdriver-binaries/src/main/java/io/github/selcukes/wdb/util/FileExtractUtil.java @@ -64,7 +64,7 @@ private static Path unZipFile(Path source, Path destination) { try (var fis = Files.newInputStream(source, StandardOpenOption.READ); var zis = new ZipArchiveInputStream(fis)) { ZipArchiveEntry entry; - while ((entry = zis.getNextZipEntry()) != null) { + while ((entry = zis.getNextEntry()) != null) { if (!entry.getName().toUpperCase().contains("LICENSE")) { entryDestination = uncompress(zis, destination, entry); } @@ -81,7 +81,7 @@ private static Path unTarFile(Path source, Path destination) { var gZIPInputStream = new GZIPInputStream(fis); final var tis = new TarArchiveInputStream(gZIPInputStream)) { TarArchiveEntry entry; - while ((entry = tis.getNextTarEntry()) != null) { + while ((entry = tis.getNextEntry()) != null) { if (!entry.getName().toUpperCase().contains("LICENSE")) { entryDestination = uncompress(tis, destination, entry); }