-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to filter score and review issues by path
- Loading branch information
1 parent
7f34ee8
commit b9c9b38
Showing
10 changed files
with
219 additions
and
20 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions
23
src/main/java/org/jenkinsci/plugins/sonargerrit/sonar/ByGlobPatternPredicate.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,23 @@ | ||
package org.jenkinsci.plugins.sonargerrit.sonar; | ||
|
||
import com.google.common.base.Predicate; | ||
import java.nio.file.FileSystems; | ||
import java.nio.file.PathMatcher; | ||
import java.nio.file.Paths; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
/** @author Réda Housni Alaoui */ | ||
public class ByGlobPatternPredicate implements Predicate<Issue> { | ||
|
||
private final PathMatcher pathMatcher; | ||
|
||
public ByGlobPatternPredicate(String pattern) { | ||
this.pathMatcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern); | ||
} | ||
|
||
@Override | ||
public boolean apply(Issue input) { | ||
String filepath = StringUtils.prependIfMissing(input.getFilepath(), "/"); | ||
return pathMatcher.matches(Paths.get(filepath)); | ||
} | ||
} |
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
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
104 changes: 104 additions & 0 deletions
104
src/test/java/org/jenkinsci/plugins/sonargerrit/sonar/ByGlobPatternPredicateTest.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,104 @@ | ||
package org.jenkinsci.plugins.sonargerrit.sonar; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Date; | ||
import java.util.Optional; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** @author Réda Housni Alaoui */ | ||
class ByGlobPatternPredicateTest { | ||
|
||
@Test | ||
void test() { | ||
assertThat(new ByGlobPatternPredicate("**/*").apply(new DummyIssue("/foo.bar"))).isTrue(); | ||
assertThat(new ByGlobPatternPredicate("/foo.bar").apply(new DummyIssue("/foo.bar"))).isTrue(); | ||
assertThat(new ByGlobPatternPredicate("/foo/*").apply(new DummyIssue("/foo/bar"))).isTrue(); | ||
assertThat(new ByGlobPatternPredicate("/foo/**").apply(new DummyIssue("/foo/bar/baz"))) | ||
.isTrue(); | ||
assertThat(new ByGlobPatternPredicate("/foo/**").apply(new DummyIssue("/foo/bar/baz/bat.toto"))) | ||
.isTrue(); | ||
assertThat(new ByGlobPatternPredicate("/bar/**").apply(new DummyIssue("/foo/bar/baz/bat.toto"))) | ||
.isFalse(); | ||
} | ||
|
||
private static class DummyIssue implements Issue { | ||
|
||
private final String filePath; | ||
|
||
DummyIssue(String filePath) { | ||
this.filePath = requireNonNull(filePath); | ||
} | ||
|
||
@Override | ||
public String inspectorName() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String inspectionId() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Optional<String> detailUrl() { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public String getFilepath() { | ||
return filePath; | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getComponent() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Integer getLine() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Severity getSeverity() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getRule() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getRuleUrl() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getStatus() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isNew() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Date getCreationDate() { | ||
return null; | ||
} | ||
} | ||
} |
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