Skip to content

Improve package.json parsing in SBG #1407

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 1 commit into from
Jun 26, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio
}

/*
* Method should traverse all js files from input folder and put the ones that need traversing in another file
* */
* Method should traverse all js files from input folder and put the ones that need traversing in another file
* */
private static void generateJsInputFile() throws IOException {
try {
traverseDirectory(inputDir, false/*traverse explicitly*/);
Expand All @@ -69,7 +69,7 @@ private static void generateJsInputFile() throws IOException {
pw.close();
}

private static boolean isSuppressCallJSMethodExceptionsEnabled() throws IOException{
private static boolean isSuppressCallJSMethodExceptionsEnabled() throws IOException {
File jsonFile = new File(inputDir, "package.json");
if (!jsonFile.exists()) {
return false;
Expand All @@ -79,9 +79,13 @@ private static boolean isSuppressCallJSMethodExceptionsEnabled() throws IOExcept
try {
pjson = new JSONObject(jsonContent);
if (pjson.has("android")) {
JSONObject androidSettings = (JSONObject) pjson.get("android");
if(androidSettings.has("suppressCallJSMethodExceptions") && androidSettings.get("suppressCallJSMethodExceptions").toString().equals("true")) {
return true;
Object androidJsonProperty = pjson.get("android");

if (androidJsonProperty instanceof JSONObject) {
JSONObject androidSettings = (JSONObject) androidJsonProperty;
if (androidSettings.has("suppressCallJSMethodExceptions") && androidSettings.get("suppressCallJSMethodExceptions").toString().equals("true")) {
return true;
}
}
}
} catch (JSONException e) {
Expand Down Expand Up @@ -116,7 +120,7 @@ private static void validateInput() throws IOException {
/*
* Run the javascript static analysis [js_parser] and generate an output file.
* This output file should contain all the information needed to generate java counterparts to the traversed js classes.
* */
* */
private static void runJsParser() throws IOException {
String parserPath = Paths.get(System.getProperty("user.dir"), "jsparser", "js_parser.js").toString();

Expand All @@ -134,7 +138,7 @@ private static void runJsParser() throws IOException {
e.printStackTrace();
throw new InterruptedIOException("A problem occured while waiting for the jsparser to finish.");
}
if(p.exitValue() != 0) {
if (p.exitValue() != 0) {
System.exit(p.exitValue());
}
}
Expand Down Expand Up @@ -167,10 +171,14 @@ private static void traverseDirectory(File currentDir, boolean traverseExplicitl
if (!pjson.has("nativescript")) {
return;
} else {
JSONObject nsValue = (JSONObject) pjson.get("nativescript");
if (nsValue.has("recursive-static-bindings")) {
System.out.println(String.format("Task: traverseDirectory: Folder will be traversed completely: %s", currentDir));
traverseExplicitly = true;
Object nativeScriptJsonProperty = pjson.get("nativescript");
if (nativeScriptJsonProperty instanceof JSONObject) {
JSONObject nsValue = (JSONObject) nativeScriptJsonProperty;
if (nsValue.has("recursive-static-bindings")) {
traverseExplicitly = true;
}
} else {
return;
}
}
}
Expand All @@ -192,8 +200,8 @@ private static void traverseDirectory(File currentDir, boolean traverseExplicitl
private static List<String> webpackWorkersExcludesList;

/*
* Should provide the webpack specific files that need to be excluded from the js analysis
* */
* Should provide the webpack specific files that need to be excluded from the js analysis
* */
private static void getWorkerExcludeFile() {
webpackWorkersExcludesList = new ArrayList<String>();

Expand Down