fix(plugins): use release from asset if differ from release name with GitHub resolver
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
package jadx.plugins.tools.utils;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static jadx.plugins.tools.utils.PluginUtils.extractVersion;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
class PluginUtilsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExtractVersion() {
|
||||||
|
assertThat(extractVersion("plugin-name-v1.2.3.jar")).isEqualTo("1.2.3");
|
||||||
|
assertThat(extractVersion("plugin-name-v1.2.jar")).isEqualTo("1.2");
|
||||||
|
assertThat(extractVersion("1.2.3.jar")).isEqualTo("1.2.3");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+8
-3
@@ -10,8 +10,7 @@ import jadx.plugins.tools.data.JadxPluginMetadata;
|
|||||||
import jadx.plugins.tools.resolvers.IJadxPluginResolver;
|
import jadx.plugins.tools.resolvers.IJadxPluginResolver;
|
||||||
import jadx.plugins.tools.resolvers.github.data.Asset;
|
import jadx.plugins.tools.resolvers.github.data.Asset;
|
||||||
import jadx.plugins.tools.resolvers.github.data.Release;
|
import jadx.plugins.tools.resolvers.github.data.Release;
|
||||||
|
import jadx.plugins.tools.utils.PluginUtils;
|
||||||
import static jadx.plugins.tools.utils.PluginUtils.removePrefix;
|
|
||||||
|
|
||||||
public class GithubReleaseResolver implements IJadxPluginResolver {
|
public class GithubReleaseResolver implements IJadxPluginResolver {
|
||||||
private static final Pattern VERSION_PATTERN = Pattern.compile("v?\\d+\\.\\d+(\\.\\d+)?");
|
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) {
|
private JadxPluginMetadata buildMetadata(Release release, LocationInfo info) {
|
||||||
List<Asset> assets = release.getAssets();
|
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);
|
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();
|
JadxPluginMetadata metadata = new JadxPluginMetadata();
|
||||||
metadata.setVersion(releaseVersion);
|
metadata.setVersion(releaseVersion);
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ import java.net.URI;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class PluginUtils {
|
public class PluginUtils {
|
||||||
|
|
||||||
@@ -22,4 +26,19 @@ public class PluginUtils {
|
|||||||
throw new RuntimeException("Failed to download file: " + fileUrl, e);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user