Search in sources :

Example 26 with Version

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

the class UpgradeProcess method satisfiedAddedComponents.

/**
 * Checks if the candidate GraalVM satisfies all dependencies of added components. Added
 * components are those specified on the commandline;
 *
 * @param candidate candidate GraalVM component
 * @return broken components
 */
Collection<ComponentInfo> satisfiedAddedComponents(ComponentInfo candidate) throws IOException {
    List<ComponentInfo> broken = new ArrayList<>();
    Version gv = candidate.getVersion();
    Version.Match satisfies = gv.match(Version.Match.Type.COMPATIBLE);
    for (ComponentParam param : addComponents) {
        ComponentInfo in = param.createMetaLoader().getComponentInfo();
        String vs = in.getRequiredGraalValues().get(BundleConstants.GRAAL_VERSION);
        Version cv = Version.fromString(vs);
        if (!satisfies.test(cv)) {
            broken.add(in);
            if (minVersion.compareTo(cv) < 0) {
                minVersion = cv;
            }
        }
    }
    return broken;
}
Also used : Version(org.graalvm.component.installer.Version) ArrayList(java.util.ArrayList) ComponentParam(org.graalvm.component.installer.ComponentParam) ComponentInfo(org.graalvm.component.installer.model.ComponentInfo)

Example 27 with Version

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

the class UpgradeProcess method failIfDirectotyExistsNotEmpty.

void failIfDirectotyExistsNotEmpty(Path target) throws IOException {
    if (!Files.exists(target)) {
        return;
    }
    if (!Files.isDirectory(target)) {
        throw feedback.failure("UPGRADE_TargetExistsNotDirectory", null, target);
    }
    Path ghome = target.resolve(SystemUtils.getGraalVMJDKRoot(input.getLocalRegistry()));
    Path relFile = ghome.resolve("release");
    if (Files.isReadable(relFile)) {
        Version targetVersion = null;
        try {
            ComponentRegistry reg = createRegistryFor(ghome);
            targetVersion = reg.getGraalVersion();
        } catch (FailedOperationException ex) {
        // ignore
        }
        if (targetVersion != null) {
            throw feedback.failure("UPGRADE_TargetExistsContainsGraalVM", null, target, targetVersion.displayString());
        }
    }
    if (Files.list(target).findFirst().isPresent()) {
        throw feedback.failure("UPGRADE_TargetExistsNotEmpty", null, target);
    }
}
Also used : Path(java.nio.file.Path) FailedOperationException(org.graalvm.component.installer.FailedOperationException) Version(org.graalvm.component.installer.Version) ComponentRegistry(org.graalvm.component.installer.model.ComponentRegistry)

Example 28 with Version

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

the class GraalChannel method jsonToRelease.

/**
 * Reads JSON object into {@link ReleaseEntry}.
 *
 * @param rk release id in the index; diagnostics.
 * @param jo the JSON object to convert
 * @return Release entry or {@code null} if the entry is for a different release / os / arch
 * @throws IOException in case of I/O error or a malformed JSON.
 */
ReleaseEntry jsonToRelease(String rk, JSONObject jo) throws IOException {
    String licenseString;
    String catalogString;
    JSONObject bases;
    String name;
    String versionString;
    name = jo.getString(KEY_RELEASE_NAME);
    licenseString = jo.has(KEY_RELEASE_LICENSE) ? jo.getString(KEY_RELEASE_LICENSE) : null;
    catalogString = jo.getString(KEY_RELEASE_CATALOG);
    bases = jo.getJSONObject(KEY_RELEASE_BASES);
    if (catalogString == null || catalogString.isEmpty()) {
        return null;
    }
    versionString = jo.getString(KEY_RELEASE_VRESION);
    String javaString = jo.getString(KEY_RELEASE_JAVA);
    String editionString = jo.getString(KEY_RELEASE_EDITION);
    String licenseLabel = jo.has(KEY_RELEASE_LICENSE_LABEL) ? jo.getString(KEY_RELEASE_LICENSE_LABEL) : null;
    Version v = Version.fromString(versionString);
    String jv;
    if (javaString.startsWith("jdk")) {
        // NOI18N
        // NOI18N
        jv = "" + SystemUtils.interpretJavaMajorVersion(javaString.substring(3));
    } else if (javaString.startsWith("java")) {
        // NOI18N
        // NOI18N
        jv = "" + SystemUtils.interpretJavaMajorVersion(javaString.substring(4));
    } else {
        return null;
    }
    String u = null;
    try {
        u = licenseString;
        URL licenseURL = licenseString == null || licenseString.isEmpty() ? null : resolveURL(licenseString);
        u = catalogString;
        URL catalogURL = resolveURL(catalogString);
        ReleaseEntry e = new ReleaseEntry(rk, name, v, licenseURL, catalogURL);
        e.setEdition(editionString);
        e.setJavaVersion(jv);
        e.setLicenseLabel(licenseLabel);
        LOG.log(Level.FINEST, "Reading: {0}", rk);
        if (bases == null) {
            LOG.log(Level.FINER, "Release {0} has no bases.", rk);
            return null;
        }
        for (String k : bases.keySet()) {
            ReleaseEntry.BasePackage bp = jsonToBase(k, bases.getJSONObject(k));
            if (bp == null) {
                LOG.log(Level.FINER, "Invalid base: {0}", k);
                continue;
            }
            if (verifyOsArch(rk + "-" + k, bp)) {
                e.addBasePackage(bp);
            }
        }
        return e;
    } catch (MalformedURLException ex) {
        invalidURLs.add(u);
        return null;
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) Version(org.graalvm.component.installer.Version) URL(java.net.URL)

Example 29 with Version

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

the class CatalogContents method compatibleVersion.

public boolean compatibleVersion(ComponentInfo info) {
    // excludes components that depend on obsolete versions
    // excludes components that depend on
    Version v = info.getVersion();
    Version gv = graalVersion;
    if (allowDistUpdate) {
        return gv.updatable().compareTo(v.updatable()) <= 0;
    } else {
        Version giv = gv.installVersion();
        Version civ = v.installVersion();
        return giv.equals(civ);
    }
}
Also used : Version(org.graalvm.component.installer.Version)

Example 30 with Version

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

the class RemotePropertiesStorage method splitPropertiesToComponents.

private void splitPropertiesToComponents() {
    if (filteredComponents != null) {
        return;
    }
    filteredComponents = new HashMap<>();
    // known prefixes. Version will not be parsed again for therse.
    Set<String> knownPrefixes = new HashSet<>();
    // already accepted prefixes
    Set<String> acceptedPrefixes = new HashSet<>();
    Pattern flavourPattern = Pattern.compile("^" + flavourRegex, Pattern.CASE_INSENSITIVE);
    Pattern singlePattern = Pattern.compile("^" + singleRegex, Pattern.CASE_INSENSITIVE);
    for (String s : catalogProperties.stringPropertyNames()) {
        String cid;
        String pn;
        int slashPos = s.indexOf('/');
        int secondSlashPos = s.indexOf('/', slashPos + 1);
        int l;
        if (slashPos != -1 && secondSlashPos != -1) {
            if (!flavourPattern.matcher(s).find()) {
                continue;
            }
            pn = s.substring(slashPos + 1);
            String pref = s.substring(0, secondSlashPos);
            int lastSlashPos = s.indexOf('/', secondSlashPos + 1);
            if (lastSlashPos == -1) {
                lastSlashPos = secondSlashPos;
            }
            l = lastSlashPos + 1;
            if (knownPrefixes.add(pref)) {
                try {
                    Version vn = Version.fromString(s.substring(slashPos + 1, secondSlashPos));
                    if (acceptsVersion(vn)) {
                        acceptedPrefixes.add(pref);
                    }
                } catch (IllegalArgumentException ex) {
                    feedback.verboseOutput("REMOTE_BadComponentVersion", pn);
                }
            }
            if (!acceptedPrefixes.contains(pref)) {
                // ignore obsolete versions
                continue;
            }
        } else {
            Matcher m = singlePattern.matcher(s);
            if (!m.find()) {
                continue;
            }
            // versionless component
            l = m.end();
            // normalized version
            pn = graalVersion.toString() + "/" + s.substring(l);
        }
        int dashPos = s.indexOf("-", l);
        if (dashPos == -1) {
            dashPos = s.length();
        }
        cid = s.substring(l, dashPos);
        String patchedCid = cid.replace("_", "-");
        String patchedPn = pn.replace(cid, patchedCid);
        filteredComponents.computeIfAbsent(patchedCid, (unused) -> new Properties()).setProperty(patchedPn, catalogProperties.getProperty(s));
    }
}
Also used : ComponentRegistry(org.graalvm.component.installer.model.ComponentRegistry) Version(org.graalvm.component.installer.Version) Properties(java.util.Properties) URL(java.net.URL) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) Feedback(org.graalvm.component.installer.Feedback) ComponentInfo(org.graalvm.component.installer.model.ComponentInfo) AbstractCatalogStorage(org.graalvm.component.installer.persist.AbstractCatalogStorage) Function(java.util.function.Function) MessageFormat(java.text.MessageFormat) HashSet(java.util.HashSet) Matcher(java.util.regex.Matcher) ComponentPackageLoader(org.graalvm.component.installer.persist.ComponentPackageLoader) RemoteInfoProcessor(org.graalvm.component.installer.model.RemoteInfoProcessor) Map(java.util.Map) Pattern(java.util.regex.Pattern) Pattern(java.util.regex.Pattern) Version(org.graalvm.component.installer.Version) Matcher(java.util.regex.Matcher) Properties(java.util.Properties) 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