Skip to content

Commit

Permalink
Always front slashes when searching FS
Browse files Browse the repository at this point in the history
Also adding logging the help determining why some files is not getting picked up.
  • Loading branch information
tomasbjerre committed Oct 4, 2019
1 parent 4290147 commit 7e237cc
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 11 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,21 @@ Changelog of Violations lib.
**Documenting HadoLint**


[612e68476c144b6](https://github.com/tomasbjerre/violations-lib/commit/612e68476c144b6) Tomas Bjerre *2019-09-09 14:23:24*
[d516f1a69b84b72](https://github.com/tomasbjerre/violations-lib/commit/d516f1a69b84b72) Tomas Bjerre *2019-09-09 14:24:15*


### No issue

**Always front slashes when searching FS**

* Also adding logging the help determining why some files is not getting picked up.

[2f58fe76d962fab](https://github.com/tomasbjerre/violations-lib/commit/2f58fe76d962fab) Tomas Bjerre *2019-10-04 14:40:14*

**Create FUNDING.yml**


[429014771ec2c64](https://github.com/tomasbjerre/violations-lib/commit/429014771ec2c64) Tomas Bjerre *2019-09-28 06:58:05*


## 1.100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import se.bjurr.violations.lib.model.SEVERITY;
import se.bjurr.violations.lib.model.Violation;

Expand Down Expand Up @@ -54,7 +55,7 @@ public SEVERITY toSeverity(final String severity) {
if (isNullOrEmpty(severity)) {
return INFO;
}
final String lowerCase = severity.toLowerCase();
final String lowerCase = severity.toLowerCase(Locale.ENGLISH);
if (lowerCase.contains("low")) {
return INFO;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

public class CodeClimateParser implements ViolationsParser {
private static final Logger LOG = Logger.getLogger(CodeClimateParser.class.getSimpleName());
private static final Type listType = new TypeToken<List<CodeClimate>>() {}.getType();

@Override
public List<Violation> parseReportOutput(final String string) throws Exception {
final Type listType = new TypeToken<List<CodeClimate>>() {}.getType();
final List<CodeClimate> codeClimate = new Gson().fromJson(string, listType);

final List<Violation> violations = new ArrayList<>();
Expand All @@ -38,7 +38,7 @@ public List<Violation> parseReportOutput(final String string) throws Exception {
&& issue.getLocation().getPositions().getBegin() != null) {
begin = issue.getLocation().getPositions().getBegin().getLine();
}
if (begin == -1 || begin == null) {
if (begin == -1) {
LOG.log(Level.FINE, "Ignoring issue: " + issue);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public List<Violation> parseReportOutput(final String string) throws Exception {
.setMessage(message) //
.build() //
);
} catch (final Exception e) {
} catch (final IndexOutOfBoundsException | NullPointerException e) {
LOG.info("Was unable to parse: \"" + line + "\" found parts: " + parts);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/se/bjurr/violations/lib/parsers/IARParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import se.bjurr.violations.lib.model.SEVERITY;
import se.bjurr.violations.lib.model.Violation;

Expand All @@ -25,7 +26,7 @@ public List<Violation> parseReportOutput(final String reportContent) throws Exce
final String fileName = parts.get(1).trim();
final Integer lineNumber = parseInt(parts.get(2));
final Integer columnNumber = 0;
final String severity = parts.get(3).toLowerCase().trim();
final String severity = parts.get(3).toLowerCase(Locale.ENGLISH).trim();
final String rule = parts.get(4).trim();
final String message = parts.get(5).trim();
violations.add( //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import se.bjurr.violations.lib.model.SEVERITY;
import se.bjurr.violations.lib.model.Violation;

Expand All @@ -25,7 +26,7 @@ public List<Violation> parseReportOutput(final String reportContent) throws Exce
final String fileName = parts.get(1).trim();
final Integer lineNumber = parseInt(parts.get(2));
final Integer columnNumber = 0;
final String severity = parts.get(3).toLowerCase().trim();
final String severity = parts.get(3).toLowerCase(Locale.ENGLISH).trim();
final String rule = parts.get(4).trim();
final String message = parts.get(5).trim();
violations.add( //
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/se/bjurr/violations/lib/reports/ReportsFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,34 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ReportsFinder {

public static List<File> findAllReports(File startFile, final String pattern) {
private static Logger LOG = Logger.getLogger(ReportsFinder.class.getSimpleName());

public static List<File> findAllReports(final File startFile, final String pattern) {
final List<File> found = new ArrayList<>();
final Path startPath = startFile.toPath();
try {
walkFileTree(
startPath,
new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs)
throws IOException {
final String absoluteFile = file.toFile().getAbsolutePath();
if (matches(pattern, absoluteFile)) {
final String absolutePath = file.toFile().getAbsolutePath();
if (matches(pattern, absolutePath)
|| matches(pattern, withFrontSlashes(absolutePath))) {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, pattern + " matches " + absolutePath);
}
found.add(file.toFile());
} else {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, pattern + " does not match " + absolutePath);
}
}
return super.visitFile(file, attrs);
}
Expand All @@ -38,4 +50,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
Collections.sort(found);
return found;
}

static String withFrontSlashes(final String file) {
return file.replace('\\', '/');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package se.bjurr.violations.lib.reports;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;

public class ReportsFinderTest {

@Test
public void testThatRegexpIsAlwaysMatchedAgainsFrontSlashes() {
assertThat(ReportsFinder.withFrontSlashes("C:\\any\\thing")) //
.isEqualTo("C:/any/thing");
assertThat(ReportsFinder.withFrontSlashes("C:\\any\\thing.zip")) //
.isEqualTo("C:/any/thing.zip");
assertThat(ReportsFinder.withFrontSlashes("/c/any/thing")) //
.isEqualTo("/c/any/thing");
assertThat(ReportsFinder.withFrontSlashes("/c/any/thing.zip")) //
.isEqualTo("/c/any/thing.zip");
}
}

0 comments on commit 7e237cc

Please sign in to comment.