Skip to content

Commit 285230a

Browse files
committed
[-] Remove getPluginFile, compareVersion, listOutdated, getVersion
1 parent 8aa5316 commit 285230a

File tree

2 files changed

+5
-159
lines changed

2 files changed

+5
-159
lines changed

src/main/java/org/hydev/mcpm/client/database/tracker/SuperPluginTracker.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package org.hydev.mcpm.client.database.tracker;
22

3-
import org.hydev.mcpm.client.models.PluginModel;
4-
import org.hydev.mcpm.client.models.PluginYml;
3+
import org.hydev.mcpm.client.models.Database;
54
import org.hydev.mcpm.client.models.PluginTrackerModel;
6-
import org.hydev.mcpm.client.search.SearchPackagesBoundary;
5+
import org.hydev.mcpm.client.models.PluginVersion;
6+
import org.hydev.mcpm.client.models.PluginYml;
77

8-
import java.io.File;
98
import java.util.List;
109
import java.util.ArrayList;
1110

@@ -34,13 +33,7 @@ public interface SuperPluginTracker {
3433

3534
List<String> listManuallyInstalled();
3635

37-
List<String> listOrphanPlugins(boolean considerSoftDependencies);
38-
39-
String getVersion(String name);
40-
41-
List<PluginYml> listOutdatedPluginYml(SearchPackagesBoundary searchPackagesBoundary);
42-
43-
Boolean compareVersion(String name, SearchPackagesBoundary searchPackagesBoundary);
36+
List<PluginYml> listOrphanPlugins(boolean considerSoftDependencies);
4437

45-
Boolean compareVersionNew(File local, PluginModel remote);
38+
List<PluginVersion> listOutdatedPlugins(Database database);
4639
}

src/main/java/org/hydev/mcpm/client/local/SuperLocalPluginTracker.java

Lines changed: 0 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@
22

33
import com.fasterxml.jackson.core.type.TypeReference;
44
import com.fasterxml.jackson.databind.ObjectMapper;
5-
65
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;
106
import org.hydev.mcpm.client.models.*;
117
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;
168
import org.hydev.mcpm.utils.Pair;
179
import org.hydev.mcpm.utils.PluginJarFile;
18-
import org.hydev.mcpm.client.models.PluginTrackerModel;
1910
import org.jetbrains.annotations.Nullable;
2011

21-
import java.io.*;
2212
import java.io.File;
2313
import java.io.FileNotFoundException;
2414
import java.io.IOException;
@@ -273,141 +263,4 @@ public List<String> listManuallyInstalled() {
273263

274264
return Stream.concat(inLock, noLock).toList();
275265
}
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-
413266
}

0 commit comments

Comments
 (0)