Search in sources :

Example 21 with Version

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

the class CatalogCompatTest method testOldFormatIgnoresPrevVersionsAvailable.

/**
 * Checks that previous versions (RCs) are ignored with the old format.
 *
 * @throws Exception
 */
@Test
public void testOldFormatIgnoresPrevVersionsAvailable() throws Exception {
    storage.graalInfo.put(CommonConstants.CAP_GRAALVM_VERSION, "1.0.0");
    setupCatalogFormat1("catalogFormat1.properties");
    // interprets user input for 'available'
    Version gv = getLocalRegistry().getGraalVersion();
    Version.Match selector = gv.match(Version.Match.Type.INSTALLABLE);
    List<ComponentInfo> infos;
    // check that versions 1.0.0-rcX are ignored for version 1.0.0
    infos = new ArrayList<>(registry.loadComponents("ruby", selector, verbose));
    assertEquals(1, infos.size());
    infos = new ArrayList<>(registry.loadComponents("python", selector, verbose));
    assertEquals(1, infos.size());
    infos = new ArrayList<>(registry.loadComponents("r", selector, verbose));
    assertEquals(1, infos.size());
}
Also used : Version(org.graalvm.component.installer.Version) ComponentInfo(org.graalvm.component.installer.model.ComponentInfo) Test(org.junit.Test)

Example 22 with Version

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

the class CatalogCompatTest method testOldFormatIgnoresPrevVersionsMostRecent.

/**
 * Checks that previous versions (RCs) are ignored with the old format.
 *
 * @throws Exception
 */
@Test
public void testOldFormatIgnoresPrevVersionsMostRecent() throws Exception {
    storage.graalInfo.put(CommonConstants.CAP_GRAALVM_VERSION, "1.0.0");
    setupCatalogFormat1("catalogFormat1.properties");
    // copied from CatalogIterable, this is what interprets user input for install
    Version gv = getLocalRegistry().getGraalVersion();
    Version.Match selector = gv.match(Version.Match.Type.MOSTRECENT);
    List<ComponentInfo> infos;
    // check that versions 1.0.0-rcX are ignored for version 1.0.0
    infos = new ArrayList<>(registry.loadComponents("ruby", selector, verbose));
    assertEquals(1, infos.size());
    infos = new ArrayList<>(registry.loadComponents("python", selector, verbose));
    assertEquals(1, infos.size());
    infos = new ArrayList<>(registry.loadComponents("r", selector, verbose));
    assertEquals(1, infos.size());
}
Also used : Version(org.graalvm.component.installer.Version) ComponentInfo(org.graalvm.component.installer.model.ComponentInfo) Test(org.junit.Test)

Example 23 with Version

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

the class WebCatalog method getStorage.

@Override
public ComponentStorage getStorage() {
    if (this.storage != null) {
        return this.storage;
    }
    Map<String, String> graalCaps = local.getGraalCapabilities();
    StringBuilder sb = new StringBuilder();
    sb.append(SystemUtils.patternOsName(graalCaps.get(CommonConstants.CAP_OS_NAME)).toLowerCase());
    sb.append("_");
    sb.append(SystemUtils.patternOsArch(graalCaps.get(CommonConstants.CAP_OS_ARCH).toLowerCase()));
    try {
        catalogURL = new URL(urlString);
    } catch (MalformedURLException ex) {
        throw feedback.failure("REMOTE_InvalidURL", ex, catalogURL, ex.getLocalizedMessage());
    }
    Properties props = new Properties();
    // create the storage. If the init fails, but process will not terminate, the storage will
    // serve no components on the next call.
    RemotePropertiesStorage newStorage = createPropertiesStorage(feedback, local, props, sb.toString(), catalogURL);
    if (remoteProcessor != null) {
        newStorage.setRemoteProcessor(remoteProcessor);
    }
    Properties loadProps = new Properties();
    FileDownloader dn;
    try {
        // avoid duplicate (failed) downloads
        if (savedException != null) {
            throw savedException;
        }
        catalogURL = new URL(urlString);
        String l = source.getLabel();
        dn = new FileDownloader(feedback.l10n(l == null || l.isEmpty() ? "REMOTE_CatalogLabel2" : "REMOTE_CatalogLabel", l), catalogURL, feedback);
        dn.download();
    } catch (NoRouteToHostException | ConnectException ex) {
        throw savedException = feedback.failure("REMOTE_ErrorDownloadCatalogProxy", ex, catalogURL, ex.getLocalizedMessage());
    } catch (FileNotFoundException ex) {
        // treat missing resources as non-fatal errors, print warning
        feedback.error("REMOTE_WarningErrorDownloadCatalogNotFoundSkip", ex, catalogURL);
        this.storage = newStorage;
        return storage;
    } catch (IOException ex) {
        throw savedException = feedback.failure("REMOTE_ErrorDownloadCatalog", ex, catalogURL, ex.getLocalizedMessage());
    }
    // download is successful; if the processing fails after download, next call will report an
    // empty catalog.
    this.storage = newStorage;
    StringBuilder oldGraalPref = new StringBuilder("^" + BundleConstants.GRAAL_COMPONENT_ID);
    oldGraalPref.append('.');
    String graalVersionString;
    Version normalizedVersion;
    if (matchVersion != null) {
        graalVersionString = matchVersion.getVersion().displayString();
        normalizedVersion = matchVersion.getVersion().installVersion();
    } else {
        // read from the release file
        graalVersionString = graalCaps.get(CommonConstants.CAP_GRAALVM_VERSION).toLowerCase();
        normalizedVersion = local.getGraalVersion().installVersion();
    }
    StringBuilder graalPref = new StringBuilder(oldGraalPref);
    oldGraalPref.append(Pattern.quote(graalVersionString));
    oldGraalPref.append('_').append(sb);
    graalPref.append(sb).append('/');
    // NOI18N
    graalPref.append("(?<ver>[^/]+)$");
    try (FileInputStream fis = new FileInputStream(dn.getLocalFile())) {
        loadProps.load(fis);
    } catch (IllegalArgumentException | IOException ex) {
        throw feedback.failure("REMOTE_CorruptedCatalogFile", ex, catalogURL);
    }
    Pattern oldPrefixPattern = Pattern.compile(oldGraalPref.toString(), Pattern.CASE_INSENSITIVE);
    Pattern newPrefixPattern = Pattern.compile(graalPref.toString(), Pattern.CASE_INSENSITIVE);
    Stream<String> propNames = loadProps.stringPropertyNames().stream();
    boolean foundPrefix = propNames.anyMatch(p -> {
        if (oldPrefixPattern.matcher(p).matches()) {
            return true;
        }
        Matcher m = newPrefixPattern.matcher(p);
        if (!m.find() || m.start() > 0) {
            return false;
        }
        try {
            // NOI18N
            Version v = Version.fromString(m.group("ver"));
            return normalizedVersion.match(Version.Match.Type.INSTALLABLE).test(v);
        } catch (IllegalArgumentException ex) {
            return false;
        }
    });
    if (!foundPrefix) {
        boolean graalPrefixFound = false;
        boolean componentFound = false;
        for (String s : loadProps.stringPropertyNames()) {
            if (s.startsWith(BundleConstants.GRAAL_COMPONENT_ID)) {
                graalPrefixFound = true;
            }
            if (s.startsWith("Component.")) {
                componentFound = true;
            }
        }
        if (!componentFound) {
            // no graal prefix, no components
            feedback.verboseOutput("REMOTE_CatalogDoesNotContainComponents", catalogURL);
            return newStorage;
        } else if (!graalPrefixFound) {
            // strange thing, no graal declaration, but components are there ?
            throw feedback.failure("REMOTE_CorruptedCatalogFile", null, catalogURL);
        } else {
            throw new IncompatibleException(feedback.l10n("REMOTE_UnsupportedGraalVersion", graalCaps.get(CommonConstants.CAP_GRAALVM_VERSION), graalCaps.get(CommonConstants.CAP_OS_NAME), graalCaps.get(CommonConstants.CAP_OS_ARCH)), null);
        }
    }
    props.putAll(loadProps);
    return newStorage;
}
Also used : Pattern(java.util.regex.Pattern) MalformedURLException(java.net.MalformedURLException) RemotePropertiesStorage(org.graalvm.component.installer.remote.RemotePropertiesStorage) Matcher(java.util.regex.Matcher) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) NoRouteToHostException(java.net.NoRouteToHostException) URL(java.net.URL) FileInputStream(java.io.FileInputStream) Version(org.graalvm.component.installer.Version) FileDownloader(org.graalvm.component.installer.remote.FileDownloader) IncompatibleException(org.graalvm.component.installer.IncompatibleException) ConnectException(java.net.ConnectException)

Example 24 with Version

use of org.graalvm.component.installer.Version 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)

Example 25 with Version

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

the class UpgradeProcess method findInstallables.

Set<ComponentInfo> findInstallables(ComponentInfo graal) {
    Version gv = graal.getVersion();
    Version.Match satisfies = gv.match(Version.Match.Type.COMPATIBLE);
    Set<ComponentInfo> ret = new HashSet<>();
    for (String id : existingComponents) {
        if (explicitIds.contains(id)) {
            continue;
        }
        Collection<ComponentInfo> cis = catalog.loadComponents(id, satisfies, false);
        if (cis == null || cis.isEmpty()) {
            continue;
        }
        List<ComponentInfo> versions = new ArrayList<>(cis);
        ret.add(versions.get(versions.size() - 1));
    }
    return ret;
}
Also used : Version(org.graalvm.component.installer.Version) ArrayList(java.util.ArrayList) ComponentInfo(org.graalvm.component.installer.model.ComponentInfo) HashSet(java.util.HashSet)

Aggregations

Version (org.graalvm.component.installer.Version)44 ComponentInfo (org.graalvm.component.installer.model.ComponentInfo)21 Test (org.junit.Test)19 Path (java.nio.file.Path)10 ArrayList (java.util.ArrayList)7 URL (java.net.URL)5 HashSet (java.util.HashSet)5 Properties (java.util.Properties)5 RemotePropertiesStorage (org.graalvm.component.installer.remote.RemotePropertiesStorage)4 JSONObject (com.oracle.truffle.tools.utils.json.JSONObject)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 ComponentParam (org.graalvm.component.installer.ComponentParam)3 IncompatibleException (org.graalvm.component.installer.IncompatibleException)3 CatalogContents (org.graalvm.component.installer.model.CatalogContents)3 ComponentRegistry (org.graalvm.component.installer.model.ComponentRegistry)3 CatalogIterable (org.graalvm.component.installer.remote.CatalogIterable)3 RemoteCatalogDownloader (org.graalvm.component.installer.remote.RemoteCatalogDownloader)3 JSONException (com.oracle.truffle.tools.utils.json.JSONException)2 JSONTokener (com.oracle.truffle.tools.utils.json.JSONTokener)2