Skip to content

Commit 95535e8

Browse files
committed
Merge
2 parents 16d0cc2 + d1e822c commit 95535e8

Some content is hidden

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

44 files changed

+1011
-206
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
@@ -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/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: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.hydev.mcpm.client.arguments;
22

3+
import org.hydev.mcpm.Constants;
34
import org.hydev.mcpm.client.DatabaseManager;
45
import org.hydev.mcpm.client.Downloader;
56
import org.hydev.mcpm.client.arguments.parsers.*;
@@ -32,9 +33,10 @@ private CommandsFactory() { }
3233
/**
3334
* Creates a list of general parsers for the ArgsParser class.
3435
*
36+
* @param isMinecraft If we're in the minecraft env
3537
* @return Returns a list of argument parsers that work in any environment (Server & CLI).
3638
*/
37-
public static List<CommandParser> baseParsers() {
39+
public static List<CommandParser> baseParsers(boolean isMinecraft) {
3840
var host = URI.create("https://mcpm.hydev.org");
3941
var fetcher = new LocalDatabaseFetcher(host);
4042
var tracker = new LocalPluginTracker();
@@ -44,9 +46,16 @@ public static List<CommandParser> baseParsers() {
4446
var searchController = new SearchPackagesController(searcher);
4547
var mirrorController = new MirrorController(new MirrorSelector());
4648
var infoController = new InfoController(tracker);
49+
PluginLoader pluginLoader = null;
50+
if (isMinecraft) {
51+
pluginLoader = new PluginLoader();
52+
}
53+
DatabaseManager databaseManager = new DatabaseManager(tracker, searcher);
54+
System.out.println(isMinecraft);
4755
var installController = new InstallController(new InstallInteractor(
4856
new SpigotPluginDownloader(new Downloader(), host.toString()),
49-
new DatabaseManager(tracker, searcher)));
57+
databaseManager, pluginLoader));
58+
5059

5160
/*
5261
* Add general parsers to this list!
@@ -86,7 +95,7 @@ public static List<CommandParser> serverParsers() {
8695
new UnloadParser(unloadController)
8796
);
8897

89-
return Stream.concat(baseParsers().stream(), serverOnly.stream()).toList();
98+
return Stream.concat(baseParsers(true).stream(), serverOnly.stream()).toList();
9099
}
91100

92101
/**
@@ -95,7 +104,7 @@ public static List<CommandParser> serverParsers() {
95104
* @return An ArgsParser object. Invoke ArgsParser#parse to see more.
96105
*/
97106
public static ArgsParser baseArgsParser() {
98-
return new ArgsParser(baseParsers(), ColorLogger.toStdOut());
107+
return new ArgsParser(baseParsers(false), ColorLogger.toStdOut());
99108
}
100109

101110
/**

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public record InstallController(InstallBoundary boundary)
2121
* @param log Log string
2222
*/
2323
public void install(String name, SearchPackagesType type, boolean load, Consumer<String> log) {
24-
// TODO: log error
25-
InstallInput input = new InstallInput(name, type, load, true);
26-
boundary.installPlugin(input);
27-
log.accept("string");
24+
// TODO: User-friendly outputs
25+
var input = new InstallInput(name, type, load, true);
26+
var output = boundary.installPlugin(input);
27+
log.accept(output.type().reason());
2828
}
2929
}

src/main/java/org/hydev/mcpm/client/database/fetcher/LocalDatabaseFetcher.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.apache.hc.core5.http.io.entity.EntityUtils;
99
import org.hydev.mcpm.client.models.Database;
1010
import org.hydev.mcpm.utils.HashUtils;
11+
import org.hydev.mcpm.utils.ZstdUtils;
1112
import org.jetbrains.annotations.Nullable;
1213

1314
import java.io.ByteArrayOutputStream;
@@ -17,7 +18,6 @@
1718
import java.nio.file.Files;
1819
import java.nio.file.Path;
1920
import java.nio.file.Paths;
20-
import java.security.NoSuchAlgorithmException;
2121

2222
import static org.hydev.mcpm.Constants.JACKSON;
2323

@@ -29,7 +29,8 @@ public class LocalDatabaseFetcher implements DatabaseFetcher {
2929
private final Path cacheDirectory;
3030

3131
private Database localDatabase;
32-
private boolean enableCompression = true;
32+
33+
public static final boolean ENABLE_COMPRESSION = true;
3334

3435
public static final String HASH_FILE_NAME = "db.hash";
3536
public static final String DATABASE_FILE_NAME = "db";
@@ -152,7 +153,7 @@ private String readDatabaseFromContent(HttpEntity entity, DatabaseFetcherListene
152153
listener.finish();
153154

154155
// Decompress ZSTD
155-
if (this.enableCompression)
156+
if (ENABLE_COMPRESSION)
156157
{
157158
var bs = builder.toByteArray();
158159
bs = Zstd.decompress(bs, (int) Zstd.decompressedSize(bs));
@@ -166,7 +167,7 @@ private String readDatabaseFromContent(HttpEntity entity, DatabaseFetcherListene
166167
private Database fetchHostDatabase(DatabaseFetcherListener listener) {
167168
try (var client = HttpClients.createDefault()) {
168169
var body = client.execute(
169-
requestTo(enableCompression ? DATABASE_ZST_FILE_NAME : DATABASE_FILE_NAME),
170+
requestTo(ENABLE_COMPRESSION ? DATABASE_ZST_FILE_NAME : DATABASE_FILE_NAME),
170171
request -> readDatabaseFromContent(request.getEntity(), listener)
171172
);
172173

@@ -175,17 +176,13 @@ private Database fetchHostDatabase(DatabaseFetcherListener listener) {
175176
if (database != null) {
176177
localDatabase = database;
177178

178-
try {
179-
var hash = new HashUtils().hash(body);
179+
var hash = new HashUtils().hash(body);
180180

181-
//noinspection ResultOfMethodCallIgnored
182-
cacheDirectory.toFile().mkdirs();
181+
//noinspection ResultOfMethodCallIgnored
182+
cacheDirectory.toFile().mkdirs();
183183

184-
Files.writeString(Paths.get(cacheDirectory.toString(), DATABASE_FILE_NAME), body);
185-
Files.writeString(Paths.get(cacheDirectory.toString(), HASH_FILE_NAME), hash);
186-
} catch (NoSuchAlgorithmException e) {
187-
e.printStackTrace();
188-
}
184+
Files.writeString(Paths.get(cacheDirectory.toString(), DATABASE_FILE_NAME), body);
185+
Files.writeString(Paths.get(cacheDirectory.toString(), HASH_FILE_NAME), hash);
189186
}
190187

191188
return database;
@@ -210,10 +207,4 @@ public Database fetchDatabase(boolean cache, DatabaseFetcherListener listener) {
210207

211208
return fetchHostDatabase(listener);
212209
}
213-
214-
public LocalDatabaseFetcher enableCompression(boolean enableCompression)
215-
{
216-
this.enableCompression = enableCompression;
217-
return this;
218-
}
219210
}

0 commit comments

Comments
 (0)