Skip to content

Commit 18af8ac

Browse files
author
Vasil Hristov
authored
Merge pull request #1432 from NativeScript/vmutafov/merge-patches-into-release
Merge patches from master into release
2 parents 35d0338 + 7004531 commit 18af8ac

File tree

18 files changed

+312
-24
lines changed

18 files changed

+312
-24
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
6.0.1
2+
==
3+
4+
## Bug Fixes
5+
6+
- [Arabic and Kurdish characters show as gibberish in console.log() (#1302)](https://github.com/NativeScript/android-runtime/issues/1302)
7+
- [IntentService extending fails at runtime when service is started (#1426)](https://github.com/NativeScript/android-runtime/issues/1426)
8+
- [SBG may fail when parsing big JS files (#1430)](https://github.com/NativeScript/android-runtime/issues/1430)
9+
- [Upgrade android gradle plugin to the latest 3.4.2 version (#1425)](https://github.com/NativeScript/android-runtime/issues/1425)
10+
11+
12+
113
6.0.0
214
==
315

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"gradle": {
1313
"version": "5.1.1",
14-
"android": "3.4.1"
14+
"android": "3.4.2"
1515
},
1616
"android_ndk_version": "19c"
1717
}

test-app/build-tools/android-metadata-generator/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ buildscript {
1717
}
1818

1919
dependencies {
20-
classpath 'com.android.tools.build:gradle:3.4.1'
20+
classpath 'com.android.tools.build:gradle:3.4.2'
2121
}
2222
}
2323

test-app/build-tools/static-binding-generator/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ dependencies {
1616
compile group: 'org.json', name: 'json', version: '20090211'
1717
compile 'commons-io:commons-io:2.5'
1818
compile 'com.google.code.gson:gson:2.8.5'
19-
testCompile 'com.google.code.gson:gson:2.8.5'
20-
testCompile 'junit:junit:4.+'
2119
compile 'com.google.googlejavaformat:google-java-format:1.6'
20+
21+
testCompile 'com.google.code.gson:gson:2.8.5'
22+
testCompile 'junit:junit:4.12'
23+
testCompile 'org.mockito:mockito-core:3.0.0'
2224
}
2325

2426
compileJava {

test-app/build-tools/static-binding-generator/src/main/java/org/nativescript/staticbindinggenerator/Main.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
import org.json.JSONArray;
55
import org.json.JSONException;
66
import org.json.JSONObject;
7+
import org.nativescript.staticbindinggenerator.nodejs.NodeJSProcess;
8+
import org.nativescript.staticbindinggenerator.nodejs.impl.NodeJSProcessImpl;
9+
import org.nativescript.staticbindinggenerator.system.environment.impl.EnvironmentVariablesReaderImpl;
10+
import org.nativescript.staticbindinggenerator.system.process.impl.ProcessExecutorImpl;
711

812
import java.io.File;
913
import java.io.IOException;
10-
import java.io.InterruptedIOException;
1114
import java.io.PrintWriter;
1215
import java.nio.charset.Charset;
1316
import java.nio.file.Paths;
@@ -121,25 +124,13 @@ private static void validateInput() throws IOException {
121124
* Run the javascript static analysis [js_parser] and generate an output file.
122125
* This output file should contain all the information needed to generate java counterparts to the traversed js classes.
123126
* */
124-
private static void runJsParser() throws IOException {
127+
private static void runJsParser() {
125128
String parserPath = Paths.get(System.getProperty("user.dir"), "jsparser", "js_parser.js").toString();
129+
NodeJSProcess nodeJSProcess = new NodeJSProcessImpl(new ProcessExecutorImpl(), new EnvironmentVariablesReaderImpl());
130+
int exitCode = nodeJSProcess.runScript(parserPath);
126131

127-
List<String> l = new ArrayList<String>();
128-
l.add("node");
129-
l.add(parserPath);
130-
131-
ProcessBuilder pb = new ProcessBuilder(l);
132-
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
133-
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
134-
Process p = pb.start();
135-
try {
136-
p.waitFor();
137-
} catch (InterruptedException e) {
138-
e.printStackTrace();
139-
throw new InterruptedIOException("A problem occured while waiting for the jsparser to finish.");
140-
}
141-
if (p.exitValue() != 0) {
142-
System.exit(p.exitValue());
132+
if (exitCode != 0) {
133+
System.exit(exitCode);
143134
}
144135
}
145136

test-app/build-tools/static-binding-generator/src/main/java/org/nativescript/staticbindinggenerator/generating/writing/impl/MethodsWriterImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,12 @@ public void writeInternalServiceOnCreateMethod() {
389389
writer.write(INTERNAL_SERVICES_ONCREATE_METHOD_SIGNATURE);
390390
writer.write(OPENING_CURLY_BRACKET_LITERAL);
391391

392+
writer.write(SUPER_METHOD_CALL_PREFIX);
393+
writer.write(ON_CREATE_METHOD_NAME);
394+
writer.write(OPENING_ROUND_BRACKET_LITERAL);
395+
writer.write(CLOSING_ROUND_BRACKET_LITERAL);
396+
writer.write(END_OF_STATEMENT_LITERAL);
397+
392398
writeRuntimeInitializationForService();
393399

394400
writer.write(CLOSING_CURLY_BRACKET_LITERAL);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.nativescript.staticbindinggenerator.nodejs;
2+
3+
public interface NodeJSProcess {
4+
/**
5+
* Starts a Node process to execute a JS file
6+
*
7+
* @param scriptPath path to the JS file
8+
* @return returns the Node process' exit code
9+
*/
10+
int runScript(String scriptPath);
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.nativescript.staticbindinggenerator.nodejs.impl;
2+
3+
import org.nativescript.staticbindinggenerator.nodejs.NodeJSProcess;
4+
import org.nativescript.staticbindinggenerator.system.environment.EnvironmentVariablesReader;
5+
import org.nativescript.staticbindinggenerator.system.process.ProcessExecutor;
6+
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
public class NodeJSProcessImpl implements NodeJSProcess {
11+
12+
private static final String NODE_PROCESS_NAME = "node";
13+
private static final String NODE_OPTIONS_VARIABLE = "NODE_OPTIONS";
14+
private static final String MAX_OLD_SPACE_SIZE_PROPERTY_NAME = "max-old-space-size";
15+
private static final String MAX_OLD_SPACE_SIZE_PROPERTY_NAME_UNDERSCORED = "max_old_space_size";
16+
private static final String MAX_OLD_SPACE_SIZE_DEFAULT_PROPERTY = "--" + MAX_OLD_SPACE_SIZE_PROPERTY_NAME + "=8192";
17+
private static final String MAX_OLD_SPACE_SIZE_DEFAULT_PROPERTY_UNDERSCORED = "--" + MAX_OLD_SPACE_SIZE_PROPERTY_NAME_UNDERSCORED + "=8192";
18+
19+
private final ProcessExecutor processExecutor;
20+
private final EnvironmentVariablesReader environmentVariablesReader;
21+
22+
public NodeJSProcessImpl(ProcessExecutor processExecutor, EnvironmentVariablesReader environmentVariablesReader) {
23+
this.processExecutor = processExecutor;
24+
this.environmentVariablesReader = environmentVariablesReader;
25+
}
26+
27+
@Override
28+
public int runScript(String scriptPath) {
29+
List<String> parameters = createNodeJSParameters(scriptPath);
30+
return processExecutor.executeProcess(NODE_PROCESS_NAME, parameters);
31+
}
32+
33+
private List<String> createNodeJSParameters(String scriptPath) {
34+
List<String> parameters = new ArrayList<>();
35+
36+
if (!hasUserProvidedV8HeapSizeProperty()) {
37+
parameters.add(MAX_OLD_SPACE_SIZE_DEFAULT_PROPERTY);
38+
parameters.add(MAX_OLD_SPACE_SIZE_DEFAULT_PROPERTY_UNDERSCORED);
39+
}
40+
41+
parameters.add(scriptPath);
42+
43+
return parameters;
44+
}
45+
46+
private boolean hasUserProvidedV8HeapSizeProperty() {
47+
return environmentVariablesReader.readEnvironmentVariables()
48+
.entrySet()
49+
.stream()
50+
.anyMatch(x -> x.getKey().equals(NODE_OPTIONS_VARIABLE)
51+
&& (x.getValue().contains(MAX_OLD_SPACE_SIZE_PROPERTY_NAME)
52+
|| x.getValue().contains(MAX_OLD_SPACE_SIZE_PROPERTY_NAME_UNDERSCORED)));
53+
}
54+
55+
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.nativescript.staticbindinggenerator.system.environment;
2+
3+
import java.util.Map;
4+
5+
public interface EnvironmentVariablesReader {
6+
/**
7+
* Reads the current process' environment variables
8+
*
9+
* @return the environment variables as name=value collection
10+
*/
11+
Map<String, String> readEnvironmentVariables();
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.nativescript.staticbindinggenerator.system.environment.impl;
2+
3+
import org.nativescript.staticbindinggenerator.system.environment.EnvironmentVariablesReader;
4+
5+
import java.util.Map;
6+
7+
public class EnvironmentVariablesReaderImpl implements EnvironmentVariablesReader {
8+
9+
@Override
10+
public Map<String, String> readEnvironmentVariables() {
11+
return System.getenv();
12+
}
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.nativescript.staticbindinggenerator.system.process;
2+
3+
public class ProcessExecutionException extends RuntimeException {
4+
5+
private static final long serialVersionUID = 1L;
6+
7+
public ProcessExecutionException(String message) {
8+
super(message);
9+
}
10+
11+
public ProcessExecutionException(String message, Throwable origin) {
12+
super(message, origin);
13+
}
14+
15+
public ProcessExecutionException(Throwable origin) {
16+
super(origin);
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.nativescript.staticbindinggenerator.system.process;
2+
3+
import java.util.List;
4+
5+
public interface ProcessExecutor {
6+
7+
/**
8+
* Executes a process by a given name or path with specified arguments
9+
*
10+
* @param processNameOrPath process name or path
11+
* @param arguments arguments to pass to the process
12+
* @return status code of the executed process
13+
* @throws ProcessExecutionException if no process name/path given or InterruptedException/IOException occurs
14+
*/
15+
int executeProcess(String processNameOrPath, List<String> arguments);
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.nativescript.staticbindinggenerator.system.process.impl;
2+
3+
import com.google.common.base.Strings;
4+
5+
import org.nativescript.staticbindinggenerator.system.process.ProcessExecutionException;
6+
import org.nativescript.staticbindinggenerator.system.process.ProcessExecutor;
7+
8+
import java.io.IOException;
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
12+
public class ProcessExecutorImpl implements ProcessExecutor {
13+
14+
@Override
15+
public int executeProcess(String processNameOrPath, List<String> arguments) {
16+
if (Strings.isNullOrEmpty(processNameOrPath)) {
17+
throw new ProcessExecutionException("Missing process name!");
18+
}
19+
20+
List<String> processBuilderArguments = new ArrayList<>();
21+
processBuilderArguments.add(processNameOrPath);
22+
processBuilderArguments.addAll(arguments);
23+
24+
ProcessBuilder processBuilder = new ProcessBuilder(processBuilderArguments);
25+
processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
26+
processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
27+
28+
try {
29+
Process p = processBuilder.start();
30+
p.waitFor();
31+
return p.exitValue();
32+
} catch (InterruptedException | IOException e) {
33+
throw new ProcessExecutionException(e);
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package org.nativescript.staticbindinggenerator.nodejs.impl;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
import org.mockito.Mock;
6+
import org.nativescript.staticbindinggenerator.nodejs.NodeJSProcess;
7+
import org.nativescript.staticbindinggenerator.system.environment.EnvironmentVariablesReader;
8+
import org.nativescript.staticbindinggenerator.system.process.ProcessExecutor;
9+
10+
import java.util.ArrayList;
11+
import java.util.HashMap;
12+
import java.util.List;
13+
import java.util.Map;
14+
15+
import static org.junit.Assert.assertEquals;
16+
import static org.mockito.ArgumentMatchers.any;
17+
import static org.mockito.Mockito.verify;
18+
import static org.mockito.Mockito.when;
19+
import static org.mockito.MockitoAnnotations.initMocks;
20+
21+
public class NodeJSProcessImplTest {
22+
23+
private static final String NODE_PROCESS_NAME = "node";
24+
private static final String TEST_SCRIPT_FILE_PATH = "testFile.js";
25+
private static final String TEST_USER_PROVIDED_NODE_OPTIONS_UNDERSCORED = "--max_old_space_size=1234";
26+
private static final String TEST_USER_PROVIDED_NODE_OPTIONS = "--max-old-space-size=1234";
27+
private static final String DEFAULT_HEAP_SIZE_ARGUMENT_UNDERSCORED = "--max_old_space_size=8192";
28+
private static final String DEFAULT_HEAP_SIZE_ARGUMENT = "--max-old-space-size=8192";
29+
private static final int TEST_EXIT_CODE = 666;
30+
31+
@Mock
32+
private ProcessExecutor processExecutor;
33+
34+
@Mock
35+
private EnvironmentVariablesReader environmentVariablesReader;
36+
37+
private NodeJSProcess nodeJSProcess;
38+
39+
@Before
40+
public void setUp() {
41+
initMocks(this);
42+
nodeJSProcess = new NodeJSProcessImpl(processExecutor, environmentVariablesReader);
43+
}
44+
45+
@Test
46+
public void testProcessStartedWithoutDefaultHeapSizeIfUserProvidedNodeOptions() {
47+
when(environmentVariablesReader.readEnvironmentVariables()).thenReturn(createTestNodeOptionsEnvironmentVariable(TEST_USER_PROVIDED_NODE_OPTIONS));
48+
List<String> expectedProcessArguments = new ArrayList<>();
49+
expectedProcessArguments.add(TEST_SCRIPT_FILE_PATH);
50+
51+
nodeJSProcess.runScript(TEST_SCRIPT_FILE_PATH);
52+
53+
verify(environmentVariablesReader).readEnvironmentVariables();
54+
verify(processExecutor).executeProcess(NODE_PROCESS_NAME, expectedProcessArguments);
55+
}
56+
57+
@Test
58+
public void testProcessStartedWithoutDefaultHeapSizeIfUserProvidedUnderscoredNodeOptions() {
59+
when(environmentVariablesReader.readEnvironmentVariables()).thenReturn(createTestNodeOptionsEnvironmentVariable(TEST_USER_PROVIDED_NODE_OPTIONS_UNDERSCORED));
60+
List<String> expectedProcessArguments = new ArrayList<>();
61+
expectedProcessArguments.add(TEST_SCRIPT_FILE_PATH);
62+
63+
nodeJSProcess.runScript(TEST_SCRIPT_FILE_PATH);
64+
65+
verify(environmentVariablesReader).readEnvironmentVariables();
66+
verify(processExecutor).executeProcess(NODE_PROCESS_NAME, expectedProcessArguments);
67+
}
68+
69+
private Map<String, String> createTestNodeOptionsEnvironmentVariable(String nodeOptionsValue) {
70+
Map<String, String> mockedEnvironment = new HashMap<>();
71+
mockedEnvironment.put("NODE_OPTIONS", nodeOptionsValue);
72+
return mockedEnvironment;
73+
}
74+
75+
@Test
76+
public void testProcessStartedWithDefaultHeapSizeIfUserDidNotProvideNodeOptions() {
77+
when(environmentVariablesReader.readEnvironmentVariables()).thenReturn(new HashMap<>());
78+
List<String> expectedProcessArguments = new ArrayList<>();
79+
expectedProcessArguments.add(DEFAULT_HEAP_SIZE_ARGUMENT);
80+
expectedProcessArguments.add(DEFAULT_HEAP_SIZE_ARGUMENT_UNDERSCORED);
81+
expectedProcessArguments.add(TEST_SCRIPT_FILE_PATH);
82+
83+
nodeJSProcess.runScript(TEST_SCRIPT_FILE_PATH);
84+
85+
verify(environmentVariablesReader).readEnvironmentVariables();
86+
verify(processExecutor).executeProcess(NODE_PROCESS_NAME, expectedProcessArguments);
87+
}
88+
89+
@Test
90+
public void testProcessExitsWithCodeFromProcessExecutor() {
91+
when(processExecutor.executeProcess(any(), any())).thenReturn(TEST_EXIT_CODE);
92+
93+
int actualExitCode = nodeJSProcess.runScript(TEST_SCRIPT_FILE_PATH);
94+
95+
assertEquals("Unexpected status code returned", TEST_EXIT_CODE, actualExitCode);
96+
}
97+
98+
99+
}

test-app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.4.1'
10+
classpath 'com.android.tools.build:gradle:3.4.2'
1111
}
1212
}
1313

0 commit comments

Comments
 (0)