use of com.eclipsesource.json.JsonValue in project kontraktor by RuedigerMoeller.
the class JSXIntrinsicTranspiler method processJSX.
protected byte[] processJSX(boolean dev, File f, FileResolver resolver, Map<String, Object> alreadyResolved) {
try {
boolean isInitialIndexJSX = "index.jsx".equals(f.getName());
if (isInitialIndexJSX) {
jnpmConfigFileCached = null;
if (dev) {
readFiles = new ArrayList<>();
nodeTopLevelImports = new HashMap<>();
if (watcher != null) {
// watcher.stopWatching(); is now singleton
watcher = null;
}
}
}
NodeLibNameResolver nodeLibNameResolver = createNodeLibNameResolver(resolver);
JSXGenerator.ParseResult result = JSXGenerator.process(f, dev, nodeLibNameResolver, getConfig());
if (dev) {
if (isNotInNodeModules(f)) {
String finalLibName = nodeLibNameResolver.getFinalLibName(f, resolver, f.getName());
readFiles.add(new WatchedFile(f, this, resolver, finalLibName));
}
}
List<ImportSpec> specs = result.getImports();
byte[] res = result.getFiledata();
if (isInitialIndexJSX) {
alreadyResolved.put("JSXIndexStart", System.currentTimeMillis());
ByteArrayOutputStream baos = new ByteArrayOutputStream(1_000_000);
baos.write((getInitialShims() + "\n").getBytes("UTF-8"));
alreadyResolved.put("JSXIndex", baos);
}
ByteArrayOutputStream indexBaos = (ByteArrayOutputStream) alreadyResolved.get("JSXIndex");
if (alreadyResolved.get("_Ignored") == null) {
alreadyResolved.put("_Ignored", result.getIgnoredRequires());
}
Set ignoredRequires = (Set) alreadyResolved.get("_Ignored");
ignoredRequires.addAll(result.getIgnoredRequires());
for (int i = 0; i < specs.size(); i++) {
ImportSpec importSpec = specs.get(i);
File redirected = resolveImportSpec(f, importSpec, resolver, alreadyResolved, ignoredRequires);
if (redirected == null)
continue;
}
ByteArrayOutputStream mainBao = dev ? new ByteArrayOutputStream(20_000) : indexBaos;
if (result.generateESWrap())
mainBao.write(generateImportPrologue(result, resolver).getBytes("UTF-8"));
if (result.generateCommonJSWrap())
mainBao.write(generateCommonJSPrologue(f, result, resolver).getBytes("UTF-8"));
mainBao.write(res);
if (result.generateESWrap())
mainBao.write(generateImportEnd(result, resolver).getBytes("UTF-8"));
if (result.generateCommonJSWrap())
mainBao.write(generateCommonJSEnd(f, result, resolver).getBytes("UTF-8"));
if (dev) {
String dirName = "_node_modules";
if (isNotInNodeModules(f)) {
dirName = "_appsrc";
}
String name = constructLibName(f, resolver) + ".transpiled";
resolver.install("/" + dirName + "/" + name, mainBao.toByteArray());
indexBaos.write(("document.write( '<script src=\"" + dirName + "/" + name + "\"></script>');\n").getBytes("UTF-8"));
}
if (isInitialIndexJSX) {
if (dev) {
indexBaos.write("document.write('<script>_kreporterr = true; kinitfuns.forEach( fun => fun() );</script>')\n".getBytes("UTF-8"));
watcher = FileWatcher.get();
watcher.setFiles(readFiles);
if (dev && getConfig().isGeneratePackageDotJson()) {
System.out.println("============================= TOP LEVEL IMPORTS ======================================");
nodeTopLevelImports.forEach((s, fi) -> {
try {
JsonValue packjson = Json.parse(new FileReader(new File(fi, "package.json")));
String version = packjson.asObject().getString("version", "*");
System.out.println("\"" + s + "\":" + "\"" + version + "\",");
} catch (IOException e) {
e.printStackTrace();
}
});
}
} else
indexBaos.write("_kreporterr = true; kinitfuns.forEach( fun => fun() );\n".getBytes("UTF-8"));
Long tim = (Long) alreadyResolved.get("JSXIndexStart");
Log.Info(this, "Transpilation time:" + (System.currentTimeMillis() - tim) / 1000.0);
return indexBaos.toByteArray();
}
return mainBao.toByteArray();
} catch (Exception e) {
Log.Error(this, e);
StringWriter out = new StringWriter();
e.printStackTrace(new PrintWriter(out));
try {
return out.getBuffer().toString().getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
}
return new byte[0];
}
use of com.eclipsesource.json.JsonValue in project SpongeVanilla by SpongePowered.
the class VanillaServerMain method downloadMinecraft.
private static boolean downloadMinecraft(Path base, boolean autoDownload) throws IOException, NoSuchAlgorithmException {
// Make sure the Minecraft server is available, or download it otherwise
Path path = base.resolve(MINECRAFT_SERVER_LOCAL);
if (Files.notExists(path)) {
if (!autoDownload) {
return false;
}
System.out.println("Downloading the versions manifest...");
// Download the file with all of the Minecraft versions information
JsonValue versions = downloadJson(MINECRAFT_MANIFEST_REMOTE);
String versionManifestRemote = null;
// Find the current version manifest URL
for (JsonValue versionInfo : versions.asObject().get("versions").asArray()) {
JsonObject obj = versionInfo.asObject();
String versionId = obj.get("id").asString();
if (versionId.equals(MINECRAFT_SERVER_VERSION)) {
versionManifestRemote = obj.get("url").asString();
break;
}
}
if (versionManifestRemote == null) {
throw new NoSuchElementException("Could not find " + MINECRAFT_SERVER_VERSION + "'s manifest URL");
}
JsonValue versionManifest = downloadJson(versionManifestRemote);
JsonObject serverObj = versionManifest.asObject().get("downloads").asObject().get("server").asObject();
// Find the server URL and SHA-1 digest
String serverRemote = serverObj.get("url").asString();
String sha1 = serverObj.get("sha1").asString();
downloadAndVerify(serverRemote, path, sha1);
}
path = base.resolve(LAUNCHWRAPPER_LOCAL);
if (!Files.exists(path)) {
if (!autoDownload) {
return false;
}
// Make sure Launchwrapper is available, or download it otherwise
downloadAndVerify(LAUNCHWRAPPER_REMOTE, path, LAUNCHWRAPPER_SHA1);
}
return true;
}
use of com.eclipsesource.json.JsonValue in project abstools by abstools.
the class AbstractModelApiTest method getValueFromResponse.
protected JsonValue getValueFromResponse(String response) {
JsonValue value = Json.parse(response);
JsonObject valueObject = value.asObject();
JsonValue result = valueObject.get("result");
return result;
}
use of com.eclipsesource.json.JsonValue in project abstools by abstools.
the class ErlangModelApiTests method test_floatByURL.
@Test
public void test_floatByURL() throws IOException {
String response = sendGetRequest("/call/test/test_float?p=5.1", 200);
JsonValue result = getValueFromResponse(response);
float value = result.asFloat();
Assert.assertEquals(5.1f, value, 0);
}
use of com.eclipsesource.json.JsonValue in project abstools by abstools.
the class ErlangModelApiTests method test_stringMap.
@Test
public void test_stringMap() throws IOException {
JsonObject parameter = Json.object().add("p", Json.object().add("a", "lalala").add("b", "lololo").add("c", "lululu"));
String response = sendPostRequest("/call/test/test_map_string", parameter.toString(), 200);
JsonValue result = getValueFromResponse(response);
JsonObject object = result.asObject();
Assert.assertEquals("lalala", object.get("a").asString());
Assert.assertEquals("lololo", object.get("b").asString());
Assert.assertEquals("lululu", object.get("c").asString());
}
Aggregations