use of org.spongepowered.plugin.meta.PluginDependency in project SpongeVanilla by SpongePowered.
the class PluginCandidate method collectDependencies.
public boolean collectDependencies(Map<String, String> loadedPlugins, Map<String, PluginCandidate> candidates) {
checkState(this.dependencies == null, "Dependencies already collected");
if (loadedPlugins.containsKey(this.id)) {
this.invalid = true;
}
this.dependencies = new HashSet<>();
this.requirements = new HashSet<>();
this.versions = new HashMap<>();
this.missingRequirements = new HashMap<>();
for (PluginDependency dependency : this.metadata.collectRequiredDependencies()) {
final String id = dependency.getId();
if (this.id.equals(id)) {
VanillaLaunch.getLogger().warn("Plugin '{}' from {} requires itself to be loaded. " + "This is redundant and can be removed from the dependencies.", this.id, this.source);
continue;
}
final String version = dependency.getVersion();
if (loadedPlugins.containsKey(id)) {
if (!verifyVersionRange(id, version, loadedPlugins.get(id))) {
this.missingRequirements.put(id, version);
}
continue;
}
PluginCandidate candidate = candidates.get(id);
if (candidate != null && verifyVersionRange(id, version, candidate.getMetadata().getVersion())) {
this.requirements.add(candidate);
continue;
}
this.missingRequirements.put(id, version);
}
Map<PluginDependency.LoadOrder, Set<PluginDependency>> dependencies = this.metadata.groupDependenciesByLoadOrder();
collectOptionalDependencies(dependencies.get(PluginDependency.LoadOrder.BEFORE), loadedPlugins, candidates);
// TODO: Dependencies to load after this plugin
// collectOptionalDependencies(dependencies.get(PluginDependency.LoadOrder.AFTER), loadedPlugins, candidates);
Set<PluginDependency> loadAfter = dependencies.get(PluginDependency.LoadOrder.AFTER);
if (loadAfter != null && !loadAfter.isEmpty()) {
this.invalid = true;
VanillaLaunch.getLogger().error("Invalid dependency with load order AFTER on plugin '{}' from {}. " + "This is currently not supported for Sponge plugins! Requested dependencies: {}", this.id, this.source, loadAfter);
}
return isLoadable();
}
use of org.spongepowered.plugin.meta.PluginDependency in project SpongeForge by SpongePowered.
the class DependencyHandler method findDependency.
@Nullable
public static PluginDependency findDependency(ModContainer container, String id) {
PluginDependency current = findDependency(id, null, PluginDependency.LoadOrder.NONE, container.getRequirements(), false);
current = findDependency(id, current, PluginDependency.LoadOrder.AFTER, container.getDependants(), true);
return findDependency(id, current, PluginDependency.LoadOrder.BEFORE, container.getDependencies(), true);
}
use of org.spongepowered.plugin.meta.PluginDependency in project SpongeVanilla by SpongePowered.
the class PluginCandidate method collectOptionalDependencies.
private void collectOptionalDependencies(@Nullable Iterable<PluginDependency> dependencies, Map<String, String> loadedPlugins, Map<String, PluginCandidate> candidates) {
if (dependencies == null) {
return;
}
for (PluginDependency dependency : dependencies) {
final String id = dependency.getId();
if (this.id.equals(id)) {
VanillaLaunch.getLogger().error("Plugin '{}' from {} cannot have a dependency on itself. This is redundant and should be " + "removed.", this.id, this.source);
this.invalid = true;
continue;
}
final String version = dependency.getVersion();
if (loadedPlugins.containsKey(id)) {
if (!verifyVersionRange(id, version, loadedPlugins.get(id))) {
this.missingRequirements.put(id, version);
}
continue;
}
PluginCandidate candidate = candidates.get(id);
if (candidate != null) {
if (verifyVersionRange(id, version, candidate.getMetadata().getVersion())) {
this.dependencies.add(candidate);
} else {
this.missingRequirements.put(id, version);
}
}
}
}
use of org.spongepowered.plugin.meta.PluginDependency in project SpongeAPI by SpongePowered.
the class PluginElement method apply.
void apply(Messager messager) {
String value = this.annotation.get().id();
if (!ID_PATTERN.matcher(value).matches()) {
messager.printMessage(ERROR, "Plugin ID '" + value + "' must match pattern '" + ID_PATTERN.pattern() + "'. " + "It should be lower case, start with an alphabetic character and may only contain alphanumeric characters, underscores or " + "dashes.", this.element, this.annotation.getMirror(), this.annotation.getValue("id"));
}
value = this.annotation.get().name();
if (value.isEmpty()) {
if (this.metadata.getName() == null) {
messager.printMessage(WARNING, "Missing plugin name", this.element, this.annotation.getMirror());
}
} else {
this.metadata.setName(value);
}
value = this.annotation.get().version();
if (value.isEmpty()) {
if (this.metadata.getVersion() == null) {
messager.printMessage(WARNING, "Missing plugin version", this.element, this.annotation.getMirror());
}
} else {
this.metadata.setVersion(value);
}
value = this.annotation.get().description();
if (value.isEmpty()) {
if (this.metadata.getDescription() == null) {
messager.printMessage(WARNING, "Missing plugin description", this.element, this.annotation.getMirror());
}
} else {
this.metadata.setDescription(value);
}
value = this.annotation.get().url();
if (!value.isEmpty()) {
if (!isLikelyValidUrl(value)) {
messager.printMessage(ERROR, "Invalid URL: " + value, this.element, this.annotation.getMirror(), this.annotation.getValue("url"));
}
this.metadata.setUrl(value);
} else if ((value = this.metadata.getUrl()) != null) {
if (!isLikelyValidUrl(value)) {
messager.printMessage(ERROR, "Invalid URL: " + value + " in extra metadata files", this.element, this.annotation.getMirror());
}
}
String[] authors = this.annotation.get().authors();
if (authors.length > 0) {
this.metadata.getAuthors().clear();
for (String author : authors) {
if (author.isEmpty()) {
messager.printMessage(ERROR, "Empty author is not allowed", this.element, this.annotation.getMirror(), this.annotation.getValue("authors"));
continue;
}
this.metadata.addAuthor(author);
}
}
checkDependencies(this.metadata.getDependencies(), messager);
Set<String> addedDependencies = new HashSet<>();
Dependency[] dependencies = this.annotation.get().dependencies();
if (dependencies.length > 0) {
for (Dependency dependency : dependencies) {
final String id = dependency.id();
if (id.isEmpty()) {
messager.printMessage(ERROR, "Dependency ID should not be empty", this.element, this.annotation.getMirror(), this.annotation.getValue("dependencies"));
continue;
}
if (id.equals("*")) {
messager.printMessage(ERROR, "Wildcard dependencies are not supported on Sponge", this.element, this.annotation.getMirror(), this.annotation.getValue("dependencies"));
continue;
}
final String version = dependency.version();
if (!version.isEmpty()) {
try {
VersionRange.createFromVersionSpec(version);
} catch (InvalidVersionSpecificationException e) {
messager.printMessage(ERROR, "Invalid dependency version range: " + version + " (" + e.getMessage() + ") Please check the Javadocs of @Dependency.version() for details.", this.element, this.annotation.getMirror(), this.annotation.getValue("dependencies"));
}
}
if (addedDependencies.add(id)) {
// TODO: Load order
this.metadata.replaceDependency(new PluginDependency(PluginDependency.LoadOrder.BEFORE, id, dependency.version(), dependency.optional()));
} else {
messager.printMessage(ERROR, "Duplicate dependency with plugin ID: " + id, this.element, this.annotation.getMirror(), this.annotation.getValue("dependencies"));
}
}
}
if (this.metadata.getDependency(Platform.API_ID) == null) {
// Add SpongeAPI as required dependency to the metadata
this.metadata.addDependency(new PluginDependency(PluginDependency.LoadOrder.BEFORE, Platform.API_ID, API_VERSION, false));
}
}
use of org.spongepowered.plugin.meta.PluginDependency in project LanternServer by LanternPowered.
the class PluginCandidate method collectDependencies.
public boolean collectDependencies(Map<String, PluginContainer> loadedPlugins, Map<String, PluginCandidate> candidates) {
checkState(this.dependencies == null, "Dependencies already collected");
if (loadedPlugins.containsKey(this.id)) {
this.invalid = true;
}
this.dependencies = new HashSet<>();
this.requirements = new HashSet<>();
this.versions = new HashMap<>();
this.missingRequirements = new HashMap<>();
for (PluginDependency dependency : this.metadata.collectRequiredDependencies()) {
final String id = dependency.getId();
if (this.id.equals(id)) {
Lantern.getLogger().warn("Plugin '{}' from {} requires itself to be loaded. " + "This is redundant and can be removed from the dependencies.", this.id, getDisplaySource());
continue;
}
final String version = dependency.getVersion();
final PluginContainer loaded = loadedPlugins.get(id);
if (loaded != null) {
if (!verifyVersionRange(id, version, loaded.getVersion().orElse(null))) {
this.missingRequirements.put(id, version);
}
continue;
}
final PluginCandidate candidate = candidates.get(id);
if (candidate != null && verifyVersionRange(id, version, candidate.getMetadata().getVersion())) {
this.requirements.add(candidate);
continue;
}
this.missingRequirements.put(id, version);
}
final Map<PluginDependency.LoadOrder, Set<PluginDependency>> dependencies = this.metadata.groupDependenciesByLoadOrder();
collectOptionalDependencies(dependencies.get(PluginDependency.LoadOrder.BEFORE), loadedPlugins, candidates);
final Set<PluginDependency> loadAfter = dependencies.get(PluginDependency.LoadOrder.AFTER);
if (loadAfter != null && !loadAfter.isEmpty()) {
this.invalid = true;
Lantern.getLogger().error("Invalid dependency with load order BEFORE on plugin '{}' from {}. " + "This is currently not supported for Sponge plugins! Requested dependencies: {}", this.id, getDisplaySource(), loadAfter);
}
return isLoadable();
}
Aggregations