-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Gustavo Pinto
committed
Jul 2, 2013
1 parent
3eb0c9a
commit 31f9883
Showing
15 changed files
with
148 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package br.ufpe.cin.groundhog; | ||
|
||
/** | ||
* Represents the license used in the project | ||
*/ | ||
public class License { | ||
|
||
private String name; | ||
private String entireContent; | ||
|
||
public License(String name) { | ||
this.name = name; | ||
} | ||
|
||
public License(String name, String entireContent) { | ||
this.entireContent = entireContent; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getEntireContent() { | ||
return entireContent; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/java/main/br/ufpe/cin/groundhog/parser/formater/FormaterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...oundhog/parser/CodeAnalyzerProcessor.java → ...og/parser/java/CodeAnalyzerProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ndhog/parser/CodeAnalyzerTreeVisitor.java → .../parser/java/CodeAnalyzerTreeVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ufpe/cin/groundhog/parser/MutableInt.java → ...cin/groundhog/parser/java/MutableInt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...dhog/parser/NotAJavaProjectException.java → ...parser/java/NotAJavaProjectException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...er/UnsupportedMetricsFormatException.java → ...va/UnsupportedMetricsFormatException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/java/main/br/ufpe/cin/groundhog/parser/license/LicenseNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package br.ufpe.cin.groundhog.parser.license; | ||
|
||
import br.ufpe.cin.groundhog.GroundhogException; | ||
|
||
public class LicenseNotFoundException extends GroundhogException { | ||
|
||
/** | ||
* | ||
*/ | ||
private static final long serialVersionUID = -6933755608744941883L; | ||
|
||
public LicenseNotFoundException(String msg) { | ||
super(msg); | ||
} | ||
|
||
} |
92 changes: 92 additions & 0 deletions
92
src/java/main/br/ufpe/cin/groundhog/parser/license/LicenseParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package br.ufpe.cin.groundhog.parser.license; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.RandomAccessFile; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import br.ufpe.cin.groundhog.License; | ||
import br.ufpe.cin.groundhog.parser.java.JavaParser; | ||
|
||
public class LicenseParser { | ||
|
||
private static Logger logger = LoggerFactory.getLogger(JavaParser.class); | ||
|
||
private final File[] files; | ||
|
||
public LicenseParser(File folder) { | ||
this.files = folder.listFiles(); | ||
} | ||
|
||
/** | ||
* Parses the top level folder looking for licenses files | ||
*/ | ||
License parser() { | ||
logger.info("Running license parser.."); | ||
|
||
try { | ||
for (File file : files) { | ||
if (isText(file)) { | ||
boolean containsLicense = containLicense(file); | ||
if(containsLicense) { | ||
return extractLicense(file); | ||
} | ||
} | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
throw new LicenseNotFoundException("No license found for project %s"); | ||
} | ||
|
||
private License extractLicense(File file) { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
private boolean containLicense(File file) { | ||
// TODO Auto-generated method stub | ||
return false; | ||
} | ||
|
||
private boolean isText(final File file) | ||
throws IOException { | ||
final int BUFFER_SIZE = 10 * 1024; | ||
boolean isText = true; | ||
byte[] buffer = new byte[BUFFER_SIZE]; | ||
|
||
final RandomAccessFile fis = new RandomAccessFile(file, "r"); | ||
try { | ||
fis.seek(0); | ||
final int read = fis.read(buffer); | ||
int lastByteTranslated = 0; | ||
for (int i = 0; i < read && isText; i++) { | ||
final byte b = buffer[i]; | ||
int ub = b & (0xff); | ||
int utf8value = lastByteTranslated + ub; | ||
lastByteTranslated = (ub) << 8; | ||
|
||
if (ub == 0x09 | ||
|| ub == 0x0A | ||
|| ub == 0x0C | ||
|| ub == 0x0D | ||
|| (ub >= 0x20 && ub <= 0x7E) | ||
|| (ub >= 0xA0 && ub <= 0xEE) | ||
|| (utf8value >= 0x2E2E && utf8value <= 0xC3BF)) { | ||
|
||
} else { | ||
isText = false; | ||
} | ||
} | ||
} finally { | ||
try { | ||
fis.close(); | ||
} catch (final Throwable th) { | ||
} | ||
|
||
} | ||
return isText; | ||
} | ||
} |