|
2 | 2 |
|
3 | 3 | import com.fasterxml.jackson.core.type.TypeReference;
|
4 | 4 | import com.fasterxml.jackson.databind.ObjectMapper;
|
5 |
| - |
6 | 5 | import org.hydev.mcpm.client.database.tracker.SuperPluginTracker;
|
7 |
| -import org.hydev.mcpm.client.models.PluginModel; |
8 |
| -import org.hydev.mcpm.client.models.PluginVersion; |
9 |
| -import org.hydev.mcpm.client.models.PluginYml; |
10 | 6 | import org.hydev.mcpm.client.models.*;
|
11 | 7 | import org.hydev.mcpm.client.models.PluginYml.InvalidPluginMetaStructure;
|
12 |
| -import org.hydev.mcpm.client.search.SearchPackagesBoundary; |
13 |
| -import org.hydev.mcpm.client.search.SearchPackagesInput; |
14 |
| -import org.hydev.mcpm.client.search.SearchPackagesResult; |
15 |
| -import org.hydev.mcpm.client.search.SearchPackagesType; |
16 | 8 | import org.hydev.mcpm.utils.Pair;
|
17 | 9 | import org.hydev.mcpm.utils.PluginJarFile;
|
18 |
| -import org.hydev.mcpm.client.models.PluginTrackerModel; |
19 | 10 | import org.jetbrains.annotations.Nullable;
|
20 | 11 |
|
21 |
| -import java.io.*; |
22 | 12 | import java.io.File;
|
23 | 13 | import java.io.FileNotFoundException;
|
24 | 14 | import java.io.IOException;
|
@@ -273,141 +263,4 @@ public List<String> listManuallyInstalled() {
|
273 | 263 |
|
274 | 264 | return Stream.concat(inLock, noLock).toList();
|
275 | 265 | }
|
276 |
| - |
277 |
| - /** |
278 |
| - * Return the version data of a plugin from the pluginYML file |
279 |
| - * |
280 |
| - * @param name Plugin id |
281 |
| - * @return Version data |
282 |
| - */ |
283 |
| - |
284 |
| - public String getVersion(String name) { |
285 |
| - // Locate the file in the plugin directory and read the version from the |
286 |
| - // plugin.yml |
287 |
| - // If the plugin is not found, throw an error |
288 |
| - |
289 |
| - File dir = new File(pluginDirectory); |
290 |
| - File[] directoryListing = dir.listFiles(); |
291 |
| - if (directoryListing != null) { |
292 |
| - for (File child : directoryListing) { |
293 |
| - if (child.getName().equals(name)) { |
294 |
| - // We probably want to keep this try catch. |
295 |
| - // A plugin can be malformed in many ways, this will just drop it from our list |
296 |
| - // if needed. |
297 |
| - try { |
298 |
| - return readMeta(child).version(); |
299 |
| - } catch (Exception e) { |
300 |
| - System.out.println("Error reading plugin.yml version from " + child); |
301 |
| - } |
302 |
| - } |
303 |
| - } |
304 |
| - } else { |
305 |
| - System.out.println("Plugin with id " + name + " not found"); |
306 |
| - return ""; |
307 |
| - } |
308 |
| - |
309 |
| - return ""; |
310 |
| - } |
311 |
| - |
312 |
| - /** |
313 |
| - * Get a list of plugin (as pluginYml) that are outdated |
314 |
| - * |
315 |
| - * @return List of plugin names |
316 |
| - */ |
317 |
| - public List<PluginYml> listOutdatedPluginYml(SearchPackagesBoundary searchPackagesBoundary) { |
318 |
| - List<PluginYml> outdatedPlugins = new ArrayList<>(); |
319 |
| - List<PluginYml> installedPlugins = listInstalled(); |
320 |
| - |
321 |
| - // For each plugin in the list of installed plugins, check if the version in the |
322 |
| - // plugin.yml file is outdated |
323 |
| - // If it is, add the plugin name to the list of outdated plugins |
324 |
| - for (PluginYml plugin : installedPlugins) { |
325 |
| - if (compareVersion(plugin.name(), searchPackagesBoundary)) { |
326 |
| - outdatedPlugins.add(plugin); |
327 |
| - } |
328 |
| - } |
329 |
| - |
330 |
| - return outdatedPlugins; |
331 |
| - } |
332 |
| - |
333 |
| - /** |
334 |
| - * Compare whether the locally installed version of the plugin matches the |
335 |
| - * version on the server. |
336 |
| - * If yes, return true. If no, return false. |
337 |
| - * |
338 |
| - * @return True if the local version of plugin with name is outdated, false |
339 |
| - * otherwise |
340 |
| - */ |
341 |
| - public Boolean compareVersion(String name, SearchPackagesBoundary searchPackagesBoundary) { |
342 |
| - File pluginYmlPath = getPluginFile(name); |
343 |
| - PluginYml currPlugin = readMeta(pluginYmlPath); |
344 |
| - String localVersion = currPlugin.version(); |
345 |
| - |
346 |
| - SearchPackagesInput searchPackagesInput = new SearchPackagesInput(SearchPackagesType.BY_NAME, name, |
347 |
| - false); |
348 |
| - SearchPackagesResult searchPackagesResult = searchPackagesBoundary.search(searchPackagesInput); |
349 |
| - |
350 |
| - // Get the version of the plugin from the server: Query for all, see if there's |
351 |
| - // a match |
352 |
| - if (searchPackagesResult.state().equals(SearchPackagesResult.State.SUCCESS)) { |
353 |
| - for (PluginModel plugin : searchPackagesResult.plugins()) { |
354 |
| - PluginVersion latest = plugin.getLatestPluginVersion().orElse(null); |
355 |
| - if (latest != null) { |
356 |
| - if (latest.meta().version().equals(localVersion)) { |
357 |
| - return true; |
358 |
| - } |
359 |
| - } |
360 |
| - |
361 |
| - } |
362 |
| - } |
363 |
| - |
364 |
| - return false; |
365 |
| - } |
366 |
| - |
367 |
| - /** |
368 |
| - * Get whether a local plugin File matches the version of the plugin on the |
369 |
| - * server |
370 |
| - * |
371 |
| - * @param local the local plugin File |
372 |
| - * @param remote a PluginModel object representing the plugin on the server |
373 |
| - * @return True if this plugin is up-to-date. |
374 |
| - */ |
375 |
| - public Boolean compareVersionNew(File local, PluginModel remote) { |
376 |
| - try { |
377 |
| - PluginYml localPlugin = readMeta(local); |
378 |
| - String localVersion = localPlugin.version(); |
379 |
| - String remoteVersion = remote.versions().get(0).meta().version(); |
380 |
| - return localVersion.equals(remoteVersion); |
381 |
| - } catch (Exception e) { |
382 |
| - throw new RuntimeException(e); |
383 |
| - } |
384 |
| - } |
385 |
| - |
386 |
| - /** |
387 |
| - * Retrieves the file path of a plugin with a specified name as a File |
388 |
| - * |
389 |
| - * @param name Plugin name |
390 |
| - * @return A File object representation of the plugin |
391 |
| - */ |
392 |
| - private File getPluginFile(String name) { |
393 |
| - // Get the file path of the plugin with name from the local plugin |
394 |
| - // directory |
395 |
| - // Return the file path as a File |
396 |
| - // Find the file from the plugin directory |
397 |
| - |
398 |
| - File dir = new File(pluginDirectory); |
399 |
| - File[] directoryListing = dir.listFiles(); |
400 |
| - if (directoryListing != null) { |
401 |
| - for (File child : directoryListing) { |
402 |
| - if (child.getName().equals(name)) { |
403 |
| - return child; |
404 |
| - } |
405 |
| - } |
406 |
| - } else { |
407 |
| - throw new IllegalArgumentException("Plugin not found, verify whether installed."); |
408 |
| - } |
409 |
| - |
410 |
| - return null; |
411 |
| - } |
412 |
| - |
413 | 266 | }
|
0 commit comments