Skip to content

Commit d554091

Browse files
committed
Merge branch 'main' into patch-mirror
2 parents f537576 + e0a0234 commit d554091

File tree

75 files changed

+1959
-853
lines changed

Some content is hidden

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

75 files changed

+1959
-853
lines changed

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
@@ -51,6 +51,7 @@ task checkStyle(type: GradleBuild) {
5151
dependencies {
5252
// The Spigot API with no shadowing. Requires the OSS repo.
5353
compileOnly 'org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT'
54+
testImplementation 'org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT'
5455

5556
// Argument parser
5657
// https://mvnrepository.com/artifact/net.sourceforge.argparse4j/argparse4j
@@ -90,6 +91,10 @@ dependencies {
9091
// https://mvnrepository.com/artifact/com.github.luben/zstd-jni
9192
implementation 'com.github.luben:zstd-jni:1.5.2-5'
9293

94+
// ZSTD but pure java for platforms that doesn't support native
95+
// https://mvnrepository.com/artifact/io.airlift/aircompressor
96+
implementation 'io.airlift:aircompressor:0.21'
97+
9398
// Unit tests
9499
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
95100
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/Constants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
*/
1717
public class Constants
1818
{
19+
// This is technically not a constant, but it should only be changed by SpigotEntry to true.
20+
// It cannot be put inside SpigotEntry because accessing SpigotEntry would try to initialize the class, then it
21+
// will try to import Spigot packages which doesn't exist outside of Spigot.
22+
public static boolean IS_MINECRAFT = false;
23+
1924
public static final ObjectMapper JACKSON = new ObjectMapper()
2025
.disable(FAIL_ON_UNKNOWN_PROPERTIES).enable(INDENT_OUTPUT);
2126

src/main/java/org/hydev/mcpm/SpigotEntry.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44
import org.bukkit.command.Command;
55
import org.bukkit.command.CommandExecutor;
66
import org.bukkit.command.CommandSender;
7-
import org.bukkit.command.TabCompleter;
87
import org.bukkit.plugin.java.JavaPlugin;
98
import org.hydev.mcpm.client.arguments.ArgsParser;
109
import org.hydev.mcpm.client.arguments.CommandsFactory;
1110
import org.hydev.mcpm.client.arguments.parsers.CommandParser;
1211
import org.hydev.mcpm.utils.ColorLogger;
1312
import org.jetbrains.annotations.NotNull;
14-
import org.jetbrains.annotations.Nullable;
1513

1614
import java.util.ArrayList;
17-
import java.util.Arrays;
1815
import java.util.List;
1916
import java.util.logging.Logger;
2017

@@ -25,6 +22,12 @@
2522
*/
2623
public class SpigotEntry extends JavaPlugin implements CommandExecutor
2724
{
25+
public SpigotEntry()
26+
{
27+
// Let the other parts of our program know that we're in minecraft
28+
Constants.IS_MINECRAFT = true;
29+
}
30+
2831
private Logger log;
2932

3033
private ArgsParser parser;

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

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
package org.hydev.mcpm.client;
22

3+
import org.hydev.mcpm.client.database.LocalPluginTracker;
34
import org.hydev.mcpm.client.database.PluginTracker;
45
import org.hydev.mcpm.client.database.boundary.SearchPackagesBoundary;
6+
import org.hydev.mcpm.client.database.fetcher.LocalDatabaseFetcher;
57
import org.hydev.mcpm.client.database.inputs.SearchPackagesInput;
68
import org.hydev.mcpm.client.database.results.SearchPackagesResult;
9+
import org.hydev.mcpm.client.database.searchusecase.SearchInteractor;
710
import org.hydev.mcpm.client.installer.InstallResult;
811
import org.hydev.mcpm.client.installer.input.InstallInput;
912
import org.hydev.mcpm.client.models.PluginVersion;
1013
import org.hydev.mcpm.client.models.PluginYml;
1114

15+
import java.net.URI;
1216
import java.util.List;
1317

1418
/**
1519
* Database API
1620
*/
1721
public class DatabaseManager {
18-
1922
private final PluginTracker localPluginTracker;
2023
private final SearchPackagesBoundary searchInteractor;
2124

22-
public DatabaseManager(PluginTracker localPluginTracker, SearchPackagesBoundary searchInteractor) {
23-
this.localPluginTracker = localPluginTracker;
24-
this.searchInteractor = searchInteractor;
25+
public DatabaseManager(PluginTracker tracker, SearchPackagesBoundary searcher) {
26+
this.localPluginTracker = tracker;
27+
this.searchInteractor = searcher;
2528
}
2629

2730
/**
2831
*
29-
* Search if the plugin exists, throw exception if it does not exist and return the information of
30-
* the pluigin needs to be installed.
32+
* Search if the plugin exists, return the Search Results
3133
*
32-
* @param input the plugin input pending for installation
34+
* @param input the input pending for installation
3335
*/
3436
public SearchPackagesResult getSearchResult(InstallInput input) {
3537
SearchPackagesInput searchPackagesInput = new SearchPackagesInput(input.type(), input.name(), false);
@@ -39,16 +41,35 @@ public SearchPackagesResult getSearchResult(InstallInput input) {
3941
}
4042

4143
/**
42-
* check if plugin already installed locally
44+
* check if plugin with given version already installed locally
45+
*
46+
* @param pluginName The version of the installed plugin
47+
* */
48+
public boolean checkPluginInstalledByName(String pluginName) {
49+
var name = pluginName;
50+
51+
List<PluginYml> pluginInstalled = localPluginTracker.listInstalled();
52+
for (PluginYml pluginYml : pluginInstalled) {
53+
if (pluginYml != null && pluginYml.name() != null && pluginYml.name().equals(name)) {
54+
return true;
55+
}
56+
}
57+
return false;
58+
}
59+
60+
61+
/**
62+
* check if plugin with given name already installed locally
4363
*
4464
* @param pluginVersion The version of the installed plugin
4565
* */
46-
public boolean checkPluginInstalled(PluginVersion pluginVersion) {
66+
public boolean checkPluginInstalledByVersion(PluginVersion pluginVersion) {
4767
var name = pluginVersion.meta().name();
4868

4969
List<PluginYml> pluginInstalled = localPluginTracker.listInstalled();
5070
for (PluginYml pluginYml : pluginInstalled) {
51-
if (pluginYml != null && pluginYml.name() != null && pluginYml.name().equals(name)) {
71+
if (pluginYml != null && pluginYml.version() != null &&
72+
pluginYml.version().equals(pluginVersion.meta().version())) {
5273
return true;
5374
}
5475
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99

1010
import java.io.*;
1111
import java.net.HttpURLConnection;
12+
import java.net.URL;
1213
import java.nio.file.Files;
1314
import java.util.ArrayList;
1415
import java.util.HashMap;
15-
import java.util.List;
1616
import java.util.Map;
17-
import java.net.URL;
1817
import java.util.concurrent.ExecutorService;
1918
import java.util.concurrent.Executors;
20-
import java.util.concurrent.TimeUnit;
2119

2220
import static java.lang.String.format;
2321

@@ -140,18 +138,20 @@ public Downloader threads(int threads)
140138
/**
141139
* Displays a demo for downloader.
142140
*
143-
* @param args Arguments are ignored.
141+
* @param args Not used
144142
*/
145-
public static void main(String[] args) throws IOException {
146-
// Remember to chang link to test
147-
String link = "https://sd.blackball.lv/library/Introduction_to_Algorithms_Third_Edition_(2009).pdf";
148-
File out = new File("./Introduction_to_Algorithms_Third_Edition.pdf");
149-
String link1 = "https://www.iusb.edu/students/academic-success-programs/academic-centers-for-excellence/docs/Basic%20Math%20Review%20Card.pdf";
150-
File out1 = new File("./Math.pdf");
151-
Downloader downloader = new Downloader();
143+
public static void main(String[] args)
144+
{
145+
String link = "https://mcpm.hydev.org/db";
146+
File out = new File("./build/db.json");
147+
String link1 = "https://mcpm.hydev.org/db.zst";
148+
File out1 = new File("./build/db.zst");
149+
Downloader downloader = new Downloader().showProgress(true).threads(2);
152150
Map<String, File> urls = new HashMap<>();
153151
urls.put(link, out);
154152
urls.put(link1, out1);
155153
downloader.downloadFiles(urls);
154+
out.delete();
155+
out1.delete();
156156
}
157157
}

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
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;
1113
import org.hydev.mcpm.client.database.fetcher.ProgressBarFetcherListener;
@@ -14,6 +16,7 @@
1416
import org.hydev.mcpm.client.injector.PluginLoader;
1517
import org.hydev.mcpm.client.installer.InstallInteractor;
1618
import org.hydev.mcpm.client.installer.SpigotPluginDownloader;
19+
import org.hydev.mcpm.client.updater.UpdateInteractor;
1720
import org.hydev.mcpm.utils.ColorLogger;
1821

1922
import java.util.List;
@@ -32,24 +35,34 @@ private CommandsFactory() { }
3235
/**
3336
* Creates a list of general parsers for the ArgsParser class.
3437
*
38+
* @param isMinecraft If we're in the minecraft env
3539
* @return Returns a list of argument parsers that work in any environment (Server & CLI).
3640
*/
37-
public static List<CommandParser> baseParsers() {
38-
var fetcherListener = new ProgressBarFetcherListener();
41+
public static List<CommandParser> baseParsers(boolean isMinecraft) {
3942
var mirror = new MirrorSelector();
4043
var fetcher = new LocalDatabaseFetcher(mirror.selectedMirrorSupplier());
4144
var tracker = new LocalPluginTracker();
42-
var searcher = new SearchInteractor(fetcher, fetcherListener);
45+
var loader = isMinecraft ? new PluginLoader() : null;
46+
var listener = new ProgressBarFetcherListener();
47+
var searcher = new SearchInteractor(fetcher, listener);
48+
var installer = new InstallInteractor(
49+
new SpigotPluginDownloader(new Downloader(), mirror.selectedMirrorSupplier()),
50+
new DatabaseManager(tracker, searcher),
51+
loader
52+
);
53+
var matcher = new MatchPluginsInteractor(fetcher, listener);
54+
var updateChecker = new CheckForUpdatesInteractor(matcher);
55+
var updater = new UpdateInteractor(updateChecker, installer, tracker);
56+
57+
// Controllers
4358
var exportPluginsController = new ExportPluginsController(new ExportInteractor(tracker));
4459
var listController = new ListController(new ListAllInteractor(tracker));
45-
4660
var searchController = new SearchPackagesController(searcher);
4761
var mirrorController = new MirrorController(mirror);
4862
var infoController = new InfoController(tracker);
49-
var installController = new InstallController(new InstallInteractor(
50-
new SpigotPluginDownloader(new Downloader(), mirror.selectedMirrorSupplier()),
51-
new DatabaseManager(tracker, searcher)));
52-
var refreshController = new RefreshController(fetcher, fetcherListener, mirror);
63+
var installController = new InstallController(installer);
64+
var updateController = new UpdateController(updater);
65+
var refreshController = new RefreshController(fetcher, listener, mirror);
5366

5467
/*
5568
* Add general parsers to this list!
@@ -63,7 +76,8 @@ public static List<CommandParser> baseParsers() {
6376
new MirrorParser(mirrorController),
6477
new InfoParser(infoController),
6578
new InstallParser(installController),
66-
new RefreshParser(refreshController)
79+
new RefreshParser(refreshController),
80+
new UpdateParser(updateController)
6781
);
6882
}
6983

@@ -90,7 +104,7 @@ public static List<CommandParser> serverParsers() {
90104
new UnloadParser(unloadController)
91105
);
92106

93-
return Stream.concat(baseParsers().stream(), serverOnly.stream()).toList();
107+
return Stream.concat(baseParsers(true).stream(), serverOnly.stream()).toList();
94108
}
95109

96110
/**
@@ -99,7 +113,7 @@ public static List<CommandParser> serverParsers() {
99113
* @return An ArgsParser object. Invoke ArgsParser#parse to see more.
100114
*/
101115
public static ArgsParser baseArgsParser() {
102-
return new ArgsParser(baseParsers(), ColorLogger.toStdOut());
116+
return new ArgsParser(baseParsers(false), ColorLogger.toStdOut());
103117
}
104118

105119
/**

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
}

0 commit comments

Comments
 (0)