Skip to content

Commit 12900c1

Browse files
committed
Merge branch 'main' into uninstall_redone
2 parents 13ad14c + e0a0234 commit 12900c1

File tree

71 files changed

+1874
-811
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1874
-811
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ build
3131
data
3232
.mcpm
3333
*.pyc
34+
35+
plugins

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ There's 3 different ways you can search for new plugins:
9494
You can execute these commands in any environment using the `search` subcommand:
9595
```shell
9696
mcpm search JedCore # Search for a plugin with the name "JedCore"
97-
mcpm search --by-keyword "protect land" # Search for a plugin that has protect in its description.
98-
mcpm search --by-command claim # Search for a plugin that provides a /claim command.
97+
mcpm search --keyword "protect land" # Search for a plugin that has protect in its description.
98+
mcpm search --command claim # Search for a plugin that provides a /claim command.
9999
```
100100

101101
# Install Plugins
@@ -112,8 +112,6 @@ For example, you can install a plugin that provides a `claim` command using the
112112

113113
```shell
114114
mcpm install JedCore # Installs the latest version of the JedCore plugin.
115-
mcpm install --by-keyword "protect land" # This is also provided for consistency with search.
116-
mcpm install --by-command claim # This will install the latest version of a command that provides claim!
117115
```
118116

119117
We recommend you use the search command before installing anything,

build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ checkstyle {
4747
dependencies {
4848
// The Spigot API with no shadowing. Requires the OSS repo.
4949
compileOnly 'org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT'
50+
testImplementation 'org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT'
5051

5152
// Argument parser
5253
// https://mvnrepository.com/artifact/net.sourceforge.argparse4j/argparse4j
@@ -86,6 +87,10 @@ dependencies {
8687
// https://mvnrepository.com/artifact/com.github.luben/zstd-jni
8788
implementation 'com.github.luben:zstd-jni:1.5.2-5'
8889

90+
// ZSTD but pure java for platforms that doesn't support native
91+
// https://mvnrepository.com/artifact/io.airlift/aircompressor
92+
implementation 'io.airlift:aircompressor:0.21'
93+
8994
// Unit tests
9095
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
9196
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'

crawl.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Get script dir
5+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
6+
pushd "$SCRIPT_DIR"
7+
8+
PY="/home/azalea/.conda/envs/310/bin/python3"
9+
10+
# Crawl packages
11+
$PY -m tools.run org.hydev.mcpm.server.crawlers.SpigetCrawler
12+
13+
# Create database
14+
$PY -m tools.run org.hydev.mcpm.server.crawlers.spiget.CreateDatabase
15+
16+
# Zstd compression
17+
rm -rf .mcpm/db.zst
18+
zstd -f -19 -T36 .mcpm/db
19+
20+
popd

src/main/java/org/hydev/mcpm/client/Downloader.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010
import java.io.ByteArrayOutputStream;
1111
import java.io.File;
1212
import java.io.IOException;
13+
import java.io.*;
14+
import java.net.HttpURLConnection;
15+
import java.net.URL;
1316
import java.nio.file.Files;
1417
import java.util.HashMap;
1518
import java.util.Map;
1619
import java.util.concurrent.ExecutorService;
1720
import java.util.concurrent.Executors;
1821

22+
import static java.lang.String.format;
23+
1924
/**
2025
* File downloader
2126
*
@@ -135,7 +140,7 @@ public Downloader threads(int threads)
135140
/**
136141
* Displays a demo for downloader.
137142
*
138-
* @param args Arguments are ignored.
143+
* @param args Not used
139144
*/
140145
public static void main(String[] args) throws IOException
141146
{
@@ -159,5 +164,7 @@ public static void main(String[] args) throws IOException
159164
urls.put(link3, out3);
160165
urls.put(link4, out4);
161166
downloader.downloadFiles(urls);
167+
out.delete();
168+
out1.delete();
162169
}
163170
}

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44
import org.hydev.mcpm.client.Downloader;
55
import org.hydev.mcpm.client.arguments.parsers.*;
66
import org.hydev.mcpm.client.commands.entries.*;
7+
import org.hydev.mcpm.client.database.CheckForUpdatesInteractor;
78
import org.hydev.mcpm.client.database.ListAllInteractor;
89
import org.hydev.mcpm.client.database.LocalPluginTracker;
10+
import org.hydev.mcpm.client.database.MatchPluginsInteractor;
911
import org.hydev.mcpm.client.database.export.ExportInteractor;
1012
import org.hydev.mcpm.client.database.fetcher.LocalDatabaseFetcher;
13+
import org.hydev.mcpm.client.database.fetcher.ProgressBarFetcherListener;
1114
import org.hydev.mcpm.client.database.mirrors.MirrorSelector;
1215
import org.hydev.mcpm.client.database.searchusecase.SearchInteractor;
1316
import org.hydev.mcpm.client.injector.LocalJarFinder;
1417
import org.hydev.mcpm.client.injector.PluginLoader;
1518
import org.hydev.mcpm.client.installer.InstallInteractor;
1619
import org.hydev.mcpm.client.installer.SpigotPluginDownloader;
1720
import org.hydev.mcpm.client.uninstall.Uninstaller;
21+
import org.hydev.mcpm.client.updater.UpdateInteractor;
1822
import org.hydev.mcpm.utils.ColorLogger;
1923

2024
import java.net.URI;
@@ -41,13 +45,19 @@ public static List<CommandParser> baseParsers(boolean isMinecraft) {
4145
var host = URI.create("https://mcpm.hydev.org");
4246
var fetcher = new LocalDatabaseFetcher(host);
4347
var tracker = new LocalPluginTracker();
44-
var searcher = new SearchInteractor(fetcher);
4548
var jarFinder = new LocalJarFinder();
4649

47-
PluginLoader pluginLoader = null;
48-
if (isMinecraft) {
49-
pluginLoader = new PluginLoader(jarFinder);
50-
}
50+
var loader = isMinecraft ? new PluginLoader(jarFinder) : null;
51+
var listener = new ProgressBarFetcherListener();
52+
var searcher = new SearchInteractor(fetcher, listener);
53+
var installer = new InstallInteractor(
54+
new SpigotPluginDownloader(new Downloader(), host.toString()),
55+
new DatabaseManager(tracker, searcher),
56+
loader
57+
);
58+
var matcher = new MatchPluginsInteractor(fetcher, listener);
59+
var updateChecker = new CheckForUpdatesInteractor(matcher);
60+
var updater = new UpdateInteractor(updateChecker, installer, tracker);
5161

5262
var exportPluginsController = new ExportPluginsController(new ExportInteractor(tracker));
5363
var listController = new ListController(new ListAllInteractor(tracker));
@@ -56,10 +66,9 @@ public static List<CommandParser> baseParsers(boolean isMinecraft) {
5666
var infoController = new InfoController(tracker);
5767

5868
var databaseManager = new DatabaseManager(tracker, searcher);
59-
var installController = new InstallController(new InstallInteractor(
60-
new SpigotPluginDownloader(new Downloader(), host.toString()),
61-
databaseManager, pluginLoader));
62-
var uninstallController = new UninstallController(new Uninstaller(tracker, pluginLoader, jarFinder));
69+
var installController = new InstallController(installer);
70+
var uninstallController = new UninstallController(new Uninstaller(tracker, loader, jarFinder));
71+
var updateController = new UpdateController(updater);
6372

6473
/*
6574
* Add general parsers to this list!
@@ -73,7 +82,8 @@ public static List<CommandParser> baseParsers(boolean isMinecraft) {
7382
new MirrorParser(mirrorController),
7483
new InfoParser(infoController),
7584
new InstallParser(installController),
76-
new UninstallParser(uninstallController)
85+
new UninstallParser(uninstallController),
86+
new UpdateParser(updateController)
7787
);
7888
}
7989

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public void run(Namespace details, Consumer<String> log)
3535
{
3636
case "ping" -> controller.ping(details.getBoolean("refresh"), log);
3737
case "select" -> controller.select(details.getString("host"), log);
38+
default -> throw new RuntimeException();
3839
}
3940
}
4041

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

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44
import net.sourceforge.argparse4j.inf.Namespace;
55
import net.sourceforge.argparse4j.inf.Subparser;
66
import org.hydev.mcpm.client.commands.entries.SearchPackagesController;
7+
8+
import java.util.List;
79
import java.util.function.Consumer;
810

911
/**
1012
* SearchParser has two arguments: "type" and "text."
1113
* When the user runs the search command, the program prompts the user to specify the type of
1214
* search and the search text.
15+
*
16+
* @author Jerry Zhu (https://github.com/jerryzhu509)
1317
*/
14-
public class SearchParser implements CommandParser {
15-
private final SearchPackagesController controller;
16-
17-
public SearchParser(SearchPackagesController controller) {
18-
this.controller = controller;
19-
}
20-
18+
public record SearchParser(SearchPackagesController controller) implements CommandParser {
2119
@Override
2220
public String name() {
2321
return "search";
@@ -30,20 +28,31 @@ public String description() {
3028

3129
@Override
3230
public void configure(Subparser parser) {
33-
parser.addArgument("by").choices("name", "keyword", "command")
34-
.setDefault("name").dest("type")
35-
.help("Specifies the Type of Search");
31+
// Default search by name, if -k is specified then search by keyword
32+
var type = parser.addMutuallyExclusiveGroup();
33+
type.addArgument("-k", "--keyword").action(Arguments.storeTrue()).dest("byKeyword")
34+
.help("Search by keyword in descriptions");
35+
type.addArgument("-c", "--command").action(Arguments.storeTrue()).dest("byCommand")
36+
.help("Search by command");
37+
38+
// Content of the search
3639
parser.addArgument("text").dest("text").nargs("+")
37-
.help("Specifies the search text.");
40+
.help("Specifies the search text.");
3841
parser.addArgument("-n", "--no-cache").action(Arguments.storeTrue()).dest("noCache")
39-
.help("Specifies whether to use local cache or not.");
42+
.help("Specifies whether to use local cache or not.");
4043
}
4144

4245
@Override
4346
public void run(Namespace details, Consumer<String> log) {
44-
var t = details.getList("text");
45-
controller.searchPackages(details.getString("type"),
46-
String.join(" ", details.getList("text")),
47-
!details.getBoolean("noCache"), log);
47+
// Convert type
48+
var type = "name";
49+
if (details.getBoolean("byKeyword"))
50+
type = "keyword";
51+
if (details.getBoolean("byCommand"))
52+
type = "command";
53+
54+
// Call searchPackages
55+
List<String> t = details.getList("text");
56+
controller.searchPackages(type, String.join(" ", t), !details.getBoolean("noCache"), log);
4857
}
4958
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package org.hydev.mcpm.client.arguments.parsers;
2+
3+
import net.sourceforge.argparse4j.impl.Arguments;
4+
import net.sourceforge.argparse4j.inf.Namespace;
5+
import net.sourceforge.argparse4j.inf.Subparser;
6+
import org.hydev.mcpm.client.commands.entries.UpdateController;
7+
import org.hydev.mcpm.client.commands.presenters.LogUpdatePresenter;
8+
9+
import java.util.function.Consumer;
10+
11+
/**
12+
* Handles parsing related to the update command.
13+
*
14+
* @param controller A controller to dispatch an update command when invoked.
15+
*/
16+
public record UpdateParser(UpdateController controller) implements CommandParser {
17+
@Override
18+
public String name() {
19+
return "update";
20+
}
21+
22+
@Override
23+
public String description() {
24+
return "Updates plugins to the latest version.";
25+
}
26+
27+
@Override
28+
public void configure(Subparser parser) {
29+
// if (Constants.IS_MINECRAFT) {
30+
parser.addArgument("--load")
31+
.type(boolean.class)
32+
.action(Arguments.storeTrue())
33+
.dest("load")
34+
.help("If true, updated plugins will be reloaded after the update.");
35+
// }
36+
37+
parser.addArgument("--no-cache")
38+
.type(boolean.class)
39+
.action(Arguments.storeTrue())
40+
.dest("no-cache")
41+
.help("If true, the cache will be skipped and database will be fetched again.");
42+
43+
parser.addArgument("names")
44+
.nargs("*")
45+
.help("List of plugin names to update.");
46+
}
47+
48+
@Override
49+
public void run(Namespace details, Consumer<String> log) {
50+
// Since log can change from invocation to invocation,
51+
// and I don't want UpdatePresenter to depend on Consumer<String>,
52+
// I'll instantiate this every call.
53+
var presenter = new LogUpdatePresenter(log);
54+
55+
controller.update(
56+
details.getList("names"),
57+
details.getBoolean("load"),
58+
details.getBoolean("no-cache"),
59+
presenter
60+
);
61+
}
62+
}

src/main/java/org/hydev/mcpm/client/commands/entries/SearchPackagesController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public SearchPackagesController(SearchPackagesBoundary searcher) {
3030
* Load plugins and output status to log.
3131
*
3232
* @param type String that specifies the type of search.
33-
* @param text String that secifies the search text.
33+
* @param text String that specifies the search text.
3434
* @param noCache Specifies whether to use local cache or not.
3535
* @param log Callback for status for log events.
3636
*/

0 commit comments

Comments
 (0)