Search in sources :

Example 1 with IncompatibleException

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

the class GraalChannel method loadReleasesIndex.

/**
 * 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<ReleaseEntry> loadReleasesIndex(Path releasesIndexPath) throws IOException {
    if (edition == null) {
        edition = localRegistry.getGraalCapabilities().get(CommonConstants.CAP_EDITION);
    }
    List<ReleaseEntry> result = new ArrayList<>();
    try (Reader urlReader = new InputStreamReader(Files.newInputStream(releasesIndexPath))) {
        JSONTokener tokener = new JSONTokener(urlReader);
        JSONObject obj = new JSONObject(tokener);
        JSONObject releases = obj.getJSONObject(KEY_RELEASES);
        if (releases == null) {
            // malformed releases file;
            throw new IncompatibleException(fb.l10n("OLDS_InvalidReleasesFile"));
        }
        Version v = localRegistry.getGraalVersion();
        for (String k : releases.keySet()) {
            JSONObject jo = releases.getJSONObject(k);
            ReleaseEntry e = null;
            try {
                e = jsonToRelease(k, jo);
            } catch (JSONException | IllegalArgumentException ex) {
                fb.error("OLDS_ErrorReadingRelease", ex, k, ex.getLocalizedMessage());
            }
            if (e == null) {
                invalidReleases.add(k);
            } else if (!localRegistry.getJavaVersion().equals(e.getJavaVersion())) {
                LOG.log(Level.FINER, "Invalid Java: {0}", k);
            } else if (e.getBasePackages().isEmpty()) {
                LOG.log(Level.FINER, "No distribution packages: {0}", k);
            } else if (edition != null && !edition.equals(e.getEdition())) {
                LOG.log(Level.FINER, "Incorrect edition: {0}", k);
            } else if (!acceptsVersion(v, e.getVersion())) {
                LOG.log(Level.FINER, "Old version: {0}", k);
            } else {
                result.add(e);
            }
        }
    }
    return result;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) JSONException(com.oracle.truffle.tools.utils.json.JSONException) JSONTokener(com.oracle.truffle.tools.utils.json.JSONTokener) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) Version(org.graalvm.component.installer.Version) IncompatibleException(org.graalvm.component.installer.IncompatibleException)

Example 2 with IncompatibleException

use of org.graalvm.component.installer.IncompatibleException 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 3 with IncompatibleException

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

the class GraalChannelTest method testThrowEmptyStorage.

@Test
public void testThrowEmptyStorage() throws Exception {
    try {
        channel.throwEmptyStorage();
        fail("Exception expected");
    } catch (IncompatibleException ex) {
    // ok
    }
    ComponentStorage chStorage = channel.throwEmptyStorage();
    assertNotNull("Stub storage expected for 2nd time", chStorage);
    assertEquals(0, chStorage.listComponentIDs().size());
    assertEquals(0, chStorage.loadComponentMetadata("org.graalvm").size());
    assertEquals(0, chStorage.loadGraalVersionInfo().size());
}
Also used : ComponentStorage(org.graalvm.component.installer.model.ComponentStorage) IncompatibleException(org.graalvm.component.installer.IncompatibleException) Test(org.junit.Test)

Example 4 with IncompatibleException

use of org.graalvm.component.installer.IncompatibleException 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 5 with IncompatibleException

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

the class MergeStorage method listComponentIDs.

@Override
public Set<String> listComponentIDs() throws IOException {
    Set<String> ids = new HashSet<>();
    List<Exception> savedEx = new ArrayList<>();
    List<SoftwareChannel> errChannels = new ArrayList<>();
    boolean oneSucceeded = false;
    Exception toThrow = null;
    for (SoftwareChannel del : new ArrayList<>(channels)) {
        try {
            ids.addAll(del.getStorage().listComponentIDs());
            oneSucceeded = true;
        } catch (IncompatibleException ex) {
            savedEx.add(ex);
            errChannels.add(del);
            channels.remove(del);
        } catch (IOException | FailedOperationException ex) {
            if (!isIgnoreCatalogErrors()) {
                throw ex;
            }
            if (!idsLoaded) {
                reportError(ex, del);
            }
            toThrow = ex;
            channels.remove(del);
        }
    }
    if (!oneSucceeded || ids.isEmpty()) {
        for (int i = 0; i < savedEx.size(); i++) {
            reportError(toThrow = savedEx.get(i), errChannels.get(i));
        }
        if (toThrow instanceof IOException) {
            throw (IOException) toThrow;
        } else if (toThrow != null) {
            throw (InstallerStopException) toThrow;
        }
    }
    idsLoaded = true;
    return ids;
}
Also used : SoftwareChannel(org.graalvm.component.installer.SoftwareChannel) ArrayList(java.util.ArrayList) IOException(java.io.IOException) InstallerStopException(org.graalvm.component.installer.InstallerStopException) IOException(java.io.IOException) IncompatibleException(org.graalvm.component.installer.IncompatibleException) FailedOperationException(org.graalvm.component.installer.FailedOperationException) FailedOperationException(org.graalvm.component.installer.FailedOperationException) IncompatibleException(org.graalvm.component.installer.IncompatibleException) HashSet(java.util.HashSet)

Aggregations

IncompatibleException (org.graalvm.component.installer.IncompatibleException)5 ArrayList (java.util.ArrayList)3 Version (org.graalvm.component.installer.Version)3 JSONException (com.oracle.truffle.tools.utils.json.JSONException)2 JSONObject (com.oracle.truffle.tools.utils.json.JSONObject)2 JSONTokener (com.oracle.truffle.tools.utils.json.JSONTokener)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 JSONArray (com.oracle.truffle.tools.utils.json.JSONArray)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 Reader (java.io.Reader)1 ConnectException (java.net.ConnectException)1 MalformedURLException (java.net.MalformedURLException)1 NoRouteToHostException (java.net.NoRouteToHostException)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1