Search in sources :

Example 16 with CatalogIterable

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

the class CatalogIterableTest method testUnknownComponentButExistingFile.

/**
 * Checks that if user mistypes a filename instead of component ID, an informative note is
 * printed.
 */
@Test
public void testUnknownComponentButExistingFile() throws Exception {
    exception.expect(FailedOperationException.class);
    exception.expectMessage("REMOTE_UnknownComponentMaybeFile");
    addRemoteComponent("persist/data/truffleruby3.jar", "test://graalvm.io/download/truffleruby.zip", false);
    File mistyped = folder.newFile("mistyped-component.jar");
    textParams.add(mistyped.getPath());
    CatalogIterable cit = new CatalogIterable(this, this);
    assertTrue(cit.iterator().hasNext());
    cit.iterator().next();
}
Also used : CatalogIterable(org.graalvm.component.installer.remote.CatalogIterable) File(java.io.File) Test(org.junit.Test)

Example 17 with CatalogIterable

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

the class CatalogIterableTest method testMixWildcardsAndLiterals.

@Test
public void testMixWildcardsAndLiterals() throws Exception {
    setupCatalog();
    textParams.add("r*");
    textParams.add("ruby");
    CatalogIterable cit = new CatalogIterable(this, this);
    Iterator<ComponentParam> comps = cit.iterator();
    List<String> fullIds = new ArrayList<>();
    for (; comps.hasNext(); ) {
        ComponentParam cp = comps.next();
        fullIds.add(cp.createMetaLoader().getComponentInfo().getId());
    }
    assertEquals(3, fullIds.size());
    assertEquals("org.graalvm.ruby", fullIds.get(1));
    assertEquals("org.graalvm.ruby", fullIds.get(2));
}
Also used : ArrayList(java.util.ArrayList) CatalogIterable(org.graalvm.component.installer.remote.CatalogIterable) Test(org.junit.Test)

Example 18 with CatalogIterable

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

the class CatalogIterableTest method testURLDoesNotExist.

@Test
public void testURLDoesNotExist() throws Exception {
    storage.graalInfo.put(BundleConstants.GRAAL_VERSION, "0.33-dev");
    addRemoteComponent("persist/data/truffleruby3.jar", "test://graalvm.io/download/truffleruby.zip", false);
    textParams.add("ruby");
    Handler.bind(url.toString(), new URLConnection(url) {

        @Override
        public InputStream getInputStream() throws IOException {
            connect();
            return clu.openStream();
        }

        @Override
        public String getHeaderField(int n) {
            try {
                connect();
            } catch (IOException ex) {
                Logger.getLogger(CatalogIterableTest.class.getName()).log(Level.SEVERE, null, ex);
            }
            return super.getHeaderField(n);
        }

        @Override
        public Map<String, List<String>> getHeaderFields() {
            try {
                connect();
            } catch (IOException ex) {
                Logger.getLogger(CatalogIterableTest.class.getName()).log(Level.SEVERE, null, ex);
            }
            return super.getHeaderFields();
        }

        @Override
        public void connect() throws IOException {
            throw new FileNotFoundException();
        }
    });
    CatalogIterable cit = new CatalogIterable(this, this);
    ComponentParam rubyComp = cit.iterator().next();
    exception.expect(FailedOperationException.class);
    exception.expectMessage("REMOTE_ErrorDownloadingNotExist");
    rubyComp.createFileLoader().getComponentInfo();
}
Also used : InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) CatalogIterable(org.graalvm.component.installer.remote.CatalogIterable) Map(java.util.Map) URLConnection(java.net.URLConnection) Test(org.junit.Test)

Example 19 with CatalogIterable

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

the class ComponentInstaller method processOptions.

int processOptions(LinkedList<String> cmdline) {
    if (cmdline.size() < 1) {
        env = SIMPLE_ENV;
        printDefaultHelp(OptionCategory.USER);
        return 1;
    }
    SimpleGetopt go = createOptions(cmdline);
    launch(cmdline);
    go = interpretOptions(go);
    if (go == null) {
        return 0;
    }
    if (env.hasOption(Commands.OPTION_PRINT_VERSION)) {
        printVersion();
        return 0;
    } else if (env.hasOption(Commands.OPTION_SHOW_VERSION)) {
        printVersion();
    }
    // check only after the version option:
    if (cmdHandler == null) {
        // NOI18N
        error("ERROR_MissingCommand");
    }
    int srcCount = 0;
    if (input.hasOption(Commands.OPTION_FILES)) {
        srcCount++;
    }
    if (input.hasOption(Commands.OPTION_URLS)) {
        srcCount++;
    }
    if (srcCount > 1) {
        error("ERROR_MultipleSourcesUnsupported");
    }
    if (input.hasOption(Commands.OPTION_AUTO_YES)) {
        env.setAutoYesEnabled(true);
    }
    if (input.hasOption(Commands.OPTION_NON_INTERACTIVE)) {
        env.setNonInteractive(true);
    }
    // explicit location
    String catalogURL = getExplicitCatalogURL();
    String builtinCatLocation = getReleaseCatalogURL();
    if (builtinCatLocation == null) {
        builtinCatLocation = feedback.l10n("Installer_BuiltingCatalogURL");
    }
    GraalEditionList editionList = new GraalEditionList(feedback, input, input.getLocalRegistry());
    editionList.setDefaultCatalogSpec(builtinCatLocation);
    editionList.setOverrideCatalogSpec(catalogURL);
    env.setCatalogFactory(editionList);
    if (input.hasOption(Commands.OPTION_USE_EDITION)) {
        input.getLocalRegistry().setOverrideEdition(input.optValue(Commands.OPTION_USE_EDITION));
    }
    boolean builtinsImplied = true;
    boolean setIterable = true;
    if (input.hasOption(Commands.OPTION_FILES)) {
        FileIterable fi = new FileIterable(env, env);
        fi.setCatalogFactory(editionList);
        env.setFileIterable(fi);
        // optionally resolve local dependencies against parent directories
        // of specified files.
        builtinsImplied = false;
        if (input.hasOption(Commands.OPTION_LOCAL_DEPENDENCIES)) {
            while (env.hasParameter()) {
                String s = env.nextParameter();
                Path p = SystemUtils.fromUserString(s);
                if (p != null) {
                    Path parent = p.getParent();
                    if (parent != null && Files.isDirectory(parent)) {
                        SoftwareChannelSource localSource = new SoftwareChannelSource(parent.toUri().toString(), null);
                        localSource.setPriority(10000);
                        editionList.addLocalChannelSource(localSource);
                    }
                }
            }
            env.resetParameters();
        }
        setIterable = false;
    } else if (input.hasOption(Commands.OPTION_URLS)) {
        DownloadURLIterable dit = new DownloadURLIterable(env, env);
        dit.setCatalogFactory(editionList);
        env.setFileIterable(dit);
        setIterable = false;
        builtinsImplied = false;
    }
    if (setIterable) {
        env.setFileIterable(new CatalogIterable(env, env));
    }
    editionList.setRemoteSourcesAllowed(builtinsImplied || env.hasOption(Commands.OPTION_CATALOG) || env.hasOption(Commands.OPTION_FOREIGN_CATALOG));
    return -1;
}
Also used : Path(java.nio.file.Path) GraalEditionList(org.graalvm.component.installer.remote.GraalEditionList) CatalogIterable(org.graalvm.component.installer.remote.CatalogIterable)

Example 20 with CatalogIterable

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

the class CatalogInstallTest method testCheckPostinstMessageLoaded.

@Test
public void testCheckPostinstMessageLoaded() throws Exception {
    setupVersion("0.33");
    URL x = getClass().getResource("postinst2.jar");
    URL rubyURL = new URL("test://release/postinst2.jar");
    Handler.bind(rubyURL.toString(), x);
    setupCatalog(null);
    paramIterable = new CatalogIterable(this, this);
    textParams.add("ruby");
    InstallCommand cmd = new InstallCommand();
    cmd.init(this, withBundle(InstallCommand.class));
    cmd.prepareInstallation();
    cmd.completeInstallers();
    assertFalse(cmd.realInstallers.isEmpty());
    for (Installer i : cmd.realInstallers.values()) {
        assertNotNull(i.getComponentInfo().getPostinstMessage());
    }
}
Also used : CatalogIterable(org.graalvm.component.installer.remote.CatalogIterable) URL(java.net.URL) Test(org.junit.Test)

Aggregations

CatalogIterable (org.graalvm.component.installer.remote.CatalogIterable)33 Test (org.junit.Test)22 ComponentInfo (org.graalvm.component.installer.model.ComponentInfo)7 URL (java.net.URL)5 ComponentParam (org.graalvm.component.installer.ComponentParam)5 CatalogContents (org.graalvm.component.installer.model.CatalogContents)5 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 RemoteCatalogDownloader (org.graalvm.component.installer.remote.RemoteCatalogDownloader)4 URLConnection (java.net.URLConnection)3 Version (org.graalvm.component.installer.Version)3 GraalEditionList (org.graalvm.component.installer.remote.GraalEditionList)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CommandInput (org.graalvm.component.installer.CommandInput)1