diff --git a/build.gradle b/build.gradle index 4a75c7334..e707855f4 100644 --- a/build.gradle +++ b/build.gradle @@ -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") } } @@ -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()) } } @@ -396,7 +396,7 @@ def getRunTestsBuildArguments = { taskName -> arguments.add("-PuseCCache") } arguments += ["--warning-mode", "all"] - return arguments; + return arguments } task runTests (type: Exec) { diff --git a/test-app/app/build.gradle b/test-app/app/build.gradle index 2055a5aee..e1bd57679 100644 --- a/test-app/app/build.gradle +++ b/test-app/app/build.gradle @@ -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 } } } @@ -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() } } @@ -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) } diff --git a/test-app/app/src/main/java/com/tns/AndroidJsV8Inspector.java b/test-app/app/src/main/java/com/tns/AndroidJsV8Inspector.java index df9a1a891..f1120c74e 100644 --- a/test-app/app/src/main/java/com/tns/AndroidJsV8Inspector.java +++ b/test-app/app/src/main/java/com/tns/AndroidJsV8Inspector.java @@ -218,6 +218,8 @@ private class JsV8InspectorServer extends NanoWSD { super(name); } + private JsV8InspectorWebSocket webSocket; + @Override protected Response serveHttp(IHTTPSession session) { if (DEBUG_LOG_ENABLED) { @@ -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; } } diff --git a/test-app/runtests.gradle b/test-app/runtests.gradle index 096053de2..cddedd83e 100644 --- a/test-app/runtests.gradle +++ b/test-app/runtests.gradle @@ -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") @@ -37,7 +37,7 @@ def getBuildArguments = { -> if (useCCache) { arguments.push("-PuseCCache") } - return arguments; + return arguments } task installApk(type: Exec) { diff --git a/test-app/runtime/src/main/cpp/com_tns_AndroidJsV8Inspector.cpp b/test-app/runtime/src/main/cpp/com_tns_AndroidJsV8Inspector.cpp index c4944e9be..cdef52e62 100644 --- a/test-app/runtime/src/main/cpp/com_tns_AndroidJsV8Inspector.cpp +++ b/test-app/runtime/src/main/cpp/com_tns_AndroidJsV8Inspector.cpp @@ -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); } diff --git a/test-app/runtime/src/main/java/fi/iki/elonen/NanoWSD.java b/test-app/runtime/src/main/java/fi/iki/elonen/NanoWSD.java index ea57b1bf5..59404e72a 100644 --- a/test-app/runtime/src/main/java/fi/iki/elonen/NanoWSD.java +++ b/test-app/runtime/src/main/java/fi/iki/elonen/NanoWSD.java @@ -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);