From 72bb076dcd1287d9483533fe4875686f94fbde00 Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 10 Mar 2017 09:33:07 +0530 Subject: [PATCH 01/62] Correct the year in copyrights --- .../.idea/copyright/WSO2.xml | 6 + .../.idea/copyright/profiles_settings.xml | 7 + .../libraries/Maven__log4j_log4j_1_2_17.xml | 13 + .../.idea/workspace.xml | 1310 +++++++++++++++++ .../CodeQualityMatrices.iml | 1 + CodeQualityMatricesProject/pom.xml | 24 +- .../code/quality/matrices/BlameCommit.java | 19 +- .../wso2/code/quality/matrices/MainClass.java | 18 + .../com/wso2/code/quality/matrices/Pmt.java | 36 +- .../code/quality/matrices/RestApiCaller.java | 19 +- .../wso2/code/quality/matrices/Reviewers.java | 19 +- 11 files changed, 1424 insertions(+), 48 deletions(-) create mode 100644 CodeQualityMatricesProject/.idea/copyright/WSO2.xml create mode 100644 CodeQualityMatricesProject/.idea/copyright/profiles_settings.xml create mode 100644 CodeQualityMatricesProject/.idea/libraries/Maven__log4j_log4j_1_2_17.xml create mode 100644 CodeQualityMatricesProject/.idea/workspace.xml diff --git a/CodeQualityMatricesProject/.idea/copyright/WSO2.xml b/CodeQualityMatricesProject/.idea/copyright/WSO2.xml new file mode 100644 index 0000000..5e83307 --- /dev/null +++ b/CodeQualityMatricesProject/.idea/copyright/WSO2.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/copyright/profiles_settings.xml b/CodeQualityMatricesProject/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..db82460 --- /dev/null +++ b/CodeQualityMatricesProject/.idea/copyright/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/libraries/Maven__log4j_log4j_1_2_17.xml b/CodeQualityMatricesProject/.idea/libraries/Maven__log4j_log4j_1_2_17.xml new file mode 100644 index 0000000..e383c1b --- /dev/null +++ b/CodeQualityMatricesProject/.idea/libraries/Maven__log4j_log4j_1_2_17.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/workspace.xml b/CodeQualityMatricesProject/.idea/workspace.xml new file mode 100644 index 0000000..92d6d14 --- /dev/null +++ b/CodeQualityMatricesProject/.idea/workspace.xml @@ -0,0 +1,1310 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1489116410824 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + file://$PROJECT_DIR$/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java + 389 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + WSO2 + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 1.8 + + + + + + + + CodeQualityMatrices + + + + + + + + Maven: log4j:log4j:1.2.17 + + + + + + + + \ No newline at end of file diff --git a/CodeQualityMatricesProject/CodeQualityMatrices.iml b/CodeQualityMatricesProject/CodeQualityMatrices.iml index 264db63..f1af523 100644 --- a/CodeQualityMatricesProject/CodeQualityMatrices.iml +++ b/CodeQualityMatricesProject/CodeQualityMatrices.iml @@ -11,6 +11,7 @@ + diff --git a/CodeQualityMatricesProject/pom.xml b/CodeQualityMatricesProject/pom.xml index cfb894e..3254fe2 100644 --- a/CodeQualityMatricesProject/pom.xml +++ b/CodeQualityMatricesProject/pom.xml @@ -1,3 +1,21 @@ + + @@ -23,7 +41,11 @@ 3.8.1 test - + + log4j + log4j + 1.2.17 + org.json json diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java index 51188a9..c5d9382 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java @@ -1,22 +1,21 @@ /* - * Copyright (c) Jan 31, 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * + * Copyright (c) 2017 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. */ - package com.wso2.code.quality.matrices; import java.io.BufferedReader; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index 800da18..549bee6 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2017 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + package com.wso2.code.quality.matrices; import org.json.JSONArray; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java index 203612a..854ee77 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java @@ -1,20 +1,22 @@ -package com.wso2.code.quality.matrices;/* -* Copyright (c) ${date}, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -* WSO2 Inc. licenses this file to you under the Apache License, -* Version 2.0 (the "License"); you may not use this file except -* in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ +/* + * Copyright (c) 2017 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package com.wso2.code.quality.matrices; import org.json.JSONArray; import org.json.JSONObject; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java index 54c8a7b..725e084 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java @@ -1,22 +1,21 @@ /* - * Copyright (c) Jan 31, 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * + * Copyright (c) 2017 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. */ - package com.wso2.code.quality.matrices; import java.io.BufferedReader; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java index 8995b72..f6e705c 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java @@ -1,22 +1,21 @@ /* - * Copyright (c) Feb 20, 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * + * Copyright (c) 2017 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. */ - package com.wso2.code.quality.matrices; import java.util.HashMap; From 2f6807836827b04e51c13fd9cb860f3a2faf2968 Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 10 Mar 2017 10:28:57 +0530 Subject: [PATCH 02/62] added .idea direcotory to gitignore file --- CodeQualityMatricesProject/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/CodeQualityMatricesProject/.gitignore b/CodeQualityMatricesProject/.gitignore index b83d222..54f62de 100644 --- a/CodeQualityMatricesProject/.gitignore +++ b/CodeQualityMatricesProject/.gitignore @@ -1 +1,2 @@ /target/ +/.idea/ \ No newline at end of file From 3a24417110db776e3e87a9797817d174121cc78e Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 10 Mar 2017 10:39:31 +0530 Subject: [PATCH 03/62] add entries for gitignore --- CodeQualityMatricesProject/.gitignore | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/CodeQualityMatricesProject/.gitignore b/CodeQualityMatricesProject/.gitignore index 54f62de..77bb683 100644 --- a/CodeQualityMatricesProject/.gitignore +++ b/CodeQualityMatricesProject/.gitignore @@ -1,2 +1,16 @@ -/target/ -/.idea/ \ No newline at end of file +*.class + +# Ignore everything in this directory +target +.classpath +.settings +.project +*.iml +*.iws +*.ipr +.idea + +# Package Files # +*.jar +*.war +*.ear \ No newline at end of file From 9b8be3f5608302a1256751246a95dac7b4f32776 Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 10 Mar 2017 10:49:11 +0530 Subject: [PATCH 04/62] removed unwanted files from the repository --- CodeQualityMatricesProject/.idea/.name | 1 - CodeQualityMatricesProject/.idea/compiler.xml | 16 - .../.idea/copyright/WSO2.xml | 6 - .../.idea/copyright/profiles_settings.xml | 7 - .../.idea/encodings.xml | 6 - ...oglecode_json_simple_json_simple_1_1_1.xml | 13 - ...Maven__commons_codec_commons_codec_1_9.xml | 13 - ...n__commons_logging_commons_logging_1_2.xml | 13 - .../libraries/Maven__junit_junit_3_8_1.xml | 13 - .../libraries/Maven__log4j_log4j_1_2_17.xml | 13 - ...__org_apache_commons_commons_lang3_3_5.xml | 13 - ...apache_httpcomponents_httpclient_4_5_2.xml | 13 - ...g_apache_httpcomponents_httpcore_4_4_4.xml | 13 - .../Maven__org_json_json_20160810.xml | 13 - CodeQualityMatricesProject/.idea/misc.xml | 13 - CodeQualityMatricesProject/.idea/modules.xml | 8 - .../.idea/uiDesigner.xml | 124 -- CodeQualityMatricesProject/.idea/vcs.xml | 6 - .../.idea/workspace.xml | 1310 ----------------- .../org.eclipse.core.resources.prefs | 4 - .../.settings/org.eclipse.jdt.core.prefs | 12 - .../.settings/org.eclipse.m2e.core.prefs | 4 - .../wso2/carbon-apimgt/ReviewFor1120.json | 1 - .../wso2/carbon-apimgt/ReviewFor1584.json | 1 - .../wso2/carbon-apimgt/ReviewFor1590.json | 1 - .../wso2/carbon-apimgt/ReviewFor1594.json | 1 - .../wso2/carbon-apimgt/ReviewFor1618.json | 1 - .../wso2/carbon-apimgt/ReviewFor1703.json | 1 - .../wso2/carbon-apimgt/ReviewFor178.json | 1 - .../wso2/carbon-apimgt/ReviewFor2868.json | 1 - .../wso2/carbon-apimgt/ReviewFor2873.json | 1 - .../wso2/carbon-apimgt/ReviewFor53.json | 1 - .../wso2/carbon-apimgt/ReviewFor656.json | 1 - .../wso2/carbon-apimgt/ReviewFor657.json | 1 - .../jsonOutPutFileCommits.json | 1 - .../jsonOutPutFileOfSearchCommitAPI.json | 1 - .../jsonOutPutFilePRs.json | 1 - CodeQualityMatricesProject/pullOutput.json | 1 - .../pullReviewOutPutFile.json | 1 - ...5c02145c8ec6d3bba433f2fb5e850e1d25846.json | 1 - ...f5325075702fb2367743559ffc03d2b596cfd.json | 1 - ...02613db654fa15679f8e77bc282fcb30de3a9.json | 1 - ...c0b0272253dcf21d222ad2ac19d35a71198d7.json | 1 - ...3d2f6ec285a65e69ec71765e55409db103e03.json | 1 - ...3567c105e223d7edc397526017df22fe8aa43.json | 1 - ...eb84b7cfd161b4dad565bcd698e824e1ec099.json | 1 - ...207449a58b65ae9c7bdac6f60ce5ef474fb58.json | 1 - ...43d15b1d63af642cc562afc3c63812c45d84d.json | 1 - ...c3deead1bc3e07ac281d0ab12cdc177206831.json | 1 - ...747f2501215e8e56eb879b12998795315d15c.json | 1 - 50 files changed, 1662 deletions(-) delete mode 100644 CodeQualityMatricesProject/.idea/.name delete mode 100644 CodeQualityMatricesProject/.idea/compiler.xml delete mode 100644 CodeQualityMatricesProject/.idea/copyright/WSO2.xml delete mode 100644 CodeQualityMatricesProject/.idea/copyright/profiles_settings.xml delete mode 100644 CodeQualityMatricesProject/.idea/encodings.xml delete mode 100644 CodeQualityMatricesProject/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1.xml delete mode 100644 CodeQualityMatricesProject/.idea/libraries/Maven__commons_codec_commons_codec_1_9.xml delete mode 100644 CodeQualityMatricesProject/.idea/libraries/Maven__commons_logging_commons_logging_1_2.xml delete mode 100644 CodeQualityMatricesProject/.idea/libraries/Maven__junit_junit_3_8_1.xml delete mode 100644 CodeQualityMatricesProject/.idea/libraries/Maven__log4j_log4j_1_2_17.xml delete mode 100644 CodeQualityMatricesProject/.idea/libraries/Maven__org_apache_commons_commons_lang3_3_5.xml delete mode 100644 CodeQualityMatricesProject/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_5_2.xml delete mode 100644 CodeQualityMatricesProject/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_4_4.xml delete mode 100644 CodeQualityMatricesProject/.idea/libraries/Maven__org_json_json_20160810.xml delete mode 100644 CodeQualityMatricesProject/.idea/misc.xml delete mode 100644 CodeQualityMatricesProject/.idea/modules.xml delete mode 100644 CodeQualityMatricesProject/.idea/uiDesigner.xml delete mode 100644 CodeQualityMatricesProject/.idea/vcs.xml delete mode 100644 CodeQualityMatricesProject/.idea/workspace.xml delete mode 100644 CodeQualityMatricesProject/.settings/org.eclipse.core.resources.prefs delete mode 100644 CodeQualityMatricesProject/.settings/org.eclipse.jdt.core.prefs delete mode 100644 CodeQualityMatricesProject/.settings/org.eclipse.m2e.core.prefs delete mode 100644 CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1120.json delete mode 100644 CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1584.json delete mode 100644 CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1590.json delete mode 100644 CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1594.json delete mode 100644 CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1618.json delete mode 100644 CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1703.json delete mode 100644 CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor178.json delete mode 100644 CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor2868.json delete mode 100644 CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor2873.json delete mode 100644 CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor53.json delete mode 100644 CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor656.json delete mode 100644 CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor657.json delete mode 100644 CodeQualityMatricesProject/jsonOutPutFileCommits.json delete mode 100644 CodeQualityMatricesProject/jsonOutPutFileOfSearchCommitAPI.json delete mode 100644 CodeQualityMatricesProject/jsonOutPutFilePRs.json delete mode 100644 CodeQualityMatricesProject/pullOutput.json delete mode 100644 CodeQualityMatricesProject/pullReviewOutPutFile.json delete mode 100644 CodeQualityMatricesProject/searchApiOutputs/0015c02145c8ec6d3bba433f2fb5e850e1d25846.json delete mode 100644 CodeQualityMatricesProject/searchApiOutputs/653f5325075702fb2367743559ffc03d2b596cfd.json delete mode 100644 CodeQualityMatricesProject/searchApiOutputs/75e02613db654fa15679f8e77bc282fcb30de3a9.json delete mode 100644 CodeQualityMatricesProject/searchApiOutputs/82dc0b0272253dcf21d222ad2ac19d35a71198d7.json delete mode 100644 CodeQualityMatricesProject/searchApiOutputs/9f63d2f6ec285a65e69ec71765e55409db103e03.json delete mode 100644 CodeQualityMatricesProject/searchApiOutputs/b483567c105e223d7edc397526017df22fe8aa43.json delete mode 100644 CodeQualityMatricesProject/searchApiOutputs/cd4eb84b7cfd161b4dad565bcd698e824e1ec099.json delete mode 100644 CodeQualityMatricesProject/searchApiOutputs/dba207449a58b65ae9c7bdac6f60ce5ef474fb58.json delete mode 100644 CodeQualityMatricesProject/searchApiOutputs/dce43d15b1d63af642cc562afc3c63812c45d84d.json delete mode 100644 CodeQualityMatricesProject/searchApiOutputs/eccc3deead1bc3e07ac281d0ab12cdc177206831.json delete mode 100644 CodeQualityMatricesProject/searchApiOutputs/f55747f2501215e8e56eb879b12998795315d15c.json diff --git a/CodeQualityMatricesProject/.idea/.name b/CodeQualityMatricesProject/.idea/.name deleted file mode 100644 index f94cade..0000000 --- a/CodeQualityMatricesProject/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -CodeQualityMatrices \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/compiler.xml b/CodeQualityMatricesProject/.idea/compiler.xml deleted file mode 100644 index 838d49b..0000000 --- a/CodeQualityMatricesProject/.idea/compiler.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/copyright/WSO2.xml b/CodeQualityMatricesProject/.idea/copyright/WSO2.xml deleted file mode 100644 index 5e83307..0000000 --- a/CodeQualityMatricesProject/.idea/copyright/WSO2.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/copyright/profiles_settings.xml b/CodeQualityMatricesProject/.idea/copyright/profiles_settings.xml deleted file mode 100644 index db82460..0000000 --- a/CodeQualityMatricesProject/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/encodings.xml b/CodeQualityMatricesProject/.idea/encodings.xml deleted file mode 100644 index b26911b..0000000 --- a/CodeQualityMatricesProject/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1.xml b/CodeQualityMatricesProject/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1.xml deleted file mode 100644 index f3f3738..0000000 --- a/CodeQualityMatricesProject/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/libraries/Maven__commons_codec_commons_codec_1_9.xml b/CodeQualityMatricesProject/.idea/libraries/Maven__commons_codec_commons_codec_1_9.xml deleted file mode 100644 index a66d039..0000000 --- a/CodeQualityMatricesProject/.idea/libraries/Maven__commons_codec_commons_codec_1_9.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/libraries/Maven__commons_logging_commons_logging_1_2.xml b/CodeQualityMatricesProject/.idea/libraries/Maven__commons_logging_commons_logging_1_2.xml deleted file mode 100644 index eab40b3..0000000 --- a/CodeQualityMatricesProject/.idea/libraries/Maven__commons_logging_commons_logging_1_2.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/libraries/Maven__junit_junit_3_8_1.xml b/CodeQualityMatricesProject/.idea/libraries/Maven__junit_junit_3_8_1.xml deleted file mode 100644 index 71b2993..0000000 --- a/CodeQualityMatricesProject/.idea/libraries/Maven__junit_junit_3_8_1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/libraries/Maven__log4j_log4j_1_2_17.xml b/CodeQualityMatricesProject/.idea/libraries/Maven__log4j_log4j_1_2_17.xml deleted file mode 100644 index e383c1b..0000000 --- a/CodeQualityMatricesProject/.idea/libraries/Maven__log4j_log4j_1_2_17.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/libraries/Maven__org_apache_commons_commons_lang3_3_5.xml b/CodeQualityMatricesProject/.idea/libraries/Maven__org_apache_commons_commons_lang3_3_5.xml deleted file mode 100644 index 666266c..0000000 --- a/CodeQualityMatricesProject/.idea/libraries/Maven__org_apache_commons_commons_lang3_3_5.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_5_2.xml b/CodeQualityMatricesProject/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_5_2.xml deleted file mode 100644 index fdb7ead..0000000 --- a/CodeQualityMatricesProject/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_5_2.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_4_4.xml b/CodeQualityMatricesProject/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_4_4.xml deleted file mode 100644 index 3a5aa19..0000000 --- a/CodeQualityMatricesProject/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_4_4.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/libraries/Maven__org_json_json_20160810.xml b/CodeQualityMatricesProject/.idea/libraries/Maven__org_json_json_20160810.xml deleted file mode 100644 index 774f062..0000000 --- a/CodeQualityMatricesProject/.idea/libraries/Maven__org_json_json_20160810.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/misc.xml b/CodeQualityMatricesProject/.idea/misc.xml deleted file mode 100644 index ff20635..0000000 --- a/CodeQualityMatricesProject/.idea/misc.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/modules.xml b/CodeQualityMatricesProject/.idea/modules.xml deleted file mode 100644 index 0b9f2ed..0000000 --- a/CodeQualityMatricesProject/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/uiDesigner.xml b/CodeQualityMatricesProject/.idea/uiDesigner.xml deleted file mode 100644 index e96534f..0000000 --- a/CodeQualityMatricesProject/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/vcs.xml b/CodeQualityMatricesProject/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/CodeQualityMatricesProject/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.idea/workspace.xml b/CodeQualityMatricesProject/.idea/workspace.xml deleted file mode 100644 index 92d6d14..0000000 --- a/CodeQualityMatricesProject/.idea/workspace.xml +++ /dev/null @@ -1,1310 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - DEFINITION_ORDER - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1489116410824 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - file://$PROJECT_DIR$/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java - 389 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - WSO2 - - - - - - - - No facets are configured - - - - - - - - - - - - - - - 1.8 - - - - - - - - CodeQualityMatrices - - - - - - - - Maven: log4j:log4j:1.2.17 - - - - - - - - \ No newline at end of file diff --git a/CodeQualityMatricesProject/.settings/org.eclipse.core.resources.prefs b/CodeQualityMatricesProject/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index f9fe345..0000000 --- a/CodeQualityMatricesProject/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,4 +0,0 @@ -eclipse.preferences.version=1 -encoding//src/main/java=UTF-8 -encoding//src/test/java=UTF-8 -encoding/=UTF-8 diff --git a/CodeQualityMatricesProject/.settings/org.eclipse.jdt.core.prefs b/CodeQualityMatricesProject/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 6249222..0000000 --- a/CodeQualityMatricesProject/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.7 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.7 diff --git a/CodeQualityMatricesProject/.settings/org.eclipse.m2e.core.prefs b/CodeQualityMatricesProject/.settings/org.eclipse.m2e.core.prefs deleted file mode 100644 index f897a7f..0000000 --- a/CodeQualityMatricesProject/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 diff --git a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1120.json b/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1120.json deleted file mode 100644 index 0637a08..0000000 --- a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1120.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1584.json b/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1584.json deleted file mode 100644 index 0637a08..0000000 --- a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1584.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1590.json b/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1590.json deleted file mode 100644 index 0637a08..0000000 --- a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1590.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1594.json b/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1594.json deleted file mode 100644 index 0637a08..0000000 --- a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1594.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1618.json b/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1618.json deleted file mode 100644 index 0637a08..0000000 --- a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1618.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1703.json b/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1703.json deleted file mode 100644 index 0637a08..0000000 --- a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor1703.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor178.json b/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor178.json deleted file mode 100644 index 0637a08..0000000 --- a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor178.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor2868.json b/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor2868.json deleted file mode 100644 index 0637a08..0000000 --- a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor2868.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor2873.json b/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor2873.json deleted file mode 100644 index 0637a08..0000000 --- a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor2873.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor53.json b/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor53.json deleted file mode 100644 index 0637a08..0000000 --- a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor53.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor656.json b/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor656.json deleted file mode 100644 index 0637a08..0000000 --- a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor656.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor657.json b/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor657.json deleted file mode 100644 index 0637a08..0000000 --- a/CodeQualityMatricesProject/ReviewApiOutputs/wso2/carbon-apimgt/ReviewFor657.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/CodeQualityMatricesProject/jsonOutPutFileCommits.json b/CodeQualityMatricesProject/jsonOutPutFileCommits.json deleted file mode 100644 index f4e3c4f..0000000 --- a/CodeQualityMatricesProject/jsonOutPutFileCommits.json +++ /dev/null @@ -1 +0,0 @@ -[{"name":"jiraInformation_supportJiras","value":["https://support.wso2.com/jira/browse/YENLOSUPPORTDEV-7"]},{"name":"overview_carbonPlatform","value":["4.4.0"]},{"name":"overview_issueType","value":["Bug"]},{"name":"patchInformation_svnRevisionpublic","value":["eaa45529cbabc5f30a2ffaa4781821ad0a5223ab","2b1d973d089ebc3af3b9e7b893f48cf905758cf4"]},{"name":"peopleInvolved_developedby","value":["samitha@wso2.com"]},{"name":"registry.Aspects","value":["PatchLifeCycle"]},{"name":"patchInformation_zipLocation","value":["https://svn.wso2.com/wso2/custom/projects/projects/carbon/wilkes/patches/patch0680/WSO2-CARBON-PATCH-4.4.0-0680.zip"]},{"name":"dates_releasedOn","value":["12/20/2016"]},{"name":"wum_releasedTimestamp","value":["1482238832449"]},{"name":"patchInformation_isthisabackportpatch","value":["yes"]},{"name":"testInformation_reasonCannotDo","value":["Test implementation is not supported by test framework"]},{"name":"dates_qaStartedOn","value":["12/15/2016"]},{"name":"jiraInformation_publicjirasummary","value":["Support SSO without enabling single logout"]},{"name":"testInformation_regressionTests","value":["Setup APIM Store and Publisher web apps SSO with IS 5.1.0 without enabling Single Logout\nBasic login flow should work without getting a 500 Internal Server Error in the last step of the SSO flow (user redirecting back to Store or Publisher web app).\n"]},{"name":"dates_developmentStartedOn","value":["12/09/2016"]},{"name":"jiraInformation_publicJira","value":["https://wso2.org/jira/browse/APIMANAGER-4610"]},{"name":"testInformation_automationavailable","value":["Yes"]},{"name":"patchInformation_svnRevisionsupport","value":["a663444d6a8f76dd77a164b5d76750be3722ab38"]},{"name":"patchInformation_pleaseupdatehereifthejarisaspecialcase","value":["https://docs.google.com/a/wso2.com/spreadsheet/ccc?key=0AlTtjx4c_xVpdFBMY1pSdFFoc1EzY2R6V2JrQ3R3TUE#gid=0"]},{"name":"testInformation_testsRevisionsupport","value":["caee3a2b0bb6f21575ad439b29779e8bd4905680"]},{"name":"peopleInvolved_qaedby","value":["samitha@wso2.com"]},{"name":"overview_products","value":["API Manager 2.0.0"]},{"name":"registry.lifecycle.PatchLifeCycle.state","value":["Released"]},{"name":"overview_client","value":["Yenlo BV - Development Support"]},{"name":"patchInformation_qareferencelink","value":["https://support.wso2.com/jira/browse/WSOQATESTC-775"]},{"name":"registry.LC.name","value":["PatchLifeCycle"]},{"name":"overview_name","value":["WSO2-CARBON-PATCH-4.4.0-0680"]},{"name":"testInformation_testsRevisionpublic","value":["caee3a2b0bb6f21575ad439b29779e8bd4905680"]},{"name":"testInformation_automationTestsLocation","value":["https://github.com/wso2-support/product-apim/blob/support-2.0.0/modules/integration/tests-ui-integration/src/test/java/org/wso2/am/integration/ui/tests/APIMANAGER3277SSOLogin.java"]},{"name":"patchInformation_jarsInvolved","value":["org.wso2.carbon.hostobjects.sso_6.0.4.jar"]}] \ No newline at end of file diff --git a/CodeQualityMatricesProject/jsonOutPutFileOfSearchCommitAPI.json b/CodeQualityMatricesProject/jsonOutPutFileOfSearchCommitAPI.json deleted file mode 100644 index 93827bd..0000000 --- a/CodeQualityMatricesProject/jsonOutPutFileOfSearchCommitAPI.json +++ /dev/null @@ -1 +0,0 @@ -{"total_count":1,"incomplete_results":false,"items":[{"url":"https://api.github.com/repos/wso2/carbon-apimgt/commits/2b1d973d089ebc3af3b9e7b893f48cf905758cf4","sha":"2b1d973d089ebc3af3b9e7b893f48cf905758cf4","html_url":"https://github.com/wso2/carbon-apimgt/commit/2b1d973d089ebc3af3b9e7b893f48cf905758cf4","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/commits/2b1d973d089ebc3af3b9e7b893f48cf905758cf4/comments","commit":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/git/commits/2b1d973d089ebc3af3b9e7b893f48cf905758cf4","author":{"date":"2016-08-16T16:38:48+05:30","name":"Malintha Amarasinghe","email":"malintha.prasan@gmail.com"},"committer":{"date":"2016-08-16T16:38:54+05:30","name":"Malintha Amarasinghe","email":"malintha.prasan@gmail.com"},"message":"sending ACS and signed SAML requests in Publisher","tree":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/git/trees/6bc4717c4b291fbbbb1726857d8c6eee7090104c","sha":"6bc4717c4b291fbbbb1726857d8c6eee7090104c"},"comment_count":0},"author":{"login":"malinthaprasan","id":1591316,"avatar_url":"https://avatars.githubusercontent.com/u/1591316?v=3","gravatar_id":"","url":"https://api.github.com/users/malinthaprasan","html_url":"https://github.com/malinthaprasan","followers_url":"https://api.github.com/users/malinthaprasan/followers","following_url":"https://api.github.com/users/malinthaprasan/following{/other_user}","gists_url":"https://api.github.com/users/malinthaprasan/gists{/gist_id}","starred_url":"https://api.github.com/users/malinthaprasan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/malinthaprasan/subscriptions","organizations_url":"https://api.github.com/users/malinthaprasan/orgs","repos_url":"https://api.github.com/users/malinthaprasan/repos","events_url":"https://api.github.com/users/malinthaprasan/events{/privacy}","received_events_url":"https://api.github.com/users/malinthaprasan/received_events","type":"User","site_admin":false},"committer":{"login":"malinthaprasan","id":1591316,"avatar_url":"https://avatars.githubusercontent.com/u/1591316?v=3","gravatar_id":"","url":"https://api.github.com/users/malinthaprasan","html_url":"https://github.com/malinthaprasan","followers_url":"https://api.github.com/users/malinthaprasan/followers","following_url":"https://api.github.com/users/malinthaprasan/following{/other_user}","gists_url":"https://api.github.com/users/malinthaprasan/gists{/gist_id}","starred_url":"https://api.github.com/users/malinthaprasan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/malinthaprasan/subscriptions","organizations_url":"https://api.github.com/users/malinthaprasan/orgs","repos_url":"https://api.github.com/users/malinthaprasan/repos","events_url":"https://api.github.com/users/malinthaprasan/events{/privacy}","received_events_url":"https://api.github.com/users/malinthaprasan/received_events","type":"User","site_admin":false},"parents":[{"url":"https://api.github.com/repos/wso2/carbon-apimgt/commits/eaa45529cbabc5f30a2ffaa4781821ad0a5223ab","html_url":"https://github.com/wso2/carbon-apimgt/commit/eaa45529cbabc5f30a2ffaa4781821ad0a5223ab","sha":"eaa45529cbabc5f30a2ffaa4781821ad0a5223ab"}],"repository":{"id":17201744,"name":"carbon-apimgt","full_name":"wso2/carbon-apimgt","owner":{"login":"wso2","id":533043,"avatar_url":"https://avatars.githubusercontent.com/u/533043?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wso2/carbon-apimgt","description":null,"fork":false,"url":"https://api.github.com/repos/wso2/carbon-apimgt","forks_url":"https://api.github.com/repos/wso2/carbon-apimgt/forks","keys_url":"https://api.github.com/repos/wso2/carbon-apimgt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wso2/carbon-apimgt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wso2/carbon-apimgt/teams","hooks_url":"https://api.github.com/repos/wso2/carbon-apimgt/hooks","issue_events_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/events{/number}","events_url":"https://api.github.com/repos/wso2/carbon-apimgt/events","assignees_url":"https://api.github.com/repos/wso2/carbon-apimgt/assignees{/user}","branches_url":"https://api.github.com/repos/wso2/carbon-apimgt/branches{/branch}","tags_url":"https://api.github.com/repos/wso2/carbon-apimgt/tags","blobs_url":"https://api.github.com/repos/wso2/carbon-apimgt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wso2/carbon-apimgt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wso2/carbon-apimgt/git/refs{/sha}","trees_url":"https://api.github.com/repos/wso2/carbon-apimgt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wso2/carbon-apimgt/statuses/{sha}","languages_url":"https://api.github.com/repos/wso2/carbon-apimgt/languages","stargazers_url":"https://api.github.com/repos/wso2/carbon-apimgt/stargazers","contributors_url":"https://api.github.com/repos/wso2/carbon-apimgt/contributors","subscribers_url":"https://api.github.com/repos/wso2/carbon-apimgt/subscribers","subscription_url":"https://api.github.com/repos/wso2/carbon-apimgt/subscription","commits_url":"https://api.github.com/repos/wso2/carbon-apimgt/commits{/sha}","git_commits_url":"https://api.github.com/repos/wso2/carbon-apimgt/git/commits{/sha}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/comments{/number}","issue_comment_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/comments{/number}","contents_url":"https://api.github.com/repos/wso2/carbon-apimgt/contents/{+path}","compare_url":"https://api.github.com/repos/wso2/carbon-apimgt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wso2/carbon-apimgt/merges","archive_url":"https://api.github.com/repos/wso2/carbon-apimgt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wso2/carbon-apimgt/downloads","issues_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues{/number}","pulls_url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls{/number}","milestones_url":"https://api.github.com/repos/wso2/carbon-apimgt/milestones{/number}","notifications_url":"https://api.github.com/repos/wso2/carbon-apimgt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wso2/carbon-apimgt/labels{/name}","releases_url":"https://api.github.com/repos/wso2/carbon-apimgt/releases{/id}","deployments_url":"https://api.github.com/repos/wso2/carbon-apimgt/deployments"},"score":1.0}]} \ No newline at end of file diff --git a/CodeQualityMatricesProject/jsonOutPutFilePRs.json b/CodeQualityMatricesProject/jsonOutPutFilePRs.json deleted file mode 100644 index c818f7f..0000000 --- a/CodeQualityMatricesProject/jsonOutPutFilePRs.json +++ /dev/null @@ -1 +0,0 @@ -{"total_count":3,"incomplete_results":false,"items":[{"url":"https://api.github.com/repos/wso2/carbon-kernel/issues/524","repository_url":"https://api.github.com/repos/wso2/carbon-kernel","labels_url":"https://api.github.com/repos/wso2/carbon-kernel/issues/524/labels{/name}","comments_url":"https://api.github.com/repos/wso2/carbon-kernel/issues/524/comments","events_url":"https://api.github.com/repos/wso2/carbon-kernel/issues/524/events","html_url":"https://github.com/wso2/carbon-kernel/pull/524","id":110054673,"number":524,"title":"Fixing IDENTITY-3363","user":{"login":"damithsenanayake","id":1591344,"avatar_url":"https://avatars.githubusercontent.com/u/1591344?v=3","gravatar_id":"","url":"https://api.github.com/users/damithsenanayake","html_url":"https://github.com/damithsenanayake","followers_url":"https://api.github.com/users/damithsenanayake/followers","following_url":"https://api.github.com/users/damithsenanayake/following{/other_user}","gists_url":"https://api.github.com/users/damithsenanayake/gists{/gist_id}","starred_url":"https://api.github.com/users/damithsenanayake/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damithsenanayake/subscriptions","organizations_url":"https://api.github.com/users/damithsenanayake/orgs","repos_url":"https://api.github.com/users/damithsenanayake/repos","events_url":"https://api.github.com/users/damithsenanayake/events{/privacy}","received_events_url":"https://api.github.com/users/damithsenanayake/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2015-10-06T17:06:37Z","updated_at":"2015-10-12T09:19:24Z","closed_at":"2015-10-12T09:19:24Z","pull_request":{"url":"https://api.github.com/repos/wso2/carbon-kernel/pulls/524","html_url":"https://github.com/wso2/carbon-kernel/pull/524","diff_url":"https://github.com/wso2/carbon-kernel/pull/524.diff","patch_url":"https://github.com/wso2/carbon-kernel/pull/524.patch"},"body":"","score":0.4839668},{"url":"https://api.github.com/repos/wso2/carbon-kernel/issues/573","repository_url":"https://api.github.com/repos/wso2/carbon-kernel","labels_url":"https://api.github.com/repos/wso2/carbon-kernel/issues/573/labels{/name}","comments_url":"https://api.github.com/repos/wso2/carbon-kernel/issues/573/comments","events_url":"https://api.github.com/repos/wso2/carbon-kernel/issues/573/events","html_url":"https://github.com/wso2/carbon-kernel/pull/573","id":112377096,"number":573,"title":"Identity 3874 44x","user":{"login":"damithsenanayake","id":1591344,"avatar_url":"https://avatars.githubusercontent.com/u/1591344?v=3","gravatar_id":"","url":"https://api.github.com/users/damithsenanayake","html_url":"https://github.com/damithsenanayake","followers_url":"https://api.github.com/users/damithsenanayake/followers","following_url":"https://api.github.com/users/damithsenanayake/following{/other_user}","gists_url":"https://api.github.com/users/damithsenanayake/gists{/gist_id}","starred_url":"https://api.github.com/users/damithsenanayake/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damithsenanayake/subscriptions","organizations_url":"https://api.github.com/users/damithsenanayake/orgs","repos_url":"https://api.github.com/users/damithsenanayake/repos","events_url":"https://api.github.com/users/damithsenanayake/events{/privacy}","received_events_url":"https://api.github.com/users/damithsenanayake/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2015-10-20T14:08:23Z","updated_at":"2015-10-20T14:08:34Z","closed_at":"2015-10-20T14:08:34Z","pull_request":{"url":"https://api.github.com/repos/wso2/carbon-kernel/pulls/573","html_url":"https://github.com/wso2/carbon-kernel/pull/573","diff_url":"https://github.com/wso2/carbon-kernel/pull/573.diff","patch_url":"https://github.com/wso2/carbon-kernel/pull/573.patch"},"body":"","score":0.4839668},{"url":"https://api.github.com/repos/IndunilRathnayake/carbon4-kernel/issues/1","repository_url":"https://api.github.com/repos/IndunilRathnayake/carbon4-kernel","labels_url":"https://api.github.com/repos/IndunilRathnayake/carbon4-kernel/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/IndunilRathnayake/carbon4-kernel/issues/1/comments","events_url":"https://api.github.com/repos/IndunilRathnayake/carbon4-kernel/issues/1/events","html_url":"https://github.com/IndunilRathnayake/carbon4-kernel/pull/1","id":119506644,"number":1,"title":"Crypto","user":{"login":"cdwijayarathna","id":1338607,"avatar_url":"https://avatars.githubusercontent.com/u/1338607?v=3","gravatar_id":"","url":"https://api.github.com/users/cdwijayarathna","html_url":"https://github.com/cdwijayarathna","followers_url":"https://api.github.com/users/cdwijayarathna/followers","following_url":"https://api.github.com/users/cdwijayarathna/following{/other_user}","gists_url":"https://api.github.com/users/cdwijayarathna/gists{/gist_id}","starred_url":"https://api.github.com/users/cdwijayarathna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdwijayarathna/subscriptions","organizations_url":"https://api.github.com/users/cdwijayarathna/orgs","repos_url":"https://api.github.com/users/cdwijayarathna/repos","events_url":"https://api.github.com/users/cdwijayarathna/events{/privacy}","received_events_url":"https://api.github.com/users/cdwijayarathna/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2015-11-30T14:46:19Z","updated_at":"2015-11-30T14:47:47Z","closed_at":"2015-11-30T14:47:47Z","pull_request":{"url":"https://api.github.com/repos/IndunilRathnayake/carbon4-kernel/pulls/1","html_url":"https://github.com/IndunilRathnayake/carbon4-kernel/pull/1","diff_url":"https://github.com/IndunilRathnayake/carbon4-kernel/pull/1.diff","patch_url":"https://github.com/IndunilRathnayake/carbon4-kernel/pull/1.patch"},"body":"","score":0.48394772}]} \ No newline at end of file diff --git a/CodeQualityMatricesProject/pullOutput.json b/CodeQualityMatricesProject/pullOutput.json deleted file mode 100644 index 0960714..0000000 --- a/CodeQualityMatricesProject/pullOutput.json +++ /dev/null @@ -1 +0,0 @@ -{"url":"https://api.github.com/repos/wso2/carbon-kernel/pulls/524","id":46930122,"html_url":"https://github.com/wso2/carbon-kernel/pull/524","diff_url":"https://github.com/wso2/carbon-kernel/pull/524.diff","patch_url":"https://github.com/wso2/carbon-kernel/pull/524.patch","issue_url":"https://api.github.com/repos/wso2/carbon-kernel/issues/524","number":524,"state":"closed","locked":false,"title":"Fixing IDENTITY-3363","user":{"login":"damithsenanayake","id":1591344,"avatar_url":"https://avatars.githubusercontent.com/u/1591344?v=3","gravatar_id":"","url":"https://api.github.com/users/damithsenanayake","html_url":"https://github.com/damithsenanayake","followers_url":"https://api.github.com/users/damithsenanayake/followers","following_url":"https://api.github.com/users/damithsenanayake/following{/other_user}","gists_url":"https://api.github.com/users/damithsenanayake/gists{/gist_id}","starred_url":"https://api.github.com/users/damithsenanayake/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damithsenanayake/subscriptions","organizations_url":"https://api.github.com/users/damithsenanayake/orgs","repos_url":"https://api.github.com/users/damithsenanayake/repos","events_url":"https://api.github.com/users/damithsenanayake/events{/privacy}","received_events_url":"https://api.github.com/users/damithsenanayake/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-06T17:06:37Z","updated_at":"2015-10-12T09:19:24Z","closed_at":"2015-10-12T09:19:24Z","merged_at":null,"merge_commit_sha":"d83c111609bcb4d73c8de301f55a42aad5363f52","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/wso2/carbon-kernel/pulls/524/commits","review_comments_url":"https://api.github.com/repos/wso2/carbon-kernel/pulls/524/comments","review_comment_url":"https://api.github.com/repos/wso2/carbon-kernel/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wso2/carbon-kernel/issues/524/comments","statuses_url":"https://api.github.com/repos/wso2/carbon-kernel/statuses/88b1cf36231c296a38c4804d851fa875dba652b1","head":{"label":"damithsenanayake:identity-3363-4.4.x","ref":"identity-3363-4.4.x","sha":"88b1cf36231c296a38c4804d851fa875dba652b1","user":{"login":"damithsenanayake","id":1591344,"avatar_url":"https://avatars.githubusercontent.com/u/1591344?v=3","gravatar_id":"","url":"https://api.github.com/users/damithsenanayake","html_url":"https://github.com/damithsenanayake","followers_url":"https://api.github.com/users/damithsenanayake/followers","following_url":"https://api.github.com/users/damithsenanayake/following{/other_user}","gists_url":"https://api.github.com/users/damithsenanayake/gists{/gist_id}","starred_url":"https://api.github.com/users/damithsenanayake/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damithsenanayake/subscriptions","organizations_url":"https://api.github.com/users/damithsenanayake/orgs","repos_url":"https://api.github.com/users/damithsenanayake/repos","events_url":"https://api.github.com/users/damithsenanayake/events{/privacy}","received_events_url":"https://api.github.com/users/damithsenanayake/received_events","type":"User","site_admin":false},"repo":{"id":37578769,"name":"carbon-kernel","full_name":"damithsenanayake/carbon-kernel","owner":{"login":"damithsenanayake","id":1591344,"avatar_url":"https://avatars.githubusercontent.com/u/1591344?v=3","gravatar_id":"","url":"https://api.github.com/users/damithsenanayake","html_url":"https://github.com/damithsenanayake","followers_url":"https://api.github.com/users/damithsenanayake/followers","following_url":"https://api.github.com/users/damithsenanayake/following{/other_user}","gists_url":"https://api.github.com/users/damithsenanayake/gists{/gist_id}","starred_url":"https://api.github.com/users/damithsenanayake/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damithsenanayake/subscriptions","organizations_url":"https://api.github.com/users/damithsenanayake/orgs","repos_url":"https://api.github.com/users/damithsenanayake/repos","events_url":"https://api.github.com/users/damithsenanayake/events{/privacy}","received_events_url":"https://api.github.com/users/damithsenanayake/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/damithsenanayake/carbon-kernel","description":null,"fork":true,"url":"https://api.github.com/repos/damithsenanayake/carbon-kernel","forks_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/forks","keys_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/teams","hooks_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/hooks","issue_events_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/issues/events{/number}","events_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/events","assignees_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/assignees{/user}","branches_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/branches{/branch}","tags_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/tags","blobs_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/git/refs{/sha}","trees_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/statuses/{sha}","languages_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/languages","stargazers_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/stargazers","contributors_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/contributors","subscribers_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/subscribers","subscription_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/subscription","commits_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/commits{/sha}","git_commits_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/git/commits{/sha}","comments_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/comments{/number}","issue_comment_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/issues/comments{/number}","contents_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/contents/{+path}","compare_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/merges","archive_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/downloads","issues_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/issues{/number}","pulls_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/pulls{/number}","milestones_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/milestones{/number}","notifications_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/labels{/name}","releases_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/releases{/id}","deployments_url":"https://api.github.com/repos/damithsenanayake/carbon-kernel/deployments","created_at":"2015-06-17T07:11:33Z","updated_at":"2015-11-17T11:19:33Z","pushed_at":"2016-02-05T06:52:37Z","git_url":"git://github.com/damithsenanayake/carbon-kernel.git","ssh_url":"git@github.com:damithsenanayake/carbon-kernel.git","clone_url":"https://github.com/damithsenanayake/carbon-kernel.git","svn_url":"https://github.com/damithsenanayake/carbon-kernel","homepage":null,"size":38339,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"wso2:4.4.x","ref":"4.4.x","sha":"8295cc2b7b00c2399d67447d17d02f9ce78683be","user":{"login":"wso2","id":533043,"avatar_url":"https://avatars.githubusercontent.com/u/533043?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"repo":{"id":16162184,"name":"carbon-kernel","full_name":"wso2/carbon-kernel","owner":{"login":"wso2","id":533043,"avatar_url":"https://avatars.githubusercontent.com/u/533043?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wso2/carbon-kernel","description":null,"fork":false,"url":"https://api.github.com/repos/wso2/carbon-kernel","forks_url":"https://api.github.com/repos/wso2/carbon-kernel/forks","keys_url":"https://api.github.com/repos/wso2/carbon-kernel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wso2/carbon-kernel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wso2/carbon-kernel/teams","hooks_url":"https://api.github.com/repos/wso2/carbon-kernel/hooks","issue_events_url":"https://api.github.com/repos/wso2/carbon-kernel/issues/events{/number}","events_url":"https://api.github.com/repos/wso2/carbon-kernel/events","assignees_url":"https://api.github.com/repos/wso2/carbon-kernel/assignees{/user}","branches_url":"https://api.github.com/repos/wso2/carbon-kernel/branches{/branch}","tags_url":"https://api.github.com/repos/wso2/carbon-kernel/tags","blobs_url":"https://api.github.com/repos/wso2/carbon-kernel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wso2/carbon-kernel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wso2/carbon-kernel/git/refs{/sha}","trees_url":"https://api.github.com/repos/wso2/carbon-kernel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wso2/carbon-kernel/statuses/{sha}","languages_url":"https://api.github.com/repos/wso2/carbon-kernel/languages","stargazers_url":"https://api.github.com/repos/wso2/carbon-kernel/stargazers","contributors_url":"https://api.github.com/repos/wso2/carbon-kernel/contributors","subscribers_url":"https://api.github.com/repos/wso2/carbon-kernel/subscribers","subscription_url":"https://api.github.com/repos/wso2/carbon-kernel/subscription","commits_url":"https://api.github.com/repos/wso2/carbon-kernel/commits{/sha}","git_commits_url":"https://api.github.com/repos/wso2/carbon-kernel/git/commits{/sha}","comments_url":"https://api.github.com/repos/wso2/carbon-kernel/comments{/number}","issue_comment_url":"https://api.github.com/repos/wso2/carbon-kernel/issues/comments{/number}","contents_url":"https://api.github.com/repos/wso2/carbon-kernel/contents/{+path}","compare_url":"https://api.github.com/repos/wso2/carbon-kernel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wso2/carbon-kernel/merges","archive_url":"https://api.github.com/repos/wso2/carbon-kernel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wso2/carbon-kernel/downloads","issues_url":"https://api.github.com/repos/wso2/carbon-kernel/issues{/number}","pulls_url":"https://api.github.com/repos/wso2/carbon-kernel/pulls{/number}","milestones_url":"https://api.github.com/repos/wso2/carbon-kernel/milestones{/number}","notifications_url":"https://api.github.com/repos/wso2/carbon-kernel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wso2/carbon-kernel/labels{/name}","releases_url":"https://api.github.com/repos/wso2/carbon-kernel/releases{/id}","deployments_url":"https://api.github.com/repos/wso2/carbon-kernel/deployments","created_at":"2014-01-23T04:23:41Z","updated_at":"2017-01-03T08:52:18Z","pushed_at":"2017-01-27T05:07:57Z","git_url":"git://github.com/wso2/carbon-kernel.git","ssh_url":"git@github.com:wso2/carbon-kernel.git","clone_url":"https://github.com/wso2/carbon-kernel.git","svn_url":"https://github.com/wso2/carbon-kernel","homepage":null,"size":45210,"stargazers_count":38,"watchers_count":38,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":289,"mirror_url":null,"open_issues_count":31,"forks":289,"open_issues":31,"watchers":38,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wso2/carbon-kernel/pulls/524"},"html":{"href":"https://github.com/wso2/carbon-kernel/pull/524"},"issue":{"href":"https://api.github.com/repos/wso2/carbon-kernel/issues/524"},"comments":{"href":"https://api.github.com/repos/wso2/carbon-kernel/issues/524/comments"},"review_comments":{"href":"https://api.github.com/repos/wso2/carbon-kernel/pulls/524/comments"},"review_comment":{"href":"https://api.github.com/repos/wso2/carbon-kernel/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wso2/carbon-kernel/pulls/524/commits"},"statuses":{"href":"https://api.github.com/repos/wso2/carbon-kernel/statuses/88b1cf36231c296a38c4804d851fa875dba652b1"}},"merged":false,"mergeable":false,"mergeable_state":"dirty","merged_by":null,"comments":4,"review_comments":0,"maintainer_can_modify":false,"commits":7,"additions":37,"deletions":5,"changed_files":6} \ No newline at end of file diff --git a/CodeQualityMatricesProject/pullReviewOutPutFile.json b/CodeQualityMatricesProject/pullReviewOutPutFile.json deleted file mode 100644 index 0637a08..0000000 --- a/CodeQualityMatricesProject/pullReviewOutPutFile.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/CodeQualityMatricesProject/searchApiOutputs/0015c02145c8ec6d3bba433f2fb5e850e1d25846.json b/CodeQualityMatricesProject/searchApiOutputs/0015c02145c8ec6d3bba433f2fb5e850e1d25846.json deleted file mode 100644 index 7334345..0000000 --- a/CodeQualityMatricesProject/searchApiOutputs/0015c02145c8ec6d3bba433f2fb5e850e1d25846.json +++ /dev/null @@ -1 +0,0 @@ -{"total_count":2,"incomplete_results":false,"items":[{"url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/657","repository_url":"https://api.github.com/repos/wso2/carbon-apimgt","labels_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/657/labels{/name}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/657/comments","events_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/657/events","html_url":"https://github.com/wso2/carbon-apimgt/pull/657","id":86646396,"number":657,"title":"Adding sso-hostobject","user":{"login":"jaadds","id":9979804,"avatar_url":"https://avatars.githubusercontent.com/u/9979804?v=3","gravatar_id":"","url":"https://api.github.com/users/jaadds","html_url":"https://github.com/jaadds","followers_url":"https://api.github.com/users/jaadds/followers","following_url":"https://api.github.com/users/jaadds/following{/other_user}","gists_url":"https://api.github.com/users/jaadds/gists{/gist_id}","starred_url":"https://api.github.com/users/jaadds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaadds/subscriptions","organizations_url":"https://api.github.com/users/jaadds/orgs","repos_url":"https://api.github.com/users/jaadds/repos","events_url":"https://api.github.com/users/jaadds/events{/privacy}","received_events_url":"https://api.github.com/users/jaadds/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2015-06-09T15:54:08Z","updated_at":"2015-06-09T15:54:16Z","closed_at":"2015-06-09T15:54:16Z","pull_request":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/657","html_url":"https://github.com/wso2/carbon-apimgt/pull/657","diff_url":"https://github.com/wso2/carbon-apimgt/pull/657.diff","patch_url":"https://github.com/wso2/carbon-apimgt/pull/657.patch"},"body":"","score":0.48381817},{"url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/656","repository_url":"https://api.github.com/repos/wso2/carbon-apimgt","labels_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/656/labels{/name}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/656/comments","events_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/656/events","html_url":"https://github.com/wso2/carbon-apimgt/pull/656","id":86642184,"number":656,"title":"Passive SSO support for API Store","user":{"login":"malinthaprasan","id":1591316,"avatar_url":"https://avatars.githubusercontent.com/u/1591316?v=3","gravatar_id":"","url":"https://api.github.com/users/malinthaprasan","html_url":"https://github.com/malinthaprasan","followers_url":"https://api.github.com/users/malinthaprasan/followers","following_url":"https://api.github.com/users/malinthaprasan/following{/other_user}","gists_url":"https://api.github.com/users/malinthaprasan/gists{/gist_id}","starred_url":"https://api.github.com/users/malinthaprasan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/malinthaprasan/subscriptions","organizations_url":"https://api.github.com/users/malinthaprasan/orgs","repos_url":"https://api.github.com/users/malinthaprasan/repos","events_url":"https://api.github.com/users/malinthaprasan/events{/privacy}","received_events_url":"https://api.github.com/users/malinthaprasan/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2015-06-09T15:41:21Z","updated_at":"2015-11-29T13:17:51Z","closed_at":"2015-06-09T17:03:44Z","pull_request":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/656","html_url":"https://github.com/wso2/carbon-apimgt/pull/656","diff_url":"https://github.com/wso2/carbon-apimgt/pull/656.diff","patch_url":"https://github.com/wso2/carbon-apimgt/pull/656.patch"},"body":"","score":0.48381817}]} \ No newline at end of file diff --git a/CodeQualityMatricesProject/searchApiOutputs/653f5325075702fb2367743559ffc03d2b596cfd.json b/CodeQualityMatricesProject/searchApiOutputs/653f5325075702fb2367743559ffc03d2b596cfd.json deleted file mode 100644 index 988bccc..0000000 --- a/CodeQualityMatricesProject/searchApiOutputs/653f5325075702fb2367743559ffc03d2b596cfd.json +++ /dev/null @@ -1 +0,0 @@ -{"total_count":1,"incomplete_results":false,"items":[{"url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/53","repository_url":"https://api.github.com/repos/wso2/carbon-apimgt","labels_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/53/labels{/name}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/53/comments","events_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/53/events","html_url":"https://github.com/wso2/carbon-apimgt/pull/53","id":60088673,"number":53,"title":"Remove hard dependency to the class 'WSO2ExternalAPIStore' Release 1.9.0","user":{"login":"binalip","id":8734514,"avatar_url":"https://avatars.githubusercontent.com/u/8734514?v=3","gravatar_id":"","url":"https://api.github.com/users/binalip","html_url":"https://github.com/binalip","followers_url":"https://api.github.com/users/binalip/followers","following_url":"https://api.github.com/users/binalip/following{/other_user}","gists_url":"https://api.github.com/users/binalip/gists{/gist_id}","starred_url":"https://api.github.com/users/binalip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/binalip/subscriptions","organizations_url":"https://api.github.com/users/binalip/orgs","repos_url":"https://api.github.com/users/binalip/repos","events_url":"https://api.github.com/users/binalip/events{/privacy}","received_events_url":"https://api.github.com/users/binalip/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2015-03-06T11:09:55Z","updated_at":"2015-03-06T11:35:08Z","closed_at":"2015-03-06T11:35:08Z","pull_request":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/53","html_url":"https://github.com/wso2/carbon-apimgt/pull/53","diff_url":"https://github.com/wso2/carbon-apimgt/pull/53.diff","patch_url":"https://github.com/wso2/carbon-apimgt/pull/53.patch"},"body":"'WSO2APIStore' class is no longer directly referred from the API Manager code. The class name for the external API store reads from the 'default-external-api-store.xml'.A new attribute which is 'class' is holding the name for the External API Store class.\n","score":0.48383135}]} \ No newline at end of file diff --git a/CodeQualityMatricesProject/searchApiOutputs/75e02613db654fa15679f8e77bc282fcb30de3a9.json b/CodeQualityMatricesProject/searchApiOutputs/75e02613db654fa15679f8e77bc282fcb30de3a9.json deleted file mode 100644 index 9191937..0000000 --- a/CodeQualityMatricesProject/searchApiOutputs/75e02613db654fa15679f8e77bc282fcb30de3a9.json +++ /dev/null @@ -1 +0,0 @@ -{"total_count":2,"incomplete_results":false,"items":[{"url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1590","repository_url":"https://api.github.com/repos/wso2/carbon-apimgt","labels_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1590/labels{/name}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1590/comments","events_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1590/events","html_url":"https://github.com/wso2/carbon-apimgt/pull/1590","id":131551865,"number":1590,"title":"fix for APIMANAGER-4524","user":{"login":"chamilaadhi","id":4861150,"avatar_url":"https://avatars.githubusercontent.com/u/4861150?v=3","gravatar_id":"","url":"https://api.github.com/users/chamilaadhi","html_url":"https://github.com/chamilaadhi","followers_url":"https://api.github.com/users/chamilaadhi/followers","following_url":"https://api.github.com/users/chamilaadhi/following{/other_user}","gists_url":"https://api.github.com/users/chamilaadhi/gists{/gist_id}","starred_url":"https://api.github.com/users/chamilaadhi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chamilaadhi/subscriptions","organizations_url":"https://api.github.com/users/chamilaadhi/orgs","repos_url":"https://api.github.com/users/chamilaadhi/repos","events_url":"https://api.github.com/users/chamilaadhi/events{/privacy}","received_events_url":"https://api.github.com/users/chamilaadhi/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-02-05T04:29:59Z","updated_at":"2016-02-05T04:34:10Z","closed_at":"2016-02-05T04:34:10Z","pull_request":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/1590","html_url":"https://github.com/wso2/carbon-apimgt/pull/1590","diff_url":"https://github.com/wso2/carbon-apimgt/pull/1590.diff","patch_url":"https://github.com/wso2/carbon-apimgt/pull/1590.patch"},"body":"","score":0.48383135},{"url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1594","repository_url":"https://api.github.com/repos/wso2/carbon-apimgt","labels_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1594/labels{/name}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1594/comments","events_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1594/events","html_url":"https://github.com/wso2/carbon-apimgt/pull/1594","id":132100018,"number":1594,"title":"Merged Master to Release 1.11.x","user":{"login":"bhathiya","id":3960742,"avatar_url":"https://avatars.githubusercontent.com/u/3960742?v=3","gravatar_id":"","url":"https://api.github.com/users/bhathiya","html_url":"https://github.com/bhathiya","followers_url":"https://api.github.com/users/bhathiya/followers","following_url":"https://api.github.com/users/bhathiya/following{/other_user}","gists_url":"https://api.github.com/users/bhathiya/gists{/gist_id}","starred_url":"https://api.github.com/users/bhathiya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bhathiya/subscriptions","organizations_url":"https://api.github.com/users/bhathiya/orgs","repos_url":"https://api.github.com/users/bhathiya/repos","events_url":"https://api.github.com/users/bhathiya/events{/privacy}","received_events_url":"https://api.github.com/users/bhathiya/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-02-08T10:11:51Z","updated_at":"2016-02-08T10:13:33Z","closed_at":"2016-02-08T10:13:33Z","pull_request":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/1594","html_url":"https://github.com/wso2/carbon-apimgt/pull/1594","diff_url":"https://github.com/wso2/carbon-apimgt/pull/1594.diff","patch_url":"https://github.com/wso2/carbon-apimgt/pull/1594.patch"},"body":"","score":0.48383135}]} \ No newline at end of file diff --git a/CodeQualityMatricesProject/searchApiOutputs/82dc0b0272253dcf21d222ad2ac19d35a71198d7.json b/CodeQualityMatricesProject/searchApiOutputs/82dc0b0272253dcf21d222ad2ac19d35a71198d7.json deleted file mode 100644 index 5e58eeb..0000000 --- a/CodeQualityMatricesProject/searchApiOutputs/82dc0b0272253dcf21d222ad2ac19d35a71198d7.json +++ /dev/null @@ -1 +0,0 @@ -{"total_count":2,"incomplete_results":false,"items":[{"url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/178","repository_url":"https://api.github.com/repos/wso2/carbon-apimgt","labels_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/178/labels{/name}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/178/comments","events_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/178/events","html_url":"https://github.com/wso2/carbon-apimgt/pull/178","id":67375724,"number":178,"title":"Fixing OIDC login in store and publisher","user":{"login":"ranga-siriwardena","id":8995220,"avatar_url":"https://avatars.githubusercontent.com/u/8995220?v=3","gravatar_id":"","url":"https://api.github.com/users/ranga-siriwardena","html_url":"https://github.com/ranga-siriwardena","followers_url":"https://api.github.com/users/ranga-siriwardena/followers","following_url":"https://api.github.com/users/ranga-siriwardena/following{/other_user}","gists_url":"https://api.github.com/users/ranga-siriwardena/gists{/gist_id}","starred_url":"https://api.github.com/users/ranga-siriwardena/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ranga-siriwardena/subscriptions","organizations_url":"https://api.github.com/users/ranga-siriwardena/orgs","repos_url":"https://api.github.com/users/ranga-siriwardena/repos","events_url":"https://api.github.com/users/ranga-siriwardena/events{/privacy}","received_events_url":"https://api.github.com/users/ranga-siriwardena/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2015-04-09T14:35:35Z","updated_at":"2015-04-09T14:35:40Z","closed_at":"2015-04-09T14:35:40Z","pull_request":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/178","html_url":"https://github.com/wso2/carbon-apimgt/pull/178","diff_url":"https://github.com/wso2/carbon-apimgt/pull/178.diff","patch_url":"https://github.com/wso2/carbon-apimgt/pull/178.patch"},"body":"","score":0.48383135},{"url":"https://api.github.com/repos/udarakr/carbon-apimgt/issues/29","repository_url":"https://api.github.com/repos/udarakr/carbon-apimgt","labels_url":"https://api.github.com/repos/udarakr/carbon-apimgt/issues/29/labels{/name}","comments_url":"https://api.github.com/repos/udarakr/carbon-apimgt/issues/29/comments","events_url":"https://api.github.com/repos/udarakr/carbon-apimgt/issues/29/events","html_url":"https://github.com/udarakr/carbon-apimgt/pull/29","id":81786218,"number":29,"title":"Sync with upstream","user":{"login":"udarakr","id":1343257,"avatar_url":"https://avatars.githubusercontent.com/u/1343257?v=3","gravatar_id":"","url":"https://api.github.com/users/udarakr","html_url":"https://github.com/udarakr","followers_url":"https://api.github.com/users/udarakr/followers","following_url":"https://api.github.com/users/udarakr/following{/other_user}","gists_url":"https://api.github.com/users/udarakr/gists{/gist_id}","starred_url":"https://api.github.com/users/udarakr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/udarakr/subscriptions","organizations_url":"https://api.github.com/users/udarakr/orgs","repos_url":"https://api.github.com/users/udarakr/repos","events_url":"https://api.github.com/users/udarakr/events{/privacy}","received_events_url":"https://api.github.com/users/udarakr/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2015-05-28T06:28:48Z","updated_at":"2015-05-28T06:28:57Z","closed_at":"2015-05-28T06:28:57Z","pull_request":{"url":"https://api.github.com/repos/udarakr/carbon-apimgt/pulls/29","html_url":"https://github.com/udarakr/carbon-apimgt/pull/29","diff_url":"https://github.com/udarakr/carbon-apimgt/pull/29.diff","patch_url":"https://github.com/udarakr/carbon-apimgt/pull/29.patch"},"body":"","score":0.48383135}]} \ No newline at end of file diff --git a/CodeQualityMatricesProject/searchApiOutputs/9f63d2f6ec285a65e69ec71765e55409db103e03.json b/CodeQualityMatricesProject/searchApiOutputs/9f63d2f6ec285a65e69ec71765e55409db103e03.json deleted file mode 100644 index 6de1066..0000000 --- a/CodeQualityMatricesProject/searchApiOutputs/9f63d2f6ec285a65e69ec71765e55409db103e03.json +++ /dev/null @@ -1 +0,0 @@ -{"total_count":0,"incomplete_results":false,"items":[]} \ No newline at end of file diff --git a/CodeQualityMatricesProject/searchApiOutputs/b483567c105e223d7edc397526017df22fe8aa43.json b/CodeQualityMatricesProject/searchApiOutputs/b483567c105e223d7edc397526017df22fe8aa43.json deleted file mode 100644 index 6de1066..0000000 --- a/CodeQualityMatricesProject/searchApiOutputs/b483567c105e223d7edc397526017df22fe8aa43.json +++ /dev/null @@ -1 +0,0 @@ -{"total_count":0,"incomplete_results":false,"items":[]} \ No newline at end of file diff --git a/CodeQualityMatricesProject/searchApiOutputs/cd4eb84b7cfd161b4dad565bcd698e824e1ec099.json b/CodeQualityMatricesProject/searchApiOutputs/cd4eb84b7cfd161b4dad565bcd698e824e1ec099.json deleted file mode 100644 index ae55b35..0000000 --- a/CodeQualityMatricesProject/searchApiOutputs/cd4eb84b7cfd161b4dad565bcd698e824e1ec099.json +++ /dev/null @@ -1 +0,0 @@ -{"total_count":1,"incomplete_results":false,"items":[{"url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1703","repository_url":"https://api.github.com/repos/wso2/carbon-apimgt","labels_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1703/labels{/name}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1703/comments","events_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1703/events","html_url":"https://github.com/wso2/carbon-apimgt/pull/1703","id":141521662,"number":1703,"title":"merge am feature branch to throttle-feature branch","user":{"login":"chamilaadhi","id":4861150,"avatar_url":"https://avatars.githubusercontent.com/u/4861150?v=3","gravatar_id":"","url":"https://api.github.com/users/chamilaadhi","html_url":"https://github.com/chamilaadhi","followers_url":"https://api.github.com/users/chamilaadhi/followers","following_url":"https://api.github.com/users/chamilaadhi/following{/other_user}","gists_url":"https://api.github.com/users/chamilaadhi/gists{/gist_id}","starred_url":"https://api.github.com/users/chamilaadhi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chamilaadhi/subscriptions","organizations_url":"https://api.github.com/users/chamilaadhi/orgs","repos_url":"https://api.github.com/users/chamilaadhi/repos","events_url":"https://api.github.com/users/chamilaadhi/events{/privacy}","received_events_url":"https://api.github.com/users/chamilaadhi/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-03-17T09:06:21Z","updated_at":"2016-03-17T09:06:29Z","closed_at":"2016-03-17T09:06:29Z","pull_request":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/1703","html_url":"https://github.com/wso2/carbon-apimgt/pull/1703","diff_url":"https://github.com/wso2/carbon-apimgt/pull/1703.diff","patch_url":"https://github.com/wso2/carbon-apimgt/pull/1703.patch"},"body":"","score":0.48381817}]} \ No newline at end of file diff --git a/CodeQualityMatricesProject/searchApiOutputs/dba207449a58b65ae9c7bdac6f60ce5ef474fb58.json b/CodeQualityMatricesProject/searchApiOutputs/dba207449a58b65ae9c7bdac6f60ce5ef474fb58.json deleted file mode 100644 index 0f6f5c1..0000000 --- a/CodeQualityMatricesProject/searchApiOutputs/dba207449a58b65ae9c7bdac6f60ce5ef474fb58.json +++ /dev/null @@ -1 +0,0 @@ -{"total_count":3,"incomplete_results":false,"items":[{"url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/2868","repository_url":"https://api.github.com/repos/wso2/carbon-apimgt","labels_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/2868/labels{/name}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/2868/comments","events_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/2868/events","html_url":"https://github.com/wso2/carbon-apimgt/pull/2868","id":167874806,"number":2868,"title":"Improvements to saml2 sso validations","user":{"login":"lalaji","id":1701148,"avatar_url":"https://avatars.githubusercontent.com/u/1701148?v=3","gravatar_id":"","url":"https://api.github.com/users/lalaji","html_url":"https://github.com/lalaji","followers_url":"https://api.github.com/users/lalaji/followers","following_url":"https://api.github.com/users/lalaji/following{/other_user}","gists_url":"https://api.github.com/users/lalaji/gists{/gist_id}","starred_url":"https://api.github.com/users/lalaji/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lalaji/subscriptions","organizations_url":"https://api.github.com/users/lalaji/orgs","repos_url":"https://api.github.com/users/lalaji/repos","events_url":"https://api.github.com/users/lalaji/events{/privacy}","received_events_url":"https://api.github.com/users/lalaji/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-27T14:54:28Z","updated_at":"2016-07-27T14:55:22Z","closed_at":"2016-07-27T14:55:22Z","pull_request":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/2868","html_url":"https://github.com/wso2/carbon-apimgt/pull/2868","diff_url":"https://github.com/wso2/carbon-apimgt/pull/2868.diff","patch_url":"https://github.com/wso2/carbon-apimgt/pull/2868.patch"},"body":"","score":0.48381817},{"url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/2873","repository_url":"https://api.github.com/repos/wso2/carbon-apimgt","labels_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/2873/labels{/name}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/2873/comments","events_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/2873/events","html_url":"https://github.com/wso2/carbon-apimgt/pull/2873","id":168296155,"number":2873,"title":"Merged release branch back to master","user":{"login":"abimarank","id":2951657,"avatar_url":"https://avatars.githubusercontent.com/u/2951657?v=3","gravatar_id":"","url":"https://api.github.com/users/abimarank","html_url":"https://github.com/abimarank","followers_url":"https://api.github.com/users/abimarank/followers","following_url":"https://api.github.com/users/abimarank/following{/other_user}","gists_url":"https://api.github.com/users/abimarank/gists{/gist_id}","starred_url":"https://api.github.com/users/abimarank/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abimarank/subscriptions","organizations_url":"https://api.github.com/users/abimarank/orgs","repos_url":"https://api.github.com/users/abimarank/repos","events_url":"https://api.github.com/users/abimarank/events{/privacy}","received_events_url":"https://api.github.com/users/abimarank/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-29T10:27:10Z","updated_at":"2016-07-29T10:27:18Z","closed_at":"2016-07-29T10:27:17Z","pull_request":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/2873","html_url":"https://github.com/wso2/carbon-apimgt/pull/2873","diff_url":"https://github.com/wso2/carbon-apimgt/pull/2873.diff","patch_url":"https://github.com/wso2/carbon-apimgt/pull/2873.patch"},"body":"","score":0.48381817},{"url":"https://api.github.com/repos/sanjeewa-malalgoda/carbon-apimgt/issues/3","repository_url":"https://api.github.com/repos/sanjeewa-malalgoda/carbon-apimgt","labels_url":"https://api.github.com/repos/sanjeewa-malalgoda/carbon-apimgt/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/sanjeewa-malalgoda/carbon-apimgt/issues/3/comments","events_url":"https://api.github.com/repos/sanjeewa-malalgoda/carbon-apimgt/issues/3/events","html_url":"https://github.com/sanjeewa-malalgoda/carbon-apimgt/pull/3","id":172398042,"number":3,"title":"test1","user":{"login":"sanjeewa-malalgoda","id":7975153,"avatar_url":"https://avatars.githubusercontent.com/u/7975153?v=3","gravatar_id":"","url":"https://api.github.com/users/sanjeewa-malalgoda","html_url":"https://github.com/sanjeewa-malalgoda","followers_url":"https://api.github.com/users/sanjeewa-malalgoda/followers","following_url":"https://api.github.com/users/sanjeewa-malalgoda/following{/other_user}","gists_url":"https://api.github.com/users/sanjeewa-malalgoda/gists{/gist_id}","starred_url":"https://api.github.com/users/sanjeewa-malalgoda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sanjeewa-malalgoda/subscriptions","organizations_url":"https://api.github.com/users/sanjeewa-malalgoda/orgs","repos_url":"https://api.github.com/users/sanjeewa-malalgoda/repos","events_url":"https://api.github.com/users/sanjeewa-malalgoda/events{/privacy}","received_events_url":"https://api.github.com/users/sanjeewa-malalgoda/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-22T08:45:37Z","updated_at":"2017-01-03T07:09:02Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/sanjeewa-malalgoda/carbon-apimgt/pulls/3","html_url":"https://github.com/sanjeewa-malalgoda/carbon-apimgt/pull/3","diff_url":"https://github.com/sanjeewa-malalgoda/carbon-apimgt/pull/3.diff","patch_url":"https://github.com/sanjeewa-malalgoda/carbon-apimgt/pull/3.patch"},"body":"","score":0.48378763}]} \ No newline at end of file diff --git a/CodeQualityMatricesProject/searchApiOutputs/dce43d15b1d63af642cc562afc3c63812c45d84d.json b/CodeQualityMatricesProject/searchApiOutputs/dce43d15b1d63af642cc562afc3c63812c45d84d.json deleted file mode 100644 index ea355dd..0000000 --- a/CodeQualityMatricesProject/searchApiOutputs/dce43d15b1d63af642cc562afc3c63812c45d84d.json +++ /dev/null @@ -1 +0,0 @@ -{"total_count":1,"incomplete_results":false,"items":[{"url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1120","repository_url":"https://api.github.com/repos/wso2/carbon-apimgt","labels_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1120/labels{/name}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1120/comments","events_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1120/events","html_url":"https://github.com/wso2/carbon-apimgt/pull/1120","id":111578113,"number":1120,"title":"Adding missing codes with release-1.9.1 branch in /features","user":{"login":"malinthaprasan","id":1591316,"avatar_url":"https://avatars.githubusercontent.com/u/1591316?v=3","gravatar_id":"","url":"https://api.github.com/users/malinthaprasan","html_url":"https://github.com/malinthaprasan","followers_url":"https://api.github.com/users/malinthaprasan/followers","following_url":"https://api.github.com/users/malinthaprasan/following{/other_user}","gists_url":"https://api.github.com/users/malinthaprasan/gists{/gist_id}","starred_url":"https://api.github.com/users/malinthaprasan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/malinthaprasan/subscriptions","organizations_url":"https://api.github.com/users/malinthaprasan/orgs","repos_url":"https://api.github.com/users/malinthaprasan/repos","events_url":"https://api.github.com/users/malinthaprasan/events{/privacy}","received_events_url":"https://api.github.com/users/malinthaprasan/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2015-10-15T09:28:44Z","updated_at":"2015-10-15T09:32:20Z","closed_at":"2015-10-15T09:32:20Z","pull_request":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/1120","html_url":"https://github.com/wso2/carbon-apimgt/pull/1120","diff_url":"https://github.com/wso2/carbon-apimgt/pull/1120.diff","patch_url":"https://github.com/wso2/carbon-apimgt/pull/1120.patch"},"body":"","score":0.48383135}]} \ No newline at end of file diff --git a/CodeQualityMatricesProject/searchApiOutputs/eccc3deead1bc3e07ac281d0ab12cdc177206831.json b/CodeQualityMatricesProject/searchApiOutputs/eccc3deead1bc3e07ac281d0ab12cdc177206831.json deleted file mode 100644 index e9abbbd..0000000 --- a/CodeQualityMatricesProject/searchApiOutputs/eccc3deead1bc3e07ac281d0ab12cdc177206831.json +++ /dev/null @@ -1 +0,0 @@ -{"total_count":2,"incomplete_results":false,"items":[{"url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1594","repository_url":"https://api.github.com/repos/wso2/carbon-apimgt","labels_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1594/labels{/name}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1594/comments","events_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1594/events","html_url":"https://github.com/wso2/carbon-apimgt/pull/1594","id":132100018,"number":1594,"title":"Merged Master to Release 1.11.x","user":{"login":"bhathiya","id":3960742,"avatar_url":"https://avatars.githubusercontent.com/u/3960742?v=3","gravatar_id":"","url":"https://api.github.com/users/bhathiya","html_url":"https://github.com/bhathiya","followers_url":"https://api.github.com/users/bhathiya/followers","following_url":"https://api.github.com/users/bhathiya/following{/other_user}","gists_url":"https://api.github.com/users/bhathiya/gists{/gist_id}","starred_url":"https://api.github.com/users/bhathiya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bhathiya/subscriptions","organizations_url":"https://api.github.com/users/bhathiya/orgs","repos_url":"https://api.github.com/users/bhathiya/repos","events_url":"https://api.github.com/users/bhathiya/events{/privacy}","received_events_url":"https://api.github.com/users/bhathiya/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-02-08T10:11:51Z","updated_at":"2016-02-08T10:13:33Z","closed_at":"2016-02-08T10:13:33Z","pull_request":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/1594","html_url":"https://github.com/wso2/carbon-apimgt/pull/1594","diff_url":"https://github.com/wso2/carbon-apimgt/pull/1594.diff","patch_url":"https://github.com/wso2/carbon-apimgt/pull/1594.patch"},"body":"","score":0.48383135},{"url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1584","repository_url":"https://api.github.com/repos/wso2/carbon-apimgt","labels_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1584/labels{/name}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1584/comments","events_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1584/events","html_url":"https://github.com/wso2/carbon-apimgt/pull/1584","id":130588153,"number":1584,"title":"fix for APIMANAGER-4509","user":{"login":"chamilaadhi","id":4861150,"avatar_url":"https://avatars.githubusercontent.com/u/4861150?v=3","gravatar_id":"","url":"https://api.github.com/users/chamilaadhi","html_url":"https://github.com/chamilaadhi","followers_url":"https://api.github.com/users/chamilaadhi/followers","following_url":"https://api.github.com/users/chamilaadhi/following{/other_user}","gists_url":"https://api.github.com/users/chamilaadhi/gists{/gist_id}","starred_url":"https://api.github.com/users/chamilaadhi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chamilaadhi/subscriptions","organizations_url":"https://api.github.com/users/chamilaadhi/orgs","repos_url":"https://api.github.com/users/chamilaadhi/repos","events_url":"https://api.github.com/users/chamilaadhi/events{/privacy}","received_events_url":"https://api.github.com/users/chamilaadhi/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-02-02T06:25:44Z","updated_at":"2016-02-02T06:25:52Z","closed_at":"2016-02-02T06:25:52Z","pull_request":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/1584","html_url":"https://github.com/wso2/carbon-apimgt/pull/1584","diff_url":"https://github.com/wso2/carbon-apimgt/pull/1584.diff","patch_url":"https://github.com/wso2/carbon-apimgt/pull/1584.patch"},"body":"","score":0.48383135}]} \ No newline at end of file diff --git a/CodeQualityMatricesProject/searchApiOutputs/f55747f2501215e8e56eb879b12998795315d15c.json b/CodeQualityMatricesProject/searchApiOutputs/f55747f2501215e8e56eb879b12998795315d15c.json deleted file mode 100644 index b53e36a..0000000 --- a/CodeQualityMatricesProject/searchApiOutputs/f55747f2501215e8e56eb879b12998795315d15c.json +++ /dev/null @@ -1 +0,0 @@ -{"total_count":3,"incomplete_results":false,"items":[{"url":"https://api.github.com/repos/tharindu1st/carbon-apimgt/issues/6","repository_url":"https://api.github.com/repos/tharindu1st/carbon-apimgt","labels_url":"https://api.github.com/repos/tharindu1st/carbon-apimgt/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/tharindu1st/carbon-apimgt/issues/6/comments","events_url":"https://api.github.com/repos/tharindu1st/carbon-apimgt/issues/6/events","html_url":"https://github.com/tharindu1st/carbon-apimgt/pull/6","id":137556039,"number":6,"title":"Feature execution merge","user":{"login":"jranabahu","id":3318658,"avatar_url":"https://avatars.githubusercontent.com/u/3318658?v=3","gravatar_id":"","url":"https://api.github.com/users/jranabahu","html_url":"https://github.com/jranabahu","followers_url":"https://api.github.com/users/jranabahu/followers","following_url":"https://api.github.com/users/jranabahu/following{/other_user}","gists_url":"https://api.github.com/users/jranabahu/gists{/gist_id}","starred_url":"https://api.github.com/users/jranabahu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jranabahu/subscriptions","organizations_url":"https://api.github.com/users/jranabahu/orgs","repos_url":"https://api.github.com/users/jranabahu/repos","events_url":"https://api.github.com/users/jranabahu/events{/privacy}","received_events_url":"https://api.github.com/users/jranabahu/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-03-01T12:10:40Z","updated_at":"2016-03-01T12:11:23Z","closed_at":"2016-03-01T12:11:23Z","pull_request":{"url":"https://api.github.com/repos/tharindu1st/carbon-apimgt/pulls/6","html_url":"https://github.com/tharindu1st/carbon-apimgt/pull/6","diff_url":"https://github.com/tharindu1st/carbon-apimgt/pull/6.diff","patch_url":"https://github.com/tharindu1st/carbon-apimgt/pull/6.patch"},"body":"","score":0.48387566},{"url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1618","repository_url":"https://api.github.com/repos/wso2/carbon-apimgt","labels_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1618/labels{/name}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1618/comments","events_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1618/events","html_url":"https://github.com/wso2/carbon-apimgt/pull/1618","id":133920071,"number":1618,"title":"Adding new wso2 bootstrap theme","user":{"login":"lakmali","id":3793436,"avatar_url":"https://avatars.githubusercontent.com/u/3793436?v=3","gravatar_id":"","url":"https://api.github.com/users/lakmali","html_url":"https://github.com/lakmali","followers_url":"https://api.github.com/users/lakmali/followers","following_url":"https://api.github.com/users/lakmali/following{/other_user}","gists_url":"https://api.github.com/users/lakmali/gists{/gist_id}","starred_url":"https://api.github.com/users/lakmali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lakmali/subscriptions","organizations_url":"https://api.github.com/users/lakmali/orgs","repos_url":"https://api.github.com/users/lakmali/repos","events_url":"https://api.github.com/users/lakmali/events{/privacy}","received_events_url":"https://api.github.com/users/lakmali/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-02-16T08:55:09Z","updated_at":"2016-02-16T08:57:14Z","closed_at":"2016-02-16T08:57:14Z","pull_request":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/1618","html_url":"https://github.com/wso2/carbon-apimgt/pull/1618","diff_url":"https://github.com/wso2/carbon-apimgt/pull/1618.diff","patch_url":"https://github.com/wso2/carbon-apimgt/pull/1618.patch"},"body":"","score":0.4838181},{"url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1703","repository_url":"https://api.github.com/repos/wso2/carbon-apimgt","labels_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1703/labels{/name}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1703/comments","events_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1703/events","html_url":"https://github.com/wso2/carbon-apimgt/pull/1703","id":141521662,"number":1703,"title":"merge am feature branch to throttle-feature branch","user":{"login":"chamilaadhi","id":4861150,"avatar_url":"https://avatars.githubusercontent.com/u/4861150?v=3","gravatar_id":"","url":"https://api.github.com/users/chamilaadhi","html_url":"https://github.com/chamilaadhi","followers_url":"https://api.github.com/users/chamilaadhi/followers","following_url":"https://api.github.com/users/chamilaadhi/following{/other_user}","gists_url":"https://api.github.com/users/chamilaadhi/gists{/gist_id}","starred_url":"https://api.github.com/users/chamilaadhi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chamilaadhi/subscriptions","organizations_url":"https://api.github.com/users/chamilaadhi/orgs","repos_url":"https://api.github.com/users/chamilaadhi/repos","events_url":"https://api.github.com/users/chamilaadhi/events{/privacy}","received_events_url":"https://api.github.com/users/chamilaadhi/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-03-17T09:06:21Z","updated_at":"2016-03-17T09:06:29Z","closed_at":"2016-03-17T09:06:29Z","pull_request":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/1703","html_url":"https://github.com/wso2/carbon-apimgt/pull/1703","diff_url":"https://github.com/wso2/carbon-apimgt/pull/1703.diff","patch_url":"https://github.com/wso2/carbon-apimgt/pull/1703.patch"},"body":"","score":0.4838181}]} \ No newline at end of file From 2440d9f88135e2b58166a48b74664abc8d2162d5 Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 10 Mar 2017 11:43:08 +0530 Subject: [PATCH 05/62] Add log messages --- CodeQualityMatricesProject/.gitignore | 3 +- .../wso2/code/quality/matrices/MainClass.java | 8 ++++- .../com/wso2/code/quality/matrices/Pmt.java | 4 ++- .../code/quality/matrices/RestApiCaller.java | 11 +++--- .../src/main/resources/log4j.properties | 34 +++++++++++++++++++ 5 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 CodeQualityMatricesProject/src/main/resources/log4j.properties diff --git a/CodeQualityMatricesProject/.gitignore b/CodeQualityMatricesProject/.gitignore index 77bb683..e9bca96 100644 --- a/CodeQualityMatricesProject/.gitignore +++ b/CodeQualityMatricesProject/.gitignore @@ -8,9 +8,10 @@ target *.iml *.iws *.ipr +*.json .idea # Package Files # *.jar *.war -*.ear \ No newline at end of file +*.ear diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index 549bee6..21bbd23 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -21,6 +21,7 @@ import org.json.JSONArray; import java.util.Set; +import java.util.logging.Logger; /** * This is the class having the main method of this application @@ -28,7 +29,10 @@ * should be passed as command line arguments when running the application */ public class MainClass { + public static Logger logger = Logger.getLogger(MainClass.class.getName()); + public static void main(String[] args) { + logger.info(" Main method got executed"); String pmtToken = args[0]; String patchId = args[1]; @@ -37,14 +41,16 @@ public static void main(String[] args) { RestApiCaller restApiCaller = new RestApiCaller(); JSONArray jsonArray = (JSONArray) restApiCaller.callingTheAPI(pmtUrl, pmtToken, false, false); - + logger.info("JSON response is received successfully from WSO2 PMT for the given patch " + args[1]); Pmt pmt = new Pmt(); String[] commitsInTheGivenPatch = pmt.getThePublicGitCommitId(jsonArray); + logger.info("Commits received from WSO2 PMT are saved in an array successfully"); String gitHubToken = args[2]; BlameCommit blameCommit = new BlameCommit(); Set commitHashObtainedForPRReview = blameCommit.obtainingRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); + logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); Reviewers reviewers = new Reviewers(); reviewers.findingReviewers(commitHashObtainedForPRReview, gitHubToken); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java index 854ee77..3e6e144 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java @@ -18,6 +18,7 @@ package com.wso2.code.quality.matrices; +import org.apache.log4j.Logger; import org.json.JSONArray; import org.json.JSONObject; @@ -27,6 +28,7 @@ public class Pmt { private String[] patchInformation_svnRevisionpublic; + static Logger pmtLogger = Logger.getLogger(Pmt.class.getName()); /** @@ -35,7 +37,6 @@ public class Pmt { * @param jsonArray jsonarray containing the output received from WSO2 PMT for the given patch * @return a copy of the array containing the commit hashes that belongs to the given patch */ - public String[] getThePublicGitCommitId(JSONArray jsonArray) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = (JSONObject) jsonArray.get(i); @@ -47,6 +48,7 @@ public String[] getThePublicGitCommitId(JSONArray jsonArray) { for (int j = 0; j < tempCommitsJSONArray.length(); j++) { patchInformation_svnRevisionpublic[j] = ((String) tempCommitsJSONArray.get(j)).trim(); // for ommiting the white spaces at the begingin and end of the commits } + pmtLogger.info("the commits hashes obtained from WSO2 PMT are successfully saved to an array"); System.out.println("The commit Ids are"); // for printing all the commits ID associated with a patch for (String tmp : patchInformation_svnRevisionpublic) { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java index 725e084..d98e0de 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java @@ -27,6 +27,7 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import org.apache.log4j.Logger; import org.json.JSONTokener; import org.json.JSONObject; import org.json.JSONArray; @@ -36,13 +37,14 @@ */ public class RestApiCaller { + static Logger restApiCallerLogger= Logger.getLogger(RestApiCaller.class.getName()); /** * calling the relevant API and saving the output to a file * - * @param URL url of the REST API to be called - * @param token either the WSO2 PMT access token or giihub.com access token - * @param requireCommitHeader should be true for accessing the github commit search API and false otherwise - * @param requireReviewHeader should be true for accessing the github review API or false otherwise + * @param URL url of the REST API to be called + * @param token either the WSO2 PMT access token or giihub.com access token + * @param requireCommitHeader should be true for accessing the github commit search API and false otherwise + * @param requireReviewHeader should be true for accessing the github review API or false otherwise */ public Object callingTheAPI(String URL, String token, boolean requireCommitHeader, boolean requireReviewHeader) { @@ -95,6 +97,7 @@ public Object callingTheAPI(String URL, String token, boolean requireCommitHeade JSONArray jsonArray = (JSONArray) json; returnedObject = jsonArray; } + restApiCallerLogger.info("JSON response is passed after calling the given REST API"); break; case 401: // to handle Response code 401: Unauthorized diff --git a/CodeQualityMatricesProject/src/main/resources/log4j.properties b/CodeQualityMatricesProject/src/main/resources/log4j.properties new file mode 100644 index 0000000..fe62898 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/resources/log4j.properties @@ -0,0 +1,34 @@ +# +# Copyright (c) 2017 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# WSO2 Inc. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# + +# Define the root logger with appender file +logs =/home/kasun/Documents/log4j +log4j.rootLogger = DEBUG, FileAppender + +# Define the file appender +log4j.appender.FileAppender= org.apache.log4j.RollingFileAppender +log4j.appender.FileAppender.File=${logs}/log.out +log4j.appender.FileAppender.MaxFileSize=10KB +log4j.appender.FileAppender.MaxBackupIndex=2 + +# Define the layout for file appender +log4j.appender.FileAppender.layout= org.apache.log4j.PatternLayout +log4j.appender.FileAppender.layout.conversionPattern=%d{yyyy-MM-dd}-5p--10c:%m%n + + + From 9424e91ff9863c8046f35ab0fdb5d01ce7a6911e Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 10 Mar 2017 11:43:08 +0530 Subject: [PATCH 06/62] Add log messages Add log messages for all classes --- CodeQualityMatricesProject/.gitignore | 3 +- .../code/quality/matrices/BlameCommit.java | 27 +++++++++++++--- .../wso2/code/quality/matrices/MainClass.java | 11 +++++++ .../com/wso2/code/quality/matrices/Pmt.java | 6 +++- .../code/quality/matrices/RestApiCaller.java | 25 +++++++++------ .../wso2/code/quality/matrices/Reviewers.java | 7 +++- .../src/main/resources/log4j.properties | 32 +++++++++++++++++++ 7 files changed, 94 insertions(+), 17 deletions(-) create mode 100644 CodeQualityMatricesProject/src/main/resources/log4j.properties diff --git a/CodeQualityMatricesProject/.gitignore b/CodeQualityMatricesProject/.gitignore index 77bb683..e9bca96 100644 --- a/CodeQualityMatricesProject/.gitignore +++ b/CodeQualityMatricesProject/.gitignore @@ -8,9 +8,10 @@ target *.iml *.iws *.ipr +*.json .idea # Package Files # *.jar *.war -*.ear \ No newline at end of file +*.ear diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java index c5d9382..6b8def7 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java @@ -39,6 +39,7 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import org.apache.log4j.Logger; import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONTokener; @@ -58,6 +59,9 @@ public class BlameCommit extends RestApiCaller { protected Set commitHashObtainedForPRReview = new HashSet(); // relevant commits in old file that need to find the PR Reviewers private String repoLocation[]; + private static final Logger BlameCommitLogger = Logger.getLogger(BlameCommit.class.getName()); + + public String getUrlForSearchingCommits() { return urlForObtainingCommits; } @@ -111,6 +115,7 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, //adding the repo name to the array repoLocation[i] = (String) repositoryJsonObject.get("full_name"); } + BlameCommitLogger.info("Repo names having the given commit are successfully saved in an array"); // for running through the repoName Array for (int i = 0; i < repoLocation.length; i++) { @@ -120,6 +125,7 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, lineRangesChanged.clear(); //authorNames.clear(); callingToGetFilesChanged(repoLocation[i], commitHash, gitHubToken); + iteratingOver(repoLocation[i], commitHash, gitHubToken); } } @@ -143,6 +149,7 @@ public void callingToGetFilesChanged(String repoLocation, String commitHash, Str rootJsonObject = (JSONObject) callingTheAPI(getUrlForGetingFilesChanged(), gitHubToken, false, false); //calling savingRelaventFileNamesAndEditLineNumbers method to read the above saved json output savingRelaventFileNamesAndEditLineNumbers(rootJsonObject); + BlameCommitLogger.info("Relevant file names and their line ranges which being affected by the given commit are saved successfully"); } /** @@ -225,6 +232,7 @@ public void iteratingOver(String repoLocation, String commitHash, String gitHubT // calling the graphql API for getting blame information for the current file and saving it in a location. rootJsonObject = (JSONObject) callingGraphQl(graphqlApiJsonObject, gitHubToken); } catch (IOException e) { + BlameCommitLogger.error("IO exception occurred when calling the github graphQL API ", e); e.printStackTrace(); } // reading the above saved output for the current selected file name @@ -233,6 +241,7 @@ public void iteratingOver(String repoLocation, String commitHash, String gitHubT // parent commit hashes are stored in the arraylist for the given file iteratingOverForFindingAuthors(owner, repositoryName, fileName, arrayListOfRelevantChangedLines, gitHubToken); + BlameCommitLogger.info("Authors of the bug lines of code which are being fixed from the given patch are saved successfully to authorNames SET"); } } @@ -260,10 +269,15 @@ public Object callingGraphQl(JSONObject queryObject, String gitHubToken) throws response = client.execute(httpPost); } catch (UnsupportedEncodingException e) { + BlameCommitLogger.error("Encoding error occured before calling the github graphQL API", e); e.printStackTrace(); } catch (ClientProtocolException e) { + BlameCommitLogger.error("Client protocol exception occurred when calling the github graphQL API", e); + e.printStackTrace(); } catch (IOException e) { + BlameCommitLogger.error("IO Exception occured when calling the github graphQL API", e); + e.printStackTrace(); } @@ -290,6 +304,7 @@ public Object callingGraphQl(JSONObject queryObject, String gitHubToken) throws // System.out.println(stringBuilder.toString()); } catch (Exception e) { + BlameCommitLogger.error("Exception occured when reading the response received from github graphQL API", e); e.printStackTrace(); } finally { @@ -419,6 +434,7 @@ public void readingTheBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList String commitHash = (String) StringUtils.substringAfter(urlOfTheParentCommit, "commit/"); commitHashesOfTheParent.add(commitHash); } + BlameCommitLogger.info("Parent Commits hashes of the lines which are being fixed by the patch are saved to commitHashesOfTheParent SET successfully "); } } } @@ -427,11 +443,11 @@ public void readingTheBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList /** * Finding the authors of the commits * - * @param owner owner of the repository - * @param repositoryName repository name - * @param fileName name of the file which is required to get blame details - * @param arrayListOfRelevantChangedLines arraylist containing the changed line ranges of the current selected file - * @param gitHubToken github token for accessing github GraphQL API + * @param owner owner of the repository + * @param repositoryName repository name + * @param fileName name of the file which is required to get blame details + * @param arrayListOfRelevantChangedLines arraylist containing the changed line ranges of the current selected file + * @param gitHubToken github token for accessing github GraphQL API */ public void iteratingOverForFindingAuthors(String owner, String repositoryName, String fileName, ArrayList arrayListOfRelevantChangedLines, String gitHubToken) { @@ -445,6 +461,7 @@ public void iteratingOverForFindingAuthors(String owner, String repositoryName, rootJsonObject = (JSONObject) callingGraphQl(graphqlApiJsonObject, gitHubToken); readingTheBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, true); } catch (IOException e) { + BlameCommitLogger.error("IO Exception occured when calling the github graphQL API for finding the authors of the bug lines which are being fixed by the given patch", e); e.printStackTrace(); } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index 549bee6..3f39956 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -18,17 +18,22 @@ package com.wso2.code.quality.matrices; +import org.apache.log4j.Logger; import org.json.JSONArray; import java.util.Set; + /** * This is the class having the main method of this application * PMT Access token, patch id and github access token * should be passed as command line arguments when running the application */ public class MainClass { + private final static Logger logger = Logger.getLogger(MainClass.class.getName()); + public static void main(String[] args) { + logger.info(" Main method got executed"); String pmtToken = args[0]; String patchId = args[1]; @@ -38,14 +43,20 @@ public static void main(String[] args) { RestApiCaller restApiCaller = new RestApiCaller(); JSONArray jsonArray = (JSONArray) restApiCaller.callingTheAPI(pmtUrl, pmtToken, false, false); + logger.info("JSON response is received successfully from WSO2 PMT for the given patch " + args[1]); + Pmt pmt = new Pmt(); String[] commitsInTheGivenPatch = pmt.getThePublicGitCommitId(jsonArray); + logger.info("Commits received from WSO2 PMT are saved in an array successfully"); + String gitHubToken = args[2]; BlameCommit blameCommit = new BlameCommit(); Set commitHashObtainedForPRReview = blameCommit.obtainingRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); + logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); + Reviewers reviewers = new Reviewers(); reviewers.findingReviewers(commitHashObtainedForPRReview, gitHubToken); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java index 854ee77..4b84df2 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java @@ -18,6 +18,7 @@ package com.wso2.code.quality.matrices; +import org.apache.log4j.Logger; import org.json.JSONArray; import org.json.JSONObject; @@ -27,6 +28,7 @@ public class Pmt { private String[] patchInformation_svnRevisionpublic; + private final Logger logger = Logger.getLogger(Pmt.class.getName()); /** @@ -35,7 +37,6 @@ public class Pmt { * @param jsonArray jsonarray containing the output received from WSO2 PMT for the given patch * @return a copy of the array containing the commit hashes that belongs to the given patch */ - public String[] getThePublicGitCommitId(JSONArray jsonArray) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = (JSONObject) jsonArray.get(i); @@ -47,6 +48,9 @@ public String[] getThePublicGitCommitId(JSONArray jsonArray) { for (int j = 0; j < tempCommitsJSONArray.length(); j++) { patchInformation_svnRevisionpublic[j] = ((String) tempCommitsJSONArray.get(j)).trim(); // for ommiting the white spaces at the begingin and end of the commits } + + logger.info(" The commits hashes obtained from WSO2 PMT are successfully saved to an array"); + System.out.println("The commit Ids are"); // for printing all the commits ID associated with a patch for (String tmp : patchInformation_svnRevisionpublic) { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java index 725e084..6c60e6d 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java @@ -27,6 +27,7 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import org.apache.log4j.Logger; import org.json.JSONTokener; import org.json.JSONObject; import org.json.JSONArray; @@ -36,13 +37,15 @@ */ public class RestApiCaller { + static Logger restApiCallerLogger = Logger.getLogger(RestApiCaller.class.getName()); + /** * calling the relevant API and saving the output to a file * - * @param URL url of the REST API to be called - * @param token either the WSO2 PMT access token or giihub.com access token - * @param requireCommitHeader should be true for accessing the github commit search API and false otherwise - * @param requireReviewHeader should be true for accessing the github review API or false otherwise + * @param URL url of the REST API to be called + * @param token either the WSO2 PMT access token or giihub.com access token + * @param requireCommitHeader should be true for accessing the github commit search API and false otherwise + * @param requireReviewHeader should be true for accessing the github review API or false otherwise */ public Object callingTheAPI(String URL, String token, boolean requireCommitHeader, boolean requireReviewHeader) { @@ -95,6 +98,9 @@ public Object callingTheAPI(String URL, String token, boolean requireCommitHeade JSONArray jsonArray = (JSONArray) json; returnedObject = jsonArray; } + + restApiCallerLogger.info("JSON response is passed after calling the given REST API"); + break; case 401: // to handle Response code 401: Unauthorized @@ -104,7 +110,7 @@ public Object callingTheAPI(String URL, String token, boolean requireCommitHeade Thread.sleep(100); runningTheAppAgain(); } catch (InterruptedException e) { - // TODO Auto-generated catch block + restApiCallerLogger.error("InterruptedException occurred when validating the github user", e); e.printStackTrace(); } break; @@ -116,7 +122,7 @@ public Object callingTheAPI(String URL, String token, boolean requireCommitHeade Thread.sleep(100); runningTheAppAgain(); } catch (InterruptedException e) { - // TODO Auto-generated catch block + restApiCallerLogger.error("InterruptedException occurred when validating the WSO2 PMT user", e); e.printStackTrace(); } @@ -129,6 +135,7 @@ public Object callingTheAPI(String URL, String token, boolean requireCommitHeade runningTheAppAgain(); } catch (InterruptedException e) { + restApiCallerLogger.error("InterruptedException occurred when validating the given patch", e); e.printStackTrace(); } @@ -137,10 +144,10 @@ public Object callingTheAPI(String URL, String token, boolean requireCommitHeade returnedObject = null; } } catch (ClientProtocolException e) { - // TODO Auto-generated catch block + restApiCallerLogger.error("ClientProtocolException when calling the REST API", e); e.printStackTrace(); } catch (IOException e) { - // TODO Auto-generated catch block + restApiCallerLogger.error("IOException occurred when calling the REST API"); e.printStackTrace(); } finally { @@ -177,7 +184,7 @@ public void runningTheAppAgain() { try { MainClass.main(null); } catch (Exception e) { - // TODO Auto-generated catch block + restApiCallerLogger.error("Exception occurred when running the main method again after invalid inputs"); e.printStackTrace(); } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java index f6e705c..18ea16e 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java @@ -25,6 +25,7 @@ import java.util.Set; import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; import org.json.JSONArray; import org.json.JSONObject; @@ -39,6 +40,8 @@ public class Reviewers extends BlameCommit { Set approvedReviewers = new HashSet(); // to store the reviewed and approved users of the pull requests Set commentedReviewers = new HashSet(); // to store the reviewed and commented users of the pull requests + private static final Logger reviewersLogger = Logger.getLogger(Reviewers.class.getName()); + public String getSearchPullReqeustAPI() { return searchPullReqeustAPIUrl; } @@ -80,10 +83,12 @@ public void findingReviewers(Set commitHashObtainedForPRReview, String g // reading thus saved json file savingPrNumberAndRepoName(rootJsonObject); } - System.out.println("Done Mapping" + mapContainingPRNoAgainstRepoName); + reviewersLogger.info("PR numbers which introduce bug lines of code with their relevant repository are saved successfully to mapContainingPRNoAgainstRepoName map"); savingReviewersToList(githubToken); + reviewersLogger.info("List of approved reviwers and comment users of the PRs which introduce bug lines to repository are saved in commentedReviewers and approvedReviewers list "); // printing the list of reviewers of pull requests printReviewUsers(); + reviewersLogger.info("Names of approved reviewers and commented reviewers are printed successfully"); } /** diff --git a/CodeQualityMatricesProject/src/main/resources/log4j.properties b/CodeQualityMatricesProject/src/main/resources/log4j.properties new file mode 100644 index 0000000..36065e8 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/resources/log4j.properties @@ -0,0 +1,32 @@ +# +# Copyright (c) 2017 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# WSO2 Inc. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# +# Define the root logger with appender file +logs=/home/kasun/Documents/log4j +log4j.rootLogger=DEBUG, APPENDER1 +#Define the file appender +log4j.appender.APPENDER1=org.apache.log4j.RollingFileAppender +log4j.appender.APPENDER1.File=${logs}/log.out +log4j.appender.APPENDER1.MaxFileSize=10KB +log4j.appender.APPENDER1.MaxBackupIndex=5 +# Define the layout for file appender +log4j.appender.APPENDER1.layout=org.apache.log4j.PatternLayout +log4j.appender.APPENDER1.layout.conversionPattern=%d{yyyy-MM-dd}-5p--10c:%m%n + + + + From dda1a46cfb2473e984a6e107df0f7ca6c2930080 Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 10 Mar 2017 17:40:51 +0530 Subject: [PATCH 07/62] Remove the CodeQualityMatrices.iml from remote --- .../CodeQualityMatrices.iml | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 CodeQualityMatricesProject/CodeQualityMatrices.iml diff --git a/CodeQualityMatricesProject/CodeQualityMatrices.iml b/CodeQualityMatricesProject/CodeQualityMatrices.iml deleted file mode 100644 index f1af523..0000000 --- a/CodeQualityMatricesProject/CodeQualityMatrices.iml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 1c39bb08b2d390b7f5af985eb89a74555a8ed61e Mon Sep 17 00:00:00 2001 From: kasun Date: Tue, 14 Mar 2017 14:56:48 +0530 Subject: [PATCH 08/62] Get the patch details for a file made by the given commit --- CodeQualityMatricesProject/pom.xml | 5 ++ .../matrices/GitHubAuthentication.java | 69 +++++++++++++++++++ .../wso2/code/quality/matrices/MainClass.java | 33 +++++---- 3 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java diff --git a/CodeQualityMatricesProject/pom.xml b/CodeQualityMatricesProject/pom.xml index 3254fe2..790c5f0 100644 --- a/CodeQualityMatricesProject/pom.xml +++ b/CodeQualityMatricesProject/pom.xml @@ -51,6 +51,11 @@ json 20160810 + + org.eclipse.mylyn.github + org.eclipse.egit.github.core + 2.1.5 + org.apache.httpcomponents diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java new file mode 100644 index 0000000..2cbea16 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java @@ -0,0 +1,69 @@ +package com.wso2.code.quality.matrices;/* +* Copyright (c) ${date}, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + + +import com.sun.org.apache.xpath.internal.SourceTree; +import org.eclipse.egit.github.core.CommitFile; +import org.eclipse.egit.github.core.IRepositoryIdProvider; +import org.eclipse.egit.github.core.Repository; +import org.eclipse.egit.github.core.RepositoryCommit; +import org.eclipse.egit.github.core.client.GitHubClient; +import org.eclipse.egit.github.core.service.CommitService; +import org.eclipse.egit.github.core.service.GitHubService; +import org.eclipse.egit.github.core.service.RepositoryService; + +import java.io.IOException; +import java.util.Iterator; +import java.util.List; + +public class GitHubAuthentication { + public void gettingGithubClient(){ + GitHubClient client= new GitHubClient(); + client.setCredentials("kasunsiyambalapitiya","resident0507"); + + CommitService commitService= new CommitService(client); +// commitService.getCommit("product-is","fdafewafd"); + + RepositoryService repositoryService= new RepositoryService(client); + try { + Repository repository=repositoryService.getRepository("wso2","wso2-axis2-transports"); + + String id=repository.generateId(); + + IRepositoryIdProvider iRepositoryIdProvider = () -> id; + RepositoryCommit repositoryCommit=commitService.getCommit(iRepositoryIdProvider,"e3c3457149b109178d510aac965d5a85cc465aa0"); + List filesChanged=repositoryCommit.getFiles(); + + Iterator listIterator= filesChanged.iterator(); + while(listIterator.hasNext()){ + CommitFile commitFile= (CommitFile) listIterator.next(); + System.out.println(commitFile.getFilename()); + String patch=commitFile.getPatch(); + System.out.println(patch); + + + } + +// filesChanged.stream().forEach(); + + + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index 9759641..f7db4ec 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -34,31 +34,34 @@ public class MainClass { public static void main(String[] args) { logger.info(" Main method got executed"); - String pmtToken = args[0]; - String patchId = args[1]; - - String pmtUrl = "http://umt.private.wso2.com:9765/codequalitymatricesapi/1.0.0//properties?path=/_system/governance/patchs/" + patchId; - - RestApiCaller restApiCaller = new RestApiCaller(); - JSONArray jsonArray = (JSONArray) restApiCaller.callingTheAPI(pmtUrl, pmtToken, false, false); +// String pmtToken = args[0]; +// String patchId = args[1]; +// +// String pmtUrl = "http://umt.private.wso2.com:9765/codequalitymatricesapi/1.0.0//properties?path=/_system/governance/patchs/" + patchId; +// +// RestApiCaller restApiCaller = new RestApiCaller(); +// JSONArray jsonArray = (JSONArray) restApiCaller.callingTheAPI(pmtUrl, pmtToken, false, false); logger.info("JSON response is received successfully from WSO2 PMT for the given patch " + args[1]); - Pmt pmt = new Pmt(); - String[] commitsInTheGivenPatch = pmt.getThePublicGitCommitId(jsonArray); +// Pmt pmt = new Pmt(); +// String[] commitsInTheGivenPatch = pmt.getThePublicGitCommitId(jsonArray); logger.info("Commits received from WSO2 PMT are saved in an array successfully"); logger.info("Commits received from WSO2 PMT are saved in an array successfully"); - String gitHubToken = args[2]; - - BlameCommit blameCommit = new BlameCommit(); - Set commitHashObtainedForPRReview = blameCommit.obtainingRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); +// String gitHubToken = args[2]; +// +// BlameCommit blameCommit = new BlameCommit(); +// Set commitHashObtainedForPRReview = blameCommit.obtainingRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); - Reviewers reviewers = new Reviewers(); - reviewers.findingReviewers(commitHashObtainedForPRReview, gitHubToken); +// Reviewers reviewers = new Reviewers(); +// reviewers.findingReviewers(commitHashObtainedForPRReview, gitHubToken); + + GitHubAuthentication gitHubAuthentication= new GitHubAuthentication(); + gitHubAuthentication.gettingGithubClient(); } } From 5699fb941a01976d956026f7589bfadf9b2723e2 Mon Sep 17 00:00:00 2001 From: kasun Date: Tue, 14 Mar 2017 18:36:50 +0530 Subject: [PATCH 09/62] Complete upto getting authors of the buggly lines from SDK --- .../code/quality/matrices/BlameCommit.java | 59 +++++++++--------- .../matrices/GitHubAuthentication.java | 62 ++++++++++++------- 2 files changed, 68 insertions(+), 53 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java index 6b8def7..8338c5f 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java @@ -52,6 +52,7 @@ public class BlameCommit extends RestApiCaller { private String urlForObtainingCommits, urlForGetingFilesChanged; protected ArrayList fileNames = new ArrayList(); + protected ArrayList patchString = new ArrayList<>(); protected List> lineRangesChanged = new ArrayList>(); // for saving the line no that are changed JSONObject graphqlApiJsonObject = new JSONObject(); Set commitHashesOfTheParent; @@ -117,14 +118,31 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, } BlameCommitLogger.info("Repo names having the given commit are successfully saved in an array"); + //========================================================================================================== + GitHubAuthentication gitHubAuthentication = new GitHubAuthentication(gitHubToken); + + //========================================================================================================== + // for running through the repoName Array for (int i = 0; i < repoLocation.length; i++) { if (StringUtils.contains(repoLocation[i], "wso2/")) { //clearing all the data in the current fileNames and lineRangesChanged arraylists for each repository fileNames.clear(); lineRangesChanged.clear(); + patchString.clear(); //authorNames.clear(); - callingToGetFilesChanged(repoLocation[i], commitHash, gitHubToken); + + //============================================================================================== + + Map> mapWithFileNamesAndPatch = gitHubAuthentication.gettingFilesChanged(repoLocation[i], commitHash); + + fileNames = mapWithFileNamesAndPatch.get("fileNames"); + patchString = mapWithFileNamesAndPatch.get("patchString"); + + savingRelaventEditLineNumbers(fileNames, patchString); + + + //============================================================================================== iteratingOver(repoLocation[i], commitHash, gitHubToken); } @@ -134,40 +152,19 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, System.out.println(commitHashObtainedForPRReview); } - /** - * calling github single commit API to get files changed from the current selected commit in the current selected repository - * - * @param repoLocation current selected repository - * @param commitHash current selected commit hash - * @param gitHubToken github token for accessing github REST API + /** + * @param fileNames + * @param patchString */ - public void callingToGetFilesChanged(String repoLocation, String commitHash, String gitHubToken) { - // setting the URL for calling github single commit API - setUrlForGetingFilesChanged(repoLocation, commitHash); - JSONObject rootJsonObject = null; - //saving the commit details for the commit hash on the relevant repository - rootJsonObject = (JSONObject) callingTheAPI(getUrlForGetingFilesChanged(), gitHubToken, false, false); - //calling savingRelaventFileNamesAndEditLineNumbers method to read the above saved json output - savingRelaventFileNamesAndEditLineNumbers(rootJsonObject); - BlameCommitLogger.info("Relevant file names and their line ranges which being affected by the given commit are saved successfully"); - } - /** - * saving relevant file names and their changed line ranges from the current selected commit in the current selected repository - * - * @param rootJsonObject JSONObject received from the calling the single commit API in github - */ - public void savingRelaventFileNamesAndEditLineNumbers(JSONObject rootJsonObject) { - JSONArray fileJsonArray = (JSONArray) rootJsonObject.get("files"); - // to save one file at a time - for (int i = 0; i < fileJsonArray.length(); i++) { - JSONObject tempJsonObject = (JSONObject) fileJsonArray.get(i); - String fileName = (String) tempJsonObject.get("filename"); - //saving the file name in the filename arraylist - fileNames.add(fileName); + public void savingRelaventEditLineNumbers(ArrayList fileNames, ArrayList patchString) { + + Iterator patchStringIterator = patchString.iterator(); + while (patchStringIterator.hasNext()) { + String patch = (String) patchStringIterator.next(); + //filtering only the line ranges that are modified and saving to a string array - String patch = (String) tempJsonObject.get("patch"); String lineChanges[] = StringUtils.substringsBetween(patch, "@@ ", " @@"); //filtering the lines that existed in the previous file, that exists in the new file and saving them in to the same array diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java index 2cbea16..ffeabe8 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java @@ -17,53 +17,71 @@ */ -import com.sun.org.apache.xpath.internal.SourceTree; +import org.apache.commons.lang3.StringUtils; import org.eclipse.egit.github.core.CommitFile; import org.eclipse.egit.github.core.IRepositoryIdProvider; import org.eclipse.egit.github.core.Repository; import org.eclipse.egit.github.core.RepositoryCommit; import org.eclipse.egit.github.core.client.GitHubClient; import org.eclipse.egit.github.core.service.CommitService; -import org.eclipse.egit.github.core.service.GitHubService; import org.eclipse.egit.github.core.service.RepositoryService; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; + +/** + * + */ public class GitHubAuthentication { - public void gettingGithubClient(){ - GitHubClient client= new GitHubClient(); - client.setCredentials("kasunsiyambalapitiya","resident0507"); + protected GitHubClient gitHubClient = null; + protected CommitService commitService = null; + protected RepositoryService repositoryService = null; + protected ArrayList fileNames = new ArrayList(); + protected ArrayList patchString = new ArrayList(); - CommitService commitService= new CommitService(client); -// commitService.getCommit("product-is","fdafewafd"); - RepositoryService repositoryService= new RepositoryService(client); - try { - Repository repository=repositoryService.getRepository("wso2","wso2-axis2-transports"); + GitHubAuthentication(String githubToken) { + gitHubClient = new GitHubClient(); + gitHubClient.setOAuth2Token(githubToken); + commitService = new CommitService(gitHubClient); + repositoryService = new RepositoryService(gitHubClient); - String id=repository.generateId(); - IRepositoryIdProvider iRepositoryIdProvider = () -> id; - RepositoryCommit repositoryCommit=commitService.getCommit(iRepositoryIdProvider,"e3c3457149b109178d510aac965d5a85cc465aa0"); - List filesChanged=repositoryCommit.getFiles(); + } - Iterator listIterator= filesChanged.iterator(); - while(listIterator.hasNext()){ - CommitFile commitFile= (CommitFile) listIterator.next(); - System.out.println(commitFile.getFilename()); - String patch=commitFile.getPatch(); - System.out.println(patch); + public Map> gettingFilesChanged(String repositoryName, String commitHash) { + Map> mapWithFileNamesAndPatches = new HashMap<>(); + try { +// Repository repository = repositoryService.getRepository("wso2", "carbon-apimgt"); +// String id = repository.generateId(); - } + IRepositoryIdProvider iRepositoryIdProvider = () -> repositoryName; + RepositoryCommit repositoryCommit = commitService.getCommit(iRepositoryIdProvider, commitHash); + List filesChanged = repositoryCommit.getFiles(); -// filesChanged.stream().forEach(); + Iterator listIterator = filesChanged.iterator(); + while (listIterator.hasNext()) { + CommitFile commitFile = (CommitFile) listIterator.next(); + fileNames.add(commitFile.getFilename()); + patchString.add(commitFile.getPatch()); + + } +// System.out.println(fileNames); + mapWithFileNamesAndPatches.put("fileNames", fileNames); + mapWithFileNamesAndPatches.put("patchString", patchString); } catch (IOException e) { e.printStackTrace(); } + return mapWithFileNamesAndPatches; + } + } From c77dcd00f4c0ba15effe4eb8597979292faf4163 Mon Sep 17 00:00:00 2001 From: kasun Date: Wed, 15 Mar 2017 09:02:53 +0530 Subject: [PATCH 10/62] Added docs --- .../code/quality/matrices/BlameCommit.java | 18 +---------- .../matrices/GitHubAuthentication.java | 7 +++- .../wso2/code/quality/matrices/MainClass.java | 32 +++++++++---------- 3 files changed, 22 insertions(+), 35 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java index 8338c5f..1660b43 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java @@ -71,14 +71,6 @@ public void setUrlForSearchingCommits(String commitHash) { this.urlForObtainingCommits = "https://api.github.com/search/commits?q=hash%3A" + commitHash; } - public String getUrlForGetingFilesChanged() { - return urlForGetingFilesChanged; - } - - public void setUrlForGetingFilesChanged(String repoName, String commitHash) { - this.urlForGetingFilesChanged = "http://api.github.com/repos/" + repoName + "/commits/" + commitHash; - } - /** * This method is used for obtaining the repositories that contain the relevant commits belongs to the given patch * @@ -118,11 +110,8 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, } BlameCommitLogger.info("Repo names having the given commit are successfully saved in an array"); - //========================================================================================================== GitHubAuthentication gitHubAuthentication = new GitHubAuthentication(gitHubToken); - //========================================================================================================== - // for running through the repoName Array for (int i = 0; i < repoLocation.length; i++) { if (StringUtils.contains(repoLocation[i], "wso2/")) { @@ -132,8 +121,6 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, patchString.clear(); //authorNames.clear(); - //============================================================================================== - Map> mapWithFileNamesAndPatch = gitHubAuthentication.gettingFilesChanged(repoLocation[i], commitHash); fileNames = mapWithFileNamesAndPatch.get("fileNames"); @@ -141,9 +128,6 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, savingRelaventEditLineNumbers(fileNames, patchString); - - //============================================================================================== - iteratingOver(repoLocation[i], commitHash, gitHubToken); } } @@ -152,7 +136,7 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, System.out.println(commitHashObtainedForPRReview); } - /** + /** * @param fileNames * @param patchString */ diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java index ffeabe8..0b6a406 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java @@ -34,7 +34,7 @@ import java.util.Map; /** - * + * This class is used for communicating with the github REST API from egit github API */ public class GitHubAuthentication { @@ -54,6 +54,11 @@ public class GitHubAuthentication { } + /** + * @param repositoryName The repository name that contain the given commit hash + * @param commitHash The querying commit hash + * @return a map containg arraylist of file changed and their relevant patch + */ public Map> gettingFilesChanged(String repositoryName, String commitHash) { Map> mapWithFileNamesAndPatches = new HashMap<>(); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index f7db4ec..f31ddce 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -34,34 +34,32 @@ public class MainClass { public static void main(String[] args) { logger.info(" Main method got executed"); -// String pmtToken = args[0]; -// String patchId = args[1]; -// -// String pmtUrl = "http://umt.private.wso2.com:9765/codequalitymatricesapi/1.0.0//properties?path=/_system/governance/patchs/" + patchId; -// -// RestApiCaller restApiCaller = new RestApiCaller(); -// JSONArray jsonArray = (JSONArray) restApiCaller.callingTheAPI(pmtUrl, pmtToken, false, false); + String pmtToken = args[0]; + String patchId = args[1]; + + String pmtUrl = "http://umt.private.wso2.com:9765/codequalitymatricesapi/1.0.0//properties?path=/_system/governance/patchs/" + patchId; + + RestApiCaller restApiCaller = new RestApiCaller(); + JSONArray jsonArray = (JSONArray) restApiCaller.callingTheAPI(pmtUrl, pmtToken, false, false); logger.info("JSON response is received successfully from WSO2 PMT for the given patch " + args[1]); -// Pmt pmt = new Pmt(); -// String[] commitsInTheGivenPatch = pmt.getThePublicGitCommitId(jsonArray); + Pmt pmt = new Pmt(); + String[] commitsInTheGivenPatch = pmt.getThePublicGitCommitId(jsonArray); logger.info("Commits received from WSO2 PMT are saved in an array successfully"); logger.info("Commits received from WSO2 PMT are saved in an array successfully"); -// String gitHubToken = args[2]; -// -// BlameCommit blameCommit = new BlameCommit(); -// Set commitHashObtainedForPRReview = blameCommit.obtainingRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); + String gitHubToken = args[2]; + + BlameCommit blameCommit = new BlameCommit(); + Set commitHashObtainedForPRReview = blameCommit.obtainingRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); -// Reviewers reviewers = new Reviewers(); -// reviewers.findingReviewers(commitHashObtainedForPRReview, gitHubToken); + Reviewers reviewers = new Reviewers(); + reviewers.findingReviewers(commitHashObtainedForPRReview, gitHubToken); - GitHubAuthentication gitHubAuthentication= new GitHubAuthentication(); - gitHubAuthentication.gettingGithubClient(); } } From df622e0b9ee18134d725d825011f13111b69fb28 Mon Sep 17 00:00:00 2001 From: kasun Date: Wed, 15 Mar 2017 09:37:12 +0530 Subject: [PATCH 11/62] Pmt.java convert to use java8 --- .../main/java/com/wso2/code/quality/matrices/Pmt.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java index ef26653..987ffd1 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java @@ -22,6 +22,8 @@ import org.json.JSONArray; import org.json.JSONObject; +import java.util.stream.IntStream; + /** * This class is used for obtaining the commit hashes that belongs to the given patch */ @@ -45,17 +47,14 @@ public String[] getThePublicGitCommitId(JSONArray jsonArray) { JSONArray tempCommitsJSONArray = (JSONArray) jsonObject.get("value"); //initializing the patchInformation_svnRevisionpublic array patchInformation_svnRevisionpublic = new String[tempCommitsJSONArray.length()]; - for (int j = 0; j < tempCommitsJSONArray.length(); j++) { - patchInformation_svnRevisionpublic[j] = ((String) tempCommitsJSONArray.get(j)).trim(); // for ommiting the white spaces at the begingin and end of the commits - } + // for ommiting the white spaces at the begingin and end of the commits + IntStream.range(0, tempCommitsJSONArray.length()).forEach(j -> patchInformation_svnRevisionpublic[j] = ((String) tempCommitsJSONArray.get(j)).trim()); logger.info(" The commits hashes obtained from WSO2 PMT are successfully saved to an array"); System.out.println("The commit Ids are"); // for printing all the commits ID associated with a patch - for (String tmp : patchInformation_svnRevisionpublic) { - System.out.println(tmp); - } + IntStream.range(0, patchInformation_svnRevisionpublic.length).mapToObj(i1 -> patchInformation_svnRevisionpublic[i1]).forEach(System.out::println); System.out.println(); break; } From e3d9da50bb53b898486dbdb8e1b367ae6acecced Mon Sep 17 00:00:00 2001 From: kasun Date: Wed, 15 Mar 2017 15:16:48 +0530 Subject: [PATCH 12/62] convert BlameCommit.java to java8 --- .../code/quality/matrices/BlameCommit.java | 115 +++++++----------- .../matrices/GitHubAuthentication.java | 14 ++- 2 files changed, 53 insertions(+), 76 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java index 1660b43..338ef1d 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java @@ -31,6 +31,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; +import java.util.stream.IntStream; import org.apache.commons.lang3.StringUtils; import org.apache.http.client.ClientProtocolException; @@ -81,12 +82,12 @@ public void setUrlForSearchingCommits(String commitHash) { */ public Set obtainingRepoNamesForCommitHashes(String gitHubToken, String[] commitsInTheGivenPatch, RestApiCaller restApiCaller) { - for (String commitHash : commitsInTheGivenPatch) { + //calling the API calling method + IntStream.range(0, commitsInTheGivenPatch.length).mapToObj(i -> commitsInTheGivenPatch[i]).forEach(commitHash -> { setUrlForSearchingCommits(commitHash); - //calling the API calling method JSONObject jsonObject = (JSONObject) restApiCaller.callingTheAPI(getUrlForSearchingCommits(), gitHubToken, true, false); saveRepoNamesInAnArray(jsonObject, commitHash, gitHubToken); - } + }); return commitHashObtainedForPRReview; } @@ -102,58 +103,49 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, JSONArray jsonArrayOfItems = (JSONArray) rootJsonObject.get("items"); // setting the size of the repoLocationArray repoLocation = new String[jsonArrayOfItems.length()]; - for (int i = 0; i < jsonArrayOfItems.length(); i++) { + //adding the repo name to the array + IntStream.range(0, jsonArrayOfItems.length()).forEach(i -> { JSONObject jsonObject = (JSONObject) jsonArrayOfItems.get(i); JSONObject repositoryJsonObject = (JSONObject) jsonObject.get("repository"); - //adding the repo name to the array repoLocation[i] = (String) repositoryJsonObject.get("full_name"); - } + }); BlameCommitLogger.info("Repo names having the given commit are successfully saved in an array"); GitHubAuthentication gitHubAuthentication = new GitHubAuthentication(gitHubToken); // for running through the repoName Array - for (int i = 0; i < repoLocation.length; i++) { - if (StringUtils.contains(repoLocation[i], "wso2/")) { - //clearing all the data in the current fileNames and lineRangesChanged arraylists for each repository - fileNames.clear(); - lineRangesChanged.clear(); - patchString.clear(); - //authorNames.clear(); - - Map> mapWithFileNamesAndPatch = gitHubAuthentication.gettingFilesChanged(repoLocation[i], commitHash); - - fileNames = mapWithFileNamesAndPatch.get("fileNames"); - patchString = mapWithFileNamesAndPatch.get("patchString"); + IntStream.range(0, repoLocation.length).filter(i -> StringUtils.contains(repoLocation[i], "wso2/")).forEach(i -> { + //clearing all the data in the current fileNames and lineRangesChanged arraylists for each repository + //authorNames.clear(); + fileNames.clear(); + lineRangesChanged.clear(); + patchString.clear(); + Map> mapWithFileNamesAndPatch = gitHubAuthentication.gettingFilesChanged(repoLocation[i], commitHash); + fileNames = mapWithFileNamesAndPatch.get("fileNames"); + patchString = mapWithFileNamesAndPatch.get("patchString"); + savingRelaventEditLineNumbers(fileNames, patchString); + iteratingOver(repoLocation[i], commitHash, gitHubToken); + }); - savingRelaventEditLineNumbers(fileNames, patchString); - iteratingOver(repoLocation[i], commitHash, gitHubToken); - } - } // for printing the author names and commit hashes for a certain commit. System.out.println(authorNames); System.out.println(commitHashObtainedForPRReview); } /** - * @param fileNames - * @param patchString + * This method is used to save the line ranges being modified in a given file to a list and add that list to the root list of + * @param fileNames Arraylist of files names that are being affected by the relevant commit + * @param patchString Array list having the patch string value for each of the file being changed */ public void savingRelaventEditLineNumbers(ArrayList fileNames, ArrayList patchString) { + //filtering only the line ranges that are modified and saving to a string array - Iterator patchStringIterator = patchString.iterator(); - while (patchStringIterator.hasNext()) { - String patch = (String) patchStringIterator.next(); - - - //filtering only the line ranges that are modified and saving to a string array - String lineChanges[] = StringUtils.substringsBetween(patch, "@@ ", " @@"); - - //filtering the lines that existed in the previous file, that exists in the new file and saving them in to the same array - for (int j = 0; j < lineChanges.length; j++) { - + // cannot ues parallel streams here as the order of the line changes must be preserved + patchString.stream().map(patch -> StringUtils.substringsBetween(patch, "@@ ", " @@")).forEach(lineChanges -> { + //filtering the lines ranges that existed in the previous file, that exists in the new file and saving them in to the same array + IntStream.range(0, lineChanges.length).forEach(j -> { //@@ -22,7 +22,7 @@ String tempString = lineChanges[j]; String lineRangeInTheOldFileBeingModified = StringUtils.substringBetween(tempString, "-", " +"); // for taking the authors and commit hashes of the previous lines @@ -171,14 +163,13 @@ public void savingRelaventEditLineNumbers(ArrayList fileNames, ArrayList int intialLineNoInNewFile = Integer.parseInt(StringUtils.substringBefore(lineRangeInTheNewFileResultedFromModification, ",")); int tempEndLineNoInNewFile = Integer.parseInt(StringUtils.substringAfter(lineRangeInTheNewFileResultedFromModification, ",")); int endLineNoOfNewFile = intialLineNoInNewFile + (tempEndLineNoInNewFile - 1); - // storing the line ranges that are being modified in the same array by replacing values lineChanges[j] = intialLineNoInOldFile + "," + endLineNoOfOldFile + "/" + intialLineNoInNewFile + "," + endLineNoOfNewFile; - } + }); ArrayList tempArrayList = new ArrayList<>(Arrays.asList(lineChanges)); //adding to the array list which keep track of the line ranges which are being changed to the main arrayList lineRangesChanged.add(tempArrayList); - } + }); System.out.println("done saving file names and their relevant modification line ranges"); System.out.println(fileNames); System.out.println(lineRangesChanged + "\n"); @@ -198,16 +189,13 @@ public void iteratingOver(String repoLocation, String commitHash, String gitHubT String owner = StringUtils.substringBefore(repoLocation, "/"); String repositoryName = StringUtils.substringAfter(repoLocation, "/"); // iterating over the fileNames arraylist for the given commit - Iterator iteratorForFileNames = fileNames.iterator(); - - while (iteratorForFileNames.hasNext()) { - String fileName = (String) iteratorForFileNames.next(); + // cannot use parallel streams here as the order of the file names is important in the process + fileNames.stream().forEach(fileName -> { int index = fileNames.indexOf(fileName); // the relevant arraylist of changed lines for that file ArrayList arrayListOfRelevantChangedLines = lineRangesChanged.get(index); commitHashesOfTheParent = new HashSet<>(); // for storing the parent commit hashes for all the line ranges of the relevant file graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + commitHash + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{history(first: 2) { edges { node { message url } } } author { name email } } } } } } } }"); - JSONObject rootJsonObject = null; try { // calling the graphql API for getting blame information for the current file and saving it in a location. @@ -223,7 +211,7 @@ public void iteratingOver(String repoLocation, String commitHash, String gitHubT iteratingOverForFindingAuthors(owner, repositoryName, fileName, arrayListOfRelevantChangedLines, gitHubToken); BlameCommitLogger.info("Authors of the bug lines of code which are being fixed from the given patch are saved successfully to authorNames SET"); - } + }); } /** @@ -315,33 +303,22 @@ public void readingTheBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList JSONArray rangeJSONArray = (JSONArray) blameJSONObject.get("ranges"); //getting the starting line no of the range of lines that are modified from the patch - Iterator arrayListOfRelevantChangedLinesIterator = arrayListOfRelevantChangedLines.iterator(); // iterator for the array list inside the root arraylist - - while (arrayListOfRelevantChangedLinesIterator.hasNext()) { - + // parallel streams are not used in here as the order of the arraylist is important in the process + arrayListOfRelevantChangedLines.stream().forEach(lineRanges -> { int startingLineNo; int endLineNo; - - String lineRanges = (String) arrayListOfRelevantChangedLinesIterator.next(); - String oldFileRange = StringUtils.substringBefore(lineRanges, "/"); String newFileRange = StringUtils.substringAfter(lineRanges, "/"); - // need to skip the newly created files from taking the blame if (oldFileRange.equals("0,0")) { - - continue; - + return; } //non newly created files else { - if (gettingPr) { // need to consider the line range in the old file for finding authors and reviewers - startingLineNo = Integer.parseInt(StringUtils.substringBefore(oldFileRange, ",")); endLineNo = Integer.parseInt(StringUtils.substringAfter(oldFileRange, ",")); - } else { // need to consider the line range in the new file resulted from applying the commit for finding parent commits @@ -398,27 +375,24 @@ public void readingTheBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList int minimumKeyOfMapForStoringAgeAndIndex = treeMap.firstKey(); // getting the minimum key // getting the relevant JSONObject indexes which consists of the recent commit with in the relevant line range ArrayList indexesOfJsonObjectForRecentCommit = mapForStoringAgeAndIndex.get(minimumKeyOfMapForStoringAgeAndIndex); - Iterator indexesOfJsonObjectForRecentCommitIterator = indexesOfJsonObjectForRecentCommit.iterator(); - - while (indexesOfJsonObjectForRecentCommitIterator.hasNext()) { - int index = (int) indexesOfJsonObjectForRecentCommitIterator.next(); - // this is the range where the code gets actually modified + // the order of the indexesOfJsonObjectForRecentCommit is not important as we only need to get the parent commit hashes + indexesOfJsonObjectForRecentCommit.parallelStream().forEach(index -> { JSONObject rangeJSONObject = (JSONObject) rangeJSONArray.get(index); JSONObject commitJSONObject = (JSONObject) rangeJSONObject.get("commit"); JSONObject historyJSONObject = (JSONObject) commitJSONObject.get("history"); JSONArray edgesJSONArray = (JSONArray) historyJSONObject.get("edges"); - //getting the second json object from the array as it contain the commit of the parent which modified the above line range JSONObject edgeJSONObject = (JSONObject) edgesJSONArray.get(1); JSONObject nodeJSONObject = (JSONObject) edgeJSONObject.get("node"); String urlOfTheParentCommit = (String) nodeJSONObject.get("url"); // this contain the URL of the parent commit String commitHash = (String) StringUtils.substringAfter(urlOfTheParentCommit, "commit/"); commitHashesOfTheParent.add(commitHash); - } + + }); BlameCommitLogger.info("Parent Commits hashes of the lines which are being fixed by the patch are saved to commitHashesOfTheParent SET successfully "); } } - } + }); } /** @@ -432,10 +406,9 @@ public void readingTheBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList */ public void iteratingOverForFindingAuthors(String owner, String repositoryName, String fileName, ArrayList arrayListOfRelevantChangedLines, String gitHubToken) { - // calling the graphql api to get the blame details of the current file for the parent commits (That is found by filtering in the graqhql output) - Iterator commitHashOfTheParentIterator = commitHashesOfTheParent.iterator(); - while (commitHashOfTheParentIterator.hasNext()) { - String parentCommitHashForCallingGraphQl = (String) commitHashOfTheParentIterator.next(); + // calling the graphql api to get the blame details of the current file for the parent commits (That is found by filtering in the graqhQL output) + //as the order is not important in here parallel streams are used + commitHashesOfTheParent.parallelStream().forEach(parentCommitHashForCallingGraphQl -> { graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + parentCommitHashForCallingGraphQl + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{ url author { name email } } } } } } } }"); JSONObject rootJsonObject = null; try { @@ -445,7 +418,7 @@ public void iteratingOverForFindingAuthors(String owner, String repositoryName, BlameCommitLogger.error("IO Exception occured when calling the github graphQL API for finding the authors of the bug lines which are being fixed by the given patch", e); e.printStackTrace(); } - } + }); } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java index 0b6a406..10ad332 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java @@ -70,13 +70,17 @@ public Map> gettingFilesChanged(String repositoryName, RepositoryCommit repositoryCommit = commitService.getCommit(iRepositoryIdProvider, commitHash); List filesChanged = repositoryCommit.getFiles(); - Iterator listIterator = filesChanged.iterator(); - while (listIterator.hasNext()) { - CommitFile commitFile = (CommitFile) listIterator.next(); +// Iterator listIterator = filesChanged.iterator(); + // this can be run parallely as patchString of a file will always be in the same index as the file + filesChanged.parallelStream().forEach(commitFile -> { fileNames.add(commitFile.getFilename()); patchString.add(commitFile.getPatch()); - - } + }); +// while (listIterator.hasNext()) { +// CommitFile commitFile = (CommitFile) listIterator.next(); +// +// +// } // System.out.println(fileNames); mapWithFileNamesAndPatches.put("fileNames", fileNames); mapWithFileNamesAndPatches.put("patchString", patchString); From a9df118949a884336197e1a4c494a15b60b74640 Mon Sep 17 00:00:00 2001 From: kasun Date: Wed, 15 Mar 2017 15:43:29 +0530 Subject: [PATCH 13/62] create seperate class for calling graphql API --- .../code/quality/matrices/BlameCommit.java | 77 +------------ .../quality/matrices/GraphQlApiCaller.java | 109 ++++++++++++++++++ 2 files changed, 113 insertions(+), 73 deletions(-) create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java index 338ef1d..d2fbe96 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java @@ -60,6 +60,7 @@ public class BlameCommit extends RestApiCaller { Set authorNames = new HashSet(); //as the authors are for all the commits that exists in the relevant patch protected Set commitHashObtainedForPRReview = new HashSet(); // relevant commits in old file that need to find the PR Reviewers private String repoLocation[]; + GraphQlApiCaller graphQlApiCaller = new GraphQlApiCaller(); private static final Logger BlameCommitLogger = Logger.getLogger(BlameCommit.class.getName()); @@ -135,6 +136,7 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, /** * This method is used to save the line ranges being modified in a given file to a list and add that list to the root list of + * * @param fileNames Arraylist of files names that are being affected by the relevant commit * @param patchString Array list having the patch string value for each of the file being changed */ @@ -199,7 +201,7 @@ public void iteratingOver(String repoLocation, String commitHash, String gitHubT JSONObject rootJsonObject = null; try { // calling the graphql API for getting blame information for the current file and saving it in a location. - rootJsonObject = (JSONObject) callingGraphQl(graphqlApiJsonObject, gitHubToken); + rootJsonObject = (JSONObject) graphQlApiCaller.callingGraphQl(graphqlApiJsonObject, gitHubToken); } catch (IOException e) { BlameCommitLogger.error("IO exception occurred when calling the github graphQL API ", e); e.printStackTrace(); @@ -214,77 +216,6 @@ public void iteratingOver(String repoLocation, String commitHash, String gitHubT }); } - /** - * Calling the github graphQL API - * - * @param queryObject the JSONObject required for querying - * @param gitHubToken github token for accessing github GraphQL API - * @return Depending on the content return a JSONObject or a JSONArray - * @throws IOException - */ - public Object callingGraphQl(JSONObject queryObject, String gitHubToken) throws IOException { - - CloseableHttpClient client = null; - CloseableHttpResponse response = null; - client = HttpClients.createDefault(); - HttpPost httpPost = new HttpPost("https://api.github.com/graphql"); - httpPost.addHeader("Authorization", "Bearer " + gitHubToken); - httpPost.addHeader("Accept", "application/json"); - Object returnedObject = null; - - try { - StringEntity entity = new StringEntity(queryObject.toString()); - httpPost.setEntity(entity); - response = client.execute(httpPost); - - } catch (UnsupportedEncodingException e) { - BlameCommitLogger.error("Encoding error occured before calling the github graphQL API", e); - e.printStackTrace(); - } catch (ClientProtocolException e) { - BlameCommitLogger.error("Client protocol exception occurred when calling the github graphQL API", e); - - e.printStackTrace(); - } catch (IOException e) { - BlameCommitLogger.error("IO Exception occured when calling the github graphQL API", e); - - e.printStackTrace(); - } - - BufferedReader bufferedReader = null; - try { - bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); - String line; - StringBuilder stringBuilder = new StringBuilder(); - while ((line = bufferedReader.readLine()) != null) { - - stringBuilder.append(line); - } - - String jsonText = stringBuilder.toString(); - Object json = new JSONTokener(jsonText).nextValue(); // gives an object http://stackoverflow.com/questions/14685777/how-to-check-if-response-from-server-is-jsonaobject-or-jsonarray - - if (json instanceof JSONObject) { - JSONObject jsonObject = (JSONObject) json; - returnedObject = jsonObject; - } else if (json instanceof JSONArray) { - JSONArray jsonArray = (JSONArray) json; - returnedObject = jsonArray; - } - - // System.out.println(stringBuilder.toString()); - } catch (Exception e) { - BlameCommitLogger.error("Exception occured when reading the response received from github graphQL API", e); - e.printStackTrace(); - } finally { - - if (bufferedReader != null) { - bufferedReader.close(); - } - } - - return returnedObject; - } - /** * Reading the blame received for a current selected file name and insert the parent commits of the changed lines, * relevant authors and the relevant commits hashes to look for the reviewers of those line ranges @@ -412,7 +343,7 @@ public void iteratingOverForFindingAuthors(String owner, String repositoryName, graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + parentCommitHashForCallingGraphQl + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{ url author { name email } } } } } } } }"); JSONObject rootJsonObject = null; try { - rootJsonObject = (JSONObject) callingGraphQl(graphqlApiJsonObject, gitHubToken); + rootJsonObject = (JSONObject) graphQlApiCaller.callingGraphQl(graphqlApiJsonObject, gitHubToken); readingTheBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, true); } catch (IOException e) { BlameCommitLogger.error("IO Exception occured when calling the github graphQL API for finding the authors of the bug lines which are being fixed by the given patch", e); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java new file mode 100644 index 0000000..1f74e4a --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java @@ -0,0 +1,109 @@ +package com.wso2.code.quality.matrices;/* +* Copyright (c) ${date}, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.log4j.Logger; +import org.json.JSONArray; +import org.json.JSONObject; +import org.json.JSONTokener; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; + +public class GraphQlApiCaller { + + protected static final Logger GraphQlApiCallerLogger= Logger.getLogger(GraphQlApiCaller.class.getName()); + + /** + * Calling the github graphQL API + * + * @param queryObject the JSONObject required for querying + * @param gitHubToken github token for accessing github GraphQL API + * @return Depending on the content return a JSONObject or a JSONArray + * @throws IOException + */ + public Object callingGraphQl(JSONObject queryObject, String gitHubToken) throws IOException { + + CloseableHttpClient client = null; + CloseableHttpResponse response = null; + client = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost("https://api.github.com/graphql"); + httpPost.addHeader("Authorization", "Bearer " + gitHubToken); + httpPost.addHeader("Accept", "application/json"); + Object returnedObject = null; + + try { + StringEntity entity = new StringEntity(queryObject.toString()); + httpPost.setEntity(entity); + response = client.execute(httpPost); + + } catch (UnsupportedEncodingException e) { + GraphQlApiCallerLogger.error("Encoding error occured before calling the github graphQL API", e); + e.printStackTrace(); + } catch (ClientProtocolException e) { + GraphQlApiCallerLogger.error("Client protocol exception occurred when calling the github graphQL API", e); + + e.printStackTrace(); + } catch (IOException e) { + GraphQlApiCallerLogger.error("IO Exception occured when calling the github graphQL API", e); + + e.printStackTrace(); + } + + BufferedReader bufferedReader = null; + try { + bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); + String line; + StringBuilder stringBuilder = new StringBuilder(); + while ((line = bufferedReader.readLine()) != null) { + + stringBuilder.append(line); + } + + String jsonText = stringBuilder.toString(); + Object json = new JSONTokener(jsonText).nextValue(); // gives an object http://stackoverflow.com/questions/14685777/how-to-check-if-response-from-server-is-jsonaobject-or-jsonarray + + if (json instanceof JSONObject) { + JSONObject jsonObject = (JSONObject) json; + returnedObject = jsonObject; + } else if (json instanceof JSONArray) { + JSONArray jsonArray = (JSONArray) json; + returnedObject = jsonArray; + } + + // System.out.println(stringBuilder.toString()); + } catch (Exception e) { + GraphQlApiCallerLogger.error("Exception occured when reading the response received from github graphQL API", e); + e.printStackTrace(); + } finally { + + if (bufferedReader != null) { + bufferedReader.close(); + } + } + + return returnedObject; + } +} From 9ee6d5f4bda3a9096877299c714f1f8aa38b7dd4 Mon Sep 17 00:00:00 2001 From: kasun Date: Wed, 15 Mar 2017 17:03:31 +0530 Subject: [PATCH 14/62] Change the Logger initiliation in classes as suggested in the pull request https://github.com/kasunsiyambalapitiya/CodeQualityMatricesProject/pull/1 format the code --- .../code/quality/matrices/BlameCommit.java | 26 +++++-------------- .../matrices/GitHubAuthentication.java | 24 +++-------------- .../quality/matrices/GraphQlApiCaller.java | 3 +-- .../wso2/code/quality/matrices/MainClass.java | 3 +-- .../code/quality/matrices/RestApiCaller.java | 14 +++++----- .../wso2/code/quality/matrices/Reviewers.java | 12 ++++----- 6 files changed, 25 insertions(+), 57 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java index d2fbe96..1f48280 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java @@ -18,33 +18,22 @@ package com.wso2.code.quality.matrices; -import java.io.BufferedReader; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import org.json.JSONArray; +import org.json.JSONObject; + import java.io.IOException; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; import java.util.stream.IntStream; -import org.apache.commons.lang3.StringUtils; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.log4j.Logger; -import org.json.JSONArray; -import org.json.JSONObject; -import org.json.JSONTokener; - /** * This class is used for getting the blame information on relevant lines changeed from the given patch */ @@ -62,8 +51,7 @@ public class BlameCommit extends RestApiCaller { private String repoLocation[]; GraphQlApiCaller graphQlApiCaller = new GraphQlApiCaller(); - private static final Logger BlameCommitLogger = Logger.getLogger(BlameCommit.class.getName()); - + private static final Logger BlameCommitLogger = Logger.getLogger(BlameCommit.class); public String getUrlForSearchingCommits() { return urlForObtainingCommits; @@ -169,7 +157,7 @@ public void savingRelaventEditLineNumbers(ArrayList fileNames, ArrayList lineChanges[j] = intialLineNoInOldFile + "," + endLineNoOfOldFile + "/" + intialLineNoInNewFile + "," + endLineNoOfNewFile; }); ArrayList tempArrayList = new ArrayList<>(Arrays.asList(lineChanges)); - //adding to the array list which keep track of the line ranges which are being changed to the main arrayList + //adding to the array list which keep track of the line ranges being changed lineRangesChanged.add(tempArrayList); }); System.out.println("done saving file names and their relevant modification line ranges"); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java index 10ad332..0dc9ed5 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java @@ -17,10 +17,9 @@ */ -import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; import org.eclipse.egit.github.core.CommitFile; import org.eclipse.egit.github.core.IRepositoryIdProvider; -import org.eclipse.egit.github.core.Repository; import org.eclipse.egit.github.core.RepositoryCommit; import org.eclipse.egit.github.core.client.GitHubClient; import org.eclipse.egit.github.core.service.CommitService; @@ -29,7 +28,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -44,14 +42,13 @@ public class GitHubAuthentication { protected ArrayList fileNames = new ArrayList(); protected ArrayList patchString = new ArrayList(); + private static final Logger githubAuthenticationLogger = Logger.getLogger(GitHubAuthentication.class); GitHubAuthentication(String githubToken) { gitHubClient = new GitHubClient(); gitHubClient.setOAuth2Token(githubToken); commitService = new CommitService(gitHubClient); repositoryService = new RepositoryService(gitHubClient); - - } /** @@ -61,36 +58,21 @@ public class GitHubAuthentication { */ public Map> gettingFilesChanged(String repositoryName, String commitHash) { Map> mapWithFileNamesAndPatches = new HashMap<>(); - try { -// Repository repository = repositoryService.getRepository("wso2", "carbon-apimgt"); -// String id = repository.generateId(); - IRepositoryIdProvider iRepositoryIdProvider = () -> repositoryName; RepositoryCommit repositoryCommit = commitService.getCommit(iRepositoryIdProvider, commitHash); List filesChanged = repositoryCommit.getFiles(); - -// Iterator listIterator = filesChanged.iterator(); // this can be run parallely as patchString of a file will always be in the same index as the file filesChanged.parallelStream().forEach(commitFile -> { fileNames.add(commitFile.getFilename()); patchString.add(commitFile.getPatch()); }); -// while (listIterator.hasNext()) { -// CommitFile commitFile = (CommitFile) listIterator.next(); -// -// -// } -// System.out.println(fileNames); + githubAuthenticationLogger.info("for" + commitHash + " on the " + repositoryName + " repository, files changed and their relevant changed line ranges added to the arraylists successfully"); mapWithFileNamesAndPatches.put("fileNames", fileNames); mapWithFileNamesAndPatches.put("patchString", patchString); - - } catch (IOException e) { e.printStackTrace(); } return mapWithFileNamesAndPatches; - } - } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java index 1f74e4a..b713c6f 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java @@ -34,7 +34,7 @@ public class GraphQlApiCaller { - protected static final Logger GraphQlApiCallerLogger= Logger.getLogger(GraphQlApiCaller.class.getName()); + protected static final Logger GraphQlApiCallerLogger = Logger.getLogger(GraphQlApiCaller.class); /** * Calling the github graphQL API @@ -103,7 +103,6 @@ public Object callingGraphQl(JSONObject queryObject, String gitHubToken) throws bufferedReader.close(); } } - return returnedObject; } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index f31ddce..2e0eba2 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -29,7 +29,7 @@ * should be passed as command line arguments when running the application */ public class MainClass { - private final static Logger logger = Logger.getLogger(MainClass.class.getName()); + private final static Logger logger = Logger.getLogger(MainClass.class); public static void main(String[] args) { logger.info(" Main method got executed"); @@ -60,6 +60,5 @@ public static void main(String[] args) { Reviewers reviewers = new Reviewers(); reviewers.findingReviewers(commitHashObtainedForPRReview, gitHubToken); - } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java index be97997..d5751c5 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java @@ -18,19 +18,19 @@ package com.wso2.code.quality.matrices; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; - import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.log4j.Logger; -import org.json.JSONTokener; -import org.json.JSONObject; import org.json.JSONArray; +import org.json.JSONObject; +import org.json.JSONTokener; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; /** * This class is used to call the REST API of both WSO2 PMT and github.com @@ -38,7 +38,7 @@ public class RestApiCaller { - static Logger restApiCallerLogger = Logger.getLogger(RestApiCaller.class.getName()); + static Logger restApiCallerLogger = Logger.getLogger(RestApiCaller.class); /** * calling the relevant API and saving the output to a file diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java index 18ea16e..aa6890c 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java @@ -18,17 +18,17 @@ package com.wso2.code.quality.matrices; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import org.json.JSONArray; +import org.json.JSONObject; + import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; -import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; -import org.json.JSONArray; -import org.json.JSONObject; - /** * This class is used to find the revierwers of the buggy lines of code */ @@ -40,7 +40,7 @@ public class Reviewers extends BlameCommit { Set approvedReviewers = new HashSet(); // to store the reviewed and approved users of the pull requests Set commentedReviewers = new HashSet(); // to store the reviewed and commented users of the pull requests - private static final Logger reviewersLogger = Logger.getLogger(Reviewers.class.getName()); + private static final Logger reviewersLogger = Logger.getLogger(Reviewers.class); public String getSearchPullReqeustAPI() { return searchPullReqeustAPIUrl; From f4c2571fe1b66aa8db7d9ec9259859abd087f3d8 Mon Sep 17 00:00:00 2001 From: kasun Date: Wed, 15 Mar 2017 17:33:45 +0530 Subject: [PATCH 15/62] fix the copyright header --- .../code/quality/matrices/BlameCommit.java | 24 ++++++------- .../matrices/GitHubAuthentication.java | 35 +++++++++--------- .../quality/matrices/GraphQlApiCaller.java | 36 ++++++++++--------- .../wso2/code/quality/matrices/MainClass.java | 24 ++++++------- .../com/wso2/code/quality/matrices/Pmt.java | 24 ++++++------- .../code/quality/matrices/RestApiCaller.java | 24 ++++++------- .../wso2/code/quality/matrices/Reviewers.java | 24 ++++++------- 7 files changed, 97 insertions(+), 94 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java index 1f48280..07febee 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java @@ -1,19 +1,19 @@ /* - * Copyright (c) 2017 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package com.wso2.code.quality.matrices; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java index 0dc9ed5..4efd6b5 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java @@ -1,21 +1,22 @@ -package com.wso2.code.quality.matrices;/* -* Copyright (c) ${date}, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -* WSO2 Inc. licenses this file to you under the Apache License, -* Version 2.0 (the "License"); you may not use this file except -* in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.wso2.code.quality.matrices; import org.apache.log4j.Logger; import org.eclipse.egit.github.core.CommitFile; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java index b713c6f..7d59e3a 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java @@ -1,20 +1,22 @@ -package com.wso2.code.quality.matrices;/* -* Copyright (c) ${date}, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -* WSO2 Inc. licenses this file to you under the Apache License, -* Version 2.0 (the "License"); you may not use this file except -* in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index 2e0eba2..c6253e9 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -1,19 +1,19 @@ /* - * Copyright (c) 2017 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package com.wso2.code.quality.matrices; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java index 987ffd1..fb58fcd 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java @@ -1,19 +1,19 @@ /* - * Copyright (c) 2017 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package com.wso2.code.quality.matrices; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java index d5751c5..3d2a8d9 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java @@ -1,19 +1,19 @@ /* - * Copyright (c) 2017 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package com.wso2.code.quality.matrices; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java index aa6890c..eecb8ed 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java @@ -1,19 +1,19 @@ /* - * Copyright (c) 2017 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package com.wso2.code.quality.matrices; From ebfef31b597d75645181a9faf6735653d9a4e710 Mon Sep 17 00:00:00 2001 From: kasun Date: Thu, 16 Mar 2017 13:56:30 +0530 Subject: [PATCH 16/62] add CodeQualityMatricesException class --- .../CodeQualityMatricesException.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java new file mode 100644 index 0000000..de07755 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices;/* +* Copyright (c) ${date}, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +public class CodeQualityMatricesException extends Exception { + public CodeQualityMatricesException(String message) { + super(message); + } + public CodeQualityMatricesException(String message, Throwable cause) { + super(message, cause); + } +} From 3c76e95538ab63780c543a9ef8acdae22ee92ddc Mon Sep 17 00:00:00 2001 From: kasun Date: Thu, 16 Mar 2017 14:09:48 +0530 Subject: [PATCH 17/62] Add exceptions for classes --- .../code/quality/matrices/BlameCommit.java | 14 +++++++++-- .../CodeQualityMatricesException.java | 23 +++++-------------- .../matrices/GitHubAuthentication.java | 5 ++-- .../wso2/code/quality/matrices/MainClass.java | 8 ++++++- .../wso2/code/quality/matrices/Reviewers.java | 14 +++++++++-- 5 files changed, 40 insertions(+), 24 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java index 07febee..14fb941 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java @@ -74,7 +74,12 @@ public Set obtainingRepoNamesForCommitHashes(String gitHubToken, String[] commit //calling the API calling method IntStream.range(0, commitsInTheGivenPatch.length).mapToObj(i -> commitsInTheGivenPatch[i]).forEach(commitHash -> { setUrlForSearchingCommits(commitHash); - JSONObject jsonObject = (JSONObject) restApiCaller.callingTheAPI(getUrlForSearchingCommits(), gitHubToken, true, false); + JSONObject jsonObject = null; + try { + jsonObject = (JSONObject) restApiCaller.callingTheAPI(getUrlForSearchingCommits(), gitHubToken, true, false); + } catch (Exception e) { + System.out.println(e.getMessage() + "cause" + e.getCause()); + } saveRepoNamesInAnArray(jsonObject, commitHash, gitHubToken); }); return commitHashObtainedForPRReview; @@ -109,7 +114,12 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, fileNames.clear(); lineRangesChanged.clear(); patchString.clear(); - Map> mapWithFileNamesAndPatch = gitHubAuthentication.gettingFilesChanged(repoLocation[i], commitHash); + Map> mapWithFileNamesAndPatch = null; + try { + mapWithFileNamesAndPatch = gitHubAuthentication.gettingFilesChanged(repoLocation[i], commitHash); + } catch (Exception e) { + System.out.println(e.getMessage() + "cause" + e.getCause()); + } fileNames = mapWithFileNamesAndPatch.get("fileNames"); patchString = mapWithFileNamesAndPatch.get("patchString"); savingRelaventEditLineNumbers(fileNames, patchString); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java index de07755..e3b7247 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java @@ -16,24 +16,13 @@ * under the License. */ -package com.wso2.code.quality.matrices;/* -* Copyright (c) ${date}, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -* WSO2 Inc. licenses this file to you under the Apache License, -* Version 2.0 (the "License"); you may not use this file except -* in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ +package com.wso2.code.quality.matrices; +/** + * The exception class for all Code Quality Matrices project related exceptions + * + * + */ public class CodeQualityMatricesException extends Exception { public CodeQualityMatricesException(String message) { super(message); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java index 4efd6b5..1768242 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java @@ -57,7 +57,7 @@ public class GitHubAuthentication { * @param commitHash The querying commit hash * @return a map containg arraylist of file changed and their relevant patch */ - public Map> gettingFilesChanged(String repositoryName, String commitHash) { + public Map> gettingFilesChanged(String repositoryName, String commitHash) throws CodeQualityMatricesException { Map> mapWithFileNamesAndPatches = new HashMap<>(); try { IRepositoryIdProvider iRepositoryIdProvider = () -> repositoryName; @@ -72,7 +72,8 @@ public Map> gettingFilesChanged(String repositoryName, mapWithFileNamesAndPatches.put("fileNames", fileNames); mapWithFileNamesAndPatches.put("patchString", patchString); } catch (IOException e) { - e.printStackTrace(); + githubAuthenticationLogger.error("IO Exception occurred when getting the commit with the given SHA form the given repository ",e); + throw new CodeQualityMatricesException("IO Exception occurred when getting the commit with the given SHA form the given repository ",e); } return mapWithFileNamesAndPatches; } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index c6253e9..17b1e19 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -40,7 +40,13 @@ public static void main(String[] args) { String pmtUrl = "http://umt.private.wso2.com:9765/codequalitymatricesapi/1.0.0//properties?path=/_system/governance/patchs/" + patchId; RestApiCaller restApiCaller = new RestApiCaller(); - JSONArray jsonArray = (JSONArray) restApiCaller.callingTheAPI(pmtUrl, pmtToken, false, false); + JSONArray jsonArray = null; + try { + jsonArray = (JSONArray) restApiCaller.callingTheAPI(pmtUrl, pmtToken, false, false); + } catch (Exception e) { + System.out.println(e.getMessage()+"cause"+e.getCause()); + + } logger.info("JSON response is received successfully from WSO2 PMT for the given patch " + args[1]); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java index eecb8ed..b68d0e8 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java @@ -79,7 +79,12 @@ public void findingReviewers(Set commitHashObtainedForPRReview, String g String commitHashForFindingReviewers = (String) commitHashObtainedForPRReviewIterator.next(); setSearchPullReqeustAPI(commitHashForFindingReviewers); // calling the github search API - JSONObject rootJsonObject = (JSONObject) callingTheAPI(getSearchPullReqeustAPI(), githubToken, false, true); + JSONObject rootJsonObject = null; + try { + rootJsonObject = (JSONObject) callingTheAPI(getSearchPullReqeustAPI(), githubToken, false, true); + } catch (Exception e) { + System.out.println(e.getMessage() + "cause" + e.getCause()); + } // reading thus saved json file savingPrNumberAndRepoName(rootJsonObject); } @@ -130,7 +135,12 @@ public void savingReviewersToList(String githubToken) { while (prNumberIterator.hasNext()) { int prNumber = (int) prNumberIterator.next(); setPullRequestReviewAPIUrl(productLocation, prNumber); - JSONArray rootJsonArray = (JSONArray) callingTheAPI(getPullRequestReviewAPIUrl(), githubToken, false, true); + JSONArray rootJsonArray = null; + try { + rootJsonArray = (JSONArray) callingTheAPI(getPullRequestReviewAPIUrl(), githubToken, false, true); + } catch (Exception e) { + System.out.println(e.getMessage() + "cause" + e.getCause()); + } // for reading the output JSON from above and adding the reviewers to the Set readingTheReviewOutJSON(rootJsonArray, productLocation, prNumber); } From 0efc4b2706d2c6629339576ecbb83bef00ada069 Mon Sep 17 00:00:00 2001 From: kasun Date: Thu, 16 Mar 2017 14:11:04 +0530 Subject: [PATCH 18/62] Remove invalid user input handling in RestApiCaller.java --- .../code/quality/matrices/RestApiCaller.java | 104 ++++-------------- 1 file changed, 22 insertions(+), 82 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java index 3d2a8d9..c0cef2e 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java @@ -49,7 +49,7 @@ public class RestApiCaller { * @param requireReviewHeader should be true for accessing the github review API or false otherwise */ - public Object callingTheAPI(String URL, String token, boolean requireCommitHeader, boolean requireReviewHeader) { + public Object callingTheAPI(String URL, String token, boolean requireCommitHeader, boolean requireReviewHeader) throws CodeQualityMatricesException { BufferedReader bufferedReader = null; CloseableHttpClient httpclient = null; @@ -76,80 +76,32 @@ public Object callingTheAPI(String URL, String token, boolean requireCommitHeade } httpResponse = httpclient.execute(httpGet); - int responseCode = httpResponse.getStatusLine().getStatusCode(); // to get the response code - - switch (responseCode) { - case 200: - //success - bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8")); - StringBuilder stringBuilder = new StringBuilder(); - String line; - while ((line = bufferedReader.readLine()) != null) { - stringBuilder.append(line); - } - - // creating a JSON object from the response - String JSONText = stringBuilder.toString(); - Object json = new JSONTokener(JSONText).nextValue(); // gives an object http://stackoverflow.com/questions/14685777/how-to-check-if-response-from-server-is-jsonaobject-or-jsonarray - - if (json instanceof JSONObject) { - JSONObject jsonObject = (JSONObject) json; - returnedObject = jsonObject; - } else if (json instanceof JSONArray) { - JSONArray jsonArray = (JSONArray) json; - returnedObject = jsonArray; - } - - restApiCallerLogger.info("JSON response is passed after calling the given REST API"); - - break; - case 401: - // to handle Response code 401: Unauthorized - System.err.print("Response code 401 : Git hub access token is invalid"); - try { - - Thread.sleep(100); - runningTheAppAgain(); - } catch (InterruptedException e) { - restApiCallerLogger.error("InterruptedException occurred when validating the github user", e); - e.printStackTrace(); - } - break; - case 403: - // to handle invalid credentials - System.err.println("Response Code:403 Invalid Credentials, insert a correct token"); - try { - - Thread.sleep(100); - runningTheAppAgain(); - } catch (InterruptedException e) { - restApiCallerLogger.error("InterruptedException occurred when validating the WSO2 PMT user", e); - e.printStackTrace(); - } - - break; - case 404: - // to handle invalid patch - System.err.println("Reponse Code 404: Patch not found, enter a valid patch"); - try { - Thread.sleep(100); - runningTheAppAgain(); - - } catch (InterruptedException e) { - restApiCallerLogger.error("InterruptedException occurred when validating the given patch", e); - e.printStackTrace(); - } - - break; - default: - returnedObject = null; + bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8")); + StringBuilder stringBuilder = new StringBuilder(); + String line; + while ((line = bufferedReader.readLine()) != null) { + stringBuilder.append(line); } + + // creating a JSON object from the response + String JSONText = stringBuilder.toString(); + Object json = new JSONTokener(JSONText).nextValue(); // gives an object http://stackoverflow.com/questions/14685777/how-to-check-if-response-from-server-is-jsonaobject-or-jsonarray + + if (json instanceof JSONObject) { + JSONObject jsonObject = (JSONObject) json; + returnedObject = jsonObject; + } else if (json instanceof JSONArray) { + JSONArray jsonArray = (JSONArray) json; + returnedObject = jsonArray; + } + restApiCallerLogger.info("JSON response is passed after calling the given REST API"); + } catch (ClientProtocolException e) { restApiCallerLogger.error("ClientProtocolException when calling the REST API", e); - e.printStackTrace(); + throw new CodeQualityMatricesException("ClientProtocolException when calling the REST API", e); } catch (IOException e) { restApiCallerLogger.error("IOException occurred when calling the REST API"); - e.printStackTrace(); + throw new CodeQualityMatricesException("IOException occurred when calling the REST API", e); } finally { if (bufferedReader != null) { @@ -177,18 +129,6 @@ public Object callingTheAPI(String URL, String token, boolean requireCommitHeade } return returnedObject; } - - /** - * this method calls the main method again when incorrect inputs are supplied - */ - public void runningTheAppAgain() { - try { - MainClass.main(null); - } catch (Exception e) { - restApiCallerLogger.error("Exception occurred when running the main method again after invalid inputs"); - e.printStackTrace(); - } - } } From 960a85938585ff3e02efeccf7b5c97e6239d9298 Mon Sep 17 00:00:00 2001 From: kasun Date: Thu, 16 Mar 2017 14:27:18 +0530 Subject: [PATCH 19/62] Rename log object and fixed possible null value passings --- .../wso2/code/quality/matrices/BlameCommit.java | 12 ++++++------ .../quality/matrices/GitHubAuthentication.java | 6 +++--- .../code/quality/matrices/GraphQlApiCaller.java | 10 +++++----- .../wso2/code/quality/matrices/MainClass.java | 16 ++++++++++++---- .../code/quality/matrices/RestApiCaller.java | 8 ++++---- .../wso2/code/quality/matrices/Reviewers.java | 16 ++++++++++------ 6 files changed, 40 insertions(+), 28 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java index 14fb941..fda9a42 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java @@ -51,7 +51,7 @@ public class BlameCommit extends RestApiCaller { private String repoLocation[]; GraphQlApiCaller graphQlApiCaller = new GraphQlApiCaller(); - private static final Logger BlameCommitLogger = Logger.getLogger(BlameCommit.class); + private static final Logger logger = Logger.getLogger(BlameCommit.class); public String getUrlForSearchingCommits() { return urlForObtainingCommits; @@ -103,7 +103,7 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, JSONObject repositoryJsonObject = (JSONObject) jsonObject.get("repository"); repoLocation[i] = (String) repositoryJsonObject.get("full_name"); }); - BlameCommitLogger.info("Repo names having the given commit are successfully saved in an array"); + logger.info("Repo names having the given commit are successfully saved in an array"); GitHubAuthentication gitHubAuthentication = new GitHubAuthentication(gitHubToken); @@ -201,7 +201,7 @@ public void iteratingOver(String repoLocation, String commitHash, String gitHubT // calling the graphql API for getting blame information for the current file and saving it in a location. rootJsonObject = (JSONObject) graphQlApiCaller.callingGraphQl(graphqlApiJsonObject, gitHubToken); } catch (IOException e) { - BlameCommitLogger.error("IO exception occurred when calling the github graphQL API ", e); + logger.error("IO exception occurred when calling the github graphQL API ", e); e.printStackTrace(); } // reading the above saved output for the current selected file name @@ -210,7 +210,7 @@ public void iteratingOver(String repoLocation, String commitHash, String gitHubT // parent commit hashes are stored in the arraylist for the given file iteratingOverForFindingAuthors(owner, repositoryName, fileName, arrayListOfRelevantChangedLines, gitHubToken); - BlameCommitLogger.info("Authors of the bug lines of code which are being fixed from the given patch are saved successfully to authorNames SET"); + logger.info("Authors of the bug lines of code which are being fixed from the given patch are saved successfully to authorNames SET"); }); } @@ -318,7 +318,7 @@ public void readingTheBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList commitHashesOfTheParent.add(commitHash); }); - BlameCommitLogger.info("Parent Commits hashes of the lines which are being fixed by the patch are saved to commitHashesOfTheParent SET successfully "); + logger.info("Parent Commits hashes of the lines which are being fixed by the patch are saved to commitHashesOfTheParent SET successfully "); } } }); @@ -344,7 +344,7 @@ public void iteratingOverForFindingAuthors(String owner, String repositoryName, rootJsonObject = (JSONObject) graphQlApiCaller.callingGraphQl(graphqlApiJsonObject, gitHubToken); readingTheBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, true); } catch (IOException e) { - BlameCommitLogger.error("IO Exception occured when calling the github graphQL API for finding the authors of the bug lines which are being fixed by the given patch", e); + logger.error("IO Exception occured when calling the github graphQL API for finding the authors of the bug lines which are being fixed by the given patch", e); e.printStackTrace(); } }); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java index 1768242..24fad7a 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java @@ -43,7 +43,7 @@ public class GitHubAuthentication { protected ArrayList fileNames = new ArrayList(); protected ArrayList patchString = new ArrayList(); - private static final Logger githubAuthenticationLogger = Logger.getLogger(GitHubAuthentication.class); + private static final Logger logger = Logger.getLogger(GitHubAuthentication.class); GitHubAuthentication(String githubToken) { gitHubClient = new GitHubClient(); @@ -68,11 +68,11 @@ public Map> gettingFilesChanged(String repositoryName, fileNames.add(commitFile.getFilename()); patchString.add(commitFile.getPatch()); }); - githubAuthenticationLogger.info("for" + commitHash + " on the " + repositoryName + " repository, files changed and their relevant changed line ranges added to the arraylists successfully"); + logger.info("for" + commitHash + " on the " + repositoryName + " repository, files changed and their relevant changed line ranges added to the arraylists successfully"); mapWithFileNamesAndPatches.put("fileNames", fileNames); mapWithFileNamesAndPatches.put("patchString", patchString); } catch (IOException e) { - githubAuthenticationLogger.error("IO Exception occurred when getting the commit with the given SHA form the given repository ",e); + logger.error("IO Exception occurred when getting the commit with the given SHA form the given repository ",e); throw new CodeQualityMatricesException("IO Exception occurred when getting the commit with the given SHA form the given repository ",e); } return mapWithFileNamesAndPatches; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java index 7d59e3a..12c2e12 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java @@ -36,7 +36,7 @@ public class GraphQlApiCaller { - protected static final Logger GraphQlApiCallerLogger = Logger.getLogger(GraphQlApiCaller.class); + protected static final Logger logger = Logger.getLogger(GraphQlApiCaller.class); /** * Calling the github graphQL API @@ -62,14 +62,14 @@ public Object callingGraphQl(JSONObject queryObject, String gitHubToken) throws response = client.execute(httpPost); } catch (UnsupportedEncodingException e) { - GraphQlApiCallerLogger.error("Encoding error occured before calling the github graphQL API", e); + logger.error("Encoding error occured before calling the github graphQL API", e); e.printStackTrace(); } catch (ClientProtocolException e) { - GraphQlApiCallerLogger.error("Client protocol exception occurred when calling the github graphQL API", e); + logger.error("Client protocol exception occurred when calling the github graphQL API", e); e.printStackTrace(); } catch (IOException e) { - GraphQlApiCallerLogger.error("IO Exception occured when calling the github graphQL API", e); + logger.error("IO Exception occured when calling the github graphQL API", e); e.printStackTrace(); } @@ -97,7 +97,7 @@ public Object callingGraphQl(JSONObject queryObject, String gitHubToken) throws // System.out.println(stringBuilder.toString()); } catch (Exception e) { - GraphQlApiCallerLogger.error("Exception occured when reading the response received from github graphQL API", e); + logger.error("Exception occured when reading the response received from github graphQL API", e); e.printStackTrace(); } finally { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index 17b1e19..6fba940 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -44,14 +44,17 @@ public static void main(String[] args) { try { jsonArray = (JSONArray) restApiCaller.callingTheAPI(pmtUrl, pmtToken, false, false); } catch (Exception e) { - System.out.println(e.getMessage()+"cause"+e.getCause()); + System.out.println(e.getMessage() + "cause" + e.getCause()); } logger.info("JSON response is received successfully from WSO2 PMT for the given patch " + args[1]); Pmt pmt = new Pmt(); - String[] commitsInTheGivenPatch = pmt.getThePublicGitCommitId(jsonArray); + String[] commitsInTheGivenPatch = null; + if (jsonArray != null) { + commitsInTheGivenPatch = pmt.getThePublicGitCommitId(jsonArray); + } logger.info("Commits received from WSO2 PMT are saved in an array successfully"); logger.info("Commits received from WSO2 PMT are saved in an array successfully"); @@ -59,12 +62,17 @@ public static void main(String[] args) { String gitHubToken = args[2]; BlameCommit blameCommit = new BlameCommit(); - Set commitHashObtainedForPRReview = blameCommit.obtainingRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); + Set commitHashObtainedForPRReview = null; + if (commitsInTheGivenPatch != null) { + commitHashObtainedForPRReview = blameCommit.obtainingRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); + } logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); Reviewers reviewers = new Reviewers(); - reviewers.findingReviewers(commitHashObtainedForPRReview, gitHubToken); + if (commitHashObtainedForPRReview != null) { + reviewers.findingReviewers(commitHashObtainedForPRReview, gitHubToken); + } } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java index c0cef2e..8a95bd6 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java @@ -38,7 +38,7 @@ public class RestApiCaller { - static Logger restApiCallerLogger = Logger.getLogger(RestApiCaller.class); + private static Logger logger = Logger.getLogger(RestApiCaller.class); /** * calling the relevant API and saving the output to a file @@ -94,13 +94,13 @@ public Object callingTheAPI(String URL, String token, boolean requireCommitHeade JSONArray jsonArray = (JSONArray) json; returnedObject = jsonArray; } - restApiCallerLogger.info("JSON response is passed after calling the given REST API"); + logger.info("JSON response is passed after calling the given REST API"); } catch (ClientProtocolException e) { - restApiCallerLogger.error("ClientProtocolException when calling the REST API", e); + logger.error("ClientProtocolException when calling the REST API", e); throw new CodeQualityMatricesException("ClientProtocolException when calling the REST API", e); } catch (IOException e) { - restApiCallerLogger.error("IOException occurred when calling the REST API"); + logger.error("IOException occurred when calling the REST API"); throw new CodeQualityMatricesException("IOException occurred when calling the REST API", e); } finally { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java index b68d0e8..b143bb3 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java @@ -40,7 +40,7 @@ public class Reviewers extends BlameCommit { Set approvedReviewers = new HashSet(); // to store the reviewed and approved users of the pull requests Set commentedReviewers = new HashSet(); // to store the reviewed and commented users of the pull requests - private static final Logger reviewersLogger = Logger.getLogger(Reviewers.class); + private static final Logger logger = Logger.getLogger(Reviewers.class); public String getSearchPullReqeustAPI() { return searchPullReqeustAPIUrl; @@ -86,14 +86,16 @@ public void findingReviewers(Set commitHashObtainedForPRReview, String g System.out.println(e.getMessage() + "cause" + e.getCause()); } // reading thus saved json file - savingPrNumberAndRepoName(rootJsonObject); + if (rootJsonObject != null) { + savingPrNumberAndRepoName(rootJsonObject); + } } - reviewersLogger.info("PR numbers which introduce bug lines of code with their relevant repository are saved successfully to mapContainingPRNoAgainstRepoName map"); + logger.info("PR numbers which introduce bug lines of code with their relevant repository are saved successfully to mapContainingPRNoAgainstRepoName map"); savingReviewersToList(githubToken); - reviewersLogger.info("List of approved reviwers and comment users of the PRs which introduce bug lines to repository are saved in commentedReviewers and approvedReviewers list "); + logger.info("List of approved reviwers and comment users of the PRs which introduce bug lines to repository are saved in commentedReviewers and approvedReviewers list "); // printing the list of reviewers of pull requests printReviewUsers(); - reviewersLogger.info("Names of approved reviewers and commented reviewers are printed successfully"); + logger.info("Names of approved reviewers and commented reviewers are printed successfully"); } /** @@ -142,7 +144,9 @@ public void savingReviewersToList(String githubToken) { System.out.println(e.getMessage() + "cause" + e.getCause()); } // for reading the output JSON from above and adding the reviewers to the Set - readingTheReviewOutJSON(rootJsonArray, productLocation, prNumber); + if (rootJsonArray != null) { + readingTheReviewOutJSON(rootJsonArray, productLocation, prNumber); + } } } } From 57592c6d9def0d5a0bd16d1d1fb5db5ffa2cf0fe Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 17 Mar 2017 10:26:08 +0530 Subject: [PATCH 20/62] fix the changes asked by DilanUA in PR 2 --- .../code/quality/matrices/BlameCommit.java | 26 +++++++++------- .../CodeQualityMatricesException.java | 4 +-- .../matrices/GitHubAuthentication.java | 11 +++++-- .../quality/matrices/GraphQlApiCaller.java | 30 +++++++++++-------- .../wso2/code/quality/matrices/MainClass.java | 6 ---- .../code/quality/matrices/RestApiCaller.java | 11 +++---- 6 files changed, 49 insertions(+), 39 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java index fda9a42..dbffb83 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java @@ -80,7 +80,11 @@ public Set obtainingRepoNamesForCommitHashes(String gitHubToken, String[] commit } catch (Exception e) { System.out.println(e.getMessage() + "cause" + e.getCause()); } - saveRepoNamesInAnArray(jsonObject, commitHash, gitHubToken); + try { + saveRepoNamesInAnArray(jsonObject, commitHash, gitHubToken); + } catch (CodeQualityMatricesException e) { + logger.error("IO exception occurred when calling the github graphQL API", e); + } }); return commitHashObtainedForPRReview; } @@ -93,7 +97,7 @@ public Set obtainingRepoNamesForCommitHashes(String gitHubToken, String[] commit * @param gitHubToken github token for accessing the github REST API */ - public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, String gitHubToken) { + public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, String gitHubToken) throws CodeQualityMatricesException { JSONArray jsonArrayOfItems = (JSONArray) rootJsonObject.get("items"); // setting the size of the repoLocationArray repoLocation = new String[jsonArrayOfItems.length()]; @@ -123,7 +127,11 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, fileNames = mapWithFileNamesAndPatch.get("fileNames"); patchString = mapWithFileNamesAndPatch.get("patchString"); savingRelaventEditLineNumbers(fileNames, patchString); - iteratingOver(repoLocation[i], commitHash, gitHubToken); + try { + iteratingOver(repoLocation[i], commitHash, gitHubToken); + } catch (Exception e) { + System.out.println(e.getMessage() + "cause" + e.getCause()); + } }); @@ -200,10 +208,8 @@ public void iteratingOver(String repoLocation, String commitHash, String gitHubT try { // calling the graphql API for getting blame information for the current file and saving it in a location. rootJsonObject = (JSONObject) graphQlApiCaller.callingGraphQl(graphqlApiJsonObject, gitHubToken); - } catch (IOException e) { - logger.error("IO exception occurred when calling the github graphQL API ", e); - e.printStackTrace(); - } + } catch (CodeQualityMatricesException e) { + System.out.println(e.getMessage() + "cause" + e.getCause()); } // reading the above saved output for the current selected file name readingTheBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, false); @@ -343,10 +349,8 @@ public void iteratingOverForFindingAuthors(String owner, String repositoryName, try { rootJsonObject = (JSONObject) graphQlApiCaller.callingGraphQl(graphqlApiJsonObject, gitHubToken); readingTheBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, true); - } catch (IOException e) { - logger.error("IO Exception occured when calling the github graphQL API for finding the authors of the bug lines which are being fixed by the given patch", e); - e.printStackTrace(); - } + } catch (CodeQualityMatricesException e) { + System.out.println(e.getMessage() + "cause" + e.getCause()); } }); } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java index e3b7247..e281bfe 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java @@ -19,9 +19,9 @@ package com.wso2.code.quality.matrices; /** - * The exception class for all Code Quality Matrices project related exceptions - * + * The exception class for all Code Quality Matrices project related exceptions. * + *@since 1.0.0 */ public class CodeQualityMatricesException extends Exception { public CodeQualityMatricesException(String message) { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java index 24fad7a..661763c 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java @@ -33,7 +33,9 @@ import java.util.Map; /** - * This class is used for communicating with the github REST API from egit github API + * This class is used for communicating with the github REST API from egit github API. + * + * @since 1.0.0 */ public class GitHubAuthentication { @@ -53,6 +55,9 @@ public class GitHubAuthentication { } /** + * This method is used for saving the files changed and their relevant changed line ranges from + * the given commit in the given repository + * * @param repositoryName The repository name that contain the given commit hash * @param commitHash The querying commit hash * @return a map containg arraylist of file changed and their relevant patch @@ -72,8 +77,8 @@ public Map> gettingFilesChanged(String repositoryName, mapWithFileNamesAndPatches.put("fileNames", fileNames); mapWithFileNamesAndPatches.put("patchString", patchString); } catch (IOException e) { - logger.error("IO Exception occurred when getting the commit with the given SHA form the given repository ",e); - throw new CodeQualityMatricesException("IO Exception occurred when getting the commit with the given SHA form the given repository ",e); + logger.error("IO Exception occurred when getting the commit with the given SHA form the given repository ", e); + throw new CodeQualityMatricesException("IO Exception occurred when getting the commit with the given SHA form the given repository ", e); } return mapWithFileNamesAndPatches; } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java index 12c2e12..b4d006e 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java @@ -34,19 +34,25 @@ import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; +/** + * This class is used for calling the GithubGraphQL API which is currently in early access mode. + * + * @since 1.0.0 + */ + public class GraphQlApiCaller { protected static final Logger logger = Logger.getLogger(GraphQlApiCaller.class); /** - * Calling the github graphQL API + * Calls the github graphQL API and returns the relevant JSON response received * * @param queryObject the JSONObject required for querying * @param gitHubToken github token for accessing github GraphQL API * @return Depending on the content return a JSONObject or a JSONArray * @throws IOException */ - public Object callingGraphQl(JSONObject queryObject, String gitHubToken) throws IOException { + public Object callingGraphQl(JSONObject queryObject, String gitHubToken) throws CodeQualityMatricesException { CloseableHttpClient client = null; CloseableHttpResponse response = null; @@ -60,18 +66,15 @@ public Object callingGraphQl(JSONObject queryObject, String gitHubToken) throws StringEntity entity = new StringEntity(queryObject.toString()); httpPost.setEntity(entity); response = client.execute(httpPost); - } catch (UnsupportedEncodingException e) { logger.error("Encoding error occured before calling the github graphQL API", e); - e.printStackTrace(); + throw new CodeQualityMatricesException("Encoding error occured before calling the github graphQL API",e); } catch (ClientProtocolException e) { logger.error("Client protocol exception occurred when calling the github graphQL API", e); - - e.printStackTrace(); + throw new CodeQualityMatricesException("Client protocol exception occurred when calling the github graphQL API",e); } catch (IOException e) { logger.error("IO Exception occured when calling the github graphQL API", e); - - e.printStackTrace(); + throw new CodeQualityMatricesException("IO Exception occured when calling the github graphQL API",e); } BufferedReader bufferedReader = null; @@ -80,7 +83,6 @@ public Object callingGraphQl(JSONObject queryObject, String gitHubToken) throws String line; StringBuilder stringBuilder = new StringBuilder(); while ((line = bufferedReader.readLine()) != null) { - stringBuilder.append(line); } @@ -98,11 +100,15 @@ public Object callingGraphQl(JSONObject queryObject, String gitHubToken) throws // System.out.println(stringBuilder.toString()); } catch (Exception e) { logger.error("Exception occured when reading the response received from github graphQL API", e); - e.printStackTrace(); + throw new CodeQualityMatricesException("Exception occured when reading the response received from github graphQL API",e); } finally { - if (bufferedReader != null) { - bufferedReader.close(); + try { + bufferedReader.close(); + } catch (IOException e) { + logger.error("IOException occured when closing the buffered reader",e); + throw new CodeQualityMatricesException("IOException occured when closing the buffered reader",e); + } } } return returnedObject; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index 6fba940..888e54b 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -47,7 +47,6 @@ public static void main(String[] args) { System.out.println(e.getMessage() + "cause" + e.getCause()); } - logger.info("JSON response is received successfully from WSO2 PMT for the given patch " + args[1]); Pmt pmt = new Pmt(); @@ -57,10 +56,7 @@ public static void main(String[] args) { } logger.info("Commits received from WSO2 PMT are saved in an array successfully"); - logger.info("Commits received from WSO2 PMT are saved in an array successfully"); - String gitHubToken = args[2]; - BlameCommit blameCommit = new BlameCommit(); Set commitHashObtainedForPRReview = null; if (commitsInTheGivenPatch != null) { @@ -68,8 +64,6 @@ public static void main(String[] args) { } logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); - logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); - Reviewers reviewers = new Reviewers(); if (commitHashObtainedForPRReview != null) { reviewers.findingReviewers(commitHashObtainedForPRReview, gitHubToken); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java index 8a95bd6..979abb6 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java @@ -108,7 +108,8 @@ public Object callingTheAPI(String URL, String token, boolean requireCommitHeade try { bufferedReader.close(); } catch (IOException e) { - e.printStackTrace(); + logger.error("IOException occurred when closing the BufferedReader"); + throw new CodeQualityMatricesException("IOException occurred when closing the BufferedReader", e); } } @@ -116,15 +117,15 @@ public Object callingTheAPI(String URL, String token, boolean requireCommitHeade try { httpResponse.close(); } catch (IOException e) { - e.printStackTrace(); - } + logger.error("IOException occurred when closing the HttpResponse"); + throw new CodeQualityMatricesException("IOException occurred when closing the HttpResponse", e); } } if (httpclient != null) { try { httpclient.close(); } catch (IOException e) { - e.printStackTrace(); - } + logger.error("IOException occurred when closing the HttpClient"); + throw new CodeQualityMatricesException("IOException occurred when closing the HttpClient", e); } } } return returnedObject; From bc8c7b8f5bed7337625be61e2ebbe4efd7e7486d Mon Sep 17 00:00:00 2001 From: kasun Date: Mon, 20 Mar 2017 10:35:12 +0530 Subject: [PATCH 21/62] Changed method names to have a good English flow --- .../{BlameCommit.java => ChangeFinder.java} | 40 +++++------ .../quality/matrices/GraphQlApiCaller.java | 2 +- .../wso2/code/quality/matrices/MainClass.java | 14 ++-- .../com/wso2/code/quality/matrices/Pmt.java | 69 ++++++++++++++----- .../code/quality/matrices/RestApiCaller.java | 8 +-- .../{Reviewers.java => Reviewer.java} | 24 +++---- ...thentication.java => SdkGitHubClient.java} | 8 +-- 7 files changed, 99 insertions(+), 66 deletions(-) rename CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/{BlameCommit.java => ChangeFinder.java} (91%) rename CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/{Reviewers.java => Reviewer.java} (89%) rename CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/{GitHubAuthentication.java => SdkGitHubClient.java} (92%) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java similarity index 91% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java rename to CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java index dbffb83..0830dbe 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/BlameCommit.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java @@ -23,7 +23,6 @@ import org.json.JSONArray; import org.json.JSONObject; -import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -35,10 +34,11 @@ import java.util.stream.IntStream; /** - * This class is used for getting the blame information on relevant lines changeed from the given patch + * This class is used for getting the blame information on relevant lines changed from the given patch + * @since 1.0.0 */ -public class BlameCommit extends RestApiCaller { +public class ChangeFinder { private String urlForObtainingCommits, urlForGetingFilesChanged; protected ArrayList fileNames = new ArrayList(); @@ -47,11 +47,11 @@ public class BlameCommit extends RestApiCaller { JSONObject graphqlApiJsonObject = new JSONObject(); Set commitHashesOfTheParent; Set authorNames = new HashSet(); //as the authors are for all the commits that exists in the relevant patch - protected Set commitHashObtainedForPRReview = new HashSet(); // relevant commits in old file that need to find the PR Reviewers + protected Set commitHashObtainedForPRReview = new HashSet(); // relevant commits in old file that need to find the PR Reviewer private String repoLocation[]; GraphQlApiCaller graphQlApiCaller = new GraphQlApiCaller(); - private static final Logger logger = Logger.getLogger(BlameCommit.class); + private static final Logger logger = Logger.getLogger(ChangeFinder.class); public String getUrlForSearchingCommits() { return urlForObtainingCommits; @@ -69,14 +69,14 @@ public void setUrlForSearchingCommits(String commitHash) { * @param restApiCaller Instance of the RestApiCaller class for accessing the REST APIs * @return a Set containing the commit hashes that needs to be checked for reviewers */ - public Set obtainingRepoNamesForCommitHashes(String gitHubToken, String[] commitsInTheGivenPatch, RestApiCaller restApiCaller) { + public Set obtainRepoNamesForCommitHashes(String gitHubToken, String[] commitsInTheGivenPatch, RestApiCaller restApiCaller) { //calling the API calling method IntStream.range(0, commitsInTheGivenPatch.length).mapToObj(i -> commitsInTheGivenPatch[i]).forEach(commitHash -> { setUrlForSearchingCommits(commitHash); JSONObject jsonObject = null; try { - jsonObject = (JSONObject) restApiCaller.callingTheAPI(getUrlForSearchingCommits(), gitHubToken, true, false); + jsonObject = (JSONObject) restApiCaller.callApi(getUrlForSearchingCommits(), gitHubToken, true, false); } catch (Exception e) { System.out.println(e.getMessage() + "cause" + e.getCause()); } @@ -109,7 +109,7 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, }); logger.info("Repo names having the given commit are successfully saved in an array"); - GitHubAuthentication gitHubAuthentication = new GitHubAuthentication(gitHubToken); + SdkGitHubClient sdkGitHubClient = new SdkGitHubClient(gitHubToken); // for running through the repoName Array IntStream.range(0, repoLocation.length).filter(i -> StringUtils.contains(repoLocation[i], "wso2/")).forEach(i -> { @@ -120,15 +120,15 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, patchString.clear(); Map> mapWithFileNamesAndPatch = null; try { - mapWithFileNamesAndPatch = gitHubAuthentication.gettingFilesChanged(repoLocation[i], commitHash); + mapWithFileNamesAndPatch = sdkGitHubClient.getFilesChanged(repoLocation[i], commitHash); } catch (Exception e) { System.out.println(e.getMessage() + "cause" + e.getCause()); } fileNames = mapWithFileNamesAndPatch.get("fileNames"); patchString = mapWithFileNamesAndPatch.get("patchString"); - savingRelaventEditLineNumbers(fileNames, patchString); + saveRelaventEditLineNumbers(fileNames, patchString); try { - iteratingOver(repoLocation[i], commitHash, gitHubToken); + iterateOverFileChanges(repoLocation[i], commitHash, gitHubToken); } catch (Exception e) { System.out.println(e.getMessage() + "cause" + e.getCause()); } @@ -147,7 +147,7 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, * @param patchString Array list having the patch string value for each of the file being changed */ - public void savingRelaventEditLineNumbers(ArrayList fileNames, ArrayList patchString) { + public void saveRelaventEditLineNumbers(ArrayList fileNames, ArrayList patchString) { //filtering only the line ranges that are modified and saving to a string array // cannot ues parallel streams here as the order of the line changes must be preserved @@ -191,7 +191,7 @@ public void savingRelaventEditLineNumbers(ArrayList fileNames, ArrayList * @param commitHash current selected repository * @param gitHubToken github token for accessing github GraphQL API */ - public void iteratingOver(String repoLocation, String commitHash, String gitHubToken) { + public void iterateOverFileChanges(String repoLocation, String commitHash, String gitHubToken) { // filtering the owner and the repository name from the repoLocation String owner = StringUtils.substringBefore(repoLocation, "/"); @@ -207,15 +207,15 @@ public void iteratingOver(String repoLocation, String commitHash, String gitHubT JSONObject rootJsonObject = null; try { // calling the graphql API for getting blame information for the current file and saving it in a location. - rootJsonObject = (JSONObject) graphQlApiCaller.callingGraphQl(graphqlApiJsonObject, gitHubToken); + rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); } catch (CodeQualityMatricesException e) { System.out.println(e.getMessage() + "cause" + e.getCause()); } // reading the above saved output for the current selected file name - readingTheBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, false); + readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, false); // parent commit hashes are stored in the arraylist for the given file - iteratingOverForFindingAuthors(owner, repositoryName, fileName, arrayListOfRelevantChangedLines, gitHubToken); + iterateOverToFindAuthors(owner, repositoryName, fileName, arrayListOfRelevantChangedLines, gitHubToken); logger.info("Authors of the bug lines of code which are being fixed from the given patch are saved successfully to authorNames SET"); }); } @@ -228,7 +228,7 @@ public void iteratingOver(String repoLocation, String commitHash, String gitHubT * @param arrayListOfRelevantChangedLines arraylist containing the changed line ranges of the current selected file * @param gettingPr should be true if running this method for finding the authors of buggy lines which are being fixed from the patch */ - public void readingTheBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList arrayListOfRelevantChangedLines, boolean gettingPr) { + public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList arrayListOfRelevantChangedLines, boolean gettingPr) { //running a iterator for fileName arrayList to get the location of the above saved file JSONObject dataJSONObject = (JSONObject) rootJsonObject.get("data"); @@ -339,7 +339,7 @@ public void readingTheBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList * @param arrayListOfRelevantChangedLines arraylist containing the changed line ranges of the current selected file * @param gitHubToken github token for accessing github GraphQL API */ - public void iteratingOverForFindingAuthors(String owner, String repositoryName, String fileName, ArrayList arrayListOfRelevantChangedLines, String gitHubToken) { + public void iterateOverToFindAuthors(String owner, String repositoryName, String fileName, ArrayList arrayListOfRelevantChangedLines, String gitHubToken) { // calling the graphql api to get the blame details of the current file for the parent commits (That is found by filtering in the graqhQL output) //as the order is not important in here parallel streams are used @@ -347,8 +347,8 @@ public void iteratingOverForFindingAuthors(String owner, String repositoryName, graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + parentCommitHashForCallingGraphQl + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{ url author { name email } } } } } } } }"); JSONObject rootJsonObject = null; try { - rootJsonObject = (JSONObject) graphQlApiCaller.callingGraphQl(graphqlApiJsonObject, gitHubToken); - readingTheBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, true); + rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); + readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, true); } catch (CodeQualityMatricesException e) { System.out.println(e.getMessage() + "cause" + e.getCause()); } }); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java index b4d006e..69137ac 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java @@ -52,7 +52,7 @@ public class GraphQlApiCaller { * @return Depending on the content return a JSONObject or a JSONArray * @throws IOException */ - public Object callingGraphQl(JSONObject queryObject, String gitHubToken) throws CodeQualityMatricesException { + public Object callGraphQlApi(JSONObject queryObject, String gitHubToken) throws CodeQualityMatricesException { CloseableHttpClient client = null; CloseableHttpResponse response = null; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index 888e54b..5ffd48a 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -42,31 +42,31 @@ public static void main(String[] args) { RestApiCaller restApiCaller = new RestApiCaller(); JSONArray jsonArray = null; try { - jsonArray = (JSONArray) restApiCaller.callingTheAPI(pmtUrl, pmtToken, false, false); + jsonArray = (JSONArray) restApiCaller.callApi(pmtUrl, pmtToken, false, false); } catch (Exception e) { + //Check these System.out.println(e.getMessage() + "cause" + e.getCause()); - } logger.info("JSON response is received successfully from WSO2 PMT for the given patch " + args[1]); Pmt pmt = new Pmt(); String[] commitsInTheGivenPatch = null; if (jsonArray != null) { - commitsInTheGivenPatch = pmt.getThePublicGitCommitId(jsonArray); + commitsInTheGivenPatch = pmt.getPublicGitCommitHashes(jsonArray); } logger.info("Commits received from WSO2 PMT are saved in an array successfully"); String gitHubToken = args[2]; - BlameCommit blameCommit = new BlameCommit(); + ChangeFinder changeFinder = new ChangeFinder(); Set commitHashObtainedForPRReview = null; if (commitsInTheGivenPatch != null) { - commitHashObtainedForPRReview = blameCommit.obtainingRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); + commitHashObtainedForPRReview = changeFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); } logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); - Reviewers reviewers = new Reviewers(); + Reviewer reviewer = new Reviewer(); if (commitHashObtainedForPRReview != null) { - reviewers.findingReviewers(commitHashObtainedForPRReview, gitHubToken); + reviewer.findReviewers(commitHashObtainedForPRReview, gitHubToken,restApiCaller); } } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java index fb58fcd..01550d5 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java @@ -22,10 +22,17 @@ import org.json.JSONArray; import org.json.JSONObject; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; import java.util.stream.IntStream; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; /** * This class is used for obtaining the commit hashes that belongs to the given patch + * + * @since 1.0.0 */ public class Pmt { @@ -33,34 +40,60 @@ public class Pmt { private final Logger logger = Logger.getLogger(Pmt.class.getName()); + private static final String COMMITS_IN_PATCH_IDENTIFIER = "patchInformation_svnRevisionpublic"; //key used to identify the commits in a patch from JSON response received from PMT + private static final String KEY_STRING = "name"; + private static final String VALUE_STRING = "value"; + /** * getting the commit IDs from the received json response * * @param jsonArray jsonarray containing the output received from WSO2 PMT for the given patch * @return a copy of the array containing the commit hashes that belongs to the given patch */ - public String[] getThePublicGitCommitId(JSONArray jsonArray) { - for (int i = 0; i < jsonArray.length(); i++) { - JSONObject jsonObject = (JSONObject) jsonArray.get(i); - String tempName = (String) jsonObject.get("name"); - if (tempName.equals("patchInformation_svnRevisionpublic")) { - JSONArray tempCommitsJSONArray = (JSONArray) jsonObject.get("value"); - //initializing the patchInformation_svnRevisionpublic array - patchInformation_svnRevisionpublic = new String[tempCommitsJSONArray.length()]; - // for ommiting the white spaces at the begingin and end of the commits - IntStream.range(0, tempCommitsJSONArray.length()).forEach(j -> patchInformation_svnRevisionpublic[j] = ((String) tempCommitsJSONArray.get(j)).trim()); + public String[] getPublicGitCommitHashes(JSONArray jsonArray) { - logger.info(" The commits hashes obtained from WSO2 PMT are successfully saved to an array"); + List listOfCommits = getCommitHashesToList(jsonArray); + logger.info(" The commits hashes obtained from WSO2 PMT are successfully saved to an Array list"); + patchInformation_svnRevisionpublic = listOfCommits.toArray(new String[listOfCommits.size()]); + logger.info(" The commits hashes obtained from WSO2 PMT are successfully saved to an array"); + System.out.println("The commit Ids are"); + // for printing all the commits ID associated with a patch + IntStream.range(0, patchInformation_svnRevisionpublic.length).mapToObj(i -> patchInformation_svnRevisionpublic[i]).forEach(System.out::println); + System.out.println(); - System.out.println("The commit Ids are"); - // for printing all the commits ID associated with a patch - IntStream.range(0, patchInformation_svnRevisionpublic.length).mapToObj(i1 -> patchInformation_svnRevisionpublic[i1]).forEach(System.out::println); - System.out.println(); - break; - } - } //to prevent from internaal representation by returning referecnce to mutable object String clonedPatchInformation_svnRevisionpublic[] = patchInformation_svnRevisionpublic.clone(); return clonedPatchInformation_svnRevisionpublic; } + + /** + * This method returns the commit hashes belongs to the given patch in as a list of Strings + * + * @param array jsonarray containing the output received from WSO2 PMT for the given patch + * @return a List containing the commit hashes that belongs to the given patch + */ + + public List getCommitHashesToList(JSONArray array) { + return arrayToStream(array) + .map(JSONObject.class::cast) + .filter(o -> o.get(KEY_STRING).equals(COMMITS_IN_PATCH_IDENTIFIER)) + .findFirst() + .map(o -> (JSONArray) o.get(VALUE_STRING)) + .map(Pmt::arrayToStream) + .map(commits -> + commits.map(Object::toString) + .map(String::trim) + .collect(Collectors.toList()) + ) + .orElseGet(Collections::emptyList); + } + + /** + * @param array JSON array that a sequential stream should be obtained from + * @return a sequential stream created from the supplied JSON Array + */ + private static Stream arrayToStream(JSONArray array) { + return StreamSupport.stream(array.spliterator(), false); + } + } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java index 979abb6..7701932 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java @@ -44,12 +44,12 @@ public class RestApiCaller { * calling the relevant API and saving the output to a file * * @param URL url of the REST API to be called - * @param token either the WSO2 PMT access token or giihub.com access token + * @param accessToken either the WSO2 PMT access accessToken or giihub.com access accessToken * @param requireCommitHeader should be true for accessing the github commit search API and false otherwise * @param requireReviewHeader should be true for accessing the github review API or false otherwise */ - public Object callingTheAPI(String URL, String token, boolean requireCommitHeader, boolean requireReviewHeader) throws CodeQualityMatricesException { + public Object callApi(String URL, String accessToken, boolean requireCommitHeader, boolean requireReviewHeader) throws CodeQualityMatricesException { BufferedReader bufferedReader = null; CloseableHttpClient httpclient = null; @@ -60,9 +60,9 @@ public Object callingTheAPI(String URL, String token, boolean requireCommitHeade httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet(URL); - if (token != null) { + if (accessToken != null) { - httpGet.addHeader("Authorization", "Bearer " + token); // passing the token for the API call + httpGet.addHeader("Authorization", "Bearer " + accessToken); // passing the accessToken for the API call } //as the accept header is needed for the review API since it is still in preview mode diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java similarity index 89% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java rename to CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java index b143bb3..5dec1e5 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewers.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java @@ -33,14 +33,14 @@ * This class is used to find the revierwers of the buggy lines of code */ -public class Reviewers extends BlameCommit { +public class Reviewer { String searchPullReqeustAPIUrl; String pullRequestReviewAPIUrl; Set approvedReviewers = new HashSet(); // to store the reviewed and approved users of the pull requests Set commentedReviewers = new HashSet(); // to store the reviewed and commented users of the pull requests - private static final Logger logger = Logger.getLogger(Reviewers.class); + private static final Logger logger = Logger.getLogger(Reviewer.class); public String getSearchPullReqeustAPI() { return searchPullReqeustAPIUrl; @@ -73,7 +73,7 @@ public void setPullRequestReviewAPIUrl(String repoLocation, int pullRequestNumbe * @param commitHashObtainedForPRReview commit hash Set for finding the pull requests * @param githubToken github token for accessing github REST API */ - public void findingReviewers(Set commitHashObtainedForPRReview, String githubToken) { + public void findReviewers(Set commitHashObtainedForPRReview, String githubToken, RestApiCaller restApiCaller) { Iterator commitHashObtainedForPRReviewIterator = commitHashObtainedForPRReview.iterator(); while (commitHashObtainedForPRReviewIterator.hasNext()) { String commitHashForFindingReviewers = (String) commitHashObtainedForPRReviewIterator.next(); @@ -81,17 +81,17 @@ public void findingReviewers(Set commitHashObtainedForPRReview, String g // calling the github search API JSONObject rootJsonObject = null; try { - rootJsonObject = (JSONObject) callingTheAPI(getSearchPullReqeustAPI(), githubToken, false, true); + rootJsonObject = (JSONObject) restApiCaller.callApi(getSearchPullReqeustAPI(), githubToken, false, true); } catch (Exception e) { - System.out.println(e.getMessage() + "cause" + e.getCause()); + System.out.println(e.getMessage() + " cause " + e.getCause()); } // reading thus saved json file if (rootJsonObject != null) { - savingPrNumberAndRepoName(rootJsonObject); + savePrNumberAndRepoName(rootJsonObject); } } logger.info("PR numbers which introduce bug lines of code with their relevant repository are saved successfully to mapContainingPRNoAgainstRepoName map"); - savingReviewersToList(githubToken); + saveReviewersToList(githubToken,restApiCaller); logger.info("List of approved reviwers and comment users of the PRs which introduce bug lines to repository are saved in commentedReviewers and approvedReviewers list "); // printing the list of reviewers of pull requests printReviewUsers(); @@ -103,7 +103,7 @@ public void findingReviewers(Set commitHashObtainedForPRReview, String g * * @param rootJsonObject JSONObject received from github search API */ - public void savingPrNumberAndRepoName(JSONObject rootJsonObject) { + public void savePrNumberAndRepoName(JSONObject rootJsonObject) { JSONArray itemsJsonArray = (JSONArray) rootJsonObject.get("items"); for (int i = 0; i < itemsJsonArray.length(); i++) { @@ -127,7 +127,7 @@ public void savingPrNumberAndRepoName(JSONObject rootJsonObject) { * * @param githubToken github token for accessing github REST API */ - public void savingReviewersToList(String githubToken) { + public void saveReviewersToList(String githubToken, RestApiCaller restApiCaller) { for (Map.Entry m : mapContainingPRNoAgainstRepoName.entrySet()) { String productLocation = (String) m.getKey(); @@ -139,13 +139,13 @@ public void savingReviewersToList(String githubToken) { setPullRequestReviewAPIUrl(productLocation, prNumber); JSONArray rootJsonArray = null; try { - rootJsonArray = (JSONArray) callingTheAPI(getPullRequestReviewAPIUrl(), githubToken, false, true); + rootJsonArray = (JSONArray) restApiCaller.callApi(getPullRequestReviewAPIUrl(), githubToken, false, true); } catch (Exception e) { System.out.println(e.getMessage() + "cause" + e.getCause()); } // for reading the output JSON from above and adding the reviewers to the Set if (rootJsonArray != null) { - readingTheReviewOutJSON(rootJsonArray, productLocation, prNumber); + readTheReviewOutJSON(rootJsonArray, productLocation, prNumber); } } } @@ -158,7 +158,7 @@ public void savingReviewersToList(String githubToken) { * @param productLocation Product Location for printing the error message when there are no reviewers and a commented users * @param prNumber relevant PR number for finding the reviewers and commenters */ - public void readingTheReviewOutJSON(JSONArray reviewJsonArray, String productLocation, int prNumber) { + public void readTheReviewOutJSON(JSONArray reviewJsonArray, String productLocation, int prNumber) { if (reviewJsonArray.length() != 0) { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java similarity index 92% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java rename to CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java index 661763c..7bbdfc8 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GitHubAuthentication.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java @@ -38,16 +38,16 @@ * @since 1.0.0 */ -public class GitHubAuthentication { +public class SdkGitHubClient { protected GitHubClient gitHubClient = null; protected CommitService commitService = null; protected RepositoryService repositoryService = null; protected ArrayList fileNames = new ArrayList(); protected ArrayList patchString = new ArrayList(); - private static final Logger logger = Logger.getLogger(GitHubAuthentication.class); + private static final Logger logger = Logger.getLogger(SdkGitHubClient.class); - GitHubAuthentication(String githubToken) { + SdkGitHubClient(String githubToken) { gitHubClient = new GitHubClient(); gitHubClient.setOAuth2Token(githubToken); commitService = new CommitService(gitHubClient); @@ -62,7 +62,7 @@ public class GitHubAuthentication { * @param commitHash The querying commit hash * @return a map containg arraylist of file changed and their relevant patch */ - public Map> gettingFilesChanged(String repositoryName, String commitHash) throws CodeQualityMatricesException { + public Map> getFilesChanged(String repositoryName, String commitHash) throws CodeQualityMatricesException { Map> mapWithFileNamesAndPatches = new HashMap<>(); try { IRepositoryIdProvider iRepositoryIdProvider = () -> repositoryName; From 03c8563f815b3ac9eed18d40e60ec65ea21a65cc Mon Sep 17 00:00:00 2001 From: kasun Date: Mon, 20 Mar 2017 13:30:04 +0530 Subject: [PATCH 22/62] change the part where it skips taking blme of new files --- .../code/quality/matrices/ChangeFinder.java | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java index 0830dbe..feee71b 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java @@ -122,6 +122,8 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, try { mapWithFileNamesAndPatch = sdkGitHubClient.getFilesChanged(repoLocation[i], commitHash); } catch (Exception e) { + + // here System.out.println(e.getMessage() + "cause" + e.getCause()); } fileNames = mapWithFileNamesAndPatch.get("fileNames"); @@ -209,6 +211,7 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin // calling the graphql API for getting blame information for the current file and saving it in a location. rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); } catch (CodeQualityMatricesException e) { + //check here System.out.println(e.getMessage() + "cause" + e.getCause()); } // reading the above saved output for the current selected file name readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, false); @@ -244,12 +247,8 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList= startingLineNo) { //running through the rangeJSONArray +// IntStream.range(0,rangeJSONArray.length()).forEach(j->{ +// JSONObject rangeJSONObject = (JSONObject) rangeJSONArray.get(j); +// int tempStartingLineNo = (int) rangeJSONObject.get("startingLine"); +// int tempEndingLineNo = (int) rangeJSONObject.get("endingLine"); +// +// //checking whether the line belongs to that line range group +// if ((tempStartingLineNo <= startingLineNo) && (tempEndingLineNo >= startingLineNo)) { +// // so the relevant startingLineNo belongs in this line range in other words in this JSONObject +// if (!gettingPr) { +// int age = (int) rangeJSONObject.get("age"); +// // storing the age field with relevant index of the JSONObject +// mapForStoringAgeAndIndex.putIfAbsent(age, new ArrayList()); +// if (!mapForStoringAgeAndIndex.get(age).contains(j)) { +// mapForStoringAgeAndIndex.get(age).add(j); // adding if the index is not present in the array list for the relevant age +// } +// +// }); + for (int i = 0; i < rangeJSONArray.length(); i++) { JSONObject rangeJSONObject = (JSONObject) rangeJSONArray.get(i); int tempStartingLineNo = (int) rangeJSONObject.get("startingLine"); @@ -326,7 +343,9 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList Date: Mon, 20 Mar 2017 13:52:39 +0530 Subject: [PATCH 23/62] replaced code with java 8 features added streams for saveReviewersToList method added streams for savePrNumberAndRepoName method replaced for loop with for each loop in readTheReviewOutJSON method --- .../code/quality/matrices/ChangeFinder.java | 22 +-- .../com/wso2/code/quality/matrices/Pmt.java | 2 +- .../wso2/code/quality/matrices/Reviewer.java | 148 +++++++++++++----- 3 files changed, 111 insertions(+), 61 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java index feee71b..6ceda93 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java @@ -265,25 +265,7 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList= startingLineNo) { - //running through the rangeJSONArray -// IntStream.range(0,rangeJSONArray.length()).forEach(j->{ -// JSONObject rangeJSONObject = (JSONObject) rangeJSONArray.get(j); -// int tempStartingLineNo = (int) rangeJSONObject.get("startingLine"); -// int tempEndingLineNo = (int) rangeJSONObject.get("endingLine"); -// -// //checking whether the line belongs to that line range group -// if ((tempStartingLineNo <= startingLineNo) && (tempEndingLineNo >= startingLineNo)) { -// // so the relevant startingLineNo belongs in this line range in other words in this JSONObject -// if (!gettingPr) { -// int age = (int) rangeJSONObject.get("age"); -// // storing the age field with relevant index of the JSONObject -// mapForStoringAgeAndIndex.putIfAbsent(age, new ArrayList()); -// if (!mapForStoringAgeAndIndex.get(age).contains(j)) { -// mapForStoringAgeAndIndex.get(age).add(j); // adding if the index is not present in the array list for the relevant age -// } -// -// }); - + // since the index value is required for later processing for loop is used for iteration for (int i = 0; i < rangeJSONArray.length(); i++) { JSONObject rangeJSONObject = (JSONObject) rangeJSONArray.get(i); int tempStartingLineNo = (int) rangeJSONObject.get("startingLine"); @@ -325,7 +307,7 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList> treeMap = new TreeMap<>(mapForStoringAgeAndIndex); int minimumKeyOfMapForStoringAgeAndIndex = treeMap.firstKey(); // getting the minimum key - // getting the relevant JSONObject indexes which consists of the recent commit with in the relevant line range + //getting the relevant JSONObject indexes which consists of the recent commit with in the relevant line range ArrayList indexesOfJsonObjectForRecentCommit = mapForStoringAgeAndIndex.get(minimumKeyOfMapForStoringAgeAndIndex); // the order of the indexesOfJsonObjectForRecentCommit is not important as we only need to get the parent commit hashes indexesOfJsonObjectForRecentCommit.parallelStream().forEach(index -> { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java index 01550d5..ba9483e 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java @@ -92,7 +92,7 @@ public List getCommitHashesToList(JSONArray array) { * @param array JSON array that a sequential stream should be obtained from * @return a sequential stream created from the supplied JSON Array */ - private static Stream arrayToStream(JSONArray array) { + public static Stream arrayToStream(JSONArray array) { return StreamSupport.stream(array.spliterator(), false); } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java index 5dec1e5..a07db37 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java @@ -25,7 +25,6 @@ import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -74,9 +73,8 @@ public void setPullRequestReviewAPIUrl(String repoLocation, int pullRequestNumbe * @param githubToken github token for accessing github REST API */ public void findReviewers(Set commitHashObtainedForPRReview, String githubToken, RestApiCaller restApiCaller) { - Iterator commitHashObtainedForPRReviewIterator = commitHashObtainedForPRReview.iterator(); - while (commitHashObtainedForPRReviewIterator.hasNext()) { - String commitHashForFindingReviewers = (String) commitHashObtainedForPRReviewIterator.next(); + + commitHashObtainedForPRReview.stream().forEach(commitHashForFindingReviewers -> { setSearchPullReqeustAPI(commitHashForFindingReviewers); // calling the github search API JSONObject rootJsonObject = null; @@ -89,9 +87,26 @@ public void findReviewers(Set commitHashObtainedForPRReview, String gith if (rootJsonObject != null) { savePrNumberAndRepoName(rootJsonObject); } - } + }); + +// Iterator commitHashObtainedForPRReviewIterator = commitHashObtainedForPRReview.iterator(); +// while (commitHashObtainedForPRReviewIterator.hasNext()) { +// String commitHashForFindingReviewers = (String) commitHashObtainedForPRReviewIterator.next(); +// setSearchPullReqeustAPI(commitHashForFindingReviewers); +// // calling the github search API +// JSONObject rootJsonObject = null; +// try { +// rootJsonObject = (JSONObject) restApiCaller.callApi(getSearchPullReqeustAPI(), githubToken, false, true); +// } catch (Exception e) { +// System.out.println(e.getMessage() + " cause " + e.getCause()); +// } +// // reading thus saved json file +// if (rootJsonObject != null) { +// savePrNumberAndRepoName(rootJsonObject); +// } +// } logger.info("PR numbers which introduce bug lines of code with their relevant repository are saved successfully to mapContainingPRNoAgainstRepoName map"); - saveReviewersToList(githubToken,restApiCaller); + saveReviewersToList(githubToken, restApiCaller); logger.info("List of approved reviwers and comment users of the PRs which introduce bug lines to repository are saved in commentedReviewers and approvedReviewers list "); // printing the list of reviewers of pull requests printReviewUsers(); @@ -106,20 +121,31 @@ public void findReviewers(Set commitHashObtainedForPRReview, String gith public void savePrNumberAndRepoName(JSONObject rootJsonObject) { JSONArray itemsJsonArray = (JSONArray) rootJsonObject.get("items"); - for (int i = 0; i < itemsJsonArray.length(); i++) { - JSONObject prJsonObject = (JSONObject) itemsJsonArray.get(i); - // filtering only the closed repositories - if (((String) prJsonObject.get("state")).equals("closed")) { - String repositoryUrl = (String) prJsonObject.get("repository_url"); - String repositoryLocation = StringUtils.substringAfter(repositoryUrl, "https://api.github.com/repos/"); - if (repositoryLocation.contains("wso2/")) { - // to filter out only the repositories belongs to wso2 - int pullRequetNumber = (int) prJsonObject.get("number"); - mapContainingPRNoAgainstRepoName.putIfAbsent(repositoryLocation, new HashSet()); // put the repo name key only if it does not exists in the map - mapContainingPRNoAgainstRepoName.get(repositoryLocation).add(pullRequetNumber); // since SET is there we do not need to check for availability of the key in the map - } + Pmt.arrayToStream(itemsJsonArray).map(JSONObject.class::cast).filter(o -> o.get("state").equals("closed")).forEach(prJsonObject -> { + String repositoryUrl = (String) prJsonObject.get("repository_url"); + String repositoryLocation = StringUtils.substringAfter(repositoryUrl, "https://api.github.com/repos/"); + if (repositoryLocation.contains("wso2/")) { + // to filter out only the repositories belongs to wso2 + int pullRequetNumber = (int) prJsonObject.get("number"); + mapContainingPRNoAgainstRepoName.putIfAbsent(repositoryLocation, new HashSet()); // put the repo name key only if it does not exists in the map + mapContainingPRNoAgainstRepoName.get(repositoryLocation).add(pullRequetNumber); // since SET is there we do not need to check for availability of the key in the map } - } + }); + +// for (int i = 0; i < itemsJsonArray.length(); i++) { +// JSONObject prJsonObject = (JSONObject) itemsJsonArray.get(i); +// // filtering only the closed repositories +// if (((String) prJsonObject.get("state")).equals("closed")) { +// String repositoryUrl = (String) prJsonObject.get("repository_url"); +// String repositoryLocation = StringUtils.substringAfter(repositoryUrl, "https://api.github.com/repos/"); +// if (repositoryLocation.contains("wso2/")) { +// // to filter out only the repositories belongs to wso2 +// int pullRequetNumber = (int) prJsonObject.get("number"); +// mapContainingPRNoAgainstRepoName.putIfAbsent(repositoryLocation, new HashSet()); // put the repo name key only if it does not exists in the map +// mapContainingPRNoAgainstRepoName.get(repositoryLocation).add(pullRequetNumber); // since SET is there we do not need to check for availability of the key in the map +// } +// } +// } } /** @@ -133,26 +159,43 @@ public void saveReviewersToList(String githubToken, RestApiCaller restApiCaller) String productLocation = (String) m.getKey(); @SuppressWarnings("unchecked") Set prNumbers = (Set) m.getValue(); - Iterator prNumberIterator = prNumbers.iterator(); - while (prNumberIterator.hasNext()) { - int prNumber = (int) prNumberIterator.next(); + + prNumbers.stream().forEach(prNumber -> { setPullRequestReviewAPIUrl(productLocation, prNumber); - JSONArray rootJsonArray = null; + JSONArray reviewJsonArray = null; try { - rootJsonArray = (JSONArray) restApiCaller.callApi(getPullRequestReviewAPIUrl(), githubToken, false, true); + reviewJsonArray = (JSONArray) restApiCaller.callApi(getPullRequestReviewAPIUrl(), githubToken, false, true); } catch (Exception e) { System.out.println(e.getMessage() + "cause" + e.getCause()); } // for reading the output JSON from above and adding the reviewers to the Set - if (rootJsonArray != null) { - readTheReviewOutJSON(rootJsonArray, productLocation, prNumber); + if (reviewJsonArray != null) { + readTheReviewOutJSON(reviewJsonArray, productLocation, prNumber); } - } + + + }); + +// Iterator prNumberIterator = prNumbers.iterator(); +// while (prNumberIterator.hasNext()) { +// int prNumber = (int) prNumberIterator.next(); +// setPullRequestReviewAPIUrl(productLocation, prNumber); +// JSONArray rootJsonArray = null; +// try { +// rootJsonArray = (JSONArray) restApiCaller.callApi(getPullRequestReviewAPIUrl(), githubToken, false, true); +// } catch (Exception e) { +// System.out.println(e.getMessage() + "cause" + e.getCause()); +// } +// // for reading the output JSON from above and adding the reviewers to the Set +// if (rootJsonArray != null) { +// readTheReviewOutJSON(rootJsonArray, productLocation, prNumber); +// } +// } } } /** - * Reading the output received from the review API and saving the relevant reviewers and commented users to a Set + * Reading the output received from the review API and saving the relevant reviewers and commented users to relevant Sets * * @param reviewJsonArray JSON response from the github Review API * @param productLocation Product Location for printing the error message when there are no reviewers and a commented users @@ -161,26 +204,51 @@ public void saveReviewersToList(String githubToken, RestApiCaller restApiCaller) public void readTheReviewOutJSON(JSONArray reviewJsonArray, String productLocation, int prNumber) { if (reviewJsonArray.length() != 0) { + for (Object object : reviewJsonArray) { + if (object instanceof JSONObject) { + JSONObject reviewJsonObject = (JSONObject) object; - for (int i = 0; i < reviewJsonArray.length(); i++) { - JSONObject reviewJsonObject = (JSONObject) reviewJsonArray.get(i); - if ((reviewJsonObject.get("state")).equals("APPROVED")) { - - JSONObject userJsonObject = (JSONObject) reviewJsonObject.get("user"); - String approvedReviwer = (String) userJsonObject.get("login"); - approvedReviewers.add(approvedReviwer); // adding the approved user to the Set - - } else if ((reviewJsonObject.get("state")).equals("COMMENTED")) { - JSONObject userJsonObject = (JSONObject) reviewJsonObject.get("user"); - String commentedReviwer = (String) userJsonObject.get("login"); - commentedReviewers.add(commentedReviwer); // adding the commented user to the Set + addRelevantUsersToList(reviewJsonObject); } } +// for (int i = 0; i < reviewJsonArray.length(); i++) { +// JSONObject reviewJsonObject = (JSONObject) reviewJsonArray.get(i); +// if ((reviewJsonObject.get("state")).equals("APPROVED")) { +// +// JSONObject userJsonObject = (JSONObject) reviewJsonObject.get("user"); +// String approvedReviwer = (String) userJsonObject.get("login"); +// approvedReviewers.add(approvedReviwer); // adding the approved user to the Set +// +// } else if ((reviewJsonObject.get("state")).equals("COMMENTED")) { +// JSONObject userJsonObject = (JSONObject) reviewJsonObject.get("user"); +// String commentedReviwer = (String) userJsonObject.get("login"); +// commentedReviewers.add(commentedReviwer); // adding the commented user to the Set +// } +// } } else { System.out.println("There are no records of reviews for pull request: " + prNumber + " on " + productLocation + " repository"); } } + /** + * This method is used for saving the relevant reviewers and commented users to relevant Sets + * @param reviewJsonObject jsonObject received from readTheReviewOutJSON method + */ + + public void addRelevantUsersToList(JSONObject reviewJsonObject ){ + if ((reviewJsonObject.get("state")).equals("APPROVED")) { + + JSONObject userJsonObject = (JSONObject) reviewJsonObject.get("user"); + String approvedReviwer = (String) userJsonObject.get("login"); + approvedReviewers.add(approvedReviwer); // adding the approved user to the Set + + } else if ((reviewJsonObject.get("state")).equals("COMMENTED")) { + JSONObject userJsonObject = (JSONObject) reviewJsonObject.get("user"); + String commentedReviwer = (String) userJsonObject.get("login"); + commentedReviewers.add(commentedReviwer); // adding the commented user to the Set + } + } + /** * Print the list of reviewers and commented users on the pull requests which introduce bugs to the code base */ From 49c87dca6ba37666cbae7b48b4f85bac9f5205a5 Mon Sep 17 00:00:00 2001 From: kasun Date: Mon, 20 Mar 2017 15:27:49 +0530 Subject: [PATCH 24/62] Replaced variables with contants add constants for Reviewers.java --- .../code/quality/matrices/ChangeFinder.java | 64 +++++++++++++------ .../wso2/code/quality/matrices/Reviewer.java | 34 +++++++--- 2 files changed, 67 insertions(+), 31 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java index 6ceda93..92dc9d2 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java @@ -52,6 +52,28 @@ public class ChangeFinder { GraphQlApiCaller graphQlApiCaller = new GraphQlApiCaller(); private static final Logger logger = Logger.getLogger(ChangeFinder.class); + // constants for accessing the Github API responses + private static final String GITHUB_SEARCH_API_ITEMS_KEY_STRING="items"; + private static final String GITHUB_SEARCH_API_REPOSITORY_KEY_STRING="repository"; + private static final String GITHUB_SEARCH_API_FULL_NAME_OF_REPOSITORY_KEY_STRING="full_name"; + private static final String GITHUB_GRAPHQL_API_STARTING_LINE_KEY_STRING="startingLine"; + private static final String GITHUB_GRAPHQL_API_ENDING_LINE_KEY_STRING="endingLine"; + private static final String GITHUB_GRAPHQL_API_AGE_KEY_STRING="age"; + private static final String GITHUB_GRAPHQL_API_DATA_KEY_STRING="data"; + private static final String GITHUB_GRAPHQL_API_REPOSITORY_KEY_STRING="repository"; + private static final String GITHUB_GRAPHQL_API_OBJECT_KEY_STRING="object"; + private static final String GITHUB_GRAPHQL_API_BLAME_KEY_STRING="blame"; + private static final String GITHUB_GRAPHQL_API_RANGES_KEY_STRING="ranges"; + private static final String GITHUB_GRAPHQL_API_COMMIT_KEY_STRING="commit"; + private static final String GITHUB_GRAPHQL_API_AUTHOR_KEY_STRING="author"; + private static final String GITHUB_GRAPHQL_API_NAME_KEY_STRING="name"; + private static final String GITHUB_GRAPHQL_API_URL_KEY_STRING="url"; + private static final String GITHUB_GRAPHQL_API_HISTORY_KEY_STRING="history"; + private static final String GITHUB_GRAPHQL_API_EDGE_KEY_STRING="edges"; + private static final String GITHUB_GRAPHQL_API_NODE_KEY_STRING="node"; + + + public String getUrlForSearchingCommits() { return urlForObtainingCommits; @@ -98,14 +120,14 @@ public Set obtainRepoNamesForCommitHashes(String gitHubToken, String[] commitsIn */ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, String gitHubToken) throws CodeQualityMatricesException { - JSONArray jsonArrayOfItems = (JSONArray) rootJsonObject.get("items"); + JSONArray jsonArrayOfItems = (JSONArray) rootJsonObject.get(GITHUB_SEARCH_API_ITEMS_KEY_STRING); // setting the size of the repoLocationArray repoLocation = new String[jsonArrayOfItems.length()]; //adding the repo name to the array IntStream.range(0, jsonArrayOfItems.length()).forEach(i -> { JSONObject jsonObject = (JSONObject) jsonArrayOfItems.get(i); - JSONObject repositoryJsonObject = (JSONObject) jsonObject.get("repository"); - repoLocation[i] = (String) repositoryJsonObject.get("full_name"); + JSONObject repositoryJsonObject = (JSONObject) jsonObject.get(GITHUB_SEARCH_API_REPOSITORY_KEY_STRING); + repoLocation[i] = (String) repositoryJsonObject.get(GITHUB_SEARCH_API_FULL_NAME_OF_REPOSITORY_KEY_STRING); }); logger.info("Repo names having the given commit are successfully saved in an array"); @@ -234,11 +256,11 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList arrayListOfRelevantChangedLines, boolean gettingPr) { //running a iterator for fileName arrayList to get the location of the above saved file - JSONObject dataJSONObject = (JSONObject) rootJsonObject.get("data"); - JSONObject repositoryJSONObect = (JSONObject) dataJSONObject.get("repository"); - JSONObject objectJSONObject = (JSONObject) repositoryJSONObect.get("object"); - JSONObject blameJSONObject = (JSONObject) objectJSONObject.get("blame"); - JSONArray rangeJSONArray = (JSONArray) blameJSONObject.get("ranges"); + JSONObject dataJSONObject = (JSONObject) rootJsonObject.get(GITHUB_GRAPHQL_API_DATA_KEY_STRING); + JSONObject repositoryJSONObect = (JSONObject) dataJSONObject.get(GITHUB_GRAPHQL_API_REPOSITORY_KEY_STRING); + JSONObject objectJSONObject = (JSONObject) repositoryJSONObect.get(GITHUB_GRAPHQL_API_OBJECT_KEY_STRING); + JSONObject blameJSONObject = (JSONObject) objectJSONObject.get(GITHUB_GRAPHQL_API_BLAME_KEY_STRING); + JSONArray rangeJSONArray = (JSONArray) blameJSONObject.get(GITHUB_GRAPHQL_API_RANGES_KEY_STRING); //getting the starting line no of the range of lines that are modified from the patch // parallel streams are not used in here as the order of the arraylist is important in the process @@ -265,17 +287,17 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList= startingLineNo) { - // since the index value is required for later processing for loop is used for iteration + // since the index value is required for later processing "for loop" is used for iteration for (int i = 0; i < rangeJSONArray.length(); i++) { JSONObject rangeJSONObject = (JSONObject) rangeJSONArray.get(i); - int tempStartingLineNo = (int) rangeJSONObject.get("startingLine"); - int tempEndingLineNo = (int) rangeJSONObject.get("endingLine"); + int tempStartingLineNo = (int) rangeJSONObject.get(GITHUB_GRAPHQL_API_STARTING_LINE_KEY_STRING); + int tempEndingLineNo = (int) rangeJSONObject.get(GITHUB_GRAPHQL_API_ENDING_LINE_KEY_STRING); //checking whether the line belongs to that line range group if ((tempStartingLineNo <= startingLineNo) && (tempEndingLineNo >= startingLineNo)) { // so the relevant startingLineNo belongs in this line range in other words in this JSONObject if (!gettingPr) { - int age = (int) rangeJSONObject.get("age"); + int age = (int) rangeJSONObject.get(GITHUB_GRAPHQL_API_AGE_KEY_STRING); // storing the age field with relevant index of the JSONObject mapForStoringAgeAndIndex.putIfAbsent(age, new ArrayList()); if (!mapForStoringAgeAndIndex.get(age).contains(i)) { @@ -284,13 +306,13 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList { JSONObject rangeJSONObject = (JSONObject) rangeJSONArray.get(index); - JSONObject commitJSONObject = (JSONObject) rangeJSONObject.get("commit"); - JSONObject historyJSONObject = (JSONObject) commitJSONObject.get("history"); - JSONArray edgesJSONArray = (JSONArray) historyJSONObject.get("edges"); + JSONObject commitJSONObject = (JSONObject) rangeJSONObject.get(GITHUB_GRAPHQL_API_COMMIT_KEY_STRING); + JSONObject historyJSONObject = (JSONObject) commitJSONObject.get(GITHUB_GRAPHQL_API_HISTORY_KEY_STRING); + JSONArray edgesJSONArray = (JSONArray) historyJSONObject.get(GITHUB_GRAPHQL_API_EDGE_KEY_STRING); //getting the second json object from the array as it contain the commit of the parent which modified the above line range JSONObject edgeJSONObject = (JSONObject) edgesJSONArray.get(1); - JSONObject nodeJSONObject = (JSONObject) edgeJSONObject.get("node"); - String urlOfTheParentCommit = (String) nodeJSONObject.get("url"); // this contain the URL of the parent commit + JSONObject nodeJSONObject = (JSONObject) edgeJSONObject.get(GITHUB_GRAPHQL_API_NODE_KEY_STRING); + String urlOfTheParentCommit = (String) nodeJSONObject.get(GITHUB_GRAPHQL_API_URL_KEY_STRING); // this contain the URL of the parent commit String commitHash = (String) StringUtils.substringAfter(urlOfTheParentCommit, "commit/"); commitHashesOfTheParent.add(commitHash); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java index a07db37..7f1b6f5 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java @@ -41,6 +41,20 @@ public class Reviewer { private static final Logger logger = Logger.getLogger(Reviewer.class); + //constants for accessing github API + private static final String GITHUB_REVIEW_API_STATE_KEY="state"; + private static final String GITHUB_REVIEW_API_APPROVED_KEY="APPROVED"; + private static final String GITHUB_REVIEW_API_COMMENTED_KEY="COMMENTED"; + private static final String GITHUB_REVIEW_API_LOGIN_KEY="login"; + private static final String GITHUB_REVIEW_API_USER_KEY="user"; + private static final String GITHUB_REVIEW_API_ITEMS_KEY="items"; + private static final String GITHUB_REVIEW_API_REPOSITORY_URL_KEY="repository_url"; + private static final String GITHUB_REVIEW_API_NUMBER_KEY="number"; + private static final String GITHUB_REVIEW_API_CLOSED_STATE_KEY ="closed"; + + + + public String getSearchPullReqeustAPI() { return searchPullReqeustAPIUrl; } @@ -119,14 +133,14 @@ public void findReviewers(Set commitHashObtainedForPRReview, String gith * @param rootJsonObject JSONObject received from github search API */ public void savePrNumberAndRepoName(JSONObject rootJsonObject) { - JSONArray itemsJsonArray = (JSONArray) rootJsonObject.get("items"); + JSONArray itemsJsonArray = (JSONArray) rootJsonObject.get(GITHUB_REVIEW_API_ITEMS_KEY); - Pmt.arrayToStream(itemsJsonArray).map(JSONObject.class::cast).filter(o -> o.get("state").equals("closed")).forEach(prJsonObject -> { - String repositoryUrl = (String) prJsonObject.get("repository_url"); + Pmt.arrayToStream(itemsJsonArray).map(JSONObject.class::cast).filter(o -> o.get(GITHUB_REVIEW_API_STATE_KEY).equals(GITHUB_REVIEW_API_CLOSED_STATE_KEY)).forEach(prJsonObject -> { + String repositoryUrl = (String) prJsonObject.get(GITHUB_REVIEW_API_REPOSITORY_URL_KEY); String repositoryLocation = StringUtils.substringAfter(repositoryUrl, "https://api.github.com/repos/"); if (repositoryLocation.contains("wso2/")) { // to filter out only the repositories belongs to wso2 - int pullRequetNumber = (int) prJsonObject.get("number"); + int pullRequetNumber = (int) prJsonObject.get(GITHUB_REVIEW_API_NUMBER_KEY); mapContainingPRNoAgainstRepoName.putIfAbsent(repositoryLocation, new HashSet()); // put the repo name key only if it does not exists in the map mapContainingPRNoAgainstRepoName.get(repositoryLocation).add(pullRequetNumber); // since SET is there we do not need to check for availability of the key in the map } @@ -236,15 +250,15 @@ public void readTheReviewOutJSON(JSONArray reviewJsonArray, String productLocati */ public void addRelevantUsersToList(JSONObject reviewJsonObject ){ - if ((reviewJsonObject.get("state")).equals("APPROVED")) { + if ((reviewJsonObject.get(GITHUB_REVIEW_API_STATE_KEY)).equals(GITHUB_REVIEW_API_APPROVED_KEY)) { - JSONObject userJsonObject = (JSONObject) reviewJsonObject.get("user"); - String approvedReviwer = (String) userJsonObject.get("login"); + JSONObject userJsonObject = (JSONObject) reviewJsonObject.get(GITHUB_REVIEW_API_USER_KEY); + String approvedReviwer = (String) userJsonObject.get(GITHUB_REVIEW_API_LOGIN_KEY); approvedReviewers.add(approvedReviwer); // adding the approved user to the Set - } else if ((reviewJsonObject.get("state")).equals("COMMENTED")) { - JSONObject userJsonObject = (JSONObject) reviewJsonObject.get("user"); - String commentedReviwer = (String) userJsonObject.get("login"); + } else if ((reviewJsonObject.get(GITHUB_REVIEW_API_STATE_KEY)).equals(GITHUB_REVIEW_API_COMMENTED_KEY)) { + JSONObject userJsonObject = (JSONObject) reviewJsonObject.get(GITHUB_REVIEW_API_USER_KEY); + String commentedReviwer = (String) userJsonObject.get(GITHUB_REVIEW_API_LOGIN_KEY); commentedReviewers.add(commentedReviwer); // adding the commented user to the Set } } From 5fdedc44309a8c512794ac2fe971393e68f84bed Mon Sep 17 00:00:00 2001 From: kasun Date: Mon, 20 Mar 2017 21:53:15 +0530 Subject: [PATCH 25/62] Correct Exceptional Handling --- .../{ChangeFinder.java => ChangesFinder.java} | 75 +++++++++---------- .../quality/matrices/GraphQlApiCaller.java | 20 ++--- .../wso2/code/quality/matrices/MainClass.java | 12 +-- .../com/wso2/code/quality/matrices/Pmt.java | 1 + .../code/quality/matrices/RestApiCaller.java | 6 +- .../wso2/code/quality/matrices/Reviewer.java | 12 +-- .../quality/matrices/SdkGitHubClient.java | 1 - .../src/main/resources/log4j.properties | 6 ++ 8 files changed, 68 insertions(+), 65 deletions(-) rename CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/{ChangeFinder.java => ChangesFinder.java} (94%) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java similarity index 94% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java rename to CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index 92dc9d2..8a2f4d0 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangeFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -35,10 +35,11 @@ /** * This class is used for getting the blame information on relevant lines changed from the given patch + * * @since 1.0.0 */ -public class ChangeFinder { +public class ChangesFinder { private String urlForObtainingCommits, urlForGetingFilesChanged; protected ArrayList fileNames = new ArrayList(); @@ -51,28 +52,26 @@ public class ChangeFinder { private String repoLocation[]; GraphQlApiCaller graphQlApiCaller = new GraphQlApiCaller(); - private static final Logger logger = Logger.getLogger(ChangeFinder.class); + private static final Logger logger = Logger.getLogger(ChangesFinder.class); // constants for accessing the Github API responses - private static final String GITHUB_SEARCH_API_ITEMS_KEY_STRING="items"; - private static final String GITHUB_SEARCH_API_REPOSITORY_KEY_STRING="repository"; - private static final String GITHUB_SEARCH_API_FULL_NAME_OF_REPOSITORY_KEY_STRING="full_name"; - private static final String GITHUB_GRAPHQL_API_STARTING_LINE_KEY_STRING="startingLine"; - private static final String GITHUB_GRAPHQL_API_ENDING_LINE_KEY_STRING="endingLine"; - private static final String GITHUB_GRAPHQL_API_AGE_KEY_STRING="age"; - private static final String GITHUB_GRAPHQL_API_DATA_KEY_STRING="data"; - private static final String GITHUB_GRAPHQL_API_REPOSITORY_KEY_STRING="repository"; - private static final String GITHUB_GRAPHQL_API_OBJECT_KEY_STRING="object"; - private static final String GITHUB_GRAPHQL_API_BLAME_KEY_STRING="blame"; - private static final String GITHUB_GRAPHQL_API_RANGES_KEY_STRING="ranges"; - private static final String GITHUB_GRAPHQL_API_COMMIT_KEY_STRING="commit"; - private static final String GITHUB_GRAPHQL_API_AUTHOR_KEY_STRING="author"; - private static final String GITHUB_GRAPHQL_API_NAME_KEY_STRING="name"; - private static final String GITHUB_GRAPHQL_API_URL_KEY_STRING="url"; - private static final String GITHUB_GRAPHQL_API_HISTORY_KEY_STRING="history"; - private static final String GITHUB_GRAPHQL_API_EDGE_KEY_STRING="edges"; - private static final String GITHUB_GRAPHQL_API_NODE_KEY_STRING="node"; - - + private static final String GITHUB_SEARCH_API_ITEMS_KEY_STRING = "items"; + private static final String GITHUB_SEARCH_API_REPOSITORY_KEY_STRING = "repository"; + private static final String GITHUB_SEARCH_API_FULL_NAME_OF_REPOSITORY_KEY_STRING = "full_name"; + private static final String GITHUB_GRAPHQL_API_STARTING_LINE_KEY_STRING = "startingLine"; + private static final String GITHUB_GRAPHQL_API_ENDING_LINE_KEY_STRING = "endingLine"; + private static final String GITHUB_GRAPHQL_API_AGE_KEY_STRING = "age"; + private static final String GITHUB_GRAPHQL_API_DATA_KEY_STRING = "data"; + private static final String GITHUB_GRAPHQL_API_REPOSITORY_KEY_STRING = "repository"; + private static final String GITHUB_GRAPHQL_API_OBJECT_KEY_STRING = "object"; + private static final String GITHUB_GRAPHQL_API_BLAME_KEY_STRING = "blame"; + private static final String GITHUB_GRAPHQL_API_RANGES_KEY_STRING = "ranges"; + private static final String GITHUB_GRAPHQL_API_COMMIT_KEY_STRING = "commit"; + private static final String GITHUB_GRAPHQL_API_AUTHOR_KEY_STRING = "author"; + private static final String GITHUB_GRAPHQL_API_NAME_KEY_STRING = "name"; + private static final String GITHUB_GRAPHQL_API_URL_KEY_STRING = "url"; + private static final String GITHUB_GRAPHQL_API_HISTORY_KEY_STRING = "history"; + private static final String GITHUB_GRAPHQL_API_EDGE_KEY_STRING = "edges"; + private static final String GITHUB_GRAPHQL_API_NODE_KEY_STRING = "node"; public String getUrlForSearchingCommits() { @@ -99,14 +98,12 @@ public Set obtainRepoNamesForCommitHashes(String gitHubToken, String[] commitsIn JSONObject jsonObject = null; try { jsonObject = (JSONObject) restApiCaller.callApi(getUrlForSearchingCommits(), gitHubToken, true, false); - } catch (Exception e) { - System.out.println(e.getMessage() + "cause" + e.getCause()); - } - try { - saveRepoNamesInAnArray(jsonObject, commitHash, gitHubToken); } catch (CodeQualityMatricesException e) { - logger.error("IO exception occurred when calling the github graphQL API", e); + logger.error(e.getMessage(), e.getCause()); + System.exit(1); } + + saveRepoNamesInAnArray(jsonObject, commitHash, gitHubToken); }); return commitHashObtainedForPRReview; } @@ -119,7 +116,7 @@ public Set obtainRepoNamesForCommitHashes(String gitHubToken, String[] commitsIn * @param gitHubToken github token for accessing the github REST API */ - public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, String gitHubToken) throws CodeQualityMatricesException { + public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, String gitHubToken) { JSONArray jsonArrayOfItems = (JSONArray) rootJsonObject.get(GITHUB_SEARCH_API_ITEMS_KEY_STRING); // setting the size of the repoLocationArray repoLocation = new String[jsonArrayOfItems.length()]; @@ -143,10 +140,9 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, Map> mapWithFileNamesAndPatch = null; try { mapWithFileNamesAndPatch = sdkGitHubClient.getFilesChanged(repoLocation[i], commitHash); - } catch (Exception e) { - - // here - System.out.println(e.getMessage() + "cause" + e.getCause()); + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside a lambda expression + System.exit(2); } fileNames = mapWithFileNamesAndPatch.get("fileNames"); patchString = mapWithFileNamesAndPatch.get("patchString"); @@ -154,11 +150,11 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, try { iterateOverFileChanges(repoLocation[i], commitHash, gitHubToken); } catch (Exception e) { - System.out.println(e.getMessage() + "cause" + e.getCause()); + logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside a lambda expression + System.exit(3); } }); - // for printing the author names and commit hashes for a certain commit. System.out.println(authorNames); System.out.println(commitHashObtainedForPRReview); @@ -233,8 +229,9 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin // calling the graphql API for getting blame information for the current file and saving it in a location. rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); } catch (CodeQualityMatricesException e) { - //check here - System.out.println(e.getMessage() + "cause" + e.getCause()); } + logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside lambda expression + System.exit(1); + } // reading the above saved output for the current selected file name readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, false); @@ -373,7 +370,9 @@ public void iterateOverToFindAuthors(String owner, String repositoryName, String rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, true); } catch (CodeQualityMatricesException e) { - System.out.println(e.getMessage() + "cause" + e.getCause()); } + logger.error(e.getMessage(), e.getCause()); + System.exit(1); + } }); } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java index 69137ac..0f71167 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java @@ -67,14 +67,11 @@ public Object callGraphQlApi(JSONObject queryObject, String gitHubToken) throws httpPost.setEntity(entity); response = client.execute(httpPost); } catch (UnsupportedEncodingException e) { - logger.error("Encoding error occured before calling the github graphQL API", e); - throw new CodeQualityMatricesException("Encoding error occured before calling the github graphQL API",e); + throw new CodeQualityMatricesException("Encoding error occured before calling the github graphQL API", e); } catch (ClientProtocolException e) { - logger.error("Client protocol exception occurred when calling the github graphQL API", e); - throw new CodeQualityMatricesException("Client protocol exception occurred when calling the github graphQL API",e); + throw new CodeQualityMatricesException("Client protocol exception occurred when calling the github graphQL API", e); } catch (IOException e) { - logger.error("IO Exception occured when calling the github graphQL API", e); - throw new CodeQualityMatricesException("IO Exception occured when calling the github graphQL API",e); + throw new CodeQualityMatricesException("IO Exception occured when calling the github graphQL API", e); } BufferedReader bufferedReader = null; @@ -87,27 +84,30 @@ public Object callGraphQlApi(JSONObject queryObject, String gitHubToken) throws } String jsonText = stringBuilder.toString(); + logger.info("The response received from the Github GraphQL converted to a JSON text successfully"); + Object json = new JSONTokener(jsonText).nextValue(); // gives an object http://stackoverflow.com/questions/14685777/how-to-check-if-response-from-server-is-jsonaobject-or-jsonarray if (json instanceof JSONObject) { JSONObject jsonObject = (JSONObject) json; returnedObject = jsonObject; + logger.info("JSONObject was returned successfully after calling the GraphQL API"); } else if (json instanceof JSONArray) { JSONArray jsonArray = (JSONArray) json; returnedObject = jsonArray; + logger.info("JSONArray was returned successfully after calling the GraphQL API"); + } // System.out.println(stringBuilder.toString()); } catch (Exception e) { - logger.error("Exception occured when reading the response received from github graphQL API", e); - throw new CodeQualityMatricesException("Exception occured when reading the response received from github graphQL API",e); + throw new CodeQualityMatricesException("Exception occurred when reading the response received from github graphQL API", e); } finally { if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException e) { - logger.error("IOException occured when closing the buffered reader",e); - throw new CodeQualityMatricesException("IOException occured when closing the buffered reader",e); + throw new CodeQualityMatricesException("IOException occurred when closing the buffered reader", e); } } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index 5ffd48a..4227cba 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -37,15 +37,15 @@ public static void main(String[] args) { String pmtToken = args[0]; String patchId = args[1]; - String pmtUrl = "http://umt.private.wso2.com:9765/codequalitymatricesapi/1.0.0//properties?path=/_system/governance/patchs/" + patchId; + String pmtUrl = "http://umt.private.wso2.com:8765/codequalitymatricesapi/1.0.0//properties?path=/_system/governance/patchs/" + patchId; RestApiCaller restApiCaller = new RestApiCaller(); JSONArray jsonArray = null; try { jsonArray = (JSONArray) restApiCaller.callApi(pmtUrl, pmtToken, false, false); - } catch (Exception e) { - //Check these - System.out.println(e.getMessage() + "cause" + e.getCause()); + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(),e.getCause()); + System.exit(1); } logger.info("JSON response is received successfully from WSO2 PMT for the given patch " + args[1]); @@ -57,10 +57,10 @@ public static void main(String[] args) { logger.info("Commits received from WSO2 PMT are saved in an array successfully"); String gitHubToken = args[2]; - ChangeFinder changeFinder = new ChangeFinder(); + ChangesFinder changesFinder = new ChangesFinder(); Set commitHashObtainedForPRReview = null; if (commitsInTheGivenPatch != null) { - commitHashObtainedForPRReview = changeFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); + commitHashObtainedForPRReview = changesFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); } logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java index ba9483e..923a8cd 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java @@ -89,6 +89,7 @@ public List getCommitHashesToList(JSONArray array) { } /** + * This method is used to obtain a sequential stream * @param array JSON array that a sequential stream should be obtained from * @return a sequential stream created from the supplied JSON Array */ diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java index 7701932..e7a33ed 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java @@ -97,10 +97,9 @@ public Object callApi(String URL, String accessToken, boolean requireCommitHeade logger.info("JSON response is passed after calling the given REST API"); } catch (ClientProtocolException e) { - logger.error("ClientProtocolException when calling the REST API", e); throw new CodeQualityMatricesException("ClientProtocolException when calling the REST API", e); + } catch (IOException e) { - logger.error("IOException occurred when calling the REST API"); throw new CodeQualityMatricesException("IOException occurred when calling the REST API", e); } finally { @@ -108,7 +107,6 @@ public Object callApi(String URL, String accessToken, boolean requireCommitHeade try { bufferedReader.close(); } catch (IOException e) { - logger.error("IOException occurred when closing the BufferedReader"); throw new CodeQualityMatricesException("IOException occurred when closing the BufferedReader", e); } } @@ -117,14 +115,12 @@ public Object callApi(String URL, String accessToken, boolean requireCommitHeade try { httpResponse.close(); } catch (IOException e) { - logger.error("IOException occurred when closing the HttpResponse"); throw new CodeQualityMatricesException("IOException occurred when closing the HttpResponse", e); } } if (httpclient != null) { try { httpclient.close(); } catch (IOException e) { - logger.error("IOException occurred when closing the HttpClient"); throw new CodeQualityMatricesException("IOException occurred when closing the HttpClient", e); } } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java index 7f1b6f5..8588b7b 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java @@ -94,8 +94,9 @@ public void findReviewers(Set commitHashObtainedForPRReview, String gith JSONObject rootJsonObject = null; try { rootJsonObject = (JSONObject) restApiCaller.callApi(getSearchPullReqeustAPI(), githubToken, false, true); - } catch (Exception e) { - System.out.println(e.getMessage() + " cause " + e.getCause()); + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(),e.getCause()); + System.exit(1); } // reading thus saved json file if (rootJsonObject != null) { @@ -171,7 +172,7 @@ public void saveReviewersToList(String githubToken, RestApiCaller restApiCaller) for (Map.Entry m : mapContainingPRNoAgainstRepoName.entrySet()) { String productLocation = (String) m.getKey(); - @SuppressWarnings("unchecked") + Set prNumbers = (Set) m.getValue(); prNumbers.stream().forEach(prNumber -> { @@ -179,8 +180,9 @@ public void saveReviewersToList(String githubToken, RestApiCaller restApiCaller) JSONArray reviewJsonArray = null; try { reviewJsonArray = (JSONArray) restApiCaller.callApi(getPullRequestReviewAPIUrl(), githubToken, false, true); - } catch (Exception e) { - System.out.println(e.getMessage() + "cause" + e.getCause()); + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(),e.getCause()); + System.exit(1); } // for reading the output JSON from above and adding the reviewers to the Set if (reviewJsonArray != null) { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java index 7bbdfc8..2e83590 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java @@ -77,7 +77,6 @@ public Map> getFilesChanged(String repositoryName, Str mapWithFileNamesAndPatches.put("fileNames", fileNames); mapWithFileNamesAndPatches.put("patchString", patchString); } catch (IOException e) { - logger.error("IO Exception occurred when getting the commit with the given SHA form the given repository ", e); throw new CodeQualityMatricesException("IO Exception occurred when getting the commit with the given SHA form the given repository ", e); } return mapWithFileNamesAndPatches; diff --git a/CodeQualityMatricesProject/src/main/resources/log4j.properties b/CodeQualityMatricesProject/src/main/resources/log4j.properties index 5e0581b..c969242 100644 --- a/CodeQualityMatricesProject/src/main/resources/log4j.properties +++ b/CodeQualityMatricesProject/src/main/resources/log4j.properties @@ -27,6 +27,12 @@ log4j.appender.APPENDER1.MaxBackupIndex=5 log4j.appender.APPENDER1.layout=org.apache.log4j.PatternLayout log4j.appender.APPENDER1.layout.conversionPattern=%d{yyyy-MM-dd}-5p--10c:%m%n +#log4j.appender.CONSOLE= org.apache.log4j.ConsoleAppender +#log4j.appender.CONSOLE.Target=System.out +#log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +#log4j.appender.CONSOLE.layout.conversionPattern=%d{yyyy-MM-dd}-5p--10c:%m%n + + From 43c52d1fc803ddd138fd1596e3c44e5afc997b82 Mon Sep 17 00:00:00 2001 From: kasun Date: Mon, 20 Mar 2017 21:56:49 +0530 Subject: [PATCH 26/62] Delete replaced codes from Java 8 --- .../code/quality/matrices/ChangesFinder.java | 2 +- .../wso2/code/quality/matrices/Reviewer.java | 61 ------------------- 2 files changed, 1 insertion(+), 62 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index 8a2f4d0..77507c4 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -41,7 +41,7 @@ public class ChangesFinder { - private String urlForObtainingCommits, urlForGetingFilesChanged; + private String urlForObtainingCommits; protected ArrayList fileNames = new ArrayList(); protected ArrayList patchString = new ArrayList<>(); protected List> lineRangesChanged = new ArrayList>(); // for saving the line no that are changed diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java index 8588b7b..2d6720c 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java @@ -104,22 +104,6 @@ public void findReviewers(Set commitHashObtainedForPRReview, String gith } }); -// Iterator commitHashObtainedForPRReviewIterator = commitHashObtainedForPRReview.iterator(); -// while (commitHashObtainedForPRReviewIterator.hasNext()) { -// String commitHashForFindingReviewers = (String) commitHashObtainedForPRReviewIterator.next(); -// setSearchPullReqeustAPI(commitHashForFindingReviewers); -// // calling the github search API -// JSONObject rootJsonObject = null; -// try { -// rootJsonObject = (JSONObject) restApiCaller.callApi(getSearchPullReqeustAPI(), githubToken, false, true); -// } catch (Exception e) { -// System.out.println(e.getMessage() + " cause " + e.getCause()); -// } -// // reading thus saved json file -// if (rootJsonObject != null) { -// savePrNumberAndRepoName(rootJsonObject); -// } -// } logger.info("PR numbers which introduce bug lines of code with their relevant repository are saved successfully to mapContainingPRNoAgainstRepoName map"); saveReviewersToList(githubToken, restApiCaller); logger.info("List of approved reviwers and comment users of the PRs which introduce bug lines to repository are saved in commentedReviewers and approvedReviewers list "); @@ -146,21 +130,6 @@ public void savePrNumberAndRepoName(JSONObject rootJsonObject) { mapContainingPRNoAgainstRepoName.get(repositoryLocation).add(pullRequetNumber); // since SET is there we do not need to check for availability of the key in the map } }); - -// for (int i = 0; i < itemsJsonArray.length(); i++) { -// JSONObject prJsonObject = (JSONObject) itemsJsonArray.get(i); -// // filtering only the closed repositories -// if (((String) prJsonObject.get("state")).equals("closed")) { -// String repositoryUrl = (String) prJsonObject.get("repository_url"); -// String repositoryLocation = StringUtils.substringAfter(repositoryUrl, "https://api.github.com/repos/"); -// if (repositoryLocation.contains("wso2/")) { -// // to filter out only the repositories belongs to wso2 -// int pullRequetNumber = (int) prJsonObject.get("number"); -// mapContainingPRNoAgainstRepoName.putIfAbsent(repositoryLocation, new HashSet()); // put the repo name key only if it does not exists in the map -// mapContainingPRNoAgainstRepoName.get(repositoryLocation).add(pullRequetNumber); // since SET is there we do not need to check for availability of the key in the map -// } -// } -// } } /** @@ -191,22 +160,6 @@ public void saveReviewersToList(String githubToken, RestApiCaller restApiCaller) }); - -// Iterator prNumberIterator = prNumbers.iterator(); -// while (prNumberIterator.hasNext()) { -// int prNumber = (int) prNumberIterator.next(); -// setPullRequestReviewAPIUrl(productLocation, prNumber); -// JSONArray rootJsonArray = null; -// try { -// rootJsonArray = (JSONArray) restApiCaller.callApi(getPullRequestReviewAPIUrl(), githubToken, false, true); -// } catch (Exception e) { -// System.out.println(e.getMessage() + "cause" + e.getCause()); -// } -// // for reading the output JSON from above and adding the reviewers to the Set -// if (rootJsonArray != null) { -// readTheReviewOutJSON(rootJsonArray, productLocation, prNumber); -// } -// } } } @@ -227,20 +180,6 @@ public void readTheReviewOutJSON(JSONArray reviewJsonArray, String productLocati addRelevantUsersToList(reviewJsonObject); } } -// for (int i = 0; i < reviewJsonArray.length(); i++) { -// JSONObject reviewJsonObject = (JSONObject) reviewJsonArray.get(i); -// if ((reviewJsonObject.get("state")).equals("APPROVED")) { -// -// JSONObject userJsonObject = (JSONObject) reviewJsonObject.get("user"); -// String approvedReviwer = (String) userJsonObject.get("login"); -// approvedReviewers.add(approvedReviwer); // adding the approved user to the Set -// -// } else if ((reviewJsonObject.get("state")).equals("COMMENTED")) { -// JSONObject userJsonObject = (JSONObject) reviewJsonObject.get("user"); -// String commentedReviwer = (String) userJsonObject.get("login"); -// commentedReviewers.add(commentedReviwer); // adding the commented user to the Set -// } -// } } else { System.out.println("There are no records of reviews for pull request: " + prNumber + " on " + productLocation + " repository"); } From 772a100788beb7c4321e7d179c4cdf5f4791873b Mon Sep 17 00:00:00 2001 From: kasun Date: Mon, 20 Mar 2017 22:33:24 +0530 Subject: [PATCH 27/62] fix formatting in java 8 stream API codes --- .../code/quality/matrices/ChangesFinder.java | 376 +++++++++--------- .../CodeQualityMatricesException.java | 3 +- .../wso2/code/quality/matrices/MainClass.java | 4 +- .../com/wso2/code/quality/matrices/Pmt.java | 5 +- .../code/quality/matrices/RestApiCaller.java | 8 +- .../wso2/code/quality/matrices/Reviewer.java | 111 +++--- .../quality/matrices/SdkGitHubClient.java | 9 +- 7 files changed, 269 insertions(+), 247 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index 77507c4..a3a4382 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -93,18 +93,20 @@ public void setUrlForSearchingCommits(String commitHash) { public Set obtainRepoNamesForCommitHashes(String gitHubToken, String[] commitsInTheGivenPatch, RestApiCaller restApiCaller) { //calling the API calling method - IntStream.range(0, commitsInTheGivenPatch.length).mapToObj(i -> commitsInTheGivenPatch[i]).forEach(commitHash -> { - setUrlForSearchingCommits(commitHash); - JSONObject jsonObject = null; - try { - jsonObject = (JSONObject) restApiCaller.callApi(getUrlForSearchingCommits(), gitHubToken, true, false); - } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); - System.exit(1); - } - - saveRepoNamesInAnArray(jsonObject, commitHash, gitHubToken); - }); + IntStream.range(0, commitsInTheGivenPatch.length) + .mapToObj(i -> commitsInTheGivenPatch[i]) + .forEach(commitHash -> { + setUrlForSearchingCommits(commitHash); + JSONObject jsonObject = null; + try { + jsonObject = (JSONObject) restApiCaller.callApi(getUrlForSearchingCommits(), gitHubToken, true, false); + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e.getCause()); + System.exit(1); + } + + saveRepoNamesInAnArray(jsonObject, commitHash, gitHubToken); + }); return commitHashObtainedForPRReview; } @@ -121,39 +123,42 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, // setting the size of the repoLocationArray repoLocation = new String[jsonArrayOfItems.length()]; //adding the repo name to the array - IntStream.range(0, jsonArrayOfItems.length()).forEach(i -> { - JSONObject jsonObject = (JSONObject) jsonArrayOfItems.get(i); - JSONObject repositoryJsonObject = (JSONObject) jsonObject.get(GITHUB_SEARCH_API_REPOSITORY_KEY_STRING); - repoLocation[i] = (String) repositoryJsonObject.get(GITHUB_SEARCH_API_FULL_NAME_OF_REPOSITORY_KEY_STRING); - }); + IntStream.range(0, jsonArrayOfItems.length()) + .forEach(i -> { + JSONObject jsonObject = (JSONObject) jsonArrayOfItems.get(i); + JSONObject repositoryJsonObject = (JSONObject) jsonObject.get(GITHUB_SEARCH_API_REPOSITORY_KEY_STRING); + repoLocation[i] = (String) repositoryJsonObject.get(GITHUB_SEARCH_API_FULL_NAME_OF_REPOSITORY_KEY_STRING); + }); logger.info("Repo names having the given commit are successfully saved in an array"); SdkGitHubClient sdkGitHubClient = new SdkGitHubClient(gitHubToken); // for running through the repoName Array - IntStream.range(0, repoLocation.length).filter(i -> StringUtils.contains(repoLocation[i], "wso2/")).forEach(i -> { - //clearing all the data in the current fileNames and lineRangesChanged arraylists for each repository - //authorNames.clear(); - fileNames.clear(); - lineRangesChanged.clear(); - patchString.clear(); - Map> mapWithFileNamesAndPatch = null; - try { - mapWithFileNamesAndPatch = sdkGitHubClient.getFilesChanged(repoLocation[i], commitHash); - } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside a lambda expression - System.exit(2); - } - fileNames = mapWithFileNamesAndPatch.get("fileNames"); - patchString = mapWithFileNamesAndPatch.get("patchString"); - saveRelaventEditLineNumbers(fileNames, patchString); - try { - iterateOverFileChanges(repoLocation[i], commitHash, gitHubToken); - } catch (Exception e) { - logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside a lambda expression - System.exit(3); - } - }); + IntStream.range(0, repoLocation.length) + .filter(i -> StringUtils.contains(repoLocation[i], "wso2/")) + .forEach(i -> { + //clearing all the data in the current fileNames and lineRangesChanged arraylists for each repository + //authorNames.clear(); + fileNames.clear(); + lineRangesChanged.clear(); + patchString.clear(); + Map> mapWithFileNamesAndPatch = null; + try { + mapWithFileNamesAndPatch = sdkGitHubClient.getFilesChanged(repoLocation[i], commitHash); + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside a lambda expression + System.exit(2); + } + fileNames = mapWithFileNamesAndPatch.get("fileNames"); + patchString = mapWithFileNamesAndPatch.get("patchString"); + saveRelaventEditLineNumbers(fileNames, patchString); + try { + iterateOverFileChanges(repoLocation[i], commitHash, gitHubToken); + } catch (Exception e) { + logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside a lambda expression + System.exit(3); + } + }); // for printing the author names and commit hashes for a certain commit. System.out.println(authorNames); @@ -171,33 +176,36 @@ public void saveRelaventEditLineNumbers(ArrayList fileNames, ArrayList StringUtils.substringsBetween(patch, "@@ ", " @@")).forEach(lineChanges -> { - //filtering the lines ranges that existed in the previous file, that exists in the new file and saving them in to the same array - IntStream.range(0, lineChanges.length).forEach(j -> { - //@@ -22,7 +22,7 @@ - String tempString = lineChanges[j]; - String lineRangeInTheOldFileBeingModified = StringUtils.substringBetween(tempString, "-", " +"); // for taking the authors and commit hashes of the previous lines - String lineRangeInTheNewFileResultedFromModification = StringUtils.substringAfter(tempString, "+"); // for taking the parent commit - - int intialLineNoInOldFile = Integer.parseInt(StringUtils.substringBefore(lineRangeInTheOldFileBeingModified, ",")); - int tempEndLineNoInOldFile = Integer.parseInt(StringUtils.substringAfter(lineRangeInTheOldFileBeingModified, ",")); - int endLineNoOfOldFile; - if (intialLineNoInOldFile != 0) { - // to filterout the newly created files - endLineNoOfOldFile = intialLineNoInOldFile + (tempEndLineNoInOldFile - 1); - } else { - endLineNoOfOldFile = tempEndLineNoInOldFile; - } - int intialLineNoInNewFile = Integer.parseInt(StringUtils.substringBefore(lineRangeInTheNewFileResultedFromModification, ",")); - int tempEndLineNoInNewFile = Integer.parseInt(StringUtils.substringAfter(lineRangeInTheNewFileResultedFromModification, ",")); - int endLineNoOfNewFile = intialLineNoInNewFile + (tempEndLineNoInNewFile - 1); - // storing the line ranges that are being modified in the same array by replacing values - lineChanges[j] = intialLineNoInOldFile + "," + endLineNoOfOldFile + "/" + intialLineNoInNewFile + "," + endLineNoOfNewFile; - }); - ArrayList tempArrayList = new ArrayList<>(Arrays.asList(lineChanges)); - //adding to the array list which keep track of the line ranges being changed - lineRangesChanged.add(tempArrayList); - }); + patchString.stream() + .map(patch -> StringUtils.substringsBetween(patch, "@@ ", " @@")) + .forEach(lineChanges -> { + //filtering the lines ranges that existed in the previous file, that exists in the new file and saving them in to the same array + IntStream.range(0, lineChanges.length) + .forEach(j -> { + //@@ -22,7 +22,7 @@ + String tempString = lineChanges[j]; + String lineRangeInTheOldFileBeingModified = StringUtils.substringBetween(tempString, "-", " +"); // for taking the authors and commit hashes of the previous lines + String lineRangeInTheNewFileResultedFromModification = StringUtils.substringAfter(tempString, "+"); // for taking the parent commit + + int intialLineNoInOldFile = Integer.parseInt(StringUtils.substringBefore(lineRangeInTheOldFileBeingModified, ",")); + int tempEndLineNoInOldFile = Integer.parseInt(StringUtils.substringAfter(lineRangeInTheOldFileBeingModified, ",")); + int endLineNoOfOldFile; + if (intialLineNoInOldFile != 0) { + // to filterout the newly created files + endLineNoOfOldFile = intialLineNoInOldFile + (tempEndLineNoInOldFile - 1); + } else { + endLineNoOfOldFile = tempEndLineNoInOldFile; + } + int intialLineNoInNewFile = Integer.parseInt(StringUtils.substringBefore(lineRangeInTheNewFileResultedFromModification, ",")); + int tempEndLineNoInNewFile = Integer.parseInt(StringUtils.substringAfter(lineRangeInTheNewFileResultedFromModification, ",")); + int endLineNoOfNewFile = intialLineNoInNewFile + (tempEndLineNoInNewFile - 1); + // storing the line ranges that are being modified in the same array by replacing values + lineChanges[j] = intialLineNoInOldFile + "," + endLineNoOfOldFile + "/" + intialLineNoInNewFile + "," + endLineNoOfNewFile; + }); + ArrayList tempArrayList = new ArrayList<>(Arrays.asList(lineChanges)); + //adding to the array list which keep track of the line ranges being changed + lineRangesChanged.add(tempArrayList); + }); System.out.println("done saving file names and their relevant modification line ranges"); System.out.println(fileNames); System.out.println(lineRangesChanged + "\n"); @@ -218,28 +226,29 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin String repositoryName = StringUtils.substringAfter(repoLocation, "/"); // iterating over the fileNames arraylist for the given commit // cannot use parallel streams here as the order of the file names is important in the process - fileNames.stream().forEach(fileName -> { - int index = fileNames.indexOf(fileName); - // the relevant arraylist of changed lines for that file - ArrayList arrayListOfRelevantChangedLines = lineRangesChanged.get(index); - commitHashesOfTheParent = new HashSet<>(); // for storing the parent commit hashes for all the line ranges of the relevant file - graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + commitHash + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{history(first: 2) { edges { node { message url } } } author { name email } } } } } } } }"); - JSONObject rootJsonObject = null; - try { - // calling the graphql API for getting blame information for the current file and saving it in a location. - rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); - } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside lambda expression - System.exit(1); - } - // reading the above saved output for the current selected file name - readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, false); - - // parent commit hashes are stored in the arraylist for the given file - - iterateOverToFindAuthors(owner, repositoryName, fileName, arrayListOfRelevantChangedLines, gitHubToken); - logger.info("Authors of the bug lines of code which are being fixed from the given patch are saved successfully to authorNames SET"); - }); + fileNames.stream() + .forEach(fileName -> { + int index = fileNames.indexOf(fileName); + // the relevant arraylist of changed lines for that file + ArrayList arrayListOfRelevantChangedLines = lineRangesChanged.get(index); + commitHashesOfTheParent = new HashSet<>(); // for storing the parent commit hashes for all the line ranges of the relevant file + graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + commitHash + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{history(first: 2) { edges { node { message url } } } author { name email } } } } } } } }"); + JSONObject rootJsonObject = null; + try { + // calling the graphql API for getting blame information for the current file and saving it in a location. + rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside lambda expression + System.exit(1); + } + // reading the above saved output for the current selected file name + readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, false); + + // parent commit hashes are stored in the arraylist for the given file + + iterateOverToFindAuthors(owner, repositoryName, fileName, arrayListOfRelevantChangedLines, gitHubToken); + logger.info("Authors of the bug lines of code which are being fixed from the given patch are saved successfully to authorNames SET"); + }); } /** @@ -261,93 +270,95 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList { - int startingLineNo; - int endLineNo; - String oldFileRange = StringUtils.substringBefore(lineRanges, "/"); - String newFileRange = StringUtils.substringAfter(lineRanges, "/"); - // need to skip the newly created files from taking the blame as they contain no previous commits - if (!oldFileRange.equals("0,0")) { - if (gettingPr) { - // need to consider the line range in the old file for finding authors and reviewers - startingLineNo = Integer.parseInt(StringUtils.substringBefore(oldFileRange, ",")); - endLineNo = Integer.parseInt(StringUtils.substringAfter(oldFileRange, ",")); - } else { - // need to consider the line range in the new file resulted from applying the commit for finding parent commits - - startingLineNo = Integer.parseInt(StringUtils.substringBefore(newFileRange, ",")); - endLineNo = Integer.parseInt(StringUtils.substringAfter(newFileRange, ",")); - } - - // as it is required to create a new Map for finding the recent commit for each line range - Map> mapForStoringAgeAndIndex = new HashMap>(); - - //checking line by line by iterating the startinLineNo - while (endLineNo >= startingLineNo) { - // since the index value is required for later processing "for loop" is used for iteration - for (int i = 0; i < rangeJSONArray.length(); i++) { - JSONObject rangeJSONObject = (JSONObject) rangeJSONArray.get(i); - int tempStartingLineNo = (int) rangeJSONObject.get(GITHUB_GRAPHQL_API_STARTING_LINE_KEY_STRING); - int tempEndingLineNo = (int) rangeJSONObject.get(GITHUB_GRAPHQL_API_ENDING_LINE_KEY_STRING); - - //checking whether the line belongs to that line range group - if ((tempStartingLineNo <= startingLineNo) && (tempEndingLineNo >= startingLineNo)) { - // so the relevant startingLineNo belongs in this line range in other words in this JSONObject - if (!gettingPr) { - int age = (int) rangeJSONObject.get(GITHUB_GRAPHQL_API_AGE_KEY_STRING); - // storing the age field with relevant index of the JSONObject - mapForStoringAgeAndIndex.putIfAbsent(age, new ArrayList()); - if (!mapForStoringAgeAndIndex.get(age).contains(i)) { - mapForStoringAgeAndIndex.get(age).add(i); // adding if the index is not present in the array list for the relevant age - } - - } else { - //for saving the author names of commiters - JSONObject commitJSONObject = (JSONObject) rangeJSONObject.get(GITHUB_GRAPHQL_API_COMMIT_KEY_STRING); + arrayListOfRelevantChangedLines.stream() + .forEach(lineRanges -> { + int startingLineNo; + int endLineNo; + String oldFileRange = StringUtils.substringBefore(lineRanges, "/"); + String newFileRange = StringUtils.substringAfter(lineRanges, "/"); + // need to skip the newly created files from taking the blame as they contain no previous commits + if (!oldFileRange.equals("0,0")) { + if (gettingPr) { + // need to consider the line range in the old file for finding authors and reviewers + startingLineNo = Integer.parseInt(StringUtils.substringBefore(oldFileRange, ",")); + endLineNo = Integer.parseInt(StringUtils.substringAfter(oldFileRange, ",")); + } else { + // need to consider the line range in the new file resulted from applying the commit for finding parent commits - JSONObject authorJSONObject = (JSONObject) commitJSONObject.get(GITHUB_GRAPHQL_API_AUTHOR_KEY_STRING); - String nameOfTheAuthor = (String) authorJSONObject.get(GITHUB_GRAPHQL_API_NAME_KEY_STRING); - authorNames.add(nameOfTheAuthor); // authors are added to the Set + startingLineNo = Integer.parseInt(StringUtils.substringBefore(newFileRange, ",")); + endLineNo = Integer.parseInt(StringUtils.substringAfter(newFileRange, ",")); + } - String urlOfCommit = (String) commitJSONObject.get(GITHUB_GRAPHQL_API_URL_KEY_STRING); - String commitHashForPRReview = StringUtils.substringAfter(urlOfCommit, "commit/"); - commitHashObtainedForPRReview.add(commitHashForPRReview); + // as it is required to create a new Map for finding the recent commit for each line range + Map> mapForStoringAgeAndIndex = new HashMap>(); + + //checking line by line by iterating the startinLineNo + while (endLineNo >= startingLineNo) { + // since the index value is required for later processing, without Java 8 features "for loop" is used for iteration + for (int i = 0; i < rangeJSONArray.length(); i++) { + JSONObject rangeJSONObject = (JSONObject) rangeJSONArray.get(i); + int tempStartingLineNo = (int) rangeJSONObject.get(GITHUB_GRAPHQL_API_STARTING_LINE_KEY_STRING); + int tempEndingLineNo = (int) rangeJSONObject.get(GITHUB_GRAPHQL_API_ENDING_LINE_KEY_STRING); + + //checking whether the line belongs to that line range group + if ((tempStartingLineNo <= startingLineNo) && (tempEndingLineNo >= startingLineNo)) { + // so the relevant startingLineNo belongs in this line range in other words in this JSONObject + if (!gettingPr) { + int age = (int) rangeJSONObject.get(GITHUB_GRAPHQL_API_AGE_KEY_STRING); + // storing the age field with relevant index of the JSONObject + mapForStoringAgeAndIndex.putIfAbsent(age, new ArrayList()); + if (!mapForStoringAgeAndIndex.get(age).contains(i)) { + mapForStoringAgeAndIndex.get(age).add(i); // adding if the index is not present in the array list for the relevant age + } + + } else { + //for saving the author names of commiters + JSONObject commitJSONObject = (JSONObject) rangeJSONObject.get(GITHUB_GRAPHQL_API_COMMIT_KEY_STRING); + + JSONObject authorJSONObject = (JSONObject) commitJSONObject.get(GITHUB_GRAPHQL_API_AUTHOR_KEY_STRING); + String nameOfTheAuthor = (String) authorJSONObject.get(GITHUB_GRAPHQL_API_NAME_KEY_STRING); + authorNames.add(nameOfTheAuthor); // authors are added to the Set + + String urlOfCommit = (String) commitJSONObject.get(GITHUB_GRAPHQL_API_URL_KEY_STRING); + String commitHashForPRReview = StringUtils.substringAfter(urlOfCommit, "commit/"); + commitHashObtainedForPRReview.add(commitHashForPRReview); + } + break; + } else { + continue; + } } - break; - } else { - continue; + startingLineNo++; // to check for other line numbers } + + //for the above line range getting the lastest commit which modified the lines + if (!gettingPr) { + //converting the map into a treeMap to get it ordered + TreeMap> treeMap = new TreeMap<>(mapForStoringAgeAndIndex); + int minimumKeyOfMapForStoringAgeAndIndex = treeMap.firstKey(); // getting the minimum key + //getting the relevant JSONObject indexes which consists of the recent commit with in the relevant line range + ArrayList indexesOfJsonObjectForRecentCommit = mapForStoringAgeAndIndex.get(minimumKeyOfMapForStoringAgeAndIndex); + // the order of the indexesOfJsonObjectForRecentCommit is not important as we only need to get the parent commit hashes + indexesOfJsonObjectForRecentCommit.parallelStream() + .forEach(index -> { + JSONObject rangeJSONObject = (JSONObject) rangeJSONArray.get(index); + JSONObject commitJSONObject = (JSONObject) rangeJSONObject.get(GITHUB_GRAPHQL_API_COMMIT_KEY_STRING); + JSONObject historyJSONObject = (JSONObject) commitJSONObject.get(GITHUB_GRAPHQL_API_HISTORY_KEY_STRING); + JSONArray edgesJSONArray = (JSONArray) historyJSONObject.get(GITHUB_GRAPHQL_API_EDGE_KEY_STRING); + //getting the second json object from the array as it contain the commit of the parent which modified the above line range + JSONObject edgeJSONObject = (JSONObject) edgesJSONArray.get(1); + JSONObject nodeJSONObject = (JSONObject) edgeJSONObject.get(GITHUB_GRAPHQL_API_NODE_KEY_STRING); + String urlOfTheParentCommit = (String) nodeJSONObject.get(GITHUB_GRAPHQL_API_URL_KEY_STRING); // this contain the URL of the parent commit + String commitHash = (String) StringUtils.substringAfter(urlOfTheParentCommit, "commit/"); + commitHashesOfTheParent.add(commitHash); + + }); + logger.info("Parent Commits hashes of the lines which are being fixed by the patch are saved to commitHashesOfTheParent SET successfully "); + } + } - startingLineNo++; // to check for other line numbers - } - - //for the above line range getting the lastest commit which modified the lines - if (!gettingPr) { - //converting the map into a treeMap to get it ordered - TreeMap> treeMap = new TreeMap<>(mapForStoringAgeAndIndex); - int minimumKeyOfMapForStoringAgeAndIndex = treeMap.firstKey(); // getting the minimum key - //getting the relevant JSONObject indexes which consists of the recent commit with in the relevant line range - ArrayList indexesOfJsonObjectForRecentCommit = mapForStoringAgeAndIndex.get(minimumKeyOfMapForStoringAgeAndIndex); - // the order of the indexesOfJsonObjectForRecentCommit is not important as we only need to get the parent commit hashes - indexesOfJsonObjectForRecentCommit.parallelStream().forEach(index -> { - JSONObject rangeJSONObject = (JSONObject) rangeJSONArray.get(index); - JSONObject commitJSONObject = (JSONObject) rangeJSONObject.get(GITHUB_GRAPHQL_API_COMMIT_KEY_STRING); - JSONObject historyJSONObject = (JSONObject) commitJSONObject.get(GITHUB_GRAPHQL_API_HISTORY_KEY_STRING); - JSONArray edgesJSONArray = (JSONArray) historyJSONObject.get(GITHUB_GRAPHQL_API_EDGE_KEY_STRING); - //getting the second json object from the array as it contain the commit of the parent which modified the above line range - JSONObject edgeJSONObject = (JSONObject) edgesJSONArray.get(1); - JSONObject nodeJSONObject = (JSONObject) edgeJSONObject.get(GITHUB_GRAPHQL_API_NODE_KEY_STRING); - String urlOfTheParentCommit = (String) nodeJSONObject.get(GITHUB_GRAPHQL_API_URL_KEY_STRING); // this contain the URL of the parent commit - String commitHash = (String) StringUtils.substringAfter(urlOfTheParentCommit, "commit/"); - commitHashesOfTheParent.add(commitHash); - - }); - logger.info("Parent Commits hashes of the lines which are being fixed by the patch are saved to commitHashesOfTheParent SET successfully "); - } - - } - - }); + + }); } /** @@ -363,17 +374,18 @@ public void iterateOverToFindAuthors(String owner, String repositoryName, String // calling the graphql api to get the blame details of the current file for the parent commits (That is found by filtering in the graqhQL output) //as the order is not important in here parallel streams are used - commitHashesOfTheParent.parallelStream().forEach(parentCommitHashForCallingGraphQl -> { - graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + parentCommitHashForCallingGraphQl + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{ url author { name email } } } } } } } }"); - JSONObject rootJsonObject = null; - try { - rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); - readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, true); - } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); - System.exit(1); - } - }); + commitHashesOfTheParent.parallelStream() + .forEach(parentCommitHashForCallingGraphQl -> { + graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + parentCommitHashForCallingGraphQl + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{ url author { name email } } } } } } } }"); + JSONObject rootJsonObject = null; + try { + rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); + readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, true); + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e.getCause()); + System.exit(1); + } + }); } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java index e281bfe..7c0b71c 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java @@ -21,12 +21,13 @@ /** * The exception class for all Code Quality Matrices project related exceptions. * - *@since 1.0.0 + * @since 1.0.0 */ public class CodeQualityMatricesException extends Exception { public CodeQualityMatricesException(String message) { super(message); } + public CodeQualityMatricesException(String message, Throwable cause) { super(message, cause); } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index 4227cba..21fd510 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -44,7 +44,7 @@ public static void main(String[] args) { try { jsonArray = (JSONArray) restApiCaller.callApi(pmtUrl, pmtToken, false, false); } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(),e.getCause()); + logger.error(e.getMessage(), e.getCause()); System.exit(1); } logger.info("JSON response is received successfully from WSO2 PMT for the given patch " + args[1]); @@ -66,7 +66,7 @@ public static void main(String[] args) { Reviewer reviewer = new Reviewer(); if (commitHashObtainedForPRReview != null) { - reviewer.findReviewers(commitHashObtainedForPRReview, gitHubToken,restApiCaller); + reviewer.findReviewers(commitHashObtainedForPRReview, gitHubToken, restApiCaller); } } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java index 923a8cd..5b7b482 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java @@ -58,7 +58,9 @@ public String[] getPublicGitCommitHashes(JSONArray jsonArray) { logger.info(" The commits hashes obtained from WSO2 PMT are successfully saved to an array"); System.out.println("The commit Ids are"); // for printing all the commits ID associated with a patch - IntStream.range(0, patchInformation_svnRevisionpublic.length).mapToObj(i -> patchInformation_svnRevisionpublic[i]).forEach(System.out::println); + IntStream.range(0, patchInformation_svnRevisionpublic.length) + .mapToObj(i -> patchInformation_svnRevisionpublic[i]) + .forEach(System.out::println); System.out.println(); //to prevent from internaal representation by returning referecnce to mutable object @@ -90,6 +92,7 @@ public List getCommitHashesToList(JSONArray array) { /** * This method is used to obtain a sequential stream + * * @param array JSON array that a sequential stream should be obtained from * @return a sequential stream created from the supplied JSON Array */ diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java index e7a33ed..80f31fa 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java @@ -44,7 +44,7 @@ public class RestApiCaller { * calling the relevant API and saving the output to a file * * @param URL url of the REST API to be called - * @param accessToken either the WSO2 PMT access accessToken or giihub.com access accessToken + * @param accessToken either the WSO2 PMT access accessToken or giihub.com access accessToken * @param requireCommitHeader should be true for accessing the github commit search API and false otherwise * @param requireReviewHeader should be true for accessing the github review API or false otherwise */ @@ -115,13 +115,15 @@ public Object callApi(String URL, String accessToken, boolean requireCommitHeade try { httpResponse.close(); } catch (IOException e) { - throw new CodeQualityMatricesException("IOException occurred when closing the HttpResponse", e); } + throw new CodeQualityMatricesException("IOException occurred when closing the HttpResponse", e); + } } if (httpclient != null) { try { httpclient.close(); } catch (IOException e) { - throw new CodeQualityMatricesException("IOException occurred when closing the HttpClient", e); } + throw new CodeQualityMatricesException("IOException occurred when closing the HttpClient", e); + } } } return returnedObject; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java index 2d6720c..8e89fee 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java @@ -42,17 +42,15 @@ public class Reviewer { private static final Logger logger = Logger.getLogger(Reviewer.class); //constants for accessing github API - private static final String GITHUB_REVIEW_API_STATE_KEY="state"; - private static final String GITHUB_REVIEW_API_APPROVED_KEY="APPROVED"; - private static final String GITHUB_REVIEW_API_COMMENTED_KEY="COMMENTED"; - private static final String GITHUB_REVIEW_API_LOGIN_KEY="login"; - private static final String GITHUB_REVIEW_API_USER_KEY="user"; - private static final String GITHUB_REVIEW_API_ITEMS_KEY="items"; - private static final String GITHUB_REVIEW_API_REPOSITORY_URL_KEY="repository_url"; - private static final String GITHUB_REVIEW_API_NUMBER_KEY="number"; - private static final String GITHUB_REVIEW_API_CLOSED_STATE_KEY ="closed"; - - + private static final String GITHUB_REVIEW_API_STATE_KEY = "state"; + private static final String GITHUB_REVIEW_API_APPROVED_KEY = "APPROVED"; + private static final String GITHUB_REVIEW_API_COMMENTED_KEY = "COMMENTED"; + private static final String GITHUB_REVIEW_API_LOGIN_KEY = "login"; + private static final String GITHUB_REVIEW_API_USER_KEY = "user"; + private static final String GITHUB_REVIEW_API_ITEMS_KEY = "items"; + private static final String GITHUB_REVIEW_API_REPOSITORY_URL_KEY = "repository_url"; + private static final String GITHUB_REVIEW_API_NUMBER_KEY = "number"; + private static final String GITHUB_REVIEW_API_CLOSED_STATE_KEY = "closed"; public String getSearchPullReqeustAPI() { @@ -88,21 +86,22 @@ public void setPullRequestReviewAPIUrl(String repoLocation, int pullRequestNumbe */ public void findReviewers(Set commitHashObtainedForPRReview, String githubToken, RestApiCaller restApiCaller) { - commitHashObtainedForPRReview.stream().forEach(commitHashForFindingReviewers -> { - setSearchPullReqeustAPI(commitHashForFindingReviewers); - // calling the github search API - JSONObject rootJsonObject = null; - try { - rootJsonObject = (JSONObject) restApiCaller.callApi(getSearchPullReqeustAPI(), githubToken, false, true); - } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(),e.getCause()); - System.exit(1); - } - // reading thus saved json file - if (rootJsonObject != null) { - savePrNumberAndRepoName(rootJsonObject); - } - }); + commitHashObtainedForPRReview.stream() + .forEach(commitHashForFindingReviewers -> { + setSearchPullReqeustAPI(commitHashForFindingReviewers); + // calling the github search API + JSONObject rootJsonObject = null; + try { + rootJsonObject = (JSONObject) restApiCaller.callApi(getSearchPullReqeustAPI(), githubToken, false, true); + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e.getCause()); + System.exit(1); + } + // reading thus saved json file + if (rootJsonObject != null) { + savePrNumberAndRepoName(rootJsonObject); + } + }); logger.info("PR numbers which introduce bug lines of code with their relevant repository are saved successfully to mapContainingPRNoAgainstRepoName map"); saveReviewersToList(githubToken, restApiCaller); @@ -120,16 +119,19 @@ public void findReviewers(Set commitHashObtainedForPRReview, String gith public void savePrNumberAndRepoName(JSONObject rootJsonObject) { JSONArray itemsJsonArray = (JSONArray) rootJsonObject.get(GITHUB_REVIEW_API_ITEMS_KEY); - Pmt.arrayToStream(itemsJsonArray).map(JSONObject.class::cast).filter(o -> o.get(GITHUB_REVIEW_API_STATE_KEY).equals(GITHUB_REVIEW_API_CLOSED_STATE_KEY)).forEach(prJsonObject -> { - String repositoryUrl = (String) prJsonObject.get(GITHUB_REVIEW_API_REPOSITORY_URL_KEY); - String repositoryLocation = StringUtils.substringAfter(repositoryUrl, "https://api.github.com/repos/"); - if (repositoryLocation.contains("wso2/")) { - // to filter out only the repositories belongs to wso2 - int pullRequetNumber = (int) prJsonObject.get(GITHUB_REVIEW_API_NUMBER_KEY); - mapContainingPRNoAgainstRepoName.putIfAbsent(repositoryLocation, new HashSet()); // put the repo name key only if it does not exists in the map - mapContainingPRNoAgainstRepoName.get(repositoryLocation).add(pullRequetNumber); // since SET is there we do not need to check for availability of the key in the map - } - }); + Pmt.arrayToStream(itemsJsonArray) + .map(JSONObject.class::cast) + .filter(o -> o.get(GITHUB_REVIEW_API_STATE_KEY).equals(GITHUB_REVIEW_API_CLOSED_STATE_KEY)) + .forEach(prJsonObject -> { + String repositoryUrl = (String) prJsonObject.get(GITHUB_REVIEW_API_REPOSITORY_URL_KEY); + String repositoryLocation = StringUtils.substringAfter(repositoryUrl, "https://api.github.com/repos/"); + if (repositoryLocation.contains("wso2/")) { + // to filter out only the repositories belongs to wso2 + int pullRequetNumber = (int) prJsonObject.get(GITHUB_REVIEW_API_NUMBER_KEY); + mapContainingPRNoAgainstRepoName.putIfAbsent(repositoryLocation, new HashSet()); // put the repo name key only if it does not exists in the map + mapContainingPRNoAgainstRepoName.get(repositoryLocation).add(pullRequetNumber); // since SET is there we do not need to check for availability of the key in the map + } + }); } /** @@ -144,22 +146,22 @@ public void saveReviewersToList(String githubToken, RestApiCaller restApiCaller) Set prNumbers = (Set) m.getValue(); - prNumbers.stream().forEach(prNumber -> { - setPullRequestReviewAPIUrl(productLocation, prNumber); - JSONArray reviewJsonArray = null; - try { - reviewJsonArray = (JSONArray) restApiCaller.callApi(getPullRequestReviewAPIUrl(), githubToken, false, true); - } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(),e.getCause()); - System.exit(1); - } - // for reading the output JSON from above and adding the reviewers to the Set - if (reviewJsonArray != null) { - readTheReviewOutJSON(reviewJsonArray, productLocation, prNumber); - } - - - }); + prNumbers.stream() + .forEach(prNumber -> { + setPullRequestReviewAPIUrl(productLocation, prNumber); + JSONArray reviewJsonArray = null; + try { + reviewJsonArray = (JSONArray) restApiCaller.callApi(getPullRequestReviewAPIUrl(), githubToken, false, true); + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e.getCause()); + System.exit(1); + } + // for reading the output JSON from above and adding the reviewers to the Set + if (reviewJsonArray != null) { + readTheReviewOutJSON(reviewJsonArray, productLocation, prNumber); + } + + }); } } @@ -187,10 +189,11 @@ public void readTheReviewOutJSON(JSONArray reviewJsonArray, String productLocati /** * This method is used for saving the relevant reviewers and commented users to relevant Sets - * @param reviewJsonObject jsonObject received from readTheReviewOutJSON method + * + * @param reviewJsonObject jsonObject received from readTheReviewOutJSON method */ - public void addRelevantUsersToList(JSONObject reviewJsonObject ){ + public void addRelevantUsersToList(JSONObject reviewJsonObject) { if ((reviewJsonObject.get(GITHUB_REVIEW_API_STATE_KEY)).equals(GITHUB_REVIEW_API_APPROVED_KEY)) { JSONObject userJsonObject = (JSONObject) reviewJsonObject.get(GITHUB_REVIEW_API_USER_KEY); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java index 2e83590..994a4a7 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java @@ -69,10 +69,11 @@ public Map> getFilesChanged(String repositoryName, Str RepositoryCommit repositoryCommit = commitService.getCommit(iRepositoryIdProvider, commitHash); List filesChanged = repositoryCommit.getFiles(); // this can be run parallely as patchString of a file will always be in the same index as the file - filesChanged.parallelStream().forEach(commitFile -> { - fileNames.add(commitFile.getFilename()); - patchString.add(commitFile.getPatch()); - }); + filesChanged.parallelStream() + .forEach(commitFile -> { + fileNames.add(commitFile.getFilename()); + patchString.add(commitFile.getPatch()); + }); logger.info("for" + commitHash + " on the " + repositoryName + " repository, files changed and their relevant changed line ranges added to the arraylists successfully"); mapWithFileNamesAndPatches.put("fileNames", fileNames); mapWithFileNamesAndPatches.put("patchString", patchString); From d28a36113a206f9f84cc97bc72ff84aa93f87ee8 Mon Sep 17 00:00:00 2001 From: kasun Date: Tue, 21 Mar 2017 09:59:41 +0530 Subject: [PATCH 28/62] Handle response codes Handle the response code recieved from Graphql API Correct the message thrown in Exception --- .../code/quality/matrices/ChangesFinder.java | 4 +- .../quality/matrices/GraphQlApiCaller.java | 72 ++++++++++--------- .../wso2/code/quality/matrices/MainClass.java | 64 +++++++++-------- .../code/quality/matrices/RestApiCaller.java | 56 +++++++++------ .../quality/matrices/SdkGitHubClient.java | 1 + 5 files changed, 114 insertions(+), 83 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index a3a4382..77eddfa 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -325,7 +325,7 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList commitHashObtainedForPRReview = null; - if (commitsInTheGivenPatch != null) { - commitHashObtainedForPRReview = changesFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); - } - logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); + String gitHubToken = args[2]; + ChangesFinder changesFinder = new ChangesFinder(); + Set commitHashObtainedForPRReview = null; + if (commitsInTheGivenPatch != null) { + commitHashObtainedForPRReview = changesFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); + } + logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); - Reviewer reviewer = new Reviewer(); - if (commitHashObtainedForPRReview != null) { - reviewer.findReviewers(commitHashObtainedForPRReview, gitHubToken, restApiCaller); + Reviewer reviewer = new Reviewer(); + if (commitHashObtainedForPRReview != null) { + reviewer.findReviewers(commitHashObtainedForPRReview, gitHubToken, restApiCaller); + } + } + else{ + logger.error("at least one of the command line arguments are null."); + System.exit(4); } } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java index 80f31fa..f85c3ad 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java @@ -76,33 +76,50 @@ public Object callApi(String URL, String accessToken, boolean requireCommitHeade } httpResponse = httpclient.execute(httpGet); - bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8")); - StringBuilder stringBuilder = new StringBuilder(); - String line; - while ((line = bufferedReader.readLine()) != null) { - stringBuilder.append(line); + int responseCode = httpResponse.getStatusLine().getStatusCode(); // to get the response code + + switch (responseCode) { + case 200: + //success + bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8")); + StringBuilder stringBuilder = new StringBuilder(); + String line; + while ((line = bufferedReader.readLine()) != null) { + stringBuilder.append(line); + } + + // creating a JSON object from the response + String JSONText = stringBuilder.toString(); + Object json = new JSONTokener(JSONText).nextValue(); // gives an object http://stackoverflow.com/questions/14685777/how-to-check-if-response-from-server-is-jsonaobject-or-jsonarray + + if (json instanceof JSONObject) { + JSONObject jsonObject = (JSONObject) json; + returnedObject = jsonObject; + } else if (json instanceof JSONArray) { + JSONArray jsonArray = (JSONArray) json; + returnedObject = jsonArray; + } + logger.info("JSON response is passed after calling the given REST API"); + break; + case 401: + // to handle Response code 401: Unauthorized + throw new CodeQualityMatricesException("Response code 401 : Git hub access token is invalid"); + case 403: + // to handle invalid credentials + throw new CodeQualityMatricesException("Response Code:403 Invalid Credentials, insert a correct token for PMT"); + case 404: + // to handle invalid patch + throw new CodeQualityMatricesException("Response Code 404: Patch not found, enter a valid patch"); + default: + returnedObject = null; } - // creating a JSON object from the response - String JSONText = stringBuilder.toString(); - Object json = new JSONTokener(JSONText).nextValue(); // gives an object http://stackoverflow.com/questions/14685777/how-to-check-if-response-from-server-is-jsonaobject-or-jsonarray - - if (json instanceof JSONObject) { - JSONObject jsonObject = (JSONObject) json; - returnedObject = jsonObject; - } else if (json instanceof JSONArray) { - JSONArray jsonArray = (JSONArray) json; - returnedObject = jsonArray; - } - logger.info("JSON response is passed after calling the given REST API"); - } catch (ClientProtocolException e) { throw new CodeQualityMatricesException("ClientProtocolException when calling the REST API", e); } catch (IOException e) { throw new CodeQualityMatricesException("IOException occurred when calling the REST API", e); } finally { - if (bufferedReader != null) { try { bufferedReader.close(); @@ -110,7 +127,6 @@ public Object callApi(String URL, String accessToken, boolean requireCommitHeade throw new CodeQualityMatricesException("IOException occurred when closing the BufferedReader", e); } } - if (httpResponse != null) { try { httpResponse.close(); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java index 994a4a7..2145a3a 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java @@ -77,6 +77,7 @@ public Map> getFilesChanged(String repositoryName, Str logger.info("for" + commitHash + " on the " + repositoryName + " repository, files changed and their relevant changed line ranges added to the arraylists successfully"); mapWithFileNamesAndPatches.put("fileNames", fileNames); mapWithFileNamesAndPatches.put("patchString", patchString); + logger.info("map with the modified file names with their relevant modified line ranges are saved successfully"); } catch (IOException e) { throw new CodeQualityMatricesException("IO Exception occurred when getting the commit with the given SHA form the given repository ", e); } From 81db43de80ba597a8fe1a2c5c8c0e9a545d8e5b9 Mon Sep 17 00:00:00 2001 From: kasun Date: Tue, 21 Mar 2017 15:12:17 +0530 Subject: [PATCH 29/62] fix getting graphql blame issue --- .../code/quality/matrices/ChangesFinder.java | 71 +++++++++++++------ 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index 77eddfa..ab6a5cd 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -46,7 +46,7 @@ public class ChangesFinder { protected ArrayList patchString = new ArrayList<>(); protected List> lineRangesChanged = new ArrayList>(); // for saving the line no that are changed JSONObject graphqlApiJsonObject = new JSONObject(); - Set commitHashesOfTheParent; + Map> commitHashesMapOfTheParent; Set authorNames = new HashSet(); //as the authors are for all the commits that exists in the relevant patch protected Set commitHashObtainedForPRReview = new HashSet(); // relevant commits in old file that need to find the PR Reviewer private String repoLocation[]; @@ -231,7 +231,7 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin int index = fileNames.indexOf(fileName); // the relevant arraylist of changed lines for that file ArrayList arrayListOfRelevantChangedLines = lineRangesChanged.get(index); - commitHashesOfTheParent = new HashSet<>(); // for storing the parent commit hashes for all the line ranges of the relevant file + commitHashesMapOfTheParent = new HashMap<>(); // for storing the parent commit hashes for all the changed line ranges of the relevant file graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + commitHash + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{history(first: 2) { edges { node { message url } } } author { name email } } } } } } } }"); JSONObject rootJsonObject = null; try { @@ -242,7 +242,7 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin System.exit(1); } // reading the above saved output for the current selected file name - readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, false); + readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, false, null); // parent commit hashes are stored in the arraylist for the given file @@ -259,7 +259,7 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin * @param arrayListOfRelevantChangedLines arraylist containing the changed line ranges of the current selected file * @param gettingPr should be true if running this method for finding the authors of buggy lines which are being fixed from the patch */ - public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList arrayListOfRelevantChangedLines, boolean gettingPr) { + public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList arrayListOfRelevantChangedLines, boolean gettingPr, String oldRange) { //running a iterator for fileName arrayList to get the location of the above saved file JSONObject dataJSONObject = (JSONObject) rootJsonObject.get(GITHUB_GRAPHQL_API_DATA_KEY_STRING); @@ -272,22 +272,24 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList { - int startingLineNo; - int endLineNo; + int startingLineNo = 0; + int endLineNo = 0; String oldFileRange = StringUtils.substringBefore(lineRanges, "/"); String newFileRange = StringUtils.substringAfter(lineRanges, "/"); // need to skip the newly created files from taking the blame as they contain no previous commits if (!oldFileRange.equals("0,0")) { - if (gettingPr) { + if (gettingPr && oldRange.equals(oldFileRange)) { // need to consider the line range in the old file for finding authors and reviewers startingLineNo = Integer.parseInt(StringUtils.substringBefore(oldFileRange, ",")); endLineNo = Integer.parseInt(StringUtils.substringAfter(oldFileRange, ",")); - } else { - // need to consider the line range in the new file resulted from applying the commit for finding parent commits - + } else if (!gettingPr && oldRange == null) { + // need to consider the line range in the new file resulted from applying the commit, for finding parent commits startingLineNo = Integer.parseInt(StringUtils.substringBefore(newFileRange, ",")); endLineNo = Integer.parseInt(StringUtils.substringAfter(newFileRange, ",")); } + else{ + return; // to skip the to the next iteration if oldRange != oldFileRange when finding authornames and commits for obtaining PRs + } // as it is required to create a new Map for finding the recent commit for each line range Map> mapForStoringAgeAndIndex = new HashMap>(); @@ -350,8 +352,12 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList()); + if (!commitHashesMapOfTheParent.get(oldFileRange).contains(commitHash)) { + commitHashesMapOfTheParent.get(oldFileRange).add(commitHash); + } }); logger.info("Parent Commits hashes of the lines which are being fixed by the patch are saved to commitHashesOfTheParent SET successfully "); } @@ -372,20 +378,39 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList arrayListOfRelevantChangedLines, String gitHubToken) { + + for (Map.Entry m : commitHashesMapOfTheParent.entrySet()) { + String oldRange = (String) m.getKey(); + Set commitHashes = (Set) m.getValue(); + commitHashes.parallelStream() + .forEach(parentCommitHashForCallingGraphQl -> { + graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + parentCommitHashForCallingGraphQl + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{ url author { name email } } } } } } } }"); + JSONObject rootJsonObject = null; + try { + rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); + readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, true, oldRange); + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e.getCause()); + System.exit(1); + } + }); + + } + // calling the graphql api to get the blame details of the current file for the parent commits (That is found by filtering in the graqhQL output) //as the order is not important in here parallel streams are used - commitHashesOfTheParent.parallelStream() - .forEach(parentCommitHashForCallingGraphQl -> { - graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + parentCommitHashForCallingGraphQl + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{ url author { name email } } } } } } } }"); - JSONObject rootJsonObject = null; - try { - rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); - readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, true); - } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); - System.exit(1); - } - }); +// commitHashesOfTheParent.parallelStream() +// .forEach(parentCommitHashForCallingGraphQl -> { +// graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + parentCommitHashForCallingGraphQl + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{ url author { name email } } } } } } } }"); +// JSONObject rootJsonObject = null; +// try { +// rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); +// readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, true); +// } catch (CodeQualityMatricesException e) { +// logger.error(e.getMessage(), e.getCause()); +// System.exit(1); +// } +// }); } } From 8622a8279f3778e3e9126658c937e63f6f9c8579 Mon Sep 17 00:00:00 2001 From: kasun Date: Wed, 22 Mar 2017 12:40:33 +0530 Subject: [PATCH 30/62] use stream API in Reviewers.java --- .../code/quality/matrices/ChangesFinder.java | 64 +++++++------------ .../wso2/code/quality/matrices/Reviewer.java | 21 +++--- .../quality/matrices/SdkGitHubClient.java | 11 ++-- 3 files changed, 42 insertions(+), 54 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index ab6a5cd..8bf0441 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -182,7 +182,7 @@ public void saveRelaventEditLineNumbers(ArrayList fileNames, ArrayList { - //@@ -22,7 +22,7 @@ + //@@ -22,7 +22,7 @@ => -22,7 +22,7 => 22,28/22,28 String tempString = lineChanges[j]; String lineRangeInTheOldFileBeingModified = StringUtils.substringBetween(tempString, "-", " +"); // for taking the authors and commit hashes of the previous lines String lineRangeInTheNewFileResultedFromModification = StringUtils.substringAfter(tempString, "+"); // for taking the parent commit @@ -230,23 +230,22 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin .forEach(fileName -> { int index = fileNames.indexOf(fileName); // the relevant arraylist of changed lines for that file - ArrayList arrayListOfRelevantChangedLines = lineRangesChanged.get(index); + ArrayList arrayListOfRelevantChangedLinesOfSelectedFile = lineRangesChanged.get(index); commitHashesMapOfTheParent = new HashMap<>(); // for storing the parent commit hashes for all the changed line ranges of the relevant file graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + commitHash + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{history(first: 2) { edges { node { message url } } } author { name email } } } } } } } }"); JSONObject rootJsonObject = null; try { - // calling the graphql API for getting blame information for the current file and saving it in a location. + // calling the graphql API for getting blame information for the current file. rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); } catch (CodeQualityMatricesException e) { logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside lambda expression System.exit(1); } // reading the above saved output for the current selected file name - readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, false, null); + readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLinesOfSelectedFile, false, null); + logger.info("Parent Commits hashes of the lines which are being fixed by the patch in file " + fileName + " are saved to commitHashesMapOfTheParent map successfully "); - // parent commit hashes are stored in the arraylist for the given file - - iterateOverToFindAuthors(owner, repositoryName, fileName, arrayListOfRelevantChangedLines, gitHubToken); + iterateOverToFindAuthors(owner, repositoryName, fileName, arrayListOfRelevantChangedLinesOfSelectedFile, gitHubToken); logger.info("Authors of the bug lines of code which are being fixed from the given patch are saved successfully to authorNames SET"); }); } @@ -255,11 +254,11 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin * Reading the blame received for a current selected file name and insert the parent commits of the changed lines, * relevant authors and the relevant commits hashes to look for the reviewers of those line ranges * - * @param rootJsonObject JSONObject containing blame information for current selected file - * @param arrayListOfRelevantChangedLines arraylist containing the changed line ranges of the current selected file - * @param gettingPr should be true if running this method for finding the authors of buggy lines which are being fixed from the patch + * @param rootJsonObject JSONObject containing blame information for current selected file + * @param arrayListOfRelevantChangedLinesOfSelectedFile arraylist containing the changed line ranges of the current selected file + * @param gettingPr should be true if running this method for finding the authors of buggy lines which are being fixed from the patch */ - public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList arrayListOfRelevantChangedLines, boolean gettingPr, String oldRange) { + public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList arrayListOfRelevantChangedLinesOfSelectedFile, boolean gettingPr, String oldRange) { //running a iterator for fileName arrayList to get the location of the above saved file JSONObject dataJSONObject = (JSONObject) rootJsonObject.get(GITHUB_GRAPHQL_API_DATA_KEY_STRING); @@ -270,7 +269,7 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList { int startingLineNo = 0; int endLineNo = 0; @@ -286,15 +285,14 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList> mapForStoringAgeAndIndex = new HashMap>(); - //checking line by line by iterating the startinLineNo + //checking line by line by iterating the startingLineNo while (endLineNo >= startingLineNo) { // since the index value is required for later processing, without Java 8 features "for loop" is used for iteration for (int i = 0; i < rangeJSONArray.length(); i++) { @@ -338,7 +336,7 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList> treeMap = new TreeMap<>(mapForStoringAgeAndIndex); int minimumKeyOfMapForStoringAgeAndIndex = treeMap.firstKey(); // getting the minimum key - //getting the relevant JSONObject indexes which consists of the recent commit with in the relevant line range + //getting the relevant JSONObject indexes which consists of the recent change with in the relevant line range ArrayList indexesOfJsonObjectForRecentCommit = mapForStoringAgeAndIndex.get(minimumKeyOfMapForStoringAgeAndIndex); // the order of the indexesOfJsonObjectForRecentCommit is not important as we only need to get the parent commit hashes indexesOfJsonObjectForRecentCommit.parallelStream() @@ -359,7 +357,6 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList arrayListOfRelevantChangedLines, String gitHubToken) { - + public void iterateOverToFindAuthors(String owner, String repositoryName, String fileName, ArrayList arrayListOfRelevantChangedLinesOfSelectedFile, String gitHubToken) { for (Map.Entry m : commitHashesMapOfTheParent.entrySet()) { String oldRange = (String) m.getKey(); @@ -388,29 +384,13 @@ public void iterateOverToFindAuthors(String owner, String repositoryName, String JSONObject rootJsonObject = null; try { rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); - readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, true, oldRange); + readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLinesOfSelectedFile, true, oldRange); } catch (CodeQualityMatricesException e) { logger.error(e.getMessage(), e.getCause()); System.exit(1); } }); - } - - // calling the graphql api to get the blame details of the current file for the parent commits (That is found by filtering in the graqhQL output) - //as the order is not important in here parallel streams are used -// commitHashesOfTheParent.parallelStream() -// .forEach(parentCommitHashForCallingGraphQl -> { -// graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + parentCommitHashForCallingGraphQl + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{ url author { name email } } } } } } } }"); -// JSONObject rootJsonObject = null; -// try { -// rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); -// readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLines, true); -// } catch (CodeQualityMatricesException e) { -// logger.error(e.getMessage(), e.getCause()); -// System.exit(1); -// } -// }); } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java index 8e89fee..c42ea4b 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java @@ -143,9 +143,7 @@ public void saveReviewersToList(String githubToken, RestApiCaller restApiCaller) for (Map.Entry m : mapContainingPRNoAgainstRepoName.entrySet()) { String productLocation = (String) m.getKey(); - Set prNumbers = (Set) m.getValue(); - prNumbers.stream() .forEach(prNumber -> { setPullRequestReviewAPIUrl(productLocation, prNumber); @@ -175,15 +173,22 @@ public void saveReviewersToList(String githubToken, RestApiCaller restApiCaller) public void readTheReviewOutJSON(JSONArray reviewJsonArray, String productLocation, int prNumber) { if (reviewJsonArray.length() != 0) { - for (Object object : reviewJsonArray) { - if (object instanceof JSONObject) { - JSONObject reviewJsonObject = (JSONObject) object; + Pmt.arrayToStream(reviewJsonArray) + .map(JSONObject.class::cast) + .forEach(reviewJsonObject->{ + addRelevantUsersToList(reviewJsonObject); + }); - addRelevantUsersToList(reviewJsonObject); - } - } +// for (Object object : reviewJsonArray) { +// if (object instanceof JSONObject) { +// JSONObject reviewJsonObject = (JSONObject) object; +// +// +// } +// } } else { System.out.println("There are no records of reviews for pull request: " + prNumber + " on " + productLocation + " repository"); + logger.info("There are no records of reviews for pull request: " + prNumber + " on " + productLocation + " repository"); } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java index 2145a3a..6b4469b 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java @@ -68,15 +68,18 @@ public Map> getFilesChanged(String repositoryName, Str IRepositoryIdProvider iRepositoryIdProvider = () -> repositoryName; RepositoryCommit repositoryCommit = commitService.getCommit(iRepositoryIdProvider, commitHash); List filesChanged = repositoryCommit.getFiles(); + ArrayList tempFileNames=new ArrayList<>(); + ArrayList tempPatchString= new ArrayList<>(); + // this can be run parallely as patchString of a file will always be in the same index as the file filesChanged.parallelStream() .forEach(commitFile -> { - fileNames.add(commitFile.getFilename()); - patchString.add(commitFile.getPatch()); + tempFileNames.add(commitFile.getFilename()); + tempPatchString.add(commitFile.getPatch()); }); logger.info("for" + commitHash + " on the " + repositoryName + " repository, files changed and their relevant changed line ranges added to the arraylists successfully"); - mapWithFileNamesAndPatches.put("fileNames", fileNames); - mapWithFileNamesAndPatches.put("patchString", patchString); + mapWithFileNamesAndPatches.put("fileNames", tempFileNames); + mapWithFileNamesAndPatches.put("patchString", tempPatchString); logger.info("map with the modified file names with their relevant modified line ranges are saved successfully"); } catch (IOException e) { throw new CodeQualityMatricesException("IO Exception occurred when getting the commit with the given SHA form the given repository ", e); From ff28d3deb945cdd6a0532be44d42bd5f8460392f Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 24 Mar 2017 10:34:26 +0530 Subject: [PATCH 31/62] changes within the code review --- .../wso2/code/quality/matrices/ChangesFinder.java | 12 ++++++------ .../com/wso2/code/quality/matrices/MainClass.java | 6 ++---- .../java/com/wso2/code/quality/matrices/Pmt.java | 4 ++-- .../wso2/code/quality/matrices/RestApiCaller.java | 2 +- .../wso2/code/quality/matrices/SdkGitHubClient.java | 12 ++++++------ .../src/main/resources/log4j.properties | 2 +- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index 8bf0441..8c04331 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -44,7 +44,7 @@ public class ChangesFinder { private String urlForObtainingCommits; protected ArrayList fileNames = new ArrayList(); protected ArrayList patchString = new ArrayList<>(); - protected List> lineRangesChanged = new ArrayList>(); // for saving the line no that are changed + protected List> changedLineRanges = new ArrayList>(); // for saving the line no that are changed JSONObject graphqlApiJsonObject = new JSONObject(); Map> commitHashesMapOfTheParent; Set authorNames = new HashSet(); //as the authors are for all the commits that exists in the relevant patch @@ -137,10 +137,10 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, IntStream.range(0, repoLocation.length) .filter(i -> StringUtils.contains(repoLocation[i], "wso2/")) .forEach(i -> { - //clearing all the data in the current fileNames and lineRangesChanged arraylists for each repository + //clearing all the data in the current fileNames and changedLineRanges arraylists for each repository //authorNames.clear(); fileNames.clear(); - lineRangesChanged.clear(); + changedLineRanges.clear(); patchString.clear(); Map> mapWithFileNamesAndPatch = null; try { @@ -204,11 +204,11 @@ public void saveRelaventEditLineNumbers(ArrayList fileNames, ArrayList tempArrayList = new ArrayList<>(Arrays.asList(lineChanges)); //adding to the array list which keep track of the line ranges being changed - lineRangesChanged.add(tempArrayList); + changedLineRanges.add(tempArrayList); }); System.out.println("done saving file names and their relevant modification line ranges"); System.out.println(fileNames); - System.out.println(lineRangesChanged + "\n"); + System.out.println(changedLineRanges + "\n"); } /** @@ -230,7 +230,7 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin .forEach(fileName -> { int index = fileNames.indexOf(fileName); // the relevant arraylist of changed lines for that file - ArrayList arrayListOfRelevantChangedLinesOfSelectedFile = lineRangesChanged.get(index); + ArrayList arrayListOfRelevantChangedLinesOfSelectedFile = changedLineRanges.get(index); commitHashesMapOfTheParent = new HashMap<>(); // for storing the parent commit hashes for all the changed line ranges of the relevant file graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + commitHash + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{history(first: 2) { edges { node { message url } } } author { name email } } } } } } } }"); JSONObject rootJsonObject = null; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index cc8f7f6..0ba8f9d 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -32,8 +32,7 @@ public class MainClass { private final static Logger logger = Logger.getLogger(MainClass.class); public static void main(String[] args) { - logger.info(" Main method got executed"); - if (args.length==3) { + if (args.length == 3) { String pmtToken = args[0]; String patchId = args[1]; @@ -69,8 +68,7 @@ public static void main(String[] args) { if (commitHashObtainedForPRReview != null) { reviewer.findReviewers(commitHashObtainedForPRReview, gitHubToken, restApiCaller); } - } - else{ + } else { logger.error("at least one of the command line arguments are null."); System.exit(4); } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java index 5b7b482..acbb3a2 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java @@ -63,13 +63,13 @@ public String[] getPublicGitCommitHashes(JSONArray jsonArray) { .forEach(System.out::println); System.out.println(); - //to prevent from internaal representation by returning referecnce to mutable object + //to prevent from internal representation by returning referecnce to mutable object String clonedPatchInformation_svnRevisionpublic[] = patchInformation_svnRevisionpublic.clone(); return clonedPatchInformation_svnRevisionpublic; } /** - * This method returns the commit hashes belongs to the given patch in as a list of Strings + * This returns the commit hashes belongs to the given patch in as a list of Strings. * * @param array jsonarray containing the output received from WSO2 PMT for the given patch * @return a List containing the commit hashes that belongs to the given patch diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java index f85c3ad..98408ce 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java @@ -103,7 +103,7 @@ public Object callApi(String URL, String accessToken, boolean requireCommitHeade break; case 401: // to handle Response code 401: Unauthorized - throw new CodeQualityMatricesException("Response code 401 : Git hub access token is invalid"); + throw new CodeQualityMatricesException("Response code 401 : Github access token is invalid"); case 403: // to handle invalid credentials throw new CodeQualityMatricesException("Response Code:403 Invalid Credentials, insert a correct token for PMT"); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java index 6b4469b..1bea347 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java @@ -63,13 +63,13 @@ public class SdkGitHubClient { * @return a map containg arraylist of file changed and their relevant patch */ public Map> getFilesChanged(String repositoryName, String commitHash) throws CodeQualityMatricesException { - Map> mapWithFileNamesAndPatches = new HashMap<>(); + Map> fileNamesAndPatches = new HashMap<>(); try { IRepositoryIdProvider iRepositoryIdProvider = () -> repositoryName; RepositoryCommit repositoryCommit = commitService.getCommit(iRepositoryIdProvider, commitHash); List filesChanged = repositoryCommit.getFiles(); - ArrayList tempFileNames=new ArrayList<>(); - ArrayList tempPatchString= new ArrayList<>(); + ArrayList tempFileNames = new ArrayList<>(); + ArrayList tempPatchString = new ArrayList<>(); // this can be run parallely as patchString of a file will always be in the same index as the file filesChanged.parallelStream() @@ -78,12 +78,12 @@ public Map> getFilesChanged(String repositoryName, Str tempPatchString.add(commitFile.getPatch()); }); logger.info("for" + commitHash + " on the " + repositoryName + " repository, files changed and their relevant changed line ranges added to the arraylists successfully"); - mapWithFileNamesAndPatches.put("fileNames", tempFileNames); - mapWithFileNamesAndPatches.put("patchString", tempPatchString); + fileNamesAndPatches.put("fileNames", tempFileNames); + fileNamesAndPatches.put("patchString", tempPatchString); logger.info("map with the modified file names with their relevant modified line ranges are saved successfully"); } catch (IOException e) { throw new CodeQualityMatricesException("IO Exception occurred when getting the commit with the given SHA form the given repository ", e); } - return mapWithFileNamesAndPatches; + return fileNamesAndPatches; } } diff --git a/CodeQualityMatricesProject/src/main/resources/log4j.properties b/CodeQualityMatricesProject/src/main/resources/log4j.properties index c969242..4be4e60 100644 --- a/CodeQualityMatricesProject/src/main/resources/log4j.properties +++ b/CodeQualityMatricesProject/src/main/resources/log4j.properties @@ -17,7 +17,7 @@ # # Define the root logger with appender file logs=/home/kasun/Documents/log4j -log4j.rootLogger=DEBUG, APPENDER1 +log4j.rootLogger=INFO, APPENDER1 #Define the file appender log4j.appender.APPENDER1=org.apache.log4j.RollingFileAppender log4j.appender.APPENDER1.File=${logs}/log.out From b218275e58d27e61d0e7a563fb930858414a4c3c Mon Sep 17 00:00:00 2001 From: kasun Date: Mon, 27 Mar 2017 13:08:11 +0530 Subject: [PATCH 32/62] Seperate PMT communication to a seperate class --- .../code/quality/matrices/PmtApiCaller.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java new file mode 100644 index 0000000..47144e7 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices; + +import org.apache.http.client.methods.HttpGet; + +public class PmtApiCaller { + public PmtApiCaller() { + + } + + /** + * @param accessToken + * @param patchId + * @return + * @throws CodeQualityMatricesException + */ + public String callApi(String accessToken, String patchId) throws CodeQualityMatricesException { + String pmtUrl = "http://umt.private.wso2.com:9765/codequalitymatricesapi/1.0.0//properties?path=/_system/governance/patchs/" + patchId; + HttpGet httpGet; + try { + httpGet = new HttpGet(pmtUrl); + httpGet.addHeader("Authorization", "Bearer " + accessToken); + + } catch (IllegalArgumentException e) { + throw new CodeQualityMatricesException("The url provided for accessing the PMT API is invalid ", e); + } + + return ApiUtility.callApi(httpGet); + } +} From b43ea6eb8f7bdbe54578b24673cf7dac600ef70f Mon Sep 17 00:00:00 2001 From: kasun Date: Mon, 27 Mar 2017 13:08:28 +0530 Subject: [PATCH 33/62] Seperate Github communication to a seperate class --- .../quality/matrices/GithubApiCaller.java | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java new file mode 100644 index 0000000..d15678c --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices; + +import org.apache.http.client.methods.HttpGet; + +/** + * This is used for all github communications + */ +public class GithubApiCaller { + private HttpGet httpGet; + + /** + * @param commitHash + * @param accessToken + * @throws CodeQualityMatricesException + */ + public String callSearchCommitApi(String commitHash, String accessToken) throws CodeQualityMatricesException { + String url = "https://api.github.com/search/commits?q=hash%3A" + commitHash; + try { + httpGet = new HttpGet(url); + httpGet.addHeader("Authorization", "Bearer " + accessToken); + //as the accept header is needed for accessing commit search API which is still in preview mode + httpGet.addHeader("Accept", "application/vnd.github.cloak-preview"); + } catch (IllegalArgumentException e) { + throw new CodeQualityMatricesException("The url provided for accessing the Github Search Commit API is " + + "invalid ", e); + } + return ApiUtility.callApi(httpGet); + } + + /** + * @param repoLocation + * @param pullRequestNumber + * @param accessToken + * @throws CodeQualityMatricesException + */ + public String callReviewApi(String repoLocation, String pullRequestNumber, String accessToken) throws + CodeQualityMatricesException { + String url = "https://api.github.com/repos/" + repoLocation + "/pulls/" + pullRequestNumber + "/reviews"; + try { + httpGet = new HttpGet(url); + httpGet.addHeader("Accept", "application/vnd.github.black-cat-preview+json"); + httpGet.addHeader("Authorization", "Bearer " + accessToken); + } catch (IllegalArgumentException e) { + throw new CodeQualityMatricesException("The url provided for accessing the Github Review Commit API is " + + "invalid ", e); + } + return ApiUtility.callApi(httpGet); + } + + /** + * @param commitHashToBeSearched + * @param accessToken + * @throws CodeQualityMatricesException + */ + public String callSearchIssueApi(String commitHashToBeSearched, String accessToken) throws + CodeQualityMatricesException { + String url = "https://api.github.com/search/issues?q=" + commitHashToBeSearched; + try { + httpGet = new HttpGet(url); + httpGet.addHeader("Accept", "application/vnd.github.mercy-preview+json"); + httpGet.addHeader("Authorization", "Bearer " + accessToken); + } catch (IllegalArgumentException e) { + throw new CodeQualityMatricesException("The url provided for accessing the Github Search Issue API is " + + "invalid ", e); + } + return ApiUtility.callApi(httpGet); + } +} + From 42aa0553ddaf09035638d6c72ff741efcf3fc541 Mon Sep 17 00:00:00 2001 From: kasun Date: Mon, 27 Mar 2017 13:09:15 +0530 Subject: [PATCH 34/62] Add a utility class --- .../code/quality/matrices/ApiUtility.java | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java new file mode 100644 index 0000000..dbd3306 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices; + +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.log4j.Logger; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/** + * This is a utility class for calling APIs + */ +public final class ApiUtility { + // to prevent instantiation + private ApiUtility() { + + } + + private static Logger logger = Logger.getLogger(ApiUtility.class); + + public static String callApi(HttpGet httpGet) throws CodeQualityMatricesException { + BufferedReader bufferedReader = null; + CloseableHttpClient httpClient = null; + CloseableHttpResponse httpResponse = null; + httpClient = HttpClients.createDefault(); + String JSONText = null; + + try { + httpResponse = httpClient.execute(httpGet); + int responseCode = httpResponse.getStatusLine().getStatusCode(); + + if (responseCode == 200) { + //success + bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), + "UTF-8")); + StringBuilder stringBuilder = new StringBuilder(); + String line; + while ((line = bufferedReader.readLine()) != null) { + stringBuilder.append(line); + } + // creating a JSON object from the response + JSONText = stringBuilder.toString(); + + + } else { + throw new CodeQualityMatricesException("Error occurred while calling the API, the reponse code is " + + responseCode); + } + } catch (ClientProtocolException e) { + throw new CodeQualityMatricesException("ClientProtocolException when calling the REST API", e); + } catch (IOException e) { + throw new CodeQualityMatricesException("IOException occurred when calling the REST API", e); + } finally { + if (bufferedReader != null) { + try { + bufferedReader.close(); + } catch (IOException e) { + logger.error("IOException occurred when closing the BufferedReader", e); + } + } + if (httpResponse != null) { + try { + httpResponse.close(); + } catch (IOException e) { + logger.error("IOException occurred when closing the HttpResponse", e); + } + } + if (httpClient != null) { + try { + httpClient.close(); + } catch (IOException e) { + logger.error("IOException occurred when closing the HttpClient", e); + } + } + } + return JSONText; + } +} From 991b90258bfac481ab1992998a42b6982009e0b3 Mon Sep 17 00:00:00 2001 From: kasun Date: Mon, 27 Mar 2017 16:55:01 +0530 Subject: [PATCH 35/62] Use Gson for PMT response processing --- CodeQualityMatricesProject/pom.xml | 5 + .../code/quality/matrices/ApiUtility.java | 6 +- .../code/quality/matrices/ChangesFinder.java | 161 ++++++++++-------- .../quality/matrices/CodeQualityMatrices.java | 103 +++++++++++ .../wso2/code/quality/matrices/MainClass.java | 102 +++++++---- .../code/quality/matrices/RestApiCaller.java | 4 +- 6 files changed, 270 insertions(+), 111 deletions(-) create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java diff --git a/CodeQualityMatricesProject/pom.xml b/CodeQualityMatricesProject/pom.xml index 790c5f0..d50020b 100644 --- a/CodeQualityMatricesProject/pom.xml +++ b/CodeQualityMatricesProject/pom.xml @@ -51,6 +51,11 @@ json 20160810 + + com.google.code.gson + gson + 2.8.0 + org.eclipse.mylyn.github org.eclipse.egit.github.core diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java index dbd3306..33f588a 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java @@ -45,7 +45,7 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio CloseableHttpClient httpClient = null; CloseableHttpResponse httpResponse = null; httpClient = HttpClients.createDefault(); - String JSONText = null; + String jsonText = null; try { httpResponse = httpClient.execute(httpGet); @@ -61,7 +61,7 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio stringBuilder.append(line); } // creating a JSON object from the response - JSONText = stringBuilder.toString(); + jsonText = stringBuilder.toString(); } else { @@ -95,6 +95,6 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio } } } - return JSONText; + return jsonText; } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index 8c04331..d5ffc68 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -46,7 +46,7 @@ public class ChangesFinder { protected ArrayList patchString = new ArrayList<>(); protected List> changedLineRanges = new ArrayList>(); // for saving the line no that are changed JSONObject graphqlApiJsonObject = new JSONObject(); - Map> commitHashesMapOfTheParent; + Map> commitHashesOfParent; Set authorNames = new HashSet(); //as the authors are for all the commits that exists in the relevant patch protected Set commitHashObtainedForPRReview = new HashSet(); // relevant commits in old file that need to find the PR Reviewer private String repoLocation[]; @@ -54,24 +54,23 @@ public class ChangesFinder { private static final Logger logger = Logger.getLogger(ChangesFinder.class); // constants for accessing the Github API responses - private static final String GITHUB_SEARCH_API_ITEMS_KEY_STRING = "items"; - private static final String GITHUB_SEARCH_API_REPOSITORY_KEY_STRING = "repository"; - private static final String GITHUB_SEARCH_API_FULL_NAME_OF_REPOSITORY_KEY_STRING = "full_name"; - private static final String GITHUB_GRAPHQL_API_STARTING_LINE_KEY_STRING = "startingLine"; - private static final String GITHUB_GRAPHQL_API_ENDING_LINE_KEY_STRING = "endingLine"; - private static final String GITHUB_GRAPHQL_API_AGE_KEY_STRING = "age"; - private static final String GITHUB_GRAPHQL_API_DATA_KEY_STRING = "data"; - private static final String GITHUB_GRAPHQL_API_REPOSITORY_KEY_STRING = "repository"; - private static final String GITHUB_GRAPHQL_API_OBJECT_KEY_STRING = "object"; - private static final String GITHUB_GRAPHQL_API_BLAME_KEY_STRING = "blame"; - private static final String GITHUB_GRAPHQL_API_RANGES_KEY_STRING = "ranges"; - private static final String GITHUB_GRAPHQL_API_COMMIT_KEY_STRING = "commit"; - private static final String GITHUB_GRAPHQL_API_AUTHOR_KEY_STRING = "author"; - private static final String GITHUB_GRAPHQL_API_NAME_KEY_STRING = "name"; - private static final String GITHUB_GRAPHQL_API_URL_KEY_STRING = "url"; - private static final String GITHUB_GRAPHQL_API_HISTORY_KEY_STRING = "history"; - private static final String GITHUB_GRAPHQL_API_EDGE_KEY_STRING = "edges"; - private static final String GITHUB_GRAPHQL_API_NODE_KEY_STRING = "node"; + private static final String GITHUB_API_ITEMS = "items"; + private static final String GITHUB_API_REPOSITORY = "repository"; + private static final String GITHUB_API_FULL_NAME_OF_REPOSITORY = "full_name"; + private static final String GITHUB_API_STARTING_LINE = "startingLine"; + private static final String GITHUB_API_ENDING_LINE = "endingLine"; + private static final String GITHUB_API_AGE = "age"; + private static final String GITHUB_API_DATA = "data"; + private static final String GITHUB_API_OBJECT = "object"; + private static final String GITHUB_API_BLAME = "blame"; + private static final String GITHUB_API_RANGES = "ranges"; + private static final String GITHUB_API_COMMIT = "commit"; + private static final String GITHUB_API_AUTHOR = "author"; + private static final String GITHUB_API_NAME = "name"; + private static final String GITHUB_API_URL = "url"; + private static final String GITHUB_API_HISTORY = "history"; + private static final String GITHUB_API_EDGE = "edges"; + private static final String GITHUB_API_NODE = "node"; public String getUrlForSearchingCommits() { @@ -82,34 +81,58 @@ public void setUrlForSearchingCommits(String commitHash) { this.urlForObtainingCommits = "https://api.github.com/search/commits?q=hash%3A" + commitHash; } - /** - * This method is used for obtaining the repositories that contain the relevant commits belongs to the given patch - * - * @param gitHubToken Github token - * @param commitsInTheGivenPatch Commits that belongs to the given patch - * @param restApiCaller Instance of the RestApiCaller class for accessing the REST APIs - * @return a Set containing the commit hashes that needs to be checked for reviewers - */ - public Set obtainRepoNamesForCommitHashes(String gitHubToken, String[] commitsInTheGivenPatch, RestApiCaller restApiCaller) { - - //calling the API calling method - IntStream.range(0, commitsInTheGivenPatch.length) - .mapToObj(i -> commitsInTheGivenPatch[i]) - .forEach(commitHash -> { - setUrlForSearchingCommits(commitHash); - JSONObject jsonObject = null; - try { - jsonObject = (JSONObject) restApiCaller.callApi(getUrlForSearchingCommits(), gitHubToken, true, false); - } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); - System.exit(1); - } - saveRepoNamesInAnArray(jsonObject, commitHash, gitHubToken); - }); + public Set obtainRepoNamesForCommitHashes(String gitHubToken, List commitHashes) { + GithubApiCaller githubApiCaller = new GithubApiCaller(); + + commitHashes.forEach(commitHash -> { + try { + String jsonText = githubApiCaller.callSearchCommitApi(commitHash, gitHubToken); + saveRepoNamesInAnArray(jsonText, commitHash, gitHubToken); + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e.getCause()); + } + + }); return commitHashObtainedForPRReview; } +//================================================================================ +// /** +// * This method is used for obtaining the repositories that contain the relevant commits belongs to the given patch +// * +// * @param gitHubToken Github token +// * @param commitsInTheGivenPatch Commits that belongs to the given patch +// * @param restApiCaller Instance of the RestApiCaller class for accessing the REST APIs +// * @return a Set containing the commit hashes that needs to be checked for reviewers +// */ +// public Set obtainRepoNamesForCommitHashes(String gitHubToken, String[] commitsInTheGivenPatch, RestApiCaller restApiCaller) { +// +// //calling the API calling method +// IntStream.range(0, commitsInTheGivenPatch.length) +// .mapToObj(i -> commitsInTheGivenPatch[i]) +// .forEach(commitHash -> { +// setUrlForSearchingCommits(commitHash); +// JSONObject jsonObject = null; +// try { +// jsonObject = (JSONObject) restApiCaller.callApi(getUrlForSearchingCommits(), gitHubToken, true, false); +// } catch (CodeQualityMatricesException e) { +// logger.error(e.getMessage(), e.getCause()); +// System.exit(1); +// } +// +// saveRepoNamesInAnArray(jsonObject, commitHash, gitHubToken); +// }); +// return commitHashObtainedForPRReview; +// } + //============================================ + + public void saveRepoNamesInAnArray(String jsonText, String commitHash, String gitHubToken) { + + } + + + /** * saving the Repo Names in the array and calling to Get files content * @@ -119,15 +142,15 @@ public Set obtainRepoNamesForCommitHashes(String gitHubToken, String[] commitsIn */ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, String gitHubToken) { - JSONArray jsonArrayOfItems = (JSONArray) rootJsonObject.get(GITHUB_SEARCH_API_ITEMS_KEY_STRING); + JSONArray jsonArrayOfItems = (JSONArray) rootJsonObject.get(GITHUB_API_ITEMS); // setting the size of the repoLocationArray repoLocation = new String[jsonArrayOfItems.length()]; //adding the repo name to the array IntStream.range(0, jsonArrayOfItems.length()) .forEach(i -> { JSONObject jsonObject = (JSONObject) jsonArrayOfItems.get(i); - JSONObject repositoryJsonObject = (JSONObject) jsonObject.get(GITHUB_SEARCH_API_REPOSITORY_KEY_STRING); - repoLocation[i] = (String) repositoryJsonObject.get(GITHUB_SEARCH_API_FULL_NAME_OF_REPOSITORY_KEY_STRING); + JSONObject repositoryJsonObject = (JSONObject) jsonObject.get(GITHUB_API_REPOSITORY); + repoLocation[i] = (String) repositoryJsonObject.get(GITHUB_API_FULL_NAME_OF_REPOSITORY); }); logger.info("Repo names having the given commit are successfully saved in an array"); @@ -231,7 +254,7 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin int index = fileNames.indexOf(fileName); // the relevant arraylist of changed lines for that file ArrayList arrayListOfRelevantChangedLinesOfSelectedFile = changedLineRanges.get(index); - commitHashesMapOfTheParent = new HashMap<>(); // for storing the parent commit hashes for all the changed line ranges of the relevant file + commitHashesOfParent = new HashMap<>(); // for storing the parent commit hashes for all the changed line ranges of the relevant file graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + commitHash + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{history(first: 2) { edges { node { message url } } } author { name email } } } } } } } }"); JSONObject rootJsonObject = null; try { @@ -243,7 +266,7 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin } // reading the above saved output for the current selected file name readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLinesOfSelectedFile, false, null); - logger.info("Parent Commits hashes of the lines which are being fixed by the patch in file " + fileName + " are saved to commitHashesMapOfTheParent map successfully "); + logger.info("Parent Commits hashes of the lines which are being fixed by the patch in file " + fileName + " are saved to commitHashesOfParent map successfully "); iterateOverToFindAuthors(owner, repositoryName, fileName, arrayListOfRelevantChangedLinesOfSelectedFile, gitHubToken); logger.info("Authors of the bug lines of code which are being fixed from the given patch are saved successfully to authorNames SET"); @@ -261,11 +284,11 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList arrayListOfRelevantChangedLinesOfSelectedFile, boolean gettingPr, String oldRange) { //running a iterator for fileName arrayList to get the location of the above saved file - JSONObject dataJSONObject = (JSONObject) rootJsonObject.get(GITHUB_GRAPHQL_API_DATA_KEY_STRING); - JSONObject repositoryJSONObect = (JSONObject) dataJSONObject.get(GITHUB_GRAPHQL_API_REPOSITORY_KEY_STRING); - JSONObject objectJSONObject = (JSONObject) repositoryJSONObect.get(GITHUB_GRAPHQL_API_OBJECT_KEY_STRING); - JSONObject blameJSONObject = (JSONObject) objectJSONObject.get(GITHUB_GRAPHQL_API_BLAME_KEY_STRING); - JSONArray rangeJSONArray = (JSONArray) blameJSONObject.get(GITHUB_GRAPHQL_API_RANGES_KEY_STRING); + JSONObject dataJSONObject = (JSONObject) rootJsonObject.get(GITHUB_API_DATA); + JSONObject repositoryJSONObect = (JSONObject) dataJSONObject.get(GITHUB_API_REPOSITORY); + JSONObject objectJSONObject = (JSONObject) repositoryJSONObect.get(GITHUB_API_OBJECT); + JSONObject blameJSONObject = (JSONObject) objectJSONObject.get(GITHUB_API_BLAME); + JSONArray rangeJSONArray = (JSONArray) blameJSONObject.get(GITHUB_API_RANGES); //getting the starting line no of the range of lines that are modified from the patch // parallel streams are not used in here as the order of the arraylist is important in the process @@ -297,14 +320,14 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList= startingLineNo)) { // so the relevant startingLineNo belongs in this line range in other words in this JSONObject if (!gettingPr) { - int age = (int) rangeJSONObject.get(GITHUB_GRAPHQL_API_AGE_KEY_STRING); + int age = (int) rangeJSONObject.get(GITHUB_API_AGE); // storing the age field with relevant index of the JSONObject mapForStoringAgeAndIndex.putIfAbsent(age, new ArrayList()); if (!mapForStoringAgeAndIndex.get(age).contains(i)) { @@ -313,13 +336,13 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList { JSONObject rangeJSONObject = (JSONObject) rangeJSONArray.get(index); - JSONObject commitJSONObject = (JSONObject) rangeJSONObject.get(GITHUB_GRAPHQL_API_COMMIT_KEY_STRING); - JSONObject historyJSONObject = (JSONObject) commitJSONObject.get(GITHUB_GRAPHQL_API_HISTORY_KEY_STRING); - JSONArray edgesJSONArray = (JSONArray) historyJSONObject.get(GITHUB_GRAPHQL_API_EDGE_KEY_STRING); + JSONObject commitJSONObject = (JSONObject) rangeJSONObject.get(GITHUB_API_COMMIT); + JSONObject historyJSONObject = (JSONObject) commitJSONObject.get(GITHUB_API_HISTORY); + JSONArray edgesJSONArray = (JSONArray) historyJSONObject.get(GITHUB_API_EDGE); //getting the second json object from the array as it contain the commit of the parent which modified the above line range JSONObject edgeJSONObject = (JSONObject) edgesJSONArray.get(1); - JSONObject nodeJSONObject = (JSONObject) edgeJSONObject.get(GITHUB_GRAPHQL_API_NODE_KEY_STRING); - String urlOfTheParentCommit = (String) nodeJSONObject.get(GITHUB_GRAPHQL_API_URL_KEY_STRING); // this contain the URL of the parent commit + JSONObject nodeJSONObject = (JSONObject) edgeJSONObject.get(GITHUB_API_NODE); + String urlOfTheParentCommit = (String) nodeJSONObject.get(GITHUB_API_URL); // this contain the URL of the parent commit String commitHash = (String) StringUtils.substringAfter(urlOfTheParentCommit, "commit/"); // commitHashesOfTheParent.add(commitHash); // commitHashesof the parent for the selected file - commitHashesMapOfTheParent.putIfAbsent(oldFileRange, new HashSet()); - if (!commitHashesMapOfTheParent.get(oldFileRange).contains(commitHash)) { - commitHashesMapOfTheParent.get(oldFileRange).add(commitHash); + commitHashesOfParent.putIfAbsent(oldFileRange, new HashSet()); + if (!commitHashesOfParent.get(oldFileRange).contains(commitHash)) { + commitHashesOfParent.get(oldFileRange).add(commitHash); } }); } @@ -375,7 +398,7 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList arrayListOfRelevantChangedLinesOfSelectedFile, String gitHubToken) { - for (Map.Entry m : commitHashesMapOfTheParent.entrySet()) { + for (Map.Entry m : commitHashesOfParent.entrySet()) { String oldRange = (String) m.getKey(); Set commitHashes = (Set) m.getValue(); commitHashes.parallelStream() diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java new file mode 100644 index 0000000..338d5a3 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices; + +import com.google.gson.Gson; +import org.apache.log4j.Logger; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * + */ +public class CodeQualityMatrices { + private String pmtToken; + private String patchId; + private String gitHubToken; + private static final String COMMITS_INSIDE_GIVEN_PATCH = "patchInformation_svnRevisionpublic"; + private final static Logger logger = Logger.getLogger(CodeQualityMatrices.class); + + /** + * @param pmtToken + * @param patchId + * @param gitHubToken + */ + public CodeQualityMatrices(String pmtToken, String patchId, String gitHubToken) { + this.pmtToken = pmtToken; + this.patchId = patchId; + this.gitHubToken = gitHubToken; + + } + + /** + * + */ + public void execute() { + try { + ChangesFinder changesFinder= new ChangesFinder(); + List commitHashes = findCommitHashesInPatch(); + changesFinder.obtainRepoNamesForCommitHashes(gitHubToken,commitHashes); + + + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e); + + } + System.out.println(); + + + } + + /** + * + */ + public List findCommitHashesInPatch() throws CodeQualityMatricesException { + PmtApiCaller pmtApiCaller = new PmtApiCaller(); + String jsonText = null; + List commitHashes = new ArrayList<>(); + + try { + jsonText = pmtApiCaller.callApi(pmtToken, patchId); + } catch (CodeQualityMatricesException e) { + throw new CodeQualityMatricesException("Error occurred while calling PMT API", e); + } + + Gson gson = new Gson(); + + if (jsonText != null) { + List pmtResponse = gson.fromJson(jsonText, List.class); + for (Object pmtEntry : pmtResponse) { + if (pmtEntry instanceof Map) { + Map> entryMap = (Map>) pmtEntry; + if (COMMITS_INSIDE_GIVEN_PATCH.equals(entryMap.get("name"))) { + commitHashes = entryMap.get("value"); + } + } + } + System.out.println("The commit hashes are: "); + System.out.println(commitHashes); + } else { + throw new CodeQualityMatricesException("The returned jsonText from PMT API is null"); + } + + return commitHashes; + } +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index 0ba8f9d..aae1dbc 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -19,9 +19,6 @@ package com.wso2.code.quality.matrices; import org.apache.log4j.Logger; -import org.json.JSONArray; - -import java.util.Set; /** * This is the class having the main method of this application @@ -30,47 +27,78 @@ */ public class MainClass { private final static Logger logger = Logger.getLogger(MainClass.class); + public static final String COMMITS_INSIDE_GIVEN_PATCH = "patchInformation_svnRevisionpublic"; public static void main(String[] args) { if (args.length == 3) { String pmtToken = args[0]; String patchId = args[1]; + String gitHubToken = args[2]; - String pmtUrl = "http://umt.private.wso2.com:9765/codequalitymatricesapi/1.0.0//properties?path=/_system/governance/patchs/" + patchId; - - RestApiCaller restApiCaller = new RestApiCaller(); - JSONArray jsonArray = null; - try { - jsonArray = (JSONArray) restApiCaller.callApi(pmtUrl, pmtToken, false, false); - } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); - System.exit(1); - } - logger.info("JSON response is received successfully from WSO2 PMT for the given patch " + args[1]); - - Pmt pmt = new Pmt(); - String[] commitsInTheGivenPatch = null; - if (jsonArray != null) { - commitsInTheGivenPatch = pmt.getPublicGitCommitHashes(jsonArray); - } - logger.info("Commits received from WSO2 PMT are saved in an array successfully"); + CodeQualityMatrices codeQualityMatrices= new CodeQualityMatrices(pmtToken,patchId,gitHubToken); + codeQualityMatrices.execute(); - String gitHubToken = args[2]; - ChangesFinder changesFinder = new ChangesFinder(); - Set commitHashObtainedForPRReview = null; - if (commitsInTheGivenPatch != null) { - commitHashObtainedForPRReview = changesFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); - } - logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); +// PmtApiCaller pmtApiCaller = new PmtApiCaller(); +// String jsonText = null; +// List commitHashes= new ArrayList<>(); +// +// try { +// jsonText = pmtApiCaller.callApi(pmtToken, patchId); +// } catch (CodeQualityMatricesException e) { +// logger.error("Error occurred while calling PMT API", e); +// } +// +// Gson gson = new Gson(); +// +// if (jsonText != null) { +// List pmtResponse = gson.fromJson(jsonText, List.class); +// for(Object pmtEntry : pmtResponse){ +// if(pmtEntry instanceof Map){ +// Map> entryMap= (Map>)pmtEntry; +// if(COMMITS_INSIDE_GIVEN_PATCH.equals(entryMap.get("name"))){ +// commitHashes=entryMap.get("values"); +// +// +// } +// +// } +// } +// } - Reviewer reviewer = new Reviewer(); - if (commitHashObtainedForPRReview != null) { - reviewer.findReviewers(commitHashObtainedForPRReview, gitHubToken, restApiCaller); - } - } else { - logger.error("at least one of the command line arguments are null."); - System.exit(4); - } - } +// String pmtUrl = "fda"; +// RestApiCaller restApiCaller = new RestApiCaller(); +// JSONArray jsonArray = null; +// try { +// jsonArray = (JSONArray) restApiCaller.callApi(pmtUrl, pmtToken, false, false); +// } catch (CodeQualityMatricesException e) { +// logger.error(e.getMessage(), e.getCause()); +// System.exit(1); +// } +// logger.info("JSON response is received successfully from WSO2 PMT for the given patch " + args[1]); +// +// Pmt pmt = new Pmt(); +// String[] commitsInTheGivenPatch = null; +// if (jsonArray != null) { +// commitsInTheGivenPatch = pmt.getPublicGitCommitHashes(jsonArray); +// } +// logger.info("Commits received from WSO2 PMT are saved in an array successfully"); +// +// +// ChangesFinder changesFinder = new ChangesFinder(); +// Set commitHashObtainedForPRReview = null; +// if (commitsInTheGivenPatch != null) { +// commitHashObtainedForPRReview = changesFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); +// } +// logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); +// +// Reviewer reviewer = new Reviewer(); +// if (commitHashObtainedForPRReview != null) { +// reviewer.findReviewers(commitHashObtainedForPRReview, gitHubToken, restApiCaller); +// } +// } else { +// logger.error("at least one of the command line arguments are null."); +// System.exit(4); +// } + }} } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java index 98408ce..0e2a8ef 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java @@ -33,7 +33,7 @@ import java.io.InputStreamReader; /** - * This class is used to call the REST API of both WSO2 PMT and github.com + * This class is used to callApi the REST API of both WSO2 PMT and github.com */ public class RestApiCaller { @@ -62,7 +62,7 @@ public Object callApi(String URL, String accessToken, boolean requireCommitHeade if (accessToken != null) { - httpGet.addHeader("Authorization", "Bearer " + accessToken); // passing the accessToken for the API call + httpGet.addHeader("Authorization", "Bearer " + accessToken); // passing the accessToken for the API callApi } //as the accept header is needed for the review API since it is still in preview mode From 13084072835f60f1dcea3d4a934d631fbacc4606 Mon Sep 17 00:00:00 2001 From: kasun Date: Mon, 27 Mar 2017 18:50:26 +0530 Subject: [PATCH 36/62] Use Gson for processing Github Search commit API response --- .../code/quality/matrices/ChangesFinder.java | 60 ++++++++++++----- .../wso2/code/quality/matrices/MainClass.java | 2 +- .../wso2/code/quality/matrices/Reviewer.java | 10 +-- .../quality/matrices/SdkGitHubClient.java | 11 ++-- .../quality/matrices/SearchCommitPojo.java | 65 +++++++++++++++++++ 5 files changed, 121 insertions(+), 27 deletions(-) create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SearchCommitPojo.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index d5ffc68..551d997 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -18,6 +18,7 @@ package com.wso2.code.quality.matrices; +import com.google.gson.Gson; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.json.JSONArray; @@ -55,7 +56,7 @@ public class ChangesFinder { private static final Logger logger = Logger.getLogger(ChangesFinder.class); // constants for accessing the Github API responses private static final String GITHUB_API_ITEMS = "items"; - private static final String GITHUB_API_REPOSITORY = "repository"; + private static final String GITHUB_API_REPOSITORY = "Repository"; private static final String GITHUB_API_FULL_NAME_OF_REPOSITORY = "full_name"; private static final String GITHUB_API_STARTING_LINE = "startingLine"; private static final String GITHUB_API_ENDING_LINE = "endingLine"; @@ -128,9 +129,39 @@ public Set obtainRepoNamesForCommitHashes(String gitHubToken, List commi //============================================ public void saveRepoNamesInAnArray(String jsonText, String commitHash, String gitHubToken) { + List repoLocation = new ArrayList<>(); + Gson gson = new Gson(); + SearchCommitPojo searchCommitPojo = gson.fromJson(jsonText, SearchCommitPojo.class); + searchCommitPojo.getItems().forEach(recordItem -> { + repoLocation.add(recordItem.getRepository().getFull_name()); - } + }); + logger.info("Repo names having the given commit are successfully saved in an array"); + SdkGitHubClient sdkGitHubClient = new SdkGitHubClient(gitHubToken); + repoLocation.stream() + .filter(repositoryName -> StringUtils.contains(repositoryName, "wso2/")) + .forEach(repositoryName -> { + //clearing all the data in the current fileNames and changedLineRanges arraylists for each Repository + //authorNames.clear(); + fileNames.clear(); + changedLineRanges.clear(); + patchString.clear(); + Map> fileNamesAndPatches = null; + try { + fileNamesAndPatches = sdkGitHubClient.getFilesChanged(repositoryName, commitHash); + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside a lambda expression + } + fileNames = fileNamesAndPatches.get("fileNames"); + patchString = fileNamesAndPatches.get("patchString"); + saveRelaventEditLineNumbers(fileNames, patchString); + + + }); + + + } /** @@ -160,7 +191,7 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, IntStream.range(0, repoLocation.length) .filter(i -> StringUtils.contains(repoLocation[i], "wso2/")) .forEach(i -> { - //clearing all the data in the current fileNames and changedLineRanges arraylists for each repository + //clearing all the data in the current fileNames and changedLineRanges arraylists for each Repository //authorNames.clear(); fileNames.clear(); changedLineRanges.clear(); @@ -204,9 +235,9 @@ public void saveRelaventEditLineNumbers(ArrayList fileNames, ArrayList { //filtering the lines ranges that existed in the previous file, that exists in the new file and saving them in to the same array IntStream.range(0, lineChanges.length) - .forEach(j -> { + .forEach(index -> { //@@ -22,7 +22,7 @@ => -22,7 +22,7 => 22,28/22,28 - String tempString = lineChanges[j]; + String tempString = lineChanges[index]; String lineRangeInTheOldFileBeingModified = StringUtils.substringBetween(tempString, "-", " +"); // for taking the authors and commit hashes of the previous lines String lineRangeInTheNewFileResultedFromModification = StringUtils.substringAfter(tempString, "+"); // for taking the parent commit @@ -223,7 +254,7 @@ public void saveRelaventEditLineNumbers(ArrayList fileNames, ArrayList tempArrayList = new ArrayList<>(Arrays.asList(lineChanges)); //adding to the array list which keep track of the line ranges being changed @@ -238,24 +269,23 @@ public void saveRelaventEditLineNumbers(ArrayList fileNames, ArrayList { + fileNames.forEach(fileName -> { int index = fileNames.indexOf(fileName); // the relevant arraylist of changed lines for that file ArrayList arrayListOfRelevantChangedLinesOfSelectedFile = changedLineRanges.get(index); commitHashesOfParent = new HashMap<>(); // for storing the parent commit hashes for all the changed line ranges of the relevant file - graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + commitHash + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{history(first: 2) { edges { node { message url } } } author { name email } } } } } } } }"); + graphqlApiJsonObject.put("query", "{Repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + commitHash + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{history(first: 2) { edges { node { message url } } } author { name email } } } } } } } }"); JSONObject rootJsonObject = null; try { // calling the graphql API for getting blame information for the current file. @@ -390,8 +420,8 @@ public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList commitHashes = (Set) m.getValue(); commitHashes.parallelStream() .forEach(parentCommitHashForCallingGraphQl -> { - graphqlApiJsonObject.put("query", "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + parentCommitHashForCallingGraphQl + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{ url author { name email } } } } } } } }"); + graphqlApiJsonObject.put("query", "{Repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + parentCommitHashForCallingGraphQl + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{ url author { name email } } } } } } } }"); JSONObject rootJsonObject = null; try { rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index aae1dbc..6798255 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -90,7 +90,7 @@ public static void main(String[] args) { // if (commitsInTheGivenPatch != null) { // commitHashObtainedForPRReview = changesFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); // } -// logger.info("Author commits that introduce bug lines of code to the repository are saved in commitHashObtainedForPRReview SET successfully"); +// logger.info("Author commits that introduce bug lines of code to the Repository are saved in commitHashObtainedForPRReview SET successfully"); // // Reviewer reviewer = new Reviewer(); // if (commitHashObtainedForPRReview != null) { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java index c42ea4b..a6ad4d3 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java @@ -75,7 +75,7 @@ public void setPullRequestReviewAPIUrl(String repoLocation, int pullRequestNumbe this.pullRequestReviewAPIUrl = "https://api.github.com/repos/" + repoLocation + "/pulls/" + pullRequestNumber + "/reviews"; } - // map for storing the pull requests numbers against their repository + // map for storing the pull requests numbers against their Repository Map> mapContainingPRNoAgainstRepoName = new HashMap>(); /** @@ -103,9 +103,9 @@ public void findReviewers(Set commitHashObtainedForPRReview, String gith } }); - logger.info("PR numbers which introduce bug lines of code with their relevant repository are saved successfully to mapContainingPRNoAgainstRepoName map"); + logger.info("PR numbers which introduce bug lines of code with their relevant Repository are saved successfully to mapContainingPRNoAgainstRepoName map"); saveReviewersToList(githubToken, restApiCaller); - logger.info("List of approved reviwers and comment users of the PRs which introduce bug lines to repository are saved in commentedReviewers and approvedReviewers list "); + logger.info("List of approved reviwers and comment users of the PRs which introduce bug lines to Repository are saved in commentedReviewers and approvedReviewers list "); // printing the list of reviewers of pull requests printReviewUsers(); logger.info("Names of approved reviewers and commented reviewers are printed successfully"); @@ -187,8 +187,8 @@ public void readTheReviewOutJSON(JSONArray reviewJsonArray, String productLocati // } // } } else { - System.out.println("There are no records of reviews for pull request: " + prNumber + " on " + productLocation + " repository"); - logger.info("There are no records of reviews for pull request: " + prNumber + " on " + productLocation + " repository"); + System.out.println("There are no records of reviews for pull request: " + prNumber + " on " + productLocation + " Repository"); + logger.info("There are no records of reviews for pull request: " + prNumber + " on " + productLocation + " Repository"); } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java index 1bea347..0919d91 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java @@ -42,8 +42,6 @@ public class SdkGitHubClient { protected GitHubClient gitHubClient = null; protected CommitService commitService = null; protected RepositoryService repositoryService = null; - protected ArrayList fileNames = new ArrayList(); - protected ArrayList patchString = new ArrayList(); private static final Logger logger = Logger.getLogger(SdkGitHubClient.class); @@ -56,9 +54,9 @@ public class SdkGitHubClient { /** * This method is used for saving the files changed and their relevant changed line ranges from - * the given commit in the given repository + * the given commit in the given Repository * - * @param repositoryName The repository name that contain the given commit hash + * @param repositoryName The Repository name that contain the given commit hash * @param commitHash The querying commit hash * @return a map containg arraylist of file changed and their relevant patch */ @@ -77,12 +75,13 @@ public Map> getFilesChanged(String repositoryName, Str tempFileNames.add(commitFile.getFilename()); tempPatchString.add(commitFile.getPatch()); }); - logger.info("for" + commitHash + " on the " + repositoryName + " repository, files changed and their relevant changed line ranges added to the arraylists successfully"); + logger.info("for" + commitHash + " on the " + repositoryName + " Repository, files changed and their relevant changed line ranges added to the arraylists successfully"); fileNamesAndPatches.put("fileNames", tempFileNames); fileNamesAndPatches.put("patchString", tempPatchString); logger.info("map with the modified file names with their relevant modified line ranges are saved successfully"); } catch (IOException e) { - throw new CodeQualityMatricesException("IO Exception occurred when getting the commit with the given SHA form the given repository ", e); + throw new CodeQualityMatricesException("IO Exception occurred when getting the commit of given SHA from " + + "the given Repository ", e); } return fileNamesAndPatches; } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SearchCommitPojo.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SearchCommitPojo.java new file mode 100644 index 0000000..12354ff --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SearchCommitPojo.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices; + +import java.util.List; + +public class SearchCommitPojo { +private int total_count; +private List items; + + public int getTotal_count() { + return total_count; + } + + public void setTotal_count(int total_count) { + this.total_count = total_count; + } + + public List getItems() { + return items; + } + + public void setItems(List Items) { + this.items = Items; + } +} + +class Item { + private Repository repository; + + public Repository getRepository() { + return repository; + } + + public void setRepository(Repository Repository) { + this.repository = Repository; + } +} +class Repository { + private String full_name; + + public String getFull_name() { + return full_name; + } + + public void setFull_name(String full_name) { + this.full_name = full_name; + } +} \ No newline at end of file From 9dc9c9d83135616119e7363d16cd172eed0055e9 Mon Sep 17 00:00:00 2001 From: kasun Date: Wed, 29 Mar 2017 15:37:14 +0530 Subject: [PATCH 37/62] Add model classes --- .../code/quality/matrices/model/Author.java | 41 +++++++++++++ .../code/quality/matrices/model/Commit.java | 49 ++++++++++++++++ .../code/quality/matrices/model/Data.java | 31 ++++++++++ .../code/quality/matrices/model/Edge.java | 31 ++++++++++ .../matrices/model/GraphQlResponse.java | 44 ++++++++++++++ .../code/quality/matrices/model/Graphql.java | 56 ++++++++++++++++++ .../quality/matrices/model/GraphqlBlame.java | 37 ++++++++++++ .../quality/matrices/model/GraphqlObject.java | 31 ++++++++++ .../quality/matrices/model/GraphqlRange.java | 58 +++++++++++++++++++ .../matrices/model/GraphqlRepository.java | 30 ++++++++++ .../code/quality/matrices/model/History.java | 33 +++++++++++ .../code/quality/matrices/model/Item.java | 33 +++++++++++ .../code/quality/matrices/model/Node.java | 31 ++++++++++ .../quality/matrices/model/Repository.java | 31 ++++++++++ .../matrices/model/SearchApiResponse.java | 42 ++++++++++++++ 15 files changed, 578 insertions(+) create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Author.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Commit.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Data.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Edge.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/History.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Item.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Node.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Repository.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Author.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Author.java new file mode 100644 index 0000000..2706278 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Author.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +public class Author { + private String name; + private String email; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} + diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Commit.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Commit.java new file mode 100644 index 0000000..2228dba --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Commit.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +public class Commit { + private Author author; + private History history; + private String url; + + public Author getAuthor() { + return author; + } + + public void setAuthor(Author author) { + this.author = author; + } + + public History getHistory() { + return history; + } + + public void setHistory(History history) { + this.history = history; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getUrl() { + return url; + } +} \ No newline at end of file diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Data.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Data.java new file mode 100644 index 0000000..9c91953 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Data.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +public class Data { + private GraphqlRepository repository; + + public GraphqlRepository getRepository() { + return repository; + } + + public void setRepository(GraphqlRepository repository) { + this.repository = repository; + } +} \ No newline at end of file diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Edge.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Edge.java new file mode 100644 index 0000000..ea124db --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Edge.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +public class Edge { + private Node node; + + public Node getNode() { + return node; + } + + public void setNode(Node node) { + this.node = node; + } +} \ No newline at end of file diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java new file mode 100644 index 0000000..836d795 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +public class GraphQlResponse { + private Data data; + + public Data getData() { + return data; + } + + public void setData(Data data) { + this.data = data; + } + +} + + + + + + + + + + + + diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java new file mode 100644 index 0000000..c8ae3c4 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +import java.io.Serializable; + +/** + * This is a bean class used to set the json structures for calling the github graphql API + * + * @since 1.0.0 + */ +public class Graphql implements Serializable { + private String graphqlInputWithHistory; + private String graphqlInputWithoutHistory; + + public Graphql() { + + } + + public String getGraphqlInputWithHistory() { + return graphqlInputWithHistory; + } + + public void setGraphqlInputWithHistory(String owner, String repositoryName, String commitHash, String fileName) { + this.graphqlInputWithHistory = "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\")" + + "{object(expression:\"" + commitHash + "\"){ ... on Commit{blame(path:\"" + fileName + "\")" + + "{ranges{startingLine endingLine age commit{history(first: 2) { edges { node { message url } } } " + + "author { name email } } } } } } } }"; + } + + public String getGraphqlInputWithoutHistory() { + return graphqlInputWithoutHistory; + } + + public void setGraphqlInputWithoutHistory(String owner, String repositoryName, String + parentCommitHashForCallingGraphQl, String fileName) { + this.graphqlInputWithoutHistory = "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\")" + + "{object(expression:\"" + parentCommitHashForCallingGraphQl + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{ url author { name email } } } } } } } }"; + } +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java new file mode 100644 index 0000000..8c81726 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +import java.util.List; + +public class GraphqlBlame { + + private List ranges; + + public List getRanges() { + return ranges; + } + + public void setRanges(List ranges) { + this.ranges = ranges; + } + + +} + diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java new file mode 100644 index 0000000..61a20f3 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +public class GraphqlObject { + private GraphqlBlame blame; + + public GraphqlBlame getBlame() { + return blame; + } + + public void setBlame(GraphqlBlame blame) { + this.blame = blame; + } +} \ No newline at end of file diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java new file mode 100644 index 0000000..bb7f370 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +public class GraphqlRange { + private int startingLine; + private int endingLine; + private int age; + private Commit commit; + + public int getStartingLine() { + return startingLine; + } + + public void setStartingLine(int startingLine) { + this.startingLine = startingLine; + } + + public int getEndingLine() { + return endingLine; + } + + public void setEndingLine(int endingLine) { + this.endingLine = endingLine; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public Commit getCommit() { + return commit; + } + + public void setCommit(Commit commit) { + this.commit = commit; + } +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java new file mode 100644 index 0000000..b91ea88 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; +public class GraphqlRepository { + private GraphqlObject object; + + public GraphqlObject getObject() { + return object; + } + + public void setObject(GraphqlObject object) { + this.object = object; + } +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/History.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/History.java new file mode 100644 index 0000000..256f7bb --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/History.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +import java.util.List; + +public class History { + private List edges; + + public List getEdges() { + return edges; + } + + public void setEdges(List edges) { + this.edges = edges; + } +} \ No newline at end of file diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Item.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Item.java new file mode 100644 index 0000000..592e70f --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Item.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +public class Item { + + private Repository repository; + + public Repository getRepository() { + return repository; + } + + public void setRepository(Repository Repository) { + this.repository = Repository; + } +} + diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Node.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Node.java new file mode 100644 index 0000000..5efbbc7 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Node.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +public class Node { + private String url; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } +} \ No newline at end of file diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Repository.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Repository.java new file mode 100644 index 0000000..6bb8a5c --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Repository.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +public class Repository { + private String full_name; + + public String getFull_name() { + return full_name; + } + + public void setFull_name(String full_name) { + this.full_name = full_name; + } +} \ No newline at end of file diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java new file mode 100644 index 0000000..bc68cb4 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +import java.util.List; + +public class SearchApiResponse { + private int total_count; + private List items; + + public int getTotal_count() { + return total_count; + } + + public void setTotal_count(int total_count) { + this.total_count = total_count; + } + + public List getItems() { + return items; + } + + public void setItems(List Items) { + this.items = Items; + } +} From 5e58bc32700976bb7f000dbcdddcc8442be569aa Mon Sep 17 00:00:00 2001 From: kasun Date: Wed, 29 Mar 2017 15:38:46 +0530 Subject: [PATCH 38/62] use Gson till getting till getting author commits --- .../code/quality/matrices/ApiUtility.java | 65 ++- .../code/quality/matrices/ChangesFinder.java | 483 ++++++++---------- .../quality/matrices/CodeQualityMatrices.java | 7 +- .../quality/matrices/GithubApiCaller.java | 45 +- .../wso2/code/quality/matrices/MainClass.java | 10 +- 5 files changed, 316 insertions(+), 294 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java index 33f588a..28805b1 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java @@ -21,6 +21,7 @@ import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.log4j.Logger; @@ -28,6 +29,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; /** * This is a utility class for calling APIs @@ -65,7 +67,7 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio } else { - throw new CodeQualityMatricesException("Error occurred while calling the API, the reponse code is " + + throw new CodeQualityMatricesException("Error occurred while calling the API, the response code is " + responseCode); } } catch (ClientProtocolException e) { @@ -97,4 +99,65 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio } return jsonText; } + + public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatricesException { + BufferedReader bufferedReader = null; + CloseableHttpClient httpClient = null; + CloseableHttpResponse httpResponse = null; + httpClient = HttpClients.createDefault(); + String jsonText = null; + + try { + httpResponse = httpClient.execute(httpPost); + int responseCode = httpResponse.getStatusLine().getStatusCode(); + if (responseCode == 200) { + bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), + "UTF-8")); + String line; + StringBuilder stringBuilder = new StringBuilder(); + while ((line = bufferedReader.readLine()) != null) { + stringBuilder.append(line); + } + jsonText = stringBuilder.toString(); + logger.info("The response received from the Github GraphQL converted to a JSON text successfully"); + + } else { + throw new CodeQualityMatricesException("Error occurred while calling the API, the response code is " + + responseCode); + + } + + } catch (UnsupportedEncodingException e) { + throw new CodeQualityMatricesException("Encoding error occured before calling the github graphQL API", e); + } catch (ClientProtocolException e) { + throw new CodeQualityMatricesException("Client protocol exception occurred when calling the github graphQL API", e); + } catch (IOException e) { + throw new CodeQualityMatricesException("A problem or the connection was aborted while executing the httpPost", e); + } finally { + if (bufferedReader != null) { + try { + bufferedReader.close(); + } catch (IOException e) { + throw new CodeQualityMatricesException("IOException occurred when closing the buffered reader", e); + } + } + if (httpResponse != null) { + try { + httpResponse.close(); + } catch (IOException e) { + logger.error("IOException occurred when closing the HttpResponse", e); + } + } + if (httpClient != null) { + try { + httpClient.close(); + } catch (IOException e) { + logger.error("IOException occurred when closing the HttpClient", e); + } + } + + } + + return jsonText; + } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index 551d997..ebd6e9f 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -19,9 +19,12 @@ package com.wso2.code.quality.matrices; import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; +import com.wso2.code.quality.matrices.model.GraphQlResponse; +import com.wso2.code.quality.matrices.model.Graphql; +import com.wso2.code.quality.matrices.model.SearchApiResponse; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; -import org.json.JSONArray; import org.json.JSONObject; import java.util.ArrayList; @@ -42,46 +45,23 @@ public class ChangesFinder { - private String urlForObtainingCommits; - protected ArrayList fileNames = new ArrayList(); + protected ArrayList fileNames = new ArrayList<>(); protected ArrayList patchString = new ArrayList<>(); - protected List> changedLineRanges = new ArrayList>(); // for saving the line no that are changed - JSONObject graphqlApiJsonObject = new JSONObject(); - Map> commitHashesOfParent; - Set authorNames = new HashSet(); //as the authors are for all the commits that exists in the relevant patch - protected Set commitHashObtainedForPRReview = new HashSet(); // relevant commits in old file that need to find the PR Reviewer - private String repoLocation[]; - GraphQlApiCaller graphQlApiCaller = new GraphQlApiCaller(); + protected List> changedLineRanges = new ArrayList<>(); // for saving the line no that are changed + private JSONObject jsonStructure = new JSONObject(); + private Map> parentCommitHashes; + protected Set authorNames = new HashSet<>(); //authors of the bug lines fixed from the patch + protected Set authorCommits = new HashSet<>(); // author commits of the bug lines fixed from the patch private static final Logger logger = Logger.getLogger(ChangesFinder.class); - // constants for accessing the Github API responses - private static final String GITHUB_API_ITEMS = "items"; - private static final String GITHUB_API_REPOSITORY = "Repository"; - private static final String GITHUB_API_FULL_NAME_OF_REPOSITORY = "full_name"; - private static final String GITHUB_API_STARTING_LINE = "startingLine"; - private static final String GITHUB_API_ENDING_LINE = "endingLine"; - private static final String GITHUB_API_AGE = "age"; - private static final String GITHUB_API_DATA = "data"; - private static final String GITHUB_API_OBJECT = "object"; - private static final String GITHUB_API_BLAME = "blame"; - private static final String GITHUB_API_RANGES = "ranges"; - private static final String GITHUB_API_COMMIT = "commit"; - private static final String GITHUB_API_AUTHOR = "author"; - private static final String GITHUB_API_NAME = "name"; - private static final String GITHUB_API_URL = "url"; - private static final String GITHUB_API_HISTORY = "history"; - private static final String GITHUB_API_EDGE = "edges"; - private static final String GITHUB_API_NODE = "node"; - - - public String getUrlForSearchingCommits() { - return urlForObtainingCommits; - } - - public void setUrlForSearchingCommits(String commitHash) { - this.urlForObtainingCommits = "https://api.github.com/search/commits?q=hash%3A" + commitHash; - } + /** + * This is used for obtaining the repositories that contain the relevant commits belongs to the given patch + * + * @param gitHubToken github token for accessing github API + * @param commitHashes List of commits that belongs to the given patch + * @return author commits of the bug lines which are fixed from the given patch + */ public Set obtainRepoNamesForCommitHashes(String gitHubToken, List commitHashes) { GithubApiCaller githubApiCaller = new GithubApiCaller(); @@ -89,49 +69,31 @@ public Set obtainRepoNamesForCommitHashes(String gitHubToken, List commi commitHashes.forEach(commitHash -> { try { String jsonText = githubApiCaller.callSearchCommitApi(commitHash, gitHubToken); - saveRepoNamesInAnArray(jsonText, commitHash, gitHubToken); + saveRepoNames(jsonText, commitHash, gitHubToken); } catch (CodeQualityMatricesException e) { logger.error(e.getMessage(), e.getCause()); } }); - return commitHashObtainedForPRReview; + return authorCommits; } -//================================================================================ -// /** -// * This method is used for obtaining the repositories that contain the relevant commits belongs to the given patch -// * -// * @param gitHubToken Github token -// * @param commitsInTheGivenPatch Commits that belongs to the given patch -// * @param restApiCaller Instance of the RestApiCaller class for accessing the REST APIs -// * @return a Set containing the commit hashes that needs to be checked for reviewers -// */ -// public Set obtainRepoNamesForCommitHashes(String gitHubToken, String[] commitsInTheGivenPatch, RestApiCaller restApiCaller) { -// -// //calling the API calling method -// IntStream.range(0, commitsInTheGivenPatch.length) -// .mapToObj(i -> commitsInTheGivenPatch[i]) -// .forEach(commitHash -> { -// setUrlForSearchingCommits(commitHash); -// JSONObject jsonObject = null; -// try { -// jsonObject = (JSONObject) restApiCaller.callApi(getUrlForSearchingCommits(), gitHubToken, true, false); -// } catch (CodeQualityMatricesException e) { -// logger.error(e.getMessage(), e.getCause()); -// System.exit(1); -// } -// -// saveRepoNamesInAnArray(jsonObject, commitHash, gitHubToken); -// }); -// return commitHashObtainedForPRReview; -// } - //============================================ - - public void saveRepoNamesInAnArray(String jsonText, String commitHash, String gitHubToken) { + /** + * Saving the relevant repo Names in List + * + * @param jsonText + * @param commitHash + * @param gitHubToken + */ + public void saveRepoNames(String jsonText, String commitHash, String gitHubToken) throws CodeQualityMatricesException { List repoLocation = new ArrayList<>(); Gson gson = new Gson(); - SearchCommitPojo searchCommitPojo = gson.fromJson(jsonText, SearchCommitPojo.class); + SearchApiResponse searchCommitPojo; + try { + searchCommitPojo = gson.fromJson(jsonText, SearchApiResponse.class); + } catch (JsonSyntaxException e) { + throw new CodeQualityMatricesException(e.getMessage(), e.getCause()); + } searchCommitPojo.getItems().forEach(recordItem -> { repoLocation.add(recordItem.getRepository().getFull_name()); @@ -156,67 +118,14 @@ public void saveRepoNamesInAnArray(String jsonText, String commitHash, String gi fileNames = fileNamesAndPatches.get("fileNames"); patchString = fileNamesAndPatches.get("patchString"); saveRelaventEditLineNumbers(fileNames, patchString); - - - }); - - - } - - - /** - * saving the Repo Names in the array and calling to Get files content - * - * @param rootJsonObject JSON object containing the repositories which are having the current selected commit from the given patch - * @param commitHash the current selected commit hash - * @param gitHubToken github token for accessing the github REST API - */ - - public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, String gitHubToken) { - JSONArray jsonArrayOfItems = (JSONArray) rootJsonObject.get(GITHUB_API_ITEMS); - // setting the size of the repoLocationArray - repoLocation = new String[jsonArrayOfItems.length()]; - //adding the repo name to the array - IntStream.range(0, jsonArrayOfItems.length()) - .forEach(i -> { - JSONObject jsonObject = (JSONObject) jsonArrayOfItems.get(i); - JSONObject repositoryJsonObject = (JSONObject) jsonObject.get(GITHUB_API_REPOSITORY); - repoLocation[i] = (String) repositoryJsonObject.get(GITHUB_API_FULL_NAME_OF_REPOSITORY); - }); - logger.info("Repo names having the given commit are successfully saved in an array"); - - SdkGitHubClient sdkGitHubClient = new SdkGitHubClient(gitHubToken); - - // for running through the repoName Array - IntStream.range(0, repoLocation.length) - .filter(i -> StringUtils.contains(repoLocation[i], "wso2/")) - .forEach(i -> { - //clearing all the data in the current fileNames and changedLineRanges arraylists for each Repository - //authorNames.clear(); - fileNames.clear(); - changedLineRanges.clear(); - patchString.clear(); - Map> mapWithFileNamesAndPatch = null; try { - mapWithFileNamesAndPatch = sdkGitHubClient.getFilesChanged(repoLocation[i], commitHash); + iterateOverFileChanges(repositoryName, commitHash, gitHubToken); } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside a lambda expression - System.exit(2); - } - fileNames = mapWithFileNamesAndPatch.get("fileNames"); - patchString = mapWithFileNamesAndPatch.get("patchString"); - saveRelaventEditLineNumbers(fileNames, patchString); - try { - iterateOverFileChanges(repoLocation[i], commitHash, gitHubToken); - } catch (Exception e) { logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside a lambda expression - System.exit(3); } }); - - // for printing the author names and commit hashes for a certain commit. System.out.println(authorNames); - System.out.println(commitHashObtainedForPRReview); + System.out.println(authorCommits); } /** @@ -229,7 +138,7 @@ public void saveRepoNamesInAnArray(JSONObject rootJsonObject, String commitHash, public void saveRelaventEditLineNumbers(ArrayList fileNames, ArrayList patchString) { //filtering only the line ranges that are modified and saving to a string array - // cannot ues parallel streams here as the order of the line changes must be preserved + // cannot use parallel streams here as the order of the line changes must be preserved patchString.stream() .map(patch -> StringUtils.substringsBetween(patch, "@@ ", " @@")) .forEach(lineChanges -> { @@ -273,7 +182,7 @@ public void saveRelaventEditLineNumbers(ArrayList fileNames, ArrayList { - int index = fileNames.indexOf(fileName); - // the relevant arraylist of changed lines for that file - ArrayList arrayListOfRelevantChangedLinesOfSelectedFile = changedLineRanges.get(index); - commitHashesOfParent = new HashMap<>(); // for storing the parent commit hashes for all the changed line ranges of the relevant file - graphqlApiJsonObject.put("query", "{Repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + commitHash + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{history(first: 2) { edges { node { message url } } } author { name email } } } } } } } }"); - JSONObject rootJsonObject = null; - try { - // calling the graphql API for getting blame information for the current file. - rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); - } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside lambda expression - System.exit(1); - } - // reading the above saved output for the current selected file name - readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLinesOfSelectedFile, false, null); - logger.info("Parent Commits hashes of the lines which are being fixed by the patch in file " + fileName + " are saved to commitHashesOfParent map successfully "); + int index = fileNames.indexOf(fileName); + // the relevant arraylist of changed lines for that file + ArrayList lineRangesForSelectedFile = changedLineRanges.get(index); + parentCommitHashes = new HashMap<>(); // for storing the parent commit hashes for all the changed line ranges of the relevant file - iterateOverToFindAuthors(owner, repositoryName, fileName, arrayListOfRelevantChangedLinesOfSelectedFile, gitHubToken); - logger.info("Authors of the bug lines of code which are being fixed from the given patch are saved successfully to authorNames SET"); - }); + Graphql graphqlBean = new Graphql(); + graphqlBean.setGraphqlInputWithHistory(owner, repositoryName, commitHash, fileName); + jsonStructure.put("query", graphqlBean.getGraphqlInputWithHistory()); + + String jsonText = null; + try { + // calling the graphql API for getting blame information for the current file. + GithubApiCaller githubApiCaller = new GithubApiCaller(); + jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); + + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside lambda expression + System.exit(1); + } + //reading the above saved output for the current selected file name + try { + readBlameForSelectedFile(jsonText, lineRangesForSelectedFile); + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e.getCause()); + } + + + findAuthorCommits(owner, repositoryName, fileName, lineRangesForSelectedFile, gitHubToken); + + logger.debug("Authors and author commits of bug lines of code which are being fixed from the given " + + "patch are saved successfully to authorNames and authorCommits Sets"); + }); } + /** - * Reading the blame received for a current selected file name and insert the parent commits of the changed lines, - * relevant authors and the relevant commits hashes to look for the reviewers of those line ranges + * This reads the blame received for the current selected file and insert parent commits of the changed lines + * to a list * - * @param rootJsonObject JSONObject containing blame information for current selected file - * @param arrayListOfRelevantChangedLinesOfSelectedFile arraylist containing the changed line ranges of the current selected file - * @param gettingPr should be true if running this method for finding the authors of buggy lines which are being fixed from the patch + * @param jsonText JSON response of blame of the selected file + * @param changedRangesOfSelectedFile arraylist containing the changed line ranges of the current selected file */ - public void readBlameReceivedForAFile(JSONObject rootJsonObject, ArrayList arrayListOfRelevantChangedLinesOfSelectedFile, boolean gettingPr, String oldRange) { - - //running a iterator for fileName arrayList to get the location of the above saved file - JSONObject dataJSONObject = (JSONObject) rootJsonObject.get(GITHUB_API_DATA); - JSONObject repositoryJSONObect = (JSONObject) dataJSONObject.get(GITHUB_API_REPOSITORY); - JSONObject objectJSONObject = (JSONObject) repositoryJSONObect.get(GITHUB_API_OBJECT); - JSONObject blameJSONObject = (JSONObject) objectJSONObject.get(GITHUB_API_BLAME); - JSONArray rangeJSONArray = (JSONArray) blameJSONObject.get(GITHUB_API_RANGES); - - //getting the starting line no of the range of lines that are modified from the patch - // parallel streams are not used in here as the order of the arraylist is important in the process - arrayListOfRelevantChangedLinesOfSelectedFile.stream() - .forEach(lineRanges -> { - int startingLineNo = 0; - int endLineNo = 0; - String oldFileRange = StringUtils.substringBefore(lineRanges, "/"); - String newFileRange = StringUtils.substringAfter(lineRanges, "/"); - // need to skip the newly created files from taking the blame as they contain no previous commits - if (!oldFileRange.equals("0,0")) { - if (gettingPr && oldRange.equals(oldFileRange)) { - // need to consider the line range in the old file for finding authors and reviewers - startingLineNo = Integer.parseInt(StringUtils.substringBefore(oldFileRange, ",")); - endLineNo = Integer.parseInt(StringUtils.substringAfter(oldFileRange, ",")); - } else if (!gettingPr && oldRange == null) { - // need to consider the line range in the new file resulted from applying the commit, for finding parent commits - startingLineNo = Integer.parseInt(StringUtils.substringBefore(newFileRange, ",")); - endLineNo = Integer.parseInt(StringUtils.substringAfter(newFileRange, ",")); - } else { - return; // to skip the to the next iteration if oldRange != oldFileRange when finding authornames and commits for obtaining PRs - } - - // as a new mapForStoringAgeAndIndex map should be available for each line range to find the most recent change - Map> mapForStoringAgeAndIndex = new HashMap>(); - - //checking line by line by iterating the startingLineNo - while (endLineNo >= startingLineNo) { - // since the index value is required for later processing, without Java 8 features "for loop" is used for iteration - for (int i = 0; i < rangeJSONArray.length(); i++) { - JSONObject rangeJSONObject = (JSONObject) rangeJSONArray.get(i); - int tempStartingLineNo = (int) rangeJSONObject.get(GITHUB_API_STARTING_LINE); - int tempEndingLineNo = (int) rangeJSONObject.get(GITHUB_API_ENDING_LINE); - - //checking whether the line belongs to that line range group - if ((tempStartingLineNo <= startingLineNo) && (tempEndingLineNo >= startingLineNo)) { - // so the relevant startingLineNo belongs in this line range in other words in this JSONObject - if (!gettingPr) { - int age = (int) rangeJSONObject.get(GITHUB_API_AGE); - // storing the age field with relevant index of the JSONObject - mapForStoringAgeAndIndex.putIfAbsent(age, new ArrayList()); - if (!mapForStoringAgeAndIndex.get(age).contains(i)) { - mapForStoringAgeAndIndex.get(age).add(i); // adding if the index is not present in the array list for the relevant age - } - - } else { - //for saving the author names of commiters - JSONObject commitJSONObject = (JSONObject) rangeJSONObject.get(GITHUB_API_COMMIT); - - JSONObject authorJSONObject = (JSONObject) commitJSONObject.get(GITHUB_API_AUTHOR); - String nameOfTheAuthor = (String) authorJSONObject.get(GITHUB_API_NAME); - authorNames.add(nameOfTheAuthor); // authors are added to the Set - - String urlOfCommit = (String) commitJSONObject.get(GITHUB_API_URL); - String commitHashForPRReview = StringUtils.substringAfter(urlOfCommit, "commit/"); - commitHashObtainedForPRReview.add(commitHashForPRReview); - } - break; - } else { - continue; // to skip to the next JSON Object in the rangeJSONArray + public void readBlameForSelectedFile(String jsonText, + ArrayList changedRangesOfSelectedFile) throws CodeQualityMatricesException { + + Gson gson = new Gson(); + GraphQlResponse graphQlResponse = null; + try { + graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); + + } catch (JsonSyntaxException e) { + throw new CodeQualityMatricesException(e.getMessage(), e.getCause()); + } + + GraphQlResponse finalGraphQlResponse = graphQlResponse; // to make a effective final variable + changedRangesOfSelectedFile.forEach(lineRange -> { + int startingLineNo; + int endLineNo; + String oldFileRange = StringUtils.substringBefore(lineRange, "/"); + String newFileRange = StringUtils.substringAfter(lineRange, "/"); + // need to skip the newly created files from taking the blame as they contain no previous commits + if (!oldFileRange.equals("0,0")) { + // need to consider the line range in the new file resulted from applying the commit, for finding parent commits + startingLineNo = Integer.parseInt(StringUtils.substringBefore(newFileRange, ",")); + endLineNo = Integer.parseInt(StringUtils.substringAfter(newFileRange, ",")); + + //for storing age with the relevant parent commit hash + Map> ageWithParentCommit = new HashMap<>(); + + while (endLineNo >= startingLineNo) { + int finalStartingLineNo = startingLineNo; // to make a effective final variable + + finalGraphQlResponse.getData().getRepository().getObject().getBlame().getRanges().stream() + .filter(graphqlRange -> (graphqlRange.getStartingLine() <= finalStartingLineNo && + graphqlRange.getEndingLine() >= finalStartingLineNo)) + .forEach(graphqlRange -> { + int age = graphqlRange.getAge(); + String url = graphqlRange.getCommit().getHistory().getEdges().get(1).getNode().getUrl(); + /* get(1) is used directly as there are only 2 elements in the List and last + resembles the parent commit + */ + + String parentCommit = StringUtils.substringAfter(url, "commit/"); + ageWithParentCommit.putIfAbsent(age, new HashSet<>()); + if (!ageWithParentCommit.get(age).contains(parentCommit)) { + ageWithParentCommit.get(age).add(parentCommit); } - } - startingLineNo++; // to check for other line numbers - } - - //for the above line range getting the lastest commit which modified the lines - if (!gettingPr) { - //converting the map into a treeMap to get it ordered - TreeMap> treeMap = new TreeMap<>(mapForStoringAgeAndIndex); - int minimumKeyOfMapForStoringAgeAndIndex = treeMap.firstKey(); // getting the minimum key - //getting the relevant JSONObject indexes which consists of the recent change with in the relevant line range - ArrayList indexesOfJsonObjectForRecentCommit = mapForStoringAgeAndIndex.get(minimumKeyOfMapForStoringAgeAndIndex); - // the order of the indexesOfJsonObjectForRecentCommit is not important as we only need to get the parent commit hashes - indexesOfJsonObjectForRecentCommit.parallelStream() - .forEach(index -> { - JSONObject rangeJSONObject = (JSONObject) rangeJSONArray.get(index); - JSONObject commitJSONObject = (JSONObject) rangeJSONObject.get(GITHUB_API_COMMIT); - JSONObject historyJSONObject = (JSONObject) commitJSONObject.get(GITHUB_API_HISTORY); - JSONArray edgesJSONArray = (JSONArray) historyJSONObject.get(GITHUB_API_EDGE); - //getting the second json object from the array as it contain the commit of the parent which modified the above line range - JSONObject edgeJSONObject = (JSONObject) edgesJSONArray.get(1); - JSONObject nodeJSONObject = (JSONObject) edgeJSONObject.get(GITHUB_API_NODE); - String urlOfTheParentCommit = (String) nodeJSONObject.get(GITHUB_API_URL); // this contain the URL of the parent commit - String commitHash = (String) StringUtils.substringAfter(urlOfTheParentCommit, "commit/"); -// commitHashesOfTheParent.add(commitHash); // commitHashesof the parent for the selected file - - commitHashesOfParent.putIfAbsent(oldFileRange, new HashSet()); - if (!commitHashesOfParent.get(oldFileRange).contains(commitHash)) { - commitHashesOfParent.get(oldFileRange).add(commitHash); - } - }); - } - } - }); + }); + + + startingLineNo++; // to check for other line numbers + + } + TreeMap> sortedAgeWithParentCommit = new TreeMap<>(ageWithParentCommit); + Set parentCommit = sortedAgeWithParentCommit.get(sortedAgeWithParentCommit.firstKey()); + parentCommitHashes.put(oldFileRange, parentCommit); + + } + + + }); } + /** - * Finding the authors of the commits + * This is used to find the author and author commits of the buggy lines of code which are been fixed by the + * given patch * - * @param owner owner of the Repository - * @param repositoryName Repository name - * @param fileName name of the file which is required to get blame details - * @param arrayListOfRelevantChangedLinesOfSelectedFile arraylist containing the changed line ranges of the current selected file - * @param gitHubToken github token for accessing github GraphQL API + * @param owner owner of the selected epository + * @param repositoryName selected repository name + * @param fileName name of the file which is required to get blame details + * @param lineRangesForSelectedFile arraylist containing the changed line ranges of the current selected file + * @param gitHubToken github token for accessing github GraphQL API */ - public void iterateOverToFindAuthors(String owner, String repositoryName, String fileName, ArrayList arrayListOfRelevantChangedLinesOfSelectedFile, String gitHubToken) { - - for (Map.Entry m : commitHashesOfParent.entrySet()) { - String oldRange = (String) m.getKey(); - Set commitHashes = (Set) m.getValue(); - commitHashes.parallelStream() - .forEach(parentCommitHashForCallingGraphQl -> { - graphqlApiJsonObject.put("query", "{Repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\"){object(expression:\"" + parentCommitHashForCallingGraphQl + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{ url author { name email } } } } } } } }"); - JSONObject rootJsonObject = null; - try { - rootJsonObject = (JSONObject) graphQlApiCaller.callGraphQlApi(graphqlApiJsonObject, gitHubToken); - readBlameReceivedForAFile(rootJsonObject, arrayListOfRelevantChangedLinesOfSelectedFile, true, oldRange); - } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); - System.exit(1); - } - }); + public void findAuthorCommits(String owner, String repositoryName, String fileName, ArrayList lineRangesForSelectedFile, String gitHubToken) { + for (Map.Entry entry : parentCommitHashes.entrySet()) { + String oldRange = (String) entry.getKey(); + Set commitHashes = (Set) entry.getValue(); + Graphql graphqlBean = new Graphql(); + GithubApiCaller githubApiCaller = new GithubApiCaller(); + commitHashes.parallelStream().forEach(commitHash -> { + + graphqlBean.setGraphqlInputWithoutHistory(owner, repositoryName, commitHash, fileName); + jsonStructure.put("query", graphqlBean.getGraphqlInputWithoutHistory()); + // jsonStructure calling the graphql API for getting blame information for the current file. + + String jsonText = null; + try { + jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); + } catch (CodeQualityMatricesException e) { + logger.debug(e.getMessage(), e.getCause()); + } + + + saveAuthorCommits(jsonText, oldRange, lineRangesForSelectedFile); + }); } } + + /** + * This is used to save the authors and author commits of the buggy lines of code which are been fixed by the + * given patch, to relevant lists + * + * @param jsonText + * @param oldRange + * @param lineRangesForSelectedFile + */ + public void saveAuthorCommits(String jsonText, String oldRange, ArrayList lineRangesForSelectedFile) { + + Gson gson = new Gson(); + GraphQlResponse graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); + + lineRangesForSelectedFile.forEach(lineRange -> { + int startingLineNo; + int endLineNo; + String oldFileRange = StringUtils.substringBefore(lineRange, "/"); + // need to skip the newly created files from taking the blame as they contain no previous commits + if (!oldFileRange.equals("0,0") && oldRange.equals(oldFileRange)) { + // need to consider the line range in the old file for finding authors and author commits + startingLineNo = Integer.parseInt(StringUtils.substringBefore(oldFileRange, ",")); + endLineNo = Integer.parseInt(StringUtils.substringAfter(oldFileRange, ",")); + + while (endLineNo >= startingLineNo) { + int finalStartingLineNo = startingLineNo; // to make a effective final variable + + graphQlResponse.getData().getRepository().getObject().getBlame().getRanges().stream() + .filter(graphqlRange -> (graphqlRange.getStartingLine() <= finalStartingLineNo && + graphqlRange.getEndingLine() >= finalStartingLineNo)) + .forEach(graphqlRange -> { + + String authorName = graphqlRange.getCommit().getAuthor().getName(); + String authorcommitUrl = StringUtils.substringAfter(graphqlRange.getCommit().getUrl(), + "commit/"); + + authorNames.add(authorName); // authors are added to the Set + authorCommits.add(authorcommitUrl); // author commits are added to the set + + + }); + startingLineNo++; // to check for other line numbers + } + } + }); + } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java index 338d5a3..9f54835 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Set; /** * @@ -52,16 +53,16 @@ public CodeQualityMatrices(String pmtToken, String patchId, String gitHubToken) */ public void execute() { try { - ChangesFinder changesFinder= new ChangesFinder(); + ChangesFinder changesFinder = new ChangesFinder(); List commitHashes = findCommitHashesInPatch(); - changesFinder.obtainRepoNamesForCommitHashes(gitHubToken,commitHashes); + Set authorCommits = changesFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitHashes); + System.out.println("Author Commits"+authorCommits); } catch (CodeQualityMatricesException e) { logger.error(e.getMessage(), e); } - System.out.println(); } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java index d15678c..4c723aa 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java @@ -19,23 +19,29 @@ package com.wso2.code.quality.matrices; import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.json.JSONObject; + +import java.io.UnsupportedEncodingException; /** * This is used for all github communications */ public class GithubApiCaller { private HttpGet httpGet; + private HttpPost httpPost; /** * @param commitHash - * @param accessToken + * @param githubAccessToken * @throws CodeQualityMatricesException */ - public String callSearchCommitApi(String commitHash, String accessToken) throws CodeQualityMatricesException { + public String callSearchCommitApi(String commitHash, String githubAccessToken) throws CodeQualityMatricesException { String url = "https://api.github.com/search/commits?q=hash%3A" + commitHash; try { httpGet = new HttpGet(url); - httpGet.addHeader("Authorization", "Bearer " + accessToken); + httpGet.addHeader("Authorization", "Bearer " + githubAccessToken); //as the accept header is needed for accessing commit search API which is still in preview mode httpGet.addHeader("Accept", "application/vnd.github.cloak-preview"); } catch (IllegalArgumentException e) { @@ -48,16 +54,16 @@ public String callSearchCommitApi(String commitHash, String accessToken) throws /** * @param repoLocation * @param pullRequestNumber - * @param accessToken + * @param githubAccessToken * @throws CodeQualityMatricesException */ - public String callReviewApi(String repoLocation, String pullRequestNumber, String accessToken) throws + public String callReviewApi(String repoLocation, String pullRequestNumber, String githubAccessToken) throws CodeQualityMatricesException { String url = "https://api.github.com/repos/" + repoLocation + "/pulls/" + pullRequestNumber + "/reviews"; try { httpGet = new HttpGet(url); httpGet.addHeader("Accept", "application/vnd.github.black-cat-preview+json"); - httpGet.addHeader("Authorization", "Bearer " + accessToken); + httpGet.addHeader("Authorization", "Bearer " + githubAccessToken); } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the Github Review Commit API is " + "invalid ", e); @@ -67,21 +73,42 @@ public String callReviewApi(String repoLocation, String pullRequestNumber, Strin /** * @param commitHashToBeSearched - * @param accessToken + * @param githubAccessToken * @throws CodeQualityMatricesException */ - public String callSearchIssueApi(String commitHashToBeSearched, String accessToken) throws + public String callSearchIssueApi(String commitHashToBeSearched, String githubAccessToken) throws CodeQualityMatricesException { String url = "https://api.github.com/search/issues?q=" + commitHashToBeSearched; try { httpGet = new HttpGet(url); httpGet.addHeader("Accept", "application/vnd.github.mercy-preview+json"); - httpGet.addHeader("Authorization", "Bearer " + accessToken); + httpGet.addHeader("Authorization", "Bearer " + githubAccessToken); } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the Github Search Issue API is " + "invalid ", e); } return ApiUtility.callApi(httpGet); } + + public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken) throws CodeQualityMatricesException { + String url = "https://api.github.com/graphql"; + try { + httpPost = new HttpPost(url); + httpPost.addHeader("Authorization", "Bearer " + githubToken); + httpPost.addHeader("Accept", "application/json"); + StringEntity entity = new StringEntity(graphqlJsonStructure.toString()); + httpPost.setEntity(entity); + + } catch (IllegalArgumentException e) { + throw new CodeQualityMatricesException("The url provided for accessing the Github Graphql API is " + + "invalid",e); + } + catch (UnsupportedEncodingException e){ + throw new CodeQualityMatricesException("An error occurred when creating the String entity from Json " + + "Structure",e); + } + return ApiUtility.callGraphQlApi(httpPost); + + } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index 6798255..fab67b5 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -86,15 +86,15 @@ public static void main(String[] args) { // // // ChangesFinder changesFinder = new ChangesFinder(); -// Set commitHashObtainedForPRReview = null; +// Set authorCommits = null; // if (commitsInTheGivenPatch != null) { -// commitHashObtainedForPRReview = changesFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); +// authorCommits = changesFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); // } -// logger.info("Author commits that introduce bug lines of code to the Repository are saved in commitHashObtainedForPRReview SET successfully"); +// logger.info("Author commits that introduce bug lines of code to the Repository are saved in authorCommits SET successfully"); // // Reviewer reviewer = new Reviewer(); -// if (commitHashObtainedForPRReview != null) { -// reviewer.findReviewers(commitHashObtainedForPRReview, gitHubToken, restApiCaller); +// if (authorCommits != null) { +// reviewer.findReviewers(authorCommits, gitHubToken, restApiCaller); // } // } else { // logger.error("at least one of the command line arguments are null."); From 3930dc2ddbcd53acb2d43d5954e7defbcfb84238 Mon Sep 17 00:00:00 2001 From: kasun Date: Wed, 29 Mar 2017 17:21:44 +0530 Subject: [PATCH 39/62] Change name of Graphql Pojo classes --- .../quality/matrices/model/GraphQlResponse.java | 6 +++--- .../wso2/code/quality/matrices/model/Graphql.java | 3 ++- .../model/{Author.java => GraphqlAuthor.java} | 2 +- .../model/{Commit.java => GraphqlCommit.java} | 14 +++++++------- .../matrices/model/{Data.java => GraphqlData.java} | 2 +- .../matrices/model/{Edge.java => GraphqlEdge.java} | 8 ++++---- .../model/{History.java => GraphqlHistory.java} | 8 ++++---- .../matrices/model/{Item.java => GraphqlItem.java} | 2 +- .../matrices/model/{Node.java => GraphqlNode.java} | 2 +- .../code/quality/matrices/model/GraphqlRange.java | 6 +++--- .../quality/matrices/model/SearchApiResponse.java | 6 +++--- 11 files changed, 30 insertions(+), 29 deletions(-) rename CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/{Author.java => GraphqlAuthor.java} (97%) rename CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/{Commit.java => GraphqlCommit.java} (78%) rename CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/{Data.java => GraphqlData.java} (97%) rename CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/{Edge.java => GraphqlEdge.java} (85%) rename CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/{History.java => GraphqlHistory.java} (83%) rename CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/{Item.java => GraphqlItem.java} (97%) rename CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/{Node.java => GraphqlNode.java} (96%) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java index 836d795..482f638 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java @@ -19,13 +19,13 @@ package com.wso2.code.quality.matrices.model; public class GraphQlResponse { - private Data data; + private GraphqlData data; - public Data getData() { + public GraphqlData getData() { return data; } - public void setData(Data data) { + public void setData(GraphqlData data) { this.data = data; } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java index c8ae3c4..3a323a4 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java @@ -51,6 +51,7 @@ public String getGraphqlInputWithoutHistory() { public void setGraphqlInputWithoutHistory(String owner, String repositoryName, String parentCommitHashForCallingGraphQl, String fileName) { this.graphqlInputWithoutHistory = "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\")" + - "{object(expression:\"" + parentCommitHashForCallingGraphQl + "\"){ ... on Commit{blame(path:\"" + fileName + "\"){ranges{startingLine endingLine age commit{ url author { name email } } } } } } } }"; + "{object(expression:\"" + parentCommitHashForCallingGraphQl + "\"){ ... on Commit{blame(path:\"" + + fileName + "\"){ranges{startingLine endingLine age commit{ url author { name email } } } } } } } }"; } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Author.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java similarity index 97% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Author.java rename to CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java index 2706278..ef44a7f 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Author.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java @@ -18,7 +18,7 @@ package com.wso2.code.quality.matrices.model; -public class Author { +public class GraphqlAuthor { private String name; private String email; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Commit.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java similarity index 78% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Commit.java rename to CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java index 2228dba..dfa4e42 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Commit.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java @@ -18,24 +18,24 @@ package com.wso2.code.quality.matrices.model; -public class Commit { - private Author author; - private History history; +public class GraphqlCommit { + private GraphqlAuthor author; + private GraphqlHistory history; private String url; - public Author getAuthor() { + public GraphqlAuthor getAuthor() { return author; } - public void setAuthor(Author author) { + public void setAuthor(GraphqlAuthor author) { this.author = author; } - public History getHistory() { + public GraphqlHistory getHistory() { return history; } - public void setHistory(History history) { + public void setHistory(GraphqlHistory history) { this.history = history; } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Data.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java similarity index 97% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Data.java rename to CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java index 9c91953..3b5d474 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Data.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java @@ -18,7 +18,7 @@ package com.wso2.code.quality.matrices.model; -public class Data { +public class GraphqlData { private GraphqlRepository repository; public GraphqlRepository getRepository() { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Edge.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java similarity index 85% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Edge.java rename to CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java index ea124db..cd8e28a 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Edge.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java @@ -18,14 +18,14 @@ package com.wso2.code.quality.matrices.model; -public class Edge { - private Node node; +public class GraphqlEdge { + private GraphqlNode node; - public Node getNode() { + public GraphqlNode getNode() { return node; } - public void setNode(Node node) { + public void setNode(GraphqlNode node) { this.node = node; } } \ No newline at end of file diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/History.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java similarity index 83% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/History.java rename to CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java index 256f7bb..c4f6903 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/History.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java @@ -20,14 +20,14 @@ import java.util.List; -public class History { - private List edges; +public class GraphqlHistory { + private List edges; - public List getEdges() { + public List getEdges() { return edges; } - public void setEdges(List edges) { + public void setEdges(List edges) { this.edges = edges; } } \ No newline at end of file diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Item.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java similarity index 97% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Item.java rename to CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java index 592e70f..6ddb5cb 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Item.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java @@ -18,7 +18,7 @@ package com.wso2.code.quality.matrices.model; -public class Item { +public class GraphqlItem { private Repository repository; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Node.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java similarity index 96% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Node.java rename to CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java index 5efbbc7..826714b 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Node.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java @@ -18,7 +18,7 @@ package com.wso2.code.quality.matrices.model; -public class Node { +public class GraphqlNode { private String url; public String getUrl() { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java index bb7f370..841e5ec 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java @@ -22,7 +22,7 @@ public class GraphqlRange { private int startingLine; private int endingLine; private int age; - private Commit commit; + private GraphqlCommit commit; public int getStartingLine() { return startingLine; @@ -48,11 +48,11 @@ public void setAge(int age) { this.age = age; } - public Commit getCommit() { + public GraphqlCommit getCommit() { return commit; } - public void setCommit(Commit commit) { + public void setCommit(GraphqlCommit commit) { this.commit = commit; } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java index bc68cb4..7c55983 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java @@ -22,7 +22,7 @@ public class SearchApiResponse { private int total_count; - private List items; + private List items; public int getTotal_count() { return total_count; @@ -32,11 +32,11 @@ public void setTotal_count(int total_count) { this.total_count = total_count; } - public List getItems() { + public List getItems() { return items; } - public void setItems(List Items) { + public void setItems(List Items) { this.items = Items; } } From e5baf70d1f4d3c68657a98a2c41f29ec542e7443 Mon Sep 17 00:00:00 2001 From: kasun Date: Wed, 29 Mar 2017 17:22:32 +0530 Subject: [PATCH 40/62] Add pojo classes for github Issue API --- .../matrices/model/IssueApiResponse.java | 33 +++++++++++++ .../quality/matrices/model/SearchItem.java | 49 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java new file mode 100644 index 0000000..b0905d5 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +import java.util.List; + +public class IssueApiResponse { + private List items; + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java new file mode 100644 index 0000000..0f0c4a0 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +public class SearchItem { + private String state; + private int number; + private String repository_url; + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + public String getRepository_url() { + return repository_url; + } + + public void setRepository_url(String repository_url) { + this.repository_url = repository_url; + } +} From 92c7ee330b28032319957e0e40fcaa336c76a6dd Mon Sep 17 00:00:00 2001 From: kasun Date: Thu, 30 Mar 2017 09:13:26 +0530 Subject: [PATCH 41/62] Use Gson for processing review API output --- .../quality/matrices/RevieweAnalyser.java | 160 +++++++++++++ .../wso2/code/quality/matrices/Reviewer.java | 222 ------------------ .../matrices/model/ReviewApiResponse.java | 40 ++++ .../code/quality/matrices/model/Reviewer.java | 31 +++ .../quality/matrices/model/SearchItem.java | 4 +- 5 files changed, 233 insertions(+), 224 deletions(-) create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java delete mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java new file mode 100644 index 0000000..9d57c46 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices; + +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; +import com.wso2.code.quality.matrices.model.IssueApiResponse; +import com.wso2.code.quality.matrices.model.ReviewApiResponse; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * This class is used to find the revierwers of the buggy lines of code + * + * @since 1.0.0 + */ + +public class RevieweAnalyser { + + Set approvedReviewers = new HashSet<>(); // to store the reviewed and approved users of the pull requests + Set commentedReviewers = new HashSet<>(); // to store the reviewed and commented users of the pull requests + + private static final Logger logger = Logger.getLogger(RevieweAnalyser.class); + + //constants for filtering github API responses + private static final String GITHUB_REVIEW_APPROVED = "APPROVED"; + private static final String GITHUB_REVIEW_COMMENTED = "COMMENTED"; + private static final String GITHUB_REVIEW_API_CLOSED_STATE = "closed"; + + /** + * This is used to identify the pull requests that introduce the given commit to the code base + * + * @param authorCommits Commits which the relevant pull request no must be found + * @param githubToken Github access token for accessing github API + */ + public void findReviewers(Set authorCommits, String githubToken) { + + authorCommits.forEach(commitHash -> { + GithubApiCaller githubApiCaller = new GithubApiCaller(); + String jsonText = null; + + try { + jsonText = githubApiCaller.callSearchIssueApi(commitHash, githubToken); + Map> prNoWithRepoName = savePrNumberAndRepoName(jsonText); + saveReviewers(prNoWithRepoName, githubToken); + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e.getCause()); + } + }); + } + + /** + * This is used to save the pull requests with their relevant repository names in a map + * + * @param jsonText json reponse received from the github issue API + * @throws CodeQualityMatricesException + */ + public Map> savePrNumberAndRepoName(String jsonText) throws CodeQualityMatricesException { + + Gson gson = new Gson(); + // map for storing the pull requests numbers against their Repository + Map> prNoWithRepoName = new HashMap<>(); + try { + IssueApiResponse issueApiResponse = gson.fromJson(jsonText, IssueApiResponse.class); + + issueApiResponse.getItems().parallelStream().filter(searchItem -> GITHUB_REVIEW_API_CLOSED_STATE.equals(searchItem.getState()) + ).forEach(searchItem -> { + String repositoryName = StringUtils.substringAfter(searchItem.getRepositoryUrl(), "repos/"); + int pullRequestNo = searchItem.getNumber(); + prNoWithRepoName.putIfAbsent(repositoryName, new HashSet<>()); + if (!prNoWithRepoName.get(repositoryName).contains(pullRequestNo)) { + prNoWithRepoName.get(repositoryName).add(pullRequestNo); + } + + }); + } catch (JsonSyntaxException e) { + throw new CodeQualityMatricesException(e.getMessage(), e.getCause()); + } + return prNoWithRepoName; + } + + /** + * This is used to save the names of the users who has approved and commented on the pull requests which + * introduce bug lines of code to the code base. Approved users are saved in approvedReviewers list while + * commented users are saved in commentedReviewers list + * + * @param prNoWithRepoName Map containg the pull requests which introduce bug lines to the code base against the + * relevant reposiory + * @param githubToken Github access token for accessing github API + */ + + public void saveReviewers(Map> prNoWithRepoName, String githubToken) { + + for (Map.Entry entry : prNoWithRepoName.entrySet()) { + String repositoryName = (String) entry.getKey(); + Set prNumbers = (Set) entry.getValue(); + prNumbers.parallelStream().forEach(prNumber -> { + GithubApiCaller githubApiCaller = new GithubApiCaller(); + Gson gson = new Gson(); + try { + String jsonText = githubApiCaller.callReviewApi(repositoryName, prNumber, githubToken); + if (jsonText != null) { + List reviews = gson.fromJson(jsonText, List.class); + // to filter Approved users + reviews.parallelStream() + .filter(review -> GITHUB_REVIEW_APPROVED.equals(review.getState())) + .forEach(review -> approvedReviewers.add(review.getReviewer().getName())); + + logger.debug("Users who approved the pull requests which introduce bug lines to the code base are" + + " successfully saved to approvedReviewers list"); + + reviews.parallelStream() + .filter(review -> GITHUB_REVIEW_COMMENTED.equals(review.getState())) + .forEach(review -> commentedReviewers.add(review.getReviewer().getName())); + + logger.debug("Users who commented on the pull requests which introduce bug lines to the code base are" + + " successfully saved to approvedReviewers list"); + } else { + System.out.println("There are no records of reviews for pull request: " + prNumber + " on " + + repositoryName + " repository"); + logger.info("There are no records of reviews for pull request: " + prNumber + " on " + repositoryName + + " repository"); + } + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e.getCause()); + } + }); + } + } + + /** + * Print the list of reviewers and commented users on the pull requests which introduce bugs to the code base + */ + public void printReviewUsers() { + System.out.println("Reviewed and approved users of the bug lines: " + approvedReviewers); + System.out.println("Reviewed and commented users on bug lines: " + commentedReviewers); + } +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java deleted file mode 100644 index a6ad4d3..0000000 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Reviewer.java +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.wso2.code.quality.matrices; - -import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; -import org.json.JSONArray; -import org.json.JSONObject; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * This class is used to find the revierwers of the buggy lines of code - */ - -public class Reviewer { - - String searchPullReqeustAPIUrl; - String pullRequestReviewAPIUrl; - Set approvedReviewers = new HashSet(); // to store the reviewed and approved users of the pull requests - Set commentedReviewers = new HashSet(); // to store the reviewed and commented users of the pull requests - - private static final Logger logger = Logger.getLogger(Reviewer.class); - - //constants for accessing github API - private static final String GITHUB_REVIEW_API_STATE_KEY = "state"; - private static final String GITHUB_REVIEW_API_APPROVED_KEY = "APPROVED"; - private static final String GITHUB_REVIEW_API_COMMENTED_KEY = "COMMENTED"; - private static final String GITHUB_REVIEW_API_LOGIN_KEY = "login"; - private static final String GITHUB_REVIEW_API_USER_KEY = "user"; - private static final String GITHUB_REVIEW_API_ITEMS_KEY = "items"; - private static final String GITHUB_REVIEW_API_REPOSITORY_URL_KEY = "repository_url"; - private static final String GITHUB_REVIEW_API_NUMBER_KEY = "number"; - private static final String GITHUB_REVIEW_API_CLOSED_STATE_KEY = "closed"; - - - public String getSearchPullReqeustAPI() { - return searchPullReqeustAPIUrl; - } - - /** - * Sets the URL for Github Search API - * - * @param commitHashToBeSearched commit hash to be searched used for finding the Pull requests - */ - - public void setSearchPullReqeustAPI(String commitHashToBeSearched) { - this.searchPullReqeustAPIUrl = "https://api.github.com/search/issues?q=" + commitHashToBeSearched; - } - - public String getPullRequestReviewAPIUrl() { - return pullRequestReviewAPIUrl; - } - - public void setPullRequestReviewAPIUrl(String repoLocation, int pullRequestNumber) { - this.pullRequestReviewAPIUrl = "https://api.github.com/repos/" + repoLocation + "/pulls/" + pullRequestNumber + "/reviews"; - } - - // map for storing the pull requests numbers against their Repository - Map> mapContainingPRNoAgainstRepoName = new HashMap>(); - - /** - * for finding the reviewers of each commit and storing them in a Set - * - * @param commitHashObtainedForPRReview commit hash Set for finding the pull requests - * @param githubToken github token for accessing github REST API - */ - public void findReviewers(Set commitHashObtainedForPRReview, String githubToken, RestApiCaller restApiCaller) { - - commitHashObtainedForPRReview.stream() - .forEach(commitHashForFindingReviewers -> { - setSearchPullReqeustAPI(commitHashForFindingReviewers); - // calling the github search API - JSONObject rootJsonObject = null; - try { - rootJsonObject = (JSONObject) restApiCaller.callApi(getSearchPullReqeustAPI(), githubToken, false, true); - } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); - System.exit(1); - } - // reading thus saved json file - if (rootJsonObject != null) { - savePrNumberAndRepoName(rootJsonObject); - } - }); - - logger.info("PR numbers which introduce bug lines of code with their relevant Repository are saved successfully to mapContainingPRNoAgainstRepoName map"); - saveReviewersToList(githubToken, restApiCaller); - logger.info("List of approved reviwers and comment users of the PRs which introduce bug lines to Repository are saved in commentedReviewers and approvedReviewers list "); - // printing the list of reviewers of pull requests - printReviewUsers(); - logger.info("Names of approved reviewers and commented reviewers are printed successfully"); - } - - /** - * reads the search API output and save the pull request number with the repo name in a map - * - * @param rootJsonObject JSONObject received from github search API - */ - public void savePrNumberAndRepoName(JSONObject rootJsonObject) { - JSONArray itemsJsonArray = (JSONArray) rootJsonObject.get(GITHUB_REVIEW_API_ITEMS_KEY); - - Pmt.arrayToStream(itemsJsonArray) - .map(JSONObject.class::cast) - .filter(o -> o.get(GITHUB_REVIEW_API_STATE_KEY).equals(GITHUB_REVIEW_API_CLOSED_STATE_KEY)) - .forEach(prJsonObject -> { - String repositoryUrl = (String) prJsonObject.get(GITHUB_REVIEW_API_REPOSITORY_URL_KEY); - String repositoryLocation = StringUtils.substringAfter(repositoryUrl, "https://api.github.com/repos/"); - if (repositoryLocation.contains("wso2/")) { - // to filter out only the repositories belongs to wso2 - int pullRequetNumber = (int) prJsonObject.get(GITHUB_REVIEW_API_NUMBER_KEY); - mapContainingPRNoAgainstRepoName.putIfAbsent(repositoryLocation, new HashSet()); // put the repo name key only if it does not exists in the map - mapContainingPRNoAgainstRepoName.get(repositoryLocation).add(pullRequetNumber); // since SET is there we do not need to check for availability of the key in the map - } - }); - } - - /** - * Calling the github review API for a selected pull request on its relevant product - * - * @param githubToken github token for accessing github REST API - */ - public void saveReviewersToList(String githubToken, RestApiCaller restApiCaller) { - - for (Map.Entry m : mapContainingPRNoAgainstRepoName.entrySet()) { - String productLocation = (String) m.getKey(); - Set prNumbers = (Set) m.getValue(); - prNumbers.stream() - .forEach(prNumber -> { - setPullRequestReviewAPIUrl(productLocation, prNumber); - JSONArray reviewJsonArray = null; - try { - reviewJsonArray = (JSONArray) restApiCaller.callApi(getPullRequestReviewAPIUrl(), githubToken, false, true); - } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); - System.exit(1); - } - // for reading the output JSON from above and adding the reviewers to the Set - if (reviewJsonArray != null) { - readTheReviewOutJSON(reviewJsonArray, productLocation, prNumber); - } - - }); - } - } - - /** - * Reading the output received from the review API and saving the relevant reviewers and commented users to relevant Sets - * - * @param reviewJsonArray JSON response from the github Review API - * @param productLocation Product Location for printing the error message when there are no reviewers and a commented users - * @param prNumber relevant PR number for finding the reviewers and commenters - */ - public void readTheReviewOutJSON(JSONArray reviewJsonArray, String productLocation, int prNumber) { - - if (reviewJsonArray.length() != 0) { - Pmt.arrayToStream(reviewJsonArray) - .map(JSONObject.class::cast) - .forEach(reviewJsonObject->{ - addRelevantUsersToList(reviewJsonObject); - }); - -// for (Object object : reviewJsonArray) { -// if (object instanceof JSONObject) { -// JSONObject reviewJsonObject = (JSONObject) object; -// -// -// } -// } - } else { - System.out.println("There are no records of reviews for pull request: " + prNumber + " on " + productLocation + " Repository"); - logger.info("There are no records of reviews for pull request: " + prNumber + " on " + productLocation + " Repository"); - } - } - - /** - * This method is used for saving the relevant reviewers and commented users to relevant Sets - * - * @param reviewJsonObject jsonObject received from readTheReviewOutJSON method - */ - - public void addRelevantUsersToList(JSONObject reviewJsonObject) { - if ((reviewJsonObject.get(GITHUB_REVIEW_API_STATE_KEY)).equals(GITHUB_REVIEW_API_APPROVED_KEY)) { - - JSONObject userJsonObject = (JSONObject) reviewJsonObject.get(GITHUB_REVIEW_API_USER_KEY); - String approvedReviwer = (String) userJsonObject.get(GITHUB_REVIEW_API_LOGIN_KEY); - approvedReviewers.add(approvedReviwer); // adding the approved user to the Set - - } else if ((reviewJsonObject.get(GITHUB_REVIEW_API_STATE_KEY)).equals(GITHUB_REVIEW_API_COMMENTED_KEY)) { - JSONObject userJsonObject = (JSONObject) reviewJsonObject.get(GITHUB_REVIEW_API_USER_KEY); - String commentedReviwer = (String) userJsonObject.get(GITHUB_REVIEW_API_LOGIN_KEY); - commentedReviewers.add(commentedReviwer); // adding the commented user to the Set - } - } - - /** - * Print the list of reviewers and commented users on the pull requests which introduce bugs to the code base - */ - public void printReviewUsers() { - System.out.println("Reviewed and approved users of the bug lines: " + approvedReviewers); - System.out.println("Reviewed and commented users on bug lines: " + commentedReviewers); - } -} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java new file mode 100644 index 0000000..08b95d5 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +public class ReviewApiResponse { + private String state; + private Reviewer user; + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public Reviewer getReviewer() { + return user; + } + + public void setUser(Reviewer user) { + this.user = user; + } +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java new file mode 100644 index 0000000..8d53166 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +public class Reviewer { + private String login; + + public String getName() { + return login; + } + + public void setReviewer(String login) { + this.login = login; + } +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java index 0f0c4a0..7631af8 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java @@ -39,11 +39,11 @@ public void setNumber(int number) { this.number = number; } - public String getRepository_url() { + public String getRepositoryUrl() { return repository_url; } - public void setRepository_url(String repository_url) { + public void setRepositoryUrl(String repository_url) { this.repository_url = repository_url; } } From aca2f83381b0925eb48d3617e3b90046c66a80a4 Mon Sep 17 00:00:00 2001 From: kasun Date: Thu, 30 Mar 2017 10:39:59 +0530 Subject: [PATCH 42/62] Add java docs --- .../code/quality/matrices/ApiUtility.java | 18 ++- .../code/quality/matrices/ChangesFinder.java | 102 ++++++------ .../quality/matrices/CodeQualityMatrices.java | 28 ++-- .../quality/matrices/GithubApiCaller.java | 49 ++++-- .../wso2/code/quality/matrices/MainClass.java | 76 ++------- .../code/quality/matrices/PmtApiCaller.java | 13 +- .../code/quality/matrices/RestApiCaller.java | 150 ------------------ .../quality/matrices/RevieweAnalyser.java | 103 ++++++------ .../quality/matrices/SdkGitHubClient.java | 2 +- .../quality/matrices/SearchCommitPojo.java | 65 -------- .../code/quality/matrices/model/Graphql.java | 2 +- 11 files changed, 194 insertions(+), 414 deletions(-) delete mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java delete mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SearchCommitPojo.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java index 28805b1..fd845f9 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java @@ -32,7 +32,9 @@ import java.io.UnsupportedEncodingException; /** - * This is a utility class for calling APIs + * This is a utility class for calling APIs. + * + * @since 1.0.0 */ public final class ApiUtility { // to prevent instantiation @@ -42,6 +44,13 @@ private ApiUtility() { private static Logger logger = Logger.getLogger(ApiUtility.class); + /** + * This is used for calling the REST APIs. + * + * @param httpGet Instance of the relevant httpGet + * @return String representation of the json response + * @throws CodeQualityMatricesException + */ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesException { BufferedReader bufferedReader = null; CloseableHttpClient httpClient = null; @@ -100,6 +109,13 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio return jsonText; } + /** + * This is used for calling the github graphql API. + * + * @param httpPost relevant instance of the httpost + * @return String representation of the json response + * @throws CodeQualityMatricesException + */ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatricesException { BufferedReader bufferedReader = null; CloseableHttpClient httpClient = null; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index ebd6e9f..b29c336 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -38,7 +38,8 @@ import java.util.stream.IntStream; /** - * This class is used for getting the blame information on relevant lines changed from the given patch + * This class is used for getting the blame information on relevant changed line ranges on relevant files from the + * given patch. * * @since 1.0.0 */ @@ -53,6 +54,9 @@ public class ChangesFinder { protected Set authorNames = new HashSet<>(); //authors of the bug lines fixed from the patch protected Set authorCommits = new HashSet<>(); // author commits of the bug lines fixed from the patch + private GithubApiCaller githubApiCaller = new GithubApiCaller(); + private Gson gson = new Gson(); + private static final Logger logger = Logger.getLogger(ChangesFinder.class); /** @@ -63,8 +67,7 @@ public class ChangesFinder { * @return author commits of the bug lines which are fixed from the given patch */ - public Set obtainRepoNamesForCommitHashes(String gitHubToken, List commitHashes) { - GithubApiCaller githubApiCaller = new GithubApiCaller(); + public Set obtainRepoNamesForCommitHashes(String gitHubToken, List commitHashes) { commitHashes.forEach(commitHash -> { try { @@ -79,26 +82,24 @@ public Set obtainRepoNamesForCommitHashes(String gitHubToken, List commi } /** - * Saving the relevant repo Names in List + * Saving the relevant repository names that contain the given commit hash in a List. * - * @param jsonText - * @param commitHash - * @param gitHubToken + * @param jsonText String representation of the json response + * @param commitHash commit hash to be searched for containing WSO2 repositories + * @param gitHubToken Github access token for accessing github API */ public void saveRepoNames(String jsonText, String commitHash, String gitHubToken) throws CodeQualityMatricesException { List repoLocation = new ArrayList<>(); - Gson gson = new Gson(); SearchApiResponse searchCommitPojo; try { searchCommitPojo = gson.fromJson(jsonText, SearchApiResponse.class); } catch (JsonSyntaxException e) { throw new CodeQualityMatricesException(e.getMessage(), e.getCause()); } - searchCommitPojo.getItems().forEach(recordItem -> { - repoLocation.add(recordItem.getRepository().getFull_name()); + searchCommitPojo.getItems() + .forEach(recordItem -> repoLocation.add(recordItem.getRepository().getFull_name())); - }); - logger.info("Repo names having the given commit are successfully saved in an array"); + logger.info("All the repository names having the given commit are successfully saved in an array"); SdkGitHubClient sdkGitHubClient = new SdkGitHubClient(gitHubToken); repoLocation.stream() @@ -109,14 +110,14 @@ public void saveRepoNames(String jsonText, String commitHash, String gitHubToken fileNames.clear(); changedLineRanges.clear(); patchString.clear(); - Map> fileNamesAndPatches = null; + Map> fileNamesWithPatcheString = null; try { - fileNamesAndPatches = sdkGitHubClient.getFilesChanged(repositoryName, commitHash); + fileNamesWithPatcheString = sdkGitHubClient.getFilesChanged(repositoryName, commitHash); } catch (CodeQualityMatricesException e) { logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside a lambda expression } - fileNames = fileNamesAndPatches.get("fileNames"); - patchString = fileNamesAndPatches.get("patchString"); + fileNames = fileNamesWithPatcheString.get("fileNames"); + patchString = fileNamesWithPatcheString.get("patchString"); saveRelaventEditLineNumbers(fileNames, patchString); try { iterateOverFileChanges(repositoryName, commitHash, gitHubToken); @@ -129,7 +130,8 @@ public void saveRepoNames(String jsonText, String commitHash, String gitHubToken } /** - * This method is used to save the line ranges being modified in a given file to a list and add that list to the root list of + * This method is used to save the line ranges being modified in a given file to a list and add that list to the + * root list of. * * @param fileNames Arraylist of files names that are being affected by the relevant commit * @param patchString Array list having the patch string value for each of the file being changed @@ -165,18 +167,19 @@ public void saveRelaventEditLineNumbers(ArrayList fileNames, ArrayList tempArrayList = new ArrayList<>(Arrays.asList(lineChanges)); + ArrayList changedRange = new ArrayList<>(Arrays.asList(lineChanges)); //adding to the array list which keep track of the line ranges being changed - changedLineRanges.add(tempArrayList); + changedLineRanges.add(changedRange); }); System.out.println("done saving file names and their relevant modification line ranges"); + logger.debug("done saving file names and their relevant modification line ranges"); System.out.println(fileNames); System.out.println(changedLineRanges + "\n"); } /** - * This method will iterate over the saved filenames and their relevant changed line ranges and calls the github graphQL API - * for getting blame details for each of the files + * This will iterate over the saved filenames and their relevant changed line ranges and calls the github graphQL API + * for getting blame details for each of the files. * * @param repoLocation current selected Repository * @param commitHash current selected Repository @@ -202,16 +205,15 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin String jsonText = null; try { // calling the graphql API for getting blame information for the current file. - GithubApiCaller githubApiCaller = new GithubApiCaller(); jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); } catch (CodeQualityMatricesException e) { logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside lambda expression - System.exit(1); } //reading the above saved output for the current selected file name try { readBlameForSelectedFile(jsonText, lineRangesForSelectedFile); + logger.debug("Parent commits are saved for the " + fileName + " for all the modified line ranges"); } catch (CodeQualityMatricesException e) { logger.error(e.getMessage(), e.getCause()); } @@ -227,7 +229,7 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin /** * This reads the blame received for the current selected file and insert parent commits of the changed lines - * to a list + * to a list. * * @param jsonText JSON response of blame of the selected file * @param changedRangesOfSelectedFile arraylist containing the changed line ranges of the current selected file @@ -235,7 +237,6 @@ public void iterateOverFileChanges(String repoLocation, String commitHash, Strin public void readBlameForSelectedFile(String jsonText, ArrayList changedRangesOfSelectedFile) throws CodeQualityMatricesException { - Gson gson = new Gson(); GraphQlResponse graphQlResponse = null; try { graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); @@ -288,17 +289,14 @@ public void readBlameForSelectedFile(String jsonText, TreeMap> sortedAgeWithParentCommit = new TreeMap<>(ageWithParentCommit); Set parentCommit = sortedAgeWithParentCommit.get(sortedAgeWithParentCommit.firstKey()); parentCommitHashes.put(oldFileRange, parentCommit); - } - - }); } /** * This is used to find the author and author commits of the buggy lines of code which are been fixed by the - * given patch + * given patch. * * @param owner owner of the selected epository * @param repositoryName selected repository name @@ -311,37 +309,37 @@ public void findAuthorCommits(String owner, String repositoryName, String fileNa String oldRange = (String) entry.getKey(); Set commitHashes = (Set) entry.getValue(); Graphql graphqlBean = new Graphql(); - GithubApiCaller githubApiCaller = new GithubApiCaller(); - commitHashes.parallelStream().forEach(commitHash -> { - - graphqlBean.setGraphqlInputWithoutHistory(owner, repositoryName, commitHash, fileName); - jsonStructure.put("query", graphqlBean.getGraphqlInputWithoutHistory()); - // jsonStructure calling the graphql API for getting blame information for the current file. - - String jsonText = null; - try { - jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); - } catch (CodeQualityMatricesException e) { - logger.debug(e.getMessage(), e.getCause()); - } + commitHashes.parallelStream() + .forEach(commitHash -> { + + graphqlBean.setGraphqlInputWithoutHistory(owner, repositoryName, commitHash, fileName); + jsonStructure.put("query", graphqlBean.getGraphqlInputWithoutHistory()); + String jsonText = null; + try { + jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); + } catch (CodeQualityMatricesException e) { + logger.debug(e.getMessage(), e.getCause()); + } - saveAuthorCommits(jsonText, oldRange, lineRangesForSelectedFile); - }); + saveAuthorCommits(jsonText, oldRange, lineRangesForSelectedFile); + }); } + logger.debug("author commits and authors of bug lines of code on " + fileName + " file which are been fixed by " + + "the given patch are successfully saved to lists"); + } /** * This is used to save the authors and author commits of the buggy lines of code which are been fixed by the - * given patch, to relevant lists + * given patch, to relevant lists. * - * @param jsonText - * @param oldRange - * @param lineRangesForSelectedFile + * @param jsonText String representation of the json response + * @param oldRange Range to select the correct range for collecting author commits + * @param lineRangesForSelectedFile arraylist containing the changed line ranges of the current selected file */ public void saveAuthorCommits(String jsonText, String oldRange, ArrayList lineRangesForSelectedFile) { - Gson gson = new Gson(); GraphQlResponse graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); lineRangesForSelectedFile.forEach(lineRange -> { @@ -350,7 +348,7 @@ public void saveAuthorCommits(String jsonText, String oldRange, ArrayList { String authorName = graphqlRange.getCommit().getAuthor().getName(); - String authorcommitUrl = StringUtils.substringAfter(graphqlRange.getCommit().getUrl(), + String authorcommit = StringUtils.substringAfter(graphqlRange.getCommit().getUrl(), "commit/"); authorNames.add(authorName); // authors are added to the Set - authorCommits.add(authorcommitUrl); // author commits are added to the set + authorCommits.add(authorcommit); // author commits are added to the set }); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java index 9f54835..a986bb8 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java @@ -27,7 +27,9 @@ import java.util.Set; /** + * This is used for creating executing the program. * + * @since 1.0.0 */ public class CodeQualityMatrices { private String pmtToken; @@ -37,9 +39,11 @@ public class CodeQualityMatrices { private final static Logger logger = Logger.getLogger(CodeQualityMatrices.class); /** - * @param pmtToken - * @param patchId - * @param gitHubToken + * This create an instance of CodeQualityMatrices class. + * + * @param pmtToken PMT Access Token + * @param patchId Patch ID + * @param gitHubToken Github access token */ public CodeQualityMatrices(String pmtToken, String patchId, String gitHubToken) { this.pmtToken = pmtToken; @@ -49,26 +53,30 @@ public CodeQualityMatrices(String pmtToken, String patchId, String gitHubToken) } /** - * + * This is the entry point to this application. */ public void execute() { try { - ChangesFinder changesFinder = new ChangesFinder(); List commitHashes = findCommitHashesInPatch(); + ChangesFinder changesFinder = new ChangesFinder(); Set authorCommits = changesFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitHashes); - System.out.println("Author Commits"+authorCommits); + System.out.println("Author Commits" + authorCommits); + RevieweAnalyser revieweAnalyser = new RevieweAnalyser(); + revieweAnalyser.findReviewers(authorCommits, gitHubToken); + revieweAnalyser.printReviewUsers(); - } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e); + logger.debug("The application executed successfully"); + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e.getCause()); } - - } /** + * This is used to filter out the commit hashes that belongs to the given patch * + * @return List of commithashes contained in the given patch */ public List findCommitHashesInPatch() throws CodeQualityMatricesException { PmtApiCaller pmtApiCaller = new PmtApiCaller(); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java index 4c723aa..38ec44b 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java @@ -26,15 +26,20 @@ import java.io.UnsupportedEncodingException; /** - * This is used for all github communications + * This is used for all github communications. + * + * @since 1.0.0 */ public class GithubApiCaller { private HttpGet httpGet; private HttpPost httpPost; /** - * @param commitHash - * @param githubAccessToken + * This is used for calling the github search REST API. + * + * @param commitHash commit hash to be searched + * @param githubAccessToken Github access token for accessing github API + * @return String representation of the json response * @throws CodeQualityMatricesException */ public String callSearchCommitApi(String commitHash, String githubAccessToken) throws CodeQualityMatricesException { @@ -52,12 +57,15 @@ public String callSearchCommitApi(String commitHash, String githubAccessToken) t } /** - * @param repoLocation - * @param pullRequestNumber - * @param githubAccessToken + * This is used to call the github review API. + * + * @param repoLocation repository name + * @param pullRequestNumber pull request number to be queried for + * @param githubAccessToken Github access token for accessing github API + * @return String representation of the json response * @throws CodeQualityMatricesException */ - public String callReviewApi(String repoLocation, String pullRequestNumber, String githubAccessToken) throws + public String callReviewApi(String repoLocation, int pullRequestNumber, String githubAccessToken) throws CodeQualityMatricesException { String url = "https://api.github.com/repos/" + repoLocation + "/pulls/" + pullRequestNumber + "/reviews"; try { @@ -72,8 +80,11 @@ public String callReviewApi(String repoLocation, String pullRequestNumber, Strin } /** - * @param commitHashToBeSearched - * @param githubAccessToken + * This is used to call the github Issue Search API. + * + * @param commitHashToBeSearched commit hash to be searched for issues + * @param githubAccessToken Github access token for accessing github API + * @return String representation of the json response * @throws CodeQualityMatricesException */ public String callSearchIssueApi(String commitHashToBeSearched, String githubAccessToken) throws @@ -90,7 +101,16 @@ public String callSearchIssueApi(String commitHashToBeSearched, String githubAcc return ApiUtility.callApi(httpGet); } - public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken) throws CodeQualityMatricesException { + /** + * This is used for calling the github graphql API. + * + * @param graphqlJsonStructure JSON input structure for calling the graphql API + * @param githubToken Github access token for accessing github API + * @return String representation of the json response + * @throws CodeQualityMatricesException + */ + public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken) throws + CodeQualityMatricesException { String url = "https://api.github.com/graphql"; try { httpPost = new HttpPost(url); @@ -101,12 +121,11 @@ public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the Github Graphql API is " + - "invalid",e); - } - catch (UnsupportedEncodingException e){ + "invalid", e); + } catch (UnsupportedEncodingException e) { throw new CodeQualityMatricesException("An error occurred when creating the String entity from Json " + - "Structure",e); - } + "Structure", e); + } return ApiUtility.callGraphQlApi(httpPost); } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index fab67b5..8182b72 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -21,13 +21,12 @@ import org.apache.log4j.Logger; /** - * This is the class having the main method of this application + * This is having the main method of this application * PMT Access token, patch id and github access token - * should be passed in order as command line arguments when running the application + * should be passed in order as command line arguments when running the application. */ public class MainClass { private final static Logger logger = Logger.getLogger(MainClass.class); - public static final String COMMITS_INSIDE_GIVEN_PATCH = "patchInformation_svnRevisionpublic"; public static void main(String[] args) { if (args.length == 3) { @@ -36,69 +35,12 @@ public static void main(String[] args) { String patchId = args[1]; String gitHubToken = args[2]; - CodeQualityMatrices codeQualityMatrices= new CodeQualityMatrices(pmtToken,patchId,gitHubToken); + CodeQualityMatrices codeQualityMatrices = new CodeQualityMatrices(pmtToken, patchId, gitHubToken); codeQualityMatrices.execute(); - -// PmtApiCaller pmtApiCaller = new PmtApiCaller(); -// String jsonText = null; -// List commitHashes= new ArrayList<>(); -// -// try { -// jsonText = pmtApiCaller.callApi(pmtToken, patchId); -// } catch (CodeQualityMatricesException e) { -// logger.error("Error occurred while calling PMT API", e); -// } -// -// Gson gson = new Gson(); -// -// if (jsonText != null) { -// List pmtResponse = gson.fromJson(jsonText, List.class); -// for(Object pmtEntry : pmtResponse){ -// if(pmtEntry instanceof Map){ -// Map> entryMap= (Map>)pmtEntry; -// if(COMMITS_INSIDE_GIVEN_PATCH.equals(entryMap.get("name"))){ -// commitHashes=entryMap.get("values"); -// -// -// } -// -// } -// } -// } - -// String pmtUrl = "fda"; -// RestApiCaller restApiCaller = new RestApiCaller(); -// JSONArray jsonArray = null; -// try { -// jsonArray = (JSONArray) restApiCaller.callApi(pmtUrl, pmtToken, false, false); -// } catch (CodeQualityMatricesException e) { -// logger.error(e.getMessage(), e.getCause()); -// System.exit(1); -// } -// logger.info("JSON response is received successfully from WSO2 PMT for the given patch " + args[1]); -// -// Pmt pmt = new Pmt(); -// String[] commitsInTheGivenPatch = null; -// if (jsonArray != null) { -// commitsInTheGivenPatch = pmt.getPublicGitCommitHashes(jsonArray); -// } -// logger.info("Commits received from WSO2 PMT are saved in an array successfully"); -// -// -// ChangesFinder changesFinder = new ChangesFinder(); -// Set authorCommits = null; -// if (commitsInTheGivenPatch != null) { -// authorCommits = changesFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitsInTheGivenPatch, restApiCaller); -// } -// logger.info("Author commits that introduce bug lines of code to the Repository are saved in authorCommits SET successfully"); -// -// Reviewer reviewer = new Reviewer(); -// if (authorCommits != null) { -// reviewer.findReviewers(authorCommits, gitHubToken, restApiCaller); -// } -// } else { -// logger.error("at least one of the command line arguments are null."); -// System.exit(4); -// } - }} + } else { + logger.error("Command line arguments were not given correctly to start the execution"); + System.out.println("Please enter PMT Access token, patch id and github access token in order as command " + + "line arguments to initiate the program"); + } + } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java index 47144e7..8478f40 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java @@ -20,15 +20,22 @@ import org.apache.http.client.methods.HttpGet; +/** + * This is used for all the WSO2 PMT communications. + * + * @since 1.0.0 + */ public class PmtApiCaller { public PmtApiCaller() { } /** - * @param accessToken - * @param patchId - * @return + * This is used for calling the WSO2 PMT REST API. + * + * @param accessToken WSO2 PMT access token + * @param patchId Patch Id + * @return String representation of the json response * @throws CodeQualityMatricesException */ public String callApi(String accessToken, String patchId) throws CodeQualityMatricesException { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java deleted file mode 100644 index 0e2a8ef..0000000 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RestApiCaller.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.wso2.code.quality.matrices; - -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.log4j.Logger; -import org.json.JSONArray; -import org.json.JSONObject; -import org.json.JSONTokener; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; - -/** - * This class is used to callApi the REST API of both WSO2 PMT and github.com - */ - -public class RestApiCaller { - - private static Logger logger = Logger.getLogger(RestApiCaller.class); - - /** - * calling the relevant API and saving the output to a file - * - * @param URL url of the REST API to be called - * @param accessToken either the WSO2 PMT access accessToken or giihub.com access accessToken - * @param requireCommitHeader should be true for accessing the github commit search API and false otherwise - * @param requireReviewHeader should be true for accessing the github review API or false otherwise - */ - - public Object callApi(String URL, String accessToken, boolean requireCommitHeader, boolean requireReviewHeader) throws CodeQualityMatricesException { - - BufferedReader bufferedReader = null; - CloseableHttpClient httpclient = null; - CloseableHttpResponse httpResponse = null; - Object returnedObject = null; - - try { - httpclient = HttpClients.createDefault(); - HttpGet httpGet = new HttpGet(URL); - - if (accessToken != null) { - - httpGet.addHeader("Authorization", "Bearer " + accessToken); // passing the accessToken for the API callApi - } - - //as the accept header is needed for the review API since it is still in preview mode - if (requireReviewHeader) { - httpGet.addHeader("Accept", "application/vnd.github.black-cat-preview+json"); - } - - //as the accept header is needed for accessing commit search API which is still in preview mode - if (requireCommitHeader) { - httpGet.addHeader("Accept", "application/vnd.github.cloak-preview"); - } - - httpResponse = httpclient.execute(httpGet); - int responseCode = httpResponse.getStatusLine().getStatusCode(); // to get the response code - - switch (responseCode) { - case 200: - //success - bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8")); - StringBuilder stringBuilder = new StringBuilder(); - String line; - while ((line = bufferedReader.readLine()) != null) { - stringBuilder.append(line); - } - - // creating a JSON object from the response - String JSONText = stringBuilder.toString(); - Object json = new JSONTokener(JSONText).nextValue(); // gives an object http://stackoverflow.com/questions/14685777/how-to-check-if-response-from-server-is-jsonaobject-or-jsonarray - - if (json instanceof JSONObject) { - JSONObject jsonObject = (JSONObject) json; - returnedObject = jsonObject; - } else if (json instanceof JSONArray) { - JSONArray jsonArray = (JSONArray) json; - returnedObject = jsonArray; - } - logger.info("JSON response is passed after calling the given REST API"); - break; - case 401: - // to handle Response code 401: Unauthorized - throw new CodeQualityMatricesException("Response code 401 : Github access token is invalid"); - case 403: - // to handle invalid credentials - throw new CodeQualityMatricesException("Response Code:403 Invalid Credentials, insert a correct token for PMT"); - case 404: - // to handle invalid patch - throw new CodeQualityMatricesException("Response Code 404: Patch not found, enter a valid patch"); - default: - returnedObject = null; - } - - } catch (ClientProtocolException e) { - throw new CodeQualityMatricesException("ClientProtocolException when calling the REST API", e); - - } catch (IOException e) { - throw new CodeQualityMatricesException("IOException occurred when calling the REST API", e); - } finally { - if (bufferedReader != null) { - try { - bufferedReader.close(); - } catch (IOException e) { - throw new CodeQualityMatricesException("IOException occurred when closing the BufferedReader", e); - } - } - if (httpResponse != null) { - try { - httpResponse.close(); - } catch (IOException e) { - throw new CodeQualityMatricesException("IOException occurred when closing the HttpResponse", e); - } - } - if (httpclient != null) { - try { - httpclient.close(); - } catch (IOException e) { - throw new CodeQualityMatricesException("IOException occurred when closing the HttpClient", e); - } - } - } - return returnedObject; - } -} - - - diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java index 9d57c46..d8824dd 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java @@ -32,15 +32,17 @@ import java.util.Set; /** - * This class is used to find the revierwers of the buggy lines of code + * This class is used to find the reviewers of the buggy lines of code. * * @since 1.0.0 */ public class RevieweAnalyser { - Set approvedReviewers = new HashSet<>(); // to store the reviewed and approved users of the pull requests - Set commentedReviewers = new HashSet<>(); // to store the reviewed and commented users of the pull requests + private Set approvedReviewers = new HashSet<>(); // to store the reviewed and approved users of the pull + // requests + private Set commentedReviewers = new HashSet<>(); // to store the reviewed and commented users of the pull + // requests private static final Logger logger = Logger.getLogger(RevieweAnalyser.class); @@ -48,9 +50,11 @@ public class RevieweAnalyser { private static final String GITHUB_REVIEW_APPROVED = "APPROVED"; private static final String GITHUB_REVIEW_COMMENTED = "COMMENTED"; private static final String GITHUB_REVIEW_API_CLOSED_STATE = "closed"; + private GithubApiCaller githubApiCaller = new GithubApiCaller(); + private Gson gson = new Gson(); /** - * This is used to identify the pull requests that introduce the given commit to the code base + * This is used to identify the pull requests that introduce the given commit to the code base. * * @param authorCommits Commits which the relevant pull request no must be found * @param githubToken Github access token for accessing github API @@ -58,12 +62,12 @@ public class RevieweAnalyser { public void findReviewers(Set authorCommits, String githubToken) { authorCommits.forEach(commitHash -> { - GithubApiCaller githubApiCaller = new GithubApiCaller(); String jsonText = null; try { jsonText = githubApiCaller.callSearchIssueApi(commitHash, githubToken); Map> prNoWithRepoName = savePrNumberAndRepoName(jsonText); + logger.debug("Pull requests with their relevant repository names are successfully saved in a map."); saveReviewers(prNoWithRepoName, githubToken); } catch (CodeQualityMatricesException e) { logger.error(e.getMessage(), e.getCause()); @@ -72,29 +76,31 @@ public void findReviewers(Set authorCommits, String githubToken) { } /** - * This is used to save the pull requests with their relevant repository names in a map + * This is used to save the pull requests with their relevant repository names in a map. * * @param jsonText json reponse received from the github issue API + * @return a map of pull requests againt their repository name * @throws CodeQualityMatricesException */ public Map> savePrNumberAndRepoName(String jsonText) throws CodeQualityMatricesException { - Gson gson = new Gson(); // map for storing the pull requests numbers against their Repository Map> prNoWithRepoName = new HashMap<>(); try { IssueApiResponse issueApiResponse = gson.fromJson(jsonText, IssueApiResponse.class); - issueApiResponse.getItems().parallelStream().filter(searchItem -> GITHUB_REVIEW_API_CLOSED_STATE.equals(searchItem.getState()) - ).forEach(searchItem -> { - String repositoryName = StringUtils.substringAfter(searchItem.getRepositoryUrl(), "repos/"); - int pullRequestNo = searchItem.getNumber(); - prNoWithRepoName.putIfAbsent(repositoryName, new HashSet<>()); - if (!prNoWithRepoName.get(repositoryName).contains(pullRequestNo)) { - prNoWithRepoName.get(repositoryName).add(pullRequestNo); - } - - }); + issueApiResponse.getItems().parallelStream() + .filter(searchItem -> GITHUB_REVIEW_API_CLOSED_STATE.equals(searchItem.getState())) + .filter(searchItem -> StringUtils.contains(searchItem.getRepositoryUrl(), "/wso2/")) + .forEach(searchItem -> { + String repositoryName = StringUtils.substringAfter(searchItem.getRepositoryUrl(), "repos/"); + int pullRequestNo = searchItem.getNumber(); + prNoWithRepoName.putIfAbsent(repositoryName, new HashSet<>()); + if (!prNoWithRepoName.get(repositoryName).contains(pullRequestNo)) { + prNoWithRepoName.get(repositoryName).add(pullRequestNo); + } + + }); } catch (JsonSyntaxException e) { throw new CodeQualityMatricesException(e.getMessage(), e.getCause()); } @@ -110,43 +116,42 @@ public Map> savePrNumberAndRepoName(String jsonText) throws * relevant reposiory * @param githubToken Github access token for accessing github API */ - public void saveReviewers(Map> prNoWithRepoName, String githubToken) { for (Map.Entry entry : prNoWithRepoName.entrySet()) { String repositoryName = (String) entry.getKey(); Set prNumbers = (Set) entry.getValue(); - prNumbers.parallelStream().forEach(prNumber -> { - GithubApiCaller githubApiCaller = new GithubApiCaller(); - Gson gson = new Gson(); - try { - String jsonText = githubApiCaller.callReviewApi(repositoryName, prNumber, githubToken); - if (jsonText != null) { - List reviews = gson.fromJson(jsonText, List.class); - // to filter Approved users - reviews.parallelStream() - .filter(review -> GITHUB_REVIEW_APPROVED.equals(review.getState())) - .forEach(review -> approvedReviewers.add(review.getReviewer().getName())); - - logger.debug("Users who approved the pull requests which introduce bug lines to the code base are" + - " successfully saved to approvedReviewers list"); - - reviews.parallelStream() - .filter(review -> GITHUB_REVIEW_COMMENTED.equals(review.getState())) - .forEach(review -> commentedReviewers.add(review.getReviewer().getName())); - - logger.debug("Users who commented on the pull requests which introduce bug lines to the code base are" + - " successfully saved to approvedReviewers list"); - } else { - System.out.println("There are no records of reviews for pull request: " + prNumber + " on " + - repositoryName + " repository"); - logger.info("There are no records of reviews for pull request: " + prNumber + " on " + repositoryName + - " repository"); - } - } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); - } - }); + prNumbers.parallelStream() + .forEach(prNumber -> { + + try { + String jsonText = githubApiCaller.callReviewApi(repositoryName, prNumber, githubToken); + if (jsonText != null) { + List reviews = gson.fromJson(jsonText, List.class); + // to filter Approved users + reviews.parallelStream() + .filter(review -> GITHUB_REVIEW_APPROVED.equals(review.getState())) + .forEach(review -> approvedReviewers.add(review.getReviewer().getName())); + + logger.debug("Users who approved the pull requests which introduce bug lines to the code base are" + + " successfully saved to approvedReviewers list"); + + reviews.parallelStream() + .filter(review -> GITHUB_REVIEW_COMMENTED.equals(review.getState())) + .forEach(review -> commentedReviewers.add(review.getReviewer().getName())); + + logger.debug("Users who commented on the pull requests which introduce bug lines to the code base are" + + " successfully saved to approvedReviewers list"); + } else { + System.out.println("There are no records of reviews for pull request: " + prNumber + " on " + + repositoryName + " repository"); + logger.info("There are no records of reviews for pull request: " + prNumber + " on " + repositoryName + + " repository"); + } + } catch (CodeQualityMatricesException e) { + logger.error(e.getMessage(), e.getCause()); + } + }); } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java index 0919d91..26b0ffa 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java @@ -54,7 +54,7 @@ public class SdkGitHubClient { /** * This method is used for saving the files changed and their relevant changed line ranges from - * the given commit in the given Repository + * the given commit in the given Repository. * * @param repositoryName The Repository name that contain the given commit hash * @param commitHash The querying commit hash diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SearchCommitPojo.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SearchCommitPojo.java deleted file mode 100644 index 12354ff..0000000 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SearchCommitPojo.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.wso2.code.quality.matrices; - -import java.util.List; - -public class SearchCommitPojo { -private int total_count; -private List items; - - public int getTotal_count() { - return total_count; - } - - public void setTotal_count(int total_count) { - this.total_count = total_count; - } - - public List getItems() { - return items; - } - - public void setItems(List Items) { - this.items = Items; - } -} - -class Item { - private Repository repository; - - public Repository getRepository() { - return repository; - } - - public void setRepository(Repository Repository) { - this.repository = Repository; - } -} -class Repository { - private String full_name; - - public String getFull_name() { - return full_name; - } - - public void setFull_name(String full_name) { - this.full_name = full_name; - } -} \ No newline at end of file diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java index 3a323a4..93b91cc 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java @@ -21,7 +21,7 @@ import java.io.Serializable; /** - * This is a bean class used to set the json structures for calling the github graphql API + * This is a bean class used to set the json input structures for calling the github graphql API. * * @since 1.0.0 */ From a9cb37cd653701c14d17b327355432a1243f6016 Mon Sep 17 00:00:00 2001 From: kasun Date: Thu, 30 Mar 2017 11:05:17 +0530 Subject: [PATCH 43/62] Delete unused classes --- .../code/quality/matrices/ApiUtility.java | 2 +- .../code/quality/matrices/ChangesFinder.java | 2 +- .../quality/matrices/GithubApiCaller.java | 2 +- .../quality/matrices/GraphQlApiCaller.java | 124 ------------------ .../com/wso2/code/quality/matrices/Pmt.java | 103 --------------- .../quality/matrices/RevieweAnalyser.java | 3 +- .../quality/matrices/SdkGitHubClient.java | 6 +- 7 files changed, 9 insertions(+), 233 deletions(-) delete mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java delete mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java index fd845f9..c737045 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java @@ -135,7 +135,7 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatrice stringBuilder.append(line); } jsonText = stringBuilder.toString(); - logger.info("The response received from the Github GraphQL converted to a JSON text successfully"); + logger.debug("The response received from the Github GraphQL converted to a JSON text successfully"); } else { throw new CodeQualityMatricesException("Error occurred while calling the API, the response code is " + diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index b29c336..407fc23 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -99,7 +99,7 @@ public void saveRepoNames(String jsonText, String commitHash, String gitHubToken searchCommitPojo.getItems() .forEach(recordItem -> repoLocation.add(recordItem.getRepository().getFull_name())); - logger.info("All the repository names having the given commit are successfully saved in an array"); + logger.debug("All the repository names having the given commit are successfully saved in an array"); SdkGitHubClient sdkGitHubClient = new SdkGitHubClient(gitHubToken); repoLocation.stream() diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java index 38ec44b..8e0c034 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java @@ -32,7 +32,6 @@ */ public class GithubApiCaller { private HttpGet httpGet; - private HttpPost httpPost; /** * This is used for calling the github search REST API. @@ -112,6 +111,7 @@ public String callSearchIssueApi(String commitHashToBeSearched, String githubAcc public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken) throws CodeQualityMatricesException { String url = "https://api.github.com/graphql"; + HttpPost httpPost; try { httpPost = new HttpPost(url); httpPost.addHeader("Authorization", "Bearer " + githubToken); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java deleted file mode 100644 index d0cc269..0000000 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GraphQlApiCaller.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.wso2.code.quality.matrices; - -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.log4j.Logger; -import org.json.JSONArray; -import org.json.JSONObject; -import org.json.JSONTokener; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; - -/** - * This class is used for calling the GithubGraphQL API which is currently in early access mode. - * - * @since 1.0.0 - */ - -public class GraphQlApiCaller { - - protected static final Logger logger = Logger.getLogger(GraphQlApiCaller.class); - - /** - * Calls the github graphQL API and returns the relevant JSON response received - * - * @param queryObject the JSONObject required for querying - * @param gitHubToken github token for accessing github GraphQL API - * @return Depending on the content return a JSONObject or a JSONArray - * @throws IOException - */ - public Object callGraphQlApi(JSONObject queryObject, String gitHubToken) throws CodeQualityMatricesException { - - CloseableHttpClient client = null; - CloseableHttpResponse response = null; - BufferedReader bufferedReader = null; - - Object returnedObject = null; - - try { - client = HttpClients.createDefault(); - HttpPost httpPost = new HttpPost("https://api.github.com/graphql"); - httpPost.addHeader("Authorization", "Bearer " + gitHubToken); - httpPost.addHeader("Accept", "application/json"); - StringEntity entity = new StringEntity(queryObject.toString()); - httpPost.setEntity(entity); - response = client.execute(httpPost); - int responseCode = response.getStatusLine().getStatusCode(); - - switch (responseCode) { - case 200: - - bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); - String line; - StringBuilder stringBuilder = new StringBuilder(); - while ((line = bufferedReader.readLine()) != null) { - stringBuilder.append(line); - } - - String jsonText = stringBuilder.toString(); - logger.info("The response received from the Github GraphQL converted to a JSON text successfully"); - - Object json = new JSONTokener(jsonText).nextValue(); // gives an object http://stackoverflow.com/questions/14685777/how-to-check-if-response-from-server-is-jsonaobject-or-jsonarray - - if (json instanceof JSONObject) { - JSONObject jsonObject = (JSONObject) json; - returnedObject = jsonObject; - logger.info("JSONObject was returned successfully after calling the GraphQL API"); - } else if (json instanceof JSONArray) { - JSONArray jsonArray = (JSONArray) json; - returnedObject = jsonArray; - logger.info("JSONArray was returned successfully after calling the GraphQL API"); - } - break; - - case 401: - // to handle Response code 401: Unauthorized - throw new CodeQualityMatricesException("Response code 401 : Git hub access token is invalid"); - default: - returnedObject = null; - } - } catch (UnsupportedEncodingException e) { - throw new CodeQualityMatricesException("Encoding error occured before calling the github graphQL API", e); - } catch (ClientProtocolException e) { - throw new CodeQualityMatricesException("Client protocol exception occurred when calling the github graphQL API", e); - } catch (IOException e) { - throw new CodeQualityMatricesException("IO Exception occured when calling the github graphQL API", e); - } catch (Exception e) { - throw new CodeQualityMatricesException("Exception occurred when reading the response received from github graphQL API", e); - } finally { - if (bufferedReader != null) { - try { - bufferedReader.close(); - } catch (IOException e) { - throw new CodeQualityMatricesException("IOException occurred when closing the buffered reader", e); - } - } - } - return returnedObject; - } -} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java deleted file mode 100644 index acbb3a2..0000000 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Pmt.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.wso2.code.quality.matrices; - -import org.apache.log4j.Logger; -import org.json.JSONArray; -import org.json.JSONObject; - -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -/** - * This class is used for obtaining the commit hashes that belongs to the given patch - * - * @since 1.0.0 - */ - -public class Pmt { - private String[] patchInformation_svnRevisionpublic; - - private final Logger logger = Logger.getLogger(Pmt.class.getName()); - - private static final String COMMITS_IN_PATCH_IDENTIFIER = "patchInformation_svnRevisionpublic"; //key used to identify the commits in a patch from JSON response received from PMT - private static final String KEY_STRING = "name"; - private static final String VALUE_STRING = "value"; - - /** - * getting the commit IDs from the received json response - * - * @param jsonArray jsonarray containing the output received from WSO2 PMT for the given patch - * @return a copy of the array containing the commit hashes that belongs to the given patch - */ - public String[] getPublicGitCommitHashes(JSONArray jsonArray) { - - List listOfCommits = getCommitHashesToList(jsonArray); - logger.info(" The commits hashes obtained from WSO2 PMT are successfully saved to an Array list"); - patchInformation_svnRevisionpublic = listOfCommits.toArray(new String[listOfCommits.size()]); - logger.info(" The commits hashes obtained from WSO2 PMT are successfully saved to an array"); - System.out.println("The commit Ids are"); - // for printing all the commits ID associated with a patch - IntStream.range(0, patchInformation_svnRevisionpublic.length) - .mapToObj(i -> patchInformation_svnRevisionpublic[i]) - .forEach(System.out::println); - System.out.println(); - - //to prevent from internal representation by returning referecnce to mutable object - String clonedPatchInformation_svnRevisionpublic[] = patchInformation_svnRevisionpublic.clone(); - return clonedPatchInformation_svnRevisionpublic; - } - - /** - * This returns the commit hashes belongs to the given patch in as a list of Strings. - * - * @param array jsonarray containing the output received from WSO2 PMT for the given patch - * @return a List containing the commit hashes that belongs to the given patch - */ - - public List getCommitHashesToList(JSONArray array) { - return arrayToStream(array) - .map(JSONObject.class::cast) - .filter(o -> o.get(KEY_STRING).equals(COMMITS_IN_PATCH_IDENTIFIER)) - .findFirst() - .map(o -> (JSONArray) o.get(VALUE_STRING)) - .map(Pmt::arrayToStream) - .map(commits -> - commits.map(Object::toString) - .map(String::trim) - .collect(Collectors.toList()) - ) - .orElseGet(Collections::emptyList); - } - - /** - * This method is used to obtain a sequential stream - * - * @param array JSON array that a sequential stream should be obtained from - * @return a sequential stream created from the supplied JSON Array - */ - public static Stream arrayToStream(JSONArray array) { - return StreamSupport.stream(array.spliterator(), false); - } - -} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java index d8824dd..bac628b 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java @@ -145,7 +145,8 @@ public void saveReviewers(Map> prNoWithRepoName, String git } else { System.out.println("There are no records of reviews for pull request: " + prNumber + " on " + repositoryName + " repository"); - logger.info("There are no records of reviews for pull request: " + prNumber + " on " + repositoryName + + logger.debug("There are no records of reviews for pull request: " + prNumber + " on " + + repositoryName + " repository"); } } catch (CodeQualityMatricesException e) { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java index 26b0ffa..e081cfd 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java @@ -75,10 +75,12 @@ public Map> getFilesChanged(String repositoryName, Str tempFileNames.add(commitFile.getFilename()); tempPatchString.add(commitFile.getPatch()); }); - logger.info("for" + commitHash + " on the " + repositoryName + " Repository, files changed and their relevant changed line ranges added to the arraylists successfully"); + logger.debug("for" + commitHash + " on the " + repositoryName + " repository, files changed and their " + + "relevant changed line ranges are added to the arraylists successfully"); fileNamesAndPatches.put("fileNames", tempFileNames); fileNamesAndPatches.put("patchString", tempPatchString); - logger.info("map with the modified file names with their relevant modified line ranges are saved successfully"); + logger.debug("map with the modified file names with their relevant modified line ranges are saved " + + "successfully"); } catch (IOException e) { throw new CodeQualityMatricesException("IO Exception occurred when getting the commit of given SHA from " + "the given Repository ", e); From 501ef19d1c6019a76463c35d6f1a68bac217ec08 Mon Sep 17 00:00:00 2001 From: kasun Date: Thu, 30 Mar 2017 11:31:21 +0530 Subject: [PATCH 44/62] Fix bugs found in running Idea Analyse --- .../code/quality/matrices/ApiUtility.java | 14 +++--- .../code/quality/matrices/ChangesFinder.java | 43 ++++++++++--------- .../quality/matrices/CodeQualityMatrices.java | 12 +++--- .../CodeQualityMatricesException.java | 2 +- .../quality/matrices/GithubApiCaller.java | 2 +- .../wso2/code/quality/matrices/MainClass.java | 2 +- .../code/quality/matrices/PmtApiCaller.java | 2 +- .../quality/matrices/RevieweAnalyser.java | 16 +++---- .../quality/matrices/SdkGitHubClient.java | 8 ++-- 9 files changed, 52 insertions(+), 49 deletions(-) diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java index c737045..5f42fe1 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java @@ -36,13 +36,13 @@ * * @since 1.0.0 */ -public final class ApiUtility { +final class ApiUtility { // to prevent instantiation private ApiUtility() { } - private static Logger logger = Logger.getLogger(ApiUtility.class); + private static final Logger logger = Logger.getLogger(ApiUtility.class); /** * This is used for calling the REST APIs. @@ -53,10 +53,10 @@ private ApiUtility() { */ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesException { BufferedReader bufferedReader = null; - CloseableHttpClient httpClient = null; + CloseableHttpClient httpClient; CloseableHttpResponse httpResponse = null; httpClient = HttpClients.createDefault(); - String jsonText = null; + String jsonText; try { httpResponse = httpClient.execute(httpGet); @@ -118,10 +118,10 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio */ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatricesException { BufferedReader bufferedReader = null; - CloseableHttpClient httpClient = null; + CloseableHttpClient httpClient; CloseableHttpResponse httpResponse = null; httpClient = HttpClients.createDefault(); - String jsonText = null; + String jsonText; try { httpResponse = httpClient.execute(httpPost); @@ -154,7 +154,7 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatrice try { bufferedReader.close(); } catch (IOException e) { - throw new CodeQualityMatricesException("IOException occurred when closing the buffered reader", e); + logger.error("IOException occurred when closing the buffered reader", e); } } if (httpResponse != null) { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index 407fc23..ecf57f3 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -44,18 +44,18 @@ * @since 1.0.0 */ -public class ChangesFinder { +class ChangesFinder { - protected ArrayList fileNames = new ArrayList<>(); - protected ArrayList patchString = new ArrayList<>(); - protected List> changedLineRanges = new ArrayList<>(); // for saving the line no that are changed - private JSONObject jsonStructure = new JSONObject(); + private ArrayList fileNames = new ArrayList<>(); + private ArrayList patchString = new ArrayList<>(); + private final List> changedLineRanges = new ArrayList<>(); // for saving the line no that are changed + private final JSONObject jsonStructure = new JSONObject(); private Map> parentCommitHashes; - protected Set authorNames = new HashSet<>(); //authors of the bug lines fixed from the patch - protected Set authorCommits = new HashSet<>(); // author commits of the bug lines fixed from the patch + private Set authorNames = new HashSet<>(); //authors of the bug lines fixed from the patch + private Set authorCommits = new HashSet<>(); // author commits of the bug lines fixed from the patch - private GithubApiCaller githubApiCaller = new GithubApiCaller(); - private Gson gson = new Gson(); + private final GithubApiCaller githubApiCaller = new GithubApiCaller(); + private final Gson gson = new Gson(); private static final Logger logger = Logger.getLogger(ChangesFinder.class); @@ -88,7 +88,7 @@ public Set obtainRepoNamesForCommitHashes(String gitHubToken, List repoLocation = new ArrayList<>(); SearchApiResponse searchCommitPojo; try { @@ -116,11 +116,14 @@ public void saveRepoNames(String jsonText, String commitHash, String gitHubToken } catch (CodeQualityMatricesException e) { logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside a lambda expression } - fileNames = fileNamesWithPatcheString.get("fileNames"); - patchString = fileNamesWithPatcheString.get("patchString"); + if (fileNamesWithPatcheString != null) { + fileNames = fileNamesWithPatcheString.get("fileNames"); + patchString = fileNamesWithPatcheString.get("patchString"); + } + saveRelaventEditLineNumbers(fileNames, patchString); try { - iterateOverFileChanges(repositoryName, commitHash, gitHubToken); + findFileChanges(repositoryName, commitHash, gitHubToken); } catch (CodeQualityMatricesException e) { logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside a lambda expression } @@ -137,7 +140,7 @@ public void saveRepoNames(String jsonText, String commitHash, String gitHubToken * @param patchString Array list having the patch string value for each of the file being changed */ - public void saveRelaventEditLineNumbers(ArrayList fileNames, ArrayList patchString) { + private void saveRelaventEditLineNumbers(ArrayList fileNames, ArrayList patchString) { //filtering only the line ranges that are modified and saving to a string array // cannot use parallel streams here as the order of the line changes must be preserved @@ -185,7 +188,7 @@ public void saveRelaventEditLineNumbers(ArrayList fileNames, ArrayList changedRangesOfSelectedFile) throws CodeQualityMatricesException { + private void readBlameForSelectedFile(String jsonText, + ArrayList changedRangesOfSelectedFile) throws CodeQualityMatricesException { - GraphQlResponse graphQlResponse = null; + GraphQlResponse graphQlResponse; try { graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); @@ -304,7 +307,7 @@ public void readBlameForSelectedFile(String jsonText, * @param lineRangesForSelectedFile arraylist containing the changed line ranges of the current selected file * @param gitHubToken github token for accessing github GraphQL API */ - public void findAuthorCommits(String owner, String repositoryName, String fileName, ArrayList lineRangesForSelectedFile, String gitHubToken) { + private void findAuthorCommits(String owner, String repositoryName, String fileName, ArrayList lineRangesForSelectedFile, String gitHubToken) { for (Map.Entry entry : parentCommitHashes.entrySet()) { String oldRange = (String) entry.getKey(); Set commitHashes = (Set) entry.getValue(); @@ -338,7 +341,7 @@ public void findAuthorCommits(String owner, String repositoryName, String fileNa * @param oldRange Range to select the correct range for collecting author commits * @param lineRangesForSelectedFile arraylist containing the changed line ranges of the current selected file */ - public void saveAuthorCommits(String jsonText, String oldRange, ArrayList lineRangesForSelectedFile) { + private void saveAuthorCommits(String jsonText, String oldRange, ArrayList lineRangesForSelectedFile) { GraphQlResponse graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java index a986bb8..0524bd1 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java @@ -31,10 +31,10 @@ * * @since 1.0.0 */ -public class CodeQualityMatrices { - private String pmtToken; - private String patchId; - private String gitHubToken; +class CodeQualityMatrices { + private final String pmtToken; + private final String patchId; + private final String gitHubToken; private static final String COMMITS_INSIDE_GIVEN_PATCH = "patchInformation_svnRevisionpublic"; private final static Logger logger = Logger.getLogger(CodeQualityMatrices.class); @@ -78,9 +78,9 @@ public void execute() { * * @return List of commithashes contained in the given patch */ - public List findCommitHashesInPatch() throws CodeQualityMatricesException { + private List findCommitHashesInPatch() throws CodeQualityMatricesException { PmtApiCaller pmtApiCaller = new PmtApiCaller(); - String jsonText = null; + String jsonText; List commitHashes = new ArrayList<>(); try { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java index 7c0b71c..ff2ac35 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java @@ -23,7 +23,7 @@ * * @since 1.0.0 */ -public class CodeQualityMatricesException extends Exception { +class CodeQualityMatricesException extends Exception { public CodeQualityMatricesException(String message) { super(message); } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java index 8e0c034..a4a1c77 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java @@ -30,7 +30,7 @@ * * @since 1.0.0 */ -public class GithubApiCaller { +class GithubApiCaller { private HttpGet httpGet; /** diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java index 8182b72..aac66e8 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java @@ -25,7 +25,7 @@ * PMT Access token, patch id and github access token * should be passed in order as command line arguments when running the application. */ -public class MainClass { +class MainClass { private final static Logger logger = Logger.getLogger(MainClass.class); public static void main(String[] args) { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java index 8478f40..86c7d91 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java @@ -25,7 +25,7 @@ * * @since 1.0.0 */ -public class PmtApiCaller { +class PmtApiCaller { public PmtApiCaller() { } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java index bac628b..adf387b 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java @@ -37,11 +37,11 @@ * @since 1.0.0 */ -public class RevieweAnalyser { +class RevieweAnalyser { - private Set approvedReviewers = new HashSet<>(); // to store the reviewed and approved users of the pull + private final Set approvedReviewers = new HashSet<>(); // to store the reviewed and approved users of the pull // requests - private Set commentedReviewers = new HashSet<>(); // to store the reviewed and commented users of the pull + private final Set commentedReviewers = new HashSet<>(); // to store the reviewed and commented users of the pull // requests private static final Logger logger = Logger.getLogger(RevieweAnalyser.class); @@ -50,8 +50,8 @@ public class RevieweAnalyser { private static final String GITHUB_REVIEW_APPROVED = "APPROVED"; private static final String GITHUB_REVIEW_COMMENTED = "COMMENTED"; private static final String GITHUB_REVIEW_API_CLOSED_STATE = "closed"; - private GithubApiCaller githubApiCaller = new GithubApiCaller(); - private Gson gson = new Gson(); + private final GithubApiCaller githubApiCaller = new GithubApiCaller(); + private final Gson gson = new Gson(); /** * This is used to identify the pull requests that introduce the given commit to the code base. @@ -62,7 +62,7 @@ public class RevieweAnalyser { public void findReviewers(Set authorCommits, String githubToken) { authorCommits.forEach(commitHash -> { - String jsonText = null; + String jsonText; try { jsonText = githubApiCaller.callSearchIssueApi(commitHash, githubToken); @@ -82,7 +82,7 @@ public void findReviewers(Set authorCommits, String githubToken) { * @return a map of pull requests againt their repository name * @throws CodeQualityMatricesException */ - public Map> savePrNumberAndRepoName(String jsonText) throws CodeQualityMatricesException { + private Map> savePrNumberAndRepoName(String jsonText) throws CodeQualityMatricesException { // map for storing the pull requests numbers against their Repository Map> prNoWithRepoName = new HashMap<>(); @@ -116,7 +116,7 @@ public Map> savePrNumberAndRepoName(String jsonText) throws * relevant reposiory * @param githubToken Github access token for accessing github API */ - public void saveReviewers(Map> prNoWithRepoName, String githubToken) { + private void saveReviewers(Map> prNoWithRepoName, String githubToken) { for (Map.Entry entry : prNoWithRepoName.entrySet()) { String repositoryName = (String) entry.getKey(); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java index e081cfd..e26e63a 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java @@ -38,10 +38,10 @@ * @since 1.0.0 */ -public class SdkGitHubClient { - protected GitHubClient gitHubClient = null; - protected CommitService commitService = null; - protected RepositoryService repositoryService = null; +class SdkGitHubClient { + private GitHubClient gitHubClient = null; + private CommitService commitService = null; + private RepositoryService repositoryService = null; private static final Logger logger = Logger.getLogger(SdkGitHubClient.class); From d10fd0cfc92c68301b4c2ef4c2d5b605f79d6f71 Mon Sep 17 00:00:00 2001 From: kasun Date: Thu, 30 Mar 2017 12:36:40 +0530 Subject: [PATCH 45/62] Fix groupId in pom.xml --- CodeQualityMatricesProject/pom.xml | 4 ++-- .../code/quality/matrices/ApiUtility.java | 2 +- .../{MainClass.java => Application.java} | 8 +++---- .../code/quality/matrices/ChangesFinder.java | 22 +++++++++---------- .../CodeQualityMatricesException.java | 2 +- ....java => CodeQualityMatricesExecutor.java} | 14 ++++++------ .../quality/matrices/GithubApiCaller.java | 2 +- .../code/quality/matrices/PmtApiCaller.java | 2 +- ...vieweAnalyser.java => ReviewAnalyser.java} | 4 ++-- .../quality/matrices/SdkGitHubClient.java | 10 ++++----- ...ainClassTest.java => ApplicationTest.java} | 8 +++---- 11 files changed, 39 insertions(+), 39 deletions(-) rename CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/{MainClass.java => Application.java} (83%) rename CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/{CodeQualityMatrices.java => CodeQualityMatricesExecutor.java} (89%) rename CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/{RevieweAnalyser.java => ReviewAnalyser.java} (99%) rename CodeQualityMatricesProject/src/test/java/com/wso2/code/quality/matrices/{MainClassTest.java => ApplicationTest.java} (75%) diff --git a/CodeQualityMatricesProject/pom.xml b/CodeQualityMatricesProject/pom.xml index d50020b..5b0cc4e 100644 --- a/CodeQualityMatricesProject/pom.xml +++ b/CodeQualityMatricesProject/pom.xml @@ -21,7 +21,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - kasun.codeQualityMatrices + org.wso2.codeQualityMatrices CodeQualityMatrices 0.0.1-SNAPSHOT jar @@ -30,7 +30,7 @@ http://maven.apache.org - 1.7 + 1.8 UTF-8 diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java index 5f42fe1..7c58a65 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java @@ -36,7 +36,7 @@ * * @since 1.0.0 */ -final class ApiUtility { +public final class ApiUtility { // to prevent instantiation private ApiUtility() { diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Application.java similarity index 83% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java rename to CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Application.java index aac66e8..7364f15 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/MainClass.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Application.java @@ -25,8 +25,8 @@ * PMT Access token, patch id and github access token * should be passed in order as command line arguments when running the application. */ -class MainClass { - private final static Logger logger = Logger.getLogger(MainClass.class); +public class Application { + private final static Logger logger = Logger.getLogger(Application.class); public static void main(String[] args) { if (args.length == 3) { @@ -35,8 +35,8 @@ public static void main(String[] args) { String patchId = args[1]; String gitHubToken = args[2]; - CodeQualityMatrices codeQualityMatrices = new CodeQualityMatrices(pmtToken, patchId, gitHubToken); - codeQualityMatrices.execute(); + CodeQualityMatricesExecutor codeQualityMatricesExecutor = new CodeQualityMatricesExecutor(pmtToken, patchId, gitHubToken); + codeQualityMatricesExecutor.execute(); } else { logger.error("Command line arguments were not given correctly to start the execution"); System.out.println("Please enter PMT Access token, patch id and github access token in order as command " + diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index ecf57f3..b8ff6ff 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -44,11 +44,11 @@ * @since 1.0.0 */ -class ChangesFinder { +public class ChangesFinder { - private ArrayList fileNames = new ArrayList<>(); - private ArrayList patchString = new ArrayList<>(); - private final List> changedLineRanges = new ArrayList<>(); // for saving the line no that are changed + private List fileNames = new ArrayList<>(); + private List patchString = new ArrayList<>(); + private final List> changedLineRanges = new ArrayList<>(); // for saving the line no that are changed private final JSONObject jsonStructure = new JSONObject(); private Map> parentCommitHashes; private Set authorNames = new HashSet<>(); //authors of the bug lines fixed from the patch @@ -110,7 +110,7 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke fileNames.clear(); changedLineRanges.clear(); patchString.clear(); - Map> fileNamesWithPatcheString = null; + Map> fileNamesWithPatcheString = null; try { fileNamesWithPatcheString = sdkGitHubClient.getFilesChanged(repositoryName, commitHash); } catch (CodeQualityMatricesException e) { @@ -140,7 +140,7 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke * @param patchString Array list having the patch string value for each of the file being changed */ - private void saveRelaventEditLineNumbers(ArrayList fileNames, ArrayList patchString) { + private void saveRelaventEditLineNumbers(List fileNames, List patchString) { //filtering only the line ranges that are modified and saving to a string array // cannot use parallel streams here as the order of the line changes must be preserved @@ -170,7 +170,7 @@ private void saveRelaventEditLineNumbers(ArrayList fileNames, ArrayList< // storing the line ranges that are being modified in the same array by replacing values lineChanges[index] = intialLineNoInOldFile + "," + endLineNoOfOldFile + "/" + intialLineNoInNewFile + "," + endLineNoOfNewFile; }); - ArrayList changedRange = new ArrayList<>(Arrays.asList(lineChanges)); + List changedRange = new ArrayList<>(Arrays.asList(lineChanges)); //adding to the array list which keep track of the line ranges being changed changedLineRanges.add(changedRange); }); @@ -198,7 +198,7 @@ private void findFileChanges(String repoLocation, String commitHash, String gitH fileNames.forEach(fileName -> { int index = fileNames.indexOf(fileName); // the relevant arraylist of changed lines for that file - ArrayList lineRangesForSelectedFile = changedLineRanges.get(index); + List lineRangesForSelectedFile = changedLineRanges.get(index); parentCommitHashes = new HashMap<>(); // for storing the parent commit hashes for all the changed line ranges of the relevant file Graphql graphqlBean = new Graphql(); @@ -238,7 +238,7 @@ private void findFileChanges(String repoLocation, String commitHash, String gitH * @param changedRangesOfSelectedFile arraylist containing the changed line ranges of the current selected file */ private void readBlameForSelectedFile(String jsonText, - ArrayList changedRangesOfSelectedFile) throws CodeQualityMatricesException { + List changedRangesOfSelectedFile) throws CodeQualityMatricesException { GraphQlResponse graphQlResponse; try { @@ -307,7 +307,7 @@ private void readBlameForSelectedFile(String jsonText, * @param lineRangesForSelectedFile arraylist containing the changed line ranges of the current selected file * @param gitHubToken github token for accessing github GraphQL API */ - private void findAuthorCommits(String owner, String repositoryName, String fileName, ArrayList lineRangesForSelectedFile, String gitHubToken) { + private void findAuthorCommits(String owner, String repositoryName, String fileName, List lineRangesForSelectedFile, String gitHubToken) { for (Map.Entry entry : parentCommitHashes.entrySet()) { String oldRange = (String) entry.getKey(); Set commitHashes = (Set) entry.getValue(); @@ -341,7 +341,7 @@ private void findAuthorCommits(String owner, String repositoryName, String fileN * @param oldRange Range to select the correct range for collecting author commits * @param lineRangesForSelectedFile arraylist containing the changed line ranges of the current selected file */ - private void saveAuthorCommits(String jsonText, String oldRange, ArrayList lineRangesForSelectedFile) { + private void saveAuthorCommits(String jsonText, String oldRange, List lineRangesForSelectedFile) { GraphQlResponse graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java index ff2ac35..7c0b71c 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java @@ -23,7 +23,7 @@ * * @since 1.0.0 */ -class CodeQualityMatricesException extends Exception { +public class CodeQualityMatricesException extends Exception { public CodeQualityMatricesException(String message) { super(message); } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java similarity index 89% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java rename to CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java index 0524bd1..7dbd268 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatrices.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java @@ -31,21 +31,21 @@ * * @since 1.0.0 */ -class CodeQualityMatrices { +public class CodeQualityMatricesExecutor { private final String pmtToken; private final String patchId; private final String gitHubToken; private static final String COMMITS_INSIDE_GIVEN_PATCH = "patchInformation_svnRevisionpublic"; - private final static Logger logger = Logger.getLogger(CodeQualityMatrices.class); + private final static Logger logger = Logger.getLogger(CodeQualityMatricesExecutor.class); /** - * This create an instance of CodeQualityMatrices class. + * This create an instance of CodeQualityMatricesExecutor class. * * @param pmtToken PMT Access Token * @param patchId Patch ID * @param gitHubToken Github access token */ - public CodeQualityMatrices(String pmtToken, String patchId, String gitHubToken) { + public CodeQualityMatricesExecutor(String pmtToken, String patchId, String gitHubToken) { this.pmtToken = pmtToken; this.patchId = patchId; this.gitHubToken = gitHubToken; @@ -62,9 +62,9 @@ public void execute() { Set authorCommits = changesFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitHashes); System.out.println("Author Commits" + authorCommits); - RevieweAnalyser revieweAnalyser = new RevieweAnalyser(); - revieweAnalyser.findReviewers(authorCommits, gitHubToken); - revieweAnalyser.printReviewUsers(); + ReviewAnalyser reviewAnalyser = new ReviewAnalyser(); + reviewAnalyser.findReviewers(authorCommits, gitHubToken); + reviewAnalyser.printReviewUsers(); logger.debug("The application executed successfully"); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java index a4a1c77..8e0c034 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java @@ -30,7 +30,7 @@ * * @since 1.0.0 */ -class GithubApiCaller { +public class GithubApiCaller { private HttpGet httpGet; /** diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java index 86c7d91..8478f40 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java @@ -25,7 +25,7 @@ * * @since 1.0.0 */ -class PmtApiCaller { +public class PmtApiCaller { public PmtApiCaller() { } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java similarity index 99% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java rename to CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java index adf387b..1ff7bc7 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/RevieweAnalyser.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java @@ -37,14 +37,14 @@ * @since 1.0.0 */ -class RevieweAnalyser { +public class ReviewAnalyser { private final Set approvedReviewers = new HashSet<>(); // to store the reviewed and approved users of the pull // requests private final Set commentedReviewers = new HashSet<>(); // to store the reviewed and commented users of the pull // requests - private static final Logger logger = Logger.getLogger(RevieweAnalyser.class); + private static final Logger logger = Logger.getLogger(ReviewAnalyser.class); //constants for filtering github API responses private static final String GITHUB_REVIEW_APPROVED = "APPROVED"; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java index e26e63a..996a326 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java @@ -38,7 +38,7 @@ * @since 1.0.0 */ -class SdkGitHubClient { +public class SdkGitHubClient { private GitHubClient gitHubClient = null; private CommitService commitService = null; private RepositoryService repositoryService = null; @@ -60,14 +60,14 @@ class SdkGitHubClient { * @param commitHash The querying commit hash * @return a map containg arraylist of file changed and their relevant patch */ - public Map> getFilesChanged(String repositoryName, String commitHash) throws CodeQualityMatricesException { - Map> fileNamesAndPatches = new HashMap<>(); + public Map> getFilesChanged(String repositoryName, String commitHash) throws CodeQualityMatricesException { + Map> fileNamesAndPatches = new HashMap<>(); try { IRepositoryIdProvider iRepositoryIdProvider = () -> repositoryName; RepositoryCommit repositoryCommit = commitService.getCommit(iRepositoryIdProvider, commitHash); List filesChanged = repositoryCommit.getFiles(); - ArrayList tempFileNames = new ArrayList<>(); - ArrayList tempPatchString = new ArrayList<>(); + List tempFileNames = new ArrayList<>(); + List tempPatchString = new ArrayList<>(); // this can be run parallely as patchString of a file will always be in the same index as the file filesChanged.parallelStream() diff --git a/CodeQualityMatricesProject/src/test/java/com/wso2/code/quality/matrices/MainClassTest.java b/CodeQualityMatricesProject/src/test/java/com/wso2/code/quality/matrices/ApplicationTest.java similarity index 75% rename from CodeQualityMatricesProject/src/test/java/com/wso2/code/quality/matrices/MainClassTest.java rename to CodeQualityMatricesProject/src/test/java/com/wso2/code/quality/matrices/ApplicationTest.java index 0df981b..1d3350a 100644 --- a/CodeQualityMatricesProject/src/test/java/com/wso2/code/quality/matrices/MainClassTest.java +++ b/CodeQualityMatricesProject/src/test/java/com/wso2/code/quality/matrices/ApplicationTest.java @@ -5,9 +5,9 @@ import junit.framework.TestSuite; /** - * Unit test for simple MainClass. + * Unit test for simple Application. */ -public class MainClassTest +public class ApplicationTest extends TestCase { /** @@ -15,7 +15,7 @@ public class MainClassTest * * @param testName name of the test case */ - public MainClassTest(String testName ) + public ApplicationTest(String testName ) { super( testName ); } @@ -25,7 +25,7 @@ public MainClassTest(String testName ) */ public static Test suite() { - return new TestSuite( MainClassTest.class ); + return new TestSuite( ApplicationTest.class ); } /** From 1c9947ff24c0fb4b228e0f8b0ae2d4d783c7c1bc Mon Sep 17 00:00:00 2001 From: kasun Date: Thu, 30 Mar 2017 16:42:54 +0530 Subject: [PATCH 46/62] Fix errors received by adding wso2 parent pom --- CodeQualityMatricesProject/pom.xml | 6 ++ .../code/quality/matrices/ApiUtility.java | 21 +++-- .../code/quality/matrices/Application.java | 9 +- .../code/quality/matrices/ChangesFinder.java | 87 +++++++++++-------- .../matrices/CodeQualityMatricesExecutor.java | 13 +-- .../quality/matrices/GithubApiCaller.java | 1 - .../code/quality/matrices/PmtApiCaller.java | 3 +- .../code/quality/matrices/ReviewAnalyser.java | 45 +++++----- .../quality/matrices/SdkGitHubClient.java | 11 ++- .../quality/matrices/model/Constants.java | 33 +++++++ .../matrices/model/GraphQlResponse.java | 16 +--- .../quality/matrices/model/GraphqlAuthor.java | 4 +- .../quality/matrices/model/GraphqlBlame.java | 6 +- .../quality/matrices/model/GraphqlCommit.java | 5 +- .../quality/matrices/model/GraphqlData.java | 5 +- .../quality/matrices/model/GraphqlEdge.java | 5 +- .../matrices/model/GraphqlHistory.java | 5 +- .../quality/matrices/model/GraphqlItem.java | 8 +- .../quality/matrices/model/GraphqlNode.java | 5 +- .../quality/matrices/model/GraphqlObject.java | 5 +- .../quality/matrices/model/GraphqlRange.java | 3 + .../matrices/model/GraphqlRepository.java | 4 + .../matrices/model/IssueApiResponse.java | 3 + .../quality/matrices/model/Repository.java | 5 +- .../matrices/model/ReviewApiResponse.java | 3 + .../code/quality/matrices/model/Reviewer.java | 3 + .../matrices/model/SearchApiResponse.java | 7 +- .../quality/matrices/model/SearchItem.java | 3 + .../src/main/resources/log4j.properties | 12 +-- .../quality/matrices/ApplicationTest.java | 20 ++--- 30 files changed, 227 insertions(+), 129 deletions(-) create mode 100644 CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Constants.java diff --git a/CodeQualityMatricesProject/pom.xml b/CodeQualityMatricesProject/pom.xml index 5b0cc4e..11b129e 100644 --- a/CodeQualityMatricesProject/pom.xml +++ b/CodeQualityMatricesProject/pom.xml @@ -21,6 +21,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + + org.wso2 + wso2 + 5 + + org.wso2.codeQualityMatrices CodeQualityMatrices 0.0.1-SNAPSHOT diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java index 7c58a65..3994bdf 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java @@ -37,12 +37,13 @@ * @since 1.0.0 */ public final class ApiUtility { + private static final Logger logger = Logger.getLogger(ApiUtility.class); + // to prevent instantiation private ApiUtility() { } - private static final Logger logger = Logger.getLogger(ApiUtility.class); /** * This is used for calling the REST APIs. @@ -88,21 +89,21 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio try { bufferedReader.close(); } catch (IOException e) { - logger.error("IOException occurred when closing the BufferedReader", e); + logger.debug("IOException occurred when closing the BufferedReader", e); } } if (httpResponse != null) { try { httpResponse.close(); } catch (IOException e) { - logger.error("IOException occurred when closing the HttpResponse", e); + logger.debug("IOException occurred when closing the HttpResponse", e); } } if (httpClient != null) { try { httpClient.close(); } catch (IOException e) { - logger.error("IOException occurred when closing the HttpClient", e); + logger.debug("IOException occurred when closing the HttpClient", e); } } } @@ -146,29 +147,31 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatrice } catch (UnsupportedEncodingException e) { throw new CodeQualityMatricesException("Encoding error occured before calling the github graphQL API", e); } catch (ClientProtocolException e) { - throw new CodeQualityMatricesException("Client protocol exception occurred when calling the github graphQL API", e); + throw new CodeQualityMatricesException("Client protocol exception occurred when calling the github" + + " graphQL API", e); } catch (IOException e) { - throw new CodeQualityMatricesException("A problem or the connection was aborted while executing the httpPost", e); + throw new CodeQualityMatricesException("A problem or the connection was aborted while executing the" + + " httpPost", e); } finally { if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException e) { - logger.error("IOException occurred when closing the buffered reader", e); + logger.debug("IOException occurred when closing the buffered reader", e); } } if (httpResponse != null) { try { httpResponse.close(); } catch (IOException e) { - logger.error("IOException occurred when closing the HttpResponse", e); + logger.debug("IOException occurred when closing the HttpResponse", e); } } if (httpClient != null) { try { httpClient.close(); } catch (IOException e) { - logger.error("IOException occurred when closing the HttpClient", e); + logger.debug("IOException occurred when closing the HttpClient", e); } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Application.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Application.java index 7364f15..b6cc321 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Application.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Application.java @@ -26,7 +26,7 @@ * should be passed in order as command line arguments when running the application. */ public class Application { - private final static Logger logger = Logger.getLogger(Application.class); + private static final Logger logger = Logger.getLogger(Application.class); public static void main(String[] args) { if (args.length == 3) { @@ -35,11 +35,12 @@ public static void main(String[] args) { String patchId = args[1]; String gitHubToken = args[2]; - CodeQualityMatricesExecutor codeQualityMatricesExecutor = new CodeQualityMatricesExecutor(pmtToken, patchId, gitHubToken); + CodeQualityMatricesExecutor codeQualityMatricesExecutor = new CodeQualityMatricesExecutor(pmtToken, patchId, + gitHubToken); codeQualityMatricesExecutor.execute(); } else { - logger.error("Command line arguments were not given correctly to start the execution"); - System.out.println("Please enter PMT Access token, patch id and github access token in order as command " + + logger.debug("Command line arguments were not given correctly to start the execution"); + logger.debug("Please enter PMT Access token, patch id and github access token in order as command " + "line arguments to initiate the program"); } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index b8ff6ff..bc4c561 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -45,10 +45,12 @@ */ public class ChangesFinder { + private static final Logger logger = Logger.getLogger(ChangesFinder.class); + private List fileNames = new ArrayList<>(); private List patchString = new ArrayList<>(); - private final List> changedLineRanges = new ArrayList<>(); // for saving the line no that are changed + private final List> changedLineRanges = new ArrayList<>(); // for saving the line no that are changed private final JSONObject jsonStructure = new JSONObject(); private Map> parentCommitHashes; private Set authorNames = new HashSet<>(); //authors of the bug lines fixed from the patch @@ -57,7 +59,6 @@ public class ChangesFinder { private final GithubApiCaller githubApiCaller = new GithubApiCaller(); private final Gson gson = new Gson(); - private static final Logger logger = Logger.getLogger(ChangesFinder.class); /** * This is used for obtaining the repositories that contain the relevant commits belongs to the given patch @@ -74,7 +75,7 @@ public Set obtainRepoNamesForCommitHashes(String gitHubToken, List obtainRepoNamesForCommitHashes(String gitHubToken, List repoLocation = new ArrayList<>(); SearchApiResponse searchCommitPojo; try { @@ -99,13 +101,13 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke searchCommitPojo.getItems() .forEach(recordItem -> repoLocation.add(recordItem.getRepository().getFull_name())); - logger.debug("All the repository names having the given commit are successfully saved in an array"); + logger.debug("Repositories having the given commit are successfully saved in an List"); SdkGitHubClient sdkGitHubClient = new SdkGitHubClient(gitHubToken); repoLocation.stream() .filter(repositoryName -> StringUtils.contains(repositoryName, "wso2/")) .forEach(repositoryName -> { - //clearing all the data in the current fileNames and changedLineRanges arraylists for each Repository + //clearing all data in the current fileNames and changedLineRanges arraylists for each Repository //authorNames.clear(); fileNames.clear(); changedLineRanges.clear(); @@ -114,7 +116,7 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke try { fileNamesWithPatcheString = sdkGitHubClient.getFilesChanged(repositoryName, commitHash); } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside a lambda expression + logger.debug(e.getMessage(), e.getCause()); } if (fileNamesWithPatcheString != null) { fileNames = fileNamesWithPatcheString.get("fileNames"); @@ -125,11 +127,11 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke try { findFileChanges(repositoryName, commitHash, gitHubToken); } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside a lambda expression + logger.debug(e.getMessage(), e.getCause()); } }); - System.out.println(authorNames); - System.out.println(authorCommits); + logger.debug("\n Author names :" + authorNames); + logger.debug("\n Author commits :" + authorCommits); } /** @@ -147,16 +149,24 @@ private void saveRelaventEditLineNumbers(List fileNames, List pa patchString.stream() .map(patch -> StringUtils.substringsBetween(patch, "@@ ", " @@")) .forEach(lineChanges -> { - //filtering the lines ranges that existed in the previous file, that exists in the new file and saving them in to the same array + /*filtering the lines ranges that existed in the previous file, that exists in the new file and + saving them in to a list + */ IntStream.range(0, lineChanges.length) .forEach(index -> { //@@ -22,7 +22,7 @@ => -22,7 +22,7 => 22,28/22,28 String tempString = lineChanges[index]; - String lineRangeInTheOldFileBeingModified = StringUtils.substringBetween(tempString, "-", " +"); // for taking the authors and commit hashes of the previous lines - String lineRangeInTheNewFileResultedFromModification = StringUtils.substringAfter(tempString, "+"); // for taking the parent commit - - int intialLineNoInOldFile = Integer.parseInt(StringUtils.substringBefore(lineRangeInTheOldFileBeingModified, ",")); - int tempEndLineNoInOldFile = Integer.parseInt(StringUtils.substringAfter(lineRangeInTheOldFileBeingModified, ",")); + // for taking the authors and commit hashes of the previous lines + String lineRangeInTheOldFileBeingModified = StringUtils.substringBetween(tempString, + "-", " +"); + // for taking the parent commit + String lineRangeInTheNewFileResultedFromModification = StringUtils.substringAfter + (tempString, "+"); + + int intialLineNoInOldFile = Integer.parseInt(StringUtils.substringBefore + (lineRangeInTheOldFileBeingModified, ",")); + int tempEndLineNoInOldFile = Integer.parseInt(StringUtils.substringAfter + (lineRangeInTheOldFileBeingModified, ",")); int endLineNoOfOldFile; if (intialLineNoInOldFile != 0) { // to filterout the newly created files @@ -164,31 +174,34 @@ private void saveRelaventEditLineNumbers(List fileNames, List pa } else { endLineNoOfOldFile = tempEndLineNoInOldFile; } - int intialLineNoInNewFile = Integer.parseInt(StringUtils.substringBefore(lineRangeInTheNewFileResultedFromModification, ",")); - int tempEndLineNoInNewFile = Integer.parseInt(StringUtils.substringAfter(lineRangeInTheNewFileResultedFromModification, ",")); + int intialLineNoInNewFile = Integer.parseInt(StringUtils.substringBefore + (lineRangeInTheNewFileResultedFromModification, ",")); + int tempEndLineNoInNewFile = Integer.parseInt(StringUtils.substringAfter + (lineRangeInTheNewFileResultedFromModification, ",")); int endLineNoOfNewFile = intialLineNoInNewFile + (tempEndLineNoInNewFile - 1); // storing the line ranges that are being modified in the same array by replacing values - lineChanges[index] = intialLineNoInOldFile + "," + endLineNoOfOldFile + "/" + intialLineNoInNewFile + "," + endLineNoOfNewFile; + lineChanges[index] = intialLineNoInOldFile + "," + endLineNoOfOldFile + "/" + + intialLineNoInNewFile + "," + endLineNoOfNewFile; }); List changedRange = new ArrayList<>(Arrays.asList(lineChanges)); //adding to the array list which keep track of the line ranges being changed changedLineRanges.add(changedRange); }); - System.out.println("done saving file names and their relevant modification line ranges"); logger.debug("done saving file names and their relevant modification line ranges"); - System.out.println(fileNames); - System.out.println(changedLineRanges + "\n"); + logger.debug("\n File names : " + fileNames); + logger.debug("\n Changed ranges :" + changedLineRanges + "\n"); } /** - * This will iterate over the saved filenames and their relevant changed line ranges and calls the github graphQL API - * for getting blame details for each of the files. + * This will iterate over the saved filenames and their relevant changed line ranges and calls the github graphQL + * API for getting blame details for each of the files. * * @param repoLocation current selected Repository * @param commitHash current selected Repository * @param gitHubToken github token for accessing github GraphQL API */ - private void findFileChanges(String repoLocation, String commitHash, String gitHubToken) throws CodeQualityMatricesException { + private void findFileChanges(String repoLocation, String commitHash, String gitHubToken) + throws CodeQualityMatricesException { // filtering the owner and the Repository name from the repoLocation String owner = StringUtils.substringBefore(repoLocation, "/"); @@ -199,7 +212,8 @@ private void findFileChanges(String repoLocation, String commitHash, String gitH int index = fileNames.indexOf(fileName); // the relevant arraylist of changed lines for that file List lineRangesForSelectedFile = changedLineRanges.get(index); - parentCommitHashes = new HashMap<>(); // for storing the parent commit hashes for all the changed line ranges of the relevant file + // for storing the parent commit hashes for all the changed line ranges of the relevant file + parentCommitHashes = new HashMap<>(); Graphql graphqlBean = new Graphql(); graphqlBean.setGraphqlInputWithHistory(owner, repositoryName, commitHash, fileName); @@ -211,14 +225,14 @@ private void findFileChanges(String repoLocation, String commitHash, String gitH jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); // as exceptions cannot be thrown inside lambda expression + logger.debug(e.getMessage(), e.getCause()); } //reading the above saved output for the current selected file name try { readBlameForSelectedFile(jsonText, lineRangesForSelectedFile); logger.debug("Parent commits are saved for the " + fileName + " for all the modified line ranges"); } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); + logger.debug(e.getMessage(), e.getCause()); } @@ -237,8 +251,8 @@ private void findFileChanges(String repoLocation, String commitHash, String gitH * @param jsonText JSON response of blame of the selected file * @param changedRangesOfSelectedFile arraylist containing the changed line ranges of the current selected file */ - private void readBlameForSelectedFile(String jsonText, - List changedRangesOfSelectedFile) throws CodeQualityMatricesException { + private void readBlameForSelectedFile(String jsonText, List changedRangesOfSelectedFile) + throws CodeQualityMatricesException { GraphQlResponse graphQlResponse; try { @@ -256,7 +270,9 @@ private void readBlameForSelectedFile(String jsonText, String newFileRange = StringUtils.substringAfter(lineRange, "/"); // need to skip the newly created files from taking the blame as they contain no previous commits if (!oldFileRange.equals("0,0")) { - // need to consider the line range in the new file resulted from applying the commit, for finding parent commits + /* need to consider the line range in the new file resulted from applying the commit, for finding + parent commits + */ startingLineNo = Integer.parseInt(StringUtils.substringBefore(newFileRange, ",")); endLineNo = Integer.parseInt(StringUtils.substringAfter(newFileRange, ",")); @@ -307,7 +323,8 @@ private void readBlameForSelectedFile(String jsonText, * @param lineRangesForSelectedFile arraylist containing the changed line ranges of the current selected file * @param gitHubToken github token for accessing github GraphQL API */ - private void findAuthorCommits(String owner, String repositoryName, String fileName, List lineRangesForSelectedFile, String gitHubToken) { + private void findAuthorCommits(String owner, String repositoryName, String fileName, + List lineRangesForSelectedFile, String gitHubToken) { for (Map.Entry entry : parentCommitHashes.entrySet()) { String oldRange = (String) entry.getKey(); Set commitHashes = (Set) entry.getValue(); @@ -328,8 +345,8 @@ private void findAuthorCommits(String owner, String repositoryName, String fileN saveAuthorCommits(jsonText, oldRange, lineRangesForSelectedFile); }); } - logger.debug("author commits and authors of bug lines of code on " + fileName + " file which are been fixed by " + - "the given patch are successfully saved to lists"); + logger.debug("author commits and authors of bug lines of code on " + fileName + " file which are been fixed " + + "by the given patch are successfully saved to lists"); } @@ -378,5 +395,3 @@ private void saveAuthorCommits(String jsonText, String oldRange, List li }); } } - - diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java index 7dbd268..e63b4f7 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java @@ -26,17 +26,20 @@ import java.util.Map; import java.util.Set; +import static com.wso2.code.quality.matrices.model.Constants.COMMITS_INSIDE_GIVEN_PATCH; + + /** * This is used for creating executing the program. * * @since 1.0.0 */ public class CodeQualityMatricesExecutor { + private static final Logger logger = Logger.getLogger(CodeQualityMatricesExecutor.class); + private final String pmtToken; private final String patchId; private final String gitHubToken; - private static final String COMMITS_INSIDE_GIVEN_PATCH = "patchInformation_svnRevisionpublic"; - private final static Logger logger = Logger.getLogger(CodeQualityMatricesExecutor.class); /** * This create an instance of CodeQualityMatricesExecutor class. @@ -60,7 +63,6 @@ public void execute() { List commitHashes = findCommitHashesInPatch(); ChangesFinder changesFinder = new ChangesFinder(); Set authorCommits = changesFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitHashes); - System.out.println("Author Commits" + authorCommits); ReviewAnalyser reviewAnalyser = new ReviewAnalyser(); reviewAnalyser.findReviewers(authorCommits, gitHubToken); @@ -69,7 +71,7 @@ public void execute() { logger.debug("The application executed successfully"); } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); + logger.debug(e.getMessage(), e.getCause()); } } @@ -101,8 +103,7 @@ private List findCommitHashesInPatch() throws CodeQualityMatricesExcepti } } } - System.out.println("The commit hashes are: "); - System.out.println(commitHashes); + logger.debug("The commit hashes are: " + commitHashes); } else { throw new CodeQualityMatricesException("The returned jsonText from PMT API is null"); } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java index 8e0c034..d58daa0 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java @@ -130,4 +130,3 @@ public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken } } - diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java index 8478f40..e95b8ae 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java @@ -39,7 +39,8 @@ public PmtApiCaller() { * @throws CodeQualityMatricesException */ public String callApi(String accessToken, String patchId) throws CodeQualityMatricesException { - String pmtUrl = "http://umt.private.wso2.com:9765/codequalitymatricesapi/1.0.0//properties?path=/_system/governance/patchs/" + patchId; + String pmtUrl = "http://umt.private.wso2.com:9765/codequalitymatricesapi/1.0.0//properties?path=/_system/" + + "governance/patchs/" + patchId; HttpGet httpGet; try { httpGet = new HttpGet(pmtUrl); diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java index 1ff7bc7..33881ac 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java @@ -30,6 +30,10 @@ import java.util.List; import java.util.Map; import java.util.Set; +import static com.wso2.code.quality.matrices.model.Constants.GITHUB_REVIEW_API_CLOSED_STATE; +import static com.wso2.code.quality.matrices.model.Constants.GITHUB_REVIEW_APPROVED; +import static com.wso2.code.quality.matrices.model.Constants.GITHUB_REVIEW_COMMENTED; + /** * This class is used to find the reviewers of the buggy lines of code. @@ -38,18 +42,16 @@ */ public class ReviewAnalyser { + private static final Logger logger = Logger.getLogger(ReviewAnalyser.class); - private final Set approvedReviewers = new HashSet<>(); // to store the reviewed and approved users of the pull - // requests - private final Set commentedReviewers = new HashSet<>(); // to store the reviewed and commented users of the pull - // requests + // to store the reviewed and approved users of thepull requests + private final Set approvedReviewers = new HashSet<>(); + // to store the reviewed and commented users of the pull requests + private final Set commentedReviewers = new HashSet<>(); - private static final Logger logger = Logger.getLogger(ReviewAnalyser.class); //constants for filtering github API responses - private static final String GITHUB_REVIEW_APPROVED = "APPROVED"; - private static final String GITHUB_REVIEW_COMMENTED = "COMMENTED"; - private static final String GITHUB_REVIEW_API_CLOSED_STATE = "closed"; + private final GithubApiCaller githubApiCaller = new GithubApiCaller(); private final Gson gson = new Gson(); @@ -67,10 +69,11 @@ public void findReviewers(Set authorCommits, String githubToken) { try { jsonText = githubApiCaller.callSearchIssueApi(commitHash, githubToken); Map> prNoWithRepoName = savePrNumberAndRepoName(jsonText); - logger.debug("Pull requests with their relevant repository names are successfully saved in a map."); + logger.debug("Relevant pull requests on patch " + commitHash + " with their relevant repository " + + "names are successfully saved in a map."); saveReviewers(prNoWithRepoName, githubToken); } catch (CodeQualityMatricesException e) { - logger.error(e.getMessage(), e.getCause()); + logger.debug(e.getMessage(), e.getCause()); } }); } @@ -93,7 +96,8 @@ private Map> savePrNumberAndRepoName(String jsonText) throw .filter(searchItem -> GITHUB_REVIEW_API_CLOSED_STATE.equals(searchItem.getState())) .filter(searchItem -> StringUtils.contains(searchItem.getRepositoryUrl(), "/wso2/")) .forEach(searchItem -> { - String repositoryName = StringUtils.substringAfter(searchItem.getRepositoryUrl(), "repos/"); + String repositoryName = StringUtils.substringAfter(searchItem.getRepositoryUrl(), + "repos/"); int pullRequestNo = searchItem.getNumber(); prNoWithRepoName.putIfAbsent(repositoryName, new HashSet<>()); if (!prNoWithRepoName.get(repositoryName).contains(pullRequestNo)) { @@ -133,21 +137,18 @@ private void saveReviewers(Map> prNoWithRepoName, String gi .filter(review -> GITHUB_REVIEW_APPROVED.equals(review.getState())) .forEach(review -> approvedReviewers.add(review.getReviewer().getName())); - logger.debug("Users who approved the pull requests which introduce bug lines to the code base are" + - " successfully saved to approvedReviewers list"); + logger.debug("Users who approved the pull requests which introduce bug lines to the " + + "code base are successfully saved to approvedReviewers list"); reviews.parallelStream() .filter(review -> GITHUB_REVIEW_COMMENTED.equals(review.getState())) .forEach(review -> commentedReviewers.add(review.getReviewer().getName())); - logger.debug("Users who commented on the pull requests which introduce bug lines to the code base are" + - " successfully saved to approvedReviewers list"); + logger.debug("Users who commented on the pull requests which introduce bug lines to " + + "the code base are successfully saved to approvedReviewers list"); } else { - System.out.println("There are no records of reviews for pull request: " + prNumber + " on " + - repositoryName + " repository"); - logger.debug("There are no records of reviews for pull request: " + prNumber + " on " + - repositoryName + - " repository"); + logger.debug("There are no records of reviews for pull request: " + prNumber + + " on " + repositoryName + " repository"); } } catch (CodeQualityMatricesException e) { logger.error(e.getMessage(), e.getCause()); @@ -160,7 +161,7 @@ private void saveReviewers(Map> prNoWithRepoName, String gi * Print the list of reviewers and commented users on the pull requests which introduce bugs to the code base */ public void printReviewUsers() { - System.out.println("Reviewed and approved users of the bug lines: " + approvedReviewers); - System.out.println("Reviewed and commented users on bug lines: " + commentedReviewers); + logger.debug("\n Reviewed and approved users of the bug lines: " + approvedReviewers); + logger.debug("\n Reviewed and commented users on bug lines: " + commentedReviewers); } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java index 996a326..cb2d01a 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java @@ -39,11 +39,12 @@ */ public class SdkGitHubClient { + private static final Logger logger = Logger.getLogger(SdkGitHubClient.class); + private GitHubClient gitHubClient = null; private CommitService commitService = null; private RepositoryService repositoryService = null; - private static final Logger logger = Logger.getLogger(SdkGitHubClient.class); SdkGitHubClient(String githubToken) { gitHubClient = new GitHubClient(); @@ -60,7 +61,8 @@ public class SdkGitHubClient { * @param commitHash The querying commit hash * @return a map containg arraylist of file changed and their relevant patch */ - public Map> getFilesChanged(String repositoryName, String commitHash) throws CodeQualityMatricesException { + public Map> getFilesChanged(String repositoryName, String commitHash) + throws CodeQualityMatricesException { Map> fileNamesAndPatches = new HashMap<>(); try { IRepositoryIdProvider iRepositoryIdProvider = () -> repositoryName; @@ -75,11 +77,12 @@ public Map> getFilesChanged(String repositoryName, String c tempFileNames.add(commitFile.getFilename()); tempPatchString.add(commitFile.getPatch()); }); - logger.debug("for" + commitHash + " on the " + repositoryName + " repository, files changed and their " + + logger.debug("for commit hash" + commitHash + " on the " + repositoryName + " repository, files changed " + + "and their " + "relevant changed line ranges are added to the arraylists successfully"); fileNamesAndPatches.put("fileNames", tempFileNames); fileNamesAndPatches.put("patchString", tempPatchString); - logger.debug("map with the modified file names with their relevant modified line ranges are saved " + + logger.debug("Modified file names with their relevant modified line ranges are saved to a map " + "successfully"); } catch (IOException e) { throw new CodeQualityMatricesException("IO Exception occurred when getting the commit of given SHA from " + diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Constants.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Constants.java new file mode 100644 index 0000000..e92b4b3 --- /dev/null +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Constants.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.matrices.model; + +/** + * This is used for storing all the constants used in the Code quality matrices Application + * + * @since 1.0.0 + */ +public class Constants { + public static final String COMMITS_INSIDE_GIVEN_PATCH = "patchInformation_svnRevisionpublic"; + public static final String GITHUB_REVIEW_APPROVED = "APPROVED"; + public static final String GITHUB_REVIEW_COMMENTED = "COMMENTED"; + public static final String GITHUB_REVIEW_API_CLOSED_STATE = "closed"; + + +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java index 482f638..fc7428e 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java @@ -18,6 +18,9 @@ package com.wso2.code.quality.matrices.model; +/** + * Pojo class used for parsing JSON response received from github graphql API + */ public class GraphQlResponse { private GraphqlData data; @@ -28,17 +31,4 @@ public GraphqlData getData() { public void setData(GraphqlData data) { this.data = data; } - } - - - - - - - - - - - - diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java index ef44a7f..fa0be6c 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java @@ -18,6 +18,9 @@ package com.wso2.code.quality.matrices.model; +/** + * Pojo class used for parsing JSON response received from github graphql API + */ public class GraphqlAuthor { private String name; private String email; @@ -38,4 +41,3 @@ public void setEmail(String email) { this.email = email; } } - diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java index 8c81726..3fd4d4d 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java @@ -20,6 +20,9 @@ import java.util.List; +/** + * Pojo class used for parsing JSON response received from github graphql API + */ public class GraphqlBlame { private List ranges; @@ -31,7 +34,4 @@ public List getRanges() { public void setRanges(List ranges) { this.ranges = ranges; } - - } - diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java index dfa4e42..19d2097 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java @@ -18,6 +18,9 @@ package com.wso2.code.quality.matrices.model; +/** + * Pojo class used for parsing JSON response received from github graphql API + */ public class GraphqlCommit { private GraphqlAuthor author; private GraphqlHistory history; @@ -46,4 +49,4 @@ public void setUrl(String url) { public String getUrl() { return url; } -} \ No newline at end of file +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java index 3b5d474..e7ccbb1 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java @@ -18,6 +18,9 @@ package com.wso2.code.quality.matrices.model; +/** + * Pojo class used for parsing JSON response received from github graphql API + */ public class GraphqlData { private GraphqlRepository repository; @@ -28,4 +31,4 @@ public GraphqlRepository getRepository() { public void setRepository(GraphqlRepository repository) { this.repository = repository; } -} \ No newline at end of file +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java index cd8e28a..82b858c 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java @@ -18,6 +18,9 @@ package com.wso2.code.quality.matrices.model; +/** + * Pojo class used for parsing JSON response received from github graphql API + */ public class GraphqlEdge { private GraphqlNode node; @@ -28,4 +31,4 @@ public GraphqlNode getNode() { public void setNode(GraphqlNode node) { this.node = node; } -} \ No newline at end of file +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java index c4f6903..e204dd5 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java @@ -20,6 +20,9 @@ import java.util.List; +/** + * Pojo class used for parsing JSON response received from github graphql API + */ public class GraphqlHistory { private List edges; @@ -30,4 +33,4 @@ public List getEdges() { public void setEdges(List edges) { this.edges = edges; } -} \ No newline at end of file +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java index 6ddb5cb..8aa1bb5 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java @@ -18,6 +18,9 @@ package com.wso2.code.quality.matrices.model; +/** + * Pojo class used for parsing JSON response received from github graphql API + */ public class GraphqlItem { private Repository repository; @@ -26,8 +29,7 @@ public Repository getRepository() { return repository; } - public void setRepository(Repository Repository) { - this.repository = Repository; + public void setRepository(Repository repository) { + this.repository = repository; } } - diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java index 826714b..8e670b6 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java @@ -18,6 +18,9 @@ package com.wso2.code.quality.matrices.model; +/** + * Pojo class used for parsing JSON response received from github graphql API + */ public class GraphqlNode { private String url; @@ -28,4 +31,4 @@ public String getUrl() { public void setUrl(String url) { this.url = url; } -} \ No newline at end of file +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java index 61a20f3..197a374 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java @@ -18,6 +18,9 @@ package com.wso2.code.quality.matrices.model; +/** + * Pojo class used for parsing JSON response received from github graphql API + */ public class GraphqlObject { private GraphqlBlame blame; @@ -28,4 +31,4 @@ public GraphqlBlame getBlame() { public void setBlame(GraphqlBlame blame) { this.blame = blame; } -} \ No newline at end of file +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java index 841e5ec..62c91a1 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java @@ -18,6 +18,9 @@ package com.wso2.code.quality.matrices.model; +/** + * Pojo class used for parsing JSON response received from github graphql API + */ public class GraphqlRange { private int startingLine; private int endingLine; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java index b91ea88..38d1bce 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java @@ -17,6 +17,10 @@ */ package com.wso2.code.quality.matrices.model; + +/** + * Pojo class used for parsing JSON response received from github graphql API + */ public class GraphqlRepository { private GraphqlObject object; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java index b0905d5..1ca498e 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java @@ -20,6 +20,9 @@ import java.util.List; +/** + * Pojo class used for parsing JSON response received from github REST API + */ public class IssueApiResponse { private List items; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Repository.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Repository.java index 6bb8a5c..2808873 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Repository.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Repository.java @@ -18,6 +18,9 @@ package com.wso2.code.quality.matrices.model; +/** + * Pojo class used for parsing JSON response received from github REST API + */ public class Repository { private String full_name; @@ -28,4 +31,4 @@ public String getFull_name() { public void setFull_name(String full_name) { this.full_name = full_name; } -} \ No newline at end of file +} diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java index 08b95d5..6622772 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java @@ -18,6 +18,9 @@ package com.wso2.code.quality.matrices.model; +/** + * Pojo class used for parsing JSON response received from github REST API + */ public class ReviewApiResponse { private String state; private Reviewer user; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java index 8d53166..c31568b 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java @@ -18,6 +18,9 @@ package com.wso2.code.quality.matrices.model; +/** + * Pojo class used for parsing JSON response received from github REST API + */ public class Reviewer { private String login; diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java index 7c55983..7f254e6 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java @@ -20,6 +20,9 @@ import java.util.List; +/** + * Pojo class used for parsing JSON response received from github REST API + */ public class SearchApiResponse { private int total_count; private List items; @@ -36,7 +39,7 @@ public List getItems() { return items; } - public void setItems(List Items) { - this.items = Items; + public void setItems(List items) { + this.items = items; } } diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java index 7631af8..ce31b93 100644 --- a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java +++ b/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java @@ -18,6 +18,9 @@ package com.wso2.code.quality.matrices.model; +/** + * Pojo class used for parsing JSON response received from github REST API + */ public class SearchItem { private String state; private int number; diff --git a/CodeQualityMatricesProject/src/main/resources/log4j.properties b/CodeQualityMatricesProject/src/main/resources/log4j.properties index 4be4e60..34d5509 100644 --- a/CodeQualityMatricesProject/src/main/resources/log4j.properties +++ b/CodeQualityMatricesProject/src/main/resources/log4j.properties @@ -17,7 +17,9 @@ # # Define the root logger with appender file logs=/home/kasun/Documents/log4j -log4j.rootLogger=INFO, APPENDER1 +log4j.rootLogger=DEBUG, APPENDER1,CONSOLE +#Limiting logging level of log4j to WARN level +log4j.logger.org.apache.http=WARN #Define the file appender log4j.appender.APPENDER1=org.apache.log4j.RollingFileAppender log4j.appender.APPENDER1.File=${logs}/log.out @@ -27,10 +29,10 @@ log4j.appender.APPENDER1.MaxBackupIndex=5 log4j.appender.APPENDER1.layout=org.apache.log4j.PatternLayout log4j.appender.APPENDER1.layout.conversionPattern=%d{yyyy-MM-dd}-5p--10c:%m%n -#log4j.appender.CONSOLE= org.apache.log4j.ConsoleAppender -#log4j.appender.CONSOLE.Target=System.out -#log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout -#log4j.appender.CONSOLE.layout.conversionPattern=%d{yyyy-MM-dd}-5p--10c:%m%n +log4j.appender.CONSOLE= org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.Target=System.out +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.conversionPattern=%d{yyyy-MM-dd}-5p--10c:%m%n diff --git a/CodeQualityMatricesProject/src/test/java/com/wso2/code/quality/matrices/ApplicationTest.java b/CodeQualityMatricesProject/src/test/java/com/wso2/code/quality/matrices/ApplicationTest.java index 1d3350a..76ad9af 100644 --- a/CodeQualityMatricesProject/src/test/java/com/wso2/code/quality/matrices/ApplicationTest.java +++ b/CodeQualityMatricesProject/src/test/java/com/wso2/code/quality/matrices/ApplicationTest.java @@ -7,32 +7,28 @@ /** * Unit test for simple Application. */ -public class ApplicationTest - extends TestCase -{ +public class ApplicationTest extends TestCase { /** * Create the test case * * @param testName name of the test case */ - public ApplicationTest(String testName ) - { - super( testName ); + public ApplicationTest(String testName) { + super(testName); } /** * @return the suite of tests being tested */ - public static Test suite() - { - return new TestSuite( ApplicationTest.class ); + public static Test suite() { + return new TestSuite(ApplicationTest.class); } /** * Rigourous Test :-) */ - public void testApp() - { - assertTrue( true ); + public void testApp() { + assertTrue(true); } + } From 53645832fab1c22c65ea6e129f22b31515b6db9e Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 31 Mar 2017 00:36:44 +0530 Subject: [PATCH 47/62] Remove .classpath and .project created from Eclipse IDE --- CodeQualityMatricesProject/.classpath | 26 -------------------------- CodeQualityMatricesProject/.project | 23 ----------------------- 2 files changed, 49 deletions(-) delete mode 100644 CodeQualityMatricesProject/.classpath delete mode 100644 CodeQualityMatricesProject/.project diff --git a/CodeQualityMatricesProject/.classpath b/CodeQualityMatricesProject/.classpath deleted file mode 100644 index 9c865fb..0000000 --- a/CodeQualityMatricesProject/.classpath +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/CodeQualityMatricesProject/.project b/CodeQualityMatricesProject/.project deleted file mode 100644 index 8097dc1..0000000 --- a/CodeQualityMatricesProject/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - CodeQualityMatricesProject - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - From 184062b22cf654ec2b441fd7c29d576ddc542462 Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 31 Mar 2017 00:38:38 +0530 Subject: [PATCH 48/62] Moved .gitignore a level up in directory --- CodeQualityMatricesProject/.gitignore => .gitignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename CodeQualityMatricesProject/.gitignore => .gitignore (100%) diff --git a/CodeQualityMatricesProject/.gitignore b/.gitignore similarity index 100% rename from CodeQualityMatricesProject/.gitignore rename to .gitignore From 7ec687e65b71263149aa7e893f172184131f367f Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 31 Mar 2017 00:39:55 +0530 Subject: [PATCH 49/62] Change the repo name --- .../pom.xml | 0 .../src/main/java/com/wso2/code/quality/matrices/ApiUtility.java | 0 .../src/main/java/com/wso2/code/quality/matrices/Application.java | 0 .../main/java/com/wso2/code/quality/matrices/ChangesFinder.java | 0 .../wso2/code/quality/matrices/CodeQualityMatricesException.java | 0 .../wso2/code/quality/matrices/CodeQualityMatricesExecutor.java | 0 .../main/java/com/wso2/code/quality/matrices/GithubApiCaller.java | 0 .../main/java/com/wso2/code/quality/matrices/PmtApiCaller.java | 0 .../main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java | 0 .../main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java | 0 .../main/java/com/wso2/code/quality/matrices/model/Constants.java | 0 .../com/wso2/code/quality/matrices/model/GraphQlResponse.java | 0 .../main/java/com/wso2/code/quality/matrices/model/Graphql.java | 0 .../java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java | 0 .../java/com/wso2/code/quality/matrices/model/GraphqlBlame.java | 0 .../java/com/wso2/code/quality/matrices/model/GraphqlCommit.java | 0 .../java/com/wso2/code/quality/matrices/model/GraphqlData.java | 0 .../java/com/wso2/code/quality/matrices/model/GraphqlEdge.java | 0 .../java/com/wso2/code/quality/matrices/model/GraphqlHistory.java | 0 .../java/com/wso2/code/quality/matrices/model/GraphqlItem.java | 0 .../java/com/wso2/code/quality/matrices/model/GraphqlNode.java | 0 .../java/com/wso2/code/quality/matrices/model/GraphqlObject.java | 0 .../java/com/wso2/code/quality/matrices/model/GraphqlRange.java | 0 .../com/wso2/code/quality/matrices/model/GraphqlRepository.java | 0 .../com/wso2/code/quality/matrices/model/IssueApiResponse.java | 0 .../java/com/wso2/code/quality/matrices/model/Repository.java | 0 .../com/wso2/code/quality/matrices/model/ReviewApiResponse.java | 0 .../main/java/com/wso2/code/quality/matrices/model/Reviewer.java | 0 .../com/wso2/code/quality/matrices/model/SearchApiResponse.java | 0 .../java/com/wso2/code/quality/matrices/model/SearchItem.java | 0 .../src/main/resources/log4j.properties | 0 .../test/java/com/wso2/code/quality/matrices/ApplicationTest.java | 0 32 files changed, 0 insertions(+), 0 deletions(-) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/pom.xml (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/Application.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/Constants.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/Repository.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/main/resources/log4j.properties (100%) rename {CodeQualityMatricesProject => org.wso2.codequalitymatrices}/src/test/java/com/wso2/code/quality/matrices/ApplicationTest.java (100%) diff --git a/CodeQualityMatricesProject/pom.xml b/org.wso2.codequalitymatrices/pom.xml similarity index 100% rename from CodeQualityMatricesProject/pom.xml rename to org.wso2.codequalitymatrices/pom.xml diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Application.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/Application.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Constants.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Constants.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Repository.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Repository.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Repository.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Repository.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java diff --git a/CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java similarity index 100% rename from CodeQualityMatricesProject/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java diff --git a/CodeQualityMatricesProject/src/main/resources/log4j.properties b/org.wso2.codequalitymatrices/src/main/resources/log4j.properties similarity index 100% rename from CodeQualityMatricesProject/src/main/resources/log4j.properties rename to org.wso2.codequalitymatrices/src/main/resources/log4j.properties diff --git a/CodeQualityMatricesProject/src/test/java/com/wso2/code/quality/matrices/ApplicationTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/matrices/ApplicationTest.java similarity index 100% rename from CodeQualityMatricesProject/src/test/java/com/wso2/code/quality/matrices/ApplicationTest.java rename to org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/matrices/ApplicationTest.java From 2ce10d018c5585ec6e71c4f77954f74ce5d1c5d9 Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 31 Mar 2017 10:09:00 +0530 Subject: [PATCH 50/62] fix changes asked by Nisala in PR 1 --- org.wso2.codequalitymatrices/pom.xml | 12 +--- .../code/quality/matrices/ApiUtility.java | 12 ---- .../code/quality/matrices/Application.java | 2 - .../code/quality/matrices/ChangesFinder.java | 69 ++++++------------- .../matrices/CodeQualityMatricesExecutor.java | 13 +--- .../quality/matrices/GithubApiCaller.java | 22 +++--- .../code/quality/matrices/PmtApiCaller.java | 8 +-- .../code/quality/matrices/ReviewAnalyser.java | 33 ++++----- .../quality/matrices/SdkGitHubClient.java | 9 ++- .../quality/matrices/model/Constants.java | 5 +- .../code/quality/matrices/model/Graphql.java | 1 - 11 files changed, 61 insertions(+), 125 deletions(-) diff --git a/org.wso2.codequalitymatrices/pom.xml b/org.wso2.codequalitymatrices/pom.xml index 11b129e..6639c58 100644 --- a/org.wso2.codequalitymatrices/pom.xml +++ b/org.wso2.codequalitymatrices/pom.xml @@ -20,26 +20,21 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.wso2 wso2 5 - org.wso2.codeQualityMatrices CodeQualityMatrices - 0.0.1-SNAPSHOT + 1.0.0-SNAPSHOT jar - CodeQualityMatrices http://maven.apache.org - 1.8 UTF-8 - junit @@ -67,27 +62,22 @@ org.eclipse.egit.github.core 2.1.5 - org.apache.httpcomponents httpclient 4.5.2 - com.googlecode.json-simple json-simple 1.1.1 - org.apache.commons commons-lang3 3.5 - - diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java index 3994bdf..8f999ba 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java @@ -41,10 +41,8 @@ public final class ApiUtility { // to prevent instantiation private ApiUtility() { - } - /** * This is used for calling the REST APIs. * @@ -58,11 +56,9 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio CloseableHttpResponse httpResponse = null; httpClient = HttpClients.createDefault(); String jsonText; - try { httpResponse = httpClient.execute(httpGet); int responseCode = httpResponse.getStatusLine().getStatusCode(); - if (responseCode == 200) { //success bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), @@ -74,8 +70,6 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio } // creating a JSON object from the response jsonText = stringBuilder.toString(); - - } else { throw new CodeQualityMatricesException("Error occurred while calling the API, the response code is " + responseCode); @@ -123,7 +117,6 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatrice CloseableHttpResponse httpResponse = null; httpClient = HttpClients.createDefault(); String jsonText; - try { httpResponse = httpClient.execute(httpPost); int responseCode = httpResponse.getStatusLine().getStatusCode(); @@ -137,13 +130,10 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatrice } jsonText = stringBuilder.toString(); logger.debug("The response received from the Github GraphQL converted to a JSON text successfully"); - } else { throw new CodeQualityMatricesException("Error occurred while calling the API, the response code is " + responseCode); - } - } catch (UnsupportedEncodingException e) { throw new CodeQualityMatricesException("Encoding error occured before calling the github graphQL API", e); } catch (ClientProtocolException e) { @@ -174,9 +164,7 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatrice logger.debug("IOException occurred when closing the HttpClient", e); } } - } - return jsonText; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java index b6cc321..5109bbc 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java @@ -30,11 +30,9 @@ public class Application { public static void main(String[] args) { if (args.length == 3) { - String pmtToken = args[0]; String patchId = args[1]; String gitHubToken = args[2]; - CodeQualityMatricesExecutor codeQualityMatricesExecutor = new CodeQualityMatricesExecutor(pmtToken, patchId, gitHubToken); codeQualityMatricesExecutor.execute(); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index bc4c561..452d760 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -47,7 +47,6 @@ public class ChangesFinder { private static final Logger logger = Logger.getLogger(ChangesFinder.class); - private List fileNames = new ArrayList<>(); private List patchString = new ArrayList<>(); private final List> changedLineRanges = new ArrayList<>(); // for saving the line no that are changed @@ -59,7 +58,6 @@ public class ChangesFinder { private final GithubApiCaller githubApiCaller = new GithubApiCaller(); private final Gson gson = new Gson(); - /** * This is used for obtaining the repositories that contain the relevant commits belongs to the given patch * @@ -77,7 +75,6 @@ public Set obtainRepoNamesForCommitHashes(String gitHubToken, List StringUtils.contains(repositoryName, "wso2/")) .forEach(repositoryName -> { @@ -122,7 +118,6 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke fileNames = fileNamesWithPatcheString.get("fileNames"); patchString = fileNamesWithPatcheString.get("patchString"); } - saveRelaventEditLineNumbers(fileNames, patchString); try { findFileChanges(repositoryName, commitHash, gitHubToken); @@ -130,8 +125,10 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke logger.debug(e.getMessage(), e.getCause()); } }); - logger.debug("\n Author names :" + authorNames); - logger.debug("\n Author commits :" + authorCommits); + if (logger.isDebugEnabled()) { + logger.debug("\n Author names :" + authorNames); + logger.debug("\n Author commits :" + authorCommits); + } } /** @@ -143,9 +140,9 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke */ private void saveRelaventEditLineNumbers(List fileNames, List patchString) { - //filtering only the line ranges that are modified and saving to a string array - - // cannot use parallel streams here as the order of the line changes must be preserved + /*filtering only the line ranges that are modified and saving to a string array cannot use parallel streams + here as the order of the line changes must be preserved + */ patchString.stream() .map(patch -> StringUtils.substringsBetween(patch, "@@ ", " @@")) .forEach(lineChanges -> { @@ -162,7 +159,6 @@ private void saveRelaventEditLineNumbers(List fileNames, List pa // for taking the parent commit String lineRangeInTheNewFileResultedFromModification = StringUtils.substringAfter (tempString, "+"); - int intialLineNoInOldFile = Integer.parseInt(StringUtils.substringBefore (lineRangeInTheOldFileBeingModified, ",")); int tempEndLineNoInOldFile = Integer.parseInt(StringUtils.substringAfter @@ -188,8 +184,10 @@ private void saveRelaventEditLineNumbers(List fileNames, List pa changedLineRanges.add(changedRange); }); logger.debug("done saving file names and their relevant modification line ranges"); - logger.debug("\n File names : " + fileNames); - logger.debug("\n Changed ranges :" + changedLineRanges + "\n"); + if (logger.isDebugEnabled()) { + logger.debug("\n File names : " + fileNames); + logger.debug("\n Changed ranges :" + changedLineRanges + "\n"); + } } /** @@ -206,44 +204,40 @@ private void findFileChanges(String repoLocation, String commitHash, String gitH // filtering the owner and the Repository name from the repoLocation String owner = StringUtils.substringBefore(repoLocation, "/"); String repositoryName = StringUtils.substringAfter(repoLocation, "/"); - // iterating over the fileNames arraylist for the given commit - // cannot use parallel streams here as the order of the file names is important in the process + /* iterating over the fileNames arraylist for the given commit cannot use parallel streams here as the order + of the file names is important in the process + */ fileNames.forEach(fileName -> { int index = fileNames.indexOf(fileName); // the relevant arraylist of changed lines for that file List lineRangesForSelectedFile = changedLineRanges.get(index); // for storing the parent commit hashes for all the changed line ranges of the relevant file parentCommitHashes = new HashMap<>(); - Graphql graphqlBean = new Graphql(); graphqlBean.setGraphqlInputWithHistory(owner, repositoryName, commitHash, fileName); jsonStructure.put("query", graphqlBean.getGraphqlInputWithHistory()); - String jsonText = null; try { // calling the graphql API for getting blame information for the current file. jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); - } catch (CodeQualityMatricesException e) { logger.debug(e.getMessage(), e.getCause()); } //reading the above saved output for the current selected file name try { readBlameForSelectedFile(jsonText, lineRangesForSelectedFile); - logger.debug("Parent commits are saved for the " + fileName + " for all the modified line ranges"); + if (logger.isDebugEnabled()) { + logger.debug("Parent commits are saved for the " + fileName + " for all the modified line ranges"); + } } catch (CodeQualityMatricesException e) { logger.debug(e.getMessage(), e.getCause()); } - - findAuthorCommits(owner, repositoryName, fileName, lineRangesForSelectedFile, gitHubToken); - logger.debug("Authors and author commits of bug lines of code which are being fixed from the given " + "patch are saved successfully to authorNames and authorCommits Sets"); }); } - /** * This reads the blame received for the current selected file and insert parent commits of the changed lines * to a list. @@ -257,11 +251,9 @@ private void readBlameForSelectedFile(String jsonText, List changedRange GraphQlResponse graphQlResponse; try { graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); - } catch (JsonSyntaxException e) { throw new CodeQualityMatricesException(e.getMessage(), e.getCause()); } - GraphQlResponse finalGraphQlResponse = graphQlResponse; // to make a effective final variable changedRangesOfSelectedFile.forEach(lineRange -> { int startingLineNo; @@ -275,13 +267,10 @@ private void readBlameForSelectedFile(String jsonText, List changedRange */ startingLineNo = Integer.parseInt(StringUtils.substringBefore(newFileRange, ",")); endLineNo = Integer.parseInt(StringUtils.substringAfter(newFileRange, ",")); - //for storing age with the relevant parent commit hash Map> ageWithParentCommit = new HashMap<>(); - while (endLineNo >= startingLineNo) { int finalStartingLineNo = startingLineNo; // to make a effective final variable - finalGraphQlResponse.getData().getRepository().getObject().getBlame().getRanges().stream() .filter(graphqlRange -> (graphqlRange.getStartingLine() <= finalStartingLineNo && graphqlRange.getEndingLine() >= finalStartingLineNo)) @@ -291,19 +280,13 @@ private void readBlameForSelectedFile(String jsonText, List changedRange /* get(1) is used directly as there are only 2 elements in the List and last resembles the parent commit */ - String parentCommit = StringUtils.substringAfter(url, "commit/"); ageWithParentCommit.putIfAbsent(age, new HashSet<>()); if (!ageWithParentCommit.get(age).contains(parentCommit)) { ageWithParentCommit.get(age).add(parentCommit); } - - }); - - startingLineNo++; // to check for other line numbers - } TreeMap> sortedAgeWithParentCommit = new TreeMap<>(ageWithParentCommit); Set parentCommit = sortedAgeWithParentCommit.get(sortedAgeWithParentCommit.firstKey()); @@ -312,7 +295,6 @@ private void readBlameForSelectedFile(String jsonText, List changedRange }); } - /** * This is used to find the author and author commits of the buggy lines of code which are been fixed by the * given patch. @@ -331,23 +313,21 @@ private void findAuthorCommits(String owner, String repositoryName, String fileN Graphql graphqlBean = new Graphql(); commitHashes.parallelStream() .forEach(commitHash -> { - graphqlBean.setGraphqlInputWithoutHistory(owner, repositoryName, commitHash, fileName); jsonStructure.put("query", graphqlBean.getGraphqlInputWithoutHistory()); - String jsonText = null; try { jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); } catch (CodeQualityMatricesException e) { logger.debug(e.getMessage(), e.getCause()); } - saveAuthorCommits(jsonText, oldRange, lineRangesForSelectedFile); }); } - logger.debug("author commits and authors of bug lines of code on " + fileName + " file which are been fixed " + - "by the given patch are successfully saved to lists"); - + if (logger.isDebugEnabled()) { + logger.debug("author commits and authors of bug lines of code on " + fileName + " file which are been " + + "fixed by the given patch are successfully saved to lists"); + } } /** @@ -361,7 +341,6 @@ private void findAuthorCommits(String owner, String repositoryName, String fileN private void saveAuthorCommits(String jsonText, String oldRange, List lineRangesForSelectedFile) { GraphQlResponse graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); - lineRangesForSelectedFile.forEach(lineRange -> { int startingLineNo; int endLineNo; @@ -371,23 +350,17 @@ private void saveAuthorCommits(String jsonText, String oldRange, List li // need to consider the correct line range in the old file for finding authors and author commits startingLineNo = Integer.parseInt(StringUtils.substringBefore(oldFileRange, ",")); endLineNo = Integer.parseInt(StringUtils.substringAfter(oldFileRange, ",")); - while (endLineNo >= startingLineNo) { int finalStartingLineNo = startingLineNo; // to make a effective final variable - graphQlResponse.getData().getRepository().getObject().getBlame().getRanges().stream() .filter(graphqlRange -> (graphqlRange.getStartingLine() <= finalStartingLineNo && graphqlRange.getEndingLine() >= finalStartingLineNo)) .forEach(graphqlRange -> { - String authorName = graphqlRange.getCommit().getAuthor().getName(); String authorcommit = StringUtils.substringAfter(graphqlRange.getCommit().getUrl(), "commit/"); - authorNames.add(authorName); // authors are added to the Set authorCommits.add(authorcommit); // author commits are added to the set - - }); startingLineNo++; // to check for other line numbers } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java index e63b4f7..704b356 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java @@ -28,7 +28,6 @@ import static com.wso2.code.quality.matrices.model.Constants.COMMITS_INSIDE_GIVEN_PATCH; - /** * This is used for creating executing the program. * @@ -52,7 +51,6 @@ public CodeQualityMatricesExecutor(String pmtToken, String patchId, String gitHu this.pmtToken = pmtToken; this.patchId = patchId; this.gitHubToken = gitHubToken; - } /** @@ -63,13 +61,10 @@ public void execute() { List commitHashes = findCommitHashesInPatch(); ChangesFinder changesFinder = new ChangesFinder(); Set authorCommits = changesFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitHashes); - ReviewAnalyser reviewAnalyser = new ReviewAnalyser(); reviewAnalyser.findReviewers(authorCommits, gitHubToken); reviewAnalyser.printReviewUsers(); - logger.debug("The application executed successfully"); - } catch (CodeQualityMatricesException e) { logger.debug(e.getMessage(), e.getCause()); } @@ -84,15 +79,12 @@ private List findCommitHashesInPatch() throws CodeQualityMatricesExcepti PmtApiCaller pmtApiCaller = new PmtApiCaller(); String jsonText; List commitHashes = new ArrayList<>(); - try { jsonText = pmtApiCaller.callApi(pmtToken, patchId); } catch (CodeQualityMatricesException e) { throw new CodeQualityMatricesException("Error occurred while calling PMT API", e); } - Gson gson = new Gson(); - if (jsonText != null) { List pmtResponse = gson.fromJson(jsonText, List.class); for (Object pmtEntry : pmtResponse) { @@ -103,11 +95,12 @@ private List findCommitHashesInPatch() throws CodeQualityMatricesExcepti } } } - logger.debug("The commit hashes are: " + commitHashes); + if (logger.isDebugEnabled()) { + logger.debug("The commit hashes are: " + commitHashes); + } } else { throw new CodeQualityMatricesException("The returned jsonText from PMT API is null"); } - return commitHashes; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java index d58daa0..2c5cba6 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java @@ -25,6 +25,10 @@ import java.io.UnsupportedEncodingException; +import static com.wso2.code.quality.matrices.model.Constants.ACCEPT; +import static com.wso2.code.quality.matrices.model.Constants.AUTHORIZATION; +import static com.wso2.code.quality.matrices.model.Constants.BEARER; + /** * This is used for all github communications. * @@ -45,9 +49,9 @@ public String callSearchCommitApi(String commitHash, String githubAccessToken) t String url = "https://api.github.com/search/commits?q=hash%3A" + commitHash; try { httpGet = new HttpGet(url); - httpGet.addHeader("Authorization", "Bearer " + githubAccessToken); + httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); //as the accept header is needed for accessing commit search API which is still in preview mode - httpGet.addHeader("Accept", "application/vnd.github.cloak-preview"); + httpGet.addHeader(ACCEPT, "application/vnd.github.cloak-preview"); } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the Github Search Commit API is " + "invalid ", e); @@ -69,8 +73,8 @@ public String callReviewApi(String repoLocation, int pullRequestNumber, String g String url = "https://api.github.com/repos/" + repoLocation + "/pulls/" + pullRequestNumber + "/reviews"; try { httpGet = new HttpGet(url); - httpGet.addHeader("Accept", "application/vnd.github.black-cat-preview+json"); - httpGet.addHeader("Authorization", "Bearer " + githubAccessToken); + httpGet.addHeader(ACCEPT, "application/vnd.github.black-cat-preview+json"); + httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the Github Review Commit API is " + "invalid ", e); @@ -91,8 +95,8 @@ public String callSearchIssueApi(String commitHashToBeSearched, String githubAcc String url = "https://api.github.com/search/issues?q=" + commitHashToBeSearched; try { httpGet = new HttpGet(url); - httpGet.addHeader("Accept", "application/vnd.github.mercy-preview+json"); - httpGet.addHeader("Authorization", "Bearer " + githubAccessToken); + httpGet.addHeader(ACCEPT, "application/vnd.github.mercy-preview+json"); + httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the Github Search Issue API is " + "invalid ", e); @@ -114,11 +118,10 @@ public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken HttpPost httpPost; try { httpPost = new HttpPost(url); - httpPost.addHeader("Authorization", "Bearer " + githubToken); - httpPost.addHeader("Accept", "application/json"); + httpPost.addHeader(AUTHORIZATION, BEARER + githubToken); + httpPost.addHeader(ACCEPT, "application/json"); StringEntity entity = new StringEntity(graphqlJsonStructure.toString()); httpPost.setEntity(entity); - } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the Github Graphql API is " + "invalid", e); @@ -127,6 +130,5 @@ public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken "Structure", e); } return ApiUtility.callGraphQlApi(httpPost); - } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java index e95b8ae..799af57 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java @@ -20,6 +20,9 @@ import org.apache.http.client.methods.HttpGet; +import static com.wso2.code.quality.matrices.model.Constants.AUTHORIZATION; +import static com.wso2.code.quality.matrices.model.Constants.BEARER; + /** * This is used for all the WSO2 PMT communications. * @@ -27,7 +30,6 @@ */ public class PmtApiCaller { public PmtApiCaller() { - } /** @@ -44,12 +46,10 @@ public String callApi(String accessToken, String patchId) throws CodeQualityMatr HttpGet httpGet; try { httpGet = new HttpGet(pmtUrl); - httpGet.addHeader("Authorization", "Bearer " + accessToken); - + httpGet.addHeader(AUTHORIZATION, BEARER + accessToken); } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the PMT API is invalid ", e); } - return ApiUtility.callApi(httpGet); } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java index 33881ac..3955795 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java @@ -30,11 +30,11 @@ import java.util.List; import java.util.Map; import java.util.Set; + import static com.wso2.code.quality.matrices.model.Constants.GITHUB_REVIEW_API_CLOSED_STATE; import static com.wso2.code.quality.matrices.model.Constants.GITHUB_REVIEW_APPROVED; import static com.wso2.code.quality.matrices.model.Constants.GITHUB_REVIEW_COMMENTED; - /** * This class is used to find the reviewers of the buggy lines of code. * @@ -48,10 +48,7 @@ public class ReviewAnalyser { private final Set approvedReviewers = new HashSet<>(); // to store the reviewed and commented users of the pull requests private final Set commentedReviewers = new HashSet<>(); - - //constants for filtering github API responses - private final GithubApiCaller githubApiCaller = new GithubApiCaller(); private final Gson gson = new Gson(); @@ -62,15 +59,15 @@ public class ReviewAnalyser { * @param githubToken Github access token for accessing github API */ public void findReviewers(Set authorCommits, String githubToken) { - authorCommits.forEach(commitHash -> { String jsonText; - try { jsonText = githubApiCaller.callSearchIssueApi(commitHash, githubToken); Map> prNoWithRepoName = savePrNumberAndRepoName(jsonText); - logger.debug("Relevant pull requests on patch " + commitHash + " with their relevant repository " + - "names are successfully saved in a map."); + if (logger.isDebugEnabled()) { + logger.debug("Relevant pull requests on patch " + commitHash + " with their relevant repository " + + "names are successfully saved in a map."); + } saveReviewers(prNoWithRepoName, githubToken); } catch (CodeQualityMatricesException e) { logger.debug(e.getMessage(), e.getCause()); @@ -86,12 +83,10 @@ public void findReviewers(Set authorCommits, String githubToken) { * @throws CodeQualityMatricesException */ private Map> savePrNumberAndRepoName(String jsonText) throws CodeQualityMatricesException { - // map for storing the pull requests numbers against their Repository Map> prNoWithRepoName = new HashMap<>(); try { IssueApiResponse issueApiResponse = gson.fromJson(jsonText, IssueApiResponse.class); - issueApiResponse.getItems().parallelStream() .filter(searchItem -> GITHUB_REVIEW_API_CLOSED_STATE.equals(searchItem.getState())) .filter(searchItem -> StringUtils.contains(searchItem.getRepositoryUrl(), "/wso2/")) @@ -103,7 +98,6 @@ private Map> savePrNumberAndRepoName(String jsonText) throw if (!prNoWithRepoName.get(repositoryName).contains(pullRequestNo)) { prNoWithRepoName.get(repositoryName).add(pullRequestNo); } - }); } catch (JsonSyntaxException e) { throw new CodeQualityMatricesException(e.getMessage(), e.getCause()); @@ -121,13 +115,11 @@ private Map> savePrNumberAndRepoName(String jsonText) throw * @param githubToken Github access token for accessing github API */ private void saveReviewers(Map> prNoWithRepoName, String githubToken) { - for (Map.Entry entry : prNoWithRepoName.entrySet()) { String repositoryName = (String) entry.getKey(); Set prNumbers = (Set) entry.getValue(); prNumbers.parallelStream() .forEach(prNumber -> { - try { String jsonText = githubApiCaller.callReviewApi(repositoryName, prNumber, githubToken); if (jsonText != null) { @@ -136,19 +128,18 @@ private void saveReviewers(Map> prNoWithRepoName, String gi reviews.parallelStream() .filter(review -> GITHUB_REVIEW_APPROVED.equals(review.getState())) .forEach(review -> approvedReviewers.add(review.getReviewer().getName())); - logger.debug("Users who approved the pull requests which introduce bug lines to the " + "code base are successfully saved to approvedReviewers list"); - reviews.parallelStream() .filter(review -> GITHUB_REVIEW_COMMENTED.equals(review.getState())) .forEach(review -> commentedReviewers.add(review.getReviewer().getName())); - logger.debug("Users who commented on the pull requests which introduce bug lines to " + "the code base are successfully saved to approvedReviewers list"); } else { - logger.debug("There are no records of reviews for pull request: " + prNumber + - " on " + repositoryName + " repository"); + if (logger.isDebugEnabled()) { + logger.debug("There are no records of reviews for pull request: " + prNumber + + " on " + repositoryName + " repository"); + } } } catch (CodeQualityMatricesException e) { logger.error(e.getMessage(), e.getCause()); @@ -161,7 +152,9 @@ private void saveReviewers(Map> prNoWithRepoName, String gi * Print the list of reviewers and commented users on the pull requests which introduce bugs to the code base */ public void printReviewUsers() { - logger.debug("\n Reviewed and approved users of the bug lines: " + approvedReviewers); - logger.debug("\n Reviewed and commented users on bug lines: " + commentedReviewers); + if (logger.isDebugEnabled()) { + logger.debug("\n Reviewed and approved users of the bug lines: " + approvedReviewers); + logger.debug("\n Reviewed and commented users on bug lines: " + commentedReviewers); + } } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java index cb2d01a..ac436dc 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java @@ -45,7 +45,6 @@ public class SdkGitHubClient { private CommitService commitService = null; private RepositoryService repositoryService = null; - SdkGitHubClient(String githubToken) { gitHubClient = new GitHubClient(); gitHubClient.setOAuth2Token(githubToken); @@ -70,16 +69,16 @@ public Map> getFilesChanged(String repositoryName, String c List filesChanged = repositoryCommit.getFiles(); List tempFileNames = new ArrayList<>(); List tempPatchString = new ArrayList<>(); - // this can be run parallely as patchString of a file will always be in the same index as the file filesChanged.parallelStream() .forEach(commitFile -> { tempFileNames.add(commitFile.getFilename()); tempPatchString.add(commitFile.getPatch()); }); - logger.debug("for commit hash" + commitHash + " on the " + repositoryName + " repository, files changed " + - "and their " + - "relevant changed line ranges are added to the arraylists successfully"); + if (logger.isDebugEnabled()) { + logger.debug("for commit hash" + commitHash + " on the " + repositoryName + " repository, files" + + " changed and their relevant changed line ranges are added to the arraylists successfully"); + } fileNamesAndPatches.put("fileNames", tempFileNames); fileNamesAndPatches.put("patchString", tempPatchString); logger.debug("Modified file names with their relevant modified line ranges are saved to a map " + diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java index e92b4b3..bdedd85 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java @@ -28,6 +28,7 @@ public class Constants { public static final String GITHUB_REVIEW_APPROVED = "APPROVED"; public static final String GITHUB_REVIEW_COMMENTED = "COMMENTED"; public static final String GITHUB_REVIEW_API_CLOSED_STATE = "closed"; - - + public static final String AUTHORIZATION = "Authorization"; + public static final String BEARER = "Bearer "; + public static final String ACCEPT = "Accept"; } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java index 93b91cc..e7bc9be 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java @@ -30,7 +30,6 @@ public class Graphql implements Serializable { private String graphqlInputWithoutHistory; public Graphql() { - } public String getGraphqlInputWithHistory() { From 5d3ae060eabd054fa9174c35a4aca51dfa61fd46 Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 31 Mar 2017 10:09:00 +0530 Subject: [PATCH 51/62] fix changes asked in PR 1 --- org.wso2.codequalitymatrices/pom.xml | 12 +-- .../code/quality/matrices/ApiUtility.java | 12 --- .../code/quality/matrices/Application.java | 2 - .../code/quality/matrices/ChangesFinder.java | 80 +++++++------------ .../matrices/CodeQualityMatricesExecutor.java | 13 +-- .../quality/matrices/GithubApiCaller.java | 22 ++--- .../code/quality/matrices/PmtApiCaller.java | 8 +- .../code/quality/matrices/ReviewAnalyser.java | 43 +++++----- .../quality/matrices/SdkGitHubClient.java | 9 +-- .../quality/matrices/model/Constants.java | 5 +- .../matrices/model/GraphQlResponse.java | 13 +-- .../code/quality/matrices/model/Graphql.java | 1 - .../quality/matrices/model/GraphqlAuthor.java | 12 +-- .../quality/matrices/model/GraphqlBlame.java | 4 +- .../quality/matrices/model/GraphqlCommit.java | 5 ++ .../quality/matrices/model/GraphqlData.java | 3 + .../quality/matrices/model/GraphqlEdge.java | 13 +-- .../matrices/model/GraphqlHistory.java | 13 +-- .../quality/matrices/model/GraphqlNode.java | 3 + .../quality/matrices/model/GraphqlObject.java | 3 + .../quality/matrices/model/GraphqlRange.java | 6 ++ .../matrices/model/GraphqlRepository.java | 13 +-- .../matrices/model/IssueApiResponse.java | 13 +-- .../quality/matrices/model/Repository.java | 13 +-- .../{GraphqlItem.java => RepositoryItem.java} | 6 +- .../matrices/model/ReviewApiResponse.java | 22 ++--- .../code/quality/matrices/model/Reviewer.java | 9 ++- .../matrices/model/SearchApiResponse.java | 22 ++--- .../quality/matrices/model/SearchItem.java | 35 ++++---- 29 files changed, 197 insertions(+), 218 deletions(-) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/{GraphqlItem.java => RepositoryItem.java} (89%) diff --git a/org.wso2.codequalitymatrices/pom.xml b/org.wso2.codequalitymatrices/pom.xml index 11b129e..6639c58 100644 --- a/org.wso2.codequalitymatrices/pom.xml +++ b/org.wso2.codequalitymatrices/pom.xml @@ -20,26 +20,21 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.wso2 wso2 5 - org.wso2.codeQualityMatrices CodeQualityMatrices - 0.0.1-SNAPSHOT + 1.0.0-SNAPSHOT jar - CodeQualityMatrices http://maven.apache.org - 1.8 UTF-8 - junit @@ -67,27 +62,22 @@ org.eclipse.egit.github.core 2.1.5 - org.apache.httpcomponents httpclient 4.5.2 - com.googlecode.json-simple json-simple 1.1.1 - org.apache.commons commons-lang3 3.5 - - diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java index 3994bdf..8f999ba 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java @@ -41,10 +41,8 @@ public final class ApiUtility { // to prevent instantiation private ApiUtility() { - } - /** * This is used for calling the REST APIs. * @@ -58,11 +56,9 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio CloseableHttpResponse httpResponse = null; httpClient = HttpClients.createDefault(); String jsonText; - try { httpResponse = httpClient.execute(httpGet); int responseCode = httpResponse.getStatusLine().getStatusCode(); - if (responseCode == 200) { //success bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), @@ -74,8 +70,6 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio } // creating a JSON object from the response jsonText = stringBuilder.toString(); - - } else { throw new CodeQualityMatricesException("Error occurred while calling the API, the response code is " + responseCode); @@ -123,7 +117,6 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatrice CloseableHttpResponse httpResponse = null; httpClient = HttpClients.createDefault(); String jsonText; - try { httpResponse = httpClient.execute(httpPost); int responseCode = httpResponse.getStatusLine().getStatusCode(); @@ -137,13 +130,10 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatrice } jsonText = stringBuilder.toString(); logger.debug("The response received from the Github GraphQL converted to a JSON text successfully"); - } else { throw new CodeQualityMatricesException("Error occurred while calling the API, the response code is " + responseCode); - } - } catch (UnsupportedEncodingException e) { throw new CodeQualityMatricesException("Encoding error occured before calling the github graphQL API", e); } catch (ClientProtocolException e) { @@ -174,9 +164,7 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatrice logger.debug("IOException occurred when closing the HttpClient", e); } } - } - return jsonText; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java index b6cc321..5109bbc 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java @@ -30,11 +30,9 @@ public class Application { public static void main(String[] args) { if (args.length == 3) { - String pmtToken = args[0]; String patchId = args[1]; String gitHubToken = args[2]; - CodeQualityMatricesExecutor codeQualityMatricesExecutor = new CodeQualityMatricesExecutor(pmtToken, patchId, gitHubToken); codeQualityMatricesExecutor.execute(); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java index bc4c561..a700000 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java @@ -47,7 +47,6 @@ public class ChangesFinder { private static final Logger logger = Logger.getLogger(ChangesFinder.class); - private List fileNames = new ArrayList<>(); private List patchString = new ArrayList<>(); private final List> changedLineRanges = new ArrayList<>(); // for saving the line no that are changed @@ -59,7 +58,6 @@ public class ChangesFinder { private final GithubApiCaller githubApiCaller = new GithubApiCaller(); private final Gson gson = new Gson(); - /** * This is used for obtaining the repositories that contain the relevant commits belongs to the given patch * @@ -77,7 +75,6 @@ public Set obtainRepoNamesForCommitHashes(String gitHubToken, List repoLocation.add(recordItem.getRepository().getFull_name())); + searchCommitPojo.getContainingRepositories() + .forEach(recordItem -> repoLocation.add(recordItem.getRepository().getRepositoryLocation())); logger.debug("Repositories having the given commit are successfully saved in an List"); SdkGitHubClient sdkGitHubClient = new SdkGitHubClient(gitHubToken); - repoLocation.stream() .filter(repositoryName -> StringUtils.contains(repositoryName, "wso2/")) .forEach(repositoryName -> { @@ -122,7 +118,6 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke fileNames = fileNamesWithPatcheString.get("fileNames"); patchString = fileNamesWithPatcheString.get("patchString"); } - saveRelaventEditLineNumbers(fileNames, patchString); try { findFileChanges(repositoryName, commitHash, gitHubToken); @@ -130,8 +125,10 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke logger.debug(e.getMessage(), e.getCause()); } }); - logger.debug("\n Author names :" + authorNames); - logger.debug("\n Author commits :" + authorCommits); + if (logger.isDebugEnabled()) { + logger.debug("\n Author names :" + authorNames); + logger.debug("\n Author commits :" + authorCommits); + } } /** @@ -143,9 +140,9 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke */ private void saveRelaventEditLineNumbers(List fileNames, List patchString) { - //filtering only the line ranges that are modified and saving to a string array - - // cannot use parallel streams here as the order of the line changes must be preserved + /*filtering only the line ranges that are modified and saving to a string array cannot use parallel streams + here as the order of the line changes must be preserved + */ patchString.stream() .map(patch -> StringUtils.substringsBetween(patch, "@@ ", " @@")) .forEach(lineChanges -> { @@ -162,7 +159,6 @@ private void saveRelaventEditLineNumbers(List fileNames, List pa // for taking the parent commit String lineRangeInTheNewFileResultedFromModification = StringUtils.substringAfter (tempString, "+"); - int intialLineNoInOldFile = Integer.parseInt(StringUtils.substringBefore (lineRangeInTheOldFileBeingModified, ",")); int tempEndLineNoInOldFile = Integer.parseInt(StringUtils.substringAfter @@ -188,8 +184,10 @@ private void saveRelaventEditLineNumbers(List fileNames, List pa changedLineRanges.add(changedRange); }); logger.debug("done saving file names and their relevant modification line ranges"); - logger.debug("\n File names : " + fileNames); - logger.debug("\n Changed ranges :" + changedLineRanges + "\n"); + if (logger.isDebugEnabled()) { + logger.debug("\n File names : " + fileNames); + logger.debug("\n Changed ranges :" + changedLineRanges + "\n"); + } } /** @@ -206,44 +204,40 @@ private void findFileChanges(String repoLocation, String commitHash, String gitH // filtering the owner and the Repository name from the repoLocation String owner = StringUtils.substringBefore(repoLocation, "/"); String repositoryName = StringUtils.substringAfter(repoLocation, "/"); - // iterating over the fileNames arraylist for the given commit - // cannot use parallel streams here as the order of the file names is important in the process + /* iterating over the fileNames arraylist for the given commit cannot use parallel streams here as the order + of the file names is important in the process + */ fileNames.forEach(fileName -> { int index = fileNames.indexOf(fileName); // the relevant arraylist of changed lines for that file List lineRangesForSelectedFile = changedLineRanges.get(index); // for storing the parent commit hashes for all the changed line ranges of the relevant file parentCommitHashes = new HashMap<>(); - Graphql graphqlBean = new Graphql(); graphqlBean.setGraphqlInputWithHistory(owner, repositoryName, commitHash, fileName); jsonStructure.put("query", graphqlBean.getGraphqlInputWithHistory()); - String jsonText = null; try { // calling the graphql API for getting blame information for the current file. jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); - } catch (CodeQualityMatricesException e) { logger.debug(e.getMessage(), e.getCause()); } //reading the above saved output for the current selected file name try { readBlameForSelectedFile(jsonText, lineRangesForSelectedFile); - logger.debug("Parent commits are saved for the " + fileName + " for all the modified line ranges"); + if (logger.isDebugEnabled()) { + logger.debug("Parent commits are saved for the " + fileName + " for all the modified line ranges"); + } } catch (CodeQualityMatricesException e) { logger.debug(e.getMessage(), e.getCause()); } - - findAuthorCommits(owner, repositoryName, fileName, lineRangesForSelectedFile, gitHubToken); - logger.debug("Authors and author commits of bug lines of code which are being fixed from the given " + "patch are saved successfully to authorNames and authorCommits Sets"); }); } - /** * This reads the blame received for the current selected file and insert parent commits of the changed lines * to a list. @@ -257,11 +251,9 @@ private void readBlameForSelectedFile(String jsonText, List changedRange GraphQlResponse graphQlResponse; try { graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); - } catch (JsonSyntaxException e) { throw new CodeQualityMatricesException(e.getMessage(), e.getCause()); } - GraphQlResponse finalGraphQlResponse = graphQlResponse; // to make a effective final variable changedRangesOfSelectedFile.forEach(lineRange -> { int startingLineNo; @@ -275,35 +267,27 @@ private void readBlameForSelectedFile(String jsonText, List changedRange */ startingLineNo = Integer.parseInt(StringUtils.substringBefore(newFileRange, ",")); endLineNo = Integer.parseInt(StringUtils.substringAfter(newFileRange, ",")); - //for storing age with the relevant parent commit hash Map> ageWithParentCommit = new HashMap<>(); - while (endLineNo >= startingLineNo) { int finalStartingLineNo = startingLineNo; // to make a effective final variable - - finalGraphQlResponse.getData().getRepository().getObject().getBlame().getRanges().stream() + finalGraphQlResponse.getResponse().getRepository().getFile().getBlame().getRanges().stream() .filter(graphqlRange -> (graphqlRange.getStartingLine() <= finalStartingLineNo && graphqlRange.getEndingLine() >= finalStartingLineNo)) .forEach(graphqlRange -> { int age = graphqlRange.getAge(); - String url = graphqlRange.getCommit().getHistory().getEdges().get(1).getNode().getUrl(); + String url = graphqlRange.getCommit().getHistory().getCommits().get(1).getDetails() + .getUrl(); /* get(1) is used directly as there are only 2 elements in the List and last resembles the parent commit */ - String parentCommit = StringUtils.substringAfter(url, "commit/"); ageWithParentCommit.putIfAbsent(age, new HashSet<>()); if (!ageWithParentCommit.get(age).contains(parentCommit)) { ageWithParentCommit.get(age).add(parentCommit); } - - }); - - startingLineNo++; // to check for other line numbers - } TreeMap> sortedAgeWithParentCommit = new TreeMap<>(ageWithParentCommit); Set parentCommit = sortedAgeWithParentCommit.get(sortedAgeWithParentCommit.firstKey()); @@ -312,7 +296,6 @@ private void readBlameForSelectedFile(String jsonText, List changedRange }); } - /** * This is used to find the author and author commits of the buggy lines of code which are been fixed by the * given patch. @@ -331,23 +314,21 @@ private void findAuthorCommits(String owner, String repositoryName, String fileN Graphql graphqlBean = new Graphql(); commitHashes.parallelStream() .forEach(commitHash -> { - graphqlBean.setGraphqlInputWithoutHistory(owner, repositoryName, commitHash, fileName); jsonStructure.put("query", graphqlBean.getGraphqlInputWithoutHistory()); - String jsonText = null; try { jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); } catch (CodeQualityMatricesException e) { logger.debug(e.getMessage(), e.getCause()); } - saveAuthorCommits(jsonText, oldRange, lineRangesForSelectedFile); }); } - logger.debug("author commits and authors of bug lines of code on " + fileName + " file which are been fixed " + - "by the given patch are successfully saved to lists"); - + if (logger.isDebugEnabled()) { + logger.debug("author commits and authors of bug lines of code on " + fileName + " file which are been " + + "fixed by the given patch are successfully saved to lists"); + } } /** @@ -361,7 +342,6 @@ private void findAuthorCommits(String owner, String repositoryName, String fileN private void saveAuthorCommits(String jsonText, String oldRange, List lineRangesForSelectedFile) { GraphQlResponse graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); - lineRangesForSelectedFile.forEach(lineRange -> { int startingLineNo; int endLineNo; @@ -371,23 +351,17 @@ private void saveAuthorCommits(String jsonText, String oldRange, List li // need to consider the correct line range in the old file for finding authors and author commits startingLineNo = Integer.parseInt(StringUtils.substringBefore(oldFileRange, ",")); endLineNo = Integer.parseInt(StringUtils.substringAfter(oldFileRange, ",")); - while (endLineNo >= startingLineNo) { int finalStartingLineNo = startingLineNo; // to make a effective final variable - - graphQlResponse.getData().getRepository().getObject().getBlame().getRanges().stream() + graphQlResponse.getResponse().getRepository().getFile().getBlame().getRanges().stream() .filter(graphqlRange -> (graphqlRange.getStartingLine() <= finalStartingLineNo && graphqlRange.getEndingLine() >= finalStartingLineNo)) .forEach(graphqlRange -> { - String authorName = graphqlRange.getCommit().getAuthor().getName(); String authorcommit = StringUtils.substringAfter(graphqlRange.getCommit().getUrl(), "commit/"); - authorNames.add(authorName); // authors are added to the Set authorCommits.add(authorcommit); // author commits are added to the set - - }); startingLineNo++; // to check for other line numbers } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java index e63b4f7..704b356 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java @@ -28,7 +28,6 @@ import static com.wso2.code.quality.matrices.model.Constants.COMMITS_INSIDE_GIVEN_PATCH; - /** * This is used for creating executing the program. * @@ -52,7 +51,6 @@ public CodeQualityMatricesExecutor(String pmtToken, String patchId, String gitHu this.pmtToken = pmtToken; this.patchId = patchId; this.gitHubToken = gitHubToken; - } /** @@ -63,13 +61,10 @@ public void execute() { List commitHashes = findCommitHashesInPatch(); ChangesFinder changesFinder = new ChangesFinder(); Set authorCommits = changesFinder.obtainRepoNamesForCommitHashes(gitHubToken, commitHashes); - ReviewAnalyser reviewAnalyser = new ReviewAnalyser(); reviewAnalyser.findReviewers(authorCommits, gitHubToken); reviewAnalyser.printReviewUsers(); - logger.debug("The application executed successfully"); - } catch (CodeQualityMatricesException e) { logger.debug(e.getMessage(), e.getCause()); } @@ -84,15 +79,12 @@ private List findCommitHashesInPatch() throws CodeQualityMatricesExcepti PmtApiCaller pmtApiCaller = new PmtApiCaller(); String jsonText; List commitHashes = new ArrayList<>(); - try { jsonText = pmtApiCaller.callApi(pmtToken, patchId); } catch (CodeQualityMatricesException e) { throw new CodeQualityMatricesException("Error occurred while calling PMT API", e); } - Gson gson = new Gson(); - if (jsonText != null) { List pmtResponse = gson.fromJson(jsonText, List.class); for (Object pmtEntry : pmtResponse) { @@ -103,11 +95,12 @@ private List findCommitHashesInPatch() throws CodeQualityMatricesExcepti } } } - logger.debug("The commit hashes are: " + commitHashes); + if (logger.isDebugEnabled()) { + logger.debug("The commit hashes are: " + commitHashes); + } } else { throw new CodeQualityMatricesException("The returned jsonText from PMT API is null"); } - return commitHashes; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java index d58daa0..2c5cba6 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java @@ -25,6 +25,10 @@ import java.io.UnsupportedEncodingException; +import static com.wso2.code.quality.matrices.model.Constants.ACCEPT; +import static com.wso2.code.quality.matrices.model.Constants.AUTHORIZATION; +import static com.wso2.code.quality.matrices.model.Constants.BEARER; + /** * This is used for all github communications. * @@ -45,9 +49,9 @@ public String callSearchCommitApi(String commitHash, String githubAccessToken) t String url = "https://api.github.com/search/commits?q=hash%3A" + commitHash; try { httpGet = new HttpGet(url); - httpGet.addHeader("Authorization", "Bearer " + githubAccessToken); + httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); //as the accept header is needed for accessing commit search API which is still in preview mode - httpGet.addHeader("Accept", "application/vnd.github.cloak-preview"); + httpGet.addHeader(ACCEPT, "application/vnd.github.cloak-preview"); } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the Github Search Commit API is " + "invalid ", e); @@ -69,8 +73,8 @@ public String callReviewApi(String repoLocation, int pullRequestNumber, String g String url = "https://api.github.com/repos/" + repoLocation + "/pulls/" + pullRequestNumber + "/reviews"; try { httpGet = new HttpGet(url); - httpGet.addHeader("Accept", "application/vnd.github.black-cat-preview+json"); - httpGet.addHeader("Authorization", "Bearer " + githubAccessToken); + httpGet.addHeader(ACCEPT, "application/vnd.github.black-cat-preview+json"); + httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the Github Review Commit API is " + "invalid ", e); @@ -91,8 +95,8 @@ public String callSearchIssueApi(String commitHashToBeSearched, String githubAcc String url = "https://api.github.com/search/issues?q=" + commitHashToBeSearched; try { httpGet = new HttpGet(url); - httpGet.addHeader("Accept", "application/vnd.github.mercy-preview+json"); - httpGet.addHeader("Authorization", "Bearer " + githubAccessToken); + httpGet.addHeader(ACCEPT, "application/vnd.github.mercy-preview+json"); + httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the Github Search Issue API is " + "invalid ", e); @@ -114,11 +118,10 @@ public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken HttpPost httpPost; try { httpPost = new HttpPost(url); - httpPost.addHeader("Authorization", "Bearer " + githubToken); - httpPost.addHeader("Accept", "application/json"); + httpPost.addHeader(AUTHORIZATION, BEARER + githubToken); + httpPost.addHeader(ACCEPT, "application/json"); StringEntity entity = new StringEntity(graphqlJsonStructure.toString()); httpPost.setEntity(entity); - } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the Github Graphql API is " + "invalid", e); @@ -127,6 +130,5 @@ public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken "Structure", e); } return ApiUtility.callGraphQlApi(httpPost); - } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java index e95b8ae..799af57 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java @@ -20,6 +20,9 @@ import org.apache.http.client.methods.HttpGet; +import static com.wso2.code.quality.matrices.model.Constants.AUTHORIZATION; +import static com.wso2.code.quality.matrices.model.Constants.BEARER; + /** * This is used for all the WSO2 PMT communications. * @@ -27,7 +30,6 @@ */ public class PmtApiCaller { public PmtApiCaller() { - } /** @@ -44,12 +46,10 @@ public String callApi(String accessToken, String patchId) throws CodeQualityMatr HttpGet httpGet; try { httpGet = new HttpGet(pmtUrl); - httpGet.addHeader("Authorization", "Bearer " + accessToken); - + httpGet.addHeader(AUTHORIZATION, BEARER + accessToken); } catch (IllegalArgumentException e) { throw new CodeQualityMatricesException("The url provided for accessing the PMT API is invalid ", e); } - return ApiUtility.callApi(httpGet); } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java index 33881ac..09dd11f 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java @@ -30,11 +30,11 @@ import java.util.List; import java.util.Map; import java.util.Set; + import static com.wso2.code.quality.matrices.model.Constants.GITHUB_REVIEW_API_CLOSED_STATE; import static com.wso2.code.quality.matrices.model.Constants.GITHUB_REVIEW_APPROVED; import static com.wso2.code.quality.matrices.model.Constants.GITHUB_REVIEW_COMMENTED; - /** * This class is used to find the reviewers of the buggy lines of code. * @@ -48,10 +48,7 @@ public class ReviewAnalyser { private final Set approvedReviewers = new HashSet<>(); // to store the reviewed and commented users of the pull requests private final Set commentedReviewers = new HashSet<>(); - - //constants for filtering github API responses - private final GithubApiCaller githubApiCaller = new GithubApiCaller(); private final Gson gson = new Gson(); @@ -62,15 +59,15 @@ public class ReviewAnalyser { * @param githubToken Github access token for accessing github API */ public void findReviewers(Set authorCommits, String githubToken) { - authorCommits.forEach(commitHash -> { String jsonText; - try { jsonText = githubApiCaller.callSearchIssueApi(commitHash, githubToken); Map> prNoWithRepoName = savePrNumberAndRepoName(jsonText); - logger.debug("Relevant pull requests on patch " + commitHash + " with their relevant repository " + - "names are successfully saved in a map."); + if (logger.isDebugEnabled()) { + logger.debug("Relevant pull requests on patch " + commitHash + " with their relevant repository " + + "names are successfully saved in a map."); + } saveReviewers(prNoWithRepoName, githubToken); } catch (CodeQualityMatricesException e) { logger.debug(e.getMessage(), e.getCause()); @@ -86,24 +83,21 @@ public void findReviewers(Set authorCommits, String githubToken) { * @throws CodeQualityMatricesException */ private Map> savePrNumberAndRepoName(String jsonText) throws CodeQualityMatricesException { - // map for storing the pull requests numbers against their Repository Map> prNoWithRepoName = new HashMap<>(); try { IssueApiResponse issueApiResponse = gson.fromJson(jsonText, IssueApiResponse.class); - - issueApiResponse.getItems().parallelStream() - .filter(searchItem -> GITHUB_REVIEW_API_CLOSED_STATE.equals(searchItem.getState())) + issueApiResponse.getIssue().parallelStream() + .filter(searchItem -> GITHUB_REVIEW_API_CLOSED_STATE.equals(searchItem.getStateOfThePr())) .filter(searchItem -> StringUtils.contains(searchItem.getRepositoryUrl(), "/wso2/")) .forEach(searchItem -> { String repositoryName = StringUtils.substringAfter(searchItem.getRepositoryUrl(), "repos/"); - int pullRequestNo = searchItem.getNumber(); + int pullRequestNo = searchItem.getPrNumber(); prNoWithRepoName.putIfAbsent(repositoryName, new HashSet<>()); if (!prNoWithRepoName.get(repositoryName).contains(pullRequestNo)) { prNoWithRepoName.get(repositoryName).add(pullRequestNo); } - }); } catch (JsonSyntaxException e) { throw new CodeQualityMatricesException(e.getMessage(), e.getCause()); @@ -121,34 +115,31 @@ private Map> savePrNumberAndRepoName(String jsonText) throw * @param githubToken Github access token for accessing github API */ private void saveReviewers(Map> prNoWithRepoName, String githubToken) { - for (Map.Entry entry : prNoWithRepoName.entrySet()) { String repositoryName = (String) entry.getKey(); Set prNumbers = (Set) entry.getValue(); prNumbers.parallelStream() .forEach(prNumber -> { - try { String jsonText = githubApiCaller.callReviewApi(repositoryName, prNumber, githubToken); if (jsonText != null) { List reviews = gson.fromJson(jsonText, List.class); // to filter Approved users reviews.parallelStream() - .filter(review -> GITHUB_REVIEW_APPROVED.equals(review.getState())) + .filter(review -> GITHUB_REVIEW_APPROVED.equals(review.getReviewState())) .forEach(review -> approvedReviewers.add(review.getReviewer().getName())); - logger.debug("Users who approved the pull requests which introduce bug lines to the " + "code base are successfully saved to approvedReviewers list"); - reviews.parallelStream() - .filter(review -> GITHUB_REVIEW_COMMENTED.equals(review.getState())) + .filter(review -> GITHUB_REVIEW_COMMENTED.equals(review.getReviewState())) .forEach(review -> commentedReviewers.add(review.getReviewer().getName())); - logger.debug("Users who commented on the pull requests which introduce bug lines to " + "the code base are successfully saved to approvedReviewers list"); } else { - logger.debug("There are no records of reviews for pull request: " + prNumber + - " on " + repositoryName + " repository"); + if (logger.isDebugEnabled()) { + logger.debug("There are no records of reviews for pull request: " + prNumber + + " on " + repositoryName + " repository"); + } } } catch (CodeQualityMatricesException e) { logger.error(e.getMessage(), e.getCause()); @@ -161,7 +152,9 @@ private void saveReviewers(Map> prNoWithRepoName, String gi * Print the list of reviewers and commented users on the pull requests which introduce bugs to the code base */ public void printReviewUsers() { - logger.debug("\n Reviewed and approved users of the bug lines: " + approvedReviewers); - logger.debug("\n Reviewed and commented users on bug lines: " + commentedReviewers); + if (logger.isDebugEnabled()) { + logger.debug("\n Reviewed and approved users of the bug lines: " + approvedReviewers); + logger.debug("\n Reviewed and commented users on bug lines: " + commentedReviewers); + } } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java index cb2d01a..ac436dc 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java @@ -45,7 +45,6 @@ public class SdkGitHubClient { private CommitService commitService = null; private RepositoryService repositoryService = null; - SdkGitHubClient(String githubToken) { gitHubClient = new GitHubClient(); gitHubClient.setOAuth2Token(githubToken); @@ -70,16 +69,16 @@ public Map> getFilesChanged(String repositoryName, String c List filesChanged = repositoryCommit.getFiles(); List tempFileNames = new ArrayList<>(); List tempPatchString = new ArrayList<>(); - // this can be run parallely as patchString of a file will always be in the same index as the file filesChanged.parallelStream() .forEach(commitFile -> { tempFileNames.add(commitFile.getFilename()); tempPatchString.add(commitFile.getPatch()); }); - logger.debug("for commit hash" + commitHash + " on the " + repositoryName + " repository, files changed " + - "and their " + - "relevant changed line ranges are added to the arraylists successfully"); + if (logger.isDebugEnabled()) { + logger.debug("for commit hash" + commitHash + " on the " + repositoryName + " repository, files" + + " changed and their relevant changed line ranges are added to the arraylists successfully"); + } fileNamesAndPatches.put("fileNames", tempFileNames); fileNamesAndPatches.put("patchString", tempPatchString); logger.debug("Modified file names with their relevant modified line ranges are saved to a map " + diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java index e92b4b3..bdedd85 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java @@ -28,6 +28,7 @@ public class Constants { public static final String GITHUB_REVIEW_APPROVED = "APPROVED"; public static final String GITHUB_REVIEW_COMMENTED = "COMMENTED"; public static final String GITHUB_REVIEW_API_CLOSED_STATE = "closed"; - - + public static final String AUTHORIZATION = "Authorization"; + public static final String BEARER = "Bearer "; + public static final String ACCEPT = "Accept"; } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java index fc7428e..acc56c8 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java @@ -18,17 +18,20 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphQlResponse { - private GraphqlData data; + @SerializedName("data") + private GraphqlData response; - public GraphqlData getData() { - return data; + public GraphqlData getResponse() { + return response; } - public void setData(GraphqlData data) { - this.data = data; + public void setResponse(GraphqlData response) { + this.response = response; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java index 93b91cc..e7bc9be 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java @@ -30,7 +30,6 @@ public class Graphql implements Serializable { private String graphqlInputWithoutHistory; public Graphql() { - } public String getGraphqlInputWithHistory() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java index fa0be6c..4ed6853 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java @@ -18,12 +18,14 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlAuthor { + @SerializedName("name") private String name; - private String email; public String getName() { return name; @@ -32,12 +34,4 @@ public String getName() { public void setName(String name) { this.name = name; } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java index 3fd4d4d..b5f0237 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java @@ -18,13 +18,15 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + import java.util.List; /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlBlame { - + @SerializedName("ranges") private List ranges; public List getRanges() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java index 19d2097..6086e66 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java @@ -18,12 +18,17 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlCommit { + @SerializedName("author") private GraphqlAuthor author; + @SerializedName("history") private GraphqlHistory history; + @SerializedName("url") private String url; public GraphqlAuthor getAuthor() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java index e7ccbb1..26c38d5 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java @@ -18,10 +18,13 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlData { + @SerializedName("repository") private GraphqlRepository repository; public GraphqlRepository getRepository() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java index 82b858c..edcbfc7 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java @@ -18,17 +18,20 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlEdge { - private GraphqlNode node; + @SerializedName("node") + private GraphqlNode details; - public GraphqlNode getNode() { - return node; + public GraphqlNode getDetails() { + return details; } - public void setNode(GraphqlNode node) { - this.node = node; + public void setDetails(GraphqlNode details) { + this.details = details; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java index e204dd5..a7cfbce 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java @@ -18,19 +18,22 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + import java.util.List; /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlHistory { - private List edges; + @SerializedName("edges") + private List commits; - public List getEdges() { - return edges; + public List getCommits() { + return commits; } - public void setEdges(List edges) { - this.edges = edges; + public void setCommits(List commits) { + this.commits = commits; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java index 8e670b6..4b79eed 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java @@ -18,10 +18,13 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlNode { + @SerializedName("url") private String url; public String getUrl() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java index 197a374..e19b2de 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java @@ -18,10 +18,13 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlObject { + @SerializedName("blame") private GraphqlBlame blame; public GraphqlBlame getBlame() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java index 62c91a1..727c9fa 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java @@ -18,13 +18,19 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlRange { + @SerializedName("startingLine") private int startingLine; + @SerializedName("endingLine") private int endingLine; + @SerializedName("age") private int age; + @SerializedName("commit") private GraphqlCommit commit; public int getStartingLine() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java index 38d1bce..fb2e4ee 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java @@ -18,17 +18,20 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ public class GraphqlRepository { - private GraphqlObject object; + @SerializedName("object") + private GraphqlObject file; - public GraphqlObject getObject() { - return object; + public GraphqlObject getFile() { + return file; } - public void setObject(GraphqlObject object) { - this.object = object; + public void setFile(GraphqlObject file) { + this.file = file; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java index 1ca498e..ad9c981 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java @@ -18,19 +18,22 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + import java.util.List; /** * Pojo class used for parsing JSON response received from github REST API */ public class IssueApiResponse { - private List items; + @SerializedName("items") + private List issue; - public List getItems() { - return items; + public List getIssue() { + return issue; } - public void setItems(List items) { - this.items = items; + public void setIssue(List issue) { + this.issue = issue; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Repository.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Repository.java index 2808873..64bd9e0 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Repository.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Repository.java @@ -18,17 +18,20 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github REST API */ public class Repository { - private String full_name; + @SerializedName("full_name") + private String repositoryLocation; - public String getFull_name() { - return full_name; + public String getRepositoryLocation() { + return repositoryLocation; } - public void setFull_name(String full_name) { - this.full_name = full_name; + public void setRepositoryLocation(String repositoryLocation) { + this.repositoryLocation = repositoryLocation; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/RepositoryItem.java similarity index 89% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/RepositoryItem.java index 8aa1bb5..332ccfe 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlItem.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/RepositoryItem.java @@ -18,11 +18,13 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github graphql API */ -public class GraphqlItem { - +public class RepositoryItem { + @SerializedName("repository") private Repository repository; public Repository getRepository() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java index 6622772..7da25a0 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java @@ -18,26 +18,30 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github REST API */ public class ReviewApiResponse { - private String state; - private Reviewer user; + @SerializedName("state") + private String reviewState; + @SerializedName("user") + private Reviewer reviewer; - public String getState() { - return state; + public String getReviewState() { + return reviewState; } - public void setState(String state) { - this.state = state; + public void setReviewState(String reviewState) { + this.reviewState = reviewState; } public Reviewer getReviewer() { - return user; + return reviewer; } - public void setUser(Reviewer user) { - this.user = user; + public void setReviewer(Reviewer reviewer) { + this.reviewer = reviewer; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java index c31568b..862e4ba 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java @@ -18,17 +18,20 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github REST API */ public class Reviewer { - private String login; + @SerializedName("login") + private String name; public String getName() { - return login; + return name; } public void setReviewer(String login) { - this.login = login; + this.name = login; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java index 7f254e6..503a2de 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java @@ -18,28 +18,22 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + import java.util.List; /** * Pojo class used for parsing JSON response received from github REST API */ public class SearchApiResponse { - private int total_count; - private List items; - - public int getTotal_count() { - return total_count; - } - - public void setTotal_count(int total_count) { - this.total_count = total_count; - } + @SerializedName("items") + private List containingRepositories; - public List getItems() { - return items; + public List getContainingRepositories() { + return containingRepositories; } - public void setItems(List items) { - this.items = items; + public void setContainingRepositories(List containingRepositories) { + this.containingRepositories = containingRepositories; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java index ce31b93..86fa5e5 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java @@ -18,35 +18,40 @@ package com.wso2.code.quality.matrices.model; +import com.google.gson.annotations.SerializedName; + /** * Pojo class used for parsing JSON response received from github REST API */ public class SearchItem { - private String state; - private int number; - private String repository_url; - - public String getState() { - return state; + @SerializedName("state") + private String stateOfThePr; + @SerializedName("number") + private int prNumber; + @SerializedName("repository_url") + private String repositoryUrl; + + public String getStateOfThePr() { + return stateOfThePr; } - public void setState(String state) { - this.state = state; + public void setStateOfThePr(String stateOfThePr) { + this.stateOfThePr = stateOfThePr; } - public int getNumber() { - return number; + public int getPrNumber() { + return prNumber; } - public void setNumber(int number) { - this.number = number; + public void setPrNumber(int prNumber) { + this.prNumber = prNumber; } public String getRepositoryUrl() { - return repository_url; + return repositoryUrl; } - public void setRepositoryUrl(String repository_url) { - this.repository_url = repository_url; + public void setRepositoryUrl(String repositoryUrl) { + this.repositoryUrl = repositoryUrl; } } From 123494b710eab3fb6515eac4e1f82cf310a63fb6 Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 31 Mar 2017 12:36:46 +0530 Subject: [PATCH 52/62] Rename the package --- org.wso2.codequalitymatrices/pom.xml | 37 +++++++++++++------ .../{matrices => metrics}/ApiUtility.java | 29 ++++++++------- .../{matrices => metrics}/Application.java | 8 ++-- .../{matrices => metrics}/ChangesFinder.java | 30 +++++++-------- .../CodeQualityMetricsException.java} | 8 ++-- .../CodeQualityMetricsExecutor.java} | 24 ++++++------ .../GithubApiCaller.java | 34 ++++++++--------- .../{matrices => metrics}/PmtApiCaller.java | 12 +++--- .../{matrices => metrics}/ReviewAnalyser.java | 22 +++++------ .../SdkGitHubClient.java | 6 +-- .../model/Constants.java | 4 +- .../model/GraphQlResponse.java | 6 ++- .../{matrices => metrics}/model/Graphql.java | 2 +- .../model/GraphqlAuthor.java | 6 ++- .../model/GraphqlBlame.java | 6 ++- .../model/GraphqlCommit.java | 6 ++- .../model/GraphqlData.java | 6 ++- .../model/GraphqlEdge.java | 6 ++- .../model/GraphqlHistory.java | 6 ++- .../model/GraphqlNode.java | 6 ++- .../model/GraphqlObject.java | 6 ++- .../model/GraphqlRange.java | 6 ++- .../model/GraphqlRepository.java | 6 ++- .../model/IssueApiResponse.java | 6 ++- .../model/Repository.java | 6 ++- .../model/RepositoryItem.java | 6 ++- .../model/ReviewApiResponse.java | 6 ++- .../{matrices => metrics}/model/Reviewer.java | 6 ++- .../model/SearchApiResponse.java | 6 ++- .../model/SearchItem.java | 6 ++- .../ApplicationTest.java | 2 +- 31 files changed, 189 insertions(+), 137 deletions(-) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/ApiUtility.java (84%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/Application.java (87%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/ChangesFinder.java (95%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices/CodeQualityMatricesException.java => metrics/CodeQualityMetricsException.java} (78%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices/CodeQualityMatricesExecutor.java => metrics/CodeQualityMetricsExecutor.java} (81%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/GithubApiCaller.java (79%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/PmtApiCaller.java (80%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/ReviewAnalyser.java (91%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/SdkGitHubClient.java (94%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/Constants.java (94%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/GraphQlResponse.java (93%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/Graphql.java (97%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/GraphqlAuthor.java (92%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/GraphqlBlame.java (93%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/GraphqlCommit.java (94%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/GraphqlData.java (93%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/GraphqlEdge.java (92%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/GraphqlHistory.java (93%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/GraphqlNode.java (92%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/GraphqlObject.java (92%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/GraphqlRange.java (95%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/GraphqlRepository.java (92%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/IssueApiResponse.java (93%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/Repository.java (93%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/RepositoryItem.java (93%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/ReviewApiResponse.java (94%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/Reviewer.java (93%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/SearchApiResponse.java (94%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/{matrices => metrics}/model/SearchItem.java (95%) rename org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/{matrices => metrics}/ApplicationTest.java (93%) diff --git a/org.wso2.codequalitymatrices/pom.xml b/org.wso2.codequalitymatrices/pom.xml index 6639c58..99da0bd 100644 --- a/org.wso2.codequalitymatrices/pom.xml +++ b/org.wso2.codequalitymatrices/pom.xml @@ -20,64 +20,77 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + org.wso2 wso2 5 - org.wso2.codeQualityMatrices - CodeQualityMatrices + + org.wso2.code-quality-metrics + code-quality-metrics 1.0.0-SNAPSHOT jar - CodeQualityMatrices + code-quality-metrics http://maven.apache.org + - 1.8 + 1.8 UTF-8 + 3.8.1 + 1.2.17 + 20160810 + 2.8.0 + 2.1.5 + 1.1.1 + 4.5.2 + 3.5 + junit junit - 3.8.1 + ${junit.version} test log4j log4j - 1.2.17 + ${log4j.version} org.json json - 20160810 + ${org.json.version} com.google.code.gson gson - 2.8.0 + ${com.google.code.gson.version} org.eclipse.mylyn.github org.eclipse.egit.github.core - 2.1.5 + ${org.eclipse.mylyn.github.version} org.apache.httpcomponents httpclient - 4.5.2 + ${org.apache.httpcomponents.version} com.googlecode.json-simple json-simple - 1.1.1 + ${com.googlecode.json-simple.version} org.apache.commons commons-lang3 - 3.5 + ${org.apache.commons.version} + diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java similarity index 84% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java index 8f999ba..73d0d2c 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ApiUtility.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java @@ -16,7 +16,7 @@ * under the License. */ -package com.wso2.code.quality.matrices; +package com.wso2.code.quality.metrics; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; @@ -30,6 +30,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; /** * This is a utility class for calling APIs. @@ -48,9 +49,9 @@ private ApiUtility() { * * @param httpGet Instance of the relevant httpGet * @return String representation of the json response - * @throws CodeQualityMatricesException + * @throws CodeQualityMetricsException */ - public static String callApi(HttpGet httpGet) throws CodeQualityMatricesException { + public static String callApi(HttpGet httpGet) throws CodeQualityMetricsException { BufferedReader bufferedReader = null; CloseableHttpClient httpClient; CloseableHttpResponse httpResponse = null; @@ -62,7 +63,7 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio if (responseCode == 200) { //success bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), - "UTF-8")); + StandardCharsets.UTF_8)); StringBuilder stringBuilder = new StringBuilder(); String line; while ((line = bufferedReader.readLine()) != null) { @@ -71,13 +72,13 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio // creating a JSON object from the response jsonText = stringBuilder.toString(); } else { - throw new CodeQualityMatricesException("Error occurred while calling the API, the response code is " + + throw new CodeQualityMetricsException("Error occurred while calling the API, the response code is " + responseCode); } } catch (ClientProtocolException e) { - throw new CodeQualityMatricesException("ClientProtocolException when calling the REST API", e); + throw new CodeQualityMetricsException("ClientProtocolException when calling the REST API", e); } catch (IOException e) { - throw new CodeQualityMatricesException("IOException occurred when calling the REST API", e); + throw new CodeQualityMetricsException("IOException occurred when calling the REST API", e); } finally { if (bufferedReader != null) { try { @@ -109,9 +110,9 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMatricesExceptio * * @param httpPost relevant instance of the httpost * @return String representation of the json response - * @throws CodeQualityMatricesException + * @throws CodeQualityMetricsException */ - public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatricesException { + public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMetricsException { BufferedReader bufferedReader = null; CloseableHttpClient httpClient; CloseableHttpResponse httpResponse = null; @@ -122,7 +123,7 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatrice int responseCode = httpResponse.getStatusLine().getStatusCode(); if (responseCode == 200) { bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), - "UTF-8")); + StandardCharsets.UTF_8)); String line; StringBuilder stringBuilder = new StringBuilder(); while ((line = bufferedReader.readLine()) != null) { @@ -131,16 +132,16 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMatrice jsonText = stringBuilder.toString(); logger.debug("The response received from the Github GraphQL converted to a JSON text successfully"); } else { - throw new CodeQualityMatricesException("Error occurred while calling the API, the response code is " + + throw new CodeQualityMetricsException("Error occurred while calling the API, the response code is " + responseCode); } } catch (UnsupportedEncodingException e) { - throw new CodeQualityMatricesException("Encoding error occured before calling the github graphQL API", e); + throw new CodeQualityMetricsException("Encoding error occured before calling the github graphQL API", e); } catch (ClientProtocolException e) { - throw new CodeQualityMatricesException("Client protocol exception occurred when calling the github" + + throw new CodeQualityMetricsException("Client protocol exception occurred when calling the github" + " graphQL API", e); } catch (IOException e) { - throw new CodeQualityMatricesException("A problem or the connection was aborted while executing the" + + throw new CodeQualityMetricsException("A problem or the connection was aborted while executing the" + " httpPost", e); } finally { if (bufferedReader != null) { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java similarity index 87% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java index 5109bbc..277ee05 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/Application.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java @@ -16,7 +16,7 @@ * under the License. */ -package com.wso2.code.quality.matrices; +package com.wso2.code.quality.metrics; import org.apache.log4j.Logger; @@ -24,6 +24,8 @@ * This is having the main method of this application * PMT Access token, patch id and github access token * should be passed in order as command line arguments when running the application. + * + * @since 1.0.0 */ public class Application { private static final Logger logger = Logger.getLogger(Application.class); @@ -33,9 +35,9 @@ public static void main(String[] args) { String pmtToken = args[0]; String patchId = args[1]; String gitHubToken = args[2]; - CodeQualityMatricesExecutor codeQualityMatricesExecutor = new CodeQualityMatricesExecutor(pmtToken, patchId, + CodeQualityMetricsExecutor codeQualityMetricsExecutor = new CodeQualityMetricsExecutor(pmtToken, patchId, gitHubToken); - codeQualityMatricesExecutor.execute(); + codeQualityMetricsExecutor.execute(); } else { logger.debug("Command line arguments were not given correctly to start the execution"); logger.debug("Please enter PMT Access token, patch id and github access token in order as command " + diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java similarity index 95% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java index c02629c..bc59d4e 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ChangesFinder.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java @@ -16,13 +16,13 @@ * under the License. */ -package com.wso2.code.quality.matrices; +package com.wso2.code.quality.metrics; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; -import com.wso2.code.quality.matrices.model.GraphQlResponse; -import com.wso2.code.quality.matrices.model.Graphql; -import com.wso2.code.quality.matrices.model.SearchApiResponse; +import com.wso2.code.quality.metrics.model.GraphQlResponse; +import com.wso2.code.quality.metrics.model.Graphql; +import com.wso2.code.quality.metrics.model.SearchApiResponse; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.json.JSONObject; @@ -72,7 +72,7 @@ public Set obtainRepoNamesForCommitHashes(String gitHubToken, List obtainRepoNamesForCommitHashes(String gitHubToken, List repoLocation = new ArrayList<>(); SearchApiResponse searchCommitPojo; try { searchCommitPojo = gson.fromJson(jsonText, SearchApiResponse.class); } catch (JsonSyntaxException e) { - throw new CodeQualityMatricesException(e.getMessage(), e.getCause()); + throw new CodeQualityMetricsException(e.getMessage(), e.getCause()); } searchCommitPojo.getContainingRepositories() .forEach(recordItem -> repoLocation.add(recordItem.getRepository().getRepositoryLocation())); @@ -111,7 +111,7 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke Map> fileNamesWithPatcheString = null; try { fileNamesWithPatcheString = sdkGitHubClient.getFilesChanged(repositoryName, commitHash); - } catch (CodeQualityMatricesException e) { + } catch (CodeQualityMetricsException e) { logger.debug(e.getMessage(), e.getCause()); } if (fileNamesWithPatcheString != null) { @@ -121,7 +121,7 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke saveRelaventEditLineNumbers(fileNames, patchString); try { findFileChanges(repositoryName, commitHash, gitHubToken); - } catch (CodeQualityMatricesException e) { + } catch (CodeQualityMetricsException e) { logger.debug(e.getMessage(), e.getCause()); } }); @@ -199,7 +199,7 @@ private void saveRelaventEditLineNumbers(List fileNames, List pa * @param gitHubToken github token for accessing github GraphQL API */ private void findFileChanges(String repoLocation, String commitHash, String gitHubToken) - throws CodeQualityMatricesException { + throws CodeQualityMetricsException { // filtering the owner and the Repository name from the repoLocation String owner = StringUtils.substringBefore(repoLocation, "/"); @@ -220,7 +220,7 @@ private void findFileChanges(String repoLocation, String commitHash, String gitH try { // calling the graphql API for getting blame information for the current file. jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); - } catch (CodeQualityMatricesException e) { + } catch (CodeQualityMetricsException e) { logger.debug(e.getMessage(), e.getCause()); } //reading the above saved output for the current selected file name @@ -229,7 +229,7 @@ private void findFileChanges(String repoLocation, String commitHash, String gitH if (logger.isDebugEnabled()) { logger.debug("Parent commits are saved for the " + fileName + " for all the modified line ranges"); } - } catch (CodeQualityMatricesException e) { + } catch (CodeQualityMetricsException e) { logger.debug(e.getMessage(), e.getCause()); } findAuthorCommits(owner, repositoryName, fileName, lineRangesForSelectedFile, gitHubToken); @@ -246,13 +246,13 @@ private void findFileChanges(String repoLocation, String commitHash, String gitH * @param changedRangesOfSelectedFile arraylist containing the changed line ranges of the current selected file */ private void readBlameForSelectedFile(String jsonText, List changedRangesOfSelectedFile) - throws CodeQualityMatricesException { + throws CodeQualityMetricsException { GraphQlResponse graphQlResponse; try { graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); } catch (JsonSyntaxException e) { - throw new CodeQualityMatricesException(e.getMessage(), e.getCause()); + throw new CodeQualityMetricsException(e.getMessage(), e.getCause()); } GraphQlResponse finalGraphQlResponse = graphQlResponse; // to make a effective final variable changedRangesOfSelectedFile.forEach(lineRange -> { @@ -321,7 +321,7 @@ private void findAuthorCommits(String owner, String repositoryName, String fileN String jsonText = null; try { jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); - } catch (CodeQualityMatricesException e) { + } catch (CodeQualityMetricsException e) { logger.debug(e.getMessage(), e.getCause()); } saveAuthorCommits(jsonText, oldRange, lineRangesForSelectedFile); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsException.java similarity index 78% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsException.java index 7c0b71c..adb2c38 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesException.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsException.java @@ -16,19 +16,19 @@ * under the License. */ -package com.wso2.code.quality.matrices; +package com.wso2.code.quality.metrics; /** * The exception class for all Code Quality Matrices project related exceptions. * * @since 1.0.0 */ -public class CodeQualityMatricesException extends Exception { - public CodeQualityMatricesException(String message) { +public class CodeQualityMetricsException extends Exception { + public CodeQualityMetricsException(String message) { super(message); } - public CodeQualityMatricesException(String message, Throwable cause) { + public CodeQualityMetricsException(String message, Throwable cause) { super(message, cause); } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java similarity index 81% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java index 704b356..4b6f917 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/CodeQualityMatricesExecutor.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java @@ -16,7 +16,7 @@ * under the License. */ -package com.wso2.code.quality.matrices; +package com.wso2.code.quality.metrics; import com.google.gson.Gson; import org.apache.log4j.Logger; @@ -26,28 +26,28 @@ import java.util.Map; import java.util.Set; -import static com.wso2.code.quality.matrices.model.Constants.COMMITS_INSIDE_GIVEN_PATCH; +import static com.wso2.code.quality.metrics.model.Constants.COMMITS_INSIDE_GIVEN_PATCH; /** * This is used for creating executing the program. * * @since 1.0.0 */ -public class CodeQualityMatricesExecutor { - private static final Logger logger = Logger.getLogger(CodeQualityMatricesExecutor.class); +public class CodeQualityMetricsExecutor { + private static final Logger logger = Logger.getLogger(CodeQualityMetricsExecutor.class); private final String pmtToken; private final String patchId; private final String gitHubToken; /** - * This create an instance of CodeQualityMatricesExecutor class. + * This create an instance of CodeQualityMetricsExecutor class. * * @param pmtToken PMT Access Token * @param patchId Patch ID * @param gitHubToken Github access token */ - public CodeQualityMatricesExecutor(String pmtToken, String patchId, String gitHubToken) { + public CodeQualityMetricsExecutor(String pmtToken, String patchId, String gitHubToken) { this.pmtToken = pmtToken; this.patchId = patchId; this.gitHubToken = gitHubToken; @@ -65,7 +65,7 @@ public void execute() { reviewAnalyser.findReviewers(authorCommits, gitHubToken); reviewAnalyser.printReviewUsers(); logger.debug("The application executed successfully"); - } catch (CodeQualityMatricesException e) { + } catch (CodeQualityMetricsException e) { logger.debug(e.getMessage(), e.getCause()); } } @@ -75,17 +75,17 @@ public void execute() { * * @return List of commithashes contained in the given patch */ - private List findCommitHashesInPatch() throws CodeQualityMatricesException { + private List findCommitHashesInPatch() throws CodeQualityMetricsException { PmtApiCaller pmtApiCaller = new PmtApiCaller(); String jsonText; List commitHashes = new ArrayList<>(); try { jsonText = pmtApiCaller.callApi(pmtToken, patchId); - } catch (CodeQualityMatricesException e) { - throw new CodeQualityMatricesException("Error occurred while calling PMT API", e); + } catch (CodeQualityMetricsException e) { + throw new CodeQualityMetricsException("Error occurred while calling PMT API", e); } - Gson gson = new Gson(); if (jsonText != null) { + Gson gson = new Gson(); List pmtResponse = gson.fromJson(jsonText, List.class); for (Object pmtEntry : pmtResponse) { if (pmtEntry instanceof Map) { @@ -99,7 +99,7 @@ private List findCommitHashesInPatch() throws CodeQualityMatricesExcepti logger.debug("The commit hashes are: " + commitHashes); } } else { - throw new CodeQualityMatricesException("The returned jsonText from PMT API is null"); + throw new CodeQualityMetricsException("The returned jsonText from PMT API is null"); } return commitHashes; } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java similarity index 79% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java index 2c5cba6..d5f6eb9 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/GithubApiCaller.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java @@ -16,7 +16,7 @@ * under the License. */ -package com.wso2.code.quality.matrices; +package com.wso2.code.quality.metrics; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; @@ -25,9 +25,9 @@ import java.io.UnsupportedEncodingException; -import static com.wso2.code.quality.matrices.model.Constants.ACCEPT; -import static com.wso2.code.quality.matrices.model.Constants.AUTHORIZATION; -import static com.wso2.code.quality.matrices.model.Constants.BEARER; +import static com.wso2.code.quality.metrics.model.Constants.ACCEPT; +import static com.wso2.code.quality.metrics.model.Constants.AUTHORIZATION; +import static com.wso2.code.quality.metrics.model.Constants.BEARER; /** * This is used for all github communications. @@ -43,9 +43,9 @@ public class GithubApiCaller { * @param commitHash commit hash to be searched * @param githubAccessToken Github access token for accessing github API * @return String representation of the json response - * @throws CodeQualityMatricesException + * @throws CodeQualityMetricsException */ - public String callSearchCommitApi(String commitHash, String githubAccessToken) throws CodeQualityMatricesException { + public String callSearchCommitApi(String commitHash, String githubAccessToken) throws CodeQualityMetricsException { String url = "https://api.github.com/search/commits?q=hash%3A" + commitHash; try { httpGet = new HttpGet(url); @@ -53,7 +53,7 @@ public String callSearchCommitApi(String commitHash, String githubAccessToken) t //as the accept header is needed for accessing commit search API which is still in preview mode httpGet.addHeader(ACCEPT, "application/vnd.github.cloak-preview"); } catch (IllegalArgumentException e) { - throw new CodeQualityMatricesException("The url provided for accessing the Github Search Commit API is " + + throw new CodeQualityMetricsException("The url provided for accessing the Github Search Commit API is " + "invalid ", e); } return ApiUtility.callApi(httpGet); @@ -66,17 +66,17 @@ public String callSearchCommitApi(String commitHash, String githubAccessToken) t * @param pullRequestNumber pull request number to be queried for * @param githubAccessToken Github access token for accessing github API * @return String representation of the json response - * @throws CodeQualityMatricesException + * @throws CodeQualityMetricsException */ public String callReviewApi(String repoLocation, int pullRequestNumber, String githubAccessToken) throws - CodeQualityMatricesException { + CodeQualityMetricsException { String url = "https://api.github.com/repos/" + repoLocation + "/pulls/" + pullRequestNumber + "/reviews"; try { httpGet = new HttpGet(url); httpGet.addHeader(ACCEPT, "application/vnd.github.black-cat-preview+json"); httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); } catch (IllegalArgumentException e) { - throw new CodeQualityMatricesException("The url provided for accessing the Github Review Commit API is " + + throw new CodeQualityMetricsException("The url provided for accessing the Github Review Commit API is " + "invalid ", e); } return ApiUtility.callApi(httpGet); @@ -88,17 +88,17 @@ public String callReviewApi(String repoLocation, int pullRequestNumber, String g * @param commitHashToBeSearched commit hash to be searched for issues * @param githubAccessToken Github access token for accessing github API * @return String representation of the json response - * @throws CodeQualityMatricesException + * @throws CodeQualityMetricsException */ public String callSearchIssueApi(String commitHashToBeSearched, String githubAccessToken) throws - CodeQualityMatricesException { + CodeQualityMetricsException { String url = "https://api.github.com/search/issues?q=" + commitHashToBeSearched; try { httpGet = new HttpGet(url); httpGet.addHeader(ACCEPT, "application/vnd.github.mercy-preview+json"); httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); } catch (IllegalArgumentException e) { - throw new CodeQualityMatricesException("The url provided for accessing the Github Search Issue API is " + + throw new CodeQualityMetricsException("The url provided for accessing the Github Search Issue API is " + "invalid ", e); } return ApiUtility.callApi(httpGet); @@ -110,10 +110,10 @@ public String callSearchIssueApi(String commitHashToBeSearched, String githubAcc * @param graphqlJsonStructure JSON input structure for calling the graphql API * @param githubToken Github access token for accessing github API * @return String representation of the json response - * @throws CodeQualityMatricesException + * @throws CodeQualityMetricsException */ public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken) throws - CodeQualityMatricesException { + CodeQualityMetricsException { String url = "https://api.github.com/graphql"; HttpPost httpPost; try { @@ -123,10 +123,10 @@ public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken StringEntity entity = new StringEntity(graphqlJsonStructure.toString()); httpPost.setEntity(entity); } catch (IllegalArgumentException e) { - throw new CodeQualityMatricesException("The url provided for accessing the Github Graphql API is " + + throw new CodeQualityMetricsException("The url provided for accessing the Github Graphql API is " + "invalid", e); } catch (UnsupportedEncodingException e) { - throw new CodeQualityMatricesException("An error occurred when creating the String entity from Json " + + throw new CodeQualityMetricsException("An error occurred when creating the String entity from Json " + "Structure", e); } return ApiUtility.callGraphQlApi(httpPost); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java similarity index 80% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java index 799af57..fb37efe 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/PmtApiCaller.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java @@ -16,12 +16,12 @@ * under the License. */ -package com.wso2.code.quality.matrices; +package com.wso2.code.quality.metrics; import org.apache.http.client.methods.HttpGet; -import static com.wso2.code.quality.matrices.model.Constants.AUTHORIZATION; -import static com.wso2.code.quality.matrices.model.Constants.BEARER; +import static com.wso2.code.quality.metrics.model.Constants.AUTHORIZATION; +import static com.wso2.code.quality.metrics.model.Constants.BEARER; /** * This is used for all the WSO2 PMT communications. @@ -38,9 +38,9 @@ public PmtApiCaller() { * @param accessToken WSO2 PMT access token * @param patchId Patch Id * @return String representation of the json response - * @throws CodeQualityMatricesException + * @throws CodeQualityMetricsException */ - public String callApi(String accessToken, String patchId) throws CodeQualityMatricesException { + public String callApi(String accessToken, String patchId) throws CodeQualityMetricsException { String pmtUrl = "http://umt.private.wso2.com:9765/codequalitymatricesapi/1.0.0//properties?path=/_system/" + "governance/patchs/" + patchId; HttpGet httpGet; @@ -48,7 +48,7 @@ public String callApi(String accessToken, String patchId) throws CodeQualityMatr httpGet = new HttpGet(pmtUrl); httpGet.addHeader(AUTHORIZATION, BEARER + accessToken); } catch (IllegalArgumentException e) { - throw new CodeQualityMatricesException("The url provided for accessing the PMT API is invalid ", e); + throw new CodeQualityMetricsException("The url provided for accessing the PMT API is invalid ", e); } return ApiUtility.callApi(httpGet); } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java similarity index 91% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java index a07d1c8..1e9c1ba 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/ReviewAnalyser.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java @@ -16,12 +16,12 @@ * under the License. */ -package com.wso2.code.quality.matrices; +package com.wso2.code.quality.metrics; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; -import com.wso2.code.quality.matrices.model.IssueApiResponse; -import com.wso2.code.quality.matrices.model.ReviewApiResponse; +import com.wso2.code.quality.metrics.model.IssueApiResponse; +import com.wso2.code.quality.metrics.model.ReviewApiResponse; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; @@ -31,9 +31,9 @@ import java.util.Map; import java.util.Set; -import static com.wso2.code.quality.matrices.model.Constants.GITHUB_REVIEW_API_CLOSED_STATE; -import static com.wso2.code.quality.matrices.model.Constants.GITHUB_REVIEW_APPROVED; -import static com.wso2.code.quality.matrices.model.Constants.GITHUB_REVIEW_COMMENTED; +import static com.wso2.code.quality.metrics.model.Constants.GITHUB_REVIEW_API_CLOSED_STATE; +import static com.wso2.code.quality.metrics.model.Constants.GITHUB_REVIEW_APPROVED; +import static com.wso2.code.quality.metrics.model.Constants.GITHUB_REVIEW_COMMENTED; /** * This class is used to find the reviewers of the buggy lines of code. @@ -69,7 +69,7 @@ public void findReviewers(Set authorCommits, String githubToken) { "names are successfully saved in a map."); } saveReviewers(prNoWithRepoName, githubToken); - } catch (CodeQualityMatricesException e) { + } catch (CodeQualityMetricsException e) { logger.debug(e.getMessage(), e.getCause()); } }); @@ -80,9 +80,9 @@ public void findReviewers(Set authorCommits, String githubToken) { * * @param jsonText json reponse received from the github issue API * @return a map of pull requests againt their repository name - * @throws CodeQualityMatricesException + * @throws CodeQualityMetricsException */ - private Map> savePrNumberAndRepoName(String jsonText) throws CodeQualityMatricesException { + private Map> savePrNumberAndRepoName(String jsonText) throws CodeQualityMetricsException { // map for storing the pull requests numbers against their Repository Map> prNoWithRepoName = new HashMap<>(); try { @@ -101,7 +101,7 @@ private Map> savePrNumberAndRepoName(String jsonText) throw } }); } catch (JsonSyntaxException e) { - throw new CodeQualityMatricesException(e.getMessage(), e.getCause()); + throw new CodeQualityMetricsException(e.getMessage(), e.getCause()); } return prNoWithRepoName; } @@ -142,7 +142,7 @@ private void saveReviewers(Map> prNoWithRepoName, String gi " on " + repositoryName + " repository"); } } - } catch (CodeQualityMatricesException e) { + } catch (CodeQualityMetricsException e) { logger.error(e.getMessage(), e.getCause()); } }); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java similarity index 94% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java index ac436dc..4935f74 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/SdkGitHubClient.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java @@ -16,7 +16,7 @@ * under the License. */ -package com.wso2.code.quality.matrices; +package com.wso2.code.quality.metrics; import org.apache.log4j.Logger; import org.eclipse.egit.github.core.CommitFile; @@ -61,7 +61,7 @@ public class SdkGitHubClient { * @return a map containg arraylist of file changed and their relevant patch */ public Map> getFilesChanged(String repositoryName, String commitHash) - throws CodeQualityMatricesException { + throws CodeQualityMetricsException { Map> fileNamesAndPatches = new HashMap<>(); try { IRepositoryIdProvider iRepositoryIdProvider = () -> repositoryName; @@ -84,7 +84,7 @@ public Map> getFilesChanged(String repositoryName, String c logger.debug("Modified file names with their relevant modified line ranges are saved to a map " + "successfully"); } catch (IOException e) { - throw new CodeQualityMatricesException("IO Exception occurred when getting the commit of given SHA from " + + throw new CodeQualityMetricsException("IO Exception occurred when getting the commit of given SHA from " + "the given Repository ", e); } return fileNamesAndPatches; diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Constants.java similarity index 94% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Constants.java index bdedd85..ae42e81 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Constants.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Constants.java @@ -16,10 +16,10 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; /** - * This is used for storing all the constants used in the Code quality matrices Application + * This is used for storing all the constants used in the Code quality metrics Application * * @since 1.0.0 */ diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphQlResponse.java similarity index 93% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphQlResponse.java index acc56c8..2c2f08f 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphQlResponse.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphQlResponse.java @@ -16,12 +16,14 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; /** - * Pojo class used for parsing JSON response received from github graphql API + * Pojo class used for parsing JSON response received from github graphql API. + * + * @since 1.0.0 */ public class GraphQlResponse { @SerializedName("data") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Graphql.java similarity index 97% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Graphql.java index e7bc9be..06662ca 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Graphql.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Graphql.java @@ -16,7 +16,7 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import java.io.Serializable; diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlAuthor.java similarity index 92% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlAuthor.java index 4ed6853..dd4605d 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlAuthor.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlAuthor.java @@ -16,12 +16,14 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; /** - * Pojo class used for parsing JSON response received from github graphql API + * Pojo class used for parsing JSON response received from github graphql API. + * + * @since 1.0.0 */ public class GraphqlAuthor { @SerializedName("name") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlBlame.java similarity index 93% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlBlame.java index b5f0237..55bf9d3 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlBlame.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlBlame.java @@ -16,14 +16,16 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; import java.util.List; /** - * Pojo class used for parsing JSON response received from github graphql API + * Pojo class used for parsing JSON response received from github graphql API. + * + * @since 1.0.0 */ public class GraphqlBlame { @SerializedName("ranges") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlCommit.java similarity index 94% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlCommit.java index 6086e66..8cce2f4 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlCommit.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlCommit.java @@ -16,12 +16,14 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; /** - * Pojo class used for parsing JSON response received from github graphql API + * Pojo class used for parsing JSON response received from github graphql API. + * + * @since 1.0.0 */ public class GraphqlCommit { @SerializedName("author") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlData.java similarity index 93% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlData.java index 26c38d5..cf4a8d1 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlData.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlData.java @@ -16,12 +16,14 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; /** - * Pojo class used for parsing JSON response received from github graphql API + * Pojo class used for parsing JSON response received from github graphql API. + * + * @since 1.0.0 */ public class GraphqlData { @SerializedName("repository") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlEdge.java similarity index 92% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlEdge.java index edcbfc7..ab4e7e6 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlEdge.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlEdge.java @@ -16,12 +16,14 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; /** - * Pojo class used for parsing JSON response received from github graphql API + * Pojo class used for parsing JSON response received from github graphql API. + * + * @since 1.0.0 */ public class GraphqlEdge { @SerializedName("node") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlHistory.java similarity index 93% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlHistory.java index a7cfbce..0d89115 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlHistory.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlHistory.java @@ -16,14 +16,16 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; import java.util.List; /** - * Pojo class used for parsing JSON response received from github graphql API + * Pojo class used for parsing JSON response received from github graphql API. + * + * @since 1.0.0 */ public class GraphqlHistory { @SerializedName("edges") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlNode.java similarity index 92% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlNode.java index 4b79eed..04c23bd 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlNode.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlNode.java @@ -16,12 +16,14 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; /** - * Pojo class used for parsing JSON response received from github graphql API + * Pojo class used for parsing JSON response received from github graphql API. + * + * @since 1.0.0 */ public class GraphqlNode { @SerializedName("url") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlObject.java similarity index 92% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlObject.java index e19b2de..edc9bea 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlObject.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlObject.java @@ -16,12 +16,14 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; /** - * Pojo class used for parsing JSON response received from github graphql API + * Pojo class used for parsing JSON response received from github graphql API. + * + * @since 1.0.0 */ public class GraphqlObject { @SerializedName("blame") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlRange.java similarity index 95% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlRange.java index 727c9fa..2e4f407 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRange.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlRange.java @@ -16,12 +16,14 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; /** - * Pojo class used for parsing JSON response received from github graphql API + * Pojo class used for parsing JSON response received from github graphql API. + * + * @since 1.0.0 */ public class GraphqlRange { @SerializedName("startingLine") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlRepository.java similarity index 92% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlRepository.java index fb2e4ee..f57e421 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/GraphqlRepository.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlRepository.java @@ -16,12 +16,14 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; /** - * Pojo class used for parsing JSON response received from github graphql API + * Pojo class used for parsing JSON response received from github graphql API. + * + * @since 1.0.0 */ public class GraphqlRepository { @SerializedName("object") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/IssueApiResponse.java similarity index 93% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/IssueApiResponse.java index ad9c981..57f1964 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/IssueApiResponse.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/IssueApiResponse.java @@ -16,14 +16,16 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; import java.util.List; /** - * Pojo class used for parsing JSON response received from github REST API + * Pojo class used for parsing JSON response received from github REST API. + * + * @since 1.0.0 */ public class IssueApiResponse { @SerializedName("items") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Repository.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Repository.java similarity index 93% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Repository.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Repository.java index 64bd9e0..3e9be7f 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Repository.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Repository.java @@ -16,12 +16,14 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; /** - * Pojo class used for parsing JSON response received from github REST API + * Pojo class used for parsing JSON response received from github REST API. + * + * @since 1.0.0 */ public class Repository { @SerializedName("full_name") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/RepositoryItem.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/RepositoryItem.java similarity index 93% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/RepositoryItem.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/RepositoryItem.java index 332ccfe..9bbc8b1 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/RepositoryItem.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/RepositoryItem.java @@ -16,12 +16,14 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; /** - * Pojo class used for parsing JSON response received from github graphql API + * Pojo class used for parsing JSON response received from github graphql API. + * + * @since 1.0.0 */ public class RepositoryItem { @SerializedName("repository") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ReviewApiResponse.java similarity index 94% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ReviewApiResponse.java index 7da25a0..b160dfe 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/ReviewApiResponse.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ReviewApiResponse.java @@ -16,12 +16,14 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; /** - * Pojo class used for parsing JSON response received from github REST API + * Pojo class used for parsing JSON response received from github REST API. + * + * @since 1.0.0 */ public class ReviewApiResponse { @SerializedName("state") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Reviewer.java similarity index 93% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Reviewer.java index 862e4ba..905ebab 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/Reviewer.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Reviewer.java @@ -16,12 +16,14 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; /** - * Pojo class used for parsing JSON response received from github REST API + * Pojo class used for parsing JSON response received from github REST API. + * + * @since 1.0.0 */ public class Reviewer { @SerializedName("login") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SearchApiResponse.java similarity index 94% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SearchApiResponse.java index 503a2de..616cf49 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchApiResponse.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SearchApiResponse.java @@ -16,14 +16,16 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; import java.util.List; /** - * Pojo class used for parsing JSON response received from github REST API + * Pojo class used for parsing JSON response received from github REST API. + * + * @since 1.0.0 */ public class SearchApiResponse { @SerializedName("items") diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SearchItem.java similarity index 95% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SearchItem.java index 86fa5e5..7a96779 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/matrices/model/SearchItem.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SearchItem.java @@ -16,12 +16,14 @@ * under the License. */ -package com.wso2.code.quality.matrices.model; +package com.wso2.code.quality.metrics.model; import com.google.gson.annotations.SerializedName; /** - * Pojo class used for parsing JSON response received from github REST API + * Pojo class used for parsing JSON response received from github REST API. + * + * @since 1.0.0 */ public class SearchItem { @SerializedName("state") diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/matrices/ApplicationTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ApplicationTest.java similarity index 93% rename from org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/matrices/ApplicationTest.java rename to org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ApplicationTest.java index 76ad9af..cfd762c 100644 --- a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/matrices/ApplicationTest.java +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ApplicationTest.java @@ -1,4 +1,4 @@ -package com.wso2.code.quality.matrices; +package com.wso2.code.quality.metrics; import junit.framework.Test; import junit.framework.TestCase; From 25560d7af51164a7305b93adba2cccde2e4be2c4 Mon Sep 17 00:00:00 2001 From: kasun Date: Mon, 3 Apr 2017 11:39:09 +0530 Subject: [PATCH 53/62] Use a Configuration file --- .../wso2/code/quality/metrics/ApiUtility.java | 16 +++--- .../code/quality/metrics/Application.java | 2 +- .../code/quality/metrics/ChangesFinder.java | 30 +++++------- .../metrics/CodeQualityMetricsExecutor.java | 4 +- .../code/quality/metrics/GithubApiCaller.java | 49 ++++++++++++++----- .../code/quality/metrics/PmtApiCaller.java | 19 +++++-- .../code/quality/metrics/ReviewAnalyser.java | 10 ++-- .../src/main/resources/url.properties | 26 ++++++++++ 8 files changed, 106 insertions(+), 50 deletions(-) create mode 100644 org.wso2.codequalitymatrices/src/main/resources/url.properties diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java index 73d0d2c..5eb9057 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java @@ -49,7 +49,7 @@ private ApiUtility() { * * @param httpGet Instance of the relevant httpGet * @return String representation of the json response - * @throws CodeQualityMetricsException + * @throws CodeQualityMetricsException results */ public static String callApi(HttpGet httpGet) throws CodeQualityMetricsException { BufferedReader bufferedReader = null; @@ -84,21 +84,21 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMetricsException try { bufferedReader.close(); } catch (IOException e) { - logger.debug("IOException occurred when closing the BufferedReader", e); + logger.error("IOException occurred when closing the BufferedReader", e); } } if (httpResponse != null) { try { httpResponse.close(); } catch (IOException e) { - logger.debug("IOException occurred when closing the HttpResponse", e); + logger.error("IOException occurred when closing the HttpResponse", e); } } if (httpClient != null) { try { httpClient.close(); } catch (IOException e) { - logger.debug("IOException occurred when closing the HttpClient", e); + logger.error("IOException occurred when closing the HttpClient", e); } } } @@ -110,7 +110,7 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMetricsException * * @param httpPost relevant instance of the httpost * @return String representation of the json response - * @throws CodeQualityMetricsException + * @throws CodeQualityMetricsException results */ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMetricsException { BufferedReader bufferedReader = null; @@ -148,21 +148,21 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMetrics try { bufferedReader.close(); } catch (IOException e) { - logger.debug("IOException occurred when closing the buffered reader", e); + logger.error("IOException occurred when closing the buffered reader", e); } } if (httpResponse != null) { try { httpResponse.close(); } catch (IOException e) { - logger.debug("IOException occurred when closing the HttpResponse", e); + logger.error("IOException occurred when closing the HttpResponse", e); } } if (httpClient != null) { try { httpClient.close(); } catch (IOException e) { - logger.debug("IOException occurred when closing the HttpClient", e); + logger.error("IOException occurred when closing the HttpClient", e); } } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java index 277ee05..e8e3978 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java @@ -39,7 +39,7 @@ public static void main(String[] args) { gitHubToken); codeQualityMetricsExecutor.execute(); } else { - logger.debug("Command line arguments were not given correctly to start the execution"); + logger.error("Command line arguments were not given correctly to start the execution"); logger.debug("Please enter PMT Access token, patch id and github access token in order as command " + "line arguments to initiate the program"); } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java index bc59d4e..56558fc 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java @@ -67,13 +67,12 @@ public class ChangesFinder { */ public Set obtainRepoNamesForCommitHashes(String gitHubToken, List commitHashes) { - commitHashes.forEach(commitHash -> { try { String jsonText = githubApiCaller.callSearchCommitApi(commitHash, gitHubToken); saveRepoNames(jsonText, commitHash, gitHubToken); } catch (CodeQualityMetricsException e) { - logger.debug(e.getMessage(), e.getCause()); + logger.error(e.getMessage(), e.getCause()); } }); return authorCommits; @@ -112,18 +111,15 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke try { fileNamesWithPatcheString = sdkGitHubClient.getFilesChanged(repositoryName, commitHash); } catch (CodeQualityMetricsException e) { - logger.debug(e.getMessage(), e.getCause()); + logger.error(e.getMessage(), e.getCause()); } if (fileNamesWithPatcheString != null) { fileNames = fileNamesWithPatcheString.get("fileNames"); patchString = fileNamesWithPatcheString.get("patchString"); } saveRelaventEditLineNumbers(fileNames, patchString); - try { - findFileChanges(repositoryName, commitHash, gitHubToken); - } catch (CodeQualityMetricsException e) { - logger.debug(e.getMessage(), e.getCause()); - } + findFileChanges(repositoryName, commitHash, gitHubToken); + }); if (logger.isDebugEnabled()) { logger.debug("\n Author names :" + authorNames); @@ -198,9 +194,7 @@ private void saveRelaventEditLineNumbers(List fileNames, List pa * @param commitHash current selected Repository * @param gitHubToken github token for accessing github GraphQL API */ - private void findFileChanges(String repoLocation, String commitHash, String gitHubToken) - throws CodeQualityMetricsException { - + private void findFileChanges(String repoLocation, String commitHash, String gitHubToken) { // filtering the owner and the Repository name from the repoLocation String owner = StringUtils.substringBefore(repoLocation, "/"); String repositoryName = StringUtils.substringAfter(repoLocation, "/"); @@ -221,7 +215,7 @@ private void findFileChanges(String repoLocation, String commitHash, String gitH // calling the graphql API for getting blame information for the current file. jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); } catch (CodeQualityMetricsException e) { - logger.debug(e.getMessage(), e.getCause()); + logger.error(e.getMessage(), e.getCause()); } //reading the above saved output for the current selected file name try { @@ -230,7 +224,7 @@ private void findFileChanges(String repoLocation, String commitHash, String gitH logger.debug("Parent commits are saved for the " + fileName + " for all the modified line ranges"); } } catch (CodeQualityMetricsException e) { - logger.debug(e.getMessage(), e.getCause()); + logger.error(e.getMessage(), e.getCause()); } findAuthorCommits(owner, repositoryName, fileName, lineRangesForSelectedFile, gitHubToken); logger.debug("Authors and author commits of bug lines of code which are being fixed from the given " + @@ -247,7 +241,6 @@ private void findFileChanges(String repoLocation, String commitHash, String gitH */ private void readBlameForSelectedFile(String jsonText, List changedRangesOfSelectedFile) throws CodeQualityMetricsException { - GraphQlResponse graphQlResponse; try { graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); @@ -310,9 +303,9 @@ private void readBlameForSelectedFile(String jsonText, List changedRange */ private void findAuthorCommits(String owner, String repositoryName, String fileName, List lineRangesForSelectedFile, String gitHubToken) { - for (Map.Entry entry : parentCommitHashes.entrySet()) { - String oldRange = (String) entry.getKey(); - Set commitHashes = (Set) entry.getValue(); + for (Map.Entry> entry : parentCommitHashes.entrySet()) { + String oldRange = entry.getKey(); + Set commitHashes = entry.getValue(); Graphql graphqlBean = new Graphql(); commitHashes.parallelStream() .forEach(commitHash -> { @@ -322,7 +315,7 @@ private void findAuthorCommits(String owner, String repositoryName, String fileN try { jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); } catch (CodeQualityMetricsException e) { - logger.debug(e.getMessage(), e.getCause()); + logger.error(e.getMessage(), e.getCause()); } saveAuthorCommits(jsonText, oldRange, lineRangesForSelectedFile); }); @@ -342,7 +335,6 @@ private void findAuthorCommits(String owner, String repositoryName, String fileN * @param lineRangesForSelectedFile arraylist containing the changed line ranges of the current selected file */ private void saveAuthorCommits(String jsonText, String oldRange, List lineRangesForSelectedFile) { - GraphQlResponse graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); lineRangesForSelectedFile.forEach(lineRange -> { int startingLineNo; diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java index 4b6f917..e602b6a 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java @@ -66,7 +66,7 @@ public void execute() { reviewAnalyser.printReviewUsers(); logger.debug("The application executed successfully"); } catch (CodeQualityMetricsException e) { - logger.debug(e.getMessage(), e.getCause()); + logger.error(e.getMessage(), e.getCause()); } } @@ -96,7 +96,7 @@ private List findCommitHashesInPatch() throws CodeQualityMetricsExceptio } } if (logger.isDebugEnabled()) { - logger.debug("The commit hashes are: " + commitHashes); + logger.error("The commit hashes are: " + commitHashes); } } else { throw new CodeQualityMetricsException("The returned jsonText from PMT API is null"); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java index d5f6eb9..5151c4a 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java @@ -23,7 +23,10 @@ import org.apache.http.entity.StringEntity; import org.json.JSONObject; +import java.io.IOException; +import java.io.InputStream; import java.io.UnsupportedEncodingException; +import java.util.Properties; import static com.wso2.code.quality.metrics.model.Constants.ACCEPT; import static com.wso2.code.quality.metrics.model.Constants.AUTHORIZATION; @@ -36,6 +39,10 @@ */ public class GithubApiCaller { private HttpGet httpGet; + private final Properties defaultProperties = new Properties(); + private final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + private final InputStream inputStream = classLoader.getResourceAsStream("url.properties"); + /** * This is used for calling the github search REST API. @@ -43,18 +50,22 @@ public class GithubApiCaller { * @param commitHash commit hash to be searched * @param githubAccessToken Github access token for accessing github API * @return String representation of the json response - * @throws CodeQualityMetricsException + * @throws CodeQualityMetricsException results */ public String callSearchCommitApi(String commitHash, String githubAccessToken) throws CodeQualityMetricsException { - String url = "https://api.github.com/search/commits?q=hash%3A" + commitHash; try { + defaultProperties.load(inputStream); + String url = defaultProperties.getProperty("searchCommitApiUrl") + commitHash; httpGet = new HttpGet(url); httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); //as the accept header is needed for accessing commit search API which is still in preview mode - httpGet.addHeader(ACCEPT, "application/vnd.github.cloak-preview"); + httpGet.addHeader(ACCEPT, defaultProperties.getProperty("searchCommitApiHeader")); } catch (IllegalArgumentException e) { throw new CodeQualityMetricsException("The url provided for accessing the Github Search Commit API is " + "invalid ", e); + } catch (IOException e) { + throw new CodeQualityMetricsException("IO exception occurred when loading the inputstream to the " + + "properties object", e); } return ApiUtility.callApi(httpGet); } @@ -66,18 +77,24 @@ public String callSearchCommitApi(String commitHash, String githubAccessToken) t * @param pullRequestNumber pull request number to be queried for * @param githubAccessToken Github access token for accessing github API * @return String representation of the json response - * @throws CodeQualityMetricsException + * @throws CodeQualityMetricsException results */ public String callReviewApi(String repoLocation, int pullRequestNumber, String githubAccessToken) throws CodeQualityMetricsException { - String url = "https://api.github.com/repos/" + repoLocation + "/pulls/" + pullRequestNumber + "/reviews"; try { + defaultProperties.load(inputStream); + String tempUrl = defaultProperties.getProperty("reviewApiUrl"); + String url = tempUrl.replaceFirst("REPO_LOCATION", repoLocation).replaceFirst("PULL_REQUEST_NUMBER", + String.valueOf(pullRequestNumber)); httpGet = new HttpGet(url); - httpGet.addHeader(ACCEPT, "application/vnd.github.black-cat-preview+json"); + httpGet.addHeader(ACCEPT, defaultProperties.getProperty("reviewApiUrlHeader")); httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); } catch (IllegalArgumentException e) { throw new CodeQualityMetricsException("The url provided for accessing the Github Review Commit API is " + "invalid ", e); + } catch (IOException e) { + throw new CodeQualityMetricsException("IO exception occurred when loading the inputstream to the " + + "properties object", e); } return ApiUtility.callApi(httpGet); } @@ -88,18 +105,22 @@ public String callReviewApi(String repoLocation, int pullRequestNumber, String g * @param commitHashToBeSearched commit hash to be searched for issues * @param githubAccessToken Github access token for accessing github API * @return String representation of the json response - * @throws CodeQualityMetricsException + * @throws CodeQualityMetricsException results */ public String callSearchIssueApi(String commitHashToBeSearched, String githubAccessToken) throws CodeQualityMetricsException { - String url = "https://api.github.com/search/issues?q=" + commitHashToBeSearched; try { + defaultProperties.load(inputStream); + String url = defaultProperties.getProperty("searchIssueApiUrl") + commitHashToBeSearched; httpGet = new HttpGet(url); - httpGet.addHeader(ACCEPT, "application/vnd.github.mercy-preview+json"); + httpGet.addHeader(ACCEPT, defaultProperties.getProperty("searchIssueApiUrlHeader")); httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); } catch (IllegalArgumentException e) { throw new CodeQualityMetricsException("The url provided for accessing the Github Search Issue API is " + "invalid ", e); + } catch (IOException e) { + throw new CodeQualityMetricsException("IO exception occurred when loading the inputstream to the " + + "properties object", e); } return ApiUtility.callApi(httpGet); } @@ -110,16 +131,17 @@ public String callSearchIssueApi(String commitHashToBeSearched, String githubAcc * @param graphqlJsonStructure JSON input structure for calling the graphql API * @param githubToken Github access token for accessing github API * @return String representation of the json response - * @throws CodeQualityMetricsException + * @throws CodeQualityMetricsException results */ public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken) throws CodeQualityMetricsException { - String url = "https://api.github.com/graphql"; HttpPost httpPost; try { + defaultProperties.load(inputStream); + String url = defaultProperties.getProperty("githubGraphqlUrl"); httpPost = new HttpPost(url); httpPost.addHeader(AUTHORIZATION, BEARER + githubToken); - httpPost.addHeader(ACCEPT, "application/json"); + httpPost.addHeader(ACCEPT, defaultProperties.getProperty("githubGraphqlUrlHeader")); StringEntity entity = new StringEntity(graphqlJsonStructure.toString()); httpPost.setEntity(entity); } catch (IllegalArgumentException e) { @@ -128,6 +150,9 @@ public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken } catch (UnsupportedEncodingException e) { throw new CodeQualityMetricsException("An error occurred when creating the String entity from Json " + "Structure", e); + } catch (IOException e) { + throw new CodeQualityMetricsException("IO exception occurred when loading the inputstream to the " + + "properties object", e); } return ApiUtility.callGraphQlApi(httpPost); } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java index fb37efe..01dbf80 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java @@ -20,6 +20,10 @@ import org.apache.http.client.methods.HttpGet; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + import static com.wso2.code.quality.metrics.model.Constants.AUTHORIZATION; import static com.wso2.code.quality.metrics.model.Constants.BEARER; @@ -38,17 +42,26 @@ public PmtApiCaller() { * @param accessToken WSO2 PMT access token * @param patchId Patch Id * @return String representation of the json response - * @throws CodeQualityMetricsException + * @throws CodeQualityMetricsException results */ public String callApi(String accessToken, String patchId) throws CodeQualityMetricsException { - String pmtUrl = "http://umt.private.wso2.com:9765/codequalitymatricesapi/1.0.0//properties?path=/_system/" + - "governance/patchs/" + patchId; HttpGet httpGet; try { + Properties defaultProperties = new Properties(); + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + InputStream inputStream = classLoader.getResourceAsStream("url.properties"); + defaultProperties.load(inputStream); + String pmtApiUrl = defaultProperties.getProperty("pmtApiUrl"); + String pmtUrl = pmtApiUrl + patchId; httpGet = new HttpGet(pmtUrl); httpGet.addHeader(AUTHORIZATION, BEARER + accessToken); } catch (IllegalArgumentException e) { throw new CodeQualityMetricsException("The url provided for accessing the PMT API is invalid ", e); + } catch (SecurityException e) { + throw new CodeQualityMetricsException("The url properties file is not found", e); + } catch (IOException e) { + throw new CodeQualityMetricsException("IO exception occurred when loading the inputstream to the " + + "properties object", e); } return ApiUtility.callApi(httpGet); } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java index 1e9c1ba..ae9ed43 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java @@ -70,7 +70,7 @@ public void findReviewers(Set authorCommits, String githubToken) { } saveReviewers(prNoWithRepoName, githubToken); } catch (CodeQualityMetricsException e) { - logger.debug(e.getMessage(), e.getCause()); + logger.error(e.getMessage(), e.getCause()); } }); } @@ -80,7 +80,7 @@ public void findReviewers(Set authorCommits, String githubToken) { * * @param jsonText json reponse received from the github issue API * @return a map of pull requests againt their repository name - * @throws CodeQualityMetricsException + * @throws CodeQualityMetricsException results */ private Map> savePrNumberAndRepoName(String jsonText) throws CodeQualityMetricsException { // map for storing the pull requests numbers against their Repository @@ -116,9 +116,9 @@ private Map> savePrNumberAndRepoName(String jsonText) throw * @param githubToken Github access token for accessing github API */ private void saveReviewers(Map> prNoWithRepoName, String githubToken) { - for (Map.Entry entry : prNoWithRepoName.entrySet()) { - String repositoryName = (String) entry.getKey(); - Set prNumbers = (Set) entry.getValue(); + for (Map.Entry> entry : prNoWithRepoName.entrySet()) { + String repositoryName = entry.getKey(); + Set prNumbers = entry.getValue(); prNumbers.parallelStream() .forEach(prNumber -> { try { diff --git a/org.wso2.codequalitymatrices/src/main/resources/url.properties b/org.wso2.codequalitymatrices/src/main/resources/url.properties new file mode 100644 index 0000000..e46e20b --- /dev/null +++ b/org.wso2.codequalitymatrices/src/main/resources/url.properties @@ -0,0 +1,26 @@ +# +# Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# +# WSO2 Inc. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +pmtApiUrl=http://umt.private.wso2.com:9765/codequalitymatricesapi/1.0.0//properties?path=/_system/governance/patchs/ +searchCommitApiUrl=https://api.github.com/search/commits?q=hash%3A +searchCommitApiHeader=application/vnd.github.cloak-preview +searchIssueApiUrl=https://api.github.com/search/issues?q= +searchIssueApiUrlHeader=application/vnd.github.mercy-preview+json +githubGraphqlUrl=https://api.github.com/graphql +githubGraphqlUrlHeader=application/json +reviewApiUrl=https://api.github.com/repos/REPO_LOCATION/pulls/PULL_REQUEST_NUMBER/reviews +reviewApiUrlHeader=application/vnd.github.black-cat-preview+json From 63c43e64fc2035fda330c0df755c3248792cac82 Mon Sep 17 00:00:00 2001 From: kasun Date: Thu, 6 Apr 2017 19:08:52 +0530 Subject: [PATCH 54/62] Add test cases --- org.wso2.codequalitymatrices/pom.xml | 20 +++- .../code/quality/metrics/ChangesFinder.java | 39 +++--- .../metrics/CodeQualityMetricsExecutor.java | 6 +- .../code/quality/metrics/ReviewAnalyser.java | 28 ++++- .../code/quality/metrics/model/Graphql.java | 1 + .../metrics/model/ReviewApiResponse.java | 1 + .../src/main/resources/url.properties | 2 +- .../code/quality/metrics/ApplicationTest.java | 34 ------ .../CodeQualityMetricsExecutorTest.java | 73 ++++++++++++ .../quality/metrics/GithubResponsesTest.java | 112 ++++++++++++++++++ .../quality/metrics/GithubSdkClientRest.java | 88 ++++++++++++++ 11 files changed, 345 insertions(+), 59 deletions(-) delete mode 100644 org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ApplicationTest.java create mode 100644 org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java create mode 100644 org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java create mode 100644 org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientRest.java diff --git a/org.wso2.codequalitymatrices/pom.xml b/org.wso2.codequalitymatrices/pom.xml index 99da0bd..84b3401 100644 --- a/org.wso2.codequalitymatrices/pom.xml +++ b/org.wso2.codequalitymatrices/pom.xml @@ -37,7 +37,7 @@ 1.8 UTF-8 - 3.8.1 + 4.12 1.2.17 20160810 2.8.0 @@ -45,6 +45,7 @@ 1.1.1 4.5.2 3.5 + 1.3 @@ -53,6 +54,18 @@ junit ${junit.version} test + + + org.hamcrest + hamcrest-core + + + + + org.hamcrest + hamcrest-library + ${org.hamcrest.version} + test log4j @@ -102,6 +115,11 @@ 1.8 + + org.apache.maven.plugins + maven-surefire-plugin + 2.16 + diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java index 56558fc..213619a 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java @@ -49,14 +49,14 @@ public class ChangesFinder { private List fileNames = new ArrayList<>(); private List patchString = new ArrayList<>(); - private final List> changedLineRanges = new ArrayList<>(); // for saving the line no that are changed - private final JSONObject jsonStructure = new JSONObject(); private Map> parentCommitHashes; private Set authorNames = new HashSet<>(); //authors of the bug lines fixed from the patch private Set authorCommits = new HashSet<>(); // author commits of the bug lines fixed from the patch - + private final JSONObject jsonStructure = new JSONObject(); private final GithubApiCaller githubApiCaller = new GithubApiCaller(); private final Gson gson = new Gson(); + public final List> changedLineRanges = new ArrayList<>(); // for saving the line no that are changed + /** * This is used for obtaining the repositories that contain the relevant commits belongs to the given patch @@ -66,11 +66,12 @@ public class ChangesFinder { * @return author commits of the bug lines which are fixed from the given patch */ - public Set obtainRepoNamesForCommitHashes(String gitHubToken, List commitHashes) { + protected Set obtainRepoNamesForCommitHashes(String gitHubToken, List commitHashes) { commitHashes.forEach(commitHash -> { try { String jsonText = githubApiCaller.callSearchCommitApi(commitHash, gitHubToken); - saveRepoNames(jsonText, commitHash, gitHubToken); + List repoLocations = saveRepoNames(jsonText); + identifyChangedFile(repoLocations, commitHash, gitHubToken); } catch (CodeQualityMetricsException e) { logger.error(e.getMessage(), e.getCause()); } @@ -79,14 +80,13 @@ public Set obtainRepoNamesForCommitHashes(String gitHubToken, List saveRepoNames(String jsonText) throws CodeQualityMetricsException { List repoLocation = new ArrayList<>(); SearchApiResponse searchCommitPojo; try { @@ -96,8 +96,19 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke } searchCommitPojo.getContainingRepositories() .forEach(recordItem -> repoLocation.add(recordItem.getRepository().getRepositoryLocation())); - logger.debug("Repositories having the given commit are successfully saved in an List"); + return repoLocation; + } + + /** + * This identifies the file changed and their relevant line ranges changed in seleted repository from the given + * commit hash + * + * @param repoLocation List of repository locations having the given commit hash + * @param commitHash commit hash to be searched for containing WSO2 repositories + * @param gitHubToken Github access token for accessing github API + */ + private void identifyChangedFile(List repoLocation, String commitHash, String gitHubToken) { SdkGitHubClient sdkGitHubClient = new SdkGitHubClient(gitHubToken); repoLocation.stream() .filter(repositoryName -> StringUtils.contains(repositoryName, "wso2/")) @@ -135,7 +146,7 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke * @param patchString Array list having the patch string value for each of the file being changed */ - private void saveRelaventEditLineNumbers(List fileNames, List patchString) { + protected void saveRelaventEditLineNumbers(List fileNames, List patchString) { /*filtering only the line ranges that are modified and saving to a string array cannot use parallel streams here as the order of the line changes must be preserved */ @@ -145,7 +156,7 @@ private void saveRelaventEditLineNumbers(List fileNames, List pa /*filtering the lines ranges that existed in the previous file, that exists in the new file and saving them in to a list */ - IntStream.range(0, lineChanges.length) + IntStream.range(0, lineChanges.length) .forEach(index -> { //@@ -22,7 +22,7 @@ => -22,7 +22,7 => 22,28/22,28 String tempString = lineChanges[index]; diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java index e602b6a..9a76d0d 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java @@ -75,7 +75,7 @@ public void execute() { * * @return List of commithashes contained in the given patch */ - private List findCommitHashesInPatch() throws CodeQualityMetricsException { + protected List findCommitHashesInPatch() throws CodeQualityMetricsException { PmtApiCaller pmtApiCaller = new PmtApiCaller(); String jsonText; List commitHashes = new ArrayList<>(); @@ -89,9 +89,9 @@ private List findCommitHashesInPatch() throws CodeQualityMetricsExceptio List pmtResponse = gson.fromJson(jsonText, List.class); for (Object pmtEntry : pmtResponse) { if (pmtEntry instanceof Map) { - Map> entryMap = (Map>) pmtEntry; + Map entryMap = (Map) pmtEntry; if (COMMITS_INSIDE_GIVEN_PATCH.equals(entryMap.get("name"))) { - commitHashes = entryMap.get("value"); + commitHashes = (List) entryMap.get("value"); } } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java index ae9ed43..475245e 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java @@ -20,11 +20,13 @@ import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; +import com.google.gson.reflect.TypeToken; import com.wso2.code.quality.metrics.model.IssueApiResponse; import com.wso2.code.quality.metrics.model.ReviewApiResponse; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; +import java.lang.reflect.Type; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -45,13 +47,22 @@ public class ReviewAnalyser { private static final Logger logger = Logger.getLogger(ReviewAnalyser.class); // to store the reviewed and approved users of thepull requests - private final Set approvedReviewers = new HashSet<>(); + protected final Set approvedReviewers = new HashSet<>(); // to store the reviewed and commented users of the pull requests - private final Set commentedReviewers = new HashSet<>(); + protected final Set commentedReviewers = new HashSet<>(); //constants for filtering github API responses private final GithubApiCaller githubApiCaller = new GithubApiCaller(); private final Gson gson = new Gson(); + /** + * This class is used to prevent SIC_INNER_SHOULD_BE_STATIC_ANON error that comes when building with WSO2 parent + * pom. As suggested by the above error an static inner class is used + */ + static class ListType extends TypeToken> { + } + + + /** * This is used to identify the pull requests that introduce the given commit to the code base. * @@ -82,7 +93,7 @@ public void findReviewers(Set authorCommits, String githubToken) { * @return a map of pull requests againt their repository name * @throws CodeQualityMetricsException results */ - private Map> savePrNumberAndRepoName(String jsonText) throws CodeQualityMetricsException { + protected Map> savePrNumberAndRepoName(String jsonText) throws CodeQualityMetricsException { // map for storing the pull requests numbers against their Repository Map> prNoWithRepoName = new HashMap<>(); try { @@ -115,16 +126,21 @@ private Map> savePrNumberAndRepoName(String jsonText) throw * relevant reposiory * @param githubToken Github access token for accessing github API */ - private void saveReviewers(Map> prNoWithRepoName, String githubToken) { + protected void saveReviewers(Map> prNoWithRepoName, String githubToken) { for (Map.Entry> entry : prNoWithRepoName.entrySet()) { String repositoryName = entry.getKey(); Set prNumbers = entry.getValue(); prNumbers.parallelStream() - .forEach(prNumber -> { + .forEach((Integer prNumber) -> { try { String jsonText = githubApiCaller.callReviewApi(repositoryName, prNumber, githubToken); if (jsonText != null) { - List reviews = gson.fromJson(jsonText, List.class); +// Type listType = new TypeToken>() { +// }.getType(); + Type listType = new ListType().getType(); + List reviews = gson.fromJson(jsonText, listType); +// List reviews = gson.fromJson(jsonText, List.class); + // to filter Approved users reviews.parallelStream() .filter(review -> GITHUB_REVIEW_APPROVED.equals(review.getReviewState())) diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Graphql.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Graphql.java index 06662ca..b5f1aa8 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Graphql.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Graphql.java @@ -28,6 +28,7 @@ public class Graphql implements Serializable { private String graphqlInputWithHistory; private String graphqlInputWithoutHistory; + private static final long serialVersionUID = 42L; public Graphql() { } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ReviewApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ReviewApiResponse.java index b160dfe..d37c714 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ReviewApiResponse.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ReviewApiResponse.java @@ -31,6 +31,7 @@ public class ReviewApiResponse { @SerializedName("user") private Reviewer reviewer; + public String getReviewState() { return reviewState; } diff --git a/org.wso2.codequalitymatrices/src/main/resources/url.properties b/org.wso2.codequalitymatrices/src/main/resources/url.properties index e46e20b..b02090d 100644 --- a/org.wso2.codequalitymatrices/src/main/resources/url.properties +++ b/org.wso2.codequalitymatrices/src/main/resources/url.properties @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. # -pmtApiUrl=http://umt.private.wso2.com:9765/codequalitymatricesapi/1.0.0//properties?path=/_system/governance/patchs/ +pmtApiUrl=http://umt.private.wso2.com:9765/codequalitymatricesapi/1.0.0/properties?path=/_system/governance/patchs/ searchCommitApiUrl=https://api.github.com/search/commits?q=hash%3A searchCommitApiHeader=application/vnd.github.cloak-preview searchIssueApiUrl=https://api.github.com/search/issues?q= diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ApplicationTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ApplicationTest.java deleted file mode 100644 index cfd762c..0000000 --- a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ApplicationTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.wso2.code.quality.metrics; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Unit test for simple Application. - */ -public class ApplicationTest extends TestCase { - /** - * Create the test case - * - * @param testName name of the test case - */ - public ApplicationTest(String testName) { - super(testName); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() { - return new TestSuite(ApplicationTest.class); - } - - /** - * Rigourous Test :-) - */ - public void testApp() { - assertTrue(true); - } - -} diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java new file mode 100644 index 0000000..d44f251 --- /dev/null +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.metrics; + + +import org.apache.log4j.Logger; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + + +public class CodeQualityMetricsExecutorTest { + private static final Logger logger = Logger.getLogger(CodeQualityMetricsExecutorTest.class); + + private String pmtToken = "tQU5vxzrGeBpLMQuwOsJW_fyYLYa"; + private String githubToken = "4e8e69986aefdbae2f5fe59d892cd3badf771191"; + private final GithubApiCaller githubApiCaller = new GithubApiCaller(); + + private Set authorCommits; + + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Test + public void testUsingTempFolder() throws IOException { + File createdFile = folder.newFile("myfilefile.txt"); + assertTrue(createdFile.canRead()); + } + + @Test + public void testFindCommitHashesInPatch() throws CodeQualityMetricsException { + Map> patchesAndCommits = new HashMap<>(); + patchesAndCommits.put("WSO2-CARBON-PATCH-4.4.0-0680", Arrays.asList("eaa45529cbabc5f30a2ffaa4781821ad0a5223ab" + , "2b1d973d089ebc3af3b9e7b893f48cf905758cf4")); + patchesAndCommits.put("WSO2-CARBON-PATCH-4.4.0-0682", Arrays.asList("e3c3457149b109178d510aac965d5a85cc465aa0") + ); + patchesAndCommits.put("WSO2-CARBON-PATCH-4.4.0-0692", Arrays.asList + ("67a60e081c8e0fe01d087f60cd9b629bcea172ae")); + for (Map.Entry> map : patchesAndCommits.entrySet()) { + CodeQualityMetricsExecutor codeQualityMetricsExecutor = new CodeQualityMetricsExecutor(pmtToken, + map.getKey(), githubToken); + List commitHashes = codeQualityMetricsExecutor.findCommitHashesInPatch(); + assertEquals("Must match with the relevant commit list", map.getValue(), commitHashes); + } + } +} diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java new file mode 100644 index 0000000..c673003 --- /dev/null +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.metrics; + +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.junit.Assert.assertEquals; + +public class GithubResponsesTest { + private static String githubToken; + private static GithubApiCaller githubApiCaller; + + @BeforeClass + public static void setupTheEnvironment() { + githubToken = "4e8e69986aefdbae2f5fe59d892cd3badf771191"; + githubApiCaller = new GithubApiCaller(); + + } + + @Test +// @Ignore + public void testSaveRepoNames() throws CodeQualityMetricsException { + Map> commitHashWithRepoNames = new HashMap<>(); + commitHashWithRepoNames.put("eaa45529cbabc5f30a2ffaa4781821ad0a5223ab", Arrays.asList("wso2/carbon-apimgt")); + commitHashWithRepoNames.put("2b1d973d089ebc3af3b9e7b893f48cf905758cf4", Arrays.asList("wso2/carbon-apimgt")); + commitHashWithRepoNames.put("e3c3457149b109178d510aac965d5a85cc465aa0", + Arrays.asList("wso2/wso2-axis2-transports")); + for (Map.Entry> entry : commitHashWithRepoNames.entrySet()) { + String commitHash = entry.getKey(); + String jsonText = githubApiCaller.callSearchCommitApi(commitHash, githubToken); + ChangesFinder changesFinder = new ChangesFinder(); + List repoLocations = changesFinder.saveRepoNames(jsonText); + assertEquals("List of RepoLocations obtained must be same", entry.getValue(), repoLocations); + } + } + + @Test + @Ignore + public void testSavePrNumberAndRepoName() throws CodeQualityMetricsException { + String jsonText = githubApiCaller.callSearchIssueApi + ("0015c02145c8ec6d3bba433f2fb5e850e1d25846", githubToken); + ReviewAnalyser reviewAnalyser = new ReviewAnalyser(); + Map> actualPrNoWithRepoName = reviewAnalyser.savePrNumberAndRepoName(jsonText); + Map> expectedPrNoWithRepoName = new HashMap<>(); + Set expectedPrSet = new HashSet<>(); + expectedPrSet.add(656); + expectedPrSet.add(657); + expectedPrNoWithRepoName.put("wso2/carbon-apimgt", expectedPrSet); + assertThat(actualPrNoWithRepoName, is(expectedPrNoWithRepoName)); + + } + + @Test + public void testSaveReviewers() { + ReviewAnalyser reviewAnalyser = new ReviewAnalyser(); + Map> prNoWithRepoName1 = new HashMap<>(); + Set prNumberSet = new HashSet<>(); + prNumberSet.add(656); + prNumberSet.add(657); + prNoWithRepoName1.put("wso2/carbon-apimgt", prNumberSet); + List expectedApprovedReviewers1 = Collections.emptyList(); + List expectedCommentedReviewers1 = Collections.emptyList(); + reviewAnalyser.saveReviewers(prNoWithRepoName1, githubToken); + assertThat("List of approved users ", reviewAnalyser.approvedReviewers, + containsInAnyOrder(expectedApprovedReviewers1.toArray())); + assertThat("List of commented users ", reviewAnalyser.commentedReviewers, + containsInAnyOrder(expectedCommentedReviewers1.toArray())); + + reviewAnalyser.approvedReviewers.clear(); + reviewAnalyser.commentedReviewers.clear(); + Map> prNoWithRepoName2 = new HashMap<>(); + Set prNumberSet2 = new HashSet<>(); + prNumberSet2.add(885); + prNoWithRepoName2.put("wso2/product-is", prNumberSet2); + List expectedApprovedReviewers2 = Arrays.asList("darshanasbg"); + List expectedCommentedReviewers2 = Arrays.asList("isharak"); + reviewAnalyser.saveReviewers(prNoWithRepoName2, githubToken); + assertThat("List of approved users ", reviewAnalyser.approvedReviewers, + containsInAnyOrder(expectedApprovedReviewers2.toArray())); + assertThat("List of commented users ", reviewAnalyser.commentedReviewers, + containsInAnyOrder(expectedCommentedReviewers2.toArray())); + } +} diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientRest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientRest.java new file mode 100644 index 0000000..02987c4 --- /dev/null +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientRest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.metrics; + +import org.hamcrest.collection.IsEmptyCollection; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.hasSize; + +public class GithubSdkClientRest { + private static Map> fileNamesAndPatches; + + @BeforeClass + public static void setupTheEnvironment() throws CodeQualityMetricsException { + String githubToken = "4e8e69986aefdbae2f5fe59d892cd3badf771191"; + SdkGitHubClient sdkGitHubClient = new SdkGitHubClient(githubToken); + fileNamesAndPatches = sdkGitHubClient.getFilesChanged + ("wso2/carbon-apimgt", "eaa45529cbabc5f30a2ffaa4781821ad0a5223ab"); + } + + @Test + public void testGetFilesChanged() { + List fileChanged = new ArrayList<>(); + fileChanged.add("features/apimgt/org.wso2.carbon.apimgt.publisher.feature/src/main" + + "/resources/publisher/site/themes/wso2/templates/sso/logout/template.jag"); + fileChanged.add("features/apimgt/org.wso2.carbon.apimgt.store" + + ".feature/src/main/resources/store/site/themes/wso2" + + "/templates/sso/logout/template.jag"); + fileChanged.add("components/sso-hostobject/org.wso2.carbon.hostobjects" + + ".sso/src/main/java/org/wso2/carbon/hostobjects/" + + "sso/internal/SessionInfo.java"); + fileChanged.add("components/sso-hostobject/org.wso2.carbon.hostobjects" + + ".sso/src/main/java/org/wso2/carbon/hostobjects/" + + "sso/SAMLSSORelyingPartyObject.java"); + List fileNames = fileNamesAndPatches.get("fileNames"); + assertThat(fileNames, not(IsEmptyCollection.empty())); + assertThat(fileNames, hasSize(fileChanged.size())); + assertThat(fileNames, containsInAnyOrder(fileChanged.toArray())); + } + + @Test + public void testSaveRelaventEditLineNumbers() throws CodeQualityMetricsException { + //testing saveRelaventEditLineNumbers method + List> modifiedRanges = new ArrayList<>(); + List listRange1 = Arrays.asList("45,50/45,53"); + List listRange2 = Arrays.asList("44,49/44,52"); + List listRange3 = Arrays.asList("819,827/819,829", "901,912/903,916", "1078,1098/1082,1107", + "1140,1156/1149,1155", "1162,1168/1161,1166", "1276,1281/1274,1287", "1331,1336/1337,1367"); + List listRange4 = Arrays.asList("16,26/16,29", "57,60/60,71"); + modifiedRanges.add(listRange1); + modifiedRanges.add(listRange2); + modifiedRanges.add(listRange3); + modifiedRanges.add(listRange4); + List fileNames = fileNamesAndPatches.get("fileNames"); + List patchString = fileNamesAndPatches.get("patchString"); + ChangesFinder changesFinder = new ChangesFinder(); + changesFinder.saveRelaventEditLineNumbers(fileNames, patchString); + assertThat(changesFinder.changedLineRanges, not(IsEmptyCollection.empty())); + assertThat(changesFinder.changedLineRanges, hasSize(modifiedRanges.size())); + assertThat("Modified line ranges received from the method must be equal to the manually " + + "modifiedRanges list", changesFinder.changedLineRanges, containsInAnyOrder(modifiedRanges.toArray())); + } +} From 60a23cbb24ee6c7c2dd02c5cfc5ecbc68fc980aa Mon Sep 17 00:00:00 2001 From: kasun Date: Mon, 17 Apr 2017 15:59:07 +0530 Subject: [PATCH 55/62] fix for considering only deleted lines --- .../code/quality/metrics/ChangesFinder.java | 291 +++++++++++++++--- .../code/quality/metrics/GithubApiCaller.java | 26 ++ .../code/quality/metrics/ReviewAnalyser.java | 2 +- .../code/quality/metrics/SdkGitHubClient.java | 20 +- .../code/quality/metrics/model/Author.java | 43 +++ .../code/quality/metrics/model/Commit.java | 39 +++ .../model/CommitHistoryApiResponse.java | 53 ++++ .../src/main/resources/url.properties | 1 + .../quality/metrics/GithubSdkClientRest.java | 88 ------ .../quality/metrics/GithubSdkClientTest.java | 36 +++ 10 files changed, 447 insertions(+), 152 deletions(-) create mode 100644 org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Author.java create mode 100644 org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Commit.java create mode 100644 org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java delete mode 100644 org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientRest.java create mode 100644 org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java index 213619a..6eadc37 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java @@ -20,6 +20,8 @@ import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; +import com.google.gson.reflect.TypeToken; +import com.wso2.code.quality.metrics.model.CommitHistoryApiResponse; import com.wso2.code.quality.metrics.model.GraphQlResponse; import com.wso2.code.quality.metrics.model.Graphql; import com.wso2.code.quality.metrics.model.SearchApiResponse; @@ -27,14 +29,18 @@ import org.apache.log4j.Logger; import org.json.JSONObject; +import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Scanner; import java.util.Set; import java.util.TreeMap; +import java.util.regex.Pattern; import java.util.stream.IntStream; /** @@ -57,6 +63,12 @@ public class ChangesFinder { private final Gson gson = new Gson(); public final List> changedLineRanges = new ArrayList<>(); // for saving the line no that are changed + /** + * This class is used to prevent SIC_INNER_SHOULD_BE_STATIC_ANON error that comes when building with WSO2 parent + * pom. As suggested by the above error an static inner class is used + */ + private static class ListType extends TypeToken> { + } /** * This is used for obtaining the repositories that contain the relevant commits belongs to the given patch @@ -65,7 +77,6 @@ public class ChangesFinder { * @param commitHashes List of commits that belongs to the given patch * @return author commits of the bug lines which are fixed from the given patch */ - protected Set obtainRepoNamesForCommitHashes(String gitHubToken, List commitHashes) { commitHashes.forEach(commitHash -> { try { @@ -101,7 +112,7 @@ protected List saveRepoNames(String jsonText) throws CodeQualityMetricsE } /** - * This identifies the file changed and their relevant line ranges changed in seleted repository from the given + * This identifies the file changed and their relevant line ranges changed in selected repository from the given * commit hash * * @param repoLocation List of repository locations having the given commit hash @@ -113,23 +124,37 @@ private void identifyChangedFile(List repoLocation, String commitHash, S repoLocation.stream() .filter(repositoryName -> StringUtils.contains(repositoryName, "wso2/")) .forEach(repositoryName -> { - //clearing all data in the current fileNames and changedLineRanges arraylists for each Repository //authorNames.clear(); - fileNames.clear(); - changedLineRanges.clear(); - patchString.clear(); - Map> fileNamesWithPatcheString = null; + Map fileNamesWithPatchString = new HashMap<>(); try { - fileNamesWithPatcheString = sdkGitHubClient.getFilesChanged(repositoryName, commitHash); + fileNamesWithPatchString = sdkGitHubClient.getFilesChanged(repositoryName, commitHash); } catch (CodeQualityMetricsException e) { logger.error(e.getMessage(), e.getCause()); } - if (fileNamesWithPatcheString != null) { - fileNames = fileNamesWithPatcheString.get("fileNames"); - patchString = fileNamesWithPatcheString.get("patchString"); + + Map> fileNamesWithDeletedLineNumbers = new HashMap<>(); + Map fileNamesWithPreviousCommitHash = new HashMap<>(); + if (fileNamesWithPatchString != null) { + // looping from one file to file and saving deleted lines against the file name in another map + for (Map.Entry entry : fileNamesWithPatchString.entrySet()) { + String fileName = entry.getKey(); + String patchString = entry.getValue(); + Set deletedLines = identifyDeletedLines(patchString); + String previousCommitHash; + //for omitting files without having deleted lines + if (deletedLines.size() > 0) { + fileNamesWithDeletedLineNumbers.put(fileName, deletedLines); + previousCommitHash = findPreviousCommitOfFile(repositoryName, fileName, commitHash, + gitHubToken); + fileNamesWithPreviousCommitHash.put(fileName, previousCommitHash); + } + } } - saveRelaventEditLineNumbers(fileNames, patchString); - findFileChanges(repositoryName, commitHash, gitHubToken); +// saveRelaventEditLineNumbers(fileNames, patchString); + getBlameDetails(repositoryName, fileNamesWithPreviousCommitHash, + fileNamesWithDeletedLineNumbers, gitHubToken); + +// findFileChanges(repositoryName, commitHash, gitHubToken); }); if (logger.isDebugEnabled()) { @@ -138,6 +163,132 @@ private void identifyChangedFile(List repoLocation, String commitHash, S } } + /** + * This is used to get the previous commit hash of the selected file before the current selected commit which + * contained in the given patch + * + * @param repositoryName current selected Repository + * @param filePath current selected file name + * @param latestCommitHash current selected recent commit contained in the given patch + * @param githubToken github access token for accessing github REST API + * @return commits hash prior to the current selected commit hash contained in the given patch of the current + * selected file + */ + public String findPreviousCommitOfFile(String repositoryName, String filePath, String latestCommitHash, String githubToken) { + String previousCommit = null; + Map commitWithDate = new HashMap<>(); + try { + String jsonText = githubApiCaller.callCommitHistoryApi(repositoryName, filePath, githubToken); + if (jsonText != null) { + Type listType = new ListType().getType(); + List commitHistoryApiResponses = gson.fromJson(jsonText, listType); + commitHistoryApiResponses.forEach(commitHistoryApiResponse -> { + String commitHash = commitHistoryApiResponse.getCommitHash(); + String date = commitHistoryApiResponse.getCommit().getAuthor().getDate(); + commitWithDate.put(commitHash, date); + }); + String latestCommitDate = commitWithDate.get(latestCommitHash); + String previousCommitDate = getPreviousCommitDate(commitWithDate, latestCommitDate); + // looping for finding the commit Hash introduced in previous commit date + for (Map.Entry entry : commitWithDate.entrySet()) { + if (entry.getValue().equals(previousCommitDate)) { + previousCommit = (String) entry.getKey(); + } + } + } else { + if (logger.isDebugEnabled()) { + logger.debug("There are no commit history records for the file " + filePath + " on repository " + + "" + repositoryName); + } + } + } catch (CodeQualityMetricsException e) { + logger.error(e.getMessage(), e.getCause()); + } + return previousCommit; + } + + /** + * This is used to get the previous commit date of the selected file before the current commit + * + * @param commitWithDate map contating all the commits with their respective date of the current selected + * file + * @param latestCommitDate latest commit date of the current selected file + * @return previous commit date of the current selected file + */ + public String getPreviousCommitDate(Map commitWithDate, String latestCommitDate) { + //creating a tempory list for sorting the date in ascending order + List sortedCommitDates = new ArrayList<>(commitWithDate.values()); + Collections.sort(sortedCommitDates); + int indexOfLatestcommit = sortedCommitDates.indexOf(latestCommitDate); + String previousCommitDateOfFile = sortedCommitDates.get(--indexOfLatestcommit); + return previousCommitDateOfFile; + } + + /** + * This method is used to obtain the blame details of files for their previous commits + * + * @param repoLocation current selected Repository + * @param fileNamesWithPreviousCommitHash map containing changed files with their prior commit hashes + * @param fileNamesWithDeletedLineNumbers map containing changed files with their deleted line numbers + * @param githubToken github access token for accessing github REST API + */ + public void getBlameDetails(String repoLocation, Map fileNamesWithPreviousCommitHash, + Map> fileNamesWithDeletedLineNumbers, String githubToken) { + + // filtering the owner and the repository name from the repoLocation + String owner = StringUtils.substringBefore(repoLocation, "/"); + String repositoryName = StringUtils.substringAfter(repoLocation, "/"); + Graphql graphqlBean = new Graphql(); +// for (Map.Entry entry : fileNamesWithPreviousCommitHash.entrySet()) { +// String fileName =(String) entry.getKey(); +// String commitHash= (String)entry.getValue(); +// graphqlBean.setGraphqlInputWithoutHistory(owner, repositoryName); +// +// } + fileNamesWithPreviousCommitHash.forEach((fileName, previousCommitHash) -> { + graphqlBean.setGraphqlInputWithoutHistory(owner, repositoryName, previousCommitHash, fileName); + jsonStructure.put("query", graphqlBean.getGraphqlInputWithoutHistory()); + String jsonText = null; + try { + // calling the graphql API for getting blame information for the current file. + jsonText = githubApiCaller.callGraphqlApi(jsonStructure, githubToken); + findAuthorCommits(jsonText, fileNamesWithDeletedLineNumbers, fileName); + System.out.println(); + } catch (CodeQualityMetricsException e) { + logger.error(e.getMessage(), e.getCause()); + } + }); + + + } + + /** + * This is used to save the authors and relevant author commits of the buggy lines of code which are been fixed by + * the given patch, to relevant lists. + * + * @param jsonText String representation of the json response received from github graphql API + * @param fileNamesWithDeletedLineNumbers map containing changed files with their deleted line numbers + * @param selectedFileName selected file for finding the authors and author commits of its buggy lines + */ + public void findAuthorCommits(String jsonText, Map> fileNamesWithDeletedLineNumbers, String + selectedFileName) { + + GraphQlResponse graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); + Set deletedLines = fileNamesWithDeletedLineNumbers.get(selectedFileName); + deletedLines.forEach(deletedLineNumber -> + graphQlResponse.getResponse().getRepository().getFile().getBlame().getRanges() + .stream() + .filter(graphqlRange -> (graphqlRange.getStartingLine() <= deletedLineNumber && + graphqlRange.getEndingLine() >= deletedLineNumber)) + .forEach(graphqlRange -> { + String authorName = graphqlRange.getCommit().getAuthor().getName(); + String authorcommit = StringUtils.substringAfter(graphqlRange.getCommit().getUrl(), + "commit/"); + authorNames.add(authorName); // authors are added to the Set + authorCommits.add(authorcommit); // author commits are added to the set + })); + } + /** * This method is used to save the line ranges being modified in a given file to a list and add that list to the * root list of. @@ -156,7 +307,7 @@ protected void saveRelaventEditLineNumbers(List fileNames, List /*filtering the lines ranges that existed in the previous file, that exists in the new file and saving them in to a list */ - IntStream.range(0, lineChanges.length) + IntStream.range(0, lineChanges.length) .forEach(index -> { //@@ -22,7 +22,7 @@ => -22,7 +22,7 => 22,28/22,28 String tempString = lineChanges[index]; @@ -237,7 +388,7 @@ private void findFileChanges(String repoLocation, String commitHash, String gitH } catch (CodeQualityMetricsException e) { logger.error(e.getMessage(), e.getCause()); } - findAuthorCommits(owner, repositoryName, fileName, lineRangesForSelectedFile, gitHubToken); + findAuthorCommitsDel(owner, repositoryName, fileName, lineRangesForSelectedFile, gitHubToken); logger.debug("Authors and author commits of bug lines of code which are being fixed from the given " + "patch are saved successfully to authorNames and authorCommits Sets"); }); @@ -312,8 +463,8 @@ private void readBlameForSelectedFile(String jsonText, List changedRange * @param lineRangesForSelectedFile arraylist containing the changed line ranges of the current selected file * @param gitHubToken github token for accessing github GraphQL API */ - private void findAuthorCommits(String owner, String repositoryName, String fileName, - List lineRangesForSelectedFile, String gitHubToken) { + private void findAuthorCommitsDel(String owner, String repositoryName, String fileName, + List lineRangesForSelectedFile, String gitHubToken) { for (Map.Entry> entry : parentCommitHashes.entrySet()) { String oldRange = entry.getKey(); Set commitHashes = entry.getValue(); @@ -328,7 +479,7 @@ private void findAuthorCommits(String owner, String repositoryName, String fileN } catch (CodeQualityMetricsException e) { logger.error(e.getMessage(), e.getCause()); } - saveAuthorCommits(jsonText, oldRange, lineRangesForSelectedFile); +// saveAuthorCommits(jsonText, oldRange, lineRangesForSelectedFile); }); } if (logger.isDebugEnabled()) { @@ -337,42 +488,82 @@ private void findAuthorCommits(String owner, String repositoryName, String fileN } } +// /** +// * This is used to save the authors and author commits of the buggy lines of code which are been fixed by the +// * given patch, to relevant lists. +// * +// * @param jsonText String representation of the json response +// * @param oldRange Range to select the correct range for collecting author commits +// * @param lineRangesForSelectedFile arraylist containing the changed line ranges of the current selected file +// */ +// private void saveAuthorCommits(String jsonText, String oldRange, List lineRangesForSelectedFile) { +// GraphQlResponse graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); +// lineRangesForSelectedFile.forEach(lineRange -> { +// int startingLineNo; +// int endLineNo; +// String oldFileRange = StringUtils.substringBefore(lineRange, "/"); +// // need to skip the newly created files from taking the blame as they contain no previous commits +// if (!oldFileRange.equals("0,0") && oldRange.equals(oldFileRange)) { +// // need to consider the correct line range in the old file for finding authors and author commits +// startingLineNo = Integer.parseInt(StringUtils.substringBefore(oldFileRange, ",")); +// endLineNo = Integer.parseInt(StringUtils.substringAfter(oldFileRange, ",")); +// while (endLineNo >= startingLineNo) { +// int finalStartingLineNo = startingLineNo; // to make a effective final variable +// +// graphQlResponse.getResponse().getRepository().getFile().getBlame().getRanges().stream() +// +// .filter(graphqlRange -> (graphqlRange.getStartingLine() <= finalStartingLineNo && +// graphqlRange.getEndingLine() >= finalStartingLineNo)) +// .forEach(graphqlRange -> { +// String authorName = graphqlRange.getCommit().getAuthor().getName(); +// String authorcommit = StringUtils.substringAfter(graphqlRange.getCommit().getUrl(), +// "commit/"); +// authorNames.add(authorName); // authors are added to the Set +// authorCommits.add(authorcommit); // author commits are added to the set +// }); +// startingLineNo++; // to check for other line numbers +// } +// } +// }); +// } + /** - * This is used to save the authors and author commits of the buggy lines of code which are been fixed by the - * given patch, to relevant lists. + * This method is used to identify the deleted lines from the current selected commit in given patch * - * @param jsonText String representation of the json response - * @param oldRange Range to select the correct range for collecting author commits - * @param lineRangesForSelectedFile arraylist containing the changed line ranges of the current selected file + * @param patchString patch string of the selected file received from github SDK + * @return a Set of deleted lines in the above mentioned file */ - private void saveAuthorCommits(String jsonText, String oldRange, List lineRangesForSelectedFile) { - GraphQlResponse graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); - lineRangesForSelectedFile.forEach(lineRange -> { - int startingLineNo; - int endLineNo; - String oldFileRange = StringUtils.substringBefore(lineRange, "/"); - // need to skip the newly created files from taking the blame as they contain no previous commits - if (!oldFileRange.equals("0,0") && oldRange.equals(oldFileRange)) { - // need to consider the correct line range in the old file for finding authors and author commits - startingLineNo = Integer.parseInt(StringUtils.substringBefore(oldFileRange, ",")); - endLineNo = Integer.parseInt(StringUtils.substringAfter(oldFileRange, ",")); - while (endLineNo >= startingLineNo) { - int finalStartingLineNo = startingLineNo; // to make a effective final variable - - graphQlResponse.getResponse().getRepository().getFile().getBlame().getRanges().stream() - - .filter(graphqlRange -> (graphqlRange.getStartingLine() <= finalStartingLineNo && - graphqlRange.getEndingLine() >= finalStartingLineNo)) - .forEach(graphqlRange -> { - String authorName = graphqlRange.getCommit().getAuthor().getName(); - String authorcommit = StringUtils.substringAfter(graphqlRange.getCommit().getUrl(), - "commit/"); - authorNames.add(authorName); // authors are added to the Set - authorCommits.add(authorcommit); // author commits are added to the set - }); - startingLineNo++; // to check for other line numbers + private Set identifyDeletedLines(String patchString) { + Set linesDeletedInSelectedFile = new HashSet<>(); + Pattern pattern = Pattern.compile("@@ -"); + String patches[] = pattern.split(patchString); + for (String patchRange : patches) { + Scanner scanner = new Scanner(patchRange); + int lineNumber = 0; + //for finding the starting line number for the modified range. + if (scanner.hasNext()) { + String patchLine = scanner.nextLine(); + String words[] = patchLine.split(","); + lineNumber = Integer.parseInt(words[0]); + } + //for finding the deleted lines in the string + while (scanner.hasNext()) { + String patchLine = scanner.nextLine(); + String words[]; + if (patchLine.trim().length() != 0) { + words = patchLine.split("\\s"); + } else { + words = patchLine.trim().split("\\s"); + } + String sign = words[0]; + if ("-".equals(sign) || "".equals(sign)) { + if ("-".equals(sign)) { + linesDeletedInSelectedFile.add(lineNumber); + } + lineNumber++; } } - }); + } + return linesDeletedInSelectedFile; } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java index 5151c4a..9b793d6 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java @@ -70,6 +70,32 @@ public String callSearchCommitApi(String commitHash, String githubAccessToken) t return ApiUtility.callApi(httpGet); } + /** + * This is used to call github commit REST API + * @param repoLocation + * @param filePath + * @param githubAccessToken + * @return + * @throws CodeQualityMetricsException + */ + public String callCommitHistoryApi(String repoLocation,String filePath,String githubAccessToken) + throws CodeQualityMetricsException { + try { + defaultProperties.load(inputStream); + String tempUrl= defaultProperties.getProperty("commitHistoryApiUrl"); + String url=tempUrl.replaceFirst("REPO_LOCATION",repoLocation).replaceFirst("FILE_NAME",filePath); + httpGet= new HttpGet(url); + httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); + } catch (IllegalArgumentException e) { + throw new CodeQualityMetricsException("The url provided for accessing the Github Search Commit API is " + + "invalid ", e); + } catch (IOException e) { + throw new CodeQualityMetricsException("IO exception occurred when loading the inputstream to the " + + "properties object", e); + } + return ApiUtility.callApi(httpGet); + } + /** * This is used to call the github review API. * diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java index 475245e..124615e 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java @@ -58,7 +58,7 @@ public class ReviewAnalyser { * This class is used to prevent SIC_INNER_SHOULD_BE_STATIC_ANON error that comes when building with WSO2 parent * pom. As suggested by the above error an static inner class is used */ - static class ListType extends TypeToken> { + private static class ListType extends TypeToken> { } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java index 4935f74..92c3eef 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java @@ -27,7 +27,6 @@ import org.eclipse.egit.github.core.service.RepositoryService; import java.io.IOException; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -60,29 +59,24 @@ public class SdkGitHubClient { * @param commitHash The querying commit hash * @return a map containg arraylist of file changed and their relevant patch */ - public Map> getFilesChanged(String repositoryName, String commitHash) + public Map getFilesChanged(String repositoryName, String commitHash) throws CodeQualityMetricsException { - Map> fileNamesAndPatches = new HashMap<>(); + Map fileNamesAndPatches = new HashMap<>(); try { IRepositoryIdProvider iRepositoryIdProvider = () -> repositoryName; RepositoryCommit repositoryCommit = commitService.getCommit(iRepositoryIdProvider, commitHash); List filesChanged = repositoryCommit.getFiles(); - List tempFileNames = new ArrayList<>(); - List tempPatchString = new ArrayList<>(); - // this can be run parallely as patchString of a file will always be in the same index as the file + + // this can be run parallely as patchString of a file will always be with the same file filesChanged.parallelStream() .forEach(commitFile -> { - tempFileNames.add(commitFile.getFilename()); - tempPatchString.add(commitFile.getPatch()); + fileNamesAndPatches.put(commitFile.getFilename(),commitFile.getPatch()); }); if (logger.isDebugEnabled()) { logger.debug("for commit hash" + commitHash + " on the " + repositoryName + " repository, files" + - " changed and their relevant changed line ranges are added to the arraylists successfully"); + " changed and their relevant patch strings are saved to the map successfully"); } - fileNamesAndPatches.put("fileNames", tempFileNames); - fileNamesAndPatches.put("patchString", tempPatchString); - logger.debug("Modified file names with their relevant modified line ranges are saved to a map " + - "successfully"); + } catch (IOException e) { throw new CodeQualityMetricsException("IO Exception occurred when getting the commit of given SHA from " + "the given Repository ", e); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Author.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Author.java new file mode 100644 index 0000000..93d866b --- /dev/null +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Author.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.metrics.model; + +import com.google.gson.annotations.SerializedName; + +/** + * Pojo class used for parsing JSON response received from github REST API. + * + * @since 1.0.0 + */ +public class Author { + + @SerializedName("date") + + private String date; + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + +} diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Commit.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Commit.java new file mode 100644 index 0000000..b73150f --- /dev/null +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Commit.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.metrics.model; + +import com.google.gson.annotations.SerializedName; + +/** + * Pojo class used for parsing JSON response received from github REST API. + * + * @since 1.0.0 + */ +public class Commit { + @SerializedName("author") + private Author author; + + public Author getAuthor() { + return author; + } + + public void setAuthor(Author author) { + this.author = author; + } +} diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java new file mode 100644 index 0000000..102edb5 --- /dev/null +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.metrics.model; + +import com.google.gson.annotations.SerializedName; + +/** + * Pojo class used for parsing JSON response received from github REST API. + * + * @since 1.0.0 + */ +public class CommitHistoryApiResponse { + @SerializedName("sha") + private String commitHash; + + @SerializedName("commit") + + private Commit commit; + + public String getCommitHash() { + return commitHash; + } + + public void setCommitHash(String commitHash) { + this.commitHash = commitHash; + } + + public Commit getCommit() { + return commit; + } + + public void setCommit(Commit commit) { + this.commit = commit; + } + + +} diff --git a/org.wso2.codequalitymatrices/src/main/resources/url.properties b/org.wso2.codequalitymatrices/src/main/resources/url.properties index b02090d..a948015 100644 --- a/org.wso2.codequalitymatrices/src/main/resources/url.properties +++ b/org.wso2.codequalitymatrices/src/main/resources/url.properties @@ -20,6 +20,7 @@ searchCommitApiUrl=https://api.github.com/search/commits?q=hash%3A searchCommitApiHeader=application/vnd.github.cloak-preview searchIssueApiUrl=https://api.github.com/search/issues?q= searchIssueApiUrlHeader=application/vnd.github.mercy-preview+json +commitHistoryApiUrl=https://api.github.com/repos/REPO_LOCATION/commits?path=FILE_NAME githubGraphqlUrl=https://api.github.com/graphql githubGraphqlUrlHeader=application/json reviewApiUrl=https://api.github.com/repos/REPO_LOCATION/pulls/PULL_REQUEST_NUMBER/reviews diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientRest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientRest.java deleted file mode 100644 index 02987c4..0000000 --- a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientRest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.wso2.code.quality.metrics; - -import org.hamcrest.collection.IsEmptyCollection; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.hasSize; - -public class GithubSdkClientRest { - private static Map> fileNamesAndPatches; - - @BeforeClass - public static void setupTheEnvironment() throws CodeQualityMetricsException { - String githubToken = "4e8e69986aefdbae2f5fe59d892cd3badf771191"; - SdkGitHubClient sdkGitHubClient = new SdkGitHubClient(githubToken); - fileNamesAndPatches = sdkGitHubClient.getFilesChanged - ("wso2/carbon-apimgt", "eaa45529cbabc5f30a2ffaa4781821ad0a5223ab"); - } - - @Test - public void testGetFilesChanged() { - List fileChanged = new ArrayList<>(); - fileChanged.add("features/apimgt/org.wso2.carbon.apimgt.publisher.feature/src/main" + - "/resources/publisher/site/themes/wso2/templates/sso/logout/template.jag"); - fileChanged.add("features/apimgt/org.wso2.carbon.apimgt.store" + - ".feature/src/main/resources/store/site/themes/wso2" + - "/templates/sso/logout/template.jag"); - fileChanged.add("components/sso-hostobject/org.wso2.carbon.hostobjects" + - ".sso/src/main/java/org/wso2/carbon/hostobjects/" + - "sso/internal/SessionInfo.java"); - fileChanged.add("components/sso-hostobject/org.wso2.carbon.hostobjects" + - ".sso/src/main/java/org/wso2/carbon/hostobjects/" + - "sso/SAMLSSORelyingPartyObject.java"); - List fileNames = fileNamesAndPatches.get("fileNames"); - assertThat(fileNames, not(IsEmptyCollection.empty())); - assertThat(fileNames, hasSize(fileChanged.size())); - assertThat(fileNames, containsInAnyOrder(fileChanged.toArray())); - } - - @Test - public void testSaveRelaventEditLineNumbers() throws CodeQualityMetricsException { - //testing saveRelaventEditLineNumbers method - List> modifiedRanges = new ArrayList<>(); - List listRange1 = Arrays.asList("45,50/45,53"); - List listRange2 = Arrays.asList("44,49/44,52"); - List listRange3 = Arrays.asList("819,827/819,829", "901,912/903,916", "1078,1098/1082,1107", - "1140,1156/1149,1155", "1162,1168/1161,1166", "1276,1281/1274,1287", "1331,1336/1337,1367"); - List listRange4 = Arrays.asList("16,26/16,29", "57,60/60,71"); - modifiedRanges.add(listRange1); - modifiedRanges.add(listRange2); - modifiedRanges.add(listRange3); - modifiedRanges.add(listRange4); - List fileNames = fileNamesAndPatches.get("fileNames"); - List patchString = fileNamesAndPatches.get("patchString"); - ChangesFinder changesFinder = new ChangesFinder(); - changesFinder.saveRelaventEditLineNumbers(fileNames, patchString); - assertThat(changesFinder.changedLineRanges, not(IsEmptyCollection.empty())); - assertThat(changesFinder.changedLineRanges, hasSize(modifiedRanges.size())); - assertThat("Modified line ranges received from the method must be equal to the manually " + - "modifiedRanges list", changesFinder.changedLineRanges, containsInAnyOrder(modifiedRanges.toArray())); - } -} diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java new file mode 100644 index 0000000..d6a0084 --- /dev/null +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.metrics; + +import org.hamcrest.collection.IsEmptyCollection; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.hasSize; + +public class GithubSdkClientTest { +} From 13cca5bae9209ff5b367900f0f5d97ca7be95697 Mon Sep 17 00:00:00 2001 From: kasun Date: Mon, 17 Apr 2017 17:45:47 +0530 Subject: [PATCH 56/62] Delete unnecassary lines --- .../code/quality/metrics/ChangesFinder.java | 258 ------------------ 1 file changed, 258 deletions(-) diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java index 6eadc37..1dc54ae 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java @@ -31,7 +31,6 @@ import java.lang.reflect.Type; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -39,9 +38,7 @@ import java.util.Map; import java.util.Scanner; import java.util.Set; -import java.util.TreeMap; import java.util.regex.Pattern; -import java.util.stream.IntStream; /** * This class is used for getting the blame information on relevant changed line ranges on relevant files from the @@ -53,15 +50,11 @@ public class ChangesFinder { private static final Logger logger = Logger.getLogger(ChangesFinder.class); - private List fileNames = new ArrayList<>(); - private List patchString = new ArrayList<>(); - private Map> parentCommitHashes; private Set authorNames = new HashSet<>(); //authors of the bug lines fixed from the patch private Set authorCommits = new HashSet<>(); // author commits of the bug lines fixed from the patch private final JSONObject jsonStructure = new JSONObject(); private final GithubApiCaller githubApiCaller = new GithubApiCaller(); private final Gson gson = new Gson(); - public final List> changedLineRanges = new ArrayList<>(); // for saving the line no that are changed /** * This class is used to prevent SIC_INNER_SHOULD_BE_STATIC_ANON error that comes when building with WSO2 parent @@ -131,7 +124,6 @@ private void identifyChangedFile(List repoLocation, String commitHash, S } catch (CodeQualityMetricsException e) { logger.error(e.getMessage(), e.getCause()); } - Map> fileNamesWithDeletedLineNumbers = new HashMap<>(); Map fileNamesWithPreviousCommitHash = new HashMap<>(); if (fileNamesWithPatchString != null) { @@ -150,12 +142,8 @@ private void identifyChangedFile(List repoLocation, String commitHash, S } } } -// saveRelaventEditLineNumbers(fileNames, patchString); getBlameDetails(repositoryName, fileNamesWithPreviousCommitHash, fileNamesWithDeletedLineNumbers, gitHubToken); - -// findFileChanges(repositoryName, commitHash, gitHubToken); - }); if (logger.isDebugEnabled()) { logger.debug("\n Author names :" + authorNames); @@ -239,12 +227,6 @@ public void getBlameDetails(String repoLocation, Map fileNamesWi String owner = StringUtils.substringBefore(repoLocation, "/"); String repositoryName = StringUtils.substringAfter(repoLocation, "/"); Graphql graphqlBean = new Graphql(); -// for (Map.Entry entry : fileNamesWithPreviousCommitHash.entrySet()) { -// String fileName =(String) entry.getKey(); -// String commitHash= (String)entry.getValue(); -// graphqlBean.setGraphqlInputWithoutHistory(owner, repositoryName); -// -// } fileNamesWithPreviousCommitHash.forEach((fileName, previousCommitHash) -> { graphqlBean.setGraphqlInputWithoutHistory(owner, repositoryName, previousCommitHash, fileName); jsonStructure.put("query", graphqlBean.getGraphqlInputWithoutHistory()); @@ -258,8 +240,6 @@ public void getBlameDetails(String repoLocation, Map fileNamesWi logger.error(e.getMessage(), e.getCause()); } }); - - } /** @@ -289,244 +269,6 @@ public void findAuthorCommits(String jsonText, Map> fileNam })); } - /** - * This method is used to save the line ranges being modified in a given file to a list and add that list to the - * root list of. - * - * @param fileNames Arraylist of files names that are being affected by the relevant commit - * @param patchString Array list having the patch string value for each of the file being changed - */ - - protected void saveRelaventEditLineNumbers(List fileNames, List patchString) { - /*filtering only the line ranges that are modified and saving to a string array cannot use parallel streams - here as the order of the line changes must be preserved - */ - patchString.stream() - .map(patch -> StringUtils.substringsBetween(patch, "@@ ", " @@")) - .forEach(lineChanges -> { - /*filtering the lines ranges that existed in the previous file, that exists in the new file and - saving them in to a list - */ - IntStream.range(0, lineChanges.length) - .forEach(index -> { - //@@ -22,7 +22,7 @@ => -22,7 +22,7 => 22,28/22,28 - String tempString = lineChanges[index]; - // for taking the authors and commit hashes of the previous lines - String lineRangeInTheOldFileBeingModified = StringUtils.substringBetween(tempString, - "-", " +"); - // for taking the parent commit - String lineRangeInTheNewFileResultedFromModification = StringUtils.substringAfter - (tempString, "+"); - int intialLineNoInOldFile = Integer.parseInt(StringUtils.substringBefore - (lineRangeInTheOldFileBeingModified, ",")); - int tempEndLineNoInOldFile = Integer.parseInt(StringUtils.substringAfter - (lineRangeInTheOldFileBeingModified, ",")); - int endLineNoOfOldFile; - if (intialLineNoInOldFile != 0) { - // to filterout the newly created files - endLineNoOfOldFile = intialLineNoInOldFile + (tempEndLineNoInOldFile - 1); - } else { - endLineNoOfOldFile = tempEndLineNoInOldFile; - } - int intialLineNoInNewFile = Integer.parseInt(StringUtils.substringBefore - (lineRangeInTheNewFileResultedFromModification, ",")); - int tempEndLineNoInNewFile = Integer.parseInt(StringUtils.substringAfter - (lineRangeInTheNewFileResultedFromModification, ",")); - int endLineNoOfNewFile = intialLineNoInNewFile + (tempEndLineNoInNewFile - 1); - // storing the line ranges that are being modified in the same array by replacing values - lineChanges[index] = intialLineNoInOldFile + "," + endLineNoOfOldFile + "/" + - intialLineNoInNewFile + "," + endLineNoOfNewFile; - }); - List changedRange = new ArrayList<>(Arrays.asList(lineChanges)); - //adding to the array list which keep track of the line ranges being changed - changedLineRanges.add(changedRange); - }); - logger.debug("done saving file names and their relevant modification line ranges"); - if (logger.isDebugEnabled()) { - logger.debug("\n File names : " + fileNames); - logger.debug("\n Changed ranges :" + changedLineRanges + "\n"); - } - } - - /** - * This will iterate over the saved filenames and their relevant changed line ranges and calls the github graphQL - * API for getting blame details for each of the files. - * - * @param repoLocation current selected Repository - * @param commitHash current selected Repository - * @param gitHubToken github token for accessing github GraphQL API - */ - private void findFileChanges(String repoLocation, String commitHash, String gitHubToken) { - // filtering the owner and the Repository name from the repoLocation - String owner = StringUtils.substringBefore(repoLocation, "/"); - String repositoryName = StringUtils.substringAfter(repoLocation, "/"); - /* iterating over the fileNames arraylist for the given commit cannot use parallel streams here as the order - of the file names is important in the process - */ - fileNames.forEach(fileName -> { - int index = fileNames.indexOf(fileName); - // the relevant arraylist of changed lines for that file - List lineRangesForSelectedFile = changedLineRanges.get(index); - // for storing the parent commit hashes for all the changed line ranges of the relevant file - parentCommitHashes = new HashMap<>(); - Graphql graphqlBean = new Graphql(); - graphqlBean.setGraphqlInputWithHistory(owner, repositoryName, commitHash, fileName); - jsonStructure.put("query", graphqlBean.getGraphqlInputWithHistory()); - String jsonText = null; - try { - // calling the graphql API for getting blame information for the current file. - jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); - } catch (CodeQualityMetricsException e) { - logger.error(e.getMessage(), e.getCause()); - } - //reading the above saved output for the current selected file name - try { - readBlameForSelectedFile(jsonText, lineRangesForSelectedFile); - if (logger.isDebugEnabled()) { - logger.debug("Parent commits are saved for the " + fileName + " for all the modified line ranges"); - } - } catch (CodeQualityMetricsException e) { - logger.error(e.getMessage(), e.getCause()); - } - findAuthorCommitsDel(owner, repositoryName, fileName, lineRangesForSelectedFile, gitHubToken); - logger.debug("Authors and author commits of bug lines of code which are being fixed from the given " + - "patch are saved successfully to authorNames and authorCommits Sets"); - }); - } - - /** - * This reads the blame received for the current selected file and insert parent commits of the changed lines - * to a list. - * - * @param jsonText JSON response of blame of the selected file - * @param changedRangesOfSelectedFile arraylist containing the changed line ranges of the current selected file - */ - private void readBlameForSelectedFile(String jsonText, List changedRangesOfSelectedFile) - throws CodeQualityMetricsException { - GraphQlResponse graphQlResponse; - try { - graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); - } catch (JsonSyntaxException e) { - throw new CodeQualityMetricsException(e.getMessage(), e.getCause()); - } - GraphQlResponse finalGraphQlResponse = graphQlResponse; // to make a effective final variable - changedRangesOfSelectedFile.forEach(lineRange -> { - int startingLineNo; - int endLineNo; - String oldFileRange = StringUtils.substringBefore(lineRange, "/"); - String newFileRange = StringUtils.substringAfter(lineRange, "/"); - // need to skip the newly created files from taking the blame as they contain no previous commits - if (!oldFileRange.equals("0,0")) { - /* need to consider the line range in the new file resulted from applying the commit, for finding - parent commits - */ - startingLineNo = Integer.parseInt(StringUtils.substringBefore(newFileRange, ",")); - endLineNo = Integer.parseInt(StringUtils.substringAfter(newFileRange, ",")); - //for storing age with the relevant parent commit hash - Map> ageWithParentCommit = new HashMap<>(); - while (endLineNo >= startingLineNo) { - int finalStartingLineNo = startingLineNo; // to make a effective final variable - - finalGraphQlResponse.getResponse().getRepository().getFile().getBlame().getRanges().stream() - - .filter(graphqlRange -> (graphqlRange.getStartingLine() <= finalStartingLineNo && - graphqlRange.getEndingLine() >= finalStartingLineNo)) - .forEach(graphqlRange -> { - int age = graphqlRange.getAge(); - String url = graphqlRange.getCommit().getHistory().getCommits().get(1).getDetails() - .getUrl(); - /* get(1) is used directly as there are only 2 elements in the List and last - resembles the parent commit - */ - String parentCommit = StringUtils.substringAfter(url, "commit/"); - ageWithParentCommit.putIfAbsent(age, new HashSet<>()); - if (!ageWithParentCommit.get(age).contains(parentCommit)) { - ageWithParentCommit.get(age).add(parentCommit); - } - }); - startingLineNo++; // to check for other line numbers - } - TreeMap> sortedAgeWithParentCommit = new TreeMap<>(ageWithParentCommit); - Set parentCommit = sortedAgeWithParentCommit.get(sortedAgeWithParentCommit.firstKey()); - parentCommitHashes.put(oldFileRange, parentCommit); - } - }); - } - - /** - * This is used to find the author and author commits of the buggy lines of code which are been fixed by the - * given patch. - * - * @param owner owner of the selected epository - * @param repositoryName selected repository name - * @param fileName name of the file which is required to get blame details - * @param lineRangesForSelectedFile arraylist containing the changed line ranges of the current selected file - * @param gitHubToken github token for accessing github GraphQL API - */ - private void findAuthorCommitsDel(String owner, String repositoryName, String fileName, - List lineRangesForSelectedFile, String gitHubToken) { - for (Map.Entry> entry : parentCommitHashes.entrySet()) { - String oldRange = entry.getKey(); - Set commitHashes = entry.getValue(); - Graphql graphqlBean = new Graphql(); - commitHashes.parallelStream() - .forEach(commitHash -> { - graphqlBean.setGraphqlInputWithoutHistory(owner, repositoryName, commitHash, fileName); - jsonStructure.put("query", graphqlBean.getGraphqlInputWithoutHistory()); - String jsonText = null; - try { - jsonText = githubApiCaller.callGraphqlApi(jsonStructure, gitHubToken); - } catch (CodeQualityMetricsException e) { - logger.error(e.getMessage(), e.getCause()); - } -// saveAuthorCommits(jsonText, oldRange, lineRangesForSelectedFile); - }); - } - if (logger.isDebugEnabled()) { - logger.debug("author commits and authors of bug lines of code on " + fileName + " file which are been " + - "fixed by the given patch are successfully saved to lists"); - } - } - -// /** -// * This is used to save the authors and author commits of the buggy lines of code which are been fixed by the -// * given patch, to relevant lists. -// * -// * @param jsonText String representation of the json response -// * @param oldRange Range to select the correct range for collecting author commits -// * @param lineRangesForSelectedFile arraylist containing the changed line ranges of the current selected file -// */ -// private void saveAuthorCommits(String jsonText, String oldRange, List lineRangesForSelectedFile) { -// GraphQlResponse graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); -// lineRangesForSelectedFile.forEach(lineRange -> { -// int startingLineNo; -// int endLineNo; -// String oldFileRange = StringUtils.substringBefore(lineRange, "/"); -// // need to skip the newly created files from taking the blame as they contain no previous commits -// if (!oldFileRange.equals("0,0") && oldRange.equals(oldFileRange)) { -// // need to consider the correct line range in the old file for finding authors and author commits -// startingLineNo = Integer.parseInt(StringUtils.substringBefore(oldFileRange, ",")); -// endLineNo = Integer.parseInt(StringUtils.substringAfter(oldFileRange, ",")); -// while (endLineNo >= startingLineNo) { -// int finalStartingLineNo = startingLineNo; // to make a effective final variable -// -// graphQlResponse.getResponse().getRepository().getFile().getBlame().getRanges().stream() -// -// .filter(graphqlRange -> (graphqlRange.getStartingLine() <= finalStartingLineNo && -// graphqlRange.getEndingLine() >= finalStartingLineNo)) -// .forEach(graphqlRange -> { -// String authorName = graphqlRange.getCommit().getAuthor().getName(); -// String authorcommit = StringUtils.substringAfter(graphqlRange.getCommit().getUrl(), -// "commit/"); -// authorNames.add(authorName); // authors are added to the Set -// authorCommits.add(authorcommit); // author commits are added to the set -// }); -// startingLineNo++; // to check for other line numbers -// } -// } -// }); -// } - /** * This method is used to identify the deleted lines from the current selected commit in given patch * From 3b3e426deacb2fa94159232a15bbdf1a2d8ff194 Mon Sep 17 00:00:00 2001 From: kasun Date: Tue, 18 Apr 2017 11:24:46 +0530 Subject: [PATCH 57/62] Check for octopuss commits --- .../code/quality/metrics/ChangesFinder.java | 108 +++++++++++++----- .../code/quality/metrics/GithubApiCaller.java | 35 +++++- .../code/quality/metrics/SdkGitHubClient.java | 4 +- .../quality/metrics/model/ParentCommit.java | 39 +++++++ .../model/SingleCommitApiResponse.java | 41 +++++++ .../src/main/resources/url.properties | 1 + .../quality/metrics/GithubSdkClientTest.java | 14 --- 7 files changed, 194 insertions(+), 48 deletions(-) create mode 100644 org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ParentCommit.java create mode 100644 org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SingleCommitApiResponse.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java index 1dc54ae..8dbe357 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java @@ -25,6 +25,7 @@ import com.wso2.code.quality.metrics.model.GraphQlResponse; import com.wso2.code.quality.metrics.model.Graphql; import com.wso2.code.quality.metrics.model.SearchApiResponse; +import com.wso2.code.quality.metrics.model.SingleCommitApiResponse; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.json.JSONObject; @@ -117,33 +118,33 @@ private void identifyChangedFile(List repoLocation, String commitHash, S repoLocation.stream() .filter(repositoryName -> StringUtils.contains(repositoryName, "wso2/")) .forEach(repositoryName -> { - //authorNames.clear(); Map fileNamesWithPatchString = new HashMap<>(); try { fileNamesWithPatchString = sdkGitHubClient.getFilesChanged(repositoryName, commitHash); - } catch (CodeQualityMetricsException e) { - logger.error(e.getMessage(), e.getCause()); - } - Map> fileNamesWithDeletedLineNumbers = new HashMap<>(); - Map fileNamesWithPreviousCommitHash = new HashMap<>(); - if (fileNamesWithPatchString != null) { - // looping from one file to file and saving deleted lines against the file name in another map - for (Map.Entry entry : fileNamesWithPatchString.entrySet()) { - String fileName = entry.getKey(); - String patchString = entry.getValue(); - Set deletedLines = identifyDeletedLines(patchString); - String previousCommitHash; - //for omitting files without having deleted lines - if (deletedLines.size() > 0) { - fileNamesWithDeletedLineNumbers.put(fileName, deletedLines); - previousCommitHash = findPreviousCommitOfFile(repositoryName, fileName, commitHash, - gitHubToken); - fileNamesWithPreviousCommitHash.put(fileName, previousCommitHash); + Map> fileNamesWithDeletedLineNumbers = new HashMap<>(); + Map fileNamesWithPreviousCommitHash = new HashMap<>(); + if (fileNamesWithPatchString != null) { + /* looping from one file to file and saving deleted lines against the file name in another + map */ + for (Map.Entry entry : fileNamesWithPatchString.entrySet()) { + String fileName = entry.getKey(); + String patchString = entry.getValue(); + Set deletedLines = identifyDeletedLines(patchString); + String previousCommitHash; + //for omitting files without having deleted lines + if (deletedLines.size() > 0) { + fileNamesWithDeletedLineNumbers.put(fileName, deletedLines); + previousCommitHash = checkForOctopussMerge(repositoryName, fileName, commitHash, + gitHubToken); + fileNamesWithPreviousCommitHash.put(fileName, previousCommitHash); + } } } + getBlameDetails(repositoryName, fileNamesWithPreviousCommitHash, + fileNamesWithDeletedLineNumbers, gitHubToken); + } catch (CodeQualityMetricsException e) { + logger.error(e.getMessage(), e.getCause()); } - getBlameDetails(repositoryName, fileNamesWithPreviousCommitHash, - fileNamesWithDeletedLineNumbers, gitHubToken); }); if (logger.isDebugEnabled()) { logger.debug("\n Author names :" + authorNames); @@ -151,6 +152,54 @@ private void identifyChangedFile(List repoLocation, String commitHash, S } } + /** + * This check whether the commit in the given patch is an octopuss commit or not, if it is octopuss commit an + * exception as the current scope of the program doesnot support octopuss commits + * + * @param repositoryName current selected Repository + * @param filePath current selected file name + * @param latestCommitHash current selected recent commit contained in the given patch + * @param githubToken github access token for accessing github REST API + * @return the commit hash returned from findPreviousCommitOfFile method + * @throws CodeQualityMetricsException notifying that the current scope of the program does not support octopuss + * merges + */ + public String checkForOctopussMerge(String repositoryName, String filePath, String latestCommitHash, String + githubToken) throws CodeQualityMetricsException { + String previousCommit = null; + try { + // need check whether the given commit has more than 2 parent commits + String singleCommitJsonText = githubApiCaller.callSingleCommitApi(repositoryName, latestCommitHash, + githubToken); + if (singleCommitJsonText != null) { + SingleCommitApiResponse singleCommitApiResponse = gson.fromJson(singleCommitJsonText, + SingleCommitApiResponse.class); + if (singleCommitApiResponse.getParentCommits().size() == 1) { + /*if the singleCommitApiResponse.getParentCommits().size() == 1 it is fast forward merge, so no need + to change the latestCommitHash*/ + if (logger.isDebugEnabled()) { + logger.debug("The commit " + latestCommitHash + " in relevant patch is not a octopuss merge " + + "commit"); + } + } else if (singleCommitApiResponse.getParentCommits().size() == 2) { + latestCommitHash = singleCommitApiResponse.getParentCommits().get(1).getCommitHash(); + if (logger.isDebugEnabled()) { + logger.debug("The commit " + latestCommitHash + " in relevant patch is not a octopuss merge " + + "commit"); + } + } else if (singleCommitApiResponse.getParentCommits().size() > 2) { + throw new CodeQualityMetricsException("The commit " + latestCommitHash + " in relevant patch is " + + "an octopuss merge commit, octopuss merge commits are avoided in the current scope of " + + "the program"); + } + previousCommit = findPreviousCommitOfFile(repositoryName, filePath, latestCommitHash, githubToken); + } + } catch (CodeQualityMetricsException e) { + logger.error(e.getMessage(), e.getCause()); + } + return previousCommit; + } + /** * This is used to get the previous commit hash of the selected file before the current selected commit which * contained in the given patch @@ -162,14 +211,16 @@ private void identifyChangedFile(List repoLocation, String commitHash, S * @return commits hash prior to the current selected commit hash contained in the given patch of the current * selected file */ - public String findPreviousCommitOfFile(String repositoryName, String filePath, String latestCommitHash, String githubToken) { + public String findPreviousCommitOfFile(String repositoryName, String filePath, String latestCommitHash, + String githubToken) { String previousCommit = null; Map commitWithDate = new HashMap<>(); try { - String jsonText = githubApiCaller.callCommitHistoryApi(repositoryName, filePath, githubToken); - if (jsonText != null) { + String commitHistoryJsonText = githubApiCaller.callCommitHistoryApi(repositoryName, filePath, githubToken); + if (commitHistoryJsonText != null) { Type listType = new ListType().getType(); - List commitHistoryApiResponses = gson.fromJson(jsonText, listType); + List commitHistoryApiResponses = gson.fromJson(commitHistoryJsonText, + listType); commitHistoryApiResponses.forEach(commitHistoryApiResponse -> { String commitHash = commitHistoryApiResponse.getCommitHash(); String date = commitHistoryApiResponse.getCommit().getAuthor().getDate(); @@ -235,7 +286,6 @@ public void getBlameDetails(String repoLocation, Map fileNamesWi // calling the graphql API for getting blame information for the current file. jsonText = githubApiCaller.callGraphqlApi(jsonStructure, githubToken); findAuthorCommits(jsonText, fileNamesWithDeletedLineNumbers, fileName); - System.out.println(); } catch (CodeQualityMetricsException e) { logger.error(e.getMessage(), e.getCause()); } @@ -246,9 +296,11 @@ public void getBlameDetails(String repoLocation, Map fileNamesWi * This is used to save the authors and relevant author commits of the buggy lines of code which are been fixed by * the given patch, to relevant lists. * - * @param jsonText String representation of the json response received from github graphql API + * @param jsonText String representation of the json response received from github graphql + * API * @param fileNamesWithDeletedLineNumbers map containing changed files with their deleted line numbers - * @param selectedFileName selected file for finding the authors and author commits of its buggy lines + * @param selectedFileName selected file for finding the authors and author commits of its buggy + * lines */ public void findAuthorCommits(String jsonText, Map> fileNamesWithDeletedLineNumbers, String selectedFileName) { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java index 9b793d6..56a26c4 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java @@ -72,19 +72,20 @@ public String callSearchCommitApi(String commitHash, String githubAccessToken) t /** * This is used to call github commit REST API + * * @param repoLocation * @param filePath * @param githubAccessToken * @return * @throws CodeQualityMetricsException */ - public String callCommitHistoryApi(String repoLocation,String filePath,String githubAccessToken) + public String callCommitHistoryApi(String repoLocation, String filePath, String githubAccessToken) throws CodeQualityMetricsException { try { defaultProperties.load(inputStream); - String tempUrl= defaultProperties.getProperty("commitHistoryApiUrl"); - String url=tempUrl.replaceFirst("REPO_LOCATION",repoLocation).replaceFirst("FILE_NAME",filePath); - httpGet= new HttpGet(url); + String tempUrl = defaultProperties.getProperty("commitHistoryApiUrl"); + String url = tempUrl.replaceFirst("REPO_LOCATION", repoLocation).replaceFirst("FILE_NAME", filePath); + httpGet = new HttpGet(url); httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); } catch (IllegalArgumentException e) { throw new CodeQualityMetricsException("The url provided for accessing the Github Search Commit API is " + @@ -96,6 +97,32 @@ public String callCommitHistoryApi(String repoLocation,String filePath,String gi return ApiUtility.callApi(httpGet); } + /** + * This is used to call github single commit REST API + * @param repoLocation + * @param commitHash + * @param githubAccessToken + * @return + */ + public String callSingleCommitApi(String repoLocation, String commitHash, String githubAccessToken) + throws CodeQualityMetricsException { + try { + defaultProperties.load(inputStream); + String tempUrl = defaultProperties.getProperty("singleCommitApiUrl"); + String url = tempUrl.replaceFirst("REPO_LOCATION", repoLocation).replaceFirst("COMMIT_HASH", commitHash); + httpGet = new HttpGet(url); + httpGet.addHeader(AUTHORIZATION, BEARER + githubAccessToken); + } catch (IllegalArgumentException e) { + throw new CodeQualityMetricsException("The url provided for accessing the Github Search Commit API is " + + "invalid ", e); + } catch (IOException e) { + throw new CodeQualityMetricsException("IO exception occurred when loading the inputstream to the " + + "properties object", e); + } + return ApiUtility.callApi(httpGet); + + } + /** * This is used to call the github review API. * diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java index 92c3eef..3a7c503 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java @@ -70,10 +70,10 @@ public Map getFilesChanged(String repositoryName, String commitH // this can be run parallely as patchString of a file will always be with the same file filesChanged.parallelStream() .forEach(commitFile -> { - fileNamesAndPatches.put(commitFile.getFilename(),commitFile.getPatch()); + fileNamesAndPatches.put(commitFile.getFilename(), commitFile.getPatch()); }); if (logger.isDebugEnabled()) { - logger.debug("for commit hash" + commitHash + " on the " + repositoryName + " repository, files" + + logger.debug("for commit hash " + commitHash + " on the " + repositoryName + " repository, files" + " changed and their relevant patch strings are saved to the map successfully"); } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ParentCommit.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ParentCommit.java new file mode 100644 index 0000000..73a3557 --- /dev/null +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ParentCommit.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.metrics.model; + +import com.google.gson.annotations.SerializedName; + +/** + * Pojo class used for parsing JSON response received from github single commit REST API. + * + * @since 1.0.0 + */ +public class ParentCommit { + @SerializedName("sha") + private String commitHash; + + public String getCommitHash() { + return commitHash; + } + + public void setCommitHash(String commitHash) { + this.commitHash = commitHash; + } +} diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SingleCommitApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SingleCommitApiResponse.java new file mode 100644 index 0000000..63782c0 --- /dev/null +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SingleCommitApiResponse.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.metrics.model; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +/** + * Pojo class used for parsing JSON response received from github single commit REST API. + * + * @since 1.0.0 + */ +public class SingleCommitApiResponse { + @SerializedName("parents") + private List parentCommits; + + public List getParentCommits() { + return parentCommits; + } + + public void setParentCommits(List parentCommits) { + this.parentCommits = parentCommits; + } +} diff --git a/org.wso2.codequalitymatrices/src/main/resources/url.properties b/org.wso2.codequalitymatrices/src/main/resources/url.properties index a948015..e622b92 100644 --- a/org.wso2.codequalitymatrices/src/main/resources/url.properties +++ b/org.wso2.codequalitymatrices/src/main/resources/url.properties @@ -25,3 +25,4 @@ githubGraphqlUrl=https://api.github.com/graphql githubGraphqlUrlHeader=application/json reviewApiUrl=https://api.github.com/repos/REPO_LOCATION/pulls/PULL_REQUEST_NUMBER/reviews reviewApiUrlHeader=application/vnd.github.black-cat-preview+json +singleCommitApiUrl=https://api.github.com/repos/REPO_LOCATION/commits/COMMIT_HASH diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java index d6a0084..2105004 100644 --- a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java @@ -18,19 +18,5 @@ package com.wso2.code.quality.metrics; -import org.hamcrest.collection.IsEmptyCollection; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.hasSize; - public class GithubSdkClientTest { } From 66e61245cc3a38bb5e74fe0b78ba8013d590f709 Mon Sep 17 00:00:00 2001 From: kasun Date: Tue, 18 Apr 2017 18:23:53 +0530 Subject: [PATCH 58/62] Add testcases for new approach --- org.wso2.codequalitymatrices/pom.xml | 6 + .../code/quality/metrics/ChangesFinder.java | 106 ++++++-------- .../metrics/CodeQualityMetricsExecutor.java | 2 +- .../code/quality/metrics/GithubApiCaller.java | 19 +-- .../code/quality/metrics/ReviewAnalyser.java | 15 +- .../code/quality/metrics/SdkGitHubClient.java | 12 +- .../code/quality/metrics/model/Author.java | 2 - .../model/CommitHistoryApiResponse.java | 2 - .../quality/metrics/ChangesFinderTest.java | 97 ++++++++++++ .../CodeQualityMetricsExecutorTest.java | 40 ++--- .../quality/metrics/GithubResponsesTest.java | 24 +-- .../quality/metrics/GithubSdkClientTest.java | 37 +++++ .../com/wso2/code/quality/metrics/Token.java | 42 ++++++ .../resources/patchStrings/patchString1.txt | 138 ++++++++++++++++++ .../resources/patchStrings/patchString2.txt | 29 ++++ 15 files changed, 441 insertions(+), 130 deletions(-) create mode 100644 org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java create mode 100644 org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/Token.java create mode 100644 org.wso2.codequalitymatrices/src/test/resources/patchStrings/patchString1.txt create mode 100644 org.wso2.codequalitymatrices/src/test/resources/patchStrings/patchString2.txt diff --git a/org.wso2.codequalitymatrices/pom.xml b/org.wso2.codequalitymatrices/pom.xml index 84b3401..aa97456 100644 --- a/org.wso2.codequalitymatrices/pom.xml +++ b/org.wso2.codequalitymatrices/pom.xml @@ -46,6 +46,7 @@ 4.5.2 3.5 1.3 + 2.4 @@ -102,6 +103,11 @@ commons-lang3 ${org.apache.commons.version} + + org.apache.directory.studio + org.apache.commons.io + ${org.apache.directory.studio.version} + diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java index 8dbe357..abf3ed2 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java @@ -71,7 +71,7 @@ private static class ListType extends TypeToken> * @param commitHashes List of commits that belongs to the given patch * @return author commits of the bug lines which are fixed from the given patch */ - protected Set obtainRepoNamesForCommitHashes(String gitHubToken, List commitHashes) { + Set obtainRepoNamesForCommitHashes(String gitHubToken, List commitHashes) { commitHashes.forEach(commitHash -> { try { String jsonText = githubApiCaller.callSearchCommitApi(commitHash, gitHubToken); @@ -89,9 +89,9 @@ protected Set obtainRepoNamesForCommitHashes(String gitHubToken, List saveRepoNames(String jsonText) throws CodeQualityMetricsException { + List saveRepoNames(String jsonText) throws CodeQualityMetricsException { List repoLocation = new ArrayList<>(); SearchApiResponse searchCommitPojo; try { @@ -118,7 +118,7 @@ private void identifyChangedFile(List repoLocation, String commitHash, S repoLocation.stream() .filter(repositoryName -> StringUtils.contains(repositoryName, "wso2/")) .forEach(repositoryName -> { - Map fileNamesWithPatchString = new HashMap<>(); + Map fileNamesWithPatchString; try { fileNamesWithPatchString = sdkGitHubClient.getFilesChanged(repositoryName, commitHash); Map> fileNamesWithDeletedLineNumbers = new HashMap<>(); @@ -161,39 +161,35 @@ private void identifyChangedFile(List repoLocation, String commitHash, S * @param latestCommitHash current selected recent commit contained in the given patch * @param githubToken github access token for accessing github REST API * @return the commit hash returned from findPreviousCommitOfFile method - * @throws CodeQualityMetricsException notifying that the current scope of the program does not support octopuss - * merges */ - public String checkForOctopussMerge(String repositoryName, String filePath, String latestCommitHash, String - githubToken) throws CodeQualityMetricsException { + private String checkForOctopussMerge(String repositoryName, String filePath, String latestCommitHash, String + githubToken) { String previousCommit = null; try { // need check whether the given commit has more than 2 parent commits String singleCommitJsonText = githubApiCaller.callSingleCommitApi(repositoryName, latestCommitHash, githubToken); - if (singleCommitJsonText != null) { - SingleCommitApiResponse singleCommitApiResponse = gson.fromJson(singleCommitJsonText, - SingleCommitApiResponse.class); - if (singleCommitApiResponse.getParentCommits().size() == 1) { + SingleCommitApiResponse singleCommitApiResponse = gson.fromJson(singleCommitJsonText, + SingleCommitApiResponse.class); + if (singleCommitApiResponse.getParentCommits().size() == 1) { /*if the singleCommitApiResponse.getParentCommits().size() == 1 it is fast forward merge, so no need to change the latestCommitHash*/ - if (logger.isDebugEnabled()) { - logger.debug("The commit " + latestCommitHash + " in relevant patch is not a octopuss merge " + - "commit"); - } - } else if (singleCommitApiResponse.getParentCommits().size() == 2) { - latestCommitHash = singleCommitApiResponse.getParentCommits().get(1).getCommitHash(); - if (logger.isDebugEnabled()) { - logger.debug("The commit " + latestCommitHash + " in relevant patch is not a octopuss merge " + - "commit"); - } - } else if (singleCommitApiResponse.getParentCommits().size() > 2) { - throw new CodeQualityMetricsException("The commit " + latestCommitHash + " in relevant patch is " + - "an octopuss merge commit, octopuss merge commits are avoided in the current scope of " + - "the program"); + if (logger.isDebugEnabled()) { + logger.debug("The commit " + latestCommitHash + " in relevant patch is not a octopuss merge " + + "commit"); } - previousCommit = findPreviousCommitOfFile(repositoryName, filePath, latestCommitHash, githubToken); + } else if (singleCommitApiResponse.getParentCommits().size() == 2) { + latestCommitHash = singleCommitApiResponse.getParentCommits().get(1).getCommitHash(); + if (logger.isDebugEnabled()) { + logger.debug("The commit " + latestCommitHash + " in relevant patch is not a octopuss merge " + + "commit"); + } + } else if (singleCommitApiResponse.getParentCommits().size() > 2) { + throw new CodeQualityMetricsException("The commit " + latestCommitHash + " in relevant patch is " + + "an octopuss merge commit, octopuss merge commits are avoided in the current scope of " + + "the program"); } + previousCommit = findPreviousCommitOfFile(repositoryName, filePath, latestCommitHash, githubToken); } catch (CodeQualityMetricsException e) { logger.error(e.getMessage(), e.getCause()); } @@ -211,35 +207,30 @@ public String checkForOctopussMerge(String repositoryName, String filePath, Stri * @return commits hash prior to the current selected commit hash contained in the given patch of the current * selected file */ - public String findPreviousCommitOfFile(String repositoryName, String filePath, String latestCommitHash, - String githubToken) { + private String findPreviousCommitOfFile(String repositoryName, String filePath, String latestCommitHash, + String githubToken) { String previousCommit = null; Map commitWithDate = new HashMap<>(); try { String commitHistoryJsonText = githubApiCaller.callCommitHistoryApi(repositoryName, filePath, githubToken); - if (commitHistoryJsonText != null) { - Type listType = new ListType().getType(); - List commitHistoryApiResponses = gson.fromJson(commitHistoryJsonText, - listType); - commitHistoryApiResponses.forEach(commitHistoryApiResponse -> { - String commitHash = commitHistoryApiResponse.getCommitHash(); - String date = commitHistoryApiResponse.getCommit().getAuthor().getDate(); - commitWithDate.put(commitHash, date); - }); - String latestCommitDate = commitWithDate.get(latestCommitHash); - String previousCommitDate = getPreviousCommitDate(commitWithDate, latestCommitDate); - // looping for finding the commit Hash introduced in previous commit date - for (Map.Entry entry : commitWithDate.entrySet()) { - if (entry.getValue().equals(previousCommitDate)) { - previousCommit = (String) entry.getKey(); - } - } - } else { - if (logger.isDebugEnabled()) { - logger.debug("There are no commit history records for the file " + filePath + " on repository " + - "" + repositoryName); + + Type listType = new ListType().getType(); + List commitHistoryApiResponses = gson.fromJson(commitHistoryJsonText, + listType); + commitHistoryApiResponses.forEach(commitHistoryApiResponse -> { + String commitHash = commitHistoryApiResponse.getCommitHash(); + String date = commitHistoryApiResponse.getCommit().getAuthor().getDate(); + commitWithDate.put(commitHash, date); + }); + String latestCommitDate = commitWithDate.get(latestCommitHash); + String previousCommitDate = getPreviousCommitDate(commitWithDate, latestCommitDate); + // looping for finding the commit Hash introduced in previous commit date + for (Map.Entry entry : commitWithDate.entrySet()) { + if (entry.getValue().equals(previousCommitDate)) { + previousCommit = (String) entry.getKey(); } } + } catch (CodeQualityMetricsException e) { logger.error(e.getMessage(), e.getCause()); } @@ -254,13 +245,12 @@ public String findPreviousCommitOfFile(String repositoryName, String filePath, S * @param latestCommitDate latest commit date of the current selected file * @return previous commit date of the current selected file */ - public String getPreviousCommitDate(Map commitWithDate, String latestCommitDate) { + private String getPreviousCommitDate(Map commitWithDate, String latestCommitDate) { //creating a tempory list for sorting the date in ascending order List sortedCommitDates = new ArrayList<>(commitWithDate.values()); Collections.sort(sortedCommitDates); int indexOfLatestcommit = sortedCommitDates.indexOf(latestCommitDate); - String previousCommitDateOfFile = sortedCommitDates.get(--indexOfLatestcommit); - return previousCommitDateOfFile; + return sortedCommitDates.get(--indexOfLatestcommit); } /** @@ -271,8 +261,8 @@ public String getPreviousCommitDate(Map commitWithDate, String l * @param fileNamesWithDeletedLineNumbers map containing changed files with their deleted line numbers * @param githubToken github access token for accessing github REST API */ - public void getBlameDetails(String repoLocation, Map fileNamesWithPreviousCommitHash, - Map> fileNamesWithDeletedLineNumbers, String githubToken) { + private void getBlameDetails(String repoLocation, Map fileNamesWithPreviousCommitHash, + Map> fileNamesWithDeletedLineNumbers, String githubToken) { // filtering the owner and the repository name from the repoLocation String owner = StringUtils.substringBefore(repoLocation, "/"); @@ -281,7 +271,7 @@ public void getBlameDetails(String repoLocation, Map fileNamesWi fileNamesWithPreviousCommitHash.forEach((fileName, previousCommitHash) -> { graphqlBean.setGraphqlInputWithoutHistory(owner, repositoryName, previousCommitHash, fileName); jsonStructure.put("query", graphqlBean.getGraphqlInputWithoutHistory()); - String jsonText = null; + String jsonText; try { // calling the graphql API for getting blame information for the current file. jsonText = githubApiCaller.callGraphqlApi(jsonStructure, githubToken); @@ -302,7 +292,7 @@ public void getBlameDetails(String repoLocation, Map fileNamesWi * @param selectedFileName selected file for finding the authors and author commits of its buggy * lines */ - public void findAuthorCommits(String jsonText, Map> fileNamesWithDeletedLineNumbers, String + private void findAuthorCommits(String jsonText, Map> fileNamesWithDeletedLineNumbers, String selectedFileName) { GraphQlResponse graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); @@ -327,7 +317,7 @@ public void findAuthorCommits(String jsonText, Map> fileNam * @param patchString patch string of the selected file received from github SDK * @return a Set of deleted lines in the above mentioned file */ - private Set identifyDeletedLines(String patchString) { + Set identifyDeletedLines(String patchString) { Set linesDeletedInSelectedFile = new HashSet<>(); Pattern pattern = Pattern.compile("@@ -"); String patches[] = pattern.split(patchString); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java index 9a76d0d..fcf5b09 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java @@ -75,7 +75,7 @@ public void execute() { * * @return List of commithashes contained in the given patch */ - protected List findCommitHashesInPatch() throws CodeQualityMetricsException { + List findCommitHashesInPatch() throws CodeQualityMetricsException { PmtApiCaller pmtApiCaller = new PmtApiCaller(); String jsonText; List commitHashes = new ArrayList<>(); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java index 56a26c4..f11376b 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java @@ -73,11 +73,11 @@ public String callSearchCommitApi(String commitHash, String githubAccessToken) t /** * This is used to call github commit REST API * - * @param repoLocation - * @param filePath - * @param githubAccessToken - * @return - * @throws CodeQualityMetricsException + * @param repoLocation repository location + * @param filePath location of the file + * @param githubAccessToken Github access token for accessing github API + * @return String representation of the json response + * @throws CodeQualityMetricsException Resulted Code Quality Metrics Exception */ public String callCommitHistoryApi(String repoLocation, String filePath, String githubAccessToken) throws CodeQualityMetricsException { @@ -99,10 +99,11 @@ public String callCommitHistoryApi(String repoLocation, String filePath, String /** * This is used to call github single commit REST API - * @param repoLocation - * @param commitHash - * @param githubAccessToken - * @return + * + * @param repoLocation repository location + * @param commitHash relevant commit hash to find details of + * @param githubAccessToken Github access token for accessing github API + * @return String representation of the json response */ public String callSingleCommitApi(String repoLocation, String commitHash, String githubAccessToken) throws CodeQualityMetricsException { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java index 124615e..5c3ab5c 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java @@ -47,9 +47,9 @@ public class ReviewAnalyser { private static final Logger logger = Logger.getLogger(ReviewAnalyser.class); // to store the reviewed and approved users of thepull requests - protected final Set approvedReviewers = new HashSet<>(); + final Set approvedReviewers = new HashSet<>(); // to store the reviewed and commented users of the pull requests - protected final Set commentedReviewers = new HashSet<>(); + final Set commentedReviewers = new HashSet<>(); //constants for filtering github API responses private final GithubApiCaller githubApiCaller = new GithubApiCaller(); private final Gson gson = new Gson(); @@ -62,7 +62,6 @@ private static class ListType extends TypeToken> { } - /** * This is used to identify the pull requests that introduce the given commit to the code base. * @@ -93,7 +92,7 @@ public void findReviewers(Set authorCommits, String githubToken) { * @return a map of pull requests againt their repository name * @throws CodeQualityMetricsException results */ - protected Map> savePrNumberAndRepoName(String jsonText) throws CodeQualityMetricsException { + Map> savePrNumberAndRepoName(String jsonText) throws CodeQualityMetricsException { // map for storing the pull requests numbers against their Repository Map> prNoWithRepoName = new HashMap<>(); try { @@ -126,7 +125,7 @@ protected Map> savePrNumberAndRepoName(String jsonText) thr * relevant reposiory * @param githubToken Github access token for accessing github API */ - protected void saveReviewers(Map> prNoWithRepoName, String githubToken) { + void saveReviewers(Map> prNoWithRepoName, String githubToken) { for (Map.Entry> entry : prNoWithRepoName.entrySet()) { String repositoryName = entry.getKey(); Set prNumbers = entry.getValue(); @@ -153,10 +152,8 @@ protected void saveReviewers(Map> prNoWithRepoName, String logger.debug("Users who commented on the pull requests which introduce bug lines to " + "the code base are successfully saved to approvedReviewers list"); } else { - if (logger.isDebugEnabled()) { - logger.debug("There are no records of reviews for pull request: " + prNumber + - " on " + repositoryName + " repository"); - } + logger.warn("There are no records of reviews for pull request: " + prNumber + + " on " + repositoryName + " repository"); } } catch (CodeQualityMetricsException e) { logger.error(e.getMessage(), e.getCause()); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java index 3a7c503..1ea0956 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java @@ -24,7 +24,6 @@ import org.eclipse.egit.github.core.RepositoryCommit; import org.eclipse.egit.github.core.client.GitHubClient; import org.eclipse.egit.github.core.service.CommitService; -import org.eclipse.egit.github.core.service.RepositoryService; import java.io.IOException; import java.util.HashMap; @@ -40,15 +39,12 @@ public class SdkGitHubClient { private static final Logger logger = Logger.getLogger(SdkGitHubClient.class); - private GitHubClient gitHubClient = null; private CommitService commitService = null; - private RepositoryService repositoryService = null; SdkGitHubClient(String githubToken) { - gitHubClient = new GitHubClient(); + GitHubClient gitHubClient = new GitHubClient(); gitHubClient.setOAuth2Token(githubToken); commitService = new CommitService(gitHubClient); - repositoryService = new RepositoryService(gitHubClient); } /** @@ -66,17 +62,13 @@ public Map getFilesChanged(String repositoryName, String commitH IRepositoryIdProvider iRepositoryIdProvider = () -> repositoryName; RepositoryCommit repositoryCommit = commitService.getCommit(iRepositoryIdProvider, commitHash); List filesChanged = repositoryCommit.getFiles(); - // this can be run parallely as patchString of a file will always be with the same file filesChanged.parallelStream() - .forEach(commitFile -> { - fileNamesAndPatches.put(commitFile.getFilename(), commitFile.getPatch()); - }); + .forEach(commitFile -> fileNamesAndPatches.put(commitFile.getFilename(), commitFile.getPatch())); if (logger.isDebugEnabled()) { logger.debug("for commit hash " + commitHash + " on the " + repositoryName + " repository, files" + " changed and their relevant patch strings are saved to the map successfully"); } - } catch (IOException e) { throw new CodeQualityMetricsException("IO Exception occurred when getting the commit of given SHA from " + "the given Repository ", e); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Author.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Author.java index 93d866b..3fcd3a8 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Author.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Author.java @@ -38,6 +38,4 @@ public String getDate() { public void setDate(String date) { this.date = date; } - - } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java index 102edb5..1e7bd7e 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java @@ -48,6 +48,4 @@ public Commit getCommit() { public void setCommit(Commit commit) { this.commit = commit; } - - } diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java new file mode 100644 index 0000000..c5aa134 --- /dev/null +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.metrics; + +import org.apache.commons.io.IOUtils; +import org.apache.log4j.Logger; +import org.junit.Test; + +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertTrue; + +/** + * A class used to test identifyChangedFile method of the ChangeFinder class + * + * @since 1.0.0 + */ +public class ChangesFinderTest { + private static final Logger logger = Logger.getLogger(ChangesFinderTest.class); + + @Test + public void testIdentifyDeletedLines() { + String patchString; + Set actualDeltedLinesForPatchString; + ChangesFinder changesFinder = new ChangesFinder(); + patchString = readFile("patchStrings/patchString1.txt"); + actualDeltedLinesForPatchString = changesFinder.identifyDeletedLines(patchString); + Set expectedDeltedLinesForPatchString1 = new HashSet<>(); + expectedDeltedLinesForPatchString1.add(822); + expectedDeltedLinesForPatchString1.add(823); + expectedDeltedLinesForPatchString1.add(824); + expectedDeltedLinesForPatchString1.add(907); + expectedDeltedLinesForPatchString1.add(908); + expectedDeltedLinesForPatchString1.add(909); + expectedDeltedLinesForPatchString1.add(1081); + expectedDeltedLinesForPatchString1.add(1082); + expectedDeltedLinesForPatchString1.add(1083); + expectedDeltedLinesForPatchString1.add(1087); + expectedDeltedLinesForPatchString1.add(1094); + expectedDeltedLinesForPatchString1.add(1143); + expectedDeltedLinesForPatchString1.add(1144); + expectedDeltedLinesForPatchString1.add(1145); + expectedDeltedLinesForPatchString1.add(1146); + expectedDeltedLinesForPatchString1.add(1147); + expectedDeltedLinesForPatchString1.add(1148); + expectedDeltedLinesForPatchString1.add(1149); + expectedDeltedLinesForPatchString1.add(1150); + expectedDeltedLinesForPatchString1.add(1151); + expectedDeltedLinesForPatchString1.add(1152); + expectedDeltedLinesForPatchString1.add(1153); + expectedDeltedLinesForPatchString1.add(1165); + + assertThat(actualDeltedLinesForPatchString.size(), is(expectedDeltedLinesForPatchString1.size())); + assertThat(actualDeltedLinesForPatchString, is(expectedDeltedLinesForPatchString1)); + + patchString = readFile("patchStrings/patchString2.txt"); + actualDeltedLinesForPatchString = changesFinder.identifyDeletedLines(patchString); + assertTrue(actualDeltedLinesForPatchString.isEmpty()); + } + + /** + * This is used to get the contents of the txt file as a single String + * + * @param path location path to the relevant txt file + * @return single String containing all the contents of the given file + */ + private String readFile(String path) { + String result = ""; + ClassLoader classLoader = getClass().getClassLoader(); + try { + result = IOUtils.toString(classLoader.getResourceAsStream(path)); + } catch (IOException e) { + logger.debug(e.getMessage(), e.getCause()); + } + return result; + } +} diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java index d44f251..aa9d12c 100644 --- a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java @@ -19,50 +19,34 @@ package com.wso2.code.quality.metrics; -import org.apache.log4j.Logger; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import java.io.File; -import java.io.IOException; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - +/** + * A class used to test findCommitHashesInPatch method of the CodeQualityMetricsExecutor class + * + * @since 1.0.0 + */ public class CodeQualityMetricsExecutorTest { - private static final Logger logger = Logger.getLogger(CodeQualityMetricsExecutorTest.class); - - private String pmtToken = "tQU5vxzrGeBpLMQuwOsJW_fyYLYa"; - private String githubToken = "4e8e69986aefdbae2f5fe59d892cd3badf771191"; - private final GithubApiCaller githubApiCaller = new GithubApiCaller(); - - private Set authorCommits; - - @Rule - public TemporaryFolder folder = new TemporaryFolder(); - - @Test - public void testUsingTempFolder() throws IOException { - File createdFile = folder.newFile("myfilefile.txt"); - assertTrue(createdFile.canRead()); - } @Test public void testFindCommitHashesInPatch() throws CodeQualityMetricsException { + String pmtToken = new Token().getPmtToken(); + String githubToken = new Token().getGithubToken(); Map> patchesAndCommits = new HashMap<>(); patchesAndCommits.put("WSO2-CARBON-PATCH-4.4.0-0680", Arrays.asList("eaa45529cbabc5f30a2ffaa4781821ad0a5223ab" , "2b1d973d089ebc3af3b9e7b893f48cf905758cf4")); - patchesAndCommits.put("WSO2-CARBON-PATCH-4.4.0-0682", Arrays.asList("e3c3457149b109178d510aac965d5a85cc465aa0") - ); - patchesAndCommits.put("WSO2-CARBON-PATCH-4.4.0-0692", Arrays.asList - ("67a60e081c8e0fe01d087f60cd9b629bcea172ae")); + patchesAndCommits.put("WSO2-CARBON-PATCH-4.4.0-0682", + Collections.singletonList("e3c3457149b109178d510aac965d5a85cc465aa0")); + patchesAndCommits.put("WSO2-CARBON-PATCH-4.4.0-0692", + Collections.singletonList("67a60e081c8e0fe01d087f60cd9b629bcea172ae")); for (Map.Entry> map : patchesAndCommits.entrySet()) { CodeQualityMetricsExecutor codeQualityMetricsExecutor = new CodeQualityMetricsExecutor(pmtToken, map.getKey(), githubToken); diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java index c673003..8dfcab8 100644 --- a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java @@ -19,10 +19,8 @@ package com.wso2.code.quality.metrics; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -35,25 +33,30 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.Assert.assertEquals; +/** + * A class used to test saveRepoNames,savePrNumberAndRepoName and saveReviewers methods of the GithubResponses class + * + * @since 1.0.0 + */ public class GithubResponsesTest { private static String githubToken; private static GithubApiCaller githubApiCaller; @BeforeClass public static void setupTheEnvironment() { - githubToken = "4e8e69986aefdbae2f5fe59d892cd3badf771191"; + githubToken = new Token().getGithubToken(); githubApiCaller = new GithubApiCaller(); - } @Test -// @Ignore public void testSaveRepoNames() throws CodeQualityMetricsException { Map> commitHashWithRepoNames = new HashMap<>(); - commitHashWithRepoNames.put("eaa45529cbabc5f30a2ffaa4781821ad0a5223ab", Arrays.asList("wso2/carbon-apimgt")); - commitHashWithRepoNames.put("2b1d973d089ebc3af3b9e7b893f48cf905758cf4", Arrays.asList("wso2/carbon-apimgt")); + commitHashWithRepoNames.put("eaa45529cbabc5f30a2ffaa4781821ad0a5223ab", + Collections.singletonList("wso2/carbon-apimgt")); + commitHashWithRepoNames.put("2b1d973d089ebc3af3b9e7b893f48cf905758cf4", + Collections.singletonList("wso2/carbon-apimgt")); commitHashWithRepoNames.put("e3c3457149b109178d510aac965d5a85cc465aa0", - Arrays.asList("wso2/wso2-axis2-transports")); + Collections.singletonList("wso2/wso2-axis2-transports")); for (Map.Entry> entry : commitHashWithRepoNames.entrySet()) { String commitHash = entry.getKey(); String jsonText = githubApiCaller.callSearchCommitApi(commitHash, githubToken); @@ -64,7 +67,6 @@ public void testSaveRepoNames() throws CodeQualityMetricsException { } @Test - @Ignore public void testSavePrNumberAndRepoName() throws CodeQualityMetricsException { String jsonText = githubApiCaller.callSearchIssueApi ("0015c02145c8ec6d3bba433f2fb5e850e1d25846", githubToken); @@ -101,8 +103,8 @@ public void testSaveReviewers() { Set prNumberSet2 = new HashSet<>(); prNumberSet2.add(885); prNoWithRepoName2.put("wso2/product-is", prNumberSet2); - List expectedApprovedReviewers2 = Arrays.asList("darshanasbg"); - List expectedCommentedReviewers2 = Arrays.asList("isharak"); + List expectedApprovedReviewers2 = Collections.singletonList("darshanasbg"); + List expectedCommentedReviewers2 = Collections.singletonList("isharak"); reviewAnalyser.saveReviewers(prNoWithRepoName2, githubToken); assertThat("List of approved users ", reviewAnalyser.approvedReviewers, containsInAnyOrder(expectedApprovedReviewers2.toArray())); diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java index 2105004..8aa384d 100644 --- a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java @@ -18,5 +18,42 @@ package com.wso2.code.quality.metrics; +import org.hamcrest.collection.IsMapContaining; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.Map; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + + +/** + * A class used to getFilesChanged method of the GithubSdkClient class + * + * @since 1.0.0 + */ public class GithubSdkClientTest { + private static SdkGitHubClient sdkGitHubClient; + + @BeforeClass + public static void setupTheEnvironment() throws CodeQualityMetricsException { + String githubToken = new Token().getGithubToken(); + sdkGitHubClient = new SdkGitHubClient(githubToken); + } + + @Test + public void testGetFilesChanged() throws CodeQualityMetricsException { + Map actualFileNamesAndPatches = sdkGitHubClient.getFilesChanged + ("wso2/carbon-apimgt", "eaa45529cbabc5f30a2ffaa4781821ad0a5223ab"); + assertThat(actualFileNamesAndPatches.size(), is(4)); + assertThat(actualFileNamesAndPatches, IsMapContaining.hasKey("components/sso-hostobject/org.wso2.carbon" + + ".hostobjects.sso/src/main/java/org/wso2/carbon/hostobjects/sso/SAMLSSORelyingPartyObject.java")); + assertThat(actualFileNamesAndPatches, IsMapContaining.hasKey("components/sso-hostobject/org.wso2.carbon." + + "hostobjects.sso/src/main/java/org/wso2/carbon/hostobjects/sso/internal/SessionInfo.java")); + assertThat(actualFileNamesAndPatches, IsMapContaining.hasKey("features/apimgt/org.wso2.carbon.apimgt." + + "publisher.feature/src/main/resources/publisher/site/themes/wso2/templates/sso/logout/template.jag")); + assertThat(actualFileNamesAndPatches, IsMapContaining.hasKey("features/apimgt/org.wso2.carbon.apimgt." + + "store.feature/src/main/resources/store/site/themes/wso2/templates/sso/logout/template.jag")); + } } diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/Token.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/Token.java new file mode 100644 index 0000000..f503ae1 --- /dev/null +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/Token.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.wso2.code.quality.metrics; + +import java.nio.charset.StandardCharsets; +import java.util.Base64; + +/** + * This class is used for providing github and WSO2 PMT access tokens + * + * @since 1.0.0 + */ +public class Token { + final String pmtToken = "tQU5vxzrGeBpLMQuwOsJW_fyYLYa"; + final byte[] githubTokenByteArray = Base64.getDecoder().decode + ("ZjQxZTcwOTJmY2I1NTZmZTI2YzFlMDgwYjFjNDQ3NWRhYTZmN2MyNw"); + final String githubToken = new String(githubTokenByteArray, StandardCharsets.UTF_8); + + public String getPmtToken() { + return pmtToken; + } + + public String getGithubToken() { + return githubToken; + } +} diff --git a/org.wso2.codequalitymatrices/src/test/resources/patchStrings/patchString1.txt b/org.wso2.codequalitymatrices/src/test/resources/patchStrings/patchString1.txt new file mode 100644 index 0000000..67ca085 --- /dev/null +++ b/org.wso2.codequalitymatrices/src/test/resources/patchStrings/patchString1.txt @@ -0,0 +1,138 @@ +@@ -819,9 +819,11 @@ public static void jsFunction_invalidateSessionBySessionId(Context cx, Scriptabl + SAMLSSORelyingPartyObject relyingPartyObject = (SAMLSSORelyingPartyObject) thisObj; + String sessionId = (String) args[0]; + String sessionIndex = relyingPartyObject.getSessionIndex(sessionId); +- relyingPartyObject.handleLogout(sessionIndex); +- +- ++ if (sessionIndex != null) { ++ relyingPartyObject.handleLogout(sessionIndex); ++ } else { ++ relyingPartyObject.handleLogoutBySessionId(sessionId); ++ } + } + + /** +@@ -901,12 +903,14 @@ public static void jsFunction_setSessionAuthenticated(Context cx, Scriptable thi + log.debug("Encoded SAML token that is set on session info is " + args[1]); + } + sessionInfo.setSamlToken((String) args[1]);//We expect an encoded SamlToken here. ++ SessionHostObject sho = (SessionHostObject) args[2]; ++ sessionInfo.setSessionHostObject(sho); + relyingPartyObject.addSessionInfo(sessionInfo); + //relyingPartyObject.addSessionInfo(sessionIndex, SAMLSSORelyingPartyObject.sho); + +- SessionHostObject sho = (SessionHostObject) args[2]; +- relyingPartyObject.addSessionInfo(sessionIndex, sho); +- ++ if (sessionIndex != null) { ++ relyingPartyObject.addSessionToSessionIndexMap(sessionIndex, sho); ++ } + } + + /** +@@ -1078,21 +1082,26 @@ private void invalidateSessionBySessionId(String sessionId) { + } + + private boolean isSessionIdExists(String sessionId) throws Exception { +- Iterator>> iterator = sessionIndexMap.entrySet().iterator(); +- while (iterator.hasNext()) { +- Map.Entry> entry = iterator.next(); ++ for (Map.Entry> entry : sessionIndexMap.entrySet()) { + Set sessions = new HashSet(entry.getValue()); + for (SessionHostObject session : sessions) { + Object[] args = new Object[0]; +- if (session != null && sessionId.equals(SessionHostObject.jsFunction_getId(null, session, args, null))) { ++ if (session != null && sessionId ++ .equals(SessionHostObject.jsFunction_getId(null, session, args, null))) { + if (log.isDebugEnabled()) { + log.debug("Session Id exists:" + SessionHostObject.jsFunction_getId(null, session, args, null)); + } + return true; + } + } +- //} + } ++ log.debug("Session Id does not exist in sessionIndexMap. Now searching in sessionIdMap."); ++ if (getSessionInfo(sessionId) != null) { ++ log.debug("Session Id exists in sessionIdMap : " + sessionId); ++ return true; ++ } ++ ++ log.debug("Session Id does not exist in sessionIdMap : " + sessionId); + return false; + } + +@@ -1140,17 +1149,7 @@ private static String getSSOSamlDeflateProperty(SAMLSSORelyingPartyObject relyin + } + } + +- /** +- * Add current browser session with session index. +- */ +- private void addSessionInfo(String sessionIndex, Set sho) { +- if (log.isDebugEnabled()) { +- log.debug("Added session index:" + sessionIndex); +- } +- sessionIndexMap.put(sessionIndex, sho); +- } +- +- private void addSessionInfo(String sessionIndex, SessionHostObject sho) { ++ private void addSessionToSessionIndexMap(String sessionIndex, SessionHostObject sho) { + if (log.isDebugEnabled()) { + log.debug("Added session index:" + sessionIndex); + } +@@ -1162,7 +1161,6 @@ private void addSessionInfo(String sessionIndex, SessionHostObject sho) { + sessionSet.add(sho); + sessionIndexMap.put(sessionIndex, sessionSet); + } +- + } + + /** +@@ -1276,6 +1274,14 @@ public void handleLogout(String sessionIndex) { + } + } + ++ public void handleLogoutBySessionId(String sessionId) { ++ clearSessionDataFromSessionId(sessionId); ++ ++ if (log.isDebugEnabled()) { ++ log.debug("Cleared authenticated session id:" + sessionId + "in handle logout method"); ++ } ++ } ++ + public void handleClusterLogout(String sessionIndex) { + if (log.isDebugEnabled()) { + log.debug("session index map value:" + sessionIndexMap); +@@ -1331,6 +1337,31 @@ private void clearSessionData(String sessionIndex) { + } + } + ++ private void clearSessionDataFromSessionId(String sessionIdToClear) { ++ SessionInfo sessionInfo = getSessionInfo(sessionIdToClear); ++ if (sessionInfo != null) { ++ SessionHostObject sessionHostObject = sessionInfo.getSessionHostObject(); ++ if (sessionHostObject != null) { ++ try { ++ Object[] args = new Object[0]; ++ SessionHostObject.jsFunction_invalidate(null, sessionHostObject, args, null); ++ } catch (Exception ex) { ++ //catches generic exception since we do not need to stop the ++ // process due to invalidating one single session ++ if (ex.getMessage().contains("Session already invalidated")) { // can be ignored ++ log.info(ex.getMessage()); ++ } else { ++ //log the error and continues since this does not brake the flow. ++ log.error("Error while invalidating the session " + sessionIdToClear, ex); ++ } ++ } ++ } ++ } ++ ssho.invalidateSessionBySessionId(sessionIdToClear); ++ if (log.isDebugEnabled()) { ++ log.debug("Cleared authenticated session index:" + sessionIdToClear + "in handle logout method"); ++ } ++ } + + public void sendSessionInvalidationClusterMessage(String sessionIndex) { diff --git a/org.wso2.codequalitymatrices/src/test/resources/patchStrings/patchString2.txt b/org.wso2.codequalitymatrices/src/test/resources/patchStrings/patchString2.txt new file mode 100644 index 0000000..52c64f6 --- /dev/null +++ b/org.wso2.codequalitymatrices/src/test/resources/patchStrings/patchString2.txt @@ -0,0 +1,29 @@ +@@ -16,11 +16,14 @@ + + package org.wso2.carbon.hostobjects.sso.internal; + ++import org.jaggeryjs.hostobjects.web.SessionHostObject; ++ + public class SessionInfo { + private String sessionId; + private String loggedInUser; + private String sessionIndex; + private String samlToken; ++ private SessionHostObject sessionHostObject; + + public SessionInfo(String sessionId) { + this.sessionId = sessionId; +@@ -57,4 +60,12 @@ public String getSamlToken() { + public void setSamlToken(String samlToken) { + this.samlToken = samlToken; + } ++ ++ public void setSessionHostObject(SessionHostObject sessionHostObject) { ++ this.sessionHostObject = sessionHostObject; ++ } ++ ++ public SessionHostObject getSessionHostObject() { ++ return sessionHostObject; ++ } + } +\ No newline at end of file \ No newline at end of file From 698c71ed0e32960930e00a53d3272028ab2d399a Mon Sep 17 00:00:00 2001 From: kasun Date: Wed, 19 Apr 2017 11:00:01 +0530 Subject: [PATCH 59/62] Changes asked in PR close resources with try with resources Seperate tokens to a property file Fix bug from history simplificatio If two commits in the history of a file cancel each other out (the changes are reversed), then Git detect this and simplifies the git log output of the file by leaving out those two commits. --- .../wso2/code/quality/metrics/ApiUtility.java | 98 +++++-------------- .../code/quality/metrics/Application.java | 30 ++++-- .../code/quality/metrics/ChangesFinder.java | 90 ++++++++++------- .../metrics/CodeQualityMetricsExecutor.java | 29 +++--- ...iCaller.java => GithubApiCallerUtils.java} | 50 ++++++---- .../code/quality/metrics/PmtApiCaller.java | 12 +-- .../code/quality/metrics/ReviewAnalyser.java | 25 ++--- .../code/quality/metrics/SdkGitHubClient.java | 3 +- .../CodeQualityMetricsException.java | 4 +- .../code/quality/metrics/model/Author.java | 1 - .../model/CommitHistoryApiResponse.java | 1 - .../code/quality/metrics/model/Constants.java | 2 +- .../code/quality/metrics/model/Graphql.java | 12 --- .../quality/metrics/model/GraphqlCommit.java | 11 +-- .../quality/metrics/model/GraphqlEdge.java | 39 -------- .../quality/metrics/model/GraphqlHistory.java | 41 -------- .../quality/metrics/model/GraphqlNode.java | 39 -------- .../quality/metrics/model/GraphqlRange.java | 3 + .../metrics/model/ReviewApiResponse.java | 2 +- .../quality/metrics/model/SearchItem.java | 12 ++- .../src/main/resources/log4j.properties | 6 -- .../src/main/resources/tokens.properties | 19 ++++ .../quality/metrics/ChangesFinderTest.java | 53 +++++++++- .../CodeQualityMetricsExecutorTest.java | 15 +++ .../quality/metrics/GithubResponsesTest.java | 9 +- .../quality/metrics/GithubSdkClientTest.java | 1 + .../com/wso2/code/quality/metrics/Token.java | 26 ++++- 27 files changed, 288 insertions(+), 345 deletions(-) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/{GithubApiCaller.java => GithubApiCallerUtils.java} (82%) rename org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/{ => exceptions}/CodeQualityMetricsException.java (88%) delete mode 100644 org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlEdge.java delete mode 100644 org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlHistory.java delete mode 100644 org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlNode.java create mode 100644 org.wso2.codequalitymatrices/src/main/resources/tokens.properties diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java index 5eb9057..83a6e18 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java @@ -18,6 +18,7 @@ package com.wso2.code.quality.metrics; +import com.wso2.code.quality.metrics.exceptions.CodeQualityMetricsException; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -52,55 +53,33 @@ private ApiUtility() { * @throws CodeQualityMetricsException results */ public static String callApi(HttpGet httpGet) throws CodeQualityMetricsException { - BufferedReader bufferedReader = null; - CloseableHttpClient httpClient; - CloseableHttpResponse httpResponse = null; - httpClient = HttpClients.createDefault(); String jsonText; - try { - httpResponse = httpClient.execute(httpGet); + try (CloseableHttpClient httpClient = HttpClients.createDefault(); + CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) { int responseCode = httpResponse.getStatusLine().getStatusCode(); if (responseCode == 200) { //success - bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), - StandardCharsets.UTF_8)); - StringBuilder stringBuilder = new StringBuilder(); - String line; - while ((line = bufferedReader.readLine()) != null) { - stringBuilder.append(line); + try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity() + .getContent(), StandardCharsets.UTF_8))) { + StringBuilder stringBuilder = new StringBuilder(); + String line; + while ((line = bufferedReader.readLine()) != null) { + stringBuilder.append(line); + } + // creating a JSON object from the response + jsonText = stringBuilder.toString(); } - // creating a JSON object from the response - jsonText = stringBuilder.toString(); } else { throw new CodeQualityMetricsException("Error occurred while calling the API, the response code is " + responseCode); } } catch (ClientProtocolException e) { throw new CodeQualityMetricsException("ClientProtocolException when calling the REST API", e); + } catch (NullPointerException e) { + // thrown from both getStatusLine() and getEntity() method on httpResponse object + throw new CodeQualityMetricsException(e.getMessage(), e.getCause()); } catch (IOException e) { throw new CodeQualityMetricsException("IOException occurred when calling the REST API", e); - } finally { - if (bufferedReader != null) { - try { - bufferedReader.close(); - } catch (IOException e) { - logger.error("IOException occurred when closing the BufferedReader", e); - } - } - if (httpResponse != null) { - try { - httpResponse.close(); - } catch (IOException e) { - logger.error("IOException occurred when closing the HttpResponse", e); - } - } - if (httpClient != null) { - try { - httpClient.close(); - } catch (IOException e) { - logger.error("IOException occurred when closing the HttpClient", e); - } - } } return jsonText; } @@ -113,24 +92,21 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMetricsException * @throws CodeQualityMetricsException results */ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMetricsException { - BufferedReader bufferedReader = null; - CloseableHttpClient httpClient; - CloseableHttpResponse httpResponse = null; - httpClient = HttpClients.createDefault(); String jsonText; - try { - httpResponse = httpClient.execute(httpPost); + try (CloseableHttpClient httpClient = HttpClients.createDefault(); + CloseableHttpResponse httpResponse = httpClient.execute(httpPost)) { int responseCode = httpResponse.getStatusLine().getStatusCode(); if (responseCode == 200) { - bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), - StandardCharsets.UTF_8)); - String line; - StringBuilder stringBuilder = new StringBuilder(); - while ((line = bufferedReader.readLine()) != null) { - stringBuilder.append(line); + try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity() + .getContent(), StandardCharsets.UTF_8))) { + String line; + StringBuilder stringBuilder = new StringBuilder(); + while ((line = bufferedReader.readLine()) != null) { + stringBuilder.append(line); + } + jsonText = stringBuilder.toString(); + logger.debug("The response received from the Github GraphQL converted to a JSON text successfully"); } - jsonText = stringBuilder.toString(); - logger.debug("The response received from the Github GraphQL converted to a JSON text successfully"); } else { throw new CodeQualityMetricsException("Error occurred while calling the API, the response code is " + responseCode); @@ -143,28 +119,6 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMetrics } catch (IOException e) { throw new CodeQualityMetricsException("A problem or the connection was aborted while executing the" + " httpPost", e); - } finally { - if (bufferedReader != null) { - try { - bufferedReader.close(); - } catch (IOException e) { - logger.error("IOException occurred when closing the buffered reader", e); - } - } - if (httpResponse != null) { - try { - httpResponse.close(); - } catch (IOException e) { - logger.error("IOException occurred when closing the HttpResponse", e); - } - } - if (httpClient != null) { - try { - httpClient.close(); - } catch (IOException e) { - logger.error("IOException occurred when closing the HttpClient", e); - } - } } return jsonText; } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java index e8e3978..07279e8 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java @@ -20,6 +20,12 @@ import org.apache.log4j.Logger; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.Properties; + /** * This is having the main method of this application * PMT Access token, patch id and github access token @@ -31,13 +37,23 @@ public class Application { private static final Logger logger = Logger.getLogger(Application.class); public static void main(String[] args) { - if (args.length == 3) { - String pmtToken = args[0]; - String patchId = args[1]; - String gitHubToken = args[2]; - CodeQualityMetricsExecutor codeQualityMetricsExecutor = new CodeQualityMetricsExecutor(pmtToken, patchId, - gitHubToken); - codeQualityMetricsExecutor.execute(); + if (args.length == 1) { + String patchId = args[0]; + Properties defaultProperties = new Properties(); + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + try (InputStream inputStream = classLoader.getResourceAsStream("tokens.properties")) { + defaultProperties.load(inputStream); + byte[] pmtTokenInBytes = Base64.getDecoder().decode(defaultProperties.getProperty("pmtToken")); + String pmtToken = new String(pmtTokenInBytes, StandardCharsets.UTF_8); + byte[] githubTokenInBytes = Base64.getDecoder().decode(defaultProperties.getProperty("githubToken")); + String githubToken = new String(githubTokenInBytes, StandardCharsets.UTF_8); + CodeQualityMetricsExecutor codeQualityMetricsExecutor = new CodeQualityMetricsExecutor(pmtToken, + patchId, githubToken); + codeQualityMetricsExecutor.execute(); + } catch (IOException e) { + logger.error("IO exception occurred when loading the inputstream to the " + + "properties object", e); + } } else { logger.error("Command line arguments were not given correctly to start the execution"); logger.debug("Please enter PMT Access token, patch id and github access token in order as command " + diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java index abf3ed2..ad33777 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java @@ -21,6 +21,7 @@ import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import com.google.gson.reflect.TypeToken; +import com.wso2.code.quality.metrics.exceptions.CodeQualityMetricsException; import com.wso2.code.quality.metrics.model.CommitHistoryApiResponse; import com.wso2.code.quality.metrics.model.GraphQlResponse; import com.wso2.code.quality.metrics.model.Graphql; @@ -51,21 +52,20 @@ public class ChangesFinder { private static final Logger logger = Logger.getLogger(ChangesFinder.class); - private Set authorNames = new HashSet<>(); //authors of the bug lines fixed from the patch + Set authorNames = new HashSet<>(); //authors of the bug lines fixed from the patch private Set authorCommits = new HashSet<>(); // author commits of the bug lines fixed from the patch private final JSONObject jsonStructure = new JSONObject(); - private final GithubApiCaller githubApiCaller = new GithubApiCaller(); private final Gson gson = new Gson(); /** * This class is used to prevent SIC_INNER_SHOULD_BE_STATIC_ANON error that comes when building with WSO2 parent - * pom. As suggested by the above error an static inner class is used + * pom, as suggested by the above error an static inner class is used to prevent the error. */ private static class ListType extends TypeToken> { } /** - * This is used for obtaining the repositories that contain the relevant commits belongs to the given patch + * This is used for obtaining the repositories that contain the relevant commits belongs to the given patch. * * @param gitHubToken github token for accessing github API * @param commitHashes List of commits that belongs to the given patch @@ -74,7 +74,7 @@ private static class ListType extends TypeToken> Set obtainRepoNamesForCommitHashes(String gitHubToken, List commitHashes) { commitHashes.forEach(commitHash -> { try { - String jsonText = githubApiCaller.callSearchCommitApi(commitHash, gitHubToken); + String jsonText = GithubApiCallerUtils.callSearchCommitApi(commitHash, gitHubToken); List repoLocations = saveRepoNames(jsonText); identifyChangedFile(repoLocations, commitHash, gitHubToken); } catch (CodeQualityMetricsException e) { @@ -107,7 +107,7 @@ List saveRepoNames(String jsonText) throws CodeQualityMetricsException { /** * This identifies the file changed and their relevant line ranges changed in selected repository from the given - * commit hash + * commit hash. * * @param repoLocation List of repository locations having the given commit hash * @param commitHash commit hash to be searched for containing WSO2 repositories @@ -126,19 +126,24 @@ private void identifyChangedFile(List repoLocation, String commitHash, S if (fileNamesWithPatchString != null) { /* looping from one file to file and saving deleted lines against the file name in another map */ - for (Map.Entry entry : fileNamesWithPatchString.entrySet()) { - String fileName = entry.getKey(); - String patchString = entry.getValue(); + fileNamesWithPatchString.forEach((fileName, patchString) -> { Set deletedLines = identifyDeletedLines(patchString); - String previousCommitHash; - //for omitting files without having deleted lines + String previousCommitHashOfFile; + //for omitting files without having deleted lines in other words newly created files if (deletedLines.size() > 0) { fileNamesWithDeletedLineNumbers.put(fileName, deletedLines); - previousCommitHash = checkForOctopussMerge(repositoryName, fileName, commitHash, - gitHubToken); - fileNamesWithPreviousCommitHash.put(fileName, previousCommitHash); + previousCommitHashOfFile = checkForOctopusMerge(repositoryName, fileName, + commitHash, gitHubToken); + if (previousCommitHashOfFile != null && !previousCommitHashOfFile.isEmpty()) { + fileNamesWithPreviousCommitHash.put(fileName, previousCommitHashOfFile); + } else { + logger.warn("The changes from " + commitHash + " on " + fileName + " file " + + "may have been reversed from another commit on the same PR, so " + + "commit " + commitHash + " does not appear in history of current " + + "file due to git's history simplification when listing history"); + } } - } + }); } getBlameDetails(repositoryName, fileNamesWithPreviousCommitHash, fileNamesWithDeletedLineNumbers, gitHubToken); @@ -154,7 +159,7 @@ private void identifyChangedFile(List repoLocation, String commitHash, S /** * This check whether the commit in the given patch is an octopuss commit or not, if it is octopuss commit an - * exception as the current scope of the program doesnot support octopuss commits + * exception is thrown as the current scope of the program does not support octopus commits. * * @param repositoryName current selected Repository * @param filePath current selected file name @@ -162,12 +167,12 @@ private void identifyChangedFile(List repoLocation, String commitHash, S * @param githubToken github access token for accessing github REST API * @return the commit hash returned from findPreviousCommitOfFile method */ - private String checkForOctopussMerge(String repositoryName, String filePath, String latestCommitHash, String + private String checkForOctopusMerge(String repositoryName, String filePath, String latestCommitHash, String githubToken) { - String previousCommit = null; + String previousCommitOfFile = null; try { // need check whether the given commit has more than 2 parent commits - String singleCommitJsonText = githubApiCaller.callSingleCommitApi(repositoryName, latestCommitHash, + String singleCommitJsonText = GithubApiCallerUtils.callSingleCommitApi(repositoryName, latestCommitHash, githubToken); SingleCommitApiResponse singleCommitApiResponse = gson.fromJson(singleCommitJsonText, SingleCommitApiResponse.class); @@ -189,16 +194,16 @@ private String checkForOctopussMerge(String repositoryName, String filePath, Str "an octopuss merge commit, octopuss merge commits are avoided in the current scope of " + "the program"); } - previousCommit = findPreviousCommitOfFile(repositoryName, filePath, latestCommitHash, githubToken); + previousCommitOfFile = findPreviousCommitOfFile(repositoryName, filePath, latestCommitHash, githubToken); } catch (CodeQualityMetricsException e) { logger.error(e.getMessage(), e.getCause()); } - return previousCommit; + return previousCommitOfFile; } /** * This is used to get the previous commit hash of the selected file before the current selected commit which - * contained in the given patch + * contained in the given patch. * * @param repositoryName current selected Repository * @param filePath current selected file name @@ -209,11 +214,11 @@ private String checkForOctopussMerge(String repositoryName, String filePath, Str */ private String findPreviousCommitOfFile(String repositoryName, String filePath, String latestCommitHash, String githubToken) { - String previousCommit = null; + String previousCommitOfFile = null; Map commitWithDate = new HashMap<>(); try { - String commitHistoryJsonText = githubApiCaller.callCommitHistoryApi(repositoryName, filePath, githubToken); - + String commitHistoryJsonText = GithubApiCallerUtils.callCommitHistoryApi(repositoryName, filePath, + githubToken); Type listType = new ListType().getType(); List commitHistoryApiResponses = gson.fromJson(commitHistoryJsonText, listType); @@ -223,22 +228,29 @@ private String findPreviousCommitOfFile(String repositoryName, String filePath, commitWithDate.put(commitHash, date); }); String latestCommitDate = commitWithDate.get(latestCommitHash); - String previousCommitDate = getPreviousCommitDate(commitWithDate, latestCommitDate); - // looping for finding the commit Hash introduced in previous commit date - for (Map.Entry entry : commitWithDate.entrySet()) { - if (entry.getValue().equals(previousCommitDate)) { - previousCommit = (String) entry.getKey(); + if (latestCommitDate != null && !latestCommitDate.isEmpty()) { + String previousCommitDate = getPreviousCommitDate(commitWithDate, latestCommitDate); + // looping for finding the commit Hash introduced in previous commit date + for (Map.Entry entry : commitWithDate.entrySet()) { + if (entry.getValue().equals(previousCommitDate)) { + previousCommitOfFile = (String) entry.getKey(); + } } + } else { + return null; } - + /*the changes from given commit to the current selected file may have been reversed from another commit, so + the given commit does not appear in history of the current file due to git's history simplification when + listing history*/ } catch (CodeQualityMetricsException e) { logger.error(e.getMessage(), e.getCause()); } - return previousCommit; + return previousCommitOfFile; } /** - * This is used to get the previous commit date of the selected file before the current commit + * This is used to get the previous commit date of the selected file before the current commit by sorting the + * commit dates. * * @param commitWithDate map contating all the commits with their respective date of the current selected * file @@ -254,7 +266,7 @@ private String getPreviousCommitDate(Map commitWithDate, String } /** - * This method is used to obtain the blame details of files for their previous commits + * This method is used to obtain the blame details of files for their previous commits. * * @param repoLocation current selected Repository * @param fileNamesWithPreviousCommitHash map containing changed files with their prior commit hashes @@ -263,7 +275,6 @@ private String getPreviousCommitDate(Map commitWithDate, String */ private void getBlameDetails(String repoLocation, Map fileNamesWithPreviousCommitHash, Map> fileNamesWithDeletedLineNumbers, String githubToken) { - // filtering the owner and the repository name from the repoLocation String owner = StringUtils.substringBefore(repoLocation, "/"); String repositoryName = StringUtils.substringAfter(repoLocation, "/"); @@ -274,7 +285,7 @@ private void getBlameDetails(String repoLocation, Map fileNamesW String jsonText; try { // calling the graphql API for getting blame information for the current file. - jsonText = githubApiCaller.callGraphqlApi(jsonStructure, githubToken); + jsonText = GithubApiCallerUtils.callGraphqlApi(jsonStructure, githubToken); findAuthorCommits(jsonText, fileNamesWithDeletedLineNumbers, fileName); } catch (CodeQualityMetricsException e) { logger.error(e.getMessage(), e.getCause()); @@ -294,7 +305,6 @@ private void getBlameDetails(String repoLocation, Map fileNamesW */ private void findAuthorCommits(String jsonText, Map> fileNamesWithDeletedLineNumbers, String selectedFileName) { - GraphQlResponse graphQlResponse = gson.fromJson(jsonText, GraphQlResponse.class); Set deletedLines = fileNamesWithDeletedLineNumbers.get(selectedFileName); deletedLines.forEach(deletedLineNumber -> @@ -312,7 +322,7 @@ private void findAuthorCommits(String jsonText, Map> fileNa } /** - * This method is used to identify the deleted lines from the current selected commit in given patch + * This method is used to identify the deleted lines from the current selected commit in given patch. * * @param patchString patch string of the selected file received from github SDK * @return a Set of deleted lines in the above mentioned file @@ -328,20 +338,24 @@ Set identifyDeletedLines(String patchString) { if (scanner.hasNext()) { String patchLine = scanner.nextLine(); String words[] = patchLine.split(","); + //String at the first index of word array is the staring line number of the modified range lineNumber = Integer.parseInt(words[0]); } //for finding the deleted lines in the string while (scanner.hasNext()) { String patchLine = scanner.nextLine(); String words[]; + //to differentiate completely empty lines ("") and empty lines with spaces and tabs if (patchLine.trim().length() != 0) { words = patchLine.split("\\s"); } else { words = patchLine.trim().split("\\s"); } String sign = words[0]; + // lines starting with "+" are neglected as they are newly introduced lines from the given commit if ("-".equals(sign) || "".equals(sign)) { if ("-".equals(sign)) { + //lines starting with "-" are the modified lines in the old file linesDeletedInSelectedFile.add(lineNumber); } lineNumber++; diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java index fcf5b09..f407eab 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java @@ -19,6 +19,7 @@ package com.wso2.code.quality.metrics; import com.google.gson.Gson; +import com.wso2.code.quality.metrics.exceptions.CodeQualityMetricsException; import org.apache.log4j.Logger; import java.util.ArrayList; @@ -71,7 +72,7 @@ public void execute() { } /** - * This is used to filter out the commit hashes that belongs to the given patch + * This is used to filter out the commit hashes that belongs to the given patch. * * @return List of commithashes contained in the given patch */ @@ -84,22 +85,20 @@ List findCommitHashesInPatch() throws CodeQualityMetricsException { } catch (CodeQualityMetricsException e) { throw new CodeQualityMetricsException("Error occurred while calling PMT API", e); } - if (jsonText != null) { - Gson gson = new Gson(); - List pmtResponse = gson.fromJson(jsonText, List.class); - for (Object pmtEntry : pmtResponse) { - if (pmtEntry instanceof Map) { - Map entryMap = (Map) pmtEntry; - if (COMMITS_INSIDE_GIVEN_PATCH.equals(entryMap.get("name"))) { - commitHashes = (List) entryMap.get("value"); - } + Gson gson = new Gson(); + List pmtResponse = gson.fromJson(jsonText, List.class); + for (Object pmtEntry : pmtResponse) { + if (pmtEntry instanceof Map) { + Map entryMap = (Map) pmtEntry; + if (COMMITS_INSIDE_GIVEN_PATCH.equals(entryMap.get("name"))) { + commitHashes = (List) entryMap.get("value"); + //to avoid leading and trailing white spaces in commit hashes + commitHashes.replaceAll(String::trim); } } - if (logger.isDebugEnabled()) { - logger.error("The commit hashes are: " + commitHashes); - } - } else { - throw new CodeQualityMetricsException("The returned jsonText from PMT API is null"); + } + if (logger.isDebugEnabled()) { + logger.error("The commit hashes are: " + commitHashes); } return commitHashes; } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCallerUtils.java similarity index 82% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCallerUtils.java index f11376b..cd3342e 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCaller.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCallerUtils.java @@ -18,6 +18,7 @@ package com.wso2.code.quality.metrics; +import com.wso2.code.quality.metrics.exceptions.CodeQualityMetricsException; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; @@ -33,16 +34,19 @@ import static com.wso2.code.quality.metrics.model.Constants.BEARER; /** - * This is used for all github communications. + * This is utility class used for all github communications. * * @since 1.0.0 */ -public class GithubApiCaller { - private HttpGet httpGet; - private final Properties defaultProperties = new Properties(); - private final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - private final InputStream inputStream = classLoader.getResourceAsStream("url.properties"); +public final class GithubApiCallerUtils { + private static final Properties defaultProperties = new Properties(); + private static final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + /** + * To prevent instantiation from other classes + */ + private GithubApiCallerUtils() { + } /** * This is used for calling the github search REST API. @@ -52,8 +56,10 @@ public class GithubApiCaller { * @return String representation of the json response * @throws CodeQualityMetricsException results */ - public String callSearchCommitApi(String commitHash, String githubAccessToken) throws CodeQualityMetricsException { - try { + public static String callSearchCommitApi(String commitHash, String githubAccessToken) throws + CodeQualityMetricsException { + HttpGet httpGet; + try (InputStream inputStream = classLoader.getResourceAsStream("url.properties")) { defaultProperties.load(inputStream); String url = defaultProperties.getProperty("searchCommitApiUrl") + commitHash; httpGet = new HttpGet(url); @@ -71,7 +77,7 @@ public String callSearchCommitApi(String commitHash, String githubAccessToken) t } /** - * This is used to call github commit REST API + * This is used to call github commit REST API. * * @param repoLocation repository location * @param filePath location of the file @@ -79,9 +85,10 @@ public String callSearchCommitApi(String commitHash, String githubAccessToken) t * @return String representation of the json response * @throws CodeQualityMetricsException Resulted Code Quality Metrics Exception */ - public String callCommitHistoryApi(String repoLocation, String filePath, String githubAccessToken) + public static String callCommitHistoryApi(String repoLocation, String filePath, String githubAccessToken) throws CodeQualityMetricsException { - try { + HttpGet httpGet; + try (InputStream inputStream = classLoader.getResourceAsStream("url.properties")) { defaultProperties.load(inputStream); String tempUrl = defaultProperties.getProperty("commitHistoryApiUrl"); String url = tempUrl.replaceFirst("REPO_LOCATION", repoLocation).replaceFirst("FILE_NAME", filePath); @@ -98,16 +105,17 @@ public String callCommitHistoryApi(String repoLocation, String filePath, String } /** - * This is used to call github single commit REST API + * This is used to call github single commit REST API. * * @param repoLocation repository location * @param commitHash relevant commit hash to find details of * @param githubAccessToken Github access token for accessing github API * @return String representation of the json response */ - public String callSingleCommitApi(String repoLocation, String commitHash, String githubAccessToken) + public static String callSingleCommitApi(String repoLocation, String commitHash, String githubAccessToken) throws CodeQualityMetricsException { - try { + HttpGet httpGet; + try (InputStream inputStream = classLoader.getResourceAsStream("url.properties")) { defaultProperties.load(inputStream); String tempUrl = defaultProperties.getProperty("singleCommitApiUrl"); String url = tempUrl.replaceFirst("REPO_LOCATION", repoLocation).replaceFirst("COMMIT_HASH", commitHash); @@ -133,9 +141,10 @@ public String callSingleCommitApi(String repoLocation, String commitHash, String * @return String representation of the json response * @throws CodeQualityMetricsException results */ - public String callReviewApi(String repoLocation, int pullRequestNumber, String githubAccessToken) throws + public static String callReviewApi(String repoLocation, int pullRequestNumber, String githubAccessToken) throws CodeQualityMetricsException { - try { + HttpGet httpGet; + try (InputStream inputStream = classLoader.getResourceAsStream("url.properties")) { defaultProperties.load(inputStream); String tempUrl = defaultProperties.getProperty("reviewApiUrl"); String url = tempUrl.replaceFirst("REPO_LOCATION", repoLocation).replaceFirst("PULL_REQUEST_NUMBER", @@ -161,9 +170,10 @@ public String callReviewApi(String repoLocation, int pullRequestNumber, String g * @return String representation of the json response * @throws CodeQualityMetricsException results */ - public String callSearchIssueApi(String commitHashToBeSearched, String githubAccessToken) throws + public static String callSearchIssueApi(String commitHashToBeSearched, String githubAccessToken) throws CodeQualityMetricsException { - try { + HttpGet httpGet; + try (InputStream inputStream = classLoader.getResourceAsStream("url.properties")) { defaultProperties.load(inputStream); String url = defaultProperties.getProperty("searchIssueApiUrl") + commitHashToBeSearched; httpGet = new HttpGet(url); @@ -187,10 +197,10 @@ public String callSearchIssueApi(String commitHashToBeSearched, String githubAcc * @return String representation of the json response * @throws CodeQualityMetricsException results */ - public String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken) throws + public static String callGraphqlApi(JSONObject graphqlJsonStructure, String githubToken) throws CodeQualityMetricsException { HttpPost httpPost; - try { + try (InputStream inputStream = classLoader.getResourceAsStream("url.properties")) { defaultProperties.load(inputStream); String url = defaultProperties.getProperty("githubGraphqlUrl"); httpPost = new HttpPost(url); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java index 01dbf80..8e4e484 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java @@ -18,6 +18,7 @@ package com.wso2.code.quality.metrics; +import com.wso2.code.quality.metrics.exceptions.CodeQualityMetricsException; import org.apache.http.client.methods.HttpGet; import java.io.IOException; @@ -33,8 +34,6 @@ * @since 1.0.0 */ public class PmtApiCaller { - public PmtApiCaller() { - } /** * This is used for calling the WSO2 PMT REST API. @@ -46,10 +45,9 @@ public PmtApiCaller() { */ public String callApi(String accessToken, String patchId) throws CodeQualityMetricsException { HttpGet httpGet; - try { - Properties defaultProperties = new Properties(); - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - InputStream inputStream = classLoader.getResourceAsStream("url.properties"); + Properties defaultProperties = new Properties(); + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + try (InputStream inputStream = classLoader.getResourceAsStream("url.properties")) { defaultProperties.load(inputStream); String pmtApiUrl = defaultProperties.getProperty("pmtApiUrl"); String pmtUrl = pmtApiUrl + patchId; @@ -57,8 +55,6 @@ public String callApi(String accessToken, String patchId) throws CodeQualityMetr httpGet.addHeader(AUTHORIZATION, BEARER + accessToken); } catch (IllegalArgumentException e) { throw new CodeQualityMetricsException("The url provided for accessing the PMT API is invalid ", e); - } catch (SecurityException e) { - throw new CodeQualityMetricsException("The url properties file is not found", e); } catch (IOException e) { throw new CodeQualityMetricsException("IO exception occurred when loading the inputstream to the " + "properties object", e); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java index 5c3ab5c..1f42f3f 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java @@ -21,6 +21,7 @@ import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import com.google.gson.reflect.TypeToken; +import com.wso2.code.quality.metrics.exceptions.CodeQualityMetricsException; import com.wso2.code.quality.metrics.model.IssueApiResponse; import com.wso2.code.quality.metrics.model.ReviewApiResponse; import org.apache.commons.lang3.StringUtils; @@ -50,29 +51,26 @@ public class ReviewAnalyser { final Set approvedReviewers = new HashSet<>(); // to store the reviewed and commented users of the pull requests final Set commentedReviewers = new HashSet<>(); - //constants for filtering github API responses - private final GithubApiCaller githubApiCaller = new GithubApiCaller(); private final Gson gson = new Gson(); /** * This class is used to prevent SIC_INNER_SHOULD_BE_STATIC_ANON error that comes when building with WSO2 parent - * pom. As suggested by the above error an static inner class is used + * pom. As suggested by the above error an static inner class is used to prevent the error. */ private static class ListType extends TypeToken> { } - /** * This is used to identify the pull requests that introduce the given commit to the code base. * * @param authorCommits Commits which the relevant pull request no must be found * @param githubToken Github access token for accessing github API */ - public void findReviewers(Set authorCommits, String githubToken) { + void findReviewers(Set authorCommits, String githubToken) { authorCommits.forEach(commitHash -> { String jsonText; try { - jsonText = githubApiCaller.callSearchIssueApi(commitHash, githubToken); + jsonText = GithubApiCallerUtils.callSearchIssueApi(commitHash, githubToken); Map> prNoWithRepoName = savePrNumberAndRepoName(jsonText); if (logger.isDebugEnabled()) { logger.debug("Relevant pull requests on patch " + commitHash + " with their relevant repository " + @@ -98,8 +96,7 @@ Map> savePrNumberAndRepoName(String jsonText) throws CodeQu try { IssueApiResponse issueApiResponse = gson.fromJson(jsonText, IssueApiResponse.class); issueApiResponse.getIssue().parallelStream() - .filter(searchItem -> GITHUB_REVIEW_API_CLOSED_STATE.equals(searchItem.getStateOfThePr())) - + .filter(searchItem -> GITHUB_REVIEW_API_CLOSED_STATE.equals(searchItem.getPrState())) .filter(searchItem -> StringUtils.contains(searchItem.getRepositoryUrl(), "/wso2/")) .forEach(searchItem -> { String repositoryName = StringUtils.substringAfter(searchItem.getRepositoryUrl(), @@ -119,7 +116,7 @@ Map> savePrNumberAndRepoName(String jsonText) throws CodeQu /** * This is used to save the names of the users who has approved and commented on the pull requests which * introduce bug lines of code to the code base. Approved users are saved in approvedReviewers list while - * commented users are saved in commentedReviewers list + * commented users are saved in commentedReviewers list. * * @param prNoWithRepoName Map containg the pull requests which introduce bug lines to the code base against the * relevant reposiory @@ -132,10 +129,8 @@ void saveReviewers(Map> prNoWithRepoName, String githubToke prNumbers.parallelStream() .forEach((Integer prNumber) -> { try { - String jsonText = githubApiCaller.callReviewApi(repositoryName, prNumber, githubToken); - if (jsonText != null) { -// Type listType = new TypeToken>() { -// }.getType(); + String jsonText = GithubApiCallerUtils.callReviewApi(repositoryName, prNumber, githubToken); + if (jsonText != null && !jsonText.isEmpty()) { Type listType = new ListType().getType(); List reviews = gson.fromJson(jsonText, listType); // List reviews = gson.fromJson(jsonText, List.class); @@ -163,9 +158,9 @@ void saveReviewers(Map> prNoWithRepoName, String githubToke } /** - * Print the list of reviewers and commented users on the pull requests which introduce bugs to the code base + * Print the list of reviewers and commented users on the pull requests which introduce bugs to the code base. */ - public void printReviewUsers() { + void printReviewUsers() { if (logger.isDebugEnabled()) { logger.debug("\n Reviewed and approved users of the bug lines: " + approvedReviewers); logger.debug("\n Reviewed and commented users on bug lines: " + commentedReviewers); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java index 1ea0956..6ad4dae 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java @@ -18,6 +18,7 @@ package com.wso2.code.quality.metrics; +import com.wso2.code.quality.metrics.exceptions.CodeQualityMetricsException; import org.apache.log4j.Logger; import org.eclipse.egit.github.core.CommitFile; import org.eclipse.egit.github.core.IRepositoryIdProvider; @@ -55,7 +56,7 @@ public class SdkGitHubClient { * @param commitHash The querying commit hash * @return a map containg arraylist of file changed and their relevant patch */ - public Map getFilesChanged(String repositoryName, String commitHash) + Map getFilesChanged(String repositoryName, String commitHash) throws CodeQualityMetricsException { Map fileNamesAndPatches = new HashMap<>(); try { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsException.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/exceptions/CodeQualityMetricsException.java similarity index 88% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsException.java rename to org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/exceptions/CodeQualityMetricsException.java index adb2c38..711df8e 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsException.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/exceptions/CodeQualityMetricsException.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -16,7 +16,7 @@ * under the License. */ -package com.wso2.code.quality.metrics; +package com.wso2.code.quality.metrics.exceptions; /** * The exception class for all Code Quality Matrices project related exceptions. diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Author.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Author.java index 3fcd3a8..7fe4cd5 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Author.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Author.java @@ -28,7 +28,6 @@ public class Author { @SerializedName("date") - private String date; public String getDate() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java index 1e7bd7e..fde0f59 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java @@ -30,7 +30,6 @@ public class CommitHistoryApiResponse { private String commitHash; @SerializedName("commit") - private Commit commit; public String getCommitHash() { diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Constants.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Constants.java index ae42e81..edb2cbe 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Constants.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Constants.java @@ -19,7 +19,7 @@ package com.wso2.code.quality.metrics.model; /** - * This is used for storing all the constants used in the Code quality metrics Application + * This is used for storing all the constants used in the Code quality metrics Application. * * @since 1.0.0 */ diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Graphql.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Graphql.java index b5f1aa8..db8fcfb 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Graphql.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Graphql.java @@ -26,24 +26,12 @@ * @since 1.0.0 */ public class Graphql implements Serializable { - private String graphqlInputWithHistory; private String graphqlInputWithoutHistory; private static final long serialVersionUID = 42L; public Graphql() { } - public String getGraphqlInputWithHistory() { - return graphqlInputWithHistory; - } - - public void setGraphqlInputWithHistory(String owner, String repositoryName, String commitHash, String fileName) { - this.graphqlInputWithHistory = "{repository(owner:\"" + owner + "\",name:\"" + repositoryName + "\")" + - "{object(expression:\"" + commitHash + "\"){ ... on Commit{blame(path:\"" + fileName + "\")" + - "{ranges{startingLine endingLine age commit{history(first: 2) { edges { node { message url } } } " + - "author { name email } } } } } } } }"; - } - public String getGraphqlInputWithoutHistory() { return graphqlInputWithoutHistory; } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlCommit.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlCommit.java index 8cce2f4..89e2342 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlCommit.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlCommit.java @@ -28,8 +28,7 @@ public class GraphqlCommit { @SerializedName("author") private GraphqlAuthor author; - @SerializedName("history") - private GraphqlHistory history; + @SerializedName("url") private String url; @@ -41,14 +40,6 @@ public void setAuthor(GraphqlAuthor author) { this.author = author; } - public GraphqlHistory getHistory() { - return history; - } - - public void setHistory(GraphqlHistory history) { - this.history = history; - } - public void setUrl(String url) { this.url = url; } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlEdge.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlEdge.java deleted file mode 100644 index ab4e7e6..0000000 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlEdge.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.wso2.code.quality.metrics.model; - -import com.google.gson.annotations.SerializedName; - -/** - * Pojo class used for parsing JSON response received from github graphql API. - * - * @since 1.0.0 - */ -public class GraphqlEdge { - @SerializedName("node") - private GraphqlNode details; - - public GraphqlNode getDetails() { - return details; - } - - public void setDetails(GraphqlNode details) { - this.details = details; - } -} diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlHistory.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlHistory.java deleted file mode 100644 index 0d89115..0000000 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlHistory.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.wso2.code.quality.metrics.model; - -import com.google.gson.annotations.SerializedName; - -import java.util.List; - -/** - * Pojo class used for parsing JSON response received from github graphql API. - * - * @since 1.0.0 - */ -public class GraphqlHistory { - @SerializedName("edges") - private List commits; - - public List getCommits() { - return commits; - } - - public void setCommits(List commits) { - this.commits = commits; - } -} diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlNode.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlNode.java deleted file mode 100644 index 04c23bd..0000000 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlNode.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.wso2.code.quality.metrics.model; - -import com.google.gson.annotations.SerializedName; - -/** - * Pojo class used for parsing JSON response received from github graphql API. - * - * @since 1.0.0 - */ -public class GraphqlNode { - @SerializedName("url") - private String url; - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } -} diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlRange.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlRange.java index 2e4f407..1c0cad9 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlRange.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlRange.java @@ -28,10 +28,13 @@ public class GraphqlRange { @SerializedName("startingLine") private int startingLine; + @SerializedName("endingLine") private int endingLine; + @SerializedName("age") private int age; + @SerializedName("commit") private GraphqlCommit commit; diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ReviewApiResponse.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ReviewApiResponse.java index d37c714..03f324a 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ReviewApiResponse.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ReviewApiResponse.java @@ -28,10 +28,10 @@ public class ReviewApiResponse { @SerializedName("state") private String reviewState; + @SerializedName("user") private Reviewer reviewer; - public String getReviewState() { return reviewState; } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SearchItem.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SearchItem.java index 7a96779..dbf92eb 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SearchItem.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SearchItem.java @@ -27,18 +27,20 @@ */ public class SearchItem { @SerializedName("state") - private String stateOfThePr; + private String prState; + @SerializedName("number") private int prNumber; + @SerializedName("repository_url") private String repositoryUrl; - public String getStateOfThePr() { - return stateOfThePr; + public String getPrState() { + return prState; } - public void setStateOfThePr(String stateOfThePr) { - this.stateOfThePr = stateOfThePr; + public void setPrState(String prState) { + this.prState = prState; } public int getPrNumber() { diff --git a/org.wso2.codequalitymatrices/src/main/resources/log4j.properties b/org.wso2.codequalitymatrices/src/main/resources/log4j.properties index 34d5509..9640d66 100644 --- a/org.wso2.codequalitymatrices/src/main/resources/log4j.properties +++ b/org.wso2.codequalitymatrices/src/main/resources/log4j.properties @@ -33,9 +33,3 @@ log4j.appender.CONSOLE= org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Target=System.out log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.conversionPattern=%d{yyyy-MM-dd}-5p--10c:%m%n - - - - - - diff --git a/org.wso2.codequalitymatrices/src/main/resources/tokens.properties b/org.wso2.codequalitymatrices/src/main/resources/tokens.properties new file mode 100644 index 0000000..706b1fd --- /dev/null +++ b/org.wso2.codequalitymatrices/src/main/resources/tokens.properties @@ -0,0 +1,19 @@ +# +# Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# +# WSO2 Inc. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +pmtToken=dFFVNXZ4enJHZUJwTE1RdXdPc0pXX2Z5WUxZYQ== +githubToken=ZjQxZTcwOTJmY2I1NTZmZTI2YzFlMDgwYjFjNDQ3NWRhYTZmN2MyNw diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java index c5aa134..5a4d114 100644 --- a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java @@ -18,12 +18,15 @@ package com.wso2.code.quality.metrics; +import com.wso2.code.quality.metrics.exceptions.CodeQualityMetricsException; import org.apache.commons.io.IOUtils; import org.apache.log4j.Logger; import org.junit.Test; import java.io.IOException; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; import static org.hamcrest.CoreMatchers.is; @@ -38,11 +41,12 @@ public class ChangesFinderTest { private static final Logger logger = Logger.getLogger(ChangesFinderTest.class); + private ChangesFinder changesFinder = new ChangesFinder(); + @Test public void testIdentifyDeletedLines() { String patchString; Set actualDeltedLinesForPatchString; - ChangesFinder changesFinder = new ChangesFinder(); patchString = readFile("patchStrings/patchString1.txt"); actualDeltedLinesForPatchString = changesFinder.identifyDeletedLines(patchString); Set expectedDeltedLinesForPatchString1 = new HashSet<>(); @@ -90,8 +94,53 @@ private String readFile(String path) { try { result = IOUtils.toString(classLoader.getResourceAsStream(path)); } catch (IOException e) { - logger.debug(e.getMessage(), e.getCause()); + logger.error(e.getMessage(), e.getCause()); } return result; } + + @Test + public void testObtainRepoNamesForCommitHashes() throws CodeQualityMetricsException { + Token token = new Token(); + List commitHash = new ArrayList<>(); + commitHash.add("ad0debb15f1abac020b8ba69066ae4ebec782bdc"); + Set actualAuthorCommits = changesFinder.obtainRepoNamesForCommitHashes(token.getGithubToken(), + commitHash); + Set expectedAuthorCommits = new HashSet<>(); + expectedAuthorCommits.add("90fec04e4ac05281612de8d445c5767c26433b0d"); + assertThat(actualAuthorCommits.size(), is(expectedAuthorCommits.size())); + assertThat(actualAuthorCommits, is(expectedAuthorCommits)); + } + + @Test + public void testObtainRepoNamesForCommitHashesForAuthorNames() throws CodeQualityMetricsException { + Token token = new Token(); + List commitHash = new ArrayList<>(); + commitHash.add("bba8ce79cd3373445e21dd12deffae1a7b48dca9"); + commitHash.add("1c0e28ca181a08398efbc8ba8e984d8800e23c95"); + commitHash.add("a8ddc56575ede78c6a1882df20789bb2cc04022c"); + changesFinder.obtainRepoNamesForCommitHashes(token.getGithubToken(), + commitHash); + Set expectedAuthorName = new HashSet<>(); + expectedAuthorName.add("ruchiraw"); + assertThat(changesFinder.authorNames.size(), is(expectedAuthorName.size())); + assertThat(changesFinder.authorNames, is(expectedAuthorName)); + } + + @Test + public void testObtainRepoNamesForCommitHashesForAuthorNames2() throws CodeQualityMetricsException { + Token token = new Token(); + List commitHash = new ArrayList<>(); + commitHash.add("2b1d973d089ebc3af3b9e7b893f48cf905758cf4"); + commitHash.add("eaa45529cbabc5f30a2ffaa4781821ad0a5223ab"); + changesFinder.obtainRepoNamesForCommitHashes(token.getGithubToken(), + commitHash); + Set expectedAuthorName = new HashSet<>(); + expectedAuthorName.add("Chamila"); + expectedAuthorName.add("lalaji"); + expectedAuthorName.add("Amila De Silva"); + expectedAuthorName.add("Lakmali"); + assertThat(changesFinder.authorNames.size(), is(expectedAuthorName.size())); + assertThat(changesFinder.authorNames, is(expectedAuthorName)); + } } diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java index aa9d12c..a5fbfd3 100644 --- a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java @@ -19,7 +19,10 @@ package com.wso2.code.quality.metrics; +import com.wso2.code.quality.metrics.exceptions.CodeQualityMetricsException; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import java.util.Arrays; import java.util.Collections; @@ -36,6 +39,9 @@ */ public class CodeQualityMetricsExecutorTest { + @Rule + public final ExpectedException exception = ExpectedException.none(); + @Test public void testFindCommitHashesInPatch() throws CodeQualityMetricsException { String pmtToken = new Token().getPmtToken(); @@ -54,4 +60,13 @@ public void testFindCommitHashesInPatch() throws CodeQualityMetricsException { assertEquals("Must match with the relevant commit list", map.getValue(), commitHashes); } } + + @Test + public void testFindCommitHashesInPatchForException() throws CodeQualityMetricsException { + CodeQualityMetricsExecutor codeQualityMetricsExecutor = new CodeQualityMetricsExecutor("pmtToken", + "patch1", "githubToken"); + exception.expect(CodeQualityMetricsException.class); + exception.expectMessage("Error occurred while calling PMT API"); + codeQualityMetricsExecutor.findCommitHashesInPatch(); + } } diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java index 8dfcab8..9c9dd61 100644 --- a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java @@ -18,6 +18,7 @@ package com.wso2.code.quality.metrics; +import com.wso2.code.quality.metrics.exceptions.CodeQualityMetricsException; import org.junit.BeforeClass; import org.junit.Test; @@ -40,12 +41,10 @@ */ public class GithubResponsesTest { private static String githubToken; - private static GithubApiCaller githubApiCaller; @BeforeClass - public static void setupTheEnvironment() { + public static void setupTheEnvironment() throws CodeQualityMetricsException { githubToken = new Token().getGithubToken(); - githubApiCaller = new GithubApiCaller(); } @Test @@ -59,7 +58,7 @@ public void testSaveRepoNames() throws CodeQualityMetricsException { Collections.singletonList("wso2/wso2-axis2-transports")); for (Map.Entry> entry : commitHashWithRepoNames.entrySet()) { String commitHash = entry.getKey(); - String jsonText = githubApiCaller.callSearchCommitApi(commitHash, githubToken); + String jsonText = GithubApiCallerUtils.callSearchCommitApi(commitHash, githubToken); ChangesFinder changesFinder = new ChangesFinder(); List repoLocations = changesFinder.saveRepoNames(jsonText); assertEquals("List of RepoLocations obtained must be same", entry.getValue(), repoLocations); @@ -68,7 +67,7 @@ public void testSaveRepoNames() throws CodeQualityMetricsException { @Test public void testSavePrNumberAndRepoName() throws CodeQualityMetricsException { - String jsonText = githubApiCaller.callSearchIssueApi + String jsonText = GithubApiCallerUtils.callSearchIssueApi ("0015c02145c8ec6d3bba433f2fb5e850e1d25846", githubToken); ReviewAnalyser reviewAnalyser = new ReviewAnalyser(); Map> actualPrNoWithRepoName = reviewAnalyser.savePrNumberAndRepoName(jsonText); diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java index 8aa384d..3720b76 100644 --- a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java @@ -18,6 +18,7 @@ package com.wso2.code.quality.metrics; +import com.wso2.code.quality.metrics.exceptions.CodeQualityMetricsException; import org.hamcrest.collection.IsMapContaining; import org.junit.BeforeClass; import org.junit.Test; diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/Token.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/Token.java index f503ae1..dffcf1b 100644 --- a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/Token.java +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/Token.java @@ -18,8 +18,13 @@ package com.wso2.code.quality.metrics; +import com.wso2.code.quality.metrics.exceptions.CodeQualityMetricsException; + +import java.io.IOException; +import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Base64; +import java.util.Properties; /** * This class is used for providing github and WSO2 PMT access tokens @@ -27,10 +32,23 @@ * @since 1.0.0 */ public class Token { - final String pmtToken = "tQU5vxzrGeBpLMQuwOsJW_fyYLYa"; - final byte[] githubTokenByteArray = Base64.getDecoder().decode - ("ZjQxZTcwOTJmY2I1NTZmZTI2YzFlMDgwYjFjNDQ3NWRhYTZmN2MyNw"); - final String githubToken = new String(githubTokenByteArray, StandardCharsets.UTF_8); + private String pmtToken; + private String githubToken; + + public Token() throws CodeQualityMetricsException { + Properties defaultProperties = new Properties(); + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + try (InputStream inputStream = classLoader.getResourceAsStream("tokens.properties")) { + defaultProperties.load(inputStream); + byte[] pmtTokenInBytes = Base64.getDecoder().decode(defaultProperties.getProperty("pmtToken")); + pmtToken = new String(pmtTokenInBytes, StandardCharsets.UTF_8); + byte[] githubTokenInBytes = Base64.getDecoder().decode(defaultProperties.getProperty("githubToken")); + githubToken = new String(githubTokenInBytes, StandardCharsets.UTF_8); + } catch (IOException e) { + throw new CodeQualityMetricsException("IO exception occurred when loading the inputstream to the " + + "properties object", e); + } + } public String getPmtToken() { return pmtToken; From af853d850fc65496311d1a0584980a06c0b6192e Mon Sep 17 00:00:00 2001 From: kasunsiyambalapitiya Date: Fri, 21 Apr 2017 10:59:51 +0530 Subject: [PATCH 60/62] Add README.md file --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..af4f77a --- /dev/null +++ b/README.md @@ -0,0 +1,48 @@ +# Welcome to Code Quality Metrics + +At WSO2 when a customer report a bug on a product, often we have to issue a patch to solve the problem. As part of providing this patch, we also record the commit hashes which fixed the issue in WSO2 Patch Management System. What this program does is, it takes those commit hashes and identify the initial lines which caused the bug to arose, who authored them, reviewed them and approved them. The reason for doing this is to see whether there are any patterns on the bugs introduced to the code. If so, WSO2 can educate the people on relevant patterns and prevent the bugs in future releases. + +## Architecture +Code Quality Metrics application make API calls to WSO2 PMT REST API, Github REST API v3 and Github Graphql API in it’s execution. PMT REST API calls are made to obtain the relevant commit hashes reside in the given patch, Github REST API calls are made to identify the relevant WSO2 repositories containing the obtained commits ( obtained from WSO2 PMT REST API for the given patch), to identify whether those commits are formed from a octopus merge commit, to obtain commit history of a given file, to identify relevant pull requests containing the obtained author commits and to identify relevant reviewers of those pull requests if any. + +Since there is no Github REST API yet deployed for obtaining blame details of files, Github Graphql API was used to get the blame details of modified files from above obtained commits, even though the GraphQL API is still in early access mode. + +[Github Java API](https://github.com/eclipse/egit-github/tree/master/org.eclipse.egit.github.core) was used for obtaining the modified files and their relevant patch strings for the commits resides on the given patch. + +

+Architectural Diagram +

+ + +## Installation +### Prerequisites +* [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) installed. +* [Java](http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html) installed +* [Apache Maven](https://maven.apache.org/download.cgi) installed. + +After cloning or downloading the repository open `Eclipse IDE` or `IntelliJ IDEA` and open project’s `pom.xml`(Import all the dependencies if required). + +## Running Samples +It is required to provide the relevant WSO2 patch name as a command line argument to obtain relevant authors and reviewers of code lines been modified from the given patch. + +Run following samples and check with outputs + +1. WSO2-CARBON-PATCH-4.4.0-0680 + Authors : [Lakmali, Amila De Silva, lalaji, Chamila] + Approved Users: [] + Commented Users:[] + + Note : Since this is an old patch reviewers of bug lines are not present as github protected branch feature was used by WSO2 from 2017 onwards. +2. WSO2-CARBON-PATCH-4.4.0-1134 + Authors: [] + Approved Users: [] + Commented Users: [] + + Note : Since this patch only introduce new files to the repository, no authors of bug lines are shown. + +3. WSO2-CARBON-PATCH-4.4.0-1102 + Authors: [nuwandiw, Pasindu Nivanthaka Tennage, godwin] + Approved Users: [darshanasbg] + Commented Users: [] + + Note: Since this patch has modified lines added after enabling protected branch feature on master branches, the application provides the approved user of the bug lines as “darshanasbg” and there are no commented users on those lines. From f50b3ebf3c99ee07387bd81668f28b6308f8bb48 Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 21 Apr 2017 18:44:09 +0530 Subject: [PATCH 61/62] Use Java Reflections --- .../wso2/code/quality/metrics/ApiUtility.java | 6 +- .../code/quality/metrics/Application.java | 2 +- .../code/quality/metrics/ChangesFinder.java | 26 +-- .../metrics/CodeQualityMetricsExecutor.java | 8 +- .../quality/metrics/GithubApiCallerUtils.java | 14 +- .../code/quality/metrics/PmtApiCaller.java | 4 +- .../code/quality/metrics/ReviewAnalyser.java | 77 ++++---- .../code/quality/metrics/SdkGitHubClient.java | 4 +- .../code/quality/metrics/model/Constants.java | 2 +- .../quality/metrics/ChangesFinderTest.java | 79 +++------ .../quality/metrics/GithubResponsesTest.java | 166 +++++++++++++++--- 11 files changed, 225 insertions(+), 163 deletions(-) diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java index 83a6e18..45c60e7 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java @@ -34,7 +34,7 @@ import java.nio.charset.StandardCharsets; /** - * This is a utility class for calling APIs. + * Utility class for calling APIs. * * @since 1.0.0 */ @@ -46,7 +46,7 @@ private ApiUtility() { } /** - * This is used for calling the REST APIs. + * Used for calling the REST APIs. * * @param httpGet Instance of the relevant httpGet * @return String representation of the json response @@ -85,7 +85,7 @@ public static String callApi(HttpGet httpGet) throws CodeQualityMetricsException } /** - * This is used for calling the github graphql API. + * Used for calling the github graphql API. * * @param httpPost relevant instance of the httpost * @return String representation of the json response diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java index 07279e8..72e7f30 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java @@ -27,7 +27,7 @@ import java.util.Properties; /** - * This is having the main method of this application + * Class having the main method of this application * PMT Access token, patch id and github access token * should be passed in order as command line arguments when running the application. * diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java index ad33777..6f2cf8f 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java @@ -43,7 +43,7 @@ import java.util.regex.Pattern; /** - * This class is used for getting the blame information on relevant changed line ranges on relevant files from the + * Used for getting the blame information on relevant changed line ranges on relevant files from the * given patch. * * @since 1.0.0 @@ -52,13 +52,13 @@ public class ChangesFinder { private static final Logger logger = Logger.getLogger(ChangesFinder.class); - Set authorNames = new HashSet<>(); //authors of the bug lines fixed from the patch + private Set authorNames = new HashSet<>(); //authors of the bug lines fixed from the patch private Set authorCommits = new HashSet<>(); // author commits of the bug lines fixed from the patch private final JSONObject jsonStructure = new JSONObject(); private final Gson gson = new Gson(); /** - * This class is used to prevent SIC_INNER_SHOULD_BE_STATIC_ANON error that comes when building with WSO2 parent + * Used to prevent SIC_INNER_SHOULD_BE_STATIC_ANON error that comes when building with WSO2 parent * pom, as suggested by the above error an static inner class is used to prevent the error. */ private static class ListType extends TypeToken> { @@ -85,13 +85,13 @@ Set obtainRepoNamesForCommitHashes(String gitHubToken, List comm } /** - * This save the relevant repository names that contain the given commit hash in a List. + * Use to save the relevant repository names that contain the given commit hash to a List. * * @param jsonText String representation of the json response * @return A list of repository locations having the given commit hash * @throws CodeQualityMetricsException Resulted Code Quality Metrics Exception */ - List saveRepoNames(String jsonText) throws CodeQualityMetricsException { + private List saveRepoNames(String jsonText) throws CodeQualityMetricsException { List repoLocation = new ArrayList<>(); SearchApiResponse searchCommitPojo; try { @@ -106,7 +106,7 @@ List saveRepoNames(String jsonText) throws CodeQualityMetricsException { } /** - * This identifies the file changed and their relevant line ranges changed in selected repository from the given + * Used to identify the file changed and their relevant line ranges changed in selected repository from the given * commit hash. * * @param repoLocation List of repository locations having the given commit hash @@ -158,7 +158,7 @@ private void identifyChangedFile(List repoLocation, String commitHash, S } /** - * This check whether the commit in the given patch is an octopuss commit or not, if it is octopuss commit an + * Used to check whether the commit in the given patch is an octopuss commit or not, if it is octopuss commit an * exception is thrown as the current scope of the program does not support octopus commits. * * @param repositoryName current selected Repository @@ -202,7 +202,7 @@ private String checkForOctopusMerge(String repositoryName, String filePath, Stri } /** - * This is used to get the previous commit hash of the selected file before the current selected commit which + * Used to get the previous commit hash of the selected file before the current selected commit which * contained in the given patch. * * @param repositoryName current selected Repository @@ -249,7 +249,7 @@ private String findPreviousCommitOfFile(String repositoryName, String filePath, } /** - * This is used to get the previous commit date of the selected file before the current commit by sorting the + * Used to get the previous commit date of the selected file before the current commit by sorting the * commit dates. * * @param commitWithDate map contating all the commits with their respective date of the current selected @@ -266,7 +266,7 @@ private String getPreviousCommitDate(Map commitWithDate, String } /** - * This method is used to obtain the blame details of files for their previous commits. + * Used to obtain the blame details of files for their previous commits. * * @param repoLocation current selected Repository * @param fileNamesWithPreviousCommitHash map containing changed files with their prior commit hashes @@ -294,7 +294,7 @@ private void getBlameDetails(String repoLocation, Map fileNamesW } /** - * This is used to save the authors and relevant author commits of the buggy lines of code which are been fixed by + * Used to save the authors and relevant author commits of the buggy lines of code which are been fixed by * the given patch, to relevant lists. * * @param jsonText String representation of the json response received from github graphql @@ -322,12 +322,12 @@ private void findAuthorCommits(String jsonText, Map> fileNa } /** - * This method is used to identify the deleted lines from the current selected commit in given patch. + * Used to identify the deleted lines from the current selected commit in given patch. * * @param patchString patch string of the selected file received from github SDK * @return a Set of deleted lines in the above mentioned file */ - Set identifyDeletedLines(String patchString) { + private Set identifyDeletedLines(String patchString) { Set linesDeletedInSelectedFile = new HashSet<>(); Pattern pattern = Pattern.compile("@@ -"); String patches[] = pattern.split(patchString); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java index f407eab..514b27a 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java @@ -30,7 +30,7 @@ import static com.wso2.code.quality.metrics.model.Constants.COMMITS_INSIDE_GIVEN_PATCH; /** - * This is used for creating executing the program. + * Used for executing the program. * * @since 1.0.0 */ @@ -42,7 +42,7 @@ public class CodeQualityMetricsExecutor { private final String gitHubToken; /** - * This create an instance of CodeQualityMetricsExecutor class. + * Used to create an instance of CodeQualityMetricsExecutor class. * * @param pmtToken PMT Access Token * @param patchId Patch ID @@ -55,7 +55,7 @@ public CodeQualityMetricsExecutor(String pmtToken, String patchId, String gitHub } /** - * This is the entry point to this application. + * The entry point to Code Quality Metrics application. */ public void execute() { try { @@ -72,7 +72,7 @@ public void execute() { } /** - * This is used to filter out the commit hashes that belongs to the given patch. + * Used to filter out the commit hashes that belongs to the given patch. * * @return List of commithashes contained in the given patch */ diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCallerUtils.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCallerUtils.java index cd3342e..0fe5033 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCallerUtils.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCallerUtils.java @@ -34,7 +34,7 @@ import static com.wso2.code.quality.metrics.model.Constants.BEARER; /** - * This is utility class used for all github communications. + * Utility class used for all github communications. * * @since 1.0.0 */ @@ -49,7 +49,7 @@ private GithubApiCallerUtils() { } /** - * This is used for calling the github search REST API. + * Used for calling the github search REST API. * * @param commitHash commit hash to be searched * @param githubAccessToken Github access token for accessing github API @@ -77,7 +77,7 @@ public static String callSearchCommitApi(String commitHash, String githubAccessT } /** - * This is used to call github commit REST API. + * Used to call github commit REST API. * * @param repoLocation repository location * @param filePath location of the file @@ -105,7 +105,7 @@ public static String callCommitHistoryApi(String repoLocation, String filePath, } /** - * This is used to call github single commit REST API. + * Used to call github single commit REST API. * * @param repoLocation repository location * @param commitHash relevant commit hash to find details of @@ -133,7 +133,7 @@ public static String callSingleCommitApi(String repoLocation, String commitHash, } /** - * This is used to call the github review API. + * Used to call the github review API. * * @param repoLocation repository name * @param pullRequestNumber pull request number to be queried for @@ -163,7 +163,7 @@ public static String callReviewApi(String repoLocation, int pullRequestNumber, S } /** - * This is used to call the github Issue Search API. + * Used to call the github Issue Search API. * * @param commitHashToBeSearched commit hash to be searched for issues * @param githubAccessToken Github access token for accessing github API @@ -190,7 +190,7 @@ public static String callSearchIssueApi(String commitHashToBeSearched, String gi } /** - * This is used for calling the github graphql API. + * Used for calling the github graphql API. * * @param graphqlJsonStructure JSON input structure for calling the graphql API * @param githubToken Github access token for accessing github API diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java index 8e4e484..c49d8fd 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java @@ -29,14 +29,14 @@ import static com.wso2.code.quality.metrics.model.Constants.BEARER; /** - * This is used for all the WSO2 PMT communications. + * Used for all the WSO2 PMT communications. * * @since 1.0.0 */ public class PmtApiCaller { /** - * This is used for calling the WSO2 PMT REST API. + * Used for calling the WSO2 PMT REST API. * * @param accessToken WSO2 PMT access token * @param patchId Patch Id diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java index 1f42f3f..b4ba0ab 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java @@ -39,7 +39,7 @@ import static com.wso2.code.quality.metrics.model.Constants.GITHUB_REVIEW_COMMENTED; /** - * This class is used to find the reviewers of the buggy lines of code. + * Used to find the reviewers of the buggy lines of code. * * @since 1.0.0 */ @@ -47,21 +47,20 @@ public class ReviewAnalyser { private static final Logger logger = Logger.getLogger(ReviewAnalyser.class); - // to store the reviewed and approved users of thepull requests - final Set approvedReviewers = new HashSet<>(); - // to store the reviewed and commented users of the pull requests - final Set commentedReviewers = new HashSet<>(); + // to store the reviewed and approved users of the pull requests + private final Set approvedReviewers = new HashSet<>(); + private final Set commentedReviewers = new HashSet<>(); private final Gson gson = new Gson(); /** - * This class is used to prevent SIC_INNER_SHOULD_BE_STATIC_ANON error that comes when building with WSO2 parent + * Used to prevent SIC_INNER_SHOULD_BE_STATIC_ANON error that comes when building with WSO2 parent * pom. As suggested by the above error an static inner class is used to prevent the error. */ private static class ListType extends TypeToken> { } /** - * This is used to identify the pull requests that introduce the given commit to the code base. + * Used to identify the pull requests that introduce the given commit to the code base. * * @param authorCommits Commits which the relevant pull request no must be found * @param githubToken Github access token for accessing github API @@ -84,13 +83,13 @@ void findReviewers(Set authorCommits, String githubToken) { } /** - * This is used to save the pull requests with their relevant repository names in a map. + * Used to save the pull requests with their relevant repository names in a map. * * @param jsonText json reponse received from the github issue API * @return a map of pull requests againt their repository name * @throws CodeQualityMetricsException results */ - Map> savePrNumberAndRepoName(String jsonText) throws CodeQualityMetricsException { + private Map> savePrNumberAndRepoName(String jsonText) throws CodeQualityMetricsException { // map for storing the pull requests numbers against their Repository Map> prNoWithRepoName = new HashMap<>(); try { @@ -114,7 +113,7 @@ Map> savePrNumberAndRepoName(String jsonText) throws CodeQu } /** - * This is used to save the names of the users who has approved and commented on the pull requests which + * Used to save the names of the users who has approved and commented on the pull requests which * introduce bug lines of code to the code base. Approved users are saved in approvedReviewers list while * commented users are saved in commentedReviewers list. * @@ -122,39 +121,33 @@ Map> savePrNumberAndRepoName(String jsonText) throws CodeQu * relevant reposiory * @param githubToken Github access token for accessing github API */ - void saveReviewers(Map> prNoWithRepoName, String githubToken) { - for (Map.Entry> entry : prNoWithRepoName.entrySet()) { - String repositoryName = entry.getKey(); - Set prNumbers = entry.getValue(); - prNumbers.parallelStream() - .forEach((Integer prNumber) -> { - try { - String jsonText = GithubApiCallerUtils.callReviewApi(repositoryName, prNumber, githubToken); - if (jsonText != null && !jsonText.isEmpty()) { - Type listType = new ListType().getType(); - List reviews = gson.fromJson(jsonText, listType); -// List reviews = gson.fromJson(jsonText, List.class); - - // to filter Approved users - reviews.parallelStream() - .filter(review -> GITHUB_REVIEW_APPROVED.equals(review.getReviewState())) - .forEach(review -> approvedReviewers.add(review.getReviewer().getName())); - logger.debug("Users who approved the pull requests which introduce bug lines to the " + - "code base are successfully saved to approvedReviewers list"); - reviews.parallelStream() - .filter(review -> GITHUB_REVIEW_COMMENTED.equals(review.getReviewState())) - .forEach(review -> commentedReviewers.add(review.getReviewer().getName())); - logger.debug("Users who commented on the pull requests which introduce bug lines to " + - "the code base are successfully saved to approvedReviewers list"); - } else { - logger.warn("There are no records of reviews for pull request: " + prNumber + - " on " + repositoryName + " repository"); - } - } catch (CodeQualityMetricsException e) { - logger.error(e.getMessage(), e.getCause()); + private void saveReviewers(Map> prNoWithRepoName, String githubToken) { + prNoWithRepoName.forEach((repositoryName, prNumbers) -> prNumbers.parallelStream() + .forEach((Integer prNumber) -> { + try { + String jsonText = GithubApiCallerUtils.callReviewApi(repositoryName, prNumber, githubToken); + if (jsonText != null && !jsonText.isEmpty()) { + Type listType = new ListType().getType(); + List reviews = gson.fromJson(jsonText, listType); + // to filter Approved users + reviews.parallelStream() + .filter(review -> GITHUB_REVIEW_APPROVED.equals(review.getReviewState())) + .forEach(review -> approvedReviewers.add(review.getReviewer().getName())); + logger.debug("Users who approved the pull requests which introduce bug lines to the " + + "code base are successfully saved to approvedReviewers list"); + reviews.parallelStream() + .filter(review -> GITHUB_REVIEW_COMMENTED.equals(review.getReviewState())) + .forEach(review -> commentedReviewers.add(review.getReviewer().getName())); + logger.debug("Users who commented on the pull requests which introduce bug lines to " + + "the code base are successfully saved to approvedReviewers list"); + } else { + logger.warn("There are no records of reviews for pull request: " + prNumber + + " on " + repositoryName + " repository"); } - }); - } + } catch (CodeQualityMetricsException e) { + logger.error(e.getMessage(), e.getCause()); + } + })); } /** diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java index 6ad4dae..49d7e62 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java @@ -32,7 +32,7 @@ import java.util.Map; /** - * This class is used for communicating with the github REST API from egit github API. + * Used for communicating with the github REST API from egit github API. * * @since 1.0.0 */ @@ -49,7 +49,7 @@ public class SdkGitHubClient { } /** - * This method is used for saving the files changed and their relevant changed line ranges from + * Used for saving the files changed and their relevant changed line ranges from * the given commit in the given Repository. * * @param repositoryName The Repository name that contain the given commit hash diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Constants.java b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Constants.java index edb2cbe..5d5096c 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Constants.java +++ b/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Constants.java @@ -19,7 +19,7 @@ package com.wso2.code.quality.metrics.model; /** - * This is used for storing all the constants used in the Code quality metrics Application. + * Used for storing all the constants used in the Code quality metrics Application. * * @since 1.0.0 */ diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java index 5a4d114..25ba98d 100644 --- a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java @@ -18,15 +18,14 @@ package com.wso2.code.quality.metrics; -import com.wso2.code.quality.metrics.exceptions.CodeQualityMetricsException; import org.apache.commons.io.IOUtils; import org.apache.log4j.Logger; import org.junit.Test; import java.io.IOException; -import java.util.ArrayList; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.HashSet; -import java.util.List; import java.util.Set; import static org.hamcrest.CoreMatchers.is; @@ -41,14 +40,10 @@ public class ChangesFinderTest { private static final Logger logger = Logger.getLogger(ChangesFinderTest.class); - private ChangesFinder changesFinder = new ChangesFinder(); - @Test public void testIdentifyDeletedLines() { String patchString; Set actualDeltedLinesForPatchString; - patchString = readFile("patchStrings/patchString1.txt"); - actualDeltedLinesForPatchString = changesFinder.identifyDeletedLines(patchString); Set expectedDeltedLinesForPatchString1 = new HashSet<>(); expectedDeltedLinesForPatchString1.add(822); expectedDeltedLinesForPatchString1.add(823); @@ -73,13 +68,24 @@ public void testIdentifyDeletedLines() { expectedDeltedLinesForPatchString1.add(1152); expectedDeltedLinesForPatchString1.add(1153); expectedDeltedLinesForPatchString1.add(1165); - - assertThat(actualDeltedLinesForPatchString.size(), is(expectedDeltedLinesForPatchString1.size())); - assertThat(actualDeltedLinesForPatchString, is(expectedDeltedLinesForPatchString1)); - - patchString = readFile("patchStrings/patchString2.txt"); - actualDeltedLinesForPatchString = changesFinder.identifyDeletedLines(patchString); - assertTrue(actualDeltedLinesForPatchString.isEmpty()); + try { + Class changeFinderClass = Class.forName("com.wso2.code.quality.metrics.ChangesFinder"); + Object changeFinder = changeFinderClass.newInstance(); + Method identifyDeletedLinesMethod = changeFinderClass.getDeclaredMethod("identifyDeletedLines", + String.class); + patchString = readFile("patchStrings/patchString1.txt"); + actualDeltedLinesForPatchString = (Set) identifyDeletedLinesMethod.invoke(changeFinder, + patchString); + assertThat(actualDeltedLinesForPatchString.size(), is(expectedDeltedLinesForPatchString1.size())); + assertThat(actualDeltedLinesForPatchString, is(expectedDeltedLinesForPatchString1)); + patchString = readFile("patchStrings/patchString2.txt"); + actualDeltedLinesForPatchString = (Set) identifyDeletedLinesMethod.invoke(changeFinder, + patchString); + assertTrue(actualDeltedLinesForPatchString.isEmpty()); + } catch (IllegalAccessException | ClassNotFoundException | InstantiationException | NoSuchMethodException + | InvocationTargetException e) { + logger.error(e.getMessage(), e.getCause()); + } } /** @@ -98,49 +104,4 @@ private String readFile(String path) { } return result; } - - @Test - public void testObtainRepoNamesForCommitHashes() throws CodeQualityMetricsException { - Token token = new Token(); - List commitHash = new ArrayList<>(); - commitHash.add("ad0debb15f1abac020b8ba69066ae4ebec782bdc"); - Set actualAuthorCommits = changesFinder.obtainRepoNamesForCommitHashes(token.getGithubToken(), - commitHash); - Set expectedAuthorCommits = new HashSet<>(); - expectedAuthorCommits.add("90fec04e4ac05281612de8d445c5767c26433b0d"); - assertThat(actualAuthorCommits.size(), is(expectedAuthorCommits.size())); - assertThat(actualAuthorCommits, is(expectedAuthorCommits)); - } - - @Test - public void testObtainRepoNamesForCommitHashesForAuthorNames() throws CodeQualityMetricsException { - Token token = new Token(); - List commitHash = new ArrayList<>(); - commitHash.add("bba8ce79cd3373445e21dd12deffae1a7b48dca9"); - commitHash.add("1c0e28ca181a08398efbc8ba8e984d8800e23c95"); - commitHash.add("a8ddc56575ede78c6a1882df20789bb2cc04022c"); - changesFinder.obtainRepoNamesForCommitHashes(token.getGithubToken(), - commitHash); - Set expectedAuthorName = new HashSet<>(); - expectedAuthorName.add("ruchiraw"); - assertThat(changesFinder.authorNames.size(), is(expectedAuthorName.size())); - assertThat(changesFinder.authorNames, is(expectedAuthorName)); - } - - @Test - public void testObtainRepoNamesForCommitHashesForAuthorNames2() throws CodeQualityMetricsException { - Token token = new Token(); - List commitHash = new ArrayList<>(); - commitHash.add("2b1d973d089ebc3af3b9e7b893f48cf905758cf4"); - commitHash.add("eaa45529cbabc5f30a2ffaa4781821ad0a5223ab"); - changesFinder.obtainRepoNamesForCommitHashes(token.getGithubToken(), - commitHash); - Set expectedAuthorName = new HashSet<>(); - expectedAuthorName.add("Chamila"); - expectedAuthorName.add("lalaji"); - expectedAuthorName.add("Amila De Silva"); - expectedAuthorName.add("Lakmali"); - assertThat(changesFinder.authorNames.size(), is(expectedAuthorName.size())); - assertThat(changesFinder.authorNames, is(expectedAuthorName)); - } } diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java index 9c9dd61..966d850 100644 --- a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java +++ b/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java @@ -19,9 +19,14 @@ package com.wso2.code.quality.metrics; import com.wso2.code.quality.metrics.exceptions.CodeQualityMetricsException; +import org.apache.log4j.Logger; import org.junit.BeforeClass; import org.junit.Test; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -40,15 +45,46 @@ * @since 1.0.0 */ public class GithubResponsesTest { + private static final Logger logger = Logger.getLogger(GithubResponsesTest.class); private static String githubToken; + private static Class changesFinderClass; + private static Class reviewAnalyserClass; @BeforeClass public static void setupTheEnvironment() throws CodeQualityMetricsException { githubToken = new Token().getGithubToken(); + try { + changesFinderClass = Class.forName("com.wso2.code.quality.metrics.ChangesFinder"); + reviewAnalyserClass = Class.forName("com.wso2.code.quality.metrics.ReviewAnalyser"); + } catch (ClassNotFoundException e) { + logger.error(e.getMessage(), e.getCause()); + } + } + + @Test + public void testObtainRepoNamesForCommitHashes() throws CodeQualityMetricsException { + List commitHash = new ArrayList<>(); + commitHash.add("ad0debb15f1abac020b8ba69066ae4ebec782bdc"); + Set expectedAuthorCommits = new HashSet<>(); + expectedAuthorCommits.add("90fec04e4ac05281612de8d445c5767c26433b0d"); + try { + Method obtainRepoNamesForCommitHashesMethod = changesFinderClass.getDeclaredMethod + ("obtainRepoNamesForCommitHashes", String.class, List.class); + obtainRepoNamesForCommitHashesMethod.setAccessible(true); + Object changesFinder = changesFinderClass.newInstance(); + @SuppressWarnings("unchecked") + Set actualAuthorCommits = (Set) obtainRepoNamesForCommitHashesMethod.invoke + (changesFinder, githubToken, commitHash); + assertThat(actualAuthorCommits.size(), is(expectedAuthorCommits.size())); + assertThat(actualAuthorCommits, is(expectedAuthorCommits)); + } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | + InvocationTargetException e) { + logger.error(e.getMessage(), e.getCause()); + } } @Test - public void testSaveRepoNames() throws CodeQualityMetricsException { + public void testSaveRepoNames() { Map> commitHashWithRepoNames = new HashMap<>(); commitHashWithRepoNames.put("eaa45529cbabc5f30a2ffaa4781821ad0a5223ab", Collections.singletonList("wso2/carbon-apimgt")); @@ -56,58 +92,130 @@ public void testSaveRepoNames() throws CodeQualityMetricsException { Collections.singletonList("wso2/carbon-apimgt")); commitHashWithRepoNames.put("e3c3457149b109178d510aac965d5a85cc465aa0", Collections.singletonList("wso2/wso2-axis2-transports")); - for (Map.Entry> entry : commitHashWithRepoNames.entrySet()) { - String commitHash = entry.getKey(); - String jsonText = GithubApiCallerUtils.callSearchCommitApi(commitHash, githubToken); - ChangesFinder changesFinder = new ChangesFinder(); - List repoLocations = changesFinder.saveRepoNames(jsonText); - assertEquals("List of RepoLocations obtained must be same", entry.getValue(), repoLocations); - } + commitHashWithRepoNames.forEach((commitHash, repository) -> { + try { + String jsonText = GithubApiCallerUtils.callSearchCommitApi(commitHash, githubToken); + Method saveRepoNamesMethod = changesFinderClass.getDeclaredMethod("saveRepoNames", String.class); + saveRepoNamesMethod.setAccessible(true); + Object changesFinder = changesFinderClass.newInstance(); + @SuppressWarnings("unchecked") + List repoLocations = (List) saveRepoNamesMethod.invoke(changesFinder, jsonText); + assertEquals("List of RepoLocations obtained must be same", repository, repoLocations); + } catch (CodeQualityMetricsException | InstantiationException | IllegalAccessException | + NoSuchMethodException | + InvocationTargetException e) { + logger.error(e.getMessage(), e.getCause()); + } + }); } @Test public void testSavePrNumberAndRepoName() throws CodeQualityMetricsException { String jsonText = GithubApiCallerUtils.callSearchIssueApi ("0015c02145c8ec6d3bba433f2fb5e850e1d25846", githubToken); - ReviewAnalyser reviewAnalyser = new ReviewAnalyser(); - Map> actualPrNoWithRepoName = reviewAnalyser.savePrNumberAndRepoName(jsonText); Map> expectedPrNoWithRepoName = new HashMap<>(); Set expectedPrSet = new HashSet<>(); expectedPrSet.add(656); expectedPrSet.add(657); expectedPrNoWithRepoName.put("wso2/carbon-apimgt", expectedPrSet); - assertThat(actualPrNoWithRepoName, is(expectedPrNoWithRepoName)); + try { + Method savePrNumberAndRepoNameMethod = reviewAnalyserClass.getDeclaredMethod + ("savePrNumberAndRepoName", String.class); + savePrNumberAndRepoNameMethod.setAccessible(true); + Object reviewAnalyser = reviewAnalyserClass.newInstance(); + @SuppressWarnings("unchecked") + Map> actualPrNoWithRepoName2 = (Map>) + savePrNumberAndRepoNameMethod.invoke(reviewAnalyser, jsonText); + assertThat(actualPrNoWithRepoName2, is(expectedPrNoWithRepoName)); + } catch (IllegalAccessException | InstantiationException | InvocationTargetException | + NoSuchMethodException e) { + logger.error(e.getMessage(), e.getCause()); + } + } + @Test + public void testObtainRepoNamesForCommitHashesForAuthorNames() throws CodeQualityMetricsException { + List commitHash1 = new ArrayList<>(); + commitHash1.add("bba8ce79cd3373445e21dd12deffae1a7b48dca9"); + commitHash1.add("1c0e28ca181a08398efbc8ba8e984d8800e23c95"); + commitHash1.add("a8ddc56575ede78c6a1882df20789bb2cc04022c"); + Set expectedAuthorName1 = new HashSet<>(); + expectedAuthorName1.add("ruchiraw"); + obtainRepoNamesForCommitHashes(commitHash1, expectedAuthorName1); + + List commitHash2 = new ArrayList<>(); + commitHash2.add("2b1d973d089ebc3af3b9e7b893f48cf905758cf4"); + commitHash2.add("eaa45529cbabc5f30a2ffaa4781821ad0a5223ab"); + Set expectedAuthorName2 = new HashSet<>(); + expectedAuthorName2.add("Chamila"); + expectedAuthorName2.add("lalaji"); + expectedAuthorName2.add("Amila De Silva"); + expectedAuthorName2.add("Lakmali"); + obtainRepoNamesForCommitHashes(commitHash2, expectedAuthorName2); + } + + private void obtainRepoNamesForCommitHashes(List commitHash, Set expectedAuthorName) { + try { + Field authorNamesField = changesFinderClass.getDeclaredField("authorNames"); + Method obtainRepoNamesForCommitHashesMethod = changesFinderClass.getDeclaredMethod + ("obtainRepoNamesForCommitHashes", String.class, List.class); + Object changesFinder = changesFinderClass.newInstance(); + obtainRepoNamesForCommitHashesMethod.invoke(changesFinder, githubToken, commitHash); + @SuppressWarnings("unchecked") + Set actualAuthorNames = (Set) authorNamesField.get(changesFinder); + assertThat(actualAuthorNames.size(), is(expectedAuthorName.size())); + assertThat(actualAuthorNames, is(expectedAuthorName)); + } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | NoSuchFieldException | + InvocationTargetException e) { + logger.error(e.getMessage(), e.getCause()); + } } @Test public void testSaveReviewers() { - ReviewAnalyser reviewAnalyser = new ReviewAnalyser(); Map> prNoWithRepoName1 = new HashMap<>(); - Set prNumberSet = new HashSet<>(); - prNumberSet.add(656); - prNumberSet.add(657); - prNoWithRepoName1.put("wso2/carbon-apimgt", prNumberSet); + Set prNumberSet1 = new HashSet<>(); + prNumberSet1.add(656); + prNumberSet1.add(657); + prNoWithRepoName1.put("wso2/carbon-apimgt", prNumberSet1); + // since no reviewers for pull requests 656,657 List expectedApprovedReviewers1 = Collections.emptyList(); List expectedCommentedReviewers1 = Collections.emptyList(); - reviewAnalyser.saveReviewers(prNoWithRepoName1, githubToken); - assertThat("List of approved users ", reviewAnalyser.approvedReviewers, - containsInAnyOrder(expectedApprovedReviewers1.toArray())); - assertThat("List of commented users ", reviewAnalyser.commentedReviewers, - containsInAnyOrder(expectedCommentedReviewers1.toArray())); - - reviewAnalyser.approvedReviewers.clear(); - reviewAnalyser.commentedReviewers.clear(); + testSaveReviewersForPrs(prNoWithRepoName1, expectedApprovedReviewers1, + expectedCommentedReviewers1); Map> prNoWithRepoName2 = new HashMap<>(); Set prNumberSet2 = new HashSet<>(); prNumberSet2.add(885); prNoWithRepoName2.put("wso2/product-is", prNumberSet2); List expectedApprovedReviewers2 = Collections.singletonList("darshanasbg"); List expectedCommentedReviewers2 = Collections.singletonList("isharak"); - reviewAnalyser.saveReviewers(prNoWithRepoName2, githubToken); - assertThat("List of approved users ", reviewAnalyser.approvedReviewers, - containsInAnyOrder(expectedApprovedReviewers2.toArray())); - assertThat("List of commented users ", reviewAnalyser.commentedReviewers, - containsInAnyOrder(expectedCommentedReviewers2.toArray())); + testSaveReviewersForPrs(prNoWithRepoName2, expectedApprovedReviewers2, + expectedCommentedReviewers2); + } + + private void testSaveReviewersForPrs(Map> prNoWithRepoName1, List + expectedApprovedReviewers1, List expectedCommentedReviewers1) { + try { + Field approvedReviewersField = reviewAnalyserClass.getDeclaredField("approvedReviewers"); + Field commentedReviewersField = reviewAnalyserClass.getDeclaredField("commentedReviewers"); + approvedReviewersField.setAccessible(true); + commentedReviewersField.setAccessible(true); + Method saveReviewersMethod = reviewAnalyserClass.getDeclaredMethod("saveReviewers", Map.class, + String.class); + saveReviewersMethod.setAccessible(true); + Object reviewAnalyser = reviewAnalyserClass.newInstance(); + saveReviewersMethod.invoke(reviewAnalyser, prNoWithRepoName1, githubToken); + @SuppressWarnings("unchecked") + Set actualApprovedReviewers = (Set) approvedReviewersField.get(reviewAnalyser); + @SuppressWarnings("unchecked") + Set actualCommentedReviewers = (Set) commentedReviewersField.get(reviewAnalyser); + assertThat("List of approved users ", actualApprovedReviewers, containsInAnyOrder + (expectedApprovedReviewers1.toArray())); + assertThat("List of commented users ", actualCommentedReviewers, containsInAnyOrder + (expectedCommentedReviewers1.toArray())); + } catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException | + NoSuchFieldException e) { + logger.error(e.getMessage(), e.getCause()); + } } } From 4ceb48fda4c3b05f831e06a5d78992e69474ff80 Mon Sep 17 00:00:00 2001 From: kasun Date: Mon, 24 Apr 2017 09:23:02 +0530 Subject: [PATCH 62/62] Move Files outside --- README.md | 4 +- .../pom.xml => pom.xml | 0 .../wso2/code/quality/metrics/ApiUtility.java | 6 +- .../code/quality/metrics/Application.java | 6 +- .../code/quality/metrics/ChangesFinder.java | 60 ++++++++++--------- .../metrics/CodeQualityMetricsExecutor.java | 3 +- .../quality/metrics/GithubApiCallerUtils.java | 0 .../code/quality/metrics/PmtApiCaller.java | 0 .../code/quality/metrics/ReviewAnalyser.java | 0 .../code/quality/metrics/SdkGitHubClient.java | 4 +- .../CodeQualityMetricsException.java | 0 .../code/quality/metrics/model/Author.java | 0 .../code/quality/metrics/model/Commit.java | 0 .../model/CommitHistoryApiResponse.java | 0 .../code/quality/metrics/model/Constants.java | 0 .../metrics/model/GraphQlResponse.java | 0 .../code/quality/metrics/model/Graphql.java | 0 .../quality/metrics/model/GraphqlAuthor.java | 0 .../quality/metrics/model/GraphqlBlame.java | 0 .../quality/metrics/model/GraphqlCommit.java | 0 .../quality/metrics/model/GraphqlData.java | 0 .../quality/metrics/model/GraphqlObject.java | 0 .../quality/metrics/model/GraphqlRange.java | 0 .../metrics/model/GraphqlRepository.java | 0 .../metrics/model/IssueApiResponse.java | 0 .../quality/metrics/model/ParentCommit.java | 0 .../quality/metrics/model/Repository.java | 0 .../quality/metrics/model/RepositoryItem.java | 0 .../metrics/model/ReviewApiResponse.java | 0 .../code/quality/metrics/model/Reviewer.java | 0 .../metrics/model/SearchApiResponse.java | 0 .../quality/metrics/model/SearchItem.java | 0 .../model/SingleCommitApiResponse.java | 0 .../main/resources/log4j.properties | 3 +- .../main/resources/tokens.properties | 0 .../src => src}/main/resources/url.properties | 0 .../quality/metrics/ChangesFinderTest.java | 0 .../CodeQualityMetricsExecutorTest.java | 0 .../quality/metrics/GithubResponsesTest.java | 0 .../quality/metrics/GithubSdkClientTest.java | 0 .../com/wso2/code/quality/metrics/Token.java | 0 .../resources/patchStrings/patchString1.txt | 0 .../resources/patchStrings/patchString2.txt | 0 43 files changed, 45 insertions(+), 41 deletions(-) rename org.wso2.codequalitymatrices/pom.xml => pom.xml (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/ApiUtility.java (97%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/Application.java (89%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/ChangesFinder.java (87%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java (97%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/GithubApiCallerUtils.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java (95%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/exceptions/CodeQualityMetricsException.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/Author.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/Commit.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/Constants.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/GraphQlResponse.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/Graphql.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/GraphqlAuthor.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/GraphqlBlame.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/GraphqlCommit.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/GraphqlData.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/GraphqlObject.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/GraphqlRange.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/GraphqlRepository.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/IssueApiResponse.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/ParentCommit.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/Repository.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/RepositoryItem.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/ReviewApiResponse.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/Reviewer.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/SearchApiResponse.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/SearchItem.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/java/com/wso2/code/quality/metrics/model/SingleCommitApiResponse.java (100%) rename {org.wso2.codequalitymatrices/src => src}/main/resources/log4j.properties (94%) rename {org.wso2.codequalitymatrices/src => src}/main/resources/tokens.properties (100%) rename {org.wso2.codequalitymatrices/src => src}/main/resources/url.properties (100%) rename {org.wso2.codequalitymatrices/src => src}/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java (100%) rename {org.wso2.codequalitymatrices/src => src}/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java (100%) rename {org.wso2.codequalitymatrices/src => src}/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java (100%) rename {org.wso2.codequalitymatrices/src => src}/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java (100%) rename {org.wso2.codequalitymatrices/src => src}/test/java/com/wso2/code/quality/metrics/Token.java (100%) rename {org.wso2.codequalitymatrices/src => src}/test/resources/patchStrings/patchString1.txt (100%) rename {org.wso2.codequalitymatrices/src => src}/test/resources/patchStrings/patchString2.txt (100%) diff --git a/README.md b/README.md index af4f77a..b64ee3b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Since there is no Github REST API yet deployed for obtaining blame details of fi ## Installation ### Prerequisites * [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) installed. -* [Java](http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html) installed +* [Java](http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html) installed. * [Apache Maven](https://maven.apache.org/download.cgi) installed. After cloning or downloading the repository open `Eclipse IDE` or `IntelliJ IDEA` and open project’s `pom.xml`(Import all the dependencies if required). @@ -25,7 +25,7 @@ After cloning or downloading the repository open `Eclipse IDE` or `IntelliJ IDEA ## Running Samples It is required to provide the relevant WSO2 patch name as a command line argument to obtain relevant authors and reviewers of code lines been modified from the given patch. -Run following samples and check with outputs +Run following samples and check with outputs, 1. WSO2-CARBON-PATCH-4.4.0-0680 Authors : [Lakmali, Amila De Silva, lalaji, Chamila] diff --git a/org.wso2.codequalitymatrices/pom.xml b/pom.xml similarity index 100% rename from org.wso2.codequalitymatrices/pom.xml rename to pom.xml diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java b/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java similarity index 97% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java rename to src/main/java/com/wso2/code/quality/metrics/ApiUtility.java index 45c60e7..ef3d6d5 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java +++ b/src/main/java/com/wso2/code/quality/metrics/ApiUtility.java @@ -108,11 +108,11 @@ public static String callGraphQlApi(HttpPost httpPost) throws CodeQualityMetrics logger.debug("The response received from the Github GraphQL converted to a JSON text successfully"); } } else { - throw new CodeQualityMetricsException("Error occurred while calling the API, the response code is " + - responseCode); + throw new CodeQualityMetricsException("Error occurred while calling the graphQL API, the response " + + "code is " + responseCode); } } catch (UnsupportedEncodingException e) { - throw new CodeQualityMetricsException("Encoding error occured before calling the github graphQL API", e); + throw new CodeQualityMetricsException("Encoding error occurred before calling the github graphQL API", e); } catch (ClientProtocolException e) { throw new CodeQualityMetricsException("Client protocol exception occurred when calling the github" + " graphQL API", e); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java b/src/main/java/com/wso2/code/quality/metrics/Application.java similarity index 89% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java rename to src/main/java/com/wso2/code/quality/metrics/Application.java index 72e7f30..aa6d7ce 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/Application.java +++ b/src/main/java/com/wso2/code/quality/metrics/Application.java @@ -55,9 +55,9 @@ public static void main(String[] args) { "properties object", e); } } else { - logger.error("Command line arguments were not given correctly to start the execution"); - logger.debug("Please enter PMT Access token, patch id and github access token in order as command " + - "line arguments to initiate the program"); + logger.error("Incorrect command line arguments were given"); + logger.debug("Please enter only the required patch id as the command line argument to initiate the " + + "program"); } } } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java b/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java similarity index 87% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java rename to src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java index 6f2cf8f..105743c 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java +++ b/src/main/java/com/wso2/code/quality/metrics/ChangesFinder.java @@ -65,7 +65,7 @@ private static class ListType extends TypeToken> } /** - * This is used for obtaining the repositories that contain the relevant commits belongs to the given patch. + * Used for obtaining the repositories that contain the relevant commits belongs to the given patch. * * @param gitHubToken github token for accessing github API * @param commitHashes List of commits that belongs to the given patch @@ -119,32 +119,36 @@ private void identifyChangedFile(List repoLocation, String commitHash, S .filter(repositoryName -> StringUtils.contains(repositoryName, "wso2/")) .forEach(repositoryName -> { Map fileNamesWithPatchString; + tryBlock: try { fileNamesWithPatchString = sdkGitHubClient.getFilesChanged(repositoryName, commitHash); Map> fileNamesWithDeletedLineNumbers = new HashMap<>(); Map fileNamesWithPreviousCommitHash = new HashMap<>(); - if (fileNamesWithPatchString != null) { - /* looping from one file to file and saving deleted lines against the file name in another + if (fileNamesWithPatchString.isEmpty()) { + break tryBlock; + } + /* looping from one file to file and saving deleted lines against the file name in another map */ - fileNamesWithPatchString.forEach((fileName, patchString) -> { - Set deletedLines = identifyDeletedLines(patchString); - String previousCommitHashOfFile; - //for omitting files without having deleted lines in other words newly created files - if (deletedLines.size() > 0) { - fileNamesWithDeletedLineNumbers.put(fileName, deletedLines); - previousCommitHashOfFile = checkForOctopusMerge(repositoryName, fileName, - commitHash, gitHubToken); - if (previousCommitHashOfFile != null && !previousCommitHashOfFile.isEmpty()) { - fileNamesWithPreviousCommitHash.put(fileName, previousCommitHashOfFile); - } else { - logger.warn("The changes from " + commitHash + " on " + fileName + " file " + - "may have been reversed from another commit on the same PR, so " + - "commit " + commitHash + " does not appear in history of current " + - "file due to git's history simplification when listing history"); - } + fileNamesWithPatchString.forEach((fileName, patchString) -> { + Set deletedLines = identifyDeletedLines(patchString); + String previousCommitHashOfFile; + //for omitting files without having deleted lines in other words newly created files + if (deletedLines.size() > 0) { + fileNamesWithDeletedLineNumbers.put(fileName, deletedLines); + previousCommitHashOfFile = checkForOctopusMerge(repositoryName, fileName, + commitHash, gitHubToken); + if (previousCommitHashOfFile != null && !previousCommitHashOfFile.isEmpty()) { + fileNamesWithPreviousCommitHash.put(fileName, previousCommitHashOfFile); + } else { + logger.warn("The changes from " + commitHash + " on " + fileName + " file " + + "may have been reversed from another commit on the same PR, so " + + "commit " + commitHash + " does not appear in history of current " + + "file due to git's history simplification when listing history"); } - }); - } + } else { + logger.debug(fileName + " filename is a newly created file"); + } + }); getBlameDetails(repositoryName, fileNamesWithPreviousCommitHash, fileNamesWithDeletedLineNumbers, gitHubToken); } catch (CodeQualityMetricsException e) { @@ -238,10 +242,10 @@ private String findPreviousCommitOfFile(String repositoryName, String filePath, } } else { return null; + /*the changes from given commit to the current selected file may have been reversed from another commit, + so the given commit does not appear in history of the current file due to git's history simplification + when listing history*/ } - /*the changes from given commit to the current selected file may have been reversed from another commit, so - the given commit does not appear in history of the current file due to git's history simplification when - listing history*/ } catch (CodeQualityMetricsException e) { logger.error(e.getMessage(), e.getCause()); } @@ -258,7 +262,7 @@ private String findPreviousCommitOfFile(String repositoryName, String filePath, * @return previous commit date of the current selected file */ private String getPreviousCommitDate(Map commitWithDate, String latestCommitDate) { - //creating a tempory list for sorting the date in ascending order + //creating a temporary list for sorting the date in ascending order List sortedCommitDates = new ArrayList<>(commitWithDate.values()); Collections.sort(sortedCommitDates); int indexOfLatestcommit = sortedCommitDates.indexOf(latestCommitDate); @@ -322,7 +326,7 @@ private void findAuthorCommits(String jsonText, Map> fileNa } /** - * Used to identify the deleted lines from the current selected commit in given patch. + * Used to identify the deleted lines in the selected file from the current selected commit in given patch. * * @param patchString patch string of the selected file received from github SDK * @return a Set of deleted lines in the above mentioned file @@ -334,11 +338,11 @@ private Set identifyDeletedLines(String patchString) { for (String patchRange : patches) { Scanner scanner = new Scanner(patchRange); int lineNumber = 0; - //for finding the starting line number for the modified range. + //for finding the starting line number of the modified range. if (scanner.hasNext()) { String patchLine = scanner.nextLine(); String words[] = patchLine.split(","); - //String at the first index of word array is the staring line number of the modified range + //String at the first index of word array is the starting line number of the modified range lineNumber = Integer.parseInt(words[0]); } //for finding the deleted lines in the string diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java b/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java similarity index 97% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java rename to src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java index 514b27a..74e8810 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java +++ b/src/main/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutor.java @@ -74,7 +74,7 @@ public void execute() { /** * Used to filter out the commit hashes that belongs to the given patch. * - * @return List of commithashes contained in the given patch + * @return List of commit hashes contained in the given patch */ List findCommitHashesInPatch() throws CodeQualityMetricsException { PmtApiCaller pmtApiCaller = new PmtApiCaller(); @@ -89,6 +89,7 @@ List findCommitHashesInPatch() throws CodeQualityMetricsException { List pmtResponse = gson.fromJson(jsonText, List.class); for (Object pmtEntry : pmtResponse) { if (pmtEntry instanceof Map) { + @SuppressWarnings("unchecked") Map entryMap = (Map) pmtEntry; if (COMMITS_INSIDE_GIVEN_PATCH.equals(entryMap.get("name"))) { commitHashes = (List) entryMap.get("value"); diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCallerUtils.java b/src/main/java/com/wso2/code/quality/metrics/GithubApiCallerUtils.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/GithubApiCallerUtils.java rename to src/main/java/com/wso2/code/quality/metrics/GithubApiCallerUtils.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java b/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java rename to src/main/java/com/wso2/code/quality/metrics/PmtApiCaller.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java b/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java rename to src/main/java/com/wso2/code/quality/metrics/ReviewAnalyser.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java b/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java similarity index 95% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java rename to src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java index 49d7e62..e400a82 100644 --- a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java +++ b/src/main/java/com/wso2/code/quality/metrics/SdkGitHubClient.java @@ -71,8 +71,8 @@ Map getFilesChanged(String repositoryName, String commitHash) " changed and their relevant patch strings are saved to the map successfully"); } } catch (IOException e) { - throw new CodeQualityMetricsException("IO Exception occurred when getting the commit of given SHA from " + - "the given Repository ", e); + throw new CodeQualityMetricsException("IO Exception occurred when searching for files changed on the " + + "commit " + commitHash + " on " + repositoryName + " Repository", e); } return fileNamesAndPatches; } diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/exceptions/CodeQualityMetricsException.java b/src/main/java/com/wso2/code/quality/metrics/exceptions/CodeQualityMetricsException.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/exceptions/CodeQualityMetricsException.java rename to src/main/java/com/wso2/code/quality/metrics/exceptions/CodeQualityMetricsException.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Author.java b/src/main/java/com/wso2/code/quality/metrics/model/Author.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Author.java rename to src/main/java/com/wso2/code/quality/metrics/model/Author.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Commit.java b/src/main/java/com/wso2/code/quality/metrics/model/Commit.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Commit.java rename to src/main/java/com/wso2/code/quality/metrics/model/Commit.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java b/src/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java rename to src/main/java/com/wso2/code/quality/metrics/model/CommitHistoryApiResponse.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Constants.java b/src/main/java/com/wso2/code/quality/metrics/model/Constants.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Constants.java rename to src/main/java/com/wso2/code/quality/metrics/model/Constants.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphQlResponse.java b/src/main/java/com/wso2/code/quality/metrics/model/GraphQlResponse.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphQlResponse.java rename to src/main/java/com/wso2/code/quality/metrics/model/GraphQlResponse.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Graphql.java b/src/main/java/com/wso2/code/quality/metrics/model/Graphql.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Graphql.java rename to src/main/java/com/wso2/code/quality/metrics/model/Graphql.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlAuthor.java b/src/main/java/com/wso2/code/quality/metrics/model/GraphqlAuthor.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlAuthor.java rename to src/main/java/com/wso2/code/quality/metrics/model/GraphqlAuthor.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlBlame.java b/src/main/java/com/wso2/code/quality/metrics/model/GraphqlBlame.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlBlame.java rename to src/main/java/com/wso2/code/quality/metrics/model/GraphqlBlame.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlCommit.java b/src/main/java/com/wso2/code/quality/metrics/model/GraphqlCommit.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlCommit.java rename to src/main/java/com/wso2/code/quality/metrics/model/GraphqlCommit.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlData.java b/src/main/java/com/wso2/code/quality/metrics/model/GraphqlData.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlData.java rename to src/main/java/com/wso2/code/quality/metrics/model/GraphqlData.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlObject.java b/src/main/java/com/wso2/code/quality/metrics/model/GraphqlObject.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlObject.java rename to src/main/java/com/wso2/code/quality/metrics/model/GraphqlObject.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlRange.java b/src/main/java/com/wso2/code/quality/metrics/model/GraphqlRange.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlRange.java rename to src/main/java/com/wso2/code/quality/metrics/model/GraphqlRange.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlRepository.java b/src/main/java/com/wso2/code/quality/metrics/model/GraphqlRepository.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/GraphqlRepository.java rename to src/main/java/com/wso2/code/quality/metrics/model/GraphqlRepository.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/IssueApiResponse.java b/src/main/java/com/wso2/code/quality/metrics/model/IssueApiResponse.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/IssueApiResponse.java rename to src/main/java/com/wso2/code/quality/metrics/model/IssueApiResponse.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ParentCommit.java b/src/main/java/com/wso2/code/quality/metrics/model/ParentCommit.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ParentCommit.java rename to src/main/java/com/wso2/code/quality/metrics/model/ParentCommit.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Repository.java b/src/main/java/com/wso2/code/quality/metrics/model/Repository.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Repository.java rename to src/main/java/com/wso2/code/quality/metrics/model/Repository.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/RepositoryItem.java b/src/main/java/com/wso2/code/quality/metrics/model/RepositoryItem.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/RepositoryItem.java rename to src/main/java/com/wso2/code/quality/metrics/model/RepositoryItem.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ReviewApiResponse.java b/src/main/java/com/wso2/code/quality/metrics/model/ReviewApiResponse.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/ReviewApiResponse.java rename to src/main/java/com/wso2/code/quality/metrics/model/ReviewApiResponse.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Reviewer.java b/src/main/java/com/wso2/code/quality/metrics/model/Reviewer.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/Reviewer.java rename to src/main/java/com/wso2/code/quality/metrics/model/Reviewer.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SearchApiResponse.java b/src/main/java/com/wso2/code/quality/metrics/model/SearchApiResponse.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SearchApiResponse.java rename to src/main/java/com/wso2/code/quality/metrics/model/SearchApiResponse.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SearchItem.java b/src/main/java/com/wso2/code/quality/metrics/model/SearchItem.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SearchItem.java rename to src/main/java/com/wso2/code/quality/metrics/model/SearchItem.java diff --git a/org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SingleCommitApiResponse.java b/src/main/java/com/wso2/code/quality/metrics/model/SingleCommitApiResponse.java similarity index 100% rename from org.wso2.codequalitymatrices/src/main/java/com/wso2/code/quality/metrics/model/SingleCommitApiResponse.java rename to src/main/java/com/wso2/code/quality/metrics/model/SingleCommitApiResponse.java diff --git a/org.wso2.codequalitymatrices/src/main/resources/log4j.properties b/src/main/resources/log4j.properties similarity index 94% rename from org.wso2.codequalitymatrices/src/main/resources/log4j.properties rename to src/main/resources/log4j.properties index 9640d66..c06a553 100644 --- a/org.wso2.codequalitymatrices/src/main/resources/log4j.properties +++ b/src/main/resources/log4j.properties @@ -16,13 +16,12 @@ # # # Define the root logger with appender file -logs=/home/kasun/Documents/log4j log4j.rootLogger=DEBUG, APPENDER1,CONSOLE #Limiting logging level of log4j to WARN level log4j.logger.org.apache.http=WARN #Define the file appender log4j.appender.APPENDER1=org.apache.log4j.RollingFileAppender -log4j.appender.APPENDER1.File=${logs}/log.out +log4j.appender.APPENDER1.File=${user.home}/log.out log4j.appender.APPENDER1.MaxFileSize=10KB log4j.appender.APPENDER1.MaxBackupIndex=5 # Define the layout for file appender diff --git a/org.wso2.codequalitymatrices/src/main/resources/tokens.properties b/src/main/resources/tokens.properties similarity index 100% rename from org.wso2.codequalitymatrices/src/main/resources/tokens.properties rename to src/main/resources/tokens.properties diff --git a/org.wso2.codequalitymatrices/src/main/resources/url.properties b/src/main/resources/url.properties similarity index 100% rename from org.wso2.codequalitymatrices/src/main/resources/url.properties rename to src/main/resources/url.properties diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java b/src/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java similarity index 100% rename from org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java rename to src/test/java/com/wso2/code/quality/metrics/ChangesFinderTest.java diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java b/src/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java similarity index 100% rename from org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java rename to src/test/java/com/wso2/code/quality/metrics/CodeQualityMetricsExecutorTest.java diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java b/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java similarity index 100% rename from org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java rename to src/test/java/com/wso2/code/quality/metrics/GithubResponsesTest.java diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java b/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java similarity index 100% rename from org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java rename to src/test/java/com/wso2/code/quality/metrics/GithubSdkClientTest.java diff --git a/org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/Token.java b/src/test/java/com/wso2/code/quality/metrics/Token.java similarity index 100% rename from org.wso2.codequalitymatrices/src/test/java/com/wso2/code/quality/metrics/Token.java rename to src/test/java/com/wso2/code/quality/metrics/Token.java diff --git a/org.wso2.codequalitymatrices/src/test/resources/patchStrings/patchString1.txt b/src/test/resources/patchStrings/patchString1.txt similarity index 100% rename from org.wso2.codequalitymatrices/src/test/resources/patchStrings/patchString1.txt rename to src/test/resources/patchStrings/patchString1.txt diff --git a/org.wso2.codequalitymatrices/src/test/resources/patchStrings/patchString2.txt b/src/test/resources/patchStrings/patchString2.txt similarity index 100% rename from org.wso2.codequalitymatrices/src/test/resources/patchStrings/patchString2.txt rename to src/test/resources/patchStrings/patchString2.txt