forked from SAP/fosstars-rating-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Static analysis tool providers from Prospector Project
Fixes SAP#730
- Loading branch information
1 parent
4362ea8
commit 8a7a9b2
Showing
24 changed files
with
1,199 additions
and
173 deletions.
There are no files selected for viewing
355 changes: 347 additions & 8 deletions
355
src/main/java/com/sap/oss/phosphor/fosstars/data/AbstractStaticScanToolsDataProvider.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
25 changes: 0 additions & 25 deletions
25
src/main/java/com/sap/oss/phosphor/fosstars/data/StaticAnalysisScanTool.java
This file was deleted.
Oops, something went wrong.
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
65 changes: 65 additions & 0 deletions
65
src/main/java/com/sap/oss/phosphor/fosstars/data/github/PylintDataProvider.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,65 @@ | ||
package com.sap.oss.phosphor.fosstars.data.github; | ||
|
||
import static com.sap.oss.phosphor.fosstars.model.feature.oss.OssFeatures.RUNS_PYLINT_SCANS; | ||
import static com.sap.oss.phosphor.fosstars.model.feature.oss.OssFeatures.USES_PYLINT_SCAN_CHECKS; | ||
import static com.sap.oss.phosphor.fosstars.model.other.Utils.setOf; | ||
|
||
import com.sap.oss.phosphor.fosstars.data.AbstractStaticScanToolsDataProvider; | ||
import com.sap.oss.phosphor.fosstars.model.Value; | ||
import com.sap.oss.phosphor.fosstars.model.ValueSet; | ||
import com.sap.oss.phosphor.fosstars.model.feature.oss.OssFeatures; | ||
import com.sap.oss.phosphor.fosstars.model.subject.oss.GitHubProject; | ||
import com.sap.oss.phosphor.fosstars.model.value.ValueHashSet; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* The data provider gathers info about how a project uses Bandit for static analysis. In | ||
* particular, it tries to fill out the following features: | ||
* <ul> | ||
* <li>{@link OssFeatures#RUNS_PYLINT_SCANS}</li> | ||
* <li>{@link OssFeatures#USES_PYLINT_SCAN_CHECKS}</li> | ||
* </ul> | ||
*/ | ||
public class PylintDataProvider extends AbstractStaticScanToolsDataProvider { | ||
|
||
/** | ||
* A predicate to check if the any step of a GitHub action that triggers analysis with Pylint. | ||
*/ | ||
private static final Map<String, Predicate<String>> MATCH_PYLINT_PREDICATE_MAP = new HashMap<>(); | ||
|
||
static { | ||
MATCH_PYLINT_PREDICATE_MAP.put("uses", | ||
step -> Pattern.compile("^.*pylint.*$", Pattern.DOTALL).matcher(step).matches()); | ||
MATCH_PYLINT_PREDICATE_MAP.put("run", | ||
step -> Pattern.compile("^.*pylint .*$", Pattern.DOTALL).matcher(step).matches()); | ||
MATCH_PYLINT_PREDICATE_MAP.putAll(preCommitHookContextMap(hook -> hook.contains("pylint"))); | ||
} | ||
|
||
/** | ||
* Initializes a data provider. | ||
* | ||
* @param fetcher An interface to GitHub. | ||
*/ | ||
public PylintDataProvider(GitHubDataFetcher fetcher) { | ||
super(fetcher, setOf(RUNS_PYLINT_SCANS, USES_PYLINT_SCAN_CHECKS)); | ||
} | ||
|
||
@Override | ||
protected ValueSet fetchValuesFor(GitHubProject project) throws IOException { | ||
logger.info("Figuring out how the project uses pylint ..."); | ||
|
||
LocalRepository repository = GitHubDataFetcher.localRepositoryFor(project); | ||
|
||
Visitor visitor = withVisitor(); | ||
browse(repository, MATCH_PYLINT_PREDICATE_MAP, visitor); | ||
|
||
Value<Boolean> runsPylint = RUNS_PYLINT_SCANS.value(visitor.runCheck); | ||
Value<Boolean> usesPylintScanChecks = USES_PYLINT_SCAN_CHECKS.value(visitor.usesCheck); | ||
|
||
return ValueHashSet.from(runsPylint, usesPylintScanChecks); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/sap/oss/phosphor/fosstars/github/AbstractGitHubVisitor.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,37 @@ | ||
package com.sap.oss.phosphor.fosstars.github; | ||
|
||
import com.sap.oss.phosphor.fosstars.data.github.LocalRepository; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
|
||
/** | ||
* An implementation of {@link GitHubVisitor} that does nothing. | ||
*/ | ||
public abstract class AbstractGitHubVisitor implements GitHubVisitor { | ||
|
||
@Override | ||
public void visitPreCommitHook(LocalRepository repository, | ||
Map<String, Predicate<String>> matchers, Set<Location> locations) throws IOException { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public void visitIniConfig(LocalRepository repository, Map<String, Predicate<String>> matchers, | ||
Set<Location> locations) throws IOException { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public void visitSourceCode(LocalRepository repository, Map<String, Predicate<String>> matchers, | ||
Set<Location> locations) throws IOException { | ||
// don nothing | ||
} | ||
|
||
@Override | ||
public void visitGitHubAction(LocalRepository repository, Map<String, Predicate<String>> matchers, | ||
Set<Location> locations) throws IOException { | ||
// do nothing | ||
} | ||
} |
Oops, something went wrong.