use of com.oracle.truffle.tools.utils.json.JSONTokener 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 com.oracle.truffle.tools.utils.json.JSONTokener 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 com.oracle.truffle.tools.utils.json.JSONTokener in project graal by oracle.
the class GraalChannelTest method testReleaseInvalidCatalog.
@Test
public void testReleaseInvalidCatalog() throws Exception {
Path p = dataFile("data/rel-invalid-catalog.json");
try (InputStream is = Files.newInputStream(p)) {
JSONObject o = new JSONObject(new JSONTokener(is));
ReleaseEntry e = channel.jsonToRelease("19.3.3-ee-jdk11", o);
assertNull(e);
}
}
use of com.oracle.truffle.tools.utils.json.JSONTokener in project graal by oracle.
the class GraalChannelTest method assertNoRelease.
private void assertNoRelease(String data) throws Exception {
Path p = dataFile(data);
try (InputStream is = Files.newInputStream(p)) {
JSONObject o = new JSONObject(new JSONTokener(is));
ReleaseEntry e = channel.jsonToRelease("19.3.3-ee-jdx11", o);
assertNull(e);
}
}
use of com.oracle.truffle.tools.utils.json.JSONTokener in project graal by oracle.
the class GraalChannelTest method testReleaseNoBases.
@Test
public void testReleaseNoBases() throws Exception {
Path p = dataFile("data/rel-no-bases.json");
try (InputStream is = Files.newInputStream(p)) {
JSONObject o = new JSONObject(new JSONTokener(is));
ReleaseEntry e = channel.jsonToRelease("19.3.3-ee-jdk11", o);
assertNull(e);
fail("JSONexception expected.");
} catch (JSONException ex) {
// OK
}
}
Aggregations