use of org.graalvm.component.installer.MetadataException in project graal by oracle.
the class DirectoryStorage method propertiesToMeta.
public static ComponentInfo propertiesToMeta(Properties loaded, ComponentInfo ci, Feedback fb) {
String stability = loaded.getProperty(BundleConstants.BUNDLE_STABILITY2, loaded.getProperty(BundleConstants.BUNDLE_STABILITY));
if (stability != null) {
ci.setStability(StabilityLevel.valueOfMixedCase(stability));
}
String license = loaded.getProperty(BundleConstants.BUNDLE_LICENSE_PATH);
if (license != null) {
SystemUtils.checkCommonRelative(null, license);
ci.setLicensePath(license);
}
for (String s : loaded.stringPropertyNames()) {
if (s.startsWith(BUNDLE_REQUIRED_PREFIX)) {
String k = s.substring(BUNDLE_REQUIRED_PREFIX.length());
// NOI18N
String v = loaded.getProperty(s, "");
ci.addRequiredValue(k, v);
}
if (s.startsWith(BUNDLE_PROVIDED_PREFIX)) {
String k = s.substring(BUNDLE_PROVIDED_PREFIX.length());
// NOI18N
String v = loaded.getProperty(s, "");
if (v.length() < 2) {
continue;
}
String val = v.substring(1);
Object o;
switch(v.charAt(0)) {
case 'V':
o = Version.fromString(val);
break;
case '"':
o = val;
break;
default:
continue;
}
ci.provideValue(k, o);
}
}
Set<String> deps = new LinkedHashSet<>();
for (String s : loaded.getProperty(BundleConstants.BUNDLE_DEPENDENCY, "").split(",")) {
String p = s.trim();
if (!p.isEmpty()) {
deps.add(s.trim());
}
}
if (!deps.isEmpty()) {
ci.setDependencies(deps);
}
if (Boolean.TRUE.toString().equals(loaded.getProperty(BundleConstants.BUNDLE_POLYGLOT_PART, ""))) {
// NOI18N
ci.setPolyglotRebuild(true);
}
List<String> ll = new ArrayList<>();
for (String s : loaded.getProperty(BundleConstants.BUNDLE_WORKDIRS, "").split(":")) {
String p = s.trim();
if (!p.isEmpty()) {
SystemUtils.checkCommonRelative(null, p);
ll.add(p);
}
}
ci.addWorkingDirectories(ll);
String licType = loaded.getProperty(BundleConstants.BUNDLE_LICENSE_TYPE);
if (licType != null) {
ci.setLicenseType(licType);
}
String postInst = loaded.getProperty(BundleConstants.BUNDLE_MESSAGE_POSTINST);
if (postInst != null) {
// NOI18N
String text = postInst.replace("\\n", "\n").replace("\\\\", "\\");
ci.setPostinstMessage(text);
}
String u = loaded.getProperty(CommonConstants.BUNDLE_ORIGIN_URL);
if (u != null) {
try {
ci.setRemoteURL(new URL(u));
} catch (MalformedURLException ex) {
// ignore
}
}
String dtn = loaded.getProperty(BundleConstants.BUNDLE_COMPONENT_DISTRIBUTION, DistributionType.OPTIONAL.name());
try {
ci.setDistributionType(DistributionType.valueOf(dtn.toUpperCase(Locale.ENGLISH)));
} catch (IllegalArgumentException ex) {
throw new MetadataException(BundleConstants.BUNDLE_COMPONENT_DISTRIBUTION, fb.withBundle(DirectoryStorage.class).l10n("ERROR_InvalidDistributionType", dtn));
}
return ci;
}
use of org.graalvm.component.installer.MetadataException in project graal by oracle.
the class ListInstalledCommand method process.
boolean process() {
makeRegularExpression();
List<String> ids = findComponentIds();
List<MetadataException> exceptions = new ArrayList<>();
if (ids.isEmpty()) {
if (!simpleFormat) {
feedback.message("LIST_NoComponentsFound");
}
return false;
}
Version.Match versionFilter = getVersionFilter();
for (String id : ids) {
try {
List<ComponentInfo> infos = new ArrayList<>(catalog.loadComponents(id, versionFilter, listFiles));
if (infos != null) {
for (ComponentInfo ci : filterDisplayedVersions(id, infos)) {
addComponent(null, ci);
}
}
} catch (MetadataException ex) {
exceptions.add(ex);
}
}
if (components.isEmpty()) {
if (!simpleFormat) {
feedback.message("LIST_NoComponentsFound");
}
return false;
}
if (!simpleFormat && !exceptions.isEmpty()) {
feedback.error("LIST_ErrorInComponentMetadata", null);
for (Exception e : exceptions) {
feedback.error("LIST_ErrorInComponentMetadataItem", e, e.getLocalizedMessage());
}
}
return true;
}
use of org.graalvm.component.installer.MetadataException 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);
}
use of org.graalvm.component.installer.MetadataException in project graal by oracle.
the class ComponentPackageLoaderTest method testRequiredKeys.
/**
* Checks that the parser rejects components, if they have some keys required.
*
* @throws Exception
*/
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRequiredKeys() throws Exception {
// first try to parse OK to capture possibel bugs
info();
Properties save = new Properties();
save.putAll(this.data);
List<String> sorted = new ArrayList<>((Set) save.keySet());
Collections.sort(sorted);
for (String s : save.stringPropertyNames()) {
data = new Properties();
data.putAll(save);
data.remove(s);
try {
info();
Assert.fail("Pasrer must reject component without key " + s);
} catch (MetadataException ex) {
// OK
}
}
}
Aggregations