Skip to content

Inspector improvements #1252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ def DIST_FRAMEWORK_PATH = "$DIST_PATH/framework"

task checkEnvironmentVariables {
if ("$System.env.JAVA_HOME" == "" || "$System.env.JAVA_HOME" == "null") {
throw new GradleException("Set JAVA_HOME to point to the correct Jdk location\n");
throw new GradleException("Set JAVA_HOME to point to the correct Jdk location\n")
}

if ("$System.env.ANDROID_HOME" == "" || "$System.env.ANDROID_HOME" == "null") {
throw new GradleException("Set ANDROID_HOME to point to the correct Android SDK location\n");
throw new GradleException("Set ANDROID_HOME to point to the correct Android SDK location\n")
}

if ("$System.env.GIT_COMMIT" == "null" && !project.hasProperty("gitCommitVersion")) {
logger.warn("Warning: The GIT_COMMIT is not set. This NativeScript Android Runtime will not be tagged with the git commit it is build from\n");
logger.warn("Warning: The GIT_COMMIT is not set. This NativeScript Android Runtime will not be tagged with the git commit it is build from\n")
}

if (project.hasProperty("metadataGen") && !file("../android-metadata-generator/dist/tns-android-metadata-generator-0.0.1.tgz").exists()) {
throw new GradleException("android-metadata-generator build output not found and no metadataGen option specified. Build android-metadata-generator first.\n");
throw new GradleException("android-metadata-generator build output not found and no metadataGen option specified. Build android-metadata-generator first.\n")
}
}

Expand Down Expand Up @@ -305,7 +305,7 @@ task setPackageVersionInPackageJsonFile {
def inputFile = new File("$DIST_PATH/package.json")
def json = new JsonSlurper().parseText(inputFile.text)
json.version = pVersion
def jb = new JsonBuilder(json);
def jb = new JsonBuilder(json)
inputFile.text = JsonOutput.prettyPrint(jb.toString())
}
}
Expand Down Expand Up @@ -396,7 +396,7 @@ def getRunTestsBuildArguments = { taskName ->
arguments.add("-PuseCCache")
}
arguments += ["--warning-mode", "all"]
return arguments;
return arguments
}

task runTests (type: Exec) {
Expand Down
28 changes: 14 additions & 14 deletions test-app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -145,30 +145,30 @@ def applyPluginGradleConfigurations = { ->
}

def getAppIdentifier = { packageJsonMap ->
def appIdentifier = "";
def appIdentifier = ""
if (packageJsonMap && packageJsonMap.nativescript) {
appIdentifier = packageJsonMap.nativescript.id;
appIdentifier = packageJsonMap.nativescript.id
if (!(appIdentifier instanceof String)) {
appIdentifier = appIdentifier.android;
appIdentifier = appIdentifier.android
}
}

return appIdentifier;
return appIdentifier
}

def setAppIdentifier = { ->
println "\t + setting applicationId";
File packageJsonFile = new File("$rootDir/../../package.json");
println "\t + setting applicationId"
File packageJsonFile = new File("$rootDir/../../package.json")

if (packageJsonFile.exists()) {
def content = packageJsonFile.getText("UTF-8");
def jsonSlurper = new JsonSlurper();
def packageJsonMap = jsonSlurper.parseText(content);
def appIdentifier = getAppIdentifier(packageJsonMap);
def content = packageJsonFile.getText("UTF-8")
def jsonSlurper = new JsonSlurper()
def packageJsonMap = jsonSlurper.parseText(content)
def appIdentifier = getAppIdentifier(packageJsonMap)

if (appIdentifier) {
project.ext.nsApplicationIdentifier = appIdentifier;
android.defaultConfig.applicationId = appIdentifier;
project.ext.nsApplicationIdentifier = appIdentifier
android.defaultConfig.applicationId = appIdentifier
}
}
}
Expand Down Expand Up @@ -413,7 +413,7 @@ task runSbg(type: JavaExec) {
args "static-binding-generator.jar"

doFirst {
new File("$OUTPUT_JAVA_DIR/com/tns/gen").deleteDir();
new File("$OUTPUT_JAVA_DIR/com/tns/gen").deleteDir()
}
}

Expand Down Expand Up @@ -668,7 +668,7 @@ task validateAppIdMatch {
"NativeScript CLI might not work properly.$lineSeparator" +
"Remove applicationId from app.gradle and update the \"nativescript.id\" in package.json.$lineSeparator" +
"Actual: ${android.defaultConfig.applicationId}$lineSeparator" +
"Expected(from \"package.json\"): ${project.nsApplicationIdentifier}$lineSeparator";
"Expected(from \"package.json\"): ${project.nsApplicationIdentifier}$lineSeparator"

logger.error(errorMessage)
}
Expand Down
15 changes: 14 additions & 1 deletion test-app/app/src/main/java/com/tns/AndroidJsV8Inspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ private class JsV8InspectorServer extends NanoWSD {
super(name);
}

private JsV8InspectorWebSocket webSocket;

@Override
protected Response serveHttp(IHTTPSession session) {
if (DEBUG_LOG_ENABLED) {
Expand All @@ -228,7 +230,18 @@ protected Response serveHttp(IHTTPSession session) {

@Override
protected WebSocket openWebSocket(IHTTPSession handshake) {
return new JsV8InspectorWebSocket(handshake);
// close the previous webSocket
if(this.webSocket != null) {
try {
this.webSocket.close(WebSocketFrame.CloseCode.NormalClosure, "New browser connection is open", false);
} catch (IOException ioException) {
if(this.webSocket.getState() != State.CLOSED) {
Log.e("{N}.v8-inspector", "Error closing previous connection", ioException);
}
}
}
this.webSocket = new JsV8InspectorWebSocket(handshake);
return this.webSocket;
}
}

Expand Down
6 changes: 3 additions & 3 deletions test-app/runtests.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')
def runOnDevice = project.hasProperty("runOnDevice");
def runOnDeviceOrEmulator = runOnDevice ? "-d" : "-e";
def runOnDevice = project.hasProperty("runOnDevice")
def runOnDeviceOrEmulator = runOnDevice ? "-d" : "-e"

def onlyX86 = project.hasProperty("onlyX86")
def useCCache = project.hasProperty("useCCache")
Expand Down Expand Up @@ -37,7 +37,7 @@ def getBuildArguments = { ->
if (useCCache) {
arguments.push("-PuseCCache")
}
return arguments;
return arguments
}

task installApk(type: Exec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ JNIEXPORT extern "C" void Java_com_tns_AndroidJsV8Inspector_init(JNIEnv* env, jo
}

JNIEXPORT extern "C" void Java_com_tns_AndroidJsV8Inspector_connect(JNIEnv* env, jobject instance, jobject connection) {
JsV8InspectorClient::GetInstance()->disconnect();
JsV8InspectorClient::GetInstance()->connect(connection);
}

Expand Down
2 changes: 2 additions & 0 deletions test-app/runtime/src/main/java/fi/iki/elonen/NanoWSD.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public boolean isOpen() {
return state == State.OPEN;
}

public State getState() { return this.state; }

protected abstract void onOpen();

protected abstract void onClose(CloseCode code, String reason, boolean initiatedByRemote);
Expand Down