Skip to content

Commit

Permalink
removing all getinstances methods from codeHistory package
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Pinto committed Apr 24, 2013
1 parent 36a484f commit a8a99b0
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package br.ufpe.cin.groundhog.codehistory;

import com.google.inject.AbstractModule;
import com.google.inject.Singleton;

public class CodeHistoryModule extends AbstractModule {

@Override
protected void configure() {
bind(GitCodeHistory.class).in(Singleton.class);
bind(SFCodeHistory.class).in(Singleton.class);
bind(SvnCodeHistory.class).in(Singleton.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,6 @@
import br.ufpe.cin.groundhog.util.FileUtil;

public class GitCodeHistory implements CodeHistory {
private static GitCodeHistory instance;

public static GitCodeHistory getInstance() {
if (instance == null) {
instance = new GitCodeHistory();
}
return instance;
}

private GitCodeHistory() {

}

@Override
public File checkoutToDate(String project, String url, Date date) {
throw new NoSuchMethodError("Not implemented");
Expand Down
12 changes: 0 additions & 12 deletions src/java/main/br/ufpe/cin/groundhog/codehistory/SFCodeHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@
import br.ufpe.cin.groundhog.util.FileUtil;

public class SFCodeHistory implements CodeHistory {
private static SFCodeHistory instance;

public static SFCodeHistory getInstance() {
if (instance == null) {
instance = new SFCodeHistory();
}
return instance;
}

private SFCodeHistory() {

}

@Override
public File checkoutToDate(String project, String url, Date date) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@
import br.ufpe.cin.groundhog.util.FileUtil;

public class SvnCodeHistory implements CodeHistory {
private static SvnCodeHistory instance;

public static SvnCodeHistory getInstance() {
if (instance == null) {
instance = new SvnCodeHistory();
}
return instance;
}

private SvnCodeHistory() {

}

@Override
public File checkoutToDate(String project, String url, Date date) throws CheckoutException {
Expand All @@ -47,5 +35,4 @@ public static void main(String[] args) throws Exception {
"http://wkhtmltopdf.googlecode.com/svn/",
d);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ public class CrawlSourceForge extends ForgeCrawler {
private Requests requests;

@Inject
public CrawlSourceForge(File destinationFolder, Requests requests) {
public CrawlSourceForge(Requests requests, File destinationFolder) {
super(destinationFolder);
this.mapModifiedDate = new ConcurrentHashMap<String, Date>();
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
this.requests = requests;
}

private void parseURLsFromPage(String project, String html, Stack<String> dirURLs, List<String> fileURLs) throws IOException, InterruptedException {
Expand Down Expand Up @@ -182,7 +183,7 @@ public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector(new HttpModule());
Requests requests = injector.getInstance(Requests.class);

CrawlSourceForge crawl = new CrawlSourceForge(dest, requests);
CrawlSourceForge crawl = new CrawlSourceForge(requests, dest);
List<Future<File>> fs = crawl.downloadProjects(projects);
crawl.shutdown();
for (Future<File> f : fs) f.get();
Expand Down
10 changes: 6 additions & 4 deletions src/java/main/br/ufpe/cin/groundhog/main/CmdMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import br.ufpe.cin.groundhog.SCM;
import br.ufpe.cin.groundhog.codehistory.CheckoutException;
import br.ufpe.cin.groundhog.codehistory.CodeHistory;
import br.ufpe.cin.groundhog.codehistory.CodeHistoryModule;
import br.ufpe.cin.groundhog.codehistory.GitCodeHistory;
import br.ufpe.cin.groundhog.codehistory.SFCodeHistory;
import br.ufpe.cin.groundhog.codehistory.SvnCodeHistory;
Expand Down Expand Up @@ -81,7 +82,7 @@ public static ForgeCrawler defineForgeCrawler(SupportedForge f, File destination
case SOURCEFORGE:
Injector injector = Guice.createInjector(new HttpModule());
Requests requests = injector.getInstance(Requests.class);
crawler = new CrawlSourceForge(destinationFolder, requests);
crawler = new CrawlSourceForge(requests, destinationFolder);
break;
case GOOGLECODE:
crawler = new CrawlGoogleCode(destinationFolder);
Expand All @@ -91,16 +92,17 @@ public static ForgeCrawler defineForgeCrawler(SupportedForge f, File destination
}

public static CodeHistory defineCodeHistory(SCM scm) throws UnsupportedSCMException {
Injector injector = Guice.createInjector(new CodeHistoryModule());
CodeHistory codehistory = null;
switch (scm) {
case GIT:
codehistory = GitCodeHistory.getInstance();
codehistory = injector.getInstance(GitCodeHistory.class);
break;
case SOURCE_FORGE:
codehistory = SFCodeHistory.getInstance();
codehistory = injector.getInstance(SFCodeHistory.class);
break;
case SVN:
codehistory = SvnCodeHistory.getInstance();
codehistory = injector.getInstance(SvnCodeHistory.class);
break;
default:
throw new UnsupportedSCMException(scm.toString());
Expand Down
36 changes: 19 additions & 17 deletions src/java/main/br/ufpe/cin/groundhog/main/TestMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Guice;
import com.google.inject.Injector;

import br.ufpe.cin.groundhog.Project;
import br.ufpe.cin.groundhog.SCM;
import br.ufpe.cin.groundhog.codehistory.CodeHistoryModule;
import br.ufpe.cin.groundhog.codehistory.GitCodeHistory;
import br.ufpe.cin.groundhog.codehistory.SFCodeHistory;
import br.ufpe.cin.groundhog.codehistory.SvnCodeHistory;
Expand All @@ -34,14 +32,17 @@
import br.ufpe.cin.groundhog.search.SearchSourceForge;
import br.ufpe.cin.groundhog.util.FileUtil;

import com.google.inject.Guice;
import com.google.inject.Injector;

public class TestMain {
private static Logger logger = LoggerFactory.getLogger(TestMain.class);

public static void gitHubExample(String term) throws Exception {
File downloadFolder = FileUtil.getInstance().createTempDir();

logger.info("1 - Search for projects according to term...");
Injector injector = Guice.createInjector(new SearchModule());
Injector injector = Guice.createInjector(new SearchModule(), new CodeHistoryModule(), new CodeHistoryModule());
SearchGitHub search = injector.getInstance(SearchGitHub.class);

List<Project> projects = search.getProjects(term, 1);
Expand All @@ -59,7 +60,8 @@ public static void gitHubExample(String term) throws Exception {

logger.info("3 - Checkout repository to a given date...");
Date date = new GregorianCalendar(2012, 6, 1).getTime();
File temp = GitCodeHistory.getInstance().checkoutToDate(project.getName(), repositoryFolder, date);
GitCodeHistory codeHistory = injector.getInstance(GitCodeHistory.class);
File temp = codeHistory.checkoutToDate(project.getName(), repositoryFolder, date);

logger.info("4 - Parse...");
JavaParser parser = new JavaParser(temp);
Expand All @@ -77,8 +79,8 @@ public static void sourceForgeExample() throws Exception {
File downloadFolder = FileUtil.getInstance().createTempDir();

logger.info("1 - Search for projects according to term...");
Injector searchInjector = Guice.createInjector(new SearchModule());
SearchSourceForge search = searchInjector.getInstance(SearchSourceForge.class);
Injector injector = Guice.createInjector(new SearchModule(), new HttpModule(), new CodeHistoryModule());
SearchSourceForge search = injector.getInstance(SearchSourceForge.class);

List<Project> projects = search.getProjects("facebook chat", 1);
if (projects.size() == 0) {
Expand All @@ -89,10 +91,9 @@ public static void sourceForgeExample() throws Exception {
projects = Arrays.asList(project); // analyze only the first project

logger.info("2 - Download 1st result...");
Injector httpInjector = Guice.createInjector(new HttpModule());
Requests requests = httpInjector.getInstance(Requests.class);
Requests requests = injector.getInstance(Requests.class);

ForgeCrawler crawler = new CrawlSourceForge(downloadFolder, requests);
ForgeCrawler crawler = new CrawlSourceForge(requests, downloadFolder);
List<Future<File>> futures = crawler.downloadProjects(projects);
crawler.shutdown();
File repositoryFolder = null;
Expand All @@ -102,7 +103,8 @@ public static void sourceForgeExample() throws Exception {

logger.info("3 - Checkout repository to a given date...");
Date date = new GregorianCalendar(2012, 2, 21).getTime();
File temp = SFCodeHistory.getInstance().checkoutToDate(project.getName(), repositoryFolder, date);
SFCodeHistory codeHistory = injector.getInstance(SFCodeHistory.class);
File temp = codeHistory.checkoutToDate(project.getName(), repositoryFolder, date);

logger.info("4 - Parse...");
JavaParser parser = new JavaParser(temp);
Expand All @@ -120,7 +122,7 @@ public static void googleCodeExample(String term) throws Exception {
File downloadFolder = FileUtil.getInstance().createTempDir();

logger.info("1 - Search for projects according to term...");
Injector injector = Guice.createInjector(new SearchModule());
Injector injector = Guice.createInjector(new SearchModule(), new CodeHistoryModule());
SearchGoogleCode search = injector.getInstance(SearchGoogleCode.class);

List<Project> projects = search.getProjects(term, 1);
Expand All @@ -140,9 +142,9 @@ public static void googleCodeExample(String term) throws Exception {
Date date = new GregorianCalendar(2011, 0, 2).getTime();
File temp = null;
if (project.getSCM() == SCM.SVN) {
temp = SvnCodeHistory.getInstance().checkoutToDate(project.getName(), project.getScmURL(), date);
temp = injector.getInstance(SvnCodeHistory.class).checkoutToDate(project.getName(), project.getScmURL(), date);
} else if (project.getSCM() == SCM.GIT) {
temp = GitCodeHistory.getInstance().checkoutToDate(project.getName(), repositoryFolder, date);
temp = injector.getInstance(GitCodeHistory.class).checkoutToDate(project.getName(), repositoryFolder, date);
} else {
logger.error("Can't continue with parsing step. Unwkown SCM.");
System.exit(0);
Expand All @@ -161,9 +163,9 @@ public static void googleCodeExample(String term) throws Exception {
}

public static void main(String[] args) throws Exception {
gitHubExample("jsoup");
// sourceForgeExample();
// gitHubExample("jsoup");
sourceForgeExample();
// googleCodeExample("facebook-java-api"); // Google Code SVN
//googleCodeExample("guava-libraries"); // Google Code Git
// googleCodeExample("guava-libraries"); // Google Code Git
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class GitCodeHistoryTest {

@Before
public void setup(){
codeHistory = SFCodeHistory.getInstance();
file = new File("C:\\Users\\fjsj\\Downloads\\EponaProjects\\playframework");
calendar = new GregorianCalendar(2012, 5, 23).getTime();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class SFCodeHistoryTest {

@Before
public void setup(){
gitCodeHistory = GitCodeHistory.getInstance();
file = new File("C:\\Users\\fjsj\\Downloads\\EponaProjects\\playframework");
calendar = new GregorianCalendar(2012, 5, 23).getTime();
}
Expand Down

0 comments on commit a8a99b0

Please sign in to comment.