Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
Fix comments regex. (#13)
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Chakarov <[email protected]>

Signed-off-by: Nikolay Chakarov <[email protected]>
Co-authored-by: Nikolay Chakarov <[email protected]>
  • Loading branch information
nchakarovvmw and Nikolay Chakarov authored Sep 19, 2022
1 parent 69c72c3 commit c3eac95
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,21 @@ public void execute(SensorContext context) {
FileSystem fs = context.fileSystem();
Iterable<InputFile> files = fs.inputFiles(fs.predicates().all());
for (InputFile file : files) {
try {
String filename = file.filename();
String fileExt = FilenameUtils.getExtension(filename).toLowerCase();
if (fileExt.toLowerCase().equalsIgnoreCase("jar") || fileExt.toLowerCase().equalsIgnoreCase("zip")) {
logger.info("ITSRule: skipping binary file " + filename);
continue;
}
logger.info("Scanning " + file.filename());

String filename = file.filename();
String fileExt = FilenameUtils.getExtension(filename).toLowerCase();
if (fileExt.toLowerCase().equalsIgnoreCase("jar") || fileExt.toLowerCase().equalsIgnoreCase("zip")) {
logger.info("ITSRule: skipping binary file " + filename);
continue;
ItsFileScanner scanner = new ItsFileScanner();
scanner.scanFile(context, this, file);
} catch (Exception e) {
logger.error("An error occurred with file " + file.filename());
logger.error(e.getMessage(), e.getStackTrace());
}

ItsFileScanner scanner = new ItsFileScanner();
scanner.scanFile(context, this, file);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/sonar/plugins/its/service/ItsFileScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ public void scanFile(SensorContext context, Sensor sensor, InputFile file) {

List<SourceComment> comments = new ArrayList<SourceComment>();

// TODO add support for comments in Python, Ruby, HTML, JSON
// Check file extension and get the regex for the different file
String slComment = "//[^\r\n]*";
String mlComment = "/\\*[\\s\\S]*?\\*/";
String strLit = "\"(?:\\\\.|[^\\\\\"\r\n])*\"";
String chLit = "'(?:\\\\.|[^\\\\'\r\n])+'";
String any = "[\\s\\S]";
// String strLit = "\"(?:\\\\.|[^\\\\\"\r\n])*\"";
// String chLit = "'(?:\\\\.|[^\\\\'\r\n])+'";
// String any = "[\\s\\S]";

Pattern p = Pattern.compile(
String.format("(%s)|(%s)|%s|%s|%s", slComment, mlComment, strLit, chLit, any));
String.format("(%s)|(%s)", slComment, mlComment)); //strLit, chLit, any));

Path path = file.file().toPath();
String entireFileAsString;
Expand Down

0 comments on commit c3eac95

Please sign in to comment.