Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ jobs:
uses: ./.github/workflows/build-platform.yml
with:
display-name: 'Build Paper platform'
gradle-tasks: 'platform:paper-plugin:build'
gradle-tasks: 'platform:paper-plugin:build -x test'

build-velocity:
name: 'Velocity Platform'
needs: build-common
uses: ./.github/workflows/build-platform.yml
with:
display-name: 'Build Velocity platform'
gradle-tasks: 'platform:velocity-plugin:build'
gradle-tasks: 'platform:velocity-plugin:build -x test'
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public CLIPlatform(PluginUpdaterCLI cli) {
fallbackInfoParser = fallbackInfoParser.getFallbackInfoParser();
}
} catch (IOException e) {
throw new RuntimeException(e);
cli.getLogger().log(Level.SEVERE, "Failed to interpret jar file for " + path, e);
}

return null;
Expand Down
8 changes: 8 additions & 0 deletions platform/paper-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ dependencies {
implementation(project(":common:impl"))
implementation(project(":platform:paper-api"))
implementation("io.github.revxrsal:lamp.bukkit:4.0.0-rc.17")

testImplementation(project(":tests:common-plugins-test"))
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

tasks {
Expand Down Expand Up @@ -47,6 +51,10 @@ tasks {
modrinth("z4HZZnLr", "zAlVhTdU") // FastAsyncWorldEdit
}
}

test {
useJUnitPlatform()
}
}

modrinth {
Expand Down
4 changes: 2 additions & 2 deletions platform/paper-plugin/src/main/resources/common-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ Geyser-Spigot:
source: geyser
project-name: geyser
GPFlags:
source: spigot
spigot-resource-id: 55773
source: modrinth
modrinth-project-id: Z0NVSlL6
GriefPrevention:
source: modrinth
modrinth-project-id: O4o4mKaq
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.lushplugins.pluginupdater.paper.test;

import org.junit.jupiter.api.Test;
import org.lushplugins.pluginupdater.tests.commonplugins.CommonPluginsTest;

public class PaperUpdaterTests {

static {
System.setProperty("platform", "paper");
System.setProperty("server-version", "26.1.2");
}

@Test
public void test() {
CommonPluginsTest.runTest("common-plugins.yml");
}
}
8 changes: 8 additions & 0 deletions platform/velocity-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ dependencies {
implementation(project(":platform:velocity-api"))
implementation("io.github.revxrsal:lamp.velocity:4.0.0-rc.17")
implementation("io.github.revxrsal:lamp.brigadier:4.0.0-rc.17")

testImplementation(project(":tests:common-plugins-test"))
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

tasks {
Expand All @@ -32,6 +36,10 @@ tasks {
modrinth("tab-was-taken", "MsHr6ITb")
}
}

test {
useJUnitPlatform()
}
}

modrinth {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.lushplugins.pluginupdater.paper.test;

import org.junit.jupiter.api.Test;
import org.lushplugins.pluginupdater.tests.commonplugins.CommonPluginsTest;

public class VelocityUpdaterTests {

static {
System.setProperty("platform", "velocity");
System.setProperty("server-version", "4.1.0");
}

@Test
public void test() {
CommonPluginsTest.runTest("common-plugins.yml");
}
}
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ include("platform:cli")
include("platform:paper-api")
include("platform:paper-plugin")
include("platform:velocity-api")
include("platform:velocity-plugin")
include("platform:velocity-plugin")
include("tests:common-plugins-test")
3 changes: 3 additions & 0 deletions tests/common-plugins-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {
implementation(project(":platform:cli"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package org.lushplugins.pluginupdater.tests.commonplugins;

import com.electronwill.nightconfig.core.Config;
import com.electronwill.nightconfig.yaml.YamlFormat;
import org.lushplugins.pluginupdater.api.updater.PluginData;
import org.lushplugins.pluginupdater.api.updater.PluginInfo;
import org.lushplugins.pluginupdater.api.util.UpdaterConstants;
import org.lushplugins.pluginupdater.cli.PluginUpdaterCLI;
import org.lushplugins.pluginupdater.cli.platform.CLIPlatform;
import org.lushplugins.pluginupdater.cli.plugin.CLIPluginInfo;
import org.lushplugins.pluginupdater.common.config.deserializer.PluginDataDeserializer;

import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.logging.Level;

public class CommonPluginsTest {

static {
Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
StringWriter sw = new StringWriter();
throwable.printStackTrace(new PrintWriter(sw));
UpdaterConstants.LOGGER.severe(sw.toString());
});
}

public static void testLocalVersionParsing(List<PluginData> commonPluginData) {

}

public static void runTest(String pluginsResource) {
PluginUpdaterCLI cli = PluginUpdaterCLI.prepareCLI();

boolean passing = true;
InputStream resource = cli.getResourceStream(pluginsResource);
Config config = YamlFormat.defaultInstance().createParser().parse(resource);
List<PluginData> undownloadedPluginData = config.entrySet().stream()
.map((entry) -> {
// The following method requires PluginInfo to be available before being run but does not use the
// current version so we can just supply an empty version
PluginInfo pluginInfo = new CLIPluginInfo(entry.getKey(), "0.0.0", null);
Config pluginConfig = config.get(entry.getKey());
// As we are hard coding the local version we must remove the version-format option
pluginConfig.remove("version-format");
return PluginDataDeserializer.deserialize(pluginInfo, pluginConfig);
})
.filter(Objects::nonNull)
.sorted(Comparator.comparing((pluginData) -> pluginData.pluginName().toLowerCase()))
.toList();

// We fetch all latest versions and then download all jars
// This is to ensure that each process is handled in batches
for (PluginData pluginData : undownloadedPluginData) {
cli.getLogger().info("Fetching %s's latest version"
.formatted(pluginData.pluginName()));
try {
pluginData.latestVersion(pluginData.fetchLatestVersion().version());
} catch (RuntimeException e) {
cli.getLogger().severe(e.getMessage());
passing = false;
}
}

Path downloadDir = cli.getPluginsFolder();
for (PluginData pluginData : undownloadedPluginData) {
try {
pluginData.downloadUpdate(downloadDir);
} catch (Throwable e) {
cli.getLogger().log(Level.SEVERE, "Failed to download latest version of " + pluginData.pluginName(), e);
passing = false;
}
}

// Platform needs to be created after plugins are downloaded as it collects data from jars on startup
CLIPlatform platform = new CLIPlatform(cli);
List<PluginData> commonPluginData = config.entrySet().stream()
.map((entry) -> {
String pluginName = entry.getKey();
PluginInfo pluginInfo = platform.getPlugin(pluginName);
if (pluginInfo == null) {
cli.getLogger().log(Level.WARNING, "Failed to find plugin jar for %s"
.formatted(pluginName));
return null;
}

return PluginDataDeserializer.deserialize(pluginInfo, config.get(pluginName));
})
.filter(Objects::nonNull)
.toList();

testLocalVersionParsing(commonPluginData);

if (!passing) {
throw new IllegalStateException("This test has been marked as failed");
}
}
}
Loading