use of org.graalvm.component.installer.jar.JarMetaLoader in project graal by oracle.
the class CommandTestBase method initRemoteComponent.
protected void initRemoteComponent(String relativeJar, String u, String disp, String spec) throws IOException {
clu = getClass().getResource(relativeJar);
url = new URL(u);
Handler.bind(url.toString(), clu);
File f = dataFile(relativeJar).toFile();
JarFile jf = new JarFile(f, false);
ComponentPackageLoader cpl = new JarMetaLoader(jf, this);
info = cpl.getComponentInfo();
// unknown in catalog metadata
info.setLicensePath(null);
info.setRemoteURL(url);
param = rparam = new CatalogItemParam(this, info, disp, spec, this, false);
}
use of org.graalvm.component.installer.jar.JarMetaLoader in project graal by oracle.
the class JarPackageProvider method createLoader.
@Override
public MetadataLoader createLoader(Path p, byte[] magic, String serial, Feedback feedback, boolean verify) throws IOException {
if ((magic[0] == 0x50) && (magic[1] == 0x4b) && (magic[2] == 0x03) && (magic[3] == 0x04)) {
JarFile jf = new JarFile(p.toFile(), verify);
boolean ok = false;
try {
JarMetaLoader ldr = new JarMetaLoader(jf, serial, feedback);
ok = true;
return ldr;
} finally {
if (!ok) {
try {
jf.close();
} catch (IOException ex) {
feedback.error("ERR_ClosingJarFile", ex, ex.getLocalizedMessage());
}
}
}
} else {
return null;
}
}
use of org.graalvm.component.installer.jar.JarMetaLoader 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));
}
}
}
}
use of org.graalvm.component.installer.jar.JarMetaLoader 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);
}
use of org.graalvm.component.installer.jar.JarMetaLoader in project graal by oracle.
the class ComponentPackageLoaderTest method testCollectErrors.
@Test
public void testCollectErrors() throws Exception {
File f = dataFile("broken1.zip").toFile();
jf = new JarFile(f);
loader = new JarMetaLoader(jf, this).infoOnly(true);
info = loader.createComponentInfo();
List<String> errs = new ArrayList<>();
loader.getErrors().forEach((e) -> errs.add(((MetadataException) e).getOffendingHeader()));
Collections.sort(errs);
assertEquals("org.graalvm.ruby", info.getId());
assertEquals(Arrays.asList(BundleConstants.BUNDLE_NAME, BundleConstants.BUNDLE_REQUIRED, BundleConstants.BUNDLE_VERSION), errs);
}
Aggregations