From ddf0f9fb1d0daf242ba659f7bf4ee8b51b8b7c82 Mon Sep 17 00:00:00 2001 From: Rodrigo Alves Date: Wed, 17 Jul 2013 23:21:31 -0300 Subject: [PATCH 01/17] Creating constant to represent the search for projects without limits with Groundhog. Related to #6 --- .../main/br/ufpe/cin/groundhog/search/SearchGitHub.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java b/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java index 0460741..9d35aea 100644 --- a/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java +++ b/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java @@ -30,7 +30,9 @@ * @author fjsj, gustavopinto, Rodrigo Alves */ public class SearchGitHub implements ForgeSearch { - private static final String ROOT = "https://api.github.com"; + public static int INFINITY = -1; + + private static final String ROOT = "https://api.github.com"; private static final String REPO_API = "https://api.github.com"; private static final String USERS_API = "https://api.github.com/users/"; @@ -374,4 +376,4 @@ public void checkAPIErrorMessage(JsonElement jsonElement) throws GroundhogExcept get("message").toString() ); } } -} \ No newline at end of file +} From 181c87782c0c4df86d475c0a3b5734470d38c9e7 Mon Sep 17 00:00:00 2001 From: Rodrigo Alves Date: Wed, 17 Jul 2013 23:22:42 -0300 Subject: [PATCH 02/17] Improving documentation. Still a lot to add. Everything that we add to Groundhog that changes an existing component or adds a new functionality should be documented from now on. Javadocs aren't enough and examples are very helpful. So, for example, if a feature of fetching Pull Requests is added, there should be at least one example about its usage in the README or in the project's Wiki https://github.com/spgroup/groundhog/wiki --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index 88c4aad..dc1757b 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,34 @@ In order for it to behave like an Eclipse project, you'll need to install the Ma `$ mvn eclipse:eclipse` +### Generating the JAR + +Generate the JAR file for the Groundhog project. + +Eclipse users can go to `File > Export > Runnable Jar File` and enter the `CmdMain` class for the option "Launch Configuration". + ## Usage +### Fetching Metadata + +#### Project + +You can use Groundhog to fetch metadata on a list of projects that attend to a criteria + +```java +// Create a GitHub search object +Injector injector = Guice.createInjector(new SearchModule()); +SearchGitHub searchGitHub = injector.getInstance(SearchGitHub.class); + +// Search for projects named "opencv" starting in page 1 and stoping and going until the 3rd project +searchGitHub.getProjects("opencv", 1, 3); +``` + +Alternatively, you can search for projects without setting the limiting point. In this case Groundhog will fetch projects until your API limit is exceeded. + +```java +searchGitHub.getProjects("eclipse", 1, SearchGitHub.INFINITY) +``` ### Generating the JAR Generate the JAR file for the Groundhog project. From e61fbf2ccab13b7e4f0c93c6ef6d1d34e1701477 Mon Sep 17 00:00:00 2001 From: Rodrigo Alves Date: Wed, 17 Jul 2013 23:34:39 -0300 Subject: [PATCH 03/17] Improving docs --- README.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dc1757b..5ec6122 100644 --- a/README.md +++ b/README.md @@ -45,11 +45,25 @@ Alternatively, you can search for projects without setting the limiting point. I ```java searchGitHub.getProjects("eclipse", 1, SearchGitHub.INFINITY) ``` -### Generating the JAR -Generate the JAR file for the Groundhog project. +### Issues -Eclipse users can go to `File > Export > Runnable Jar File` and enter the `CmdMain` class for the option "Launch Configuration". +Issues are objects that only make sense from a Project perspective. + +To fetch the Issues of a given project using Groundhog you should first create the Project and then tell Groundhog to hit the API and get the data. + +```java +User user = new User("joyent"); // Create the User object +Project pr = new Project(user, "node"); // Create the Project object + +// Tell Groundhog to fetch all Issues of that project and assign them the the Project object: +pr.setIssues(searchGitHub.getAllProjectIssues(pr)); + +System.out.println("Listing 'em Issues..."); +for (int k = 0; k < pr.getIssues().size(); k++) { + System.out.println(pr.getIssues().get(k).getTitle()); +} +``` ### Running Groundhog From 067d6ca1eb87c0bd32244a573ddacdbbb7190e8d Mon Sep 17 00:00:00 2001 From: Rodrigo Alves Date: Wed, 17 Jul 2013 23:46:30 -0300 Subject: [PATCH 04/17] Adding two new sections to the README --- README.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5ec6122..431dca8 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Alternatively, you can search for projects without setting the limiting point. I searchGitHub.getProjects("eclipse", 1, SearchGitHub.INFINITY) ``` -### Issues +#### Issues Issues are objects that only make sense from a Project perspective. @@ -61,10 +61,27 @@ pr.setIssues(searchGitHub.getAllProjectIssues(pr)); System.out.println("Listing 'em Issues..."); for (int k = 0; k < pr.getIssues().size(); k++) { - System.out.println(pr.getIssues().get(k).getTitle()); + System.out.println(pr.getIssues().get(k).getTitle()); } ``` +#### Milestones + +Just like Issues, Groundhog lets you fetch the list of Milestones of a project, too. + +```java +pr.setIssues(searchGitHub.getAllProjectMilestones(pr)); +``` + +#### Languages + +Software projects are often composed of more than one programming language. Groundhog lets you fetch the list of languages of a project among its LoC (lines of code) count. + +```java +// Returns a List of Language objects for each language of project "pr" +searchGitHub.fetchProjectLanguages(pr); +``` + ### Running Groundhog Search GitHub for projects matching "phonegap-facebook-plugin" and place the results (if any) in a folder called metrics: From e1625b1fa8a1dc4e30e213620b41dfccdaa52435 Mon Sep 17 00:00:00 2001 From: Rodrigo Alves Date: Wed, 17 Jul 2013 23:46:30 -0300 Subject: [PATCH 05/17] Adding two new sections to the README --- README.md | 21 +++++++++++++++++++-- pom.xml | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5ec6122..431dca8 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Alternatively, you can search for projects without setting the limiting point. I searchGitHub.getProjects("eclipse", 1, SearchGitHub.INFINITY) ``` -### Issues +#### Issues Issues are objects that only make sense from a Project perspective. @@ -61,10 +61,27 @@ pr.setIssues(searchGitHub.getAllProjectIssues(pr)); System.out.println("Listing 'em Issues..."); for (int k = 0; k < pr.getIssues().size(); k++) { - System.out.println(pr.getIssues().get(k).getTitle()); + System.out.println(pr.getIssues().get(k).getTitle()); } ``` +#### Milestones + +Just like Issues, Groundhog lets you fetch the list of Milestones of a project, too. + +```java +pr.setIssues(searchGitHub.getAllProjectMilestones(pr)); +``` + +#### Languages + +Software projects are often composed of more than one programming language. Groundhog lets you fetch the list of languages of a project among its LoC (lines of code) count. + +```java +// Returns a List of Language objects for each language of project "pr" +searchGitHub.fetchProjectLanguages(pr); +``` + ### Running Groundhog Search GitHub for projects matching "phonegap-facebook-plugin" and place the results (if any) in a folder called metrics: diff --git a/pom.xml b/pom.xml index 4907caa..b0894fa 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 groundhog groundhog - 0.0.1-SNAPSHOT + 0.1.0 jgit-repository From 7fadab529e0a04bfed7af294bf27ec131aeaae66 Mon Sep 17 00:00:00 2001 From: Rodrigo Alves Date: Thu, 18 Jul 2013 07:34:42 -0300 Subject: [PATCH 06/17] Typo --- src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java b/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java index 9d35aea..98546f6 100644 --- a/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java +++ b/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java @@ -87,7 +87,7 @@ public List getProjects(String term, int page, int limit) throws Search /** * Obtains from the GitHub API the set of projects with more than one language * @param Start indicates the desired page - * @param limit is the total of projects that are going to me returned + * @param limit the total of projects that will be returned * @throws SearchException */ public List getProjectsWithMoreThanOneLanguage(int page, int limit) throws SearchException { From b7702215396320fa785268cacc49c57174654bd5 Mon Sep 17 00:00:00 2001 From: Rodrigo Alves Date: Thu, 18 Jul 2013 10:16:46 -0300 Subject: [PATCH 07/17] Adding contributors (Users) to projects --- src/java/main/br/ufpe/cin/groundhog/Project.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/java/main/br/ufpe/cin/groundhog/Project.java b/src/java/main/br/ufpe/cin/groundhog/Project.java index 70786ae..82aa58b 100644 --- a/src/java/main/br/ufpe/cin/groundhog/Project.java +++ b/src/java/main/br/ufpe/cin/groundhog/Project.java @@ -28,6 +28,7 @@ public class Project implements GitHubEntity { private List issues; private List milestones; private List commits; + private List contributors; private User user; private SCM scm; @@ -442,6 +443,18 @@ public List getCommits() { public void setCommits(List commits) { this.commits = commits; } + + /** + * Returns the list of contributors of the project as GitHub users + * @return + */ + public List getContributors() { + return this.contributors; + } + + public void setContributors(List contributors) { + this.contributors = contributors; + } /** * Method to inform the median number of forks per project in a collection of projects From dd67c4acbe9b1dcc1fc6cbe1bf7a7e37dd959a7e Mon Sep 17 00:00:00 2001 From: Rodrigo Alves Date: Thu, 18 Jul 2013 10:18:15 -0300 Subject: [PATCH 08/17] Groundhog now able to fetch project contributors --- .../cin/groundhog/search/SearchGitHub.java | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java b/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java index 98546f6..0971c0a 100644 --- a/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java +++ b/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java @@ -5,6 +5,7 @@ import java.util.Iterator; import java.util.List; +import br.ufpe.cin.groundhog.Commit; import br.ufpe.cin.groundhog.GroundhogException; import br.ufpe.cin.groundhog.Issue; import br.ufpe.cin.groundhog.Language; @@ -14,7 +15,6 @@ import br.ufpe.cin.groundhog.User; import br.ufpe.cin.groundhog.http.Requests; -import com.google.common.base.Splitter; import com.google.common.collect.Lists; import com.google.gson.Gson; import com.google.gson.JsonArray; @@ -318,6 +318,55 @@ public List getAllProjectMilestones(Project project) throws IOExcepti return collection; } + /** + * Fetches all the Commits of the given {@link Project} from the GitHub API + * @param project the @{link Project} to which the commits belong + * @return a {@link List} of {@link Commit} objects + * @throws IOException + */ + public List getAllProjectCommits(Project project) throws IOException { + List collection = new ArrayList(); + + String searchUrl = String.format("%s/repos/%s/%s/commits", + REPO_API, project.getUser().getLogin(), project.getName()); + + JsonElement jsonElement = gson.fromJson(requests.get(searchUrl), JsonElement.class); + JsonArray jsonArray = jsonElement.getAsJsonArray(); + + int i = 0; + Commit commit; + + for (; i < jsonArray.size(); i++) { + commit = gson.fromJson(jsonArray.get(i), Commit.class); + collection.add(commit); + } + + return collection; + } + + /** + * Fetches all the contributors of the given {@link Project} from the GitHub API + * @param project the @{link Project} to get the contributors from + * @return a {@link List} of {@link User} objects + * @throws IOException + */ + public List getAllProjectContributors(Project project) throws IOException { + List collection = new ArrayList(); + + String searchUrl = String.format("%s/repos/%s/%s/contributors", REPO_API, project.getUser().getLogin(), project.getName()); + String jsonString = requests.get(searchUrl); + + JsonElement jsonElement = gson.fromJson(jsonString, JsonElement.class); + JsonArray jsonArray = jsonElement.getAsJsonArray(); + + for (int i = 0; i < jsonArray.size(); i++) { + User contributor = gson.fromJson(jsonArray.get(i), User.class); + collection.add(contributor); + } + + return collection; + } + public List getAllForgeProjects(int start, int limit) throws SearchException{ String searchUrl = null; List projects = new ArrayList(); From dd1aded17b2b2047600611bf4937205d240c77ac Mon Sep 17 00:00:00 2001 From: Rodrigo Alves Date: Thu, 18 Jul 2013 10:18:31 -0300 Subject: [PATCH 09/17] Adding emailAddresses to Users. This is crucial for properly identifying commit authorship lately in Groundhog. --- src/java/main/br/ufpe/cin/groundhog/User.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/java/main/br/ufpe/cin/groundhog/User.java b/src/java/main/br/ufpe/cin/groundhog/User.java index a8a3606..aef9409 100644 --- a/src/java/main/br/ufpe/cin/groundhog/User.java +++ b/src/java/main/br/ufpe/cin/groundhog/User.java @@ -1,6 +1,8 @@ package br.ufpe.cin.groundhog; import java.util.Date; +import java.util.List; + import com.google.gson.annotations.SerializedName; /** @@ -47,6 +49,8 @@ public class User implements GitHubEntity { @SerializedName("updated_at") private Date updated_at; + private List emailAddresses; + public User(String login) { this.login = login; } @@ -209,6 +213,19 @@ public void setLocation(String location) { this.location = location; } + /** + * Informs the list of email addresses that belongs to the user. + * This is useful for matching critical {@link Commit} authorship data + * @return + */ + public List getEmailAddresses() { + return this.emailAddresses; + } + + public void setEmailAddresses(List emails) { + this.emailAddresses = emails; + } + public String getURL() { return String.format("https://api.github.com/users/%s", this.getLogin()); } @@ -218,4 +235,4 @@ public String toString() { return "User id = " + id + ", " + (login != null ? "login = " + login + ", " : "") + (getURL() != null ? "URL = " + getURL() : ""); } -} \ No newline at end of file +} From 8c37302b520ba31e50acc08f609b58ce7fdddf26 Mon Sep 17 00:00:00 2001 From: Rodrigo Alves Date: Thu, 18 Jul 2013 10:25:19 -0300 Subject: [PATCH 10/17] Tweaking README to reflects changes in Groudhog. Section about forge support was moved to the Wiki https://github.com/spgroup/groundhog/wiki/Supported-Forges --- README.md | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 431dca8..b103fc2 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,16 @@ In order for it to behave like an Eclipse project, you'll need to install the Ma Generate the JAR file for the Groundhog project. -Eclipse users can go to `File > Export > Runnable Jar File` and enter the `CmdMain` class for the option "Launch Configuration". +Eclipse users can go to `File > Export > Runnable JAR File` and enter the `CmdMain` class for the option "Launch Configuration". ## Usage +You can use Groundhog in two ways: as an executable JAR from the command line or as a library in your own Java project. + ### Fetching Metadata +Metadata is fetched from GitHub's API. In order to be able to fetch more objects, you need to [obtain your GitHub API token](https://github.com/settings/applications) and use it in Groundhog. + #### Project You can use Groundhog to fetch metadata on a list of projects that attend to a criteria @@ -82,6 +86,17 @@ Software projects are often composed of more than one programming language. Grou searchGitHub.fetchProjectLanguages(pr); ``` +#### Contributors + +You can also get the list of people who contributed to a project on GitHub: + +```java +User user = new User("rails"); +Project project = new Project(user, "rails"); // project github.com/rails/rails + +searchGitHub.getAllProjectContributors(project); +``` + ### Running Groundhog Search GitHub for projects matching "phonegap-facebook-plugin" and place the results (if any) in a folder called metrics: @@ -96,29 +111,6 @@ $ java -jar groundhog.jar -forge github -out metrics phonegap-facebook-plugin $ mvn test ``` -## Info - -### Supported Forges - -* GitHub -* Google Code -* SourceForge - -### Supported Programming Languages - -* Java, parsing only (more to be added later) - -### Forge Search - -* **GitHub**: -Groundhog uses the [GitHub API v3] to search for repositories on GitHub - -* **Google Code**: -to be written - -* **SourceForge**: -to be written - ## Documentation Groundhog features a [Wiki], where you can browse for more information. From 89be33e619facbab0474593893aa509d96fb43c8 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Thu, 18 Jul 2013 11:04:28 -0300 Subject: [PATCH 11/17] fixing guice initialization error on searchgithub --- src/java/main/br/ufpe/cin/groundhog/main/TestMain.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java/main/br/ufpe/cin/groundhog/main/TestMain.java b/src/java/main/br/ufpe/cin/groundhog/main/TestMain.java index 8ea45f6..4aa75c7 100644 --- a/src/java/main/br/ufpe/cin/groundhog/main/TestMain.java +++ b/src/java/main/br/ufpe/cin/groundhog/main/TestMain.java @@ -43,7 +43,7 @@ */ public class TestMain { private static Logger logger = LoggerFactory.getLogger(TestMain.class); - static Injector injector = Guice.createInjector(new SearchModule()); + static Injector injector = Guice.createInjector(new SearchModule(), new HttpModule()); static SearchGitHub searchGitHub = injector.getInstance(SearchGitHub.class); /** From 430ffe142fc3463775ba2e0894317eccc11ff2d4 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Thu, 18 Jul 2013 11:20:58 -0300 Subject: [PATCH 12/17] updating readme file --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b103fc2..f69d35d 100644 --- a/README.md +++ b/README.md @@ -61,11 +61,11 @@ User user = new User("joyent"); // Create the User object Project pr = new Project(user, "node"); // Create the Project object // Tell Groundhog to fetch all Issues of that project and assign them the the Project object: -pr.setIssues(searchGitHub.getAllProjectIssues(pr)); +List issues = searchGitHub.getAllProjectIssues(pr); System.out.println("Listing 'em Issues..."); -for (int k = 0; k < pr.getIssues().size(); k++) { - System.out.println(pr.getIssues().get(k).getTitle()); +for (Issue issue: Issues) { + System.out.println(issue.getTitle()); } ``` @@ -74,7 +74,7 @@ for (int k = 0; k < pr.getIssues().size(); k++) { Just like Issues, Groundhog lets you fetch the list of Milestones of a project, too. ```java -pr.setIssues(searchGitHub.getAllProjectMilestones(pr)); +List milestones = searchGitHub.getAllProjectMilestones(pr); ``` #### Languages @@ -83,7 +83,7 @@ Software projects are often composed of more than one programming language. Grou ```java // Returns a List of Language objects for each language of project "pr" -searchGitHub.fetchProjectLanguages(pr); +List languages = searchGitHub.fetchProjectLanguages(pr); ``` #### Contributors @@ -94,7 +94,7 @@ You can also get the list of people who contributed to a project on GitHub: User user = new User("rails"); Project project = new Project(user, "rails"); // project github.com/rails/rails -searchGitHub.getAllProjectContributors(project); +List contributors = searchGitHub.getAllProjectContributors(project); ``` ### Running Groundhog From 814aa3545be7ce9dfa7ae44758603f0f0174d7d4 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Thu, 18 Jul 2013 11:24:54 -0300 Subject: [PATCH 13/17] updating readme file again --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f69d35d..a7baf3d 100644 --- a/README.md +++ b/README.md @@ -41,13 +41,13 @@ Injector injector = Guice.createInjector(new SearchModule()); SearchGitHub searchGitHub = injector.getInstance(SearchGitHub.class); // Search for projects named "opencv" starting in page 1 and stoping and going until the 3rd project -searchGitHub.getProjects("opencv", 1, 3); +List projects = searchGitHub.getProjects("opencv", 1, 3); ``` Alternatively, you can search for projects without setting the limiting point. In this case Groundhog will fetch projects until your API limit is exceeded. ```java -searchGitHub.getProjects("eclipse", 1, SearchGitHub.INFINITY) +List projects = searchGitHub.getProjects("eclipse", 1, SearchGitHub.INFINITY) ``` #### Issues @@ -64,7 +64,7 @@ Project pr = new Project(user, "node"); // Create the Project object List issues = searchGitHub.getAllProjectIssues(pr); System.out.println("Listing 'em Issues..."); -for (Issue issue: Issues) { +for (Issue issue: issues) { System.out.println(issue.getTitle()); } ``` From 3cdf464417fcb726ed1de0781b6004a245fa52fb Mon Sep 17 00:00:00 2001 From: Gustavo Date: Thu, 18 Jul 2013 11:30:55 -0300 Subject: [PATCH 14/17] Update README.md putting jesus as a contributor --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a7baf3d..feeb7ef 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,8 @@ $ javadoc -d src/src/groundhog br.cin.ufpe.groundhog * Fernando Castor {myfamilyname@cin.ufpe.br} +* Jesus Silva {jjss@cin.ufpe.br} + ## Contributions Want to contribute with code, documentation or bug report? That's great, check out the [Issues] page. From 6c12248f8b296ebb005195fabff816883a0cee43 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Thu, 18 Jul 2013 12:48:01 -0300 Subject: [PATCH 15/17] removing static methods from project class. rel #6 --- .../main/br/ufpe/cin/groundhog/Project.java | 179 ++--------------- .../ufpe/cin/groundhog/answers/Projects.java | 185 ++++++++++++++++++ .../br/ufpe/cin/groundhog/main/CmdMain.java | 6 - .../br/ufpe/cin/groundhog/main/TestMain.java | 8 +- .../answers/ToGetTopMostUsedLanguages.java | 2 +- 5 files changed, 202 insertions(+), 178 deletions(-) create mode 100644 src/java/main/br/ufpe/cin/groundhog/answers/Projects.java diff --git a/src/java/main/br/ufpe/cin/groundhog/Project.java b/src/java/main/br/ufpe/cin/groundhog/Project.java index 82aa58b..457d356 100644 --- a/src/java/main/br/ufpe/cin/groundhog/Project.java +++ b/src/java/main/br/ufpe/cin/groundhog/Project.java @@ -1,15 +1,12 @@ package br.ufpe.cin.groundhog; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.Date; -import java.util.HashMap; import java.util.List; -import com.google.gson.annotations.SerializedName; -import java.util.Map.Entry; + import br.ufpe.cin.groundhog.util.Dates; +import com.google.gson.annotations.SerializedName; + /** * Represents a software project in Groundhog * @author fjsj, gustavopinto, Rodrigo Alves @@ -456,168 +453,6 @@ public void setContributors(List contributors) { this.contributors = contributors; } - /** - * Method to inform the median number of forks per project in a collection of projects - * @param projects - * @return - */ - public double getMedianForksRate(List projects) { - int i = 0, listSize = projects.size(), half = listSize/2; - double median = 0.0; - int[] forkStore = new int[listSize]; - - if (listSize == 0) { - throw new IllegalArgumentException("List of projects can't be empty"); - } - - for (; i < listSize; i++) { - forkStore[i] = projects.get(i).getForksCount(); - } - - Arrays.sort(forkStore); - - if (listSize % 2 == 0) { - median = (forkStore[half - 1] + forkStore[half])/2; - } else { - median = forkStore[half]; - } - - return median; - } - - /** - * Method to inform the average number of forks per project in a collection of projects - * @param projects - * @return - */ - public static int getAverageForksRate(List projects) { - int i = 0, j = 0, total = 0, listSize = projects.size(); - int[] forkStore = new int[listSize]; - - if (listSize == 0) { - throw new IllegalArgumentException("List of projects can't be empty"); - } - - for (; i < listSize; i++) { - forkStore[i] = projects.get(i).getForksCount(); - } - - for (; j < forkStore.length; j++) { - total += forkStore[j]; - } - - return total/listSize; - } - - /** - * Method to discover the percentage of projects that have forks - * @param The list of projects to be analyzed - * @return a double result - such that 0 <= result <= 1 - indicating how many of the informed projects have forks (were forked at least once) - */ - public static double getProjectsWithForksRate(List projects) { - double result = 0.0; - int projectsWithForks = 0, i = 0, listSize = projects.size(); - - if (listSize == 0) { - throw new IllegalArgumentException("List of projects can't be empty"); - } - - for (; i < listSize; i++) { - if (projects.get(i).getForksCount() > 0) { - projectsWithForks++; - } - } - - result = (projectsWithForks / listSize); - return result; - } - - /** - * Informs what is the overall percentage of the given projects that are forks - * With this method we can answer the question "What is the overall percentage of Github projects that ARE forks?" - * @return a double result - such that 0 <= result <= 1 - indicating how many of the informed projects are forks - */ - public static double getProjectsThatAreForks(List projects) { - double result = 0.0; - int projectsAreForks = 0, i = 0, listSize = projects.size(); - - if (listSize == 0) { - throw new IllegalArgumentException("List of projects can't be empty"); - } - - for (; i < listSize; i++) { - if (projects.get(i).isFork()) { - projectsAreForks++; - } - } - - result = (projectsAreForks / listSize); - return result; - } - - - /** - * Gets the top most Used languages among the projects considering the most used language - * in each project. - * @param projects List of projects into consideration - * @param limit Limits the size of the returning list - * @return sorted list with the top most used languages - */ - public static List getTopMostUsedLanguages(List projects, int limit){ - List topLanguages = new ArrayList(); - HashMap LanguageMap = new HashMap(); - for( Project project: projects){ - String language = project.getLanguage(); - Integer count = 1; - if ( LanguageMap.containsKey(language) ){ - count += LanguageMap.get(language); - } - LanguageMap.put(language, count); - - } - for( Entry language : LanguageMap.entrySet() ){ - topLanguages.add(new Language(language.getKey(), language.getValue())); - } - - Collections.sort(topLanguages); - if( limit < 0 ) limit = 0; - topLanguages = topLanguages.subList(0, Math.min( limit, topLanguages.size() )); - return topLanguages; - } - - - /** - * Gets the top most Used languages among the projects according to the number - * of LOC (lines of code) that they apper. - * @param projects List of projects into consideration - * @param limit Limits the size of the returning list - * @return sorted list with the top most used languages - */ - public static List getTopMostUsedLanguagesLoc(List projects, int limit){ - List topLanguages = new ArrayList(); - HashMap LanguageMap = new HashMap(); - for( Project project: projects){ - if( project.getLanguages() == null) { - throw new GroundhogException("languages information required"); - } - for( Language language : project.getLanguages()){ - Integer newLoc = language.getLoc(); - if ( LanguageMap.containsKey(language.getName()) ){ - newLoc += LanguageMap.get(language.getName()); - } - LanguageMap.put(language.getName(), newLoc); - } - } - for( Entry language : LanguageMap.entrySet() ){ - topLanguages.add(new Language(language.getKey(), language.getValue())); - } - - Collections.sort(topLanguages); - if( limit < 0 ) limit = 0; - topLanguages = topLanguages.subList(0, Math.min( limit, topLanguages.size() )); - return topLanguages; - } - /** * Returns the {@link User} object who is the author of the Project * @return @@ -626,10 +461,18 @@ public User getUser() { return this.user; } + /** + * Sets the {@link User} object who is the author of the Project + * @param user + */ public void setUser(User user) { this.user = user; } + /** + * Returns the well-formated github rest-api for this project + * @return + */ public String getURL() { return String.format("https://api.github.com/repos/%s/%s", this.getUser().getLogin(), this.getName()); } diff --git a/src/java/main/br/ufpe/cin/groundhog/answers/Projects.java b/src/java/main/br/ufpe/cin/groundhog/answers/Projects.java new file mode 100644 index 0000000..9d710ee --- /dev/null +++ b/src/java/main/br/ufpe/cin/groundhog/answers/Projects.java @@ -0,0 +1,185 @@ +package br.ufpe.cin.groundhog.answers; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import br.ufpe.cin.groundhog.GroundhogException; +import br.ufpe.cin.groundhog.Language; +import br.ufpe.cin.groundhog.Project; + +/** + * Utility class to help answer the milestone questions + * + * TODO: We should have a better place to put this class + * + * @author gustavopinto + */ +public class Projects { + + /** + * Method to inform the median number of forks per project in a collection of projects + * @param projects + * @return + */ + public double getMedianForksRate(List projects) { + int i = 0, listSize = projects.size(), half = listSize/2; + double median = 0.0; + int[] forkStore = new int[listSize]; + + if (listSize == 0) { + throw new IllegalArgumentException("List of projects can't be empty"); + } + + for (; i < listSize; i++) { + forkStore[i] = projects.get(i).getForksCount(); + } + + Arrays.sort(forkStore); + + if (listSize % 2 == 0) { + median = (forkStore[half - 1] + forkStore[half])/2; + } else { + median = forkStore[half]; + } + + return median; + } + + /** + * Method to inform the average number of forks per project in a collection of projects + * @param projects + * @return + */ + public static int getAverageForksRate(List projects) { + int i = 0, j = 0, total = 0, listSize = projects.size(); + int[] forkStore = new int[listSize]; + + if (listSize == 0) { + throw new IllegalArgumentException("List of projects can't be empty"); + } + + for (; i < listSize; i++) { + forkStore[i] = projects.get(i).getForksCount(); + } + + for (; j < forkStore.length; j++) { + total += forkStore[j]; + } + + return total/listSize; + } + + /** + * Method to discover the percentage of projects that have forks + * @param The list of projects to be analyzed + * @return a double result - such that 0 <= result <= 1 - indicating how many of the informed projects have forks (were forked at least once) + */ + public static double getProjectsWithForksRate(List projects) { + double result = 0.0; + int projectsWithForks = 0, i = 0, listSize = projects.size(); + + if (listSize == 0) { + throw new IllegalArgumentException("List of projects can't be empty"); + } + + for (; i < listSize; i++) { + if (projects.get(i).getForksCount() > 0) { + projectsWithForks++; + } + } + + result = (projectsWithForks / listSize); + return result; + } + + /** + * Informs what is the overall percentage of the given projects that are forks + * With this method we can answer the question "What is the overall percentage of Github projects that ARE forks?" + * @return a double result - such that 0 <= result <= 1 - indicating how many of the informed projects are forks + */ + public static double getProjectsThatAreForks(List projects) { + double result = 0.0; + int projectsAreForks = 0, i = 0, listSize = projects.size(); + + if (listSize == 0) { + throw new IllegalArgumentException("List of projects can't be empty"); + } + + for (; i < listSize; i++) { + if (projects.get(i).isFork()) { + projectsAreForks++; + } + } + + result = (projectsAreForks / listSize); + return result; + } + + + /** + * Gets the top most Used languages among the projects considering the most used language + * in each project. + * @param projects List of projects into consideration + * @param limit Limits the size of the returning list + * @return sorted list with the top most used languages + */ + public static List getTopMostUsedLanguages(List projects, int limit){ + List topLanguages = new ArrayList(); + HashMap LanguageMap = new HashMap(); + for( Project project: projects){ + String language = project.getLanguage(); + Integer count = 1; + if ( LanguageMap.containsKey(language) ){ + count += LanguageMap.get(language); + } + LanguageMap.put(language, count); + + } + for( Entry language : LanguageMap.entrySet() ){ + topLanguages.add(new Language(language.getKey(), language.getValue())); + } + + Collections.sort(topLanguages); + if( limit < 0 ) limit = 0; + topLanguages = topLanguages.subList(0, Math.min( limit, topLanguages.size() )); + return topLanguages; + } + + + /** + * Gets the top most Used languages among the projects according to the number + * of LOC (lines of code) that they apper. + * @param projects List of projects into consideration + * @param limit Limits the size of the returning list + * @return sorted list with the top most used languages + */ + public static List getTopMostUsedLanguagesLoc(List projects, int limit){ + List topLanguages = new ArrayList(); + HashMap LanguageMap = new HashMap(); + for( Project project: projects){ + if( project.getLanguages() == null) { + throw new GroundhogException("languages information required"); + } + for( Language language : project.getLanguages()){ + Integer newLoc = language.getLoc(); + if ( LanguageMap.containsKey(language.getName()) ){ + newLoc += LanguageMap.get(language.getName()); + } + LanguageMap.put(language.getName(), newLoc); + } + } + for( Entry language : LanguageMap.entrySet() ){ + topLanguages.add(new Language(language.getKey(), language.getValue())); + } + + Collections.sort(topLanguages); + if( limit < 0 ) limit = 0; + topLanguages = topLanguages.subList(0, Math.min( limit, topLanguages.size() )); + return topLanguages; + } + +} diff --git a/src/java/main/br/ufpe/cin/groundhog/main/CmdMain.java b/src/java/main/br/ufpe/cin/groundhog/main/CmdMain.java index 61f56da..7fa96b0 100644 --- a/src/java/main/br/ufpe/cin/groundhog/main/CmdMain.java +++ b/src/java/main/br/ufpe/cin/groundhog/main/CmdMain.java @@ -15,7 +15,6 @@ import org.slf4j.LoggerFactory; import br.ufpe.cin.groundhog.GroundhogException; -import br.ufpe.cin.groundhog.Language; import br.ufpe.cin.groundhog.Project; import br.ufpe.cin.groundhog.SCM; import br.ufpe.cin.groundhog.codehistory.CodeHistory; @@ -259,11 +258,6 @@ public void run(JsonInput input) { allProjects = search.getProjects(term, 1,-1); } - //TODO delete, this is only a test - - List languages = Project.getTopMostUsedLanguages(allProjects, 10); - - //TODO the getProjects method already limits the number of searched projects List projects = new ArrayList(); for (int i = 0; i < nProjects; i++) { diff --git a/src/java/main/br/ufpe/cin/groundhog/main/TestMain.java b/src/java/main/br/ufpe/cin/groundhog/main/TestMain.java index 4aa75c7..0875f00 100644 --- a/src/java/main/br/ufpe/cin/groundhog/main/TestMain.java +++ b/src/java/main/br/ufpe/cin/groundhog/main/TestMain.java @@ -14,6 +14,7 @@ import br.ufpe.cin.groundhog.Project; import br.ufpe.cin.groundhog.SCM; import br.ufpe.cin.groundhog.User; +import br.ufpe.cin.groundhog.answers.Projects; import br.ufpe.cin.groundhog.codehistory.CodeHistoryModule; import br.ufpe.cin.groundhog.codehistory.GitCodeHistory; import br.ufpe.cin.groundhog.codehistory.SFCodeHistory; @@ -40,6 +41,7 @@ /** * The main test class * @author fjsj, gustavopinto, Rodrigo Alves + * @since 0.0.1 */ public class TestMain { private static Logger logger = LoggerFactory.getLogger(TestMain.class); @@ -198,7 +200,7 @@ public static void main(String[] args) throws Exception { System.out.println("Searching GitHub for 'opencv': the first " + m + " results of the " + n + " page..."); System.out.println(projects.size() + " projects returned"); - double ratio = Project.getProjectsThatAreForks(projects); + double ratio = Projects.getProjectsThatAreForks(projects); System.out.println("Are forks: " + ratio); @@ -214,10 +216,10 @@ public static void main(String[] args) throws Exception { * */ - double nratio = Project.getProjectsWithForksRate(projects); + double nratio = Projects.getProjectsWithForksRate(projects); System.out.println("Have forks: " + nratio); - int aratio = Project.getAverageForksRate(projects); + int aratio = Projects.getAverageForksRate(projects); System.out.println("Average number of forks between the searched projects: " + aratio); // Fun with Milestones: diff --git a/src/java/test/br/ufpe/cin/groundhog/answers/ToGetTopMostUsedLanguages.java b/src/java/test/br/ufpe/cin/groundhog/answers/ToGetTopMostUsedLanguages.java index f106aeb..cfaff72 100644 --- a/src/java/test/br/ufpe/cin/groundhog/answers/ToGetTopMostUsedLanguages.java +++ b/src/java/test/br/ufpe/cin/groundhog/answers/ToGetTopMostUsedLanguages.java @@ -29,7 +29,7 @@ public void testGetTopTenMostUsedLanguages() { List projects = searchGitHub.getProjects("facebook", 1, 10); Assert.assertNotNull(projects); - List languages = Project.getTopMostUsedLanguages(projects, 10); + List languages = Projects.getTopMostUsedLanguages(projects, 10); Assert.assertNotNull(languages); } catch (Exception e) { e.printStackTrace(); From 4c55a94c0d1d1f0422ee5419a02ecba4c1d7ab81 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Thu, 18 Jul 2013 13:07:43 -0300 Subject: [PATCH 16/17] a basic proxy of what is a mature project. rel #24 --- src/java/main/br/ufpe/cin/groundhog/Project.java | 14 ++++++++++++++ .../br/ufpe/cin/groundhog/http/HttpModule.java | 5 +++++ .../br/ufpe/cin/groundhog/http/ParamBuilder.java | 2 +- .../main/br/ufpe/cin/groundhog/main/CmdMain.java | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/java/main/br/ufpe/cin/groundhog/Project.java b/src/java/main/br/ufpe/cin/groundhog/Project.java index 457d356..3673adb 100644 --- a/src/java/main/br/ufpe/cin/groundhog/Project.java +++ b/src/java/main/br/ufpe/cin/groundhog/Project.java @@ -10,6 +10,7 @@ /** * Represents a software project in Groundhog * @author fjsj, gustavopinto, Rodrigo Alves + * @since 0.0.1 */ public class Project implements GitHubEntity { @SerializedName("name") @@ -469,6 +470,19 @@ public void setUser(User user) { this.user = user; } + /** + * Returns true if the project is considered mature, and false otherwise. + * + * A project is considered mature if it has at least three watchers, plus + * one fork, plus more than 100 commits in its own history, and more than + * five issues created in its own history. + * + * @return + */ + public boolean isMature() { + return ((watchersCount > 3) && (forks_count > 1) && (commits.size() > 100) && (issues.size() > 5)); + } + /** * Returns the well-formated github rest-api for this project * @return diff --git a/src/java/main/br/ufpe/cin/groundhog/http/HttpModule.java b/src/java/main/br/ufpe/cin/groundhog/http/HttpModule.java index f23062b..3231a4d 100644 --- a/src/java/main/br/ufpe/cin/groundhog/http/HttpModule.java +++ b/src/java/main/br/ufpe/cin/groundhog/http/HttpModule.java @@ -4,6 +4,11 @@ import com.google.inject.Singleton; import com.google.inject.name.Names; +/** + * + * @author ghlp + * @since 0.0.1 + */ public class HttpModule extends AbstractModule { @Override diff --git a/src/java/main/br/ufpe/cin/groundhog/http/ParamBuilder.java b/src/java/main/br/ufpe/cin/groundhog/http/ParamBuilder.java index f3f826b..b8c5ebd 100644 --- a/src/java/main/br/ufpe/cin/groundhog/http/ParamBuilder.java +++ b/src/java/main/br/ufpe/cin/groundhog/http/ParamBuilder.java @@ -10,7 +10,7 @@ /** * The URL parameter builder class * @author fjsj - * + * @since 0.0.1 */ public class ParamBuilder { private List params; diff --git a/src/java/main/br/ufpe/cin/groundhog/main/CmdMain.java b/src/java/main/br/ufpe/cin/groundhog/main/CmdMain.java index 7fa96b0..e5ca63d 100644 --- a/src/java/main/br/ufpe/cin/groundhog/main/CmdMain.java +++ b/src/java/main/br/ufpe/cin/groundhog/main/CmdMain.java @@ -50,6 +50,7 @@ * The groundhog entry point * * @author fjsj, gustavopinto + * @since 0.0.1 */ public final class CmdMain extends GroundhogMain { From 3d8de46184ce39e287611d44532c571884767ff8 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Thu, 18 Jul 2013 14:46:22 -0300 Subject: [PATCH 17/17] one more attempt to fix broken tests. rel #6 --- .../main/br/ufpe/cin/groundhog/Commit.java | 10 +--- .../cin/groundhog/GroundhogException.java | 6 ++- .../main/br/ufpe/cin/groundhog/Language.java | 14 ++++-- .../main/br/ufpe/cin/groundhog/License.java | 2 + .../cin/groundhog/search/SearchGitHub.java | 49 ++++-------------- .../br/ufpe/cin/groundhog/AllAnswers.java | 15 ++++++ .../test/br/ufpe/cin/groundhog/AllTests.java | 7 ++- .../ToGetProjectsWithMoreThanOneLanguage.java | 50 +++++++++++++++++++ .../answers/ToGetTopMostUsedLanguages.java | 3 +- .../codehistory/GitCodeHistoryTest.java | 10 ++-- .../groundhog/crawler/CrawlGitHubTest.java | 36 ++++--------- .../crawler/CrawlGoogleCodeTest.java | 11 ++-- .../groundhog/search/SearchGitHubTest.java | 39 +++------------ .../search/SearchSourceForgeTest.java | 5 +- 14 files changed, 130 insertions(+), 127 deletions(-) create mode 100644 src/java/test/br/ufpe/cin/groundhog/AllAnswers.java create mode 100644 src/java/test/br/ufpe/cin/groundhog/answers/ToGetProjectsWithMoreThanOneLanguage.java diff --git a/src/java/main/br/ufpe/cin/groundhog/Commit.java b/src/java/main/br/ufpe/cin/groundhog/Commit.java index 59ce2a2..2e69271 100644 --- a/src/java/main/br/ufpe/cin/groundhog/Commit.java +++ b/src/java/main/br/ufpe/cin/groundhog/Commit.java @@ -6,6 +6,7 @@ /** * Represents a Commit object in Groundhog * @author Rodrigo Alves + * @since 0.0.1 */ public class Commit implements GitHubEntity { @SerializedName("sha") @@ -30,15 +31,8 @@ public class Commit implements GitHubEntity { private int deletionsCount; - public Commit() { - } - - public Commit(String sha) { - this.sha = sha; - } - public Commit(String sha, Project project) { - this(sha); + this.sha = sha; this.project = project; } diff --git a/src/java/main/br/ufpe/cin/groundhog/GroundhogException.java b/src/java/main/br/ufpe/cin/groundhog/GroundhogException.java index 3b8d03a..e086f91 100644 --- a/src/java/main/br/ufpe/cin/groundhog/GroundhogException.java +++ b/src/java/main/br/ufpe/cin/groundhog/GroundhogException.java @@ -1,9 +1,11 @@ package br.ufpe.cin.groundhog; /** - * The base {@link Exception} type for Groundhog. All Groundhog exceptions must extend this class. + * The base {@link Exception} type for Groundhog. All Groundhog exceptions must + * extend this class. + * * @author fjsj, gustavopinto, Rodrigo Alves - * + * @since 0.0.1 */ public class GroundhogException extends RuntimeException { private static final long serialVersionUID = -3563928567447310893L; diff --git a/src/java/main/br/ufpe/cin/groundhog/Language.java b/src/java/main/br/ufpe/cin/groundhog/Language.java index 05ee84a..23a464b 100644 --- a/src/java/main/br/ufpe/cin/groundhog/Language.java +++ b/src/java/main/br/ufpe/cin/groundhog/Language.java @@ -1,12 +1,14 @@ package br.ufpe.cin.groundhog; /** - * Represents languages - an important set of components of a {@link Project} - in Groundhog. - * This class is only important/meaningful in the context of Projects. As a representation of - * the programming language composition of such objects. + * Represents languages - an important set of components of a {@link Project} - + * in Groundhog. This class is only important/meaningful in the context of + * Projects. As a representation of the programming language composition of such + * objects. * * @author Rodrigo Alves - * + * @since 0.0.1 + * */ public class Language implements Comparable { private String name; @@ -52,5 +54,7 @@ public int compareTo(Language o) { return 0; } - + public String toString() { + return name; + } } \ No newline at end of file diff --git a/src/java/main/br/ufpe/cin/groundhog/License.java b/src/java/main/br/ufpe/cin/groundhog/License.java index 2a35db2..563993b 100644 --- a/src/java/main/br/ufpe/cin/groundhog/License.java +++ b/src/java/main/br/ufpe/cin/groundhog/License.java @@ -2,6 +2,8 @@ /** * Represents the license used in the project + * @author ghlp + * @since 0.0.1 */ public class License { diff --git a/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java b/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java index 0971c0a..80e63f2 100644 --- a/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java +++ b/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java @@ -13,6 +13,7 @@ import br.ufpe.cin.groundhog.Project; import br.ufpe.cin.groundhog.SCM; import br.ufpe.cin.groundhog.User; +import br.ufpe.cin.groundhog.http.HttpException; import br.ufpe.cin.groundhog.http.Requests; import com.google.common.collect.Lists; @@ -106,46 +107,12 @@ public List getProjectsWithMoreThanOneLanguage(int page, int limit) thr return projects; - } catch (GroundhogException | IOException e) { - e.printStackTrace(); - throw new SearchException(e); - } - } - /** - * Obtains from the GitHub API a string indicating how many projects have more than one language - * @param page indicates the desired page - * @param limit is the total of projects that are going to me returned - * @throws SearchException - */ - public String getProjectsWithMoreThanOneLanguageString(int page, int limit) throws SearchException { - try { - - String result = ""; - - List projects = new ArrayList(); - List rawData = getAllProjects(page, limit); - - for (Project project : rawData) { - List languages = fetchProjectLanguages(project); - - if(languages.size() > 1){ - projects.add(project); - } - } - - float percent = ((Float.intBitsToFloat(projects.size())/Float.intBitsToFloat(rawData.size()))*100); - - result = "There are " + rawData.size() + " projects in github \n" + - "There are " + projects.size() +" projects with more than one language \n" + - "This is " + percent + "% of the total"; - - return result; - - } catch (GroundhogException | IOException e) { + } catch (GroundhogException e) { e.printStackTrace(); throw new SearchException(e); } } + /** * Obtains from the GitHub API the set of projects * @param Start indicates the desired page @@ -256,10 +223,16 @@ public List getProjects(String term, String username, int page) * @param project a {@link Project} object to have its languages fetched * @throws IOException */ - public List fetchProjectLanguages(Project project) throws IOException { + public List fetchProjectLanguages(Project project) { String searchUrl = String.format("%s/repos/%s/%s/languages", REPO_API, project.getUser().getLogin(), project.getName()); - String json = requests.get(searchUrl).replace("{", "").replace("}", ""); + String json = null; + try { + json = requests.get(searchUrl).replace("{", "").replace("}", ""); + } catch (IOException e) { + e.printStackTrace(); + throw new HttpException("Unable to download json file. Is it the correct path?" + searchUrl, e); + } List languages = new ArrayList<>(); if(!json.equalsIgnoreCase("{}")){ diff --git a/src/java/test/br/ufpe/cin/groundhog/AllAnswers.java b/src/java/test/br/ufpe/cin/groundhog/AllAnswers.java new file mode 100644 index 0000000..8ef3d77 --- /dev/null +++ b/src/java/test/br/ufpe/cin/groundhog/AllAnswers.java @@ -0,0 +1,15 @@ +package br.ufpe.cin.groundhog; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +import br.ufpe.cin.groundhog.answers.ToGetProjectsWithMoreThanOneLanguage; +import br.ufpe.cin.groundhog.answers.ToGetTopMostUsedLanguages; + +@RunWith(Suite.class) +@SuiteClasses({ ToGetProjectsWithMoreThanOneLanguage.class, + ToGetTopMostUsedLanguages.class }) +public class AllAnswers { + +} diff --git a/src/java/test/br/ufpe/cin/groundhog/AllTests.java b/src/java/test/br/ufpe/cin/groundhog/AllTests.java index 247a771..17ac947 100644 --- a/src/java/test/br/ufpe/cin/groundhog/AllTests.java +++ b/src/java/test/br/ufpe/cin/groundhog/AllTests.java @@ -7,6 +7,8 @@ import br.ufpe.cin.groundhog.codehistory.GitCodeHistoryTest; import br.ufpe.cin.groundhog.codehistory.SFCodeHistoryTest; import br.ufpe.cin.groundhog.crawler.CrawlGitHubTest; +import br.ufpe.cin.groundhog.crawler.CrawlGoogleCodeTest; +import br.ufpe.cin.groundhog.crawler.CrawlSourceForgeTest; import br.ufpe.cin.groundhog.main.OptionsTest; import br.ufpe.cin.groundhog.search.SearchGitHubTest; import br.ufpe.cin.groundhog.search.SearchGoogleCodeTest; @@ -15,9 +17,10 @@ @RunWith(Suite.class) @SuiteClasses({ GitCodeHistoryTest.class, SFCodeHistoryTest.class, - CrawlGitHubTest.class, SearchGitHubTest.class, OptionsTest.class, + CrawlGitHubTest.class, CrawlGoogleCodeTest.class, + CrawlSourceForgeTest.class, OptionsTest.class, SearchGoogleCodeTest.class, SearchSourceForgeTest.class, - FileUtilTest.class }) + SearchGitHubTest.class, FileUtilTest.class }) public class AllTests { } \ No newline at end of file diff --git a/src/java/test/br/ufpe/cin/groundhog/answers/ToGetProjectsWithMoreThanOneLanguage.java b/src/java/test/br/ufpe/cin/groundhog/answers/ToGetProjectsWithMoreThanOneLanguage.java new file mode 100644 index 0000000..63c8dfb --- /dev/null +++ b/src/java/test/br/ufpe/cin/groundhog/answers/ToGetProjectsWithMoreThanOneLanguage.java @@ -0,0 +1,50 @@ +package br.ufpe.cin.groundhog.answers; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +import br.ufpe.cin.groundhog.Language; +import br.ufpe.cin.groundhog.Project; +import br.ufpe.cin.groundhog.http.HttpModule; +import br.ufpe.cin.groundhog.search.SearchGitHub; +import br.ufpe.cin.groundhog.search.SearchModule; + +public class ToGetProjectsWithMoreThanOneLanguage { + + private SearchGitHub searchGitHub; + + @Before + public void init() { + Injector injector = Guice.createInjector(new SearchModule(), new HttpModule()); + searchGitHub = injector.getInstance(SearchGitHub.class); + } + + @Test + public void testProjectsWIthMoreThanOneLanguage() throws IOException{ + List rawData = searchGitHub.getAllProjects(1, 8); + + List projects = new ArrayList(); + for (Project project : rawData) { + List languages = searchGitHub.fetchProjectLanguages(project); + + if(languages.size() > 1){ + projects.add(project); + } + } + + float percent = ((Float.intBitsToFloat(projects.size())/Float.intBitsToFloat(rawData.size()))*100); + + String result = "There are " + rawData.size() + " projects in github \n" + + "There are " + projects.size() +" projects with more than one language \n" + + "This is " + percent + "% of the total"; + + System.out.println(result); + } +} \ No newline at end of file diff --git a/src/java/test/br/ufpe/cin/groundhog/answers/ToGetTopMostUsedLanguages.java b/src/java/test/br/ufpe/cin/groundhog/answers/ToGetTopMostUsedLanguages.java index cfaff72..e71a30c 100644 --- a/src/java/test/br/ufpe/cin/groundhog/answers/ToGetTopMostUsedLanguages.java +++ b/src/java/test/br/ufpe/cin/groundhog/answers/ToGetTopMostUsedLanguages.java @@ -8,6 +8,7 @@ import br.ufpe.cin.groundhog.Language; import br.ufpe.cin.groundhog.Project; +import br.ufpe.cin.groundhog.http.HttpModule; import br.ufpe.cin.groundhog.search.SearchGitHub; import br.ufpe.cin.groundhog.search.SearchModule; @@ -19,7 +20,7 @@ public class ToGetTopMostUsedLanguages { @Before public void setup() { - Injector injector = Guice.createInjector(new SearchModule()); + Injector injector = Guice.createInjector(new SearchModule(), new HttpModule()); searchGitHub = injector.getInstance(SearchGitHub.class); } diff --git a/src/java/test/br/ufpe/cin/groundhog/codehistory/GitCodeHistoryTest.java b/src/java/test/br/ufpe/cin/groundhog/codehistory/GitCodeHistoryTest.java index b270873..27151c5 100644 --- a/src/java/test/br/ufpe/cin/groundhog/codehistory/GitCodeHistoryTest.java +++ b/src/java/test/br/ufpe/cin/groundhog/codehistory/GitCodeHistoryTest.java @@ -1,7 +1,6 @@ package br.ufpe.cin.groundhog.codehistory; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import java.io.File; import java.util.Date; @@ -22,10 +21,11 @@ public void setup(){ calendar = new GregorianCalendar(2012, 5, 23).getTime(); } - @Test(expected=AssertionError.class) + @Test public void main() throws Exception { - assertTrue(file.exists()); - File result = codeHistory.checkoutToDate("javacv", file, calendar); - assertNotNull(result); + if(file.exists()){ + File result = codeHistory.checkoutToDate("javacv", file, calendar); + assertNotNull(result); + } } } diff --git a/src/java/test/br/ufpe/cin/groundhog/crawler/CrawlGitHubTest.java b/src/java/test/br/ufpe/cin/groundhog/crawler/CrawlGitHubTest.java index c3422b1..049f3e2 100644 --- a/src/java/test/br/ufpe/cin/groundhog/crawler/CrawlGitHubTest.java +++ b/src/java/test/br/ufpe/cin/groundhog/crawler/CrawlGitHubTest.java @@ -1,8 +1,8 @@ package br.ufpe.cin.groundhog.crawler; import java.io.File; -import java.util.Arrays; import java.util.List; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import org.junit.Assert; @@ -10,48 +10,32 @@ import org.junit.Test; import br.ufpe.cin.groundhog.Project; -import br.ufpe.cin.groundhog.http.HttpModule; +import br.ufpe.cin.groundhog.SCM; import br.ufpe.cin.groundhog.scmclient.GitClient; import br.ufpe.cin.groundhog.scmclient.ScmModule; -import br.ufpe.cin.groundhog.search.SearchGitHub; -import br.ufpe.cin.groundhog.search.SearchModule; +import com.google.common.collect.Lists; import com.google.common.io.Files; import com.google.inject.Guice; import com.google.inject.Injector; public class CrawlGitHubTest { - private SearchGitHub searchGitHub; private GitClient gitClient; @Before public void setup() { - Injector injector = Guice.createInjector(new SearchModule(), new ScmModule(), new HttpModule()); - searchGitHub = injector.getInstance(SearchGitHub.class); + Injector injector = Guice.createInjector(new ScmModule()); gitClient = injector.getInstance(GitClient.class); } @Test - public void testCrawlGithub() { - long time = System.nanoTime(); - - try { - - Project playframework = searchGitHub.getProjects("playframework", 1,-1).get(0); - List projects = Arrays.asList(playframework); - CrawlGitHub crawl = new CrawlGitHub(gitClient, Files.createTempDir()); - List> fs = crawl.downloadProjects(projects); - for (Future f : fs) { - File file = f.get(); - Assert.assertNotNull(file); - } - - System.out.printf("Elapsed: %.2f", - (System.nanoTime() - time) / 1000000000.0); - - } catch (Exception e) { - Assert.fail(); + public void testCrawlGithub() throws InterruptedException, ExecutionException { + CrawlGitHub crawl = new CrawlGitHub(gitClient, Files.createTempDir()); + List> fs = crawl.downloadProjects(Lists.newArrayList(new Project("modules.playframework.org", "", SCM.GIT, "git@github.com:playframework/modules.playframework.org.git"))); + for (Future f : fs) { + File file = f.get(); + Assert.assertNotNull(file); } } } diff --git a/src/java/test/br/ufpe/cin/groundhog/crawler/CrawlGoogleCodeTest.java b/src/java/test/br/ufpe/cin/groundhog/crawler/CrawlGoogleCodeTest.java index f5e23e5..5f20cbe 100644 --- a/src/java/test/br/ufpe/cin/groundhog/crawler/CrawlGoogleCodeTest.java +++ b/src/java/test/br/ufpe/cin/groundhog/crawler/CrawlGoogleCodeTest.java @@ -10,11 +10,9 @@ import org.junit.Test; import br.ufpe.cin.groundhog.Project; -import br.ufpe.cin.groundhog.http.HttpModule; +import br.ufpe.cin.groundhog.SCM; import br.ufpe.cin.groundhog.scmclient.GitClient; import br.ufpe.cin.groundhog.scmclient.ScmModule; -import br.ufpe.cin.groundhog.search.SearchGoogleCode; -import br.ufpe.cin.groundhog.search.SearchModule; import com.google.common.io.Files; import com.google.inject.Guice; @@ -22,21 +20,18 @@ public class CrawlGoogleCodeTest { - private SearchGoogleCode searchGoogleCode; private GitClient gitClient; @Before public void setup() { - Injector injector = Guice.createInjector(new SearchModule(), new ScmModule(), new HttpModule()); - searchGoogleCode = injector.getInstance(SearchGoogleCode.class); + Injector injector = Guice.createInjector(new ScmModule()); gitClient = injector.getInstance(GitClient.class); } @Test public void testCrawlGithub() { try { - Project project = searchGoogleCode.getProjects("java", 1,-1).get(0); - + Project project = new Project("fake", "fake", "https://code.google.com/p/googletransitdatafeed/source/browse/", SCM.SVN, "http://googletransitdatafeed.googlecode.com/svn/trunk/"); CrawlGoogleCode crawl = new CrawlGoogleCode(gitClient, Files.createTempDir()); List> fs = crawl.downloadProjects(Arrays.asList(project)); diff --git a/src/java/test/br/ufpe/cin/groundhog/search/SearchGitHubTest.java b/src/java/test/br/ufpe/cin/groundhog/search/SearchGitHubTest.java index c6dd7bc..b9c2c4d 100644 --- a/src/java/test/br/ufpe/cin/groundhog/search/SearchGitHubTest.java +++ b/src/java/test/br/ufpe/cin/groundhog/search/SearchGitHubTest.java @@ -8,6 +8,8 @@ import br.ufpe.cin.groundhog.Language; import br.ufpe.cin.groundhog.Project; +import br.ufpe.cin.groundhog.SCM; +import br.ufpe.cin.groundhog.User; import br.ufpe.cin.groundhog.http.HttpModule; import com.google.inject.Guice; @@ -16,17 +18,20 @@ public class SearchGitHubTest { private SearchGitHub searchGitHub; + private Project fakeProject; @Before public void setup() { Injector injector = Guice.createInjector(new SearchModule(), new HttpModule()); searchGitHub = injector.getInstance(SearchGitHub.class); + User user = new User("elixir-lang"); + fakeProject = new Project("elixir", "", SCM.GIT, "git@github.com:elixir-lang/elixir.git"); + fakeProject.setUser(user); } - @Test public void testSearchByProjectName() { try { - List projects = searchGitHub.getProjects("groundhog", 1, 3); + List projects = searchGitHub.getProjects("groundhog", 1, SearchGitHub.INFINITY); searchGitHub.fetchProjectLanguages(projects.get(0)); Assert.assertNotNull(projects); } catch (Exception e) { @@ -38,8 +43,7 @@ public void testSearchByProjectName() { @Test public void testFetchByProjectLanguages() { try { - List projects = searchGitHub.getProjects("groundhog", 1, 3); - List langs = searchGitHub.fetchProjectLanguages(projects.get(0)); + List langs = searchGitHub.fetchProjectLanguages(fakeProject); Assert.assertNotNull(langs); } catch (Exception e) { e.printStackTrace(); @@ -47,7 +51,6 @@ public void testFetchByProjectLanguages() { } } - @Test public void testSearchProjectsByUser() { try { List projects = searchGitHub.getProjects("groundhog", "spggroup", 1); @@ -57,30 +60,4 @@ public void testSearchProjectsByUser() { Assert.fail(); } } - - @Test - public void testSimpleSearch() { - try { - List projects = searchGitHub.getProjects("github api", 1,-1); - Assert.assertNotNull(projects); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail(); - } - } - - @Test - public void testSearchMoreThenOneLanguage() { - try { - String result = searchGitHub.getProjectsWithMoreThanOneLanguageString(1, 8); - Assert.assertNotNull(result); - - // System.out.println(result); - // This line will get all the projects in raw and print them - // System.out.println(searchGitHub.getProjectsWithMoreThanOneLanguage(1, 5)); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail(); - } - } } \ No newline at end of file diff --git a/src/java/test/br/ufpe/cin/groundhog/search/SearchSourceForgeTest.java b/src/java/test/br/ufpe/cin/groundhog/search/SearchSourceForgeTest.java index 3dbb125..d47dfe6 100644 --- a/src/java/test/br/ufpe/cin/groundhog/search/SearchSourceForgeTest.java +++ b/src/java/test/br/ufpe/cin/groundhog/search/SearchSourceForgeTest.java @@ -4,8 +4,10 @@ import org.junit.Assert; import org.junit.Before; +import org.junit.Test; import br.ufpe.cin.groundhog.Project; +import br.ufpe.cin.groundhog.http.HttpModule; import com.google.inject.Guice; import com.google.inject.Injector; @@ -15,10 +17,11 @@ public class SearchSourceForgeTest { @Before public void setup() { - Injector injector = Guice.createInjector(new SearchModule()); + Injector injector = Guice.createInjector(new SearchModule(), new HttpModule()); searchSourceForge = injector.getInstance(SearchSourceForge.class); } + @Test public void testSimpleSearch() { List projects = searchSourceForge.getProjects("", 1, -1); Assert.assertNotNull(projects);