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
29 changes: 29 additions & 0 deletions src/main/java/org/spongepowered/plugin/PluginContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
* 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}
*/
Expand All @@ -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<URI> 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<InputStream> openResource(final String path) {
return this.resource().open(path);
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/spongepowered/plugin/ResourceQueryable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand All @@ -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<URI> locateResource(final String path);

/**
Expand All @@ -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<InputStream> openResource(final String path) {
return this.locateResource(path).flatMap(url -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -61,11 +64,6 @@ public final Logger logger() {
return this.logger;
}

@Override
public Optional<URI> locateResource(final String path) {
return this.resource.locateResource(path);
}

@Override
public int hashCode() {
return Objects.hashCode(this.metadata.id());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@
*/
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;

/**
* 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
Expand All @@ -58,4 +60,46 @@ default Path path() {
* @return The value or {@link Optional#empty()} if not found
*/
Optional<String> 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<URI> 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<InputStream> 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<URI> locateResource(final String path) {
return this.locate(path);
}

/**
* @deprecated Use {@link #open(String)}
*/
@Deprecated(forRemoval = true, since = "0.5.2")
@Override
default Optional<InputStream> openResource(final String path) {
return this.open(path);
}
}
Loading