From 8d84afccec214856852fd812aa26a50e88e1f9e7 Mon Sep 17 00:00:00 2001 From: codeboyzhou Date: Tue, 30 Nov 2021 00:41:12 +0800 Subject: [PATCH] fix(scripts): install_local_driver.sh can't download driver successfully (#722) --- .../microsoft/playwright/impl/DriverJar.java | 2 +- .../com/microsoft/playwright/TestInstall.java | 1 - .../playwright/impl/BrowserContextImpl.java | 7 ++---- .../playwright/impl/PlaywrightImpl.java | 4 +-- .../playwright/impl/Serialization.java | 4 +-- .../com/microsoft/playwright/impl/Utils.java | 6 ++--- scripts/install_local_driver.sh | 25 ++++++++----------- 7 files changed, 21 insertions(+), 28 deletions(-) diff --git a/driver-bundle/src/main/java/com/microsoft/playwright/impl/DriverJar.java b/driver-bundle/src/main/java/com/microsoft/playwright/impl/DriverJar.java index 058c570b..1cb24319 100644 --- a/driver-bundle/src/main/java/com/microsoft/playwright/impl/DriverJar.java +++ b/driver-bundle/src/main/java/com/microsoft/playwright/impl/DriverJar.java @@ -28,7 +28,7 @@ public class DriverJar extends Driver { private static final String PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = "PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD"; private final Path driverTempDir; - DriverJar() throws IOException, URISyntaxException, InterruptedException { + DriverJar() throws IOException { driverTempDir = Files.createTempDirectory("playwright-java-"); driverTempDir.toFile().deleteOnExit(); } diff --git a/driver-bundle/src/test/java/com/microsoft/playwright/TestInstall.java b/driver-bundle/src/test/java/com/microsoft/playwright/TestInstall.java index 43d76d7e..2446ea1c 100644 --- a/driver-bundle/src/test/java/com/microsoft/playwright/TestInstall.java +++ b/driver-bundle/src/test/java/com/microsoft/playwright/TestInstall.java @@ -24,7 +24,6 @@ import java.nio.file.Path; import java.util.Collections; import java.util.concurrent.TimeUnit; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; public class TestInstall { diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/BrowserContextImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/BrowserContextImpl.java index 5554d8d4..ccd2eda0 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/BrowserContextImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/BrowserContextImpl.java @@ -30,10 +30,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.Consumer; import java.util.function.Predicate; import java.util.regex.Pattern; @@ -174,7 +171,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext { @Override public List cookies(String url) { - return cookies(url == null ? new ArrayList<>() : asList(url)); + return cookies(url == null ? new ArrayList<>() : Collections.singletonList(url)); } private void closeImpl() { diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/PlaywrightImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/PlaywrightImpl.java index b70b9498..d2c9ffc4 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/PlaywrightImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/PlaywrightImpl.java @@ -57,7 +57,7 @@ public class PlaywrightImpl extends ChannelOwner implements Playwright { private final BrowserTypeImpl webkit; private final SelectorsImpl selectors; private final APIRequestImpl apiRequest; - private SharedSelectors sharedSelectors;; + private SharedSelectors sharedSelectors; PlaywrightImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) { super(parent, type, guid, initializer); @@ -72,7 +72,7 @@ public class PlaywrightImpl extends ChannelOwner implements Playwright { void initSharedSelectors(PlaywrightImpl parent) { assert sharedSelectors == null; if (parent == null) { - sharedSelectors = new SharedSelectors();; + sharedSelectors = new SharedSelectors(); } else { sharedSelectors = parent.sharedSelectors; } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java b/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java index d857dd91..7fb59a7e 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java @@ -33,7 +33,7 @@ import java.nio.file.Path; import java.util.*; class Serialization { - private static Gson gson = new GsonBuilder() + private static final Gson gson = new GsonBuilder() .registerTypeAdapter(SameSiteAttribute.class, new SameSiteAdapter().nullSafe()) .registerTypeAdapter(BrowserChannel.class, new ToLowerCaseAndDashSerializer()) .registerTypeAdapter(ColorScheme.class, new ToLowerCaseAndDashSerializer()) @@ -50,7 +50,7 @@ class Serialization { .registerTypeHierarchyAdapter(JSHandleImpl.class, new HandleSerializer()) .registerTypeAdapter((new TypeToken>(){}).getType(), new StringMapSerializer()) .registerTypeAdapter((new TypeToken>(){}).getType(), new FirefoxUserPrefsSerializer()) - .registerTypeHierarchyAdapter(Path.class, new PathSerializer()).create();; + .registerTypeHierarchyAdapter(Path.class, new PathSerializer()).create(); static Gson gson() { return gson; diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java b/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java index 1d704cfe..0f0a7021 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java @@ -78,7 +78,7 @@ class Utils { for (int i = 0; i < glob.length(); ++i) { char c = glob.charAt(i); if (escapeGlobChars.contains(c)) { - tokens.append("\\" + c); + tokens.append("\\").append(c); continue; } if (c == '*') { @@ -116,7 +116,7 @@ class Utils { tokens.append('|'); break; } - tokens.append("\\" + c); + tokens.append("\\").append(c); break; default: tokens.append(c); @@ -164,7 +164,7 @@ class Utils { try { Files.createDirectories(dir); } catch (IOException e) { - throw new PlaywrightException("Failed to create parent directory: " + dir.toString(), e); + throw new PlaywrightException("Failed to create parent directory: " + dir, e); } } } diff --git a/scripts/install_local_driver.sh b/scripts/install_local_driver.sh index 7e094c68..e5797800 100755 --- a/scripts/install_local_driver.sh +++ b/scripts/install_local_driver.sh @@ -3,19 +3,14 @@ set -e set +x -trap "cd $(pwd -P)" EXIT -cd "$(dirname $0)" +trap 'cd $(pwd -P)' EXIT +cd "$(dirname "$0")" CLI_VERSION=$(head -1 ./CLI_VERSION) -FILE_PREFIX=playwright-cli-$CLI_VERSION +FILE_PREFIX=playwright-$CLI_VERSION cd ../driver-bundle/src/main/resources -if [[ -d local-driver ]]; then - echo "$(pwd)/driver already exists, delete it first" - exit 1; -fi - PLATFORM="unknown" case $(uname) in Darwin) @@ -32,7 +27,7 @@ MINGW64*) ;; *) echo "Unknown platform '$(uname)'" - exit 1; + exit 1 ;; esac @@ -48,12 +43,14 @@ cd $PLATFORM FILE_NAME=$FILE_PREFIX-$PLATFORM.zip echo "Downloading driver for $PLATFORM to $(pwd)" -URL=https://playwright.azureedge.net/builds/cli -if [[ $CLI_VERSION == *"next"* ]]; then +URL=https://playwright.azureedge.net/builds/driver +if [[ "$CLI_VERSION" == *-alpha* || "$CLI_VERSION" == *-beta* || "$CLI_VERSION" == *-next* ]]; then URL=$URL/next fi -curl -O $URL/$FILE_NAME +URL=$URL/$FILE_NAME +echo "Using url: $URL" +curl -O "$URL" -unzip ${FILE_NAME} -d . -rm $FILE_NAME +unzip "${FILE_NAME}" -d . +rm "$FILE_NAME" ./playwright-cli install