Skip to content

Commit

Permalink
Fixed core-libs download issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rollno748 committed Sep 21, 2023
1 parent 8fda85a commit 40ac83b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public RestController() {
}

public enum Plugins {
DEFAULT,
PUBLIC,
CUSTOM
}
Expand Down Expand Up @@ -137,7 +136,6 @@ public void loadRestApiServices() {

get("/plugins-table", (req, res) -> {
res.type("application/json");
String type = req.queryParams("type");
PluginService pluginService = new PluginServiceImpl();
return pluginService.getPluginTable();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void run() {
try {
JSONArray pluginsArray = HttpRequest.get(props.getProperty("jmeter.plugins.url"));

if(getAvailablePluginsCount(pluginsArray) == 0){
if(getAvailablePluginsCount() == 0){
LOGGER.info("Initializing plugin download for the fresh setup : {} New Plugin(s) found to download.. ", pluginsArray.length());
Parse.downloadAllPlugins(pluginsArray);
}else{
Expand All @@ -50,8 +50,8 @@ public void run() {
LOGGER.debug("Checking for plugin updates from Plugins manager");
}

private int getAvailablePluginsCount(JSONArray pluginsArray) throws SQLException, InterruptedException{
int localStoreCount = Parse.getLocalPluginCount(pluginsArray);
private int getAvailablePluginsCount() throws SQLException, InterruptedException{
int localStoreCount = Parse.getLocalPluginCount();
setLocalDBPluginsCount(localStoreCount);
return localStoreCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public class HttpRequest {
private static final long RETRY_INTERVAL_MS = 60000;
private static final String INSERT_METADATA_INFO = "INSERT INTO metadata (id, version, changes, depends, downloadUrl, libs) VALUES (?, ?, ?, ?, ?, ?)";
private static final String INSERT_PLUGIN_INFO = "INSERT INTO plugins (id, name, type, description, helpUrl, markerClass, screenshotUrl, vendor, componentClasses, versions_count) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
private static final String SELECT_PLUGINS_WITH_FILTER = "SELECT ID, NAME, DESCRIPTION, HELPURL, MARKERCLASS, SCREENSHOTURL, VENDOR, COMPONENTCLASSES FROM plugins WHERE type = ?";
private static final String SELECT_PLUGINS_WITHOUT_FILTER = "SELECT ID, NAME, DESCRIPTION, HELPURL, MARKERCLASS, SCREENSHOTURL, VENDOR, COMPONENTCLASSES FROM plugins";
private static final String SELECT_PLUGINS_WITH_FILTER = "SELECT ID, NAME, TYPE, DESCRIPTION, HELPURL, MARKERCLASS, SCREENSHOTURL, VENDOR, COMPONENTCLASSES FROM plugins WHERE type = ?";
private static final String SELECT_PLUGINS_WITHOUT_FILTER = "SELECT ID, NAME, TYPE, DESCRIPTION, HELPURL, MARKERCLASS, SCREENSHOTURL, VENDOR, COMPONENTCLASSES FROM plugins";
private static final String SELECT_PLUGINS_TABLE_DATA = "SELECT ID, NAME, TYPE, DESCRIPTION, HELPURL, MARKERCLASS, SCREENSHOTURL, VENDOR, COMPONENTCLASSES, VERSIONS_COUNT FROM plugins";
private static final String SELECT_METADATA_BY_ID = "SELECT ID, VERSION, CHANGES, DEPENDS, DOWNLOADURL, LIBS FROM metadata WHERE ID = ?";
private static final String SELECT_PLUGIN_VERSION_METADATA = "SELECT COUNT(*) AS COUNT FROM METADATA WHERE ID = ? AND VERSION = ?";
Expand Down Expand Up @@ -134,10 +134,9 @@ public void downloadMissingPlugins(JSONObject pluginObject) throws URISyntaxExce
}else{
List<String> availableVersions = this.getAvailableLibraryVersions(downloadUrl);
for (String ver : availableVersions){
String url = downloadUrl.replace("%1$s", ver);
metaDataObj.put("downloadUrl", url.substring(url.lastIndexOf('/') + 1));
fileDownloader(this.pluginsPath, new URI(url).toURL());
fileDownloader(this.pluginsPath, new URI(ver).toURL());
}
metaDataObj.put("downloadUrl", getLibraryName(downloadUrl)+"-%1$s.jar");
}
if(verObj.has("libs")){
JSONObject libsObject = verObj.getJSONObject("libs");
Expand All @@ -159,13 +158,17 @@ public void downloadMissingPlugins(JSONObject pluginObject) throws URISyntaxExce
}

private List<String> getAvailableLibraryVersions(String downloadUrl) {
return fetchAvailableVersions(getLibraryName(downloadUrl));
}

private String getLibraryName(String downloadUrl) {
String libName = null;
Pattern pattern = Pattern.compile("jmeter/(?<libName>[^/]+)/%\\d[^/]*");
Matcher matcher = pattern.matcher(downloadUrl);
if(matcher.find()) {
libName = matcher.group("libName");
}
return fetchAvailableVersions(libName);
return libName;
}

public JSONArray fetchPluginsFromLocalDB(String query, String type) {
Expand Down Expand Up @@ -197,7 +200,7 @@ public JSONArray fetchPluginsFromLocalDB(String query, String type) {
pluginObject.put("markerClass", (markerClass == null || markerClass.isEmpty()) ? JSONObject.NULL : markerClass);
pluginObject.put("screenshotUrl", rs.getString("screenshotUrl"));
pluginObject.put("vendor", rs.getString("vendor"));
libraryObj = this.getDependentLibraryObj(rs.getString("id"), type);
libraryObj = this.getDependentLibraryObj(rs.getString("id"), rs.getString("type"));
pluginObject.put("versions", libraryObj);
String componentClasses = rs.getString("componentClasses");
if(componentClasses != null){
Expand Down Expand Up @@ -228,10 +231,6 @@ public JSONArray getAllPlugins() {
return fetchPluginsFromLocalDB(SELECT_PLUGINS_WITHOUT_FILTER, "all");
}

private JSONArray getCombinedPlugins() {
return fetchPluginsFromLocalDB(SELECT_PLUGINS_WITHOUT_FILTER, "all");
}

public JSONArray getPublicPlugins() {
return fetchPluginsFromLocalDB(SELECT_PLUGINS_WITH_FILTER, "public");
}
Expand Down Expand Up @@ -334,13 +333,12 @@ private List<String> fetchAvailableVersions(String libName) {
Document doc;
List<String> versions = new ArrayList<>();
try{
//mavenRepoUrl
doc = Jsoup.connect("https://repo1.maven.org/maven2/org/apache/jmeter/" + libName).get();
Elements links = doc.select("a[href]");
doc = Jsoup.connect(mavenRepoUrl + libName).get();
Elements links = doc.select("a[title]");
for(Element link : links) {
String href = link.attr("href");
if(href.contains(libName + "-")) {
String version = href.substring(href.lastIndexOf("-") + 1, href.lastIndexOf(".jar"));
if(!href.contains("xml")){
String version = mavenRepoUrl + libName + "/" + href + libName + "-" + href.substring(0, href.lastIndexOf('/')) + ".jar";
versions.add(version);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static void downloadAllPlugins(JSONArray jmeterRepoJson) throws URISyntax
LOGGER.info("Downloaded all the available plugins from the market");
}

public static int getLocalPluginCount(JSONArray pluginsArray) throws SQLException, InterruptedException {
public static int getLocalPluginCount() throws SQLException, InterruptedException {
int localStoreCount = 0;
conn = SQLiteConnectionPool.getConnection();

Expand All @@ -80,7 +80,7 @@ public static int getLocalPluginCount(JSONArray pluginsArray) throws SQLExceptio
return localStoreCount;
}

public static void addPluginDataToDB(JSONObject pluginObj) throws SQLException, InterruptedException {
public static void addPluginDataToDB(JSONObject pluginObj) {
String type = "custom";
httpRequest.updateCustomPluginInfoInDB(pluginObj);
}
Expand Down

0 comments on commit 40ac83b

Please sign in to comment.