Skip to content

Commit

Permalink
improving license parser. rel #56
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo committed Aug 5, 2013
1 parent efa724f commit f989659
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>br.ufpe.cin.groundhog</groupId>
<groupId>br.ufpe.cin</groupId>
<artifactId>groundhog</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>
Expand Down
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 @@ -10,6 +10,13 @@

import com.google.common.collect.Lists;

/**
* Class that tries to find what is the project's license.
* This in a work in progress. May lead to misleading results.
*
* @author ghlp
* @since 0.1.0
*/
public class LicenseParser {

private static Logger logger = LoggerFactory.getLogger(LicenseParser.class);
Expand All @@ -29,26 +36,28 @@ public License parser() {
logger.info("Running license parser..");

FileUtil filesUtils = FileUtil.getInstance();
for(File file: files) {
if(filesUtils.isTextFile(file)) {

for (File file : files) {
if (filesUtils.isTextFile(file)) {
String content = filesUtils.readAllLines(file);
if(containsLicenseWord(content)) {

if (containsLicenseWord(content)) {
return extractLicense(content);
}
}
}

logger.info(String.format("No license found for project %s", root.getName()));

logger.info(String.format("No license found for project %s",
root.getName()));
return new License("unlincesed");
}

private License extractLicense(String content) {

for(String license: Licenses.names()) {
if(content.contains(license)) {
logger.info(String.format("License found! %s uses %s.", root.getName(), license));

for (String license : Licenses.names()) {
if (content.contains(license)) {
logger.info(String.format("License found! %s uses %s.",
root.getName(), license));
return new License(license);
}
}
Expand Down

0 comments on commit f989659

Please sign in to comment.