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

Extracting resources from jar #12

Closed
nedtwigg opened this issue Dec 4, 2020 · 1 comment · Fixed by #20
Closed

Extracting resources from jar #12

nedtwigg opened this issue Dec 4, 2020 · 1 comment · Fixed by #20
Labels
enhancement New feature or request pr-welcome Extra attention is needed

Comments

@nedtwigg
Copy link
Member

nedtwigg commented Dec 4, 2020

Following a discussion at diffplug/spotless#744

The way that Blowdryer grabs a resource is this simple interface:

static interface ResourcePlugin {
String toImmutableUrl(String resourcePath);
}

Which gets initialized in the settings.gradle like this:

/** Sets the source where we will grab these scripts. */
public void github(String repoOrg, GitAnchorType anchorType, String anchor) {
assertNoLeadingOrTrailingSlash(repoOrg);
assertNoLeadingOrTrailingSlash(anchor);
String root = "https://raw.githubusercontent.com/" + repoOrg + "/" + anchor + "/" + repoSubfolder + "/";
Blowdryer.setResourcePlugin(resource -> root + resource);
}

This interface could be adapted to extract resources from a jar on the classpath, or you could add credentials for the URL. We're happy to merge PR's which add support for either usecase.

extracting from jar

If you wanted to implement this, the pseudocode might be:

public void localJar(String jarName) {
  File localJar = ... (find jar on classpath with name jarName)
  String rootUrl = "file:///" + localJar.getAbsolutePath() + "!/";
  Blowdryer.setResourcePlugin(resource -> rootUrl + resource);
}
@nedtwigg nedtwigg changed the title Extracing resources from jar, http auth, etc. Extracting resources from jar Feb 12, 2021
@nedtwigg nedtwigg added enhancement New feature or request pr-welcome Extra attention is needed labels Feb 12, 2021
@nedtwigg
Copy link
Member Author

Published in 1.2.0

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

Successfully merging a pull request may close this issue.

1 participant