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

Fetching jar from classpath #21

Open
nedtwigg opened this issue May 28, 2021 · 3 comments
Open

Fetching jar from classpath #21

nedtwigg opened this issue May 28, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@nedtwigg
Copy link
Member

nedtwigg commented May 28, 2021

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.

@nedtwigg nedtwigg added the enhancement New feature or request label May 28, 2021
@nedtwigg
Copy link
Member Author

So in concrete terms this would look like:

// settings.gradle
plugins {
  id 'com.diffplug.blowdryerSetup' version '1.2.0'
  id 'com.acme.blowdryer-scripts' version '3.0.0'
}

blowdryerSetup {
  classpathJar('blowdryer-scripts')
}

But you could even simplify down to

// settings.gradle
plugins {
  id 'com.acme.blowdryer-scripts' version '3.0.0'
}

If your blowdryer-scripts jar has a single ConfigureBlowdryerPlugin.java which is just a Plugin<Settings> which does the blowdryerSetup part.

@hakjac
Copy link

hakjac commented Jun 16, 2023

The classpathJar is exactly what I need, (or even better the simplified version), ... will this be implemented and released soon? Please! :-)

@nedtwigg
Copy link
Member Author

PR's welcome, but I have no plan to build this.

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

No branches or pull requests

2 participants