Skip to content

Commit

Permalink
with method to gather projects list by user. working on #33
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Pinto committed May 17, 2013
1 parent 7a9149f commit 2464e8b
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 15 deletions.
14 changes: 6 additions & 8 deletions src/java/main/br/ufpe/cin/groundhog/crawler/CrawlGitHub.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public File call() throws Exception {
* Should be called after downloadProjects.
*/
public void shutdown() {
ex.shutdown();
ex.shutdownNow();
}

}
11 changes: 9 additions & 2 deletions src/java/main/br/ufpe/cin/groundhog/main/CmdMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,22 @@ 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());
ForgeSearch search = defineForgeSearch(input.getForge());
ForgeCrawler crawler = defineForgeCrawler(input.getForge(), destinationFolder);

String term = input.getSearch().getProjects().get(3);
List<Project> allProjects = search.getProjects(term, 1);

List<Project> allProjects = null;
if(username != null) {
allProjects = search.getProjects(term, 1);
} else {
allProjects = search.getProjects(term, username, 1);
}

List<Project> projects = new ArrayList<Project>();
for (int i = 0; i < nProjects; i++) {
Expand Down
14 changes: 12 additions & 2 deletions src/java/main/br/ufpe/cin/groundhog/main/GroundhogMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/java/main/br/ufpe/cin/groundhog/main/JsonInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -86,7 +86,7 @@ public List<String> getProjects() {
}

public String toString() {
return Objects.toStringHelper(this)
return Objects.toStringHelper("")
.add("projects", projects)
.add("username", username)
.toString();
Expand Down
12 changes: 12 additions & 0 deletions src/java/main/br/ufpe/cin/groundhog/search/ForgeSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,17 @@ public interface ForgeSearch {
* @throws Exception when something nasty happens
*/
public List<Project> 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<Project> getProjects(String term, String username, int page) throws SearchException;

}
6 changes: 6 additions & 0 deletions src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,10 @@ public List<Project> getProjects(String term, int page) throws SearchException {
throw new SearchException(e);
}
}

@Override
public List<Project> getProjects(String term, String username, int page)
throws SearchException {
return getProjects(term, page);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,10 @@ public Integer onCompleted(Response response) throws Exception {
throw new SearchException(e);
}
}

@Override
public List<Project> getProjects(String term, String username, int page)
throws SearchException {
throw new UnsupportedOperationException("not implemented yet");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,10 @@ public List<Project> getProjects(String term, int page) throws SearchException {
throw new SearchException(e);
}
}

@Override
public List<Project> getProjects(String term, String username, int page)
throws SearchException {
throw new UnsupportedOperationException("not implemented yet");
}
}

0 comments on commit 2464e8b

Please sign in to comment.