fix(plugins): use release from asset if differ from release name with GitHub resolver

This commit is contained in:
Skylot
2024-11-24 18:52:32 +00:00
parent baa93bad63
commit a67dfcb7e1
3 changed files with 44 additions and 3 deletions
@@ -10,8 +10,7 @@ import jadx.plugins.tools.data.JadxPluginMetadata;
import jadx.plugins.tools.resolvers.IJadxPluginResolver;
import jadx.plugins.tools.resolvers.github.data.Asset;
import jadx.plugins.tools.resolvers.github.data.Release;
import static jadx.plugins.tools.utils.PluginUtils.removePrefix;
import jadx.plugins.tools.utils.PluginUtils;
public class GithubReleaseResolver implements IJadxPluginResolver {
private static final Pattern VERSION_PATTERN = Pattern.compile("v?\\d+\\.\\d+(\\.\\d+)?");
@@ -47,8 +46,14 @@ public class GithubReleaseResolver implements IJadxPluginResolver {
private JadxPluginMetadata buildMetadata(Release release, LocationInfo info) {
List<Asset> assets = release.getAssets();
String releaseVersion = removePrefix(release.getName(), "v");
String releaseVersion = PluginUtils.removePrefix(release.getName(), "v");
Asset asset = searchPluginAsset(assets, info.getArtifactPrefix(), releaseVersion);
if (!asset.getName().contains(releaseVersion)) {
String assetVersion = PluginUtils.extractVersion(asset.getName());
if (assetVersion != null) {
releaseVersion = assetVersion;
}
}
JadxPluginMetadata metadata = new JadxPluginMetadata();
metadata.setVersion(releaseVersion);
@@ -5,6 +5,10 @@ import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jetbrains.annotations.Nullable;
public class PluginUtils {
@@ -22,4 +26,19 @@ public class PluginUtils {
throw new RuntimeException("Failed to download file: " + fileUrl, e);
}
}
private static final Pattern VERSION_LONG = Pattern.compile(".*v?(\\d+\\.\\d+\\.\\d+).*");
private static final Pattern VERSION_SHORT = Pattern.compile(".*v?(\\d+\\.\\d+).*");
public static @Nullable String extractVersion(String str) {
Matcher longMatcher = VERSION_LONG.matcher(str);
if (longMatcher.matches()) {
return longMatcher.group(1);
}
Matcher shortMatcher = VERSION_SHORT.matcher(str);
if (shortMatcher.matches()) {
return shortMatcher.group(1);
}
return null;
}
}