本文整理汇总了Java中org.sonar.api.issue.Issuable.addIssue方法的典型用法代码示例。如果您正苦于以下问题:Java Issuable.addIssue方法的具体用法?Java Issuable.addIssue怎么用?Java Issuable.addIssue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sonar.api.issue.Issuable
的用法示例。
在下文中一共展示了Issuable.addIssue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addError
import org.sonar.api.issue.Issuable; //导入方法依赖的package包/类
@Override
public void addError(AuditEvent event) {
final String ruleKey = getRuleKey(event);
if (ruleKey != null) {
final String message = getMessage(event);
// In Checkstyle 5.5 exceptions are reported as an events from
// TreeWalker
if ("com.puppycrawl.tools.checkstyle.TreeWalker".equals(ruleKey)) {
LOG.warn("{} : {}", event.getFileName(), message);
}
initResource(event);
final Issuable issuable = perspectives.as(Issuable.class, currentResource);
final Rule rule = ruleFinder.findByKey(CheckstyleConstants.REPOSITORY_KEY, ruleKey);
if (rule != null && issuable != null) {
final IssueBuilder issueBuilder = issuable.newIssueBuilder().ruleKey(rule.ruleKey())
.message(message).line(getLineId(event));
issuable.addIssue(issueBuilder.build());
}
}
}
示例2: analyse
import org.sonar.api.issue.Issuable; //导入方法依赖的package包/类
public void analyse(Project project, SensorContext sensorContext) {
if (CodeReviewInitialize.reviewResult == null || CodeReviewInitialize.reviewResult.getProjectBasedir() == null) return;
logger.debug("Project basedir : " + CodeReviewInitialize.reviewResult.getProjectBasedir());
File projectBasedir = new File(CodeReviewInitialize.reviewResult.getProjectBasedir());
for (RuleType rule : CodeReviewInitialize.reviewResult.getRule()) {
if (rule.getResult().size() > 0) {
logger.debug("Found one non conformity : " + rule.getRule().getKey());
RuleKey ruleKey = RuleKey.of("FCCodeReviewRepository", rule.getRule().getKey());
for (Result result : rule.getResult()) {
File resourceToFind = new File(projectBasedir.getAbsolutePath() + result.getResource());
InputFile resource = fs.inputFile(fs.predicates().hasPath(projectBasedir.getAbsolutePath() + result.getResource()));
if (resource != null) {
logger.debug("Resource found : " + resourceToFind.getAbsolutePath());
Issuable issuable = perspectives.as(Issuable.class, resource);
issuable.addIssue(issuable.newIssueBuilder().ruleKey(ruleKey).line(1).build());
} else {
logger.debug("Resource not found : " + resourceToFind.getAbsolutePath());
}
}
}
}
}
示例3: saveMetrics
import org.sonar.api.issue.Issuable; //导入方法依赖的package包/类
private void saveMetrics(org.sonar.api.resources.File sonarFile, SensorContext context, SourceCode sourceCode) {
for (Issue issue : sourceCode.getIssues()) {
logger.finer("Saving issue: " + issue);
Issuable issuable = perspectives.as(Issuable.class, sonarFile);
if (issuable != null) {
org.sonar.api.issue.Issue sIssue = issuable.newIssueBuilder()
.ruleKey(issue.rule())
.line(issue.line())
.message(issue.message())
.build();
issuable.addIssue(sIssue);
}
}
for (Measure measure : sourceCode.getMeasures()) {
logger.finer("Saving measure: " + measure);
context.saveMeasure(sourceCode.getResource(), measure);
}
for (Dependency dependency : sourceCode.getDependencies()) {
logger.finer("Saving dependency: " + dependency);
context.saveDependency(dependency);
}
}
示例4: addIssue
import org.sonar.api.issue.Issuable; //导入方法依赖的package包/类
private void addIssue(Issuable issuable, String message, RuleKey rule) {
Issue issue = issuable.newIssueBuilder()
.ruleKey(rule)
.message(message)
.build();
issuable.addIssue(issue);
}
示例5: saveViolations
import org.sonar.api.issue.Issuable; //导入方法依赖的package包/类
private void saveViolations(InputFile inputFile, SourceFile squidFile) {
Collection<CheckMessage> messages = squidFile.getCheckMessages();
if (messages != null) {
for (CheckMessage message : messages) {
SquidCheck<Grammar> c = (SquidCheck<Grammar>) message.getCheck();
logger.debug("+++File: " + squidFile.getKey() + " - Checking message ToplevelService: " + squidFile.getInt(FlowMetric.IS_TOP_LEVEL) + " TopLevelCheck: " + String.valueOf(c instanceof TopLevelCheck));
if(squidFile.getInt(FlowMetric.IS_TOP_LEVEL)!=1 && c instanceof TopLevelCheck){
logger.debug("+++Ignoring toplevelCheck: " + c.getKey() + " for file: " + squidFile.getKey());
}else{
logger.debug("+++ Message " + message.getDefaultMessage());
logger.debug("+++ Message " + message.toString());
RuleKey ruleKey;
if(message.getCheck() instanceof NodeCheck){
ruleKey = nodeChecks.ruleKey((SquidCheck<Grammar>) message.getCheck());
}else
ruleKey = checks.ruleKey((SquidCheck<Grammar>) message.getCheck());
Issuable issuable = resourcePerspectives.as(Issuable.class, inputFile);
if (issuable != null) {
IssueBuilder issueBuilder = issuable.newIssueBuilder().ruleKey(ruleKey).line(message.getLine())
.message(message.getText(Locale.ENGLISH));
if (message.getCost() != null) {
issueBuilder.effortToFix(message.getCost());
}
issuable.addIssue(issueBuilder.build());
}
}
}
}
}
示例6: saveIssues
import org.sonar.api.issue.Issuable; //导入方法依赖的package包/类
private void saveIssues(final List<TextIssue> issuesList, final InputFile againstThisFile) {
for (TextIssue issue : issuesList) {
Issuable issuable = resourcePerspectives.as(Issuable.class, againstThisFile);
if (issuable != null) {
issuable.addIssue(
issuable.newIssueBuilder()
.ruleKey(issue.getRuleKey())
.line(issue.getLine())
.message(issue.getMessage())
.build());
}
}
}
示例7: analyse
import org.sonar.api.issue.Issuable; //导入方法依赖的package包/类
@Override
public void analyse(Project project, SensorContext sensorContext) {
LOG.info("Starting analyse of Project " + fileSystem.baseDir().getName());
for (InputFile inputFile : fileSystem.inputFiles(fileSystem.predicates().hasLanguage("bpel"))) {
PortabilityAnalyzer analyzer = new PortabilityAnalyzer();
Path currentFilePath = Paths.get(inputFile.absolutePath());
List<ReportEntry> entries = analyzer.analyzeFile(currentFilePath);
if (entries.size() > 0) {
for (ReportEntry currentEntry : entries) {
for (String currentMetric : currentEntry.getVariableNames())
if (currentMetric.equals("class")) {
sensorContext.saveMeasure(inputFile,
new Measure<String>(PortabilityMetrics.CLASSIFICATION, currentEntry.getVariableValue(currentMetric)));
} else if (currentMetric.equals("N")) {
sensorContext.saveMeasure(inputFile,
new Measure<Integer>(PortabilityMetrics.N, (double) Integer.valueOf(currentEntry.getVariableValue(currentMetric))));
} else if (currentMetric.equals("Mb")) {
sensorContext.saveMeasure(inputFile,
new Measure<Double>(PortabilityMetrics.MB, Double.valueOf(currentEntry.getVariableValue(currentMetric)), 2));
} else if (currentMetric.equals("Me")) {
sensorContext.saveMeasure(inputFile,
new Measure<Double>(PortabilityMetrics.ME, Double.valueOf(currentEntry.getVariableValue(currentMetric)), 2));
} else if (currentMetric.equals("Ma")) {
sensorContext.saveMeasure(inputFile,
new Measure<Double>(PortabilityMetrics.MA, Double.valueOf(currentEntry.getVariableValue(currentMetric)), 2));
} else if (currentMetric.equals("Ms")) {
sensorContext.saveMeasure(inputFile,
new Measure<Double>(PortabilityMetrics.MS, Double.valueOf(currentEntry.getVariableValue(currentMetric)), 2));
}
}
}
List<Warning> warnings = analyzer.getWarningsFromLastAnalysis();
if (warnings.size() > 0) {
Issuable issuable = perspectives.as(Issuable.class, inputFile);
for (Warning warning : warnings) {
if (issuable != null) {
// can be used
Issue issue = issuable.newIssueBuilder()
.ruleKey(RuleKey.of("portability-issues", warning.getAssertion().getId()))
.line(warning.getLine())
.message(warning.getAssertion().getDiagnosticMessage())
.build();
issuable.addIssue(issue);
}
}
}
}
}
示例8: parseReport
import org.sonar.api.issue.Issuable; //导入方法依赖的package包/类
private void parseReport(FileProvider fileProvider, ReSharperReportParser parser, File reportFile) {
LOG.info("Parsing ReSharper report: " + reportFile);
File solutionFile = new File(settings.getString(ReSharperPlugin.SOLUTION_FILE_PROPERTY_KEY));
String projectName = settings.getString(ReSharperPlugin.PROJECT_NAME_SONAR_PROPERTY_KEY);
LOG.info(ReSharperPlugin.PROJECT_NAME_SONAR_PROPERTY_KEY + " " + projectName);
List<ReSharperIssue> parse = parser.parse(reportFile, projectName);
for (ReSharperIssue issue : parse) {
if (!hasFileAndLine(issue)) {
logSkippedIssue(issue, "which has no associated file.");
continue;
}
File file = fileProvider.fileInSolution(solutionFile, issue.filePath());
//The below code is implemented to try to resolve an issue where something is passing a wonky file path i.e.
// "D:\\vssrc\\GregsProject\\\"D:\\vssrc\\GregsProject\\Common Libraries\\Common Libraries\\Class1.cs\"";
//The below condition will attempt to detect this type of string and rip out only the full path to the file
if(file.getAbsolutePath().contains("\\\"") && file.getAbsolutePath().endsWith("\"")){
String badFilePath = file.getAbsolutePath();
int position = badFilePath.indexOf("\\\"");
String newPath = file.getAbsolutePath().substring(position + 2,file.getAbsolutePath().length()-1);
//change the file variable to the new filePath.
file = new File(newPath);
}
InputFile inputFile;
try {
inputFile = fileSystem.inputFile(
fileSystem.predicates().and(
fileSystem.predicates().hasAbsolutePath(file.getAbsolutePath()),
fileSystem.predicates().hasType(InputFile.Type.MAIN))
);
}catch (Exception ex){
logSkippedIssue(issue, "Failed to get input file: \"" + ex.getMessage() +"\"");
continue;
}
if (inputFile == null) {
logSkippedIssueOutsideOfSonarQube(issue, file);
} else if (reSharperConf.languageKey().equals(inputFile.language())) {
Issuable issuable = perspectives.as(Issuable.class, inputFile);
if (issuable == null) {
logSkippedIssueOutsideOfSonarQube(issue, file);
} else if (!enabledRuleKeys().contains(issue.ruleKey())) {
logSkippedIssue(issue, "because the rule \"" + issue.ruleKey() + "\" is either missing or inactive in the quality profile.");
} else {
issuable.addIssue(
issuable.newIssueBuilder()
.ruleKey(RuleKey.of(reSharperConf.repositoryKey(), issue.ruleKey()))
.line(issue.line())
.message(issue.message())
.build());
}
}
}
}