Search in sources :

Example 1 with FileDownloader

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

the class GraalChannel method loadStorage.

@Override
protected ComponentStorage loadStorage() throws IOException {
    FileDownloader dn = new FileDownloader(fb.l10n("OLDS_ReleaseFile"), getIndexURL(), fb);
    dn.download();
    Path storagePath = dn.getLocalFile().toPath();
    List<ReleaseEntry> releases = loadReleasesIndex(storagePath);
    if (releases.isEmpty()) {
        return throwEmptyStorage();
    }
    MergeStorage store = new MergeStorage(localRegistry, fb);
    store.setAcceptAllSources(true);
    for (ReleaseEntry en : releases) {
        URL catURL = en.getCatalogURL();
        Version v = Version.fromString(en.getVersion().displayString());
        SoftwareChannelSource src = new SoftwareChannelSource(catURL.toString(), en.getLabel());
        WebCatalog cata = new WebCatalog(src.getLocationURL(), src) {

            @Override
            protected RemotePropertiesStorage createPropertiesStorage(Feedback aFeedback, ComponentRegistry aLocal, Properties props, String selector, URL baseURL) {
                return new RemotePropertiesStorage(aFeedback, aLocal, props, selector, v, baseURL);
            }
        };
        cata.init(localRegistry, fb);
        cata.setMatchVersion(en.getVersion().match(Version.Match.Type.EXACT));
        cata.setRemoteProcessor((i) -> configureLicense(i, en));
        store.addChannel(src, cata);
    }
    return store;
}
Also used : Path(java.nio.file.Path) SoftwareChannelSource(org.graalvm.component.installer.SoftwareChannelSource) WebCatalog(org.graalvm.component.installer.ce.WebCatalog) RemotePropertiesStorage(org.graalvm.component.installer.remote.RemotePropertiesStorage) MergeStorage(org.graalvm.component.installer.remote.MergeStorage) Properties(java.util.Properties) URL(java.net.URL) Version(org.graalvm.component.installer.Version) Feedback(org.graalvm.component.installer.Feedback) ComponentRegistry(org.graalvm.component.installer.model.ComponentRegistry) FileDownloader(org.graalvm.component.installer.remote.FileDownloader)

Example 2 with FileDownloader

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

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

the class LicensePresenter method downloadLicenseText.

File downloadLicenseText(String label, String url) throws IOException {
    FileDownloader dn = new FileDownloader(label, new URL(url), feedback);
    dn.download();
    return dn.getLocalFile();
}
Also used : FileDownloader(org.graalvm.component.installer.remote.FileDownloader) URL(java.net.URL)

Example 4 with FileDownloader

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

the class ComponentPackageLoader method downloadAndHashLicense.

public String downloadAndHashLicense(String remote) {
    String desc = getLicenseType();
    if (desc == null) {
        desc = remote;
    }
    try {
        URL u = new URL(remote);
        FileDownloader dn = createFileDownloader(u, feedback.l10n("LICENSE_RemoteLicenseDescription", desc));
        dn.download();
        String s = String.join("\n", Files.readAllLines(dn.getLocalFile().toPath()));
        return SystemUtils.digestString(s, false);
    } catch (IOException ex) {
        throw feedback.failure("ERROR_DownloadLicense", ex, desc, ex.getLocalizedMessage());
    }
}
Also used : FileDownloader(org.graalvm.component.installer.remote.FileDownloader) IOException(java.io.IOException) URL(java.net.URL)

Example 5 with FileDownloader

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

the class GDSRESTConnector method obtain.

private Path obtain(String endpoint) {
    addParam(QUERRY_LIMIT_KEY, QUERRY_LIMIT_VAL);
    try {
        FileDownloader dn = new FileDownloader(feedback.l10n("OLDS_ReleaseFile"), new URL(SystemUtils.buildUrlStringWithParameters(baseURL + endpoint, params)), feedback);
        fillBasics(dn);
        dn.download();
        return dn.getLocalFile().toPath();
    } catch (IOException ex) {
        throw feedback.failure("ERR_CouldNotLoadGDS", ex, baseURL, ex.getLocalizedMessage());
    } finally {
        params.clear();
    }
}
Also used : FileDownloader(org.graalvm.component.installer.remote.FileDownloader) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

FileDownloader (org.graalvm.component.installer.remote.FileDownloader)6 URL (java.net.URL)5 IOException (java.io.IOException)3 Properties (java.util.Properties)2 Version (org.graalvm.component.installer.Version)2 RemotePropertiesStorage (org.graalvm.component.installer.remote.RemotePropertiesStorage)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 ConnectException (java.net.ConnectException)1 MalformedURLException (java.net.MalformedURLException)1 NoRouteToHostException (java.net.NoRouteToHostException)1 Path (java.nio.file.Path)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Feedback (org.graalvm.component.installer.Feedback)1 IncompatibleException (org.graalvm.component.installer.IncompatibleException)1 SoftwareChannelSource (org.graalvm.component.installer.SoftwareChannelSource)1 WebCatalog (org.graalvm.component.installer.ce.WebCatalog)1 ComponentRegistry (org.graalvm.component.installer.model.ComponentRegistry)1 MergeStorage (org.graalvm.component.installer.remote.MergeStorage)1