Skip to content

Commit aaef6f4

Browse files
authored
[PR] Merge pull request #98 from CSC207-2022F-UofT/feat-export-import
Add Import
2 parents 1c8f576 + 902cd02 commit aaef6f4

38 files changed

+735
-240
lines changed

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
package org.hydev.mcpm.client.arguments;
22

3-
import org.hydev.mcpm.client.commands.controllers.ExportPluginsController;
4-
import org.hydev.mcpm.client.commands.controllers.InfoController;
5-
import org.hydev.mcpm.client.commands.controllers.InstallController;
6-
import org.hydev.mcpm.client.commands.controllers.ListController;
7-
import org.hydev.mcpm.client.commands.controllers.LoadController;
8-
import org.hydev.mcpm.client.commands.controllers.MirrorController;
9-
import org.hydev.mcpm.client.commands.controllers.PageBoundary;
10-
import org.hydev.mcpm.client.commands.controllers.RefreshController;
11-
import org.hydev.mcpm.client.commands.controllers.ReloadController;
12-
import org.hydev.mcpm.client.commands.controllers.SearchPackagesController;
13-
import org.hydev.mcpm.client.commands.controllers.UninstallController;
14-
import org.hydev.mcpm.client.commands.controllers.UnloadController;
15-
import org.hydev.mcpm.client.commands.controllers.UpdateController;
3+
import org.hydev.mcpm.client.commands.controllers.*;
4+
import org.hydev.mcpm.client.display.presenters.LogExportPresenter;
5+
import org.hydev.mcpm.client.display.presenters.LogImportPresenter;
166
import org.hydev.mcpm.client.local.PageController;
177

188
/**
@@ -28,8 +18,13 @@ public PageBoundary pageBoundary() {
2818
}
2919

3020
@Override
31-
public ExportPluginsController exportController() {
32-
return new ExportPluginsController(boundary.exportBoundary());
21+
public ExportController exportController() {
22+
return new ExportController(boundary.exportBoundary(), new LogExportPresenter()); // temporary presenter bandage
23+
}
24+
25+
@Override
26+
public ImportController importController() {
27+
return new ImportController(boundary.importBoundary(), new LogImportPresenter()); // temporary presenter bandage
3328
}
3429

3530
@Override

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
package org.hydev.mcpm.client.arguments;
22

3-
import org.hydev.mcpm.client.commands.controllers.ExportPluginsController;
4-
import org.hydev.mcpm.client.commands.controllers.InfoController;
5-
import org.hydev.mcpm.client.commands.controllers.InstallController;
6-
import org.hydev.mcpm.client.commands.controllers.ListController;
7-
import org.hydev.mcpm.client.commands.controllers.LoadController;
8-
import org.hydev.mcpm.client.commands.controllers.MirrorController;
9-
import org.hydev.mcpm.client.commands.controllers.PageBoundary;
10-
import org.hydev.mcpm.client.commands.controllers.RefreshController;
11-
import org.hydev.mcpm.client.commands.controllers.ReloadController;
12-
import org.hydev.mcpm.client.commands.controllers.SearchPackagesController;
13-
import org.hydev.mcpm.client.commands.controllers.UninstallController;
14-
import org.hydev.mcpm.client.commands.controllers.UnloadController;
15-
import org.hydev.mcpm.client.commands.controllers.UpdateController;
3+
import org.hydev.mcpm.client.commands.controllers.*;
164

175
/**
186
* Abstract factory for creating controller classes.
@@ -35,15 +23,22 @@ public interface ControllerFactoryBoundary {
3523
/**
3624
* Creates an export controller that interfaces with ExportPluginsBoundary.
3725
*
38-
* @return A ExportPluginsController object.
26+
* @return A ExportController object.
3927
*/
40-
ExportPluginsController exportController();
28+
ExportController exportController();
4129

30+
/**
31+
* Creates an import controller that interfaces with ImportPluginsBoundary.
32+
*
33+
* @return A ImportController object.
34+
*/
35+
ImportController importController();
4236
/**
4337
* Creates a list controller that interfaces with ListAllBoundary.
4438
*
4539
* @return A ListController object.
4640
*/
41+
4742
ListController listController();
4843

4944
/**

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.hydev.mcpm.client.display.progress.ProgressBarFetcherListener;
99
import org.hydev.mcpm.client.export.ExportInteractor;
1010
import org.hydev.mcpm.client.export.ExportPluginsBoundary;
11+
import org.hydev.mcpm.client.export.ImportInteractor;
12+
import org.hydev.mcpm.client.export.ImportPluginsBoundary;
1113
import org.hydev.mcpm.client.loader.LoadBoundary;
1214
import org.hydev.mcpm.client.loader.LocalJarBoundary;
1315
import org.hydev.mcpm.client.loader.LocalJarFinder;
@@ -186,6 +188,13 @@ public ExportPluginsBoundary exportBoundary() {
186188
return cache(ExportInteractor.class, () -> new ExportInteractor(tracker));
187189
}
188190

191+
@Override
192+
public ImportPluginsBoundary importBoundary() {
193+
var installer = installBoundary();
194+
195+
return cache(ImportInteractor.class, () -> new ImportInteractor(installer));
196+
}
197+
189198
@Override
190199
public ListAllBoundary listBoundary() {
191200
var tracker = pluginTracker();

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
import org.hydev.mcpm.client.database.mirrors.MirrorSelectBoundary;
66
import org.hydev.mcpm.client.database.tracker.PluginTracker;
77
import org.hydev.mcpm.client.export.ExportPluginsBoundary;
8+
import org.hydev.mcpm.client.export.ImportPluginsBoundary;
9+
import org.hydev.mcpm.client.installer.InstallBoundary;
10+
import org.hydev.mcpm.client.installer.PluginDownloader;
11+
import org.hydev.mcpm.client.list.ListAllBoundary;
812
import org.hydev.mcpm.client.loader.LoadBoundary;
913
import org.hydev.mcpm.client.loader.LocalJarBoundary;
1014
import org.hydev.mcpm.client.loader.ReloadBoundary;
1115
import org.hydev.mcpm.client.loader.UnloadBoundary;
12-
import org.hydev.mcpm.client.installer.InstallBoundary;
13-
import org.hydev.mcpm.client.installer.PluginDownloader;
14-
import org.hydev.mcpm.client.list.ListAllBoundary;
1516
import org.hydev.mcpm.client.matcher.MatchPluginsBoundary;
1617
import org.hydev.mcpm.client.search.SearchPackagesBoundary;
1718
import org.hydev.mcpm.client.uninstall.UninstallBoundary;
@@ -134,11 +135,18 @@ public interface InteractorFactoryBoundary {
134135
*/
135136
ExportPluginsBoundary exportBoundary();
136137

138+
/**
139+
* Creates an `import` boundary object for exporting a list of installed plugins.
140+
*
141+
* @return A ImportPluginsBoundary object.
142+
*/
143+
ImportPluginsBoundary importBoundary();
137144
/**
138145
* Creates an `list` boundary object for listing installed plugins.
139146
*
140147
* @return A ListAllBoundary object.
141148
*/
149+
142150
ListAllBoundary listBoundary();
143151

144152
/**

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
package org.hydev.mcpm.client.arguments;
22

3-
import org.hydev.mcpm.client.arguments.parsers.CommandParser;
4-
import org.hydev.mcpm.client.arguments.parsers.ExportPluginsParser;
5-
import org.hydev.mcpm.client.arguments.parsers.InfoParser;
6-
import org.hydev.mcpm.client.arguments.parsers.InstallParser;
7-
import org.hydev.mcpm.client.arguments.parsers.ListParser;
8-
import org.hydev.mcpm.client.arguments.parsers.LoadParser;
9-
import org.hydev.mcpm.client.arguments.parsers.MirrorParser;
10-
import org.hydev.mcpm.client.arguments.parsers.PageParser;
11-
import org.hydev.mcpm.client.arguments.parsers.RefreshParser;
12-
import org.hydev.mcpm.client.arguments.parsers.ReloadParser;
13-
import org.hydev.mcpm.client.arguments.parsers.SearchParser;
14-
import org.hydev.mcpm.client.arguments.parsers.UninstallParser;
15-
import org.hydev.mcpm.client.arguments.parsers.UnloadParser;
16-
import org.hydev.mcpm.client.arguments.parsers.UpdateParser;
3+
import org.hydev.mcpm.client.arguments.parsers.*;
174
import org.hydev.mcpm.client.display.presenters.InstallPresenter;
185
import org.hydev.mcpm.client.display.presenters.SearchPresenter;
196

@@ -43,6 +30,7 @@ public static List<CommandParser> baseParsers(ControllerFactoryBoundary factory)
4330
*/
4431
return List.of(
4532
new ExportPluginsParser(factory.exportController()),
33+
new ImportParser(factory.importController()),
4634
new ListParser(factory.listController()),
4735
new SearchParser(factory.searchController(), searchPresenter),
4836
new MirrorParser(factory.mirrorController()),

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@
22

33
import net.sourceforge.argparse4j.inf.Namespace;
44
import net.sourceforge.argparse4j.inf.Subparser;
5-
import org.hydev.mcpm.client.commands.controllers.ExportPluginsController;
5+
import org.hydev.mcpm.client.commands.controllers.ExportController;
66
import org.hydev.mcpm.client.export.ExportPluginsInput;
77

8-
import java.io.FileOutputStream;
9-
import java.io.OutputStream;
108
import java.util.function.Consumer;
119

1210
/**
1311
* Parser for the ExportPluginsBoundary interface.
1412
*/
15-
public class ExportPluginsParser implements CommandParser
13+
public record ExportPluginsParser(ExportController controller) implements CommandParser
1614
{
17-
private final ExportPluginsController controller;
18-
19-
public ExportPluginsParser(ExportPluginsController controller)
20-
{
21-
this.controller = controller;
22-
}
23-
2415
@Override
2516
public String name()
2617
{
@@ -36,16 +27,16 @@ public String description()
3627
@Override
3728
public void configure(Subparser parser)
3829
{
39-
parser.addArgument("outfile") // add optional output file
40-
.type(FileOutputStream.class).dest("outfile"); // of type OutputStream
41-
parser.addArgument("-c", "--cache")
42-
.setDefault(true)
43-
.type(boolean.class).dest("cache");
30+
parser.addArgument("type").nargs("?").choices("pastebin", "file", "literal")
31+
.setDefault("pastebin") // type of output
32+
.type(String.class).dest("type");
33+
parser.addArgument("out").nargs("?")
34+
.type(String.class).dest("out");
4435
}
4536

4637
@Override
4738
public void run(Namespace details, Consumer<String> log)
4839
{
49-
controller.export(details.get("outfile"), details.get("cache"), log);
40+
controller.export(new ExportPluginsInput(details.get("type"), details.get("out")), log);
5041
}
5142
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.hydev.mcpm.client.arguments.parsers;
2+
3+
import net.sourceforge.argparse4j.inf.Namespace;
4+
import net.sourceforge.argparse4j.inf.Subparser;
5+
import org.hydev.mcpm.client.commands.controllers.ImportController;
6+
import org.hydev.mcpm.client.export.ImportInput;
7+
8+
import java.util.function.Consumer;
9+
10+
/**
11+
* Parser for the import use case
12+
*/
13+
public record ImportParser(ImportController controller) implements CommandParser {
14+
@Override
15+
public String name() {
16+
return "import";
17+
}
18+
19+
@Override
20+
public String description() {
21+
return "Import a plugins config from a previous export";
22+
}
23+
24+
@Override
25+
public void configure(Subparser parser) {
26+
parser.addArgument("type").nargs("?").choices("pastebin", "file", "literal")
27+
.setDefault("pastebin") // type of input
28+
.type(String.class).dest("type"); // of type OutputStream
29+
parser.addArgument("input")
30+
.type(String.class).dest("input");
31+
}
32+
33+
@Override
34+
public void run(Namespace details, Consumer<String> log) {
35+
controller.importPlugins(new ImportInput(details.get("type"), details.get("input")), log);
36+
}
37+
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
import net.sourceforge.argparse4j.inf.Subparser;
66
import org.hydev.mcpm.client.commands.controllers.InstallController;
77
import org.hydev.mcpm.client.commands.presenters.InstallResultPresenter;
8-
import org.hydev.mcpm.client.display.presenters.InstallPresenter;
9-
import org.hydev.mcpm.client.installer.InstallInteractor;
10-
import org.hydev.mcpm.client.installer.input.InstallInput;
118
import org.hydev.mcpm.client.installer.output.InstallResult;
129
import org.hydev.mcpm.client.search.SearchPackagesType;
1310

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import net.sourceforge.argparse4j.inf.Subparser;
66
import org.hydev.mcpm.client.commands.controllers.UpdateController;
77
import org.hydev.mcpm.client.display.presenters.LogUpdatePresenter;
8-
import org.hydev.mcpm.client.display.presenters.InstallPresenter;
9-
import org.hydev.mcpm.client.commands.presenters.InstallResultPresenter;
108

119
import java.util.function.Consumer;
1210

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.hydev.mcpm.client.commands.controllers;
2+
3+
import org.hydev.mcpm.client.commands.presenters.ExportPresenter;
4+
import org.hydev.mcpm.client.export.ExportPluginsBoundary;
5+
import org.hydev.mcpm.client.export.ExportPluginsInput;
6+
7+
import java.util.function.Consumer;
8+
9+
/**
10+
* Controller for the export plugins use case.
11+
*
12+
* @param boundary The export implementation
13+
* @param presenter The presenter to show the result
14+
*/
15+
public record ExportController(
16+
ExportPluginsBoundary boundary,
17+
ExportPresenter presenter
18+
) {
19+
20+
/**
21+
* Call the boundary to perform an export.
22+
*
23+
* @param input Input specifying the export parameters
24+
* @param log where to log the operation
25+
*/
26+
public void export(ExportPluginsInput input, Consumer<String> log) {
27+
var result = boundary.export(input);
28+
presenter.present(result, log);
29+
}
30+
}

0 commit comments

Comments
 (0)