Search in sources :

Example 1 with SuppressFBWarnings

use of org.graalvm.component.installer.SuppressFBWarnings in project graal by oracle.

the class Verifier method validateRequirements.

@SuppressWarnings("StringEquality")
@SuppressFBWarnings(value = "ES_COMPARING_STRINGS_WITH_EQ", justification = "intentional comparison of strings using ==")
public Verifier validateRequirements(ComponentInfo componentInfo) {
    errors.clear();
    // check the component is not in the registry
    ComponentInfo existing = localRegistry.findComponent(componentInfo.getId());
    if (existing != null) {
        if (existing.getVersion().compareTo(componentInfo.getVersion()) >= 0) {
            if (!ignoreExisting && !replaceComponents) {
                addOrThrow(new DependencyException.Conflict(existing.getId(), componentInfo.getVersionString(), existing.getVersionString(), feedback.l10n("VERIFY_ComponentExists", existing.getName(), existing, existing.getVersionString())));
            }
        }
    }
    if (ignoreRequirements) {
        return this;
    }
    Map<String, String> requiredCaps = componentInfo.getRequiredGraalValues();
    Map<String, String> graalCaps = localRegistry.getGraalCapabilities();
    boolean verbose = feedback.verboseOutput(null);
    if (!isSilent() && verbose) {
        feedback.verboseOutput("VERIFY_VerboseCheckRequirements", catalog.shortenComponentId(componentInfo), componentInfo.getName(), componentInfo.getVersionString());
        List<String> keys = new ArrayList<>(requiredCaps.keySet());
        Collections.sort(keys);
        String none = feedback.l10n("VERIFY_VerboseCapabilityNone");
        for (String s : keys) {
            String v = graalCaps.get(s);
            feedback.verboseOutput("VERIFY_VerboseCapability", localRegistry.localizeCapabilityName(s), requiredCaps.get(s), v == null ? none : v);
        }
    }
    for (String s : requiredCaps.keySet()) {
        String reqVal = requiredCaps.get(s);
        String graalVal = graalCaps.get(s);
        boolean matches;
        if (BundleConstants.GRAAL_VERSION.equals(s)) {
            if (versionMatch != null) {
                Version cv = Version.fromString(reqVal.toLowerCase());
                matches = versionMatch.test(cv);
            } else {
                Version rv = Version.fromString(reqVal);
                Version gv = Version.fromString(graalVal);
                matches = rv.installVersion().equals(gv.installVersion());
            }
            if (!matches) {
                Version rq = Version.fromString(reqVal);
                Version gv = localRegistry.getGraalVersion();
                int n = gv.compareTo(rq);
                if (n > 0) {
                    if (!gv.installVersion().equals(rq.installVersion())) {
                        addOrThrow(new DependencyException.Mismatch(GRAALVM_CAPABILITY, s, reqVal, graalVal, feedback.l10n("VERIFY_ObsoleteGraalVM", componentInfo.getName(), reqVal, gv.displayString())));
                    }
                } else if (collectVersion) {
                    minVersion = rq;
                } else {
                    addOrThrow(new DependencyException.Mismatch(GRAALVM_CAPABILITY, s, reqVal, graalVal, feedback.l10n("VERIFY_UpdateGraalVM", componentInfo.getName(), reqVal, gv.displayString())));
                }
            }
            continue;
        } else {
            matches = matches(reqVal, graalVal);
        }
        if (!matches) {
            String val = graalVal != null ? graalVal : feedback.l10n("VERIFY_CapabilityMissing");
            addOrThrow(new DependencyException.Mismatch(componentInfo.getId(), s, reqVal, graalVal, feedback.l10n("VERIFY_Dependency_Failed", componentInfo.getName(), localRegistry.localizeCapabilityName(s), reqVal, val)));
        }
    }
    return this;
}
Also used : Version(org.graalvm.component.installer.Version) ArrayList(java.util.ArrayList) DependencyException(org.graalvm.component.installer.DependencyException) SuppressFBWarnings(org.graalvm.component.installer.SuppressFBWarnings)

Aggregations

ArrayList (java.util.ArrayList)1 DependencyException (org.graalvm.component.installer.DependencyException)1 SuppressFBWarnings (org.graalvm.component.installer.SuppressFBWarnings)1 Version (org.graalvm.component.installer.Version)1