Skip to content

Commit

Permalink
replace JSON library from org.json to com.google.code.gson.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmi committed Jan 31, 2016
1 parent 7837a97 commit 641ab94
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 35 deletions.
4 changes: 4 additions & 0 deletions RELEASENOTE.md
@@ -1,6 +1,10 @@
Selenese Runner Java Relase Note
================================

### 2.4.0

* Replace JSON library from org.json to com.google.code.gson.

### 2.3.1

* Fix problem with path relativize double URI escaping items like spaces. (PR #183 by stevenebutler)
Expand Down
9 changes: 4 additions & 5 deletions pom.xml
Expand Up @@ -524,11 +524,10 @@ It supports test-case and test-suite which are Selenium IDE's native format.</de
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20080701</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency><dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/jp/vmi/selenium/rollup/RollupRule.java
Expand Up @@ -8,8 +8,8 @@
import javax.script.ScriptException;

import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;

import com.google.gson.Gson;
import com.thoughtworks.selenium.SeleniumException;

import jp.vmi.script.JSList;
Expand Down Expand Up @@ -49,7 +49,7 @@ public CommandList getExpandedCommands(Context context, Map<String, String> roll
bindings.put("rule", ((JSMap<?, ?>) rule).unwrap());
else
bindings.put("rule", rule);
String args = new JSONObject(rollupArgs).toString();
String args = new Gson().toJson(rollupArgs);
try {
commands = JSList.toList(engine, engine.eval("rule.getExpandedCommands(" + args + ")", bindings));
} catch (ScriptException e) {
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/jp/vmi/selenium/selenese/Eval.java
Expand Up @@ -3,12 +3,10 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.io.output.StringBuilderWriter;
import org.json.JSONException;
import org.json.JSONObject;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;

import com.google.gson.Gson;
import com.thoughtworks.selenium.SeleniumException;

/**
Expand Down Expand Up @@ -51,21 +49,17 @@ public Object eval(WebDriver driver, String script) {
public Object eval(WebDriver driver, String script, String cast) {
VarsMap varsMap = context.getVarsMap();
boolean hasStoredVars = script.matches(".*\\bstoredVars\\b.*");
StringBuilderWriter writer = new StringBuilderWriter();
StringBuilder writer = new StringBuilder();
if (hasStoredVars) {
writer.append("return (function(){var storedVars = ");
try {
new JSONObject(varsMap).write(writer);
} catch (JSONException e) {
throw new RuntimeException(e);
}
new Gson().toJson(varsMap, writer);
writer.append(";\n");
}
writer.append("return [");
if (cast != null)
writer.append(cast);
writer.append("((function(){");
mutator.mutate(script, writer.getBuilder());
mutator.mutate(script, writer);
writer.append("})())");
if (hasStoredVars)
writer.append(", storedVars];})();");
Expand Down
24 changes: 6 additions & 18 deletions src/main/java/jp/vmi/selenium/webdriver/ChromeDriverFactory.java
Expand Up @@ -3,17 +3,17 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import org.json.JSONException;
import org.json.JSONObject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

import com.google.common.io.Files;
import com.google.gson.Gson;

import jp.vmi.selenium.selenese.utils.PathUtils;

Expand Down Expand Up @@ -48,22 +48,10 @@ public static void setDriverSpecificCapabilities(DesiredCapabilities caps, Drive
} catch (IOException e) {
throw new RuntimeException(e);
}
JSONObject jsonObject;
try {
jsonObject = new JSONObject(json);
} catch (JSONException e) {
throw new RuntimeException(e);
}
@SuppressWarnings("unchecked")
Iterator<String> keys = (Iterator<String>) jsonObject.keys();
while (keys.hasNext()) {
String key = keys.next();
try {
options.setExperimentalOption(key, jsonObject.get(key));
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
Map<String, Object> jsonObject = new Gson().fromJson(json, Map.class);
for (Entry<String, Object> entry : jsonObject.entrySet())
options.setExperimentalOption(entry.getKey(), entry.getValue());
}
caps.setCapability(ChromeOptions.CAPABILITY, options);
caps.merge(driverOptions.getCapabilities());
Expand Down

0 comments on commit 641ab94

Please sign in to comment.