Search in sources :

Example 1 with RemotePropertiesStorage

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

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

the class CatalogContentsTest 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");
    Properties props = new Properties();
    try (InputStream is = Files.newInputStream(catalogPath)) {
        props.load(is);
    }
    remstorage = new RemotePropertiesStorage(this, getLocalRegistry(), props, "linux_amd64", v, catalogPath.toUri().toURL());
    coll = new CatalogContents(this, remstorage, getLocalRegistry());
    return v;
}
Also used : Path(java.nio.file.Path) Version(org.graalvm.component.installer.Version) RemotePropertiesStorage(org.graalvm.component.installer.remote.RemotePropertiesStorage) InputStream(java.io.InputStream) Properties(java.util.Properties)

Example 3 with RemotePropertiesStorage

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

the class MergedCatalogContentsTest method initVersion.

private Version initVersion(String s) throws IOException {
    Version v = Version.fromString(s);
    storage.graalInfo.put(BundleConstants.GRAAL_VERSION, s);
    Path catalogPath = dataFile("catalog-deps.properties");
    Properties props = new Properties();
    try (InputStream is = Files.newInputStream(catalogPath)) {
        props.load(is);
    }
    remstorage = new RemotePropertiesStorage(this, getLocalRegistry(), props, "linux_amd64", v, catalogPath.toUri().toURL());
    coll = new CatalogContents(this, remstorage, getLocalRegistry());
    return v;
}
Also used : Path(java.nio.file.Path) Version(org.graalvm.component.installer.Version) RemotePropertiesStorage(org.graalvm.component.installer.remote.RemotePropertiesStorage) InputStream(java.io.InputStream) Properties(java.util.Properties)

Example 4 with RemotePropertiesStorage

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

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

the class ListTest method initRemoteStorage.

private void initRemoteStorage() throws MalformedURLException {
    this.remoteStorage = new RemotePropertiesStorage(this, getLocalRegistry(), catalogContents, "linux_amd64", Version.fromString("1.0.0-rc3-dev"), new URL("http://go.to/graalvm"));
    this.registry = new CatalogContents(this, remoteStorage, localRegistry);
}
Also used : RemotePropertiesStorage(org.graalvm.component.installer.remote.RemotePropertiesStorage) CatalogContents(org.graalvm.component.installer.model.CatalogContents) URL(java.net.URL)

Aggregations

RemotePropertiesStorage (org.graalvm.component.installer.remote.RemotePropertiesStorage)6 URL (java.net.URL)4 Path (java.nio.file.Path)4 Properties (java.util.Properties)4 Version (org.graalvm.component.installer.Version)4 InputStream (java.io.InputStream)3 FileInputStream (java.io.FileInputStream)2 CatalogContents (org.graalvm.component.installer.model.CatalogContents)2 FileDownloader (org.graalvm.component.installer.remote.FileDownloader)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 MalformedURLException (java.net.MalformedURLException)1 NoRouteToHostException (java.net.NoRouteToHostException)1 HashSet (java.util.HashSet)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