Skip to content

Fetching jar from classpath #21

Open
@nedtwigg

Description

@nedtwigg

The next obvious feature after #12 is classpathJar, which could be implemented with something like this:

private static URL findResourceJar(String name) {
  ClassLoader loader = Blowdryer.class.getClassloader();
  while (loader != null) {
    if (loader instanceof URLClassLoader) {
      URL[] urls = urlLoader.getUrls();
      List<URL> matchingUrls = Arrays.stream(urls)
        .filter(url -> matches name)
        .collect(Collectors.toList());
      if (matchingUrls.size() == 1) {
        return matchingUrls.get(0);
      } else if (matchingUrls.isEmpty()) {
        throw "no matches"
      } else {
        throw "multiple matches " + matchingUrls
      }
    } else {
      loader = loader.getParent()
    }
  }
  throw "couldn't find URLClassLoader"
}

You could declare your plugin script jar in the settings.gradle plugins block. You could even put a little snippet of java code into your buildscripts jar which actually does blowdryerSetup { classpathJar ('myname') } for you automatically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions