Search in sources :

Example 1 with PluginCandidate

use of org.spongepowered.server.launch.plugin.PluginCandidate in project SpongeVanilla by SpongePowered.

the class PluginReporter method crash.

static RuntimeException crash(Throwable e, Collection<PluginCandidate> candidates) {
    CrashReport crash = CrashReport.makeCrashReport(e, "Loading Sponge plugins");
    CrashReportCategory category = crash.makeCategory("Plugins being loaded");
    StringBuilder pluginsBuilder = new StringBuilder();
    StringBuilder requirementsBuilder = new StringBuilder();
    StringBuilder dependenciesBuilder = new StringBuilder();
    for (PluginCandidate candidate : candidates) {
        pluginsBuilder.append(NEW_DETAILS_LINE).append(candidate);
        if (candidate.dependenciesCollected()) {
            Set<PluginCandidate> requirements = candidate.getRequirements();
            Map<String, String> missingRequirements = candidate.getMissingRequirements();
            if (!requirements.isEmpty() || !missingRequirements.isEmpty()) {
                requirementsBuilder.append(NEW_DETAILS_LINE).append(candidate.getId()).append(SEPARATOR);
                if (!requirements.isEmpty()) {
                    Map<String, String> versioned = new HashMap<>();
                    for (PluginCandidate requirement : requirements) {
                        versioned.put(requirement.getId(), candidate.getVersion(requirement.getId()));
                    }
                    formatRequirements(requirementsBuilder, versioned);
                    if (!missingRequirements.isEmpty()) {
                        requirementsBuilder.append(", ");
                    }
                }
                if (!missingRequirements.isEmpty()) {
                    requirementsBuilder.append("missing: ");
                    formatRequirements(requirementsBuilder, missingRequirements);
                }
            }
            if (!candidate.getDependencies().isEmpty()) {
                dependenciesBuilder.append(NEW_DETAILS_LINE).append(candidate.getId()).append(SEPARATOR).append(candidate.getDependencies());
            }
        }
    }
    category.addCrashSection("Plugins", pluginsBuilder);
    if (requirementsBuilder.length() > 0) {
        category.addCrashSection("Requirements", requirementsBuilder);
    }
    if (dependenciesBuilder.length() > 0) {
        category.addCrashSection("Dependencies", dependenciesBuilder);
    }
    throw new ReportedException(crash);
}
Also used : HashMap(java.util.HashMap) CrashReport(net.minecraft.crash.CrashReport) PluginCandidate(org.spongepowered.server.launch.plugin.PluginCandidate) CrashReportCategory(net.minecraft.crash.CrashReportCategory) ReportedException(net.minecraft.util.ReportedException)

Example 2 with PluginCandidate

use of org.spongepowered.server.launch.plugin.PluginCandidate in project SpongeVanilla by SpongePowered.

the class VanillaPluginManager method checkRequirements.

private Set<PluginCandidate> checkRequirements(Map<String, PluginCandidate> candidates) {
    // Collect all versions of already loaded plugins
    Map<String, String> loadedPlugins = new HashMap<>();
    for (PluginContainer container : this.plugins.values()) {
        loadedPlugins.put(container.getId(), container.getVersion().orElse(null));
    }
    Set<PluginCandidate> successfulCandidates = new HashSet<>(candidates.size());
    List<PluginCandidate> failedCandidates = new ArrayList<>();
    for (PluginCandidate candidate : candidates.values()) {
        if (candidate.collectDependencies(loadedPlugins, candidates)) {
            successfulCandidates.add(candidate);
        } else {
            failedCandidates.add(candidate);
        }
    }
    if (failedCandidates.isEmpty()) {
        // Nothing to do, all requirements satisfied
        return successfulCandidates;
    }
    PluginCandidate candidate;
    boolean updated;
    while (true) {
        updated = false;
        Iterator<PluginCandidate> itr = successfulCandidates.iterator();
        while (itr.hasNext()) {
            candidate = itr.next();
            if (candidate.updateRequirements()) {
                updated = true;
                itr.remove();
                failedCandidates.add(candidate);
            }
        }
        if (updated) {
            // Update failed candidates as well
            failedCandidates.forEach(PluginCandidate::updateRequirements);
        } else {
            break;
        }
    }
    for (PluginCandidate failed : failedCandidates) {
        if (failed.isInvalid()) {
            SpongeImpl.getLogger().error("Plugin '{}' from {} cannot be loaded because it is invalid", failed.getId(), failed.getSource());
        } else {
            SpongeImpl.getLogger().error("Cannot load plugin '{}' from {} because it is missing the required dependencies {}", failed.getId(), failed.getSource(), PluginReporter.formatRequirements(failed.getMissingRequirements()));
        }
    }
    return successfulCandidates;
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) PluginCandidate(org.spongepowered.server.launch.plugin.PluginCandidate) HashSet(java.util.HashSet)

Aggregations

HashMap (java.util.HashMap)2 PluginCandidate (org.spongepowered.server.launch.plugin.PluginCandidate)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 IdentityHashMap (java.util.IdentityHashMap)1 CrashReport (net.minecraft.crash.CrashReport)1 CrashReportCategory (net.minecraft.crash.CrashReportCategory)1 ReportedException (net.minecraft.util.ReportedException)1 PluginContainer (org.spongepowered.api.plugin.PluginContainer)1