From 2464e8b0444ec9138350aef077efba34486b4ef1 Mon Sep 17 00:00:00 2001 From: Gustavo Pinto Date: Fri, 17 May 2013 16:45:42 -0300 Subject: [PATCH] with method to gather projects list by user. working on #33 --- .../br/ufpe/cin/groundhog/crawler/CrawlGitHub.java | 14 ++++++-------- .../ufpe/cin/groundhog/crawler/ForgeCrawler.java | 2 +- .../main/br/ufpe/cin/groundhog/main/CmdMain.java | 11 +++++++++-- .../br/ufpe/cin/groundhog/main/GroundhogMain.java | 14 ++++++++++++-- .../main/br/ufpe/cin/groundhog/main/JsonInput.java | 4 ++-- .../br/ufpe/cin/groundhog/search/ForgeSearch.java | 12 ++++++++++++ .../br/ufpe/cin/groundhog/search/SearchGitHub.java | 6 ++++++ .../cin/groundhog/search/SearchGoogleCode.java | 6 ++++++ .../cin/groundhog/search/SearchSourceForge.java | 6 ++++++ 9 files changed, 60 insertions(+), 15 deletions(-) diff --git a/src/java/main/br/ufpe/cin/groundhog/crawler/CrawlGitHub.java b/src/java/main/br/ufpe/cin/groundhog/crawler/CrawlGitHub.java index f3a6e06..8411389 100644 --- a/src/java/main/br/ufpe/cin/groundhog/crawler/CrawlGitHub.java +++ b/src/java/main/br/ufpe/cin/groundhog/crawler/CrawlGitHub.java @@ -1,13 +1,11 @@ package br.ufpe.cin.groundhog.crawler; import java.io.File; -import java.io.IOException; import java.util.Random; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.TransportException; -import org.json.JSONException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,8 +21,9 @@ */ public class CrawlGitHub extends ForgeCrawler { - private final static Logger logger = LoggerFactory.getLogger(CrawlGitHub.class); - + private final static Logger logger = LoggerFactory + .getLogger(CrawlGitHub.class); + private final GitClient gitClient; @Inject @@ -34,15 +33,14 @@ public CrawlGitHub(GitClient gitClient, File destinationFolder) { } @Override - protected File downloadProject(Project project) throws JSONException, - IOException, InvalidRemoteException, TransportException, - GitAPIException { + protected File downloadProject(Project project) + throws InvalidRemoteException, TransportException, GitAPIException { String projectName = project.getName() + "_" + new Random().nextInt(); String cloneUrl = project.getScmURL(); File projectFolder = new File(destinationFolder, projectName); logger.info(String.format("Downloading %s project..", project.getName())); - + gitClient.clone(cloneUrl, projectFolder); return projectFolder; } diff --git a/src/java/main/br/ufpe/cin/groundhog/crawler/ForgeCrawler.java b/src/java/main/br/ufpe/cin/groundhog/crawler/ForgeCrawler.java index 3c79975..dd4c006 100644 --- a/src/java/main/br/ufpe/cin/groundhog/crawler/ForgeCrawler.java +++ b/src/java/main/br/ufpe/cin/groundhog/crawler/ForgeCrawler.java @@ -71,7 +71,7 @@ public File call() throws Exception { * Should be called after downloadProjects. */ public void shutdown() { - ex.shutdown(); + ex.shutdownNow(); } } \ No newline at end of file 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 aa72215..adb1b74 100644 --- a/src/java/main/br/ufpe/cin/groundhog/main/CmdMain.java +++ b/src/java/main/br/ufpe/cin/groundhog/main/CmdMain.java @@ -244,7 +244,8 @@ public void run(JsonInput input) { createTempFolders(destinationFolder, metricsFolder); final Date datetime = input.getDatetime(); - int nProjects = input.getNprojects(); + final int nProjects = input.getNprojects(); + final String username = input.getSearch().getUsername(); // Search for projects logger.info("Searching for projects... " + input.getSearch().getProjects()); @@ -252,7 +253,13 @@ public void run(JsonInput input) { ForgeCrawler crawler = defineForgeCrawler(input.getForge(), destinationFolder); String term = input.getSearch().getProjects().get(3); - List allProjects = search.getProjects(term, 1); + + List allProjects = null; + if(username != null) { + allProjects = search.getProjects(term, 1); + } else { + allProjects = search.getProjects(term, username, 1); + } List projects = new ArrayList(); for (int i = 0; i < nProjects; i++) { diff --git a/src/java/main/br/ufpe/cin/groundhog/main/GroundhogMain.java b/src/java/main/br/ufpe/cin/groundhog/main/GroundhogMain.java index e746acc..4b586c5 100644 --- a/src/java/main/br/ufpe/cin/groundhog/main/GroundhogMain.java +++ b/src/java/main/br/ufpe/cin/groundhog/main/GroundhogMain.java @@ -15,7 +15,7 @@ public abstract class GroundhogMain { - private static Logger logger = LoggerFactory.getLogger(GroundhogMain.class); + private final static Logger logger = LoggerFactory.getLogger(GroundhogMain.class); public abstract void run(JsonInput input); @@ -38,9 +38,12 @@ public static void main(String[] args) { try { logger.info("Groundhog was initialized!"); - parser.parseArgument(args); + + checkArguments(opt); input = opt.getInputFile(); + + logger.info("We received the following parameters: " + input); new CmdMain().run(input); // Free resources and delete temporary directories @@ -55,6 +58,13 @@ public static void main(String[] args) { } } + private static void checkArguments(Options opt) { +// System.out.println(opt.getForge()); +// System.out.println(opt.getMetricsFolder()); +// System.out.println(opt.getArguments()); +// System.exit(0); + } + /** * Deletes the temporary directories and closes the log streams * @param errorStream the error stream to be closed diff --git a/src/java/main/br/ufpe/cin/groundhog/main/JsonInput.java b/src/java/main/br/ufpe/cin/groundhog/main/JsonInput.java index 13fbdf5..a83a09b 100644 --- a/src/java/main/br/ufpe/cin/groundhog/main/JsonInput.java +++ b/src/java/main/br/ufpe/cin/groundhog/main/JsonInput.java @@ -61,7 +61,7 @@ public Search getSearch() { } public String toString() { - return Objects.toStringHelper(this) + return Objects.toStringHelper("") .add("forge", forge) .add("dest", dest) .add("out", out) @@ -86,7 +86,7 @@ public List getProjects() { } public String toString() { - return Objects.toStringHelper(this) + return Objects.toStringHelper("") .add("projects", projects) .add("username", username) .toString(); diff --git a/src/java/main/br/ufpe/cin/groundhog/search/ForgeSearch.java b/src/java/main/br/ufpe/cin/groundhog/search/ForgeSearch.java index 9f84483..6addf81 100644 --- a/src/java/main/br/ufpe/cin/groundhog/search/ForgeSearch.java +++ b/src/java/main/br/ufpe/cin/groundhog/search/ForgeSearch.java @@ -24,5 +24,17 @@ public interface ForgeSearch { * @throws Exception when something nasty happens */ public List getProjects(String term, int page) throws SearchException; + + /** + * Uses search functionality of the forge to get projects. + * + * @param term term to be searched (ex: a project name, like h2database) + * @parm username the user that should have the aforementioned project + * @param page 1-indexed page to get results (ie: starts with 1) + * + * @return list of ForgeProject entities with projects info + * @throws Exception when something nasty happens + */ + public List getProjects(String term, String username, int page) throws SearchException; } \ No newline at end of file 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 5f54eed..52214ce 100644 --- a/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java +++ b/src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java @@ -115,4 +115,10 @@ public List getProjects(String term, int page) throws SearchException { throw new SearchException(e); } } + + @Override + public List getProjects(String term, String username, int page) + throws SearchException { + return getProjects(term, page); + } } \ No newline at end of file diff --git a/src/java/main/br/ufpe/cin/groundhog/search/SearchGoogleCode.java b/src/java/main/br/ufpe/cin/groundhog/search/SearchGoogleCode.java index 26cde51..9d98be0 100644 --- a/src/java/main/br/ufpe/cin/groundhog/search/SearchGoogleCode.java +++ b/src/java/main/br/ufpe/cin/groundhog/search/SearchGoogleCode.java @@ -140,4 +140,10 @@ public Integer onCompleted(Response response) throws Exception { throw new SearchException(e); } } + + @Override + public List getProjects(String term, String username, int page) + throws SearchException { + throw new UnsupportedOperationException("not implemented yet"); + } } \ No newline at end of file diff --git a/src/java/main/br/ufpe/cin/groundhog/search/SearchSourceForge.java b/src/java/main/br/ufpe/cin/groundhog/search/SearchSourceForge.java index 03a94ae..de1b696 100644 --- a/src/java/main/br/ufpe/cin/groundhog/search/SearchSourceForge.java +++ b/src/java/main/br/ufpe/cin/groundhog/search/SearchSourceForge.java @@ -65,4 +65,10 @@ public List getProjects(String term, int page) throws SearchException { throw new SearchException(e); } } + + @Override + public List getProjects(String term, String username, int page) + throws SearchException { + throw new UnsupportedOperationException("not implemented yet"); + } } \ No newline at end of file