Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider service loader for picking up custom implementations #10058

Open
niloc132 opened this issue Dec 12, 2024 · 0 comments
Open

Consider service loader for picking up custom implementations #10058

niloc132 opened this issue Dec 12, 2024 · 0 comments

Comments

@niloc132
Copy link
Member

The -runStyle and -server flags of JUnitShell and DevMode respectively take an optional classname, which can be irritating to fully populate. The -server flag defaults to using a built in class without naming it, com.google.gwt.dev.shell.JettyLauncher (see #10057 to consider changing that default), while the -runStyle flag supports Manual, Selenium (hugely out of date), HtmlUnit, and ExternalBrowser (officially unsupported, but will attempt to run if referenced by name).

Both of these features are worthy to extend and make more useful, but can be irritating to enter a fully qualified class name, especially when canonical implementations are supported by simple name.

This ticket proposes to introduce an optional factory type for this sort of feature, which would allow a create(...) method to be defined on it, and would already have a String getName() method, something like

public interface NamedFactory {
  String getName();
}

Subtypes of this would add their create() method, and implementations of the factory could then be picked up by a ServiceLoader call, and tested to ensure their names don't collide. A user-specified name then can be used in addition to the fully qualified class name (which would continue to work to avoid the factory where one doesn't exist or where there is a collision).

Example (written without the aid of an IDE, missing duplicate checking, exception handling, etc):
New class to add within GWT itself, to load by name as needed

public interface RunStyleFactory extends NamedFactory {
  static RunStyle create(JUnitShell shell, String name) {
    for (RunStyleFactory f : ServiceLoader.load(RunStyleFactory.class)) {
      if (f.getName().equals(name)) {
        return f.create(shell);
      }
    }
    return Class.forName(name);
  }
  
  RunStyle create(JUnitShell shell);
}

Example factory provided in a library for WebDriver support (something like https://github.com/gwtproject/gwt-core/pull/14/files):

public class WebDriverRunStyleFactory implements RunStyleFactory {
  @Override
  public String getName() {
    return "WebDriver";
  }
  @Override
  public WebDriverRunStyle create(JUnitShell shell) {
    return new WebDriverRunStyle(shell);
  }
}

Command line usage then can look like -runStyle WebDriver:http://localhost:4444/?firefox.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant