-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Playwright in Runtime module and GraalVM support (#95)
* Allow Playwright in Runtime module * Native Build work * fix poms * Refactor to no longer have Test jar * Replace System.out with Jboss logging * Change category to web
- Loading branch information
Showing
30 changed files
with
1,206 additions
and
274 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
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
139 changes: 139 additions & 0 deletions
139
deployment/src/main/java/io/quarkiverse/playwright/deployment/PlaywrightProcessor.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,139 @@ | ||
package io.quarkiverse.playwright.deployment; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.TreeSet; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.DotName; | ||
|
||
import com.microsoft.playwright.Browser; | ||
import com.microsoft.playwright.ElementHandle; | ||
import com.microsoft.playwright.Playwright; | ||
import com.microsoft.playwright.impl.driver.jar.DriverJar; | ||
import com.microsoft.playwright.options.HttpHeader; | ||
import com.microsoft.playwright.options.Timing; | ||
import com.microsoft.playwright.options.ViewportSize; | ||
|
||
import io.quarkiverse.playwright.PlaywrightRecorder; | ||
import io.quarkus.deployment.IsNormal; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.ExecutionTime; | ||
import io.quarkus.deployment.annotations.Record; | ||
import io.quarkus.deployment.builditem.CombinedIndexBuildItem; | ||
import io.quarkus.deployment.builditem.FeatureBuildItem; | ||
import io.quarkus.deployment.builditem.IndexDependencyBuildItem; | ||
import io.quarkus.deployment.builditem.NativeImageEnableAllCharsetsBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourcePatternsBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; | ||
import io.quarkus.logging.Log; | ||
|
||
class PlaywrightProcessor { | ||
|
||
private static final String FEATURE = "playwright"; | ||
|
||
@BuildStep | ||
FeatureBuildItem feature() { | ||
return new FeatureBuildItem(FEATURE); | ||
} | ||
|
||
@BuildStep | ||
void indexTransitiveDependencies(BuildProducer<IndexDependencyBuildItem> index) { | ||
index.produce(new IndexDependencyBuildItem("com.microsoft.playwright", "driver")); | ||
index.produce(new IndexDependencyBuildItem("com.microsoft.playwright", "driver-bundle")); | ||
index.produce(new IndexDependencyBuildItem("com.microsoft.playwright", "playwright")); | ||
} | ||
|
||
@BuildStep | ||
NativeImageEnableAllCharsetsBuildItem enableAllCharsetsBuildItem() { | ||
return new NativeImageEnableAllCharsetsBuildItem(); | ||
} | ||
|
||
@BuildStep | ||
void registerForReflection(CombinedIndexBuildItem combinedIndex, BuildProducer<ReflectiveClassBuildItem> reflectiveClass) { | ||
//@formatter:off | ||
final List<String> classNames = new ArrayList<>(); | ||
|
||
classNames.add("com.microsoft.playwright.impl.Message"); | ||
classNames.add("com.microsoft.playwright.impl.SerializedArgument"); | ||
classNames.add("com.microsoft.playwright.impl.SerializedValue"); | ||
classNames.add("com.microsoft.playwright.impl.SerializedValue$O"); | ||
classNames.add(Browser.CloseOptions.class.getName()); | ||
classNames.add(Browser.NewContextOptions.class.getName()); | ||
classNames.add(Browser.NewPageOptions.class.getName()); | ||
classNames.add(Browser.StartTracingOptions.class.getName()); | ||
classNames.add(DriverJar.class.getName()); | ||
classNames.add(ElementHandle.CheckOptions.class.getName()); | ||
classNames.add(ElementHandle.ClickOptions.class.getName()); | ||
classNames.add(ElementHandle.DblclickOptions.class.getName()); | ||
classNames.add(ElementHandle.FillOptions.class.getName()); | ||
classNames.add(ElementHandle.HoverOptions.class.getName()); | ||
classNames.add(ElementHandle.InputValueOptions.class.getName()); | ||
classNames.add(ElementHandle.PressOptions.class.getName()); | ||
classNames.add(ElementHandle.ScreenshotOptions.class.getName()); | ||
classNames.add(ElementHandle.ScrollIntoViewIfNeededOptions.class.getName()); | ||
classNames.add(ElementHandle.SelectTextOptions.class.getName()); | ||
classNames.add(ElementHandle.SetInputFilesOptions.class.getName()); | ||
classNames.add(ElementHandle.TapOptions.class.getName()); | ||
classNames.add(ElementHandle.TypeOptions.class.getName()); | ||
classNames.add(ElementHandle.UncheckOptions.class.getName()); | ||
classNames.add(ElementHandle.WaitForElementStateOptions.class.getName()); | ||
classNames.add(ElementHandle.WaitForSelectorOptions.class.getName()); | ||
classNames.add(HttpHeader.class.getName()); | ||
classNames.add(Timing.class.getName()); | ||
classNames.add(ViewportSize.class.getName()); | ||
classNames.addAll(collectImplementors(combinedIndex, Playwright.class.getName())); | ||
|
||
//@formatter:on | ||
final TreeSet<String> uniqueClasses = new TreeSet<>(classNames); | ||
Log.debugf("Playwright Reflection: %s", uniqueClasses); | ||
|
||
reflectiveClass.produce( | ||
ReflectiveClassBuildItem.builder(uniqueClasses.toArray(new String[0])).constructors().methods().fields() | ||
.serialization().unsafeAllocated().build()); | ||
} | ||
|
||
@BuildStep(onlyIf = IsNormal.class) | ||
@Record(ExecutionTime.RUNTIME_INIT) | ||
void registerRuntimeDrivers(PlaywrightRecorder recorder) { | ||
recorder.initialize(); | ||
} | ||
|
||
@BuildStep(onlyIf = IsNormal.class) | ||
void registerNativeDrivers(BuildProducer<NativeImageResourcePatternsBuildItem> nativeImageResourcePatterns) { | ||
final NativeImageResourcePatternsBuildItem.Builder builder = NativeImageResourcePatternsBuildItem.builder(); | ||
builder.includeGlob("driver/**"); | ||
nativeImageResourcePatterns.produce(builder.build()); | ||
} | ||
|
||
private List<String> collectSubclasses(CombinedIndexBuildItem combinedIndex, String className) { | ||
List<String> classes = combinedIndex.getIndex() | ||
.getAllKnownSubclasses(DotName.createSimple(className)) | ||
.stream() | ||
.map(ClassInfo::toString) | ||
.collect(Collectors.toList()); | ||
classes.add(className); | ||
Log.debugf("Subclasses: %s", classes); | ||
return classes; | ||
} | ||
|
||
private List<String> collectImplementors(CombinedIndexBuildItem combinedIndex, String className) { | ||
Set<String> classes = combinedIndex.getIndex() | ||
.getAllKnownImplementors(DotName.createSimple(className)) | ||
.stream() | ||
.map(ClassInfo::toString) | ||
.collect(Collectors.toCollection(HashSet::new)); | ||
classes.add(className); | ||
Set<String> subclasses = new HashSet<>(); | ||
for (String implementationClass : classes) { | ||
subclasses.addAll(collectSubclasses(combinedIndex, implementationClass)); | ||
} | ||
classes.addAll(subclasses); | ||
Log.debugf("Implementors: %s", classes); | ||
return new ArrayList<>(classes); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...nt/src/main/java/io/quarkiverse/playwright/deployment/devui/PlaywrightDevUIProcessor.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,33 @@ | ||
package io.quarkiverse.playwright.deployment.devui; | ||
|
||
import com.microsoft.playwright.Playwright; | ||
|
||
import io.quarkus.deployment.IsDevelopment; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.devui.spi.page.CardPageBuildItem; | ||
import io.quarkus.devui.spi.page.ExternalPageBuilder; | ||
import io.quarkus.devui.spi.page.Page; | ||
|
||
/** | ||
* Dev UI card for displaying important details such as the Playwright library version. | ||
*/ | ||
public class PlaywrightDevUIProcessor { | ||
|
||
@BuildStep(onlyIf = IsDevelopment.class) | ||
void createVersion(BuildProducer<CardPageBuildItem> cardPageBuildItemBuildProducer) { | ||
final CardPageBuildItem card = new CardPageBuildItem(); | ||
|
||
final ExternalPageBuilder versionPage = Page.externalPageBuilder("Playwright Version") | ||
.icon("font-awesome-solid:tag") | ||
.url("https://playwright.dev") | ||
.doNotEmbed() | ||
.staticLabel(Playwright.class.getPackage().getImplementationVersion()); | ||
|
||
card.addPage(versionPage); | ||
|
||
card.setCustomCard("qwc-playwright-card.js"); | ||
|
||
cardPageBuildItemBuildProducer.produce(card); | ||
} | ||
} |
Oops, something went wrong.