diff --git a/src/main/java/org/spongepowered/plugin/PluginContainer.java b/src/main/java/org/spongepowered/plugin/PluginContainer.java
index 9a79d17..7d7c49e 100644
--- a/src/main/java/org/spongepowered/plugin/PluginContainer.java
+++ b/src/main/java/org/spongepowered/plugin/PluginContainer.java
@@ -25,16 +25,27 @@
package org.spongepowered.plugin;
import org.apache.logging.log4j.Logger;
+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 {
+ /**
+ * @return The {@link PluginResource plugin resource}
+ */
+ PluginResource resource();
+
/**
* @return The {@link PluginMetadata plugin metadata}
*/
@@ -52,4 +63,22 @@ public interface PluginContainer extends ResourceQueryable {
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/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());
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);
+ }
}