Search in sources :

Example 11 with SoftwareChannelSource

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

the class GraalEditionList method init.

void init() {
    if (defaultEdition != null) {
        return;
    }
    String defEditionId = targetGraal.getGraalCapabilities().get(CommonConstants.CAP_EDITION);
    if (isExplicitOverride()) {
        initSimple(defEditionId, overrideCatalogSpec);
        return;
    }
    List<SoftwareChannelSource> srcs = readChannelSources(defEditionId);
    if (srcs.isEmpty()) {
        // no source channels defined for the editionId
        srcs = readChannelSources(null);
    }
    if (srcs.isEmpty()) {
        initSimple(defEditionId, defaultCatalogSpec);
        return;
    }
    List<String> edList = listEditionsFromRelease();
    String label;
    List<SoftwareChannelSource> sources;
    if (edList.contains(defEditionId)) {
        edList.remove(defEditionId);
        label = getEditionLabel(defEditionId);
        sources = readChannelSources(defEditionId);
    } else if (!edList.remove("")) {
        throw new IllegalStateException("Malformed release file.");
    } else {
        label = getEditionLabel(null);
        sources = readChannelSources(null);
    }
    GraalEdition ge = new GraalEdition(defEditionId, label);
    ge.setSoftwareSources(sources);
    registerEdition(ge, true);
    for (String id : edList) {
        label = getEditionLabel(id);
        sources = readChannelSources(id);
        ge = new GraalEdition(id, label);
        ge.setSoftwareSources(sources);
        registerEdition(ge, false);
    }
}
Also used : GraalEdition(org.graalvm.component.installer.model.GraalEdition) SoftwareChannelSource(org.graalvm.component.installer.SoftwareChannelSource)

Example 12 with SoftwareChannelSource

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

the class GraalEditionList method parseChannelSources.

@SuppressWarnings("ThrowableResultIgnored")
List<SoftwareChannelSource> parseChannelSources(String edId, String overrideSpec) {
    List<SoftwareChannelSource> sources = new ArrayList<>();
    if (!remoteSourcesAllowed || overrideSpec == null) {
        return sources;
    }
    int priority = 1;
    // NOI18N
    String[] parts = overrideSpec.split("\\|");
    String id = edId;
    if (id == null) {
        id = targetGraal.getGraalCapabilities().get(CommonConstants.CAP_EDITION);
    }
    for (String s : parts) {
        SoftwareChannelSource chs = new SoftwareChannelSource(s);
        chs.setPriority(priority);
        chs.setParameter("edition", id);
        sources.add(chs);
        priority++;
    }
    return sources;
}
Also used : SoftwareChannelSource(org.graalvm.component.installer.SoftwareChannelSource) ArrayList(java.util.ArrayList)

Example 13 with SoftwareChannelSource

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

the class RemoteCatalogDownloader method readChannelSources.

List<SoftwareChannelSource> readChannelSources(String pref, Map<String, String> graalCaps) {
    String prefix = pref + CommonConstants.CAP_CATALOG_PREFIX;
    List<String> orderedKeys = graalCaps.keySet().stream().filter((k) -> {
        String lk = k.toLowerCase(Locale.ENGLISH);
        return lk.startsWith(prefix) && lk.endsWith(CAP_CATALOG_URL_SUFFIX);
    }).map((k) -> k.substring(0, k.length() - CAP_CATALOG_URL_SUFFIX.length())).collect(Collectors.toList());
    Collections.sort(orderedKeys, CHANNEL_KEY_COMPARATOR);
    List<SoftwareChannelSource> sources = new ArrayList<>();
    for (String key : orderedKeys) {
        String url = graalCaps.get(key + CAP_CATALOG_URL_SUFFIX);
        String lab = graalCaps.get(key + "_" + CommonConstants.CAP_CATALOG_LABEL);
        if (url == null) {
            continue;
        }
        SoftwareChannelSource s = new SoftwareChannelSource(url, lab);
        for (String a : graalCaps.keySet()) {
            if (!(a.startsWith(key) && a.length() > key.length() + 1)) {
                continue;
            }
            String k = a.substring(key.length() + 1).toLowerCase(Locale.ENGLISH);
            switch(k) {
                case CommonConstants.CAP_CATALOG_LABEL:
                case CommonConstants.CAP_CATALOG_URL:
                    continue;
            }
            s.setParameter(k, graalCaps.get(a));
        }
        sources.add(s);
    }
    return sources;
}
Also used : SoftwareChannel(org.graalvm.component.installer.SoftwareChannel) URL(java.net.URL) CommonConstants(org.graalvm.component.installer.CommonConstants) Commands(org.graalvm.component.installer.Commands) HashMap(java.util.HashMap) ServiceLoader(java.util.ServiceLoader) CatalogContents(org.graalvm.component.installer.model.CatalogContents) Feedback(org.graalvm.component.installer.Feedback) ComponentInfo(org.graalvm.component.installer.model.ComponentInfo) ComponentStorage(org.graalvm.component.installer.model.ComponentStorage) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) ComponentCollection(org.graalvm.component.installer.ComponentCollection) Locale(java.util.Locale) Map(java.util.Map) Comparator(java.util.Comparator) SoftwareChannelSource(org.graalvm.component.installer.SoftwareChannelSource) Collections(java.util.Collections) CommandInput(org.graalvm.component.installer.CommandInput) SoftwareChannelSource(org.graalvm.component.installer.SoftwareChannelSource) ArrayList(java.util.ArrayList)

Example 14 with SoftwareChannelSource

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

the class GraalEditionListTest method testParseRelease20EEWithLabel.

@Test
public void testParseRelease20EEWithLabel() throws Exception {
    // this one contains multiple
    loadReleaseFile("release20ee.properties");
    // substitute "ee", since that's what the DirectoryStorage does in presence of
    // 'vm-enterprise' now:
    storage.graalInfo.put(CommonConstants.CAP_EDITION, "ee");
    GraalEditionList list = new GraalEditionList(this, this, getLocalRegistry());
    list.setDefaultCatalogSpec(storage.graalInfo.get(CommonConstants.RELEASE_CATALOG_KEY));
    List<GraalEdition> eds = list.editions();
    assertFalse(eds.isEmpty());
    assertEquals(1, eds.size());
    GraalEdition ge = eds.get(0);
    assertSame(list.getDefaultEdition(), ge);
    assertEquals("Expected ee for vm-enterprise", "ee", ge.getId());
    assertEquals("Unqualified label should be picked up", "Enterprise Edition", ge.getDisplayName());
    List<SoftwareChannelSource> sources = ge.getSoftwareSources();
    assertEquals("Multiple software sources must be read", 3, sources.size());
    assertEquals("Expected decreasing priority", 2, sources.get(1).getPriority());
}
Also used : GraalEdition(org.graalvm.component.installer.model.GraalEdition) SoftwareChannelSource(org.graalvm.component.installer.SoftwareChannelSource) Test(org.junit.Test)

Example 15 with SoftwareChannelSource

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

the class RemoteCatalogDownloaderTest method testParseCatalogOverride.

/**
 * Checks that simple explicit URL given 'the old way' will define a catalog that will be
 * loaded.
 *
 * @throws Exception
 */
@Test
public void testParseCatalogOverride() throws Exception {
    storage.graalInfo.put(CommonConstants.CAP_GRAALVM_VERSION, "0.33-dev");
    String single = "test://graalv.org/test/catalog.properties";
    RemoteCatalogDownloader d = new RemoteCatalogDownloader(this, this, single);
    List<SoftwareChannelSource> sources = d.getChannelSources();
    assertNotNull(sources);
    assertEquals(1, sources.size());
    assertEquals(single, sources.get(0).getLocationURL());
    URL clu1 = getClass().getResource("catalogMultiVersions.properties");
    Handler.bind(single, clu1);
    ComponentStorage store = d.getStorage();
    Set<String> ids = store.listComponentIDs();
    assertTrue(ids.contains("ruby"));
    assertTrue(Handler.isVisited(new URL(single)));
}
Also used : ComponentStorage(org.graalvm.component.installer.model.ComponentStorage) SoftwareChannelSource(org.graalvm.component.installer.SoftwareChannelSource) URL(java.net.URL) Test(org.junit.Test)

Aggregations

SoftwareChannelSource (org.graalvm.component.installer.SoftwareChannelSource)19 Test (org.junit.Test)10 GraalEdition (org.graalvm.component.installer.model.GraalEdition)8 URL (java.net.URL)6 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 CommandInput (org.graalvm.component.installer.CommandInput)3 CommonConstants (org.graalvm.component.installer.CommonConstants)3 Feedback (org.graalvm.component.installer.Feedback)3 SoftwareChannel (org.graalvm.component.installer.SoftwareChannel)3 CatalogContents (org.graalvm.component.installer.model.CatalogContents)3 ComponentInfo (org.graalvm.component.installer.model.ComponentInfo)3 ComponentRegistry (org.graalvm.component.installer.model.ComponentRegistry)3 RemoteCatalogDownloader (org.graalvm.component.installer.remote.RemoteCatalogDownloader)3 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2 Map (java.util.Map)2