From 46f726e94e43612e058c10c693d4366a5c5aeead Mon Sep 17 00:00:00 2001 From: Yeregorix Date: Thu, 3 Sep 2026 22:01:56 +0200 Subject: [PATCH 1/2] Add PluginContainer#resource --- .../spongepowered/plugin/PluginContainer.java | 16 ++++++++++++++++ .../plugin/builtin/StandardPluginContainer.java | 12 +++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/spongepowered/plugin/PluginContainer.java b/src/main/java/org/spongepowered/plugin/PluginContainer.java index 9a79d17..ebbfa88 100644 --- a/src/main/java/org/spongepowered/plugin/PluginContainer.java +++ b/src/main/java/org/spongepowered/plugin/PluginContainer.java @@ -25,6 +25,7 @@ package org.spongepowered.plugin; import org.apache.logging.log4j.Logger; +import org.spongepowered.plugin.discovery.PluginResource; import org.spongepowered.plugin.metadata.PluginMetadata; /** @@ -35,6 +36,11 @@ */ public interface PluginContainer extends ResourceQueryable { + /** + * @return The {@link PluginResource plugin resource} + */ + PluginResource resource(); + /** * @return The {@link PluginMetadata plugin metadata} */ @@ -52,4 +58,14 @@ public interface PluginContainer extends ResourceQueryable { default Object instance() { return this; } + + @Override + default Optional locateResource(final String path) { + return this.resource().locate(path); + } + + @Override + default Optional openResource(final String path) { + return this.resource().open(path); + } } diff --git a/src/main/java/org/spongepowered/plugin/builtin/StandardPluginContainer.java b/src/main/java/org/spongepowered/plugin/builtin/StandardPluginContainer.java index 1bbe20b..f47c7a5 100644 --- a/src/main/java/org/spongepowered/plugin/builtin/StandardPluginContainer.java +++ b/src/main/java/org/spongepowered/plugin/builtin/StandardPluginContainer.java @@ -30,9 +30,7 @@ import org.spongepowered.plugin.discovery.PluginResource; import org.spongepowered.plugin.metadata.PluginMetadata; -import java.net.URI; import java.util.Objects; -import java.util.Optional; import java.util.StringJoiner; public class StandardPluginContainer implements PluginContainer { @@ -51,6 +49,11 @@ public StandardPluginContainer(final PluginResource resource, final PluginMetada this.logger = Objects.requireNonNull(logger, "logger"); } + @Override + public final PluginResource resource() { + return this.resource; + } + @Override public final PluginMetadata metadata() { return this.metadata; @@ -61,11 +64,6 @@ public final Logger logger() { return this.logger; } - @Override - public Optional locateResource(final String path) { - return this.resource.locateResource(path); - } - @Override public int hashCode() { return Objects.hashCode(this.metadata.id()); From 0a3ead96824b577e82a0f0f46b78d19c57a707e2 Mon Sep 17 00:00:00 2001 From: Yeregorix Date: Thu, 3 Sep 2026 22:04:32 +0200 Subject: [PATCH 2/2] Deprecate ResourceQueryable --- .../spongepowered/plugin/PluginContainer.java | 13 +++++ .../plugin/ResourceQueryable.java | 5 ++ .../plugin/discovery/PluginResource.java | 50 +++++++++++++++++-- 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/spongepowered/plugin/PluginContainer.java b/src/main/java/org/spongepowered/plugin/PluginContainer.java index ebbfa88..7d7c49e 100644 --- a/src/main/java/org/spongepowered/plugin/PluginContainer.java +++ b/src/main/java/org/spongepowered/plugin/PluginContainer.java @@ -28,12 +28,17 @@ import org.spongepowered.plugin.discovery.PluginResource; import org.spongepowered.plugin.metadata.PluginMetadata; +import java.io.InputStream; +import java.net.URI; +import java.util.Optional; + /** * Represents the combination of a {@link PluginMetadata metadata} with its instance. *

* For most vendors, this becomes the representation of the concept of a plugin within * their ecosystem. */ +@SuppressWarnings("removal") public interface PluginContainer extends ResourceQueryable { /** @@ -59,11 +64,19 @@ default Object instance() { return this; } + /** + * @deprecated Use {@link #resource()} and {@link PluginResource#locate(String)} + */ + @Deprecated(forRemoval = true, since = "0.5.2") @Override default Optional locateResource(final String path) { return this.resource().locate(path); } + /** + * @deprecated Use {@link #resource()} and {@link PluginResource#open(String)} + */ + @Deprecated(forRemoval = true, since = "0.5.2") @Override default Optional openResource(final String path) { return this.resource().open(path); diff --git a/src/main/java/org/spongepowered/plugin/ResourceQueryable.java b/src/main/java/org/spongepowered/plugin/ResourceQueryable.java index e391fa5..8319890 100644 --- a/src/main/java/org/spongepowered/plugin/ResourceQueryable.java +++ b/src/main/java/org/spongepowered/plugin/ResourceQueryable.java @@ -31,7 +31,10 @@ /** * Represents an entity that can be queried for {@link URI resources}. + * + * @deprecated Use {@link org.spongepowered.plugin.discovery.PluginResource} */ +@Deprecated(forRemoval = true, since = "0.5.2") public interface ResourceQueryable { /** @@ -40,6 +43,7 @@ public interface ResourceQueryable { * @param path The relative path * @return The resolved resource location, if available */ + @Deprecated(forRemoval = true, since = "0.5.2") Optional locateResource(final String path); /** @@ -48,6 +52,7 @@ public interface ResourceQueryable { * @param path The relative path * @return The opened resource, if available */ + @Deprecated(forRemoval = true, since = "0.5.2") default Optional openResource(final String path) { return this.locateResource(path).flatMap(url -> { try { diff --git a/src/main/java/org/spongepowered/plugin/discovery/PluginResource.java b/src/main/java/org/spongepowered/plugin/discovery/PluginResource.java index 26b9424..b006804 100644 --- a/src/main/java/org/spongepowered/plugin/discovery/PluginResource.java +++ b/src/main/java/org/spongepowered/plugin/discovery/PluginResource.java @@ -24,8 +24,9 @@ */ package org.spongepowered.plugin.discovery; -import org.spongepowered.plugin.ResourceQueryable; - +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; import java.nio.file.Path; import java.util.List; import java.util.Optional; @@ -33,7 +34,8 @@ /** * Represents a resource provided by a {@link PluginResourceLocator locator}. */ -public interface PluginResource extends ResourceQueryable { +@SuppressWarnings({"removal", "DeprecatedIsStillUsed"}) +public interface PluginResource extends org.spongepowered.plugin.ResourceQueryable { /** * @deprecated Use {@link #paths()} instead @@ -58,4 +60,46 @@ default Path path() { * @return The value or {@link Optional#empty()} if not found */ Optional property(final String key); + + /** + * Resolves the location of a bundled resource, given a relative path. + * + * @param path The relative path + * @return The resolved location, if available + */ + Optional locate(final String path); + + /** + * Opens an {@link InputStream} of the location of a bundled resource, given a relative path. + * + * @param path The relative path + * @return The opened bundled resource, if available + */ + default Optional open(final String path) { + return this.locate(path).flatMap(url -> { + try { + return Optional.of(url.toURL().openStream()); + } catch (final IOException ignored) { + return Optional.empty(); + } + }); + } + + /** + * @deprecated Use {@link #locate(String)} + */ + @Deprecated(forRemoval = true, since = "0.5.2") + @Override + default Optional locateResource(final String path) { + return this.locate(path); + } + + /** + * @deprecated Use {@link #open(String)} + */ + @Deprecated(forRemoval = true, since = "0.5.2") + @Override + default Optional openResource(final String path) { + return this.open(path); + } }