Skip to content

Commit 3292ac7

Browse files
committed
Added tentative implementation of "listUpdateable" sub-usecase
1 parent 741cbb5 commit 3292ac7

File tree

4 files changed

+110
-64
lines changed

4 files changed

+110
-64
lines changed

src/main/java/org/hydev/mcpm/client/arguments/parsers/ListParser.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,24 @@
99
/**
1010
* Command parser for List command
1111
*/
12-
public record ListParser(ListController controller) implements CommandParser
13-
{
12+
public record ListParser(ListController controller) implements CommandParser {
1413
@Override
15-
public String name()
16-
{
14+
public String name() {
1715
return "list";
1816
}
1917

2018
@Override
21-
public String description()
22-
{
19+
public String description() {
2320
return "List installed plugins";
2421
}
2522

2623
@Override
27-
public void configure(Subparser parser)
28-
{
29-
parser.addArgument("type").choices("all", "manual", "outdated").setDefault("all").nargs("?");
24+
public void configure(Subparser parser) {
25+
parser.addArgument("type").choices("all", "manual", "automatic", "outdated").setDefault("all").nargs("?");
3026
}
3127

3228
@Override
33-
public void run(Namespace details, Consumer<String> log)
34-
{
29+
public void run(Namespace details, Consumer<String> log) {
3530
controller.listAll(details.getString("type"), log);
3631
}
3732
}

src/main/java/org/hydev/mcpm/client/list/ListAllInteractor.java

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
1-
package org.hydev.mcpm.client.database;
1+
package org.hydev.mcpm.client.list;
22

3-
import org.apache.commons.lang3.NotImplementedException;
4-
import org.hydev.mcpm.client.database.boundary.CheckForUpdatesBoundary;
5-
import org.hydev.mcpm.client.database.inputs.CheckForUpdatesInput;
6-
import org.hydev.mcpm.client.database.inputs.CheckForUpdatesResult;
7-
import org.hydev.mcpm.client.database.model.PluginVersionState;
83
import org.hydev.mcpm.client.models.PluginYml;
94
import org.hydev.mcpm.client.updater.CheckForUpdatesBoundary;
5+
import org.hydev.mcpm.client.database.tracker.SuperPluginTracker;
106

117
import java.util.List;
12-
import java.util.ArrayList;
13-
import java.util.Collection;
14-
import java.util.OptionalLong;
158

169
/**
1710
* Implementation to the ListAll functionality
1811
*
1912
* @author Kevin (https://github.com/kchprog)
2013
* @since 2022-11-20
2114
*/
22-
public record ListAllInteractor(PluginTracker tracker) implements ListAllBoundary {
15+
public record ListAllInteractor(SuperPluginTracker pluginTracker) implements ListAllBoundary {
2316
/**
2417
* listAllInteractor interacts with the LocalPluginTracker to get the list of
2518
* plugins, according to a specified
@@ -33,57 +26,23 @@ public record ListAllInteractor(PluginTracker tracker) implements ListAllBoundar
3326
* outdated.
3427
*/
3528
public List<PluginYml> listAll(String parameter, CheckForUpdatesBoundary checkForUpdatesBoundary) {
36-
var installed = tracker.listInstalled();
29+
var installed = pluginTracker.listInstalled();
3730
switch (parameter) {
3831
case "all":
3932
return installed;
4033

4134
case "manual":
42-
var local = localPluginTracker.listManuallyInstalled();
35+
var local = pluginTracker.listManuallyInstalled();
4336
return installed.stream().filter(it -> local.contains(it.name())).toList();
4437

38+
case "automatic":
39+
var manual = pluginTracker.listManuallyInstalled();
40+
return installed.stream().filter(it -> !manual.contains(it.name())).toList();
41+
4542
case "outdated":
46-
/*
47-
* ArrayList<PluginVersionState> temp = new ArrayList<>();
48-
* ArrayList<PluginTrackerModel> installedModels =
49-
* localPluginTracker.listInstalledAsModels();
50-
*
51-
* for (PluginTrackerModel installedModel : installedModels) {
52-
* PluginVersionId pluginVersionId = new PluginVersionId(
53-
* OptionalLong.of(Long.parseLong(installedModel.getVersionId())), null);
54-
*
55-
* PluginModelId pluginModelId = new PluginModelId(
56-
* OptionalLong.of(Long.parseLong(installedModel.getPluginId())),
57-
* installedModel.getName(),
58-
* null);
59-
*
60-
* temp.add(new PluginVersionState(pluginModelId, pluginVersionId));
61-
* }
62-
*
63-
* CheckForUpdatesInput input = new CheckForUpdatesInput(temp, false);
64-
*
65-
* // Read the list of installedModels and create a CheckForUpdatesInput object
66-
* // with state equal
67-
* // to the list of PluginTrackerModels's version
68-
*
69-
* CheckForUpdatesResult rawResult = checkForUpdatesBoundary.updates(input);
70-
*
71-
* if (rawResult.state() == CheckForUpdatesResult.State.SUCCESS) {
72-
* Collection<PluginModel> result = rawResult.updatable().values();
73-
*
74-
* // get the ids of the plugins that are outdated from result
75-
* ArrayList<String> outdated = new ArrayList<>();
76-
* for (PluginModel pluginModel : result) {
77-
* outdated.add(pluginModel.id() + "");
78-
* }
79-
*
80-
* // filter the installed plugins by the outdated ids
81-
*
82-
* }
83-
* // Need to associate the IDs of the outdated plugins with the installed
84-
* plugin YML files, and return all matches
85-
*/
86-
throw new NotImplementedException("Not implemented yet");
43+
ListUpdateableBoundary listUpdateableBoundary = new ListUpdateableHelper();
44+
var outdated = listUpdateableBoundary.listUpdateable(pluginTracker, checkForUpdatesBoundary);
45+
return installed.stream().filter(it -> outdated.contains(it.name())).toList();
8746

8847
default:
8948
return null;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.hydev.mcpm.client.list;
2+
3+
import java.util.ArrayList;
4+
import org.hydev.mcpm.client.updater.CheckForUpdatesBoundary;
5+
import org.hydev.mcpm.client.database.tracker.SuperPluginTracker;
6+
7+
/**
8+
* Defines an interface for obtaining a list of plugin names that may be updated
9+
*/
10+
public interface ListUpdateableBoundary {
11+
ArrayList<String> listUpdateable(SuperPluginTracker superPluginTracker,
12+
CheckForUpdatesBoundary checkForUpdatesBoundary);
13+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
package org.hydev.mcpm.client.list;
3+
4+
import org.hydev.mcpm.client.models.PluginTrackerModel;
5+
import org.hydev.mcpm.client.models.PluginModel;
6+
import org.hydev.mcpm.client.updater.CheckForUpdatesBoundary;
7+
import org.hydev.mcpm.client.database.tracker.SuperPluginTracker;
8+
import org.hydev.mcpm.client.matcher.PluginVersionState;
9+
import org.hydev.mcpm.client.matcher.PluginModelId;
10+
import org.hydev.mcpm.client.matcher.PluginVersionId;
11+
12+
import org.hydev.mcpm.client.updater.CheckForUpdatesResult;
13+
import org.hydev.mcpm.client.updater.CheckForUpdatesInput;
14+
15+
import java.util.ArrayList;
16+
17+
import java.util.OptionalLong;
18+
19+
/**
20+
* A helper class for ListUpdateableBoundary.
21+
*/
22+
public class ListUpdateableHelper implements ListUpdateableBoundary {
23+
24+
/**
25+
* Returns a list of plugins that are outdated.
26+
*
27+
* @param localPluginTracker The plugin tracker in question
28+
* @param checkForUpdatesBoundary The boundary to check for updates
29+
* @return A list of plugins that are outdated.
30+
*/
31+
public ArrayList<String> listUpdateable(
32+
SuperPluginTracker localPluginTracker, CheckForUpdatesBoundary checkForUpdatesBoundary) {
33+
34+
ArrayList<PluginVersionState> temp = new ArrayList<>();
35+
ArrayList<PluginTrackerModel> installedModels = localPluginTracker.listInstalledAsModels();
36+
37+
// Generates a list of PluginVersionStates from the installed plugins obtained
38+
// from the
39+
// SuperLocalPluginTracker instance
40+
41+
for (PluginTrackerModel installedModel : installedModels) {
42+
PluginVersionId pluginVersionId = new PluginVersionId(
43+
OptionalLong.of(Long.parseLong(installedModel.getVersionId())), null);
44+
45+
PluginModelId pluginModelId = new PluginModelId(
46+
OptionalLong.of(Long.parseLong(installedModel.getPluginId())), installedModel.getName(), null);
47+
48+
temp.add(new PluginVersionState(pluginModelId, pluginVersionId));
49+
}
50+
51+
CheckForUpdatesInput input = new CheckForUpdatesInput(temp, false);
52+
53+
// Read the list of installedModels and create a CheckForUpdatesInput object
54+
// with state equal
55+
// to the list of PluginTrackerModels's version
56+
57+
CheckForUpdatesResult rawResult = checkForUpdatesBoundary.updates(input);
58+
59+
if (rawResult.state() == CheckForUpdatesResult.State.SUCCESS) {
60+
ArrayList<String> outdatedNames = new ArrayList<>();
61+
62+
// get the ids of the plugins that are outdated from result
63+
ArrayList<String> outdated = new ArrayList<>();
64+
for (PluginModel pluginModel : rawResult.updatable().values()) {
65+
outdated.add(pluginModel.getLatestPluginVersion().get().meta().name());
66+
}
67+
return outdatedNames;
68+
69+
// filter the installed plugins by the outdated ids
70+
71+
}
72+
73+
return new ArrayList<>();
74+
// Need to associate the IDs of the outdated plugins with the installed plugin
75+
// YML files, and return all matches
76+
77+
}
78+
79+
}

0 commit comments

Comments
 (0)