Skip to content

Commit

Permalink
license parser currently on beta. rl #56
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Pinto committed Aug 6, 2013
1 parent 22d4bb5 commit ba88aeb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/java/main/br/ufpe/cin/groundhog/License.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ public String getName() {
public String getEntireContent() {
return entireContent;
}

public String toString() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public File checkoutToDate(String project, File repositoryFolder, final Date dat
FileUtil.getInstance().copyDirectory(repositoryFolder,
projectFolder);

logger.info("Checking out to the specific date..");
this.gitClient.checkout(projectFolder, date);
return projectFolder;
} catch (EmptyProjectAtDateException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public File downloadProject(Project project) {
this.gitClient.clone(cloneUrl, projectFolder);
return projectFolder;
} catch (Exception e) {
String error = String.format("Unable to download %s (%s) project", project.getName(), project.getURL());
String error = String.format("Unable to download %s (%s) project", project.getName(), project.getScmURL());
logger.error(error);
throw new DownloadExecption(error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.concurrent.Future;

import br.ufpe.cin.groundhog.Project;
import br.ufpe.cin.groundhog.main.JsonInput;

/**
* An abstract class that defines the forge crawl functionality.
Expand All @@ -26,7 +25,7 @@ public abstract class ForgeCrawler {
* Constructs a new ForgeCrawler with a given destinationFolder.
*/
protected ForgeCrawler() {
this.ex = Executors.newFixedThreadPool(JsonInput.getMaxThreads());
this.ex = Executors.newCachedThreadPool();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ private License extractLicense(String content) {

for (String license : Licenses.names()) {
if (content.contains(license)) {
logger.info(String.format("License found! %s uses %s license.",
root.getName(), license));
logger.info(String.format("License found! %s uses %s license.", root.getName(), license));
return new License(license);
}
}
Expand All @@ -75,8 +74,7 @@ private License extractLicense(String content) {

private boolean containsLicenseWord(String content) {

for (String licenseKeyword : Lists.newArrayList("license", "copyright",
"permission")) {
for (String licenseKeyword : Lists.newArrayList("license", "copyright", "permission")) {
if (content.toLowerCase().contains(licenseKeyword)) {
return true;
}
Expand Down
24 changes: 14 additions & 10 deletions src/java/main/br/ufpe/cin/groundhog/search/SearchGitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,30 +355,34 @@ public List<Project> getAllForgeProjects(int start, int limit) throws SearchExce
int totalRepositories = 0;
while(totalRepositories < limit || limit < 0){

String searchUrl = ROOT + String.format("/repositories?since=%s&language=java&%s", since, this.oauthToken);
String searchUrl = String.format("%s/repositories?since=%s&language=java&%s", ROOT, since, this.oauthToken);
String jsonString = requests.get(searchUrl);

JsonArray jsonArray = gson.fromJson(jsonString, JsonElement.class).getAsJsonArray();
for (int i = 0; i < jsonArray.size() &&
(totalRepositories + i < limit || limit < 0); i++) {

String repoName = jsonArray.get(i).getAsJsonObject().get("name").getAsString();
String searchUrlLegacy = String.format("%s/legacy/repos/search/%s?language=java&%s", ROOT, repoName, this.oauthToken);
String searchUrlLegacy = String.format("%s/legacy/repos/search/%s?language=java%s", ROOT, repoName, this.oauthToken);

String jsonLegacy = requests.get(searchUrlLegacy);

JsonObject jsonObject = gson.fromJson(jsonLegacy, JsonElement.class).getAsJsonObject();
JsonArray jsonArrayLegacy = jsonObject.get("repositories").getAsJsonArray();

if( jsonArrayLegacy.size() == 0 ) continue; // not a java project
if( jsonArrayLegacy.size() > 0) {

String element = jsonArrayLegacy.get(0).toString(); // results are sorted by best match
Project p = gson.fromJson(element, Project.class);
p.setSCM(SCM.GIT);
p.setScmURL(String.format("git://github.com/%s/%s.git", p.getOwner(), p.getName()));

projects.add(p);
totalRepositories++;
JsonObject rawJsonObject = jsonArrayLegacy.get(0).getAsJsonObject();
String stringElement = rawJsonObject.toString();
Project p = gson.fromJson(stringElement, Project.class);

p.setSCM(SCM.GIT);
String owner = rawJsonObject.getAsJsonObject().get("owner").getAsString();
p.setScmURL(String.format("git://github.com/%s/%s.git", owner, p.getName()));

projects.add(p);
totalRepositories++;
}
}
JsonElement lastPagesRepository = jsonArray.get(jsonArray.size() -1);
since = lastPagesRepository.getAsJsonObject().get("id").getAsInt();
Expand Down

0 comments on commit ba88aeb

Please sign in to comment.