use of org.graalvm.component.installer.IncompatibleException in project graal by oracle.
the class GraalChannel method loadReleasesIndex.
/**
* Loads the release index. Must be loaded from a local file.
*
* @param releasesIndexPath path to the downloaded releases index.
* @return list of entries in the index
* @throws IOException in case of I/O error.
*/
List<ReleaseEntry> loadReleasesIndex(Path releasesIndexPath) throws IOException {
if (edition == null) {
edition = localRegistry.getGraalCapabilities().get(CommonConstants.CAP_EDITION);
}
List<ReleaseEntry> result = new ArrayList<>();
try (Reader urlReader = new InputStreamReader(Files.newInputStream(releasesIndexPath))) {
JSONTokener tokener = new JSONTokener(urlReader);
JSONObject obj = new JSONObject(tokener);
JSONObject releases = obj.getJSONObject(KEY_RELEASES);
if (releases == null) {
// malformed releases file;
throw new IncompatibleException(fb.l10n("OLDS_InvalidReleasesFile"));
}
Version v = localRegistry.getGraalVersion();
for (String k : releases.keySet()) {
JSONObject jo = releases.getJSONObject(k);
ReleaseEntry e = null;
try {
e = jsonToRelease(k, jo);
} catch (JSONException | IllegalArgumentException ex) {
fb.error("OLDS_ErrorReadingRelease", ex, k, ex.getLocalizedMessage());
}
if (e == null) {
invalidReleases.add(k);
} else if (!localRegistry.getJavaVersion().equals(e.getJavaVersion())) {
LOG.log(Level.FINER, "Invalid Java: {0}", k);
} else if (e.getBasePackages().isEmpty()) {
LOG.log(Level.FINER, "No distribution packages: {0}", k);
} else if (edition != null && !edition.equals(e.getEdition())) {
LOG.log(Level.FINER, "Incorrect edition: {0}", k);
} else if (!acceptsVersion(v, e.getVersion())) {
LOG.log(Level.FINER, "Old version: {0}", k);
} else {
result.add(e);
}
}
}
return result;
}
use of org.graalvm.component.installer.IncompatibleException in project graal by oracle.
the class GDSChannel method loadArtifacts.
/**
* Loads the release index. Must be loaded from a local file.
*
* @param releasesIndexPath path to the downloaded releases index.
* @return list of entries in the index
* @throws IOException in case of I/O error.
*/
List<ComponentInfo> loadArtifacts(Path releasesIndexPath) throws IOException {
if (edition == null) {
edition = localRegistry.getGraalCapabilities().get(CommonConstants.CAP_EDITION);
}
List<ComponentInfo> result = new ArrayList<>();
try (InputStreamReader urlReader = new InputStreamReader(new GZIPInputStream(Files.newInputStream(releasesIndexPath)))) {
JSONTokener tokener = new JSONTokener(urlReader);
JSONObject obj = new JSONObject(tokener);
JSONArray releases = obj.getJSONArray(JSON_ITEMS);
if (releases == null) {
// malformed releases file;
throw new IncompatibleException(fb.l10n("OLDS_InvalidReleasesFile"));
}
Version v = localRegistry.getGraalVersion();
for (Object k : releases) {
JSONObject jo = (JSONObject) k;
ArtifactParser e;
try {
e = new ArtifactParser(jo);
} catch (JSONException | IllegalArgumentException ex) {
fb.error("OLDS_ErrorReadingRelease", ex, k, ex.getLocalizedMessage());
continue;
}
if (!OS.get().equals(OS.fromName(e.getOs()))) {
LOG.log(Level.FINER, "Incorrect OS: {0}", k);
} else if (!ARCH.get().equals(ARCH.fromName(e.getArch()))) {
LOG.log(Level.FINER, "Incorrect Arch: {0}", k);
} else if (!localRegistry.getJavaVersion().equals(e.getJava())) {
LOG.log(Level.FINER, "Incorrect Java: {0}", k);
} else if (edition != null && !edition.equals(e.getEdition())) {
LOG.log(Level.FINER, "Incorrect edition: {0}", k);
} else if (!acceptsVersion(v, Version.fromString(e.getVersion()))) {
LOG.log(Level.FINER, "Old version: {0} != {1}", new Object[] { v, Version.fromString(e.getVersion()), e.getVersion() });
} else {
result.add(e.asComponentInfo(gdsConnector, fb));
}
}
}
return result;
}
use of org.graalvm.component.installer.IncompatibleException in project graal by oracle.
the class GraalChannelTest method testThrowEmptyStorage.
@Test
public void testThrowEmptyStorage() throws Exception {
try {
channel.throwEmptyStorage();
fail("Exception expected");
} catch (IncompatibleException ex) {
// ok
}
ComponentStorage chStorage = channel.throwEmptyStorage();
assertNotNull("Stub storage expected for 2nd time", chStorage);
assertEquals(0, chStorage.listComponentIDs().size());
assertEquals(0, chStorage.loadComponentMetadata("org.graalvm").size());
assertEquals(0, chStorage.loadGraalVersionInfo().size());
}
use of org.graalvm.component.installer.IncompatibleException in project graal by oracle.
the class WebCatalog method getStorage.
@Override
public ComponentStorage getStorage() {
if (this.storage != null) {
return this.storage;
}
Map<String, String> graalCaps = local.getGraalCapabilities();
StringBuilder sb = new StringBuilder();
sb.append(SystemUtils.patternOsName(graalCaps.get(CommonConstants.CAP_OS_NAME)).toLowerCase());
sb.append("_");
sb.append(SystemUtils.patternOsArch(graalCaps.get(CommonConstants.CAP_OS_ARCH).toLowerCase()));
try {
catalogURL = new URL(urlString);
} catch (MalformedURLException ex) {
throw feedback.failure("REMOTE_InvalidURL", ex, catalogURL, ex.getLocalizedMessage());
}
Properties props = new Properties();
// create the storage. If the init fails, but process will not terminate, the storage will
// serve no components on the next call.
RemotePropertiesStorage newStorage = createPropertiesStorage(feedback, local, props, sb.toString(), catalogURL);
if (remoteProcessor != null) {
newStorage.setRemoteProcessor(remoteProcessor);
}
Properties loadProps = new Properties();
FileDownloader dn;
try {
// avoid duplicate (failed) downloads
if (savedException != null) {
throw savedException;
}
catalogURL = new URL(urlString);
String l = source.getLabel();
dn = new FileDownloader(feedback.l10n(l == null || l.isEmpty() ? "REMOTE_CatalogLabel2" : "REMOTE_CatalogLabel", l), catalogURL, feedback);
dn.download();
} catch (NoRouteToHostException | ConnectException ex) {
throw savedException = feedback.failure("REMOTE_ErrorDownloadCatalogProxy", ex, catalogURL, ex.getLocalizedMessage());
} catch (FileNotFoundException ex) {
// treat missing resources as non-fatal errors, print warning
feedback.error("REMOTE_WarningErrorDownloadCatalogNotFoundSkip", ex, catalogURL);
this.storage = newStorage;
return storage;
} catch (IOException ex) {
throw savedException = feedback.failure("REMOTE_ErrorDownloadCatalog", ex, catalogURL, ex.getLocalizedMessage());
}
// download is successful; if the processing fails after download, next call will report an
// empty catalog.
this.storage = newStorage;
StringBuilder oldGraalPref = new StringBuilder("^" + BundleConstants.GRAAL_COMPONENT_ID);
oldGraalPref.append('.');
String graalVersionString;
Version normalizedVersion;
if (matchVersion != null) {
graalVersionString = matchVersion.getVersion().displayString();
normalizedVersion = matchVersion.getVersion().installVersion();
} else {
// read from the release file
graalVersionString = graalCaps.get(CommonConstants.CAP_GRAALVM_VERSION).toLowerCase();
normalizedVersion = local.getGraalVersion().installVersion();
}
StringBuilder graalPref = new StringBuilder(oldGraalPref);
oldGraalPref.append(Pattern.quote(graalVersionString));
oldGraalPref.append('_').append(sb);
graalPref.append(sb).append('/');
// NOI18N
graalPref.append("(?<ver>[^/]+)$");
try (FileInputStream fis = new FileInputStream(dn.getLocalFile())) {
loadProps.load(fis);
} catch (IllegalArgumentException | IOException ex) {
throw feedback.failure("REMOTE_CorruptedCatalogFile", ex, catalogURL);
}
Pattern oldPrefixPattern = Pattern.compile(oldGraalPref.toString(), Pattern.CASE_INSENSITIVE);
Pattern newPrefixPattern = Pattern.compile(graalPref.toString(), Pattern.CASE_INSENSITIVE);
Stream<String> propNames = loadProps.stringPropertyNames().stream();
boolean foundPrefix = propNames.anyMatch(p -> {
if (oldPrefixPattern.matcher(p).matches()) {
return true;
}
Matcher m = newPrefixPattern.matcher(p);
if (!m.find() || m.start() > 0) {
return false;
}
try {
// NOI18N
Version v = Version.fromString(m.group("ver"));
return normalizedVersion.match(Version.Match.Type.INSTALLABLE).test(v);
} catch (IllegalArgumentException ex) {
return false;
}
});
if (!foundPrefix) {
boolean graalPrefixFound = false;
boolean componentFound = false;
for (String s : loadProps.stringPropertyNames()) {
if (s.startsWith(BundleConstants.GRAAL_COMPONENT_ID)) {
graalPrefixFound = true;
}
if (s.startsWith("Component.")) {
componentFound = true;
}
}
if (!componentFound) {
// no graal prefix, no components
feedback.verboseOutput("REMOTE_CatalogDoesNotContainComponents", catalogURL);
return newStorage;
} else if (!graalPrefixFound) {
// strange thing, no graal declaration, but components are there ?
throw feedback.failure("REMOTE_CorruptedCatalogFile", null, catalogURL);
} else {
throw new IncompatibleException(feedback.l10n("REMOTE_UnsupportedGraalVersion", graalCaps.get(CommonConstants.CAP_GRAALVM_VERSION), graalCaps.get(CommonConstants.CAP_OS_NAME), graalCaps.get(CommonConstants.CAP_OS_ARCH)), null);
}
}
props.putAll(loadProps);
return newStorage;
}
use of org.graalvm.component.installer.IncompatibleException in project graal by oracle.
the class MergeStorage method listComponentIDs.
@Override
public Set<String> listComponentIDs() throws IOException {
Set<String> ids = new HashSet<>();
List<Exception> savedEx = new ArrayList<>();
List<SoftwareChannel> errChannels = new ArrayList<>();
boolean oneSucceeded = false;
Exception toThrow = null;
for (SoftwareChannel del : new ArrayList<>(channels)) {
try {
ids.addAll(del.getStorage().listComponentIDs());
oneSucceeded = true;
} catch (IncompatibleException ex) {
savedEx.add(ex);
errChannels.add(del);
channels.remove(del);
} catch (IOException | FailedOperationException ex) {
if (!isIgnoreCatalogErrors()) {
throw ex;
}
if (!idsLoaded) {
reportError(ex, del);
}
toThrow = ex;
channels.remove(del);
}
}
if (!oneSucceeded || ids.isEmpty()) {
for (int i = 0; i < savedEx.size(); i++) {
reportError(toThrow = savedEx.get(i), errChannels.get(i));
}
if (toThrow instanceof IOException) {
throw (IOException) toThrow;
} else if (toThrow != null) {
throw (InstallerStopException) toThrow;
}
}
idsLoaded = true;
return ids;
}
Aggregations