Search in sources :

Example 6 with Version

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

the class GDSChannel method loadArtifacts.

/**
 * Loads the release index. Must be loaded from a local file.
 *
 * @param releasesIndexPath path to the downloaded releases index.
 * @return list of entries in the index
 * @throws IOException in case of I/O error.
 */
List<ComponentInfo> loadArtifacts(Path releasesIndexPath) throws IOException {
    if (edition == null) {
        edition = localRegistry.getGraalCapabilities().get(CommonConstants.CAP_EDITION);
    }
    List<ComponentInfo> result = new ArrayList<>();
    try (InputStreamReader urlReader = new InputStreamReader(new GZIPInputStream(Files.newInputStream(releasesIndexPath)))) {
        JSONTokener tokener = new JSONTokener(urlReader);
        JSONObject obj = new JSONObject(tokener);
        JSONArray releases = obj.getJSONArray(JSON_ITEMS);
        if (releases == null) {
            // malformed releases file;
            throw new IncompatibleException(fb.l10n("OLDS_InvalidReleasesFile"));
        }
        Version v = localRegistry.getGraalVersion();
        for (Object k : releases) {
            JSONObject jo = (JSONObject) k;
            ArtifactParser e;
            try {
                e = new ArtifactParser(jo);
            } catch (JSONException | IllegalArgumentException ex) {
                fb.error("OLDS_ErrorReadingRelease", ex, k, ex.getLocalizedMessage());
                continue;
            }
            if (!OS.get().equals(OS.fromName(e.getOs()))) {
                LOG.log(Level.FINER, "Incorrect OS: {0}", k);
            } else if (!ARCH.get().equals(ARCH.fromName(e.getArch()))) {
                LOG.log(Level.FINER, "Incorrect Arch: {0}", k);
            } else if (!localRegistry.getJavaVersion().equals(e.getJava())) {
                LOG.log(Level.FINER, "Incorrect Java: {0}", k);
            } else if (edition != null && !edition.equals(e.getEdition())) {
                LOG.log(Level.FINER, "Incorrect edition: {0}", k);
            } else if (!acceptsVersion(v, Version.fromString(e.getVersion()))) {
                LOG.log(Level.FINER, "Old version: {0} != {1}", new Object[] { v, Version.fromString(e.getVersion()), e.getVersion() });
            } else {
                result.add(e.asComponentInfo(gdsConnector, fb));
            }
        }
    }
    return result;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) JSONArray(com.oracle.truffle.tools.utils.json.JSONArray) JSONException(com.oracle.truffle.tools.utils.json.JSONException) GZIPInputStream(java.util.zip.GZIPInputStream) JSONTokener(com.oracle.truffle.tools.utils.json.JSONTokener) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) Version(org.graalvm.component.installer.Version) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) ComponentInfo(org.graalvm.component.installer.model.ComponentInfo) IncompatibleException(org.graalvm.component.installer.IncompatibleException)

Example 7 with Version

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

the class DirectoryStorage method getCoreInfo.

private ComponentInfo getCoreInfo() {
    if (graalCore != null) {
        return graalCore;
    }
    ComponentInfo ci = null;
    try {
        Path cmpFile = registryPath.resolve(SystemUtils.fileName(BundleConstants.GRAAL_COMPONENT_ID + COMPONENT_FILE_SUFFIX));
        if (Files.isReadable(cmpFile)) {
            ci = doLoadComponentMetadata(cmpFile, false);
            if (ci != null && !BundleConstants.GRAAL_COMPONENT_ID.equals(ci.getId())) {
                // invalid definition
                ci = null;
            }
        }
    } catch (IOException ex) {
    // ignore
    }
    if (ci == null) {
        Version v = getGraalVMVersion();
        ci = new ComponentInfo(BundleConstants.GRAAL_COMPONENT_ID, feedback.l10n("NAME_GraalCoreComponent"), v.originalString());
        // set defaults: bundled, supported.
        ci.setStability(StabilityLevel.Supported);
    }
    Path cmpFile = registryPath.resolve(SystemUtils.fileName(BundleConstants.GRAAL_COMPONENT_ID + NATIVE_COMPONENT_FILE_SUFFIX));
    if (Files.exists(cmpFile)) {
        ci.setNativeComponent(true);
    }
    ci.setDistributionType(DistributionType.BUNDLED);
    graalCore = ci;
    return graalCore;
}
Also used : Path(java.nio.file.Path) Version(org.graalvm.component.installer.Version) ComponentInfo(org.graalvm.component.installer.model.ComponentInfo) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 8 with Version

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

the class CatalogContents method compatibleComponent.

private ComponentInfo compatibleComponent(List<ComponentInfo> cis, Version.Match versionSelect, boolean fallback) {
    if (cis == null) {
        return null;
    }
    ComponentInfo first = null;
    Version.Match vm = versionMatch(versionSelect, cis);
    boolean explicit = versionSelect != null && versionSelect.getType() != Version.Match.Type.MOSTRECENT;
    for (int i = cis.size() - 1; i >= 0; i--) {
        ComponentInfo ci = cis.get(i);
        if (first == null) {
            first = ci;
        }
        Version v = ci.getVersion();
        if (!vm.test(v)) {
            continue;
        }
        if (verifier.validateRequirements(ci).hasErrors()) {
            continue;
        }
        if (explicit || compatibleVersion(ci)) {
            return ci;
        }
    }
    return fallback ? first : null;
}
Also used : Version(org.graalvm.component.installer.Version)

Example 9 with Version

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

the class InstallVersionsTest method initVersion.

private Version initVersion(String s) throws IOException {
    Version v = Version.fromString(s);
    storage.graalInfo.put(BundleConstants.GRAAL_VERSION, s);
    Path catalogPath = dataFile("../repo/catalog.properties");
    RemoteCatalogDownloader downloader = new RemoteCatalogDownloader(this, this, catalogPath.toUri().toURL());
    registry = new CatalogContents(this, downloader.getStorage(), localRegistry);
    paramIterable = new CatalogIterable(this, this);
    return v;
}
Also used : Path(java.nio.file.Path) Version(org.graalvm.component.installer.Version) CatalogContents(org.graalvm.component.installer.model.CatalogContents) RemoteCatalogDownloader(org.graalvm.component.installer.remote.RemoteCatalogDownloader) CatalogIterable(org.graalvm.component.installer.remote.CatalogIterable)

Example 10 with Version

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

the class ListTest method testListSpecifiedNewerComponentsExplicit.

/**
 * Checks that compatible components will be listed if 1st parameter is the version.
 */
@Test
public void testListSpecifiedNewerComponentsExplicit() throws Exception {
    Version v = Version.fromString("1.0.0");
    storage.graalInfo.put(BundleConstants.GRAAL_VERSION, v.originalString());
    textParams.add("+1.1.0");
    assert110Components(v, Version.fromString("1.1.0"));
}
Also used : Version(org.graalvm.component.installer.Version) Test(org.junit.Test)

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