Search in sources :

Example 16 with JSONObject

use of com.oracle.truffle.tools.utils.json.JSONObject 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;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) JSONArray(com.oracle.truffle.tools.utils.json.JSONArray) JSONException(com.oracle.truffle.tools.utils.json.JSONException) GZIPInputStream(java.util.zip.GZIPInputStream) JSONTokener(com.oracle.truffle.tools.utils.json.JSONTokener) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) Version(org.graalvm.component.installer.Version) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) ComponentInfo(org.graalvm.component.installer.model.ComponentInfo) IncompatibleException(org.graalvm.component.installer.IncompatibleException)

Example 17 with JSONObject

use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.

the class GDSChannel method interceptDownloadException.

public IOException interceptDownloadException(IOException downloadException, FileDownloader fileDownloader) {
    if (downloadException instanceof HttpConnectionException) {
        HttpConnectionException hex = (HttpConnectionException) downloadException;
        if (hex.getRetCode() < HttpURLConnection.HTTP_BAD_REQUEST) {
            return (IOException) hex.getCause();
        }
        String downloadURL = hex.getConnectionUrl().toString();
        if (!downloadURL.endsWith(EXC_URL_END)) {
            return (IOException) hex.getCause();
        }
        String licensePath = findLicensePath(downloadURL);
        if (!nonBlankString(licensePath)) {
            return (IOException) hex.getCause();
        }
        String code;
        try {
            code = new JSONObject(hex.getResponse()).getString(JSON_EXC_CODE);
        } catch (JSONException ex) {
            return (IOException) hex.getCause();
        }
        String token = getToken(licensePath);
        switch(code) {
            case EXC_CODE_INVALID_TOKEN:
                fb.output("ERR_InvalidToken", hex, token);
                token = getToken(licensePath, true);
                break;
            case EXC_CODE_UNACCEPTED:
                Map.Entry<String, String> downloadToken = initTokenStorage().getToken();
                if (fileDownloader.getAttemptNr() == 1) {
                    token = gdsConnector.sendVerificationEmail(downloadToken.getKey(), licensePath, downloadToken.getValue());
                } else {
                    token = downloadToken.getValue();
                }
                if (nonBlankString(token)) {
                    fb.output("PROMPT_VerifyEmailAddressEntry", downloadToken.getKey());
                    fb.acceptLine(false);
                }
                break;
            default:
                return (IOException) hex.getCause();
        }
        fileDownloader.addRequestHeader(HEADER_DOWNLOAD_TOKEN, token);
    } else {
        return downloadException;
    }
    return null;
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) JSONException(com.oracle.truffle.tools.utils.json.JSONException) IOException(java.io.IOException) Map(java.util.Map) HttpConnectionException(org.graalvm.component.installer.remote.ProxyConnectionFactory.HttpConnectionException)

Example 18 with JSONObject

use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.

the class Breakpoint method create.

public static Breakpoint create(Boolean verified) {
    final JSONObject json = new JSONObject();
    json.put("verified", verified);
    return new Breakpoint(json);
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject)

Example 19 with JSONObject

use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.

the class BreakpointLocationsResponse method create.

public static BreakpointLocationsResponse create(ResponseBody body, Integer requestSeq, Boolean success, String command, Integer seq) {
    final JSONObject json = new JSONObject();
    json.put("body", body.jsonData);
    json.put("type", "response");
    json.put("request_seq", requestSeq);
    json.put("success", success);
    json.put("command", command);
    json.put("seq", seq);
    return new BreakpointLocationsResponse(json);
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject)

Example 20 with JSONObject

use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.

the class CapabilitiesEvent method create.

public static CapabilitiesEvent create(EventBody body, Integer seq) {
    final JSONObject json = new JSONObject();
    json.put("event", "capabilities");
    json.put("body", body.jsonData);
    json.put("type", "event");
    json.put("seq", seq);
    return new CapabilitiesEvent(json);
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject)

Aggregations

JSONObject (com.oracle.truffle.tools.utils.json.JSONObject)318 JSONArray (com.oracle.truffle.tools.utils.json.JSONArray)71 ArrayList (java.util.ArrayList)20 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)18 DebugValue (com.oracle.truffle.api.debug.DebugValue)14 DebugException (com.oracle.truffle.api.debug.DebugException)11 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)10 SourceSection (com.oracle.truffle.api.source.SourceSection)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Collection (java.util.Collection)7 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)6 Source (com.oracle.truffle.api.source.Source)6 Map (java.util.Map)6 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)5 NoSuspendedThreadException (com.oracle.truffle.tools.chromeinspector.InspectorExecutionContext.NoSuspendedThreadException)5 RemoteObject (com.oracle.truffle.tools.chromeinspector.types.RemoteObject)5 JSONTokener (com.oracle.truffle.tools.utils.json.JSONTokener)5 Test (org.junit.Test)5 Location (com.oracle.truffle.tools.chromeinspector.types.Location)4