-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Builtin JVMPluginResource must be implemented by the platform
- Loading branch information
Showing
14 changed files
with
225 additions
and
395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
module org.spongepowered.plugin.spi { | ||
requires transitive org.spongepowered.plugin.metadata; | ||
requires transitive org.apache.logging.log4j; | ||
|
||
exports org.spongepowered.plugin; | ||
exports org.spongepowered.plugin.blackboard; | ||
exports org.spongepowered.plugin.builtin; | ||
exports org.spongepowered.plugin.builtin.jvm; | ||
exports org.spongepowered.plugin.builtin.jvm.locator; | ||
|
||
requires transitive org.spongepowered.plugin.metadata; | ||
requires transitive org.apache.logging.log4j; | ||
provides org.spongepowered.plugin.PluginResourceLocatorService with | ||
org.spongepowered.plugin.builtin.jvm.locator.DirectoryPluginResourceLocatorService, | ||
org.spongepowered.plugin.builtin.jvm.locator.EnvironmentPluginResourceLocatorService; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/org/spongepowered/plugin/builtin/jvm/JVMPluginResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* This file is part of plugin-spi, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) SpongePowered <https://www.spongepowered.org> | ||
* Copyright (c) contributors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.spongepowered.plugin.builtin.jvm; | ||
|
||
import org.spongepowered.plugin.Environment; | ||
import org.spongepowered.plugin.PluginResource; | ||
|
||
import java.net.URI; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.jar.Manifest; | ||
|
||
public interface JVMPluginResource extends PluginResource { | ||
|
||
Manifest manifest(); | ||
|
||
/** | ||
* Retrieves the root path containing all the resources. | ||
* This may or may not be the root of the file system containing the resources. | ||
* | ||
* @return The root path containing all the resources. | ||
*/ | ||
Path resourcesRoot(); | ||
|
||
@Override | ||
default Optional<String> property(final String key) { | ||
return Optional.ofNullable(this.manifest().getMainAttributes().getValue(Objects.requireNonNull(key, "key"))); | ||
} | ||
|
||
@Override | ||
default Optional<URI> locateResource(final String path) { | ||
final Path p = this.resourcesRoot().resolve(path); | ||
return Files.exists(p) ? Optional.of(p.toUri()) : Optional.empty(); | ||
} | ||
|
||
/** | ||
* Creates a {@link JVMPluginResource} from an array of paths. | ||
* Each path can point to a JAR file or a directory. | ||
* When multiple paths are given, the resulting resource is a virtual union of all files contained by these paths. | ||
* | ||
* @param environment The environment | ||
* @param locator The locator that created this resource | ||
* @param paths The paths | ||
* @return The {@link JVMPluginResource}. | ||
*/ | ||
static JVMPluginResource create(final Environment environment, final String locator, final Path... paths) { | ||
return environment.blackboard().get(JVMKeys.JVM_PLUGIN_RESOURCE_FACTORY).create(locator, paths); | ||
} | ||
|
||
interface Factory { | ||
JVMPluginResource create(final String locator, final Path[] paths); | ||
} | ||
} |
Oops, something went wrong.