Search in sources :

Example 96 with ComponentInfo

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

the class InstallCommand method registerComponent.

protected boolean registerComponent(Installer inst, ComponentParam p) throws IOException {
    ComponentInfo info = inst.getComponentInfo();
    Installer existing = installerMap.get(info.getId());
    Installer removedInstaller = null;
    if (existing == null) {
        installerMap.put(info.getId(), inst);
        if (installDependencies) {
            installers.add(0, inst);
        } else {
            installers.add(inst);
        }
        return true;
    } else {
        int i = installers.indexOf(existing);
        ComponentInfo exInfo = existing.getComponentInfo();
        int newer = exInfo.getVersion().compareTo(info.getVersion());
        if (newer < 0) {
            feedback.verboseOutput("INSTALL_UsingNewerComponent", info.getId(), info.getName(), info.getVersion().displayString(), exInfo.getVersion().displayString());
            removedInstaller = installerMap.put(info.getId(), inst);
            if (installDependencies) {
                // must reinsert at the start: later items may depend on this one
                installers.remove(i);
                installers.add(0, inst);
            } else {
                // replace at the same position, to mainain commandline order
                installers.set(i, inst);
            }
            existing.close();
            if (removedInstaller != null) {
                realInstallers.remove(p);
            }
            return true;
        } else {
            Installer toReplace = inst.isComplete() ? inst : existing;
            // of the work queue, to maintain the depenency-first order.
            if (installDependencies) {
                installers.remove(existing);
                installers.add(0, toReplace);
                installerMap.put(info.getId(), toReplace);
            } else if (!existing.isComplete() && inst.isComplete()) {
                // replace proxy for real installer:
                installers.set(i, toReplace);
                installerMap.put(info.getId(), toReplace);
            }
            return false;
        }
    }
}
Also used : ComponentInstaller(org.graalvm.component.installer.ComponentInstaller) ComponentInfo(org.graalvm.component.installer.model.ComponentInfo)

Example 97 with ComponentInfo

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

the class InstallCommand method ensureExistingComponentRemoved.

void ensureExistingComponentRemoved(ComponentInfo info) throws IOException {
    String componentId = info.getId();
    ComponentInfo oldInfo = input.getLocalRegistry().loadSingleComponent(componentId, true);
    if (oldInfo == null) {
        feedback.output("INSTALL_InstallNewComponent", info.getId(), info.getName(), info.getVersionString());
    } else {
        Uninstaller uninstaller = new Uninstaller(feedback, input.getFileOperations(), oldInfo, input.getLocalRegistry());
        uninstaller.setInstallPath(input.getGraalHomePath());
        uninstaller.setDryRun(input.optValue(Commands.OPTION_DRY_RUN) != null);
        uninstaller.setPreservePaths(new HashSet<>(input.getLocalRegistry().getPreservedFiles(oldInfo)));
        feedback.output("INSTALL_RemoveExistingComponent", oldInfo.getId(), oldInfo.getName(), oldInfo.getVersionString(), info.getId(), info.getName(), info.getVersionString());
        uninstaller.uninstall();
    }
}
Also used : ComponentInfo(org.graalvm.component.installer.model.ComponentInfo)

Example 98 with ComponentInfo

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

the class InstallCommand method printRequiredComponents.

void printRequiredComponents() throws IOException {
    if (dependencies.isEmpty()) {
        return;
    }
    feedback.output("INSTALL_RequiredDependencies");
    for (ComponentParam p : dependencies) {
        ComponentInfo ci = p.createMetaLoader().getComponentInfo();
        feedback.output("INSTALL_RequiredDependencyLine", p.getDisplayName(), ci.getId(), ci.getVersion().displayString(), printComponentList(dependencyMap.get(ci.getId())));
    }
}
Also used : ComponentParam(org.graalvm.component.installer.ComponentParam) ComponentInfo(org.graalvm.component.installer.model.ComponentInfo)

Example 99 with ComponentInfo

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

the class InstallCommand method verifyInstaller.

boolean verifyInstaller(Installer inst) {
    ComponentInfo info = inst.getComponentInfo();
    Verifier vrf = inst.createVerifier();
    vrf.setVersionMatch(matchInstallVesion());
    vrf.validateRequirements(info);
    boolean keep = force || vrf.shouldInstall(info);
    if (!keep) {
        // component will be skipped, do not bother with validation
        feedback.output("INSTALL_ComponentAlreadyInstalled", inst.getComponentInfo().getName(), inst.getComponentInfo().getId());
        return false;
    }
    ComponentInfo existing = input.getLocalRegistry().findComponent(info.getId());
    if (existing != null) {
        // will refuse to install existing bundled components:
        if (existing.getDistributionType() != DistributionType.OPTIONAL) {
            throw new DependencyException.Conflict(existing.getId(), info.getVersionString(), existing.getVersionString(), feedback.l10n("INSTALL_CannotReplaceBundledComponent", existing.getName(), existing, existing.getVersionString()));
        }
    }
    Version minV = vrf.getMinVersion();
    if (minV != null && minV.compareTo(this.minRequiredGraalVersion) > 0) {
        minRequiredGraalVersion = minV;
    }
    addDependencies(info);
    return true;
}
Also used : Version(org.graalvm.component.installer.Version) ComponentInfo(org.graalvm.component.installer.model.ComponentInfo) Verifier(org.graalvm.component.installer.model.Verifier)

Example 100 with ComponentInfo

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

the class GenerateCatalog method generateCatalog.

private void generateCatalog() throws IOException {
    for (Spec spec : componentSpecs) {
        File f = spec.f;
        byte[] hash = computeHash(f);
        String hashString = digest2String(hash);
        try (JarFile jf = new JarFile(f)) {
            ComponentPackageLoader ldr = new JarMetaLoader(jf, hashString, env);
            ComponentInfo info = ldr.createComponentInfo();
            String prefix = findComponentPrefix(info);
            if (!graalVMReleases.containsKey(prefix)) {
                graalVMReleases.put(prefix, new GraalVersion(version, os, arch));
            }
            Manifest mf = jf.getManifest();
            if (mf == null) {
                throw new IOException("No manifest in " + spec);
            }
            String tagString;
            if (formatVer < 2 || info.getTag() == null || info.getTag().isEmpty()) {
                tagString = "";
            } else {
                // include hash of the file in property prefix.
                // NOI18N
                tagString = "/" + hashString;
            }
            Attributes atts = mf.getMainAttributes();
            String bid = atts.getValue(BundleConstants.BUNDLE_ID).toLowerCase().replace("-", "_");
            String bl = atts.getValue(BundleConstants.BUNDLE_NAME);
            if (bid == null) {
                throw new IOException("Missing bundle id in " + spec);
            }
            if (bl == null) {
                throw new IOException("Missing bundle name in " + spec);
            }
            String name;
            prefix += tagString;
            if (spec.u != null) {
                name = spec.u.toString();
            } else {
                name = spec.relativePath != null ? spec.relativePath : f.getName();
            }
            int pos;
            while ((pos = name.indexOf("${")) != -1) {
                int endPos = name.indexOf("}", pos + 1);
                if (endPos == -1) {
                    break;
                }
                String key = name.substring(pos + 2, endPos);
                String repl = info.getRequiredGraalValues().get(key);
                if (repl == null) {
                    switch(key) {
                        case "version":
                            repl = version;
                            break;
                        case "os":
                            repl = os;
                            break;
                        case "arch":
                            repl = arch;
                            break;
                        case "comp_version":
                            repl = info.getVersionString();
                            break;
                        default:
                            throw new IllegalArgumentException(key);
                    }
                }
                if (repl == null) {
                    throw new IllegalArgumentException(key);
                }
                String toReplace = "${" + key + "}";
                name = name.replace(toReplace, repl);
            }
            String url = (urlPrefix == null || urlPrefix.isEmpty()) ? name : urlPrefix + "/" + name;
            String sel;
            String hashSuffix;
            switch(formatVer) {
                case 1:
                    sel = "Component.{0}.{1}";
                    hashSuffix = "-hash";
                    break;
                case 2:
                    sel = "Component.{0}/{1}";
                    hashSuffix = "-hash";
                    break;
                default:
                    throw new IllegalStateException();
            }
            catalogContents.append(MessageFormat.format(sel + "={2}\n", prefix, bid, url));
            catalogContents.append(MessageFormat.format(sel + hashSuffix + "={2}\n", prefix, bid, hashString));
            for (Object a : atts.keySet()) {
                String key = a.toString();
                String val = atts.getValue(key);
                if (key.startsWith("x-GraalVM-Message-")) {
                    // NOI18N
                    continue;
                }
                catalogContents.append(MessageFormat.format(sel + "-{2}={3}\n", prefix, bid, key, val));
            }
        }
    }
}
Also used : Attributes(java.util.jar.Attributes) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest) ComponentPackageLoader(org.graalvm.component.installer.persist.ComponentPackageLoader) JarMetaLoader(org.graalvm.component.installer.jar.JarMetaLoader) ComponentInfo(org.graalvm.component.installer.model.ComponentInfo) JarFile(java.util.jar.JarFile) File(java.io.File)

Aggregations

ComponentInfo (org.graalvm.component.installer.model.ComponentInfo)149 Test (org.junit.Test)94 Path (java.nio.file.Path)36 Version (org.graalvm.component.installer.Version)28 HashSet (java.util.HashSet)20 ArrayList (java.util.ArrayList)19 ComponentParam (org.graalvm.component.installer.ComponentParam)19 IOException (java.io.IOException)13 URL (java.net.URL)11 MetadataLoader (org.graalvm.component.installer.persist.MetadataLoader)10 InputStream (java.io.InputStream)9 HashMap (java.util.HashMap)9 Collection (java.util.Collection)8 List (java.util.List)8 Properties (java.util.Properties)8 Map (java.util.Map)7 Set (java.util.Set)7 Collections (java.util.Collections)6 FailedOperationException (org.graalvm.component.installer.FailedOperationException)6 SystemUtils (org.graalvm.component.installer.SystemUtils)6