Skip to content

Commit 833987d

Browse files
authored
[PR] Merge pull request #49 from CSC207-2022F-UofT/LocalPluginTracker
Local plugin tracker
2 parents 22f07b1 + e2c8473 commit 833987d

File tree

10 files changed

+488
-153
lines changed

10 files changed

+488
-153
lines changed

src/main/java/org/hydev/mcpm/client/arguments/CommandsFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private CommandsFactory() { }
2626
*/
2727
public static List<CommandParser> baseParsers() {
2828
var echoController = new EchoController();
29-
var exportPluginsController = new ExportPluginsController(new ExportInteractor(new LocalPluginTracker(null, null))); // idk man
29+
var exportPluginsController = new ExportPluginsController(new ExportInteractor(new LocalPluginTracker()));
3030

3131
/*
3232
* Add general parsers to this list!
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.hydev.mcpm.client.database;
2+
3+
4+
import java.util.List;
5+
6+
/**
7+
* Interface for listing all plugins
8+
*
9+
* @author Kevin (https://github.com/kchprog)
10+
* @since 2022-11-20
11+
*/
12+
public interface ListAllBoundary {
13+
14+
/**
15+
* listAllInteractor interacts with the LocalPluginTracker to get the list of plugins, according to a specified
16+
* parameter
17+
*
18+
* @param parameter The parameter for the ListAll use case. 'All' denotes a request to list all manually
19+
* installed plugins, 'manual' denotes a request to list all manually installed plugins, and 'outdated' denotes
20+
* a request to list all manually installed plugins that are outdated.
21+
*/
22+
List<String> listAll(String parameter);
23+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.hydev.mcpm.client.database;
2+
3+
import org.hydev.mcpm.client.models.PluginVersion;
4+
import org.hydev.mcpm.client.models.PluginYml;
5+
import org.hydev.mcpm.utils.HashUtils;
6+
import org.hydev.mcpm.utils.PluginJarFile;
7+
import org.hydev.mcpm.client.database.inputs.*;
8+
9+
import com.opencsv.CSVWriter;
10+
import com.opencsv.CSVReader;
11+
12+
import java.io.File;
13+
import java.util.List;
14+
import java.util.ArrayList;
15+
import java.io.*;
16+
import java.util.Scanner;
17+
import java.util.Arrays;
18+
19+
import javax.naming.NameNotFoundException;
20+
import javax.swing.plaf.metal.MetalIconFactory.FileIcon16;
21+
22+
import java.util.List;
23+
24+
/**
25+
* Controller class for the ListAll use case.
26+
*
27+
* @author Kevin Chen
28+
*/
29+
public class ListAllController {
30+
ListAllBoundary listAllBoundary;
31+
32+
/**
33+
* Constructor for ListAllController.
34+
*
35+
* @param listAllBoundary The boundary class for ListAllController.
36+
*/
37+
public ListAllController(ListAllBoundary listAllBoundary) {
38+
this.listAllBoundary = listAllBoundary;
39+
}
40+
41+
/**
42+
* Executes the ListAll use case.
43+
*
44+
* @param parameter The parameter for the ListAll use case.
45+
* @return The list of plugins.
46+
*/
47+
List<String> listAll(String parameter) {
48+
49+
String[] validIn = {"all", "manual", "outdated"};
50+
try {
51+
if (Arrays.asList(validIn).contains(parameter)) {
52+
return listAllBoundary.listAll(parameter);
53+
} else {
54+
throw new IllegalArgumentException("Invalid parameter");
55+
}
56+
} catch (Exception e) {
57+
e.printStackTrace();
58+
return null;
59+
}
60+
}
61+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.hydev.mcpm.client.database;
2+
3+
import org.apache.commons.lang3.NotImplementedException;
4+
import org.hydev.mcpm.client.models.PluginYml;
5+
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
9+
/**
10+
* Implementation to the ListAll functionality
11+
*
12+
* @author Kevin (https://github.com/kchprog)
13+
* @since 2022-11-20
14+
*/
15+
public class ListAllInteractor implements ListAllBoundary
16+
{
17+
LocalPluginTracker localPluginTracker = new LocalPluginTracker();
18+
19+
/**
20+
* listAllInteractor interacts with the LocalPluginTracker to get the list of plugins, according to a specified
21+
* parameter
22+
*
23+
* @param parameter The parameter for the ListAll use case. 'All' denotes a request to list all manually
24+
* installed plugins, 'manual' denotes a request to list all manually installed plugins, and 'outdated' denotes
25+
* a request to list all manually installed plugins that are outdated.
26+
*/
27+
public List<String> listAll(String parameter)
28+
{
29+
switch (parameter)
30+
{
31+
case "all":
32+
List<PluginYml> pluginList = localPluginTracker.listInstalled();
33+
return pluginList.stream().map(PluginYml::name).toList();
34+
35+
case "manual":
36+
return localPluginTracker.listManuallyInstalled();
37+
38+
case "outdated":
39+
throw new NotImplementedException("Method to print outdated plugins not implemented yet");
40+
41+
default:
42+
return null;
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)