Search in sources :

Example 6 with ComponentPackageLoader

use of org.graalvm.component.installer.persist.ComponentPackageLoader 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)

Example 7 with ComponentPackageLoader

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

the class VerifierTest method testGraalCapabilitiesCaseInsensitive.

@Test
public void testGraalCapabilitiesCaseInsensitive() throws Exception {
    try (JarFile jf = new JarFile(dataFile("truffleruby2.jar").toFile())) {
        ComponentPackageLoader ldr = new JarMetaLoader(jf, this);
        rubyInfo = ldr.createComponentInfo();
        ldr.loadPaths();
        ldr.loadSymlinks();
    }
    mockStorage.graalInfo.put(CAP_OS_NAME, "LiNuX");
    Verifier vfy = new Verifier(this, registry, registry);
    vfy.validateRequirements(rubyInfo);
}
Also used : JarFile(java.util.jar.JarFile) ComponentPackageLoader(org.graalvm.component.installer.persist.ComponentPackageLoader) JarMetaLoader(org.graalvm.component.installer.jar.JarMetaLoader) Test(org.junit.Test)

Aggregations

ComponentPackageLoader (org.graalvm.component.installer.persist.ComponentPackageLoader)7 JarFile (java.util.jar.JarFile)6 JarMetaLoader (org.graalvm.component.installer.jar.JarMetaLoader)6 File (java.io.File)3 URL (java.net.URL)3 ComponentInfo (org.graalvm.component.installer.model.ComponentInfo)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Attributes (java.util.jar.Attributes)1 Manifest (java.util.jar.Manifest)1 DependencyException (org.graalvm.component.installer.DependencyException)1 DownloadURLParam (org.graalvm.component.installer.DownloadURLIterable.DownloadURLParam)1 CatalogItemParam (org.graalvm.component.installer.remote.CatalogIterable.CatalogItemParam)1 Before (org.junit.Before)1