diff --git a/.github/workflows/test_cli.yml b/.github/workflows/test_cli.yml index df206608..52801895 100644 --- a/.github/workflows/test_cli.yml +++ b/.github/workflows/test_cli.yml @@ -29,3 +29,6 @@ jobs: - name: Test CLI version shell: bash run: tools/test-cli-version/test.sh + - name: Test CLI Fatjar + shell: bash + run: tools/test-cli-fatjar/test.sh diff --git a/driver-bundle/src/main/java/com/microsoft/playwright/impl/driver/jar/DriverJar.java b/driver-bundle/src/main/java/com/microsoft/playwright/impl/driver/jar/DriverJar.java index 0e5eb5c6..74fd9a4e 100644 --- a/driver-bundle/src/main/java/com/microsoft/playwright/impl/driver/jar/DriverJar.java +++ b/driver-bundle/src/main/java/com/microsoft/playwright/impl/driver/jar/DriverJar.java @@ -106,14 +106,25 @@ public class DriverJar extends Driver { return name.endsWith(".sh") || name.endsWith(".exe") || !name.contains("."); } - void extractDriverToTempDir() throws URISyntaxException, IOException { + private FileSystem initFileSystem(URI uri) throws IOException { + try { + return FileSystems.newFileSystem(uri, Collections.emptyMap()); + } catch (FileSystemAlreadyExistsException e) { + return null; + } + } + + public static URI getDriverResourceURI() throws URISyntaxException { ClassLoader classloader = Thread.currentThread().getContextClassLoader(); - URI originalUri = classloader.getResource( - "driver/" + platformDir()).toURI(); + return classloader.getResource("driver/" + platformDir()).toURI(); + } + + void extractDriverToTempDir() throws URISyntaxException, IOException { + URI originalUri = getDriverResourceURI(); URI uri = maybeExtractNestedJar(originalUri); // Create zip filesystem if loading from jar. - try (FileSystem fileSystem = "jar".equals(uri.getScheme()) ? FileSystems.newFileSystem(uri, Collections.emptyMap()) : null) { + try (FileSystem fileSystem = "jar".equals(uri.getScheme()) ? initFileSystem(uri) : null) { Path srcRoot = Paths.get(uri); // jar file system's .relativize gives wrong results when used with // spring-boot-maven-plugin, convert to the default filesystem to diff --git a/tools/test-cli-fatjar/pom.xml b/tools/test-cli-fatjar/pom.xml new file mode 100644 index 00000000..7b1dbeab --- /dev/null +++ b/tools/test-cli-fatjar/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + com.microsoft.playwright + test-cli-fatjar + 1.29.0-SNAPSHOT + Test Playwright Command Line FatJar + + 1.8 + UTF-8 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + ${compiler.version} + ${compiler.version} + + + + + + + com.microsoft.playwright + playwright + ${project.version} + + + com.microsoft.playwright + driver-bundle + ${project.version} + + + diff --git a/tools/test-cli-fatjar/src/main/java/com/microsoft/playwright/testclifatjar/TestApp.java b/tools/test-cli-fatjar/src/main/java/com/microsoft/playwright/testclifatjar/TestApp.java new file mode 100644 index 00000000..03e34f22 --- /dev/null +++ b/tools/test-cli-fatjar/src/main/java/com/microsoft/playwright/testclifatjar/TestApp.java @@ -0,0 +1,28 @@ +package com.microsoft.playwright.testclifatjar; + +import com.microsoft.playwright.Browser; +import com.microsoft.playwright.Page; +import com.microsoft.playwright.Playwright; +import com.microsoft.playwright.impl.driver.Driver; +import com.microsoft.playwright.impl.driver.jar.DriverJar; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.util.Collections; + +public class TestApp { + public static void main(String[] args) throws IOException, URISyntaxException { + URI uri = DriverJar.getDriverResourceURI(); + FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap()); + if (fs == null) { + throw new RuntimeException(); + } + try (Playwright playwright = Playwright.create()) { + Browser browser = playwright.chromium().launch(); + Page page = browser.newPage(); + } + } +} diff --git a/tools/test-cli-fatjar/test.sh b/tools/test-cli-fatjar/test.sh new file mode 100755 index 00000000..44f3610d --- /dev/null +++ b/tools/test-cli-fatjar/test.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e +set +x + +trap "cd $(pwd -P)" EXIT +cd "$(dirname $0)" + +echo "Running TestApp..." +mvn compile exec:java -e -Dexec.mainClass=com.microsoft.playwright.testclifatjar.TestApp