Skip to content

Commit

Permalink
Rename the package
Browse files Browse the repository at this point in the history
  • Loading branch information
kasunsiyambalapitiya committed Mar 31, 2017
1 parent 673a71a commit 123494b
Show file tree
Hide file tree
Showing 31 changed files with 189 additions and 137 deletions.
37 changes: 25 additions & 12 deletions org.wso2.codequalitymatrices/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.wso2</groupId>
<artifactId>wso2</artifactId>
<version>5</version>
</parent>
<groupId>org.wso2.codeQualityMatrices</groupId>
<artifactId>CodeQualityMatrices</artifactId>

<groupId>org.wso2.code-quality-metrics</groupId>
<artifactId>code-quality-metrics</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>CodeQualityMatrices</name>
<name>code-quality-metrics</name>
<url>http://maven.apache.org</url>

<properties>
<java-version>1.8</java-version>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>3.8.1</junit.version>
<log4j.version>1.2.17</log4j.version>
<org.json.version>20160810</org.json.version>
<com.google.code.gson.version>2.8.0</com.google.code.gson.version>
<org.eclipse.mylyn.github.version>2.1.5</org.eclipse.mylyn.github.version>
<com.googlecode.json-simple.version>1.1.1</com.googlecode.json-simple.version>
<org.apache.httpcomponents.version>4.5.2</org.apache.httpcomponents.version>
<org.apache.commons.version>3.5</org.apache.commons.version>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
<version>${org.json.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
<version>${com.google.code.gson.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.mylyn.github</groupId>
<artifactId>org.eclipse.egit.github.core</artifactId>
<version>2.1.5</version>
<version>${org.eclipse.mylyn.github.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
<version>${org.apache.httpcomponents.version}</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<version>${com.googlecode.json-simple.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
<version>${org.apache.commons.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
* under the License.
*/

package com.wso2.code.quality.matrices;
package com.wso2.code.quality.metrics;

import org.apache.log4j.Logger;

/**
* 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);
Expand All @@ -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 " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,7 +72,7 @@ public Set<String> obtainRepoNamesForCommitHashes(String gitHubToken, List<Strin
try {
String jsonText = githubApiCaller.callSearchCommitApi(commitHash, gitHubToken);
saveRepoNames(jsonText, commitHash, gitHubToken);
} catch (CodeQualityMatricesException e) {
} catch (CodeQualityMetricsException e) {
logger.debug(e.getMessage(), e.getCause());
}
});
Expand All @@ -87,13 +87,13 @@ public Set<String> obtainRepoNamesForCommitHashes(String gitHubToken, List<Strin
* @param gitHubToken Github access token for accessing github API
*/
private void saveRepoNames(String jsonText, String commitHash, String gitHubToken) throws
CodeQualityMatricesException {
CodeQualityMetricsException {
List<String> 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()));
Expand All @@ -111,7 +111,7 @@ private void saveRepoNames(String jsonText, String commitHash, String gitHubToke
Map<String, List<String>> fileNamesWithPatcheString = null;
try {
fileNamesWithPatcheString = sdkGitHubClient.getFilesChanged(repositoryName, commitHash);
} catch (CodeQualityMatricesException e) {
} catch (CodeQualityMetricsException e) {
logger.debug(e.getMessage(), e.getCause());
}
if (fileNamesWithPatcheString != null) {
Expand All @@ -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());
}
});
Expand Down Expand Up @@ -199,7 +199,7 @@ private void saveRelaventEditLineNumbers(List<String> fileNames, List<String> 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, "/");
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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<String> 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 -> {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading

0 comments on commit 123494b

Please sign in to comment.