Skip to content

Extracting resources from jar #12

Closed
@nedtwigg

Description

@nedtwigg

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpr-welcomeExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions