private String detectPluginJar()

in github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/PluginVelocityRuntimeProvider.java [76:97]


  private String detectPluginJar() {
    ClassLoader myClassLoader = this.getClass().getClassLoader();
    if (!URLClassLoader.class.isAssignableFrom(myClassLoader.getClass())) {
      throw new IllegalStateException(pluginName + " plugin can be loaded only from a Jar file");
    }

    @SuppressWarnings("resource")
    URLClassLoader jarClassLoader = (URLClassLoader) myClassLoader;
    URL[] jarUrls = jarClassLoader.getURLs();
    for (URL url : jarUrls) {
      if (url.getProtocol().equals("file") && url.getPath().endsWith(".jar")) {
        return "jar:" + url.toString();
      }
    }

    throw new IllegalStateException(
        "Cannot find any Jar file in "
            + pluginName
            + " plugin class loader URLs "
            + jarUrls
            + ": unable to initialize Velocity resource loading.");
  }