feat(gui): manage plugins in preferences window
This commit is contained in:
@@ -4,7 +4,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -46,7 +46,7 @@ public class JadxPluginsTools {
|
||||
|
||||
private JadxPluginsTools() {
|
||||
ProjectDirectories jadxDirs = ProjectDirectories.from("io.github", "skylot", "jadx");
|
||||
Path plugins = Paths.get(jadxDirs.configDir, "plugins"); // TODO: use dataDir?
|
||||
Path plugins = Paths.get(jadxDirs.configDir, "plugins");
|
||||
makeDirs(plugins);
|
||||
pluginsJson = plugins.resolve("plugins.json");
|
||||
dropins = plugins.resolve("dropins");
|
||||
@@ -165,7 +165,9 @@ public class JadxPluginsTools {
|
||||
}
|
||||
fillPluginInfoFromJar(metadata, tmpJar);
|
||||
|
||||
Path pluginJar = installed.resolve(metadata.getPluginId() + '-' + metadata.getVersion() + ".jar");
|
||||
String version = metadata.getVersion();
|
||||
String fileName = metadata.getPluginId() + (version != null ? '-' + version : "") + ".jar";
|
||||
Path pluginJar = installed.resolve(fileName);
|
||||
copyJar(tmpJar, pluginJar);
|
||||
metadata.setJar(installed.relativize(pluginJar).toString());
|
||||
|
||||
@@ -195,7 +197,7 @@ public class JadxPluginsTools {
|
||||
}
|
||||
|
||||
private void downloadJar(String sourceJar, Path destPath) {
|
||||
try (InputStream in = new URL(sourceJar).openStream()) {
|
||||
try (InputStream in = URI.create(sourceJar).toURL().openStream()) {
|
||||
Files.copy(in, destPath, StandardCopyOption.REPLACE_EXISTING);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to download jar: " + sourceJar, e);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package jadx.plugins.tools.data;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class JadxPluginMetadata implements Comparable<JadxPluginMetadata> {
|
||||
private String pluginId;
|
||||
private String name;
|
||||
private String description;
|
||||
private String version;
|
||||
private @Nullable String version;
|
||||
private String locationId;
|
||||
private String resolverId;
|
||||
private String jar;
|
||||
@@ -27,7 +28,7 @@ public class JadxPluginMetadata implements Comparable<JadxPluginMetadata> {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
public @Nullable String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@@ -93,7 +94,7 @@ public class JadxPluginMetadata implements Comparable<JadxPluginMetadata> {
|
||||
return "JadxPluginMetadata{"
|
||||
+ "id=" + pluginId
|
||||
+ ", name=" + name
|
||||
+ ", version=" + version
|
||||
+ ", version=" + (version != null ? version : "?")
|
||||
+ ", locationId=" + locationId
|
||||
+ ", jar=" + jar
|
||||
+ '}';
|
||||
|
||||
@@ -10,10 +10,9 @@ Examples: `github:skylot:jadx`, `github:skylot:jadx:sample-plugin` or `github:sk
|
||||
|
||||
`<version>` - exact version to install (optional), should be equal to release name
|
||||
|
||||
Artifact should have a name: `<artifact name prefix>-<release-version-name>.jar`.
|
||||
Artifact name pattern: `<artifact name prefix>[-<release-version-name>].jar`.
|
||||
|
||||
Default value for `<artifact name prefix>` is a repo name,
|
||||
`release-version-name` should have a `x.x.x` format.
|
||||
Default value for `<artifact name prefix>` is a repo name, `-<release-version-name>` is optional.
|
||||
|
||||
---
|
||||
|
||||
|
||||
+8
-1
@@ -64,7 +64,7 @@ public class GithubReleaseResolver implements IJadxPluginResolver {
|
||||
Asset asset = release.getAssets().stream()
|
||||
.filter(a -> a.getName().equals(artifactName))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new RuntimeException("Release artifact with name '" + artifactName + "' not found"));
|
||||
.orElse(searchIgnoringVersion(release, artifactPrefix));
|
||||
|
||||
JadxPluginMetadata metadata = new JadxPluginMetadata();
|
||||
metadata.setResolverId(id());
|
||||
@@ -74,6 +74,13 @@ public class GithubReleaseResolver implements IJadxPluginResolver {
|
||||
return Optional.of(metadata);
|
||||
}
|
||||
|
||||
private @NotNull Asset searchIgnoringVersion(Release release, String artifactPrefix) {
|
||||
return release.getAssets().stream()
|
||||
.filter(a -> a.getName().startsWith(artifactPrefix) && a.getName().startsWith(".jar"))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new RuntimeException("Release artifact with prefix '" + artifactPrefix + "' not found"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String buildLocationId(String owner, String project, String artifactPrefix) {
|
||||
if (project.equals(artifactPrefix)) {
|
||||
|
||||
Reference in New Issue
Block a user