Search in sources :

Example 1 with Dependency

use of org.spongepowered.api.plugin.Dependency 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));
    }
}
Also used : InvalidVersionSpecificationException(org.spongepowered.plugin.meta.version.InvalidVersionSpecificationException) PluginDependency(org.spongepowered.plugin.meta.PluginDependency) PluginDependency(org.spongepowered.plugin.meta.PluginDependency) Dependency(org.spongepowered.api.plugin.Dependency) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 Dependency (org.spongepowered.api.plugin.Dependency)1 PluginDependency (org.spongepowered.plugin.meta.PluginDependency)1 InvalidVersionSpecificationException (org.spongepowered.plugin.meta.version.InvalidVersionSpecificationException)1