本文整理汇总了Java中org.sonar.api.batch.sensor.issue.NewIssueLocation类的典型用法代码示例。如果您正苦于以下问题:Java NewIssueLocation类的具体用法?Java NewIssueLocation怎么用?Java NewIssueLocation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NewIssueLocation类属于org.sonar.api.batch.sensor.issue包,在下文中一共展示了NewIssueLocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIssuesForMutants
import org.sonar.api.batch.sensor.issue.NewIssueLocation; //导入依赖的package包/类
private void createIssuesForMutants(List<MutantResult> mutantResults, SensorContext context, MutantStatus targetStatus, String ruleKey) throws IOException {
if (isRuleActive(ruleKey)) {
int count = 0;
for (MutantResult mutantResult : mutantResults) {
if (mutantResult.getStatus() == targetStatus) {
count++;
InputFile file = locateSourceFile(mutantResult.getSourceFilePath());
NewIssue issue = context.newIssue();
NewIssueLocation location = issue.newLocation()
.on(file)
.at(mutantResult.getLocation().getRange(file))
.message(formatIssueMessage(mutantResult));
issue.at(location);
issue.forRule(RuleKey.of(RULE_REPOSITORY_KEY, ruleKey));
issue.save();
}
}
log.info("Reported {} issue(s) as {}.", count, targetStatus);
} else {
log.info("Skip reporting {} mutant(s), because rule {} is inactive", targetStatus, ruleKey);
}
}
示例2: saveLineIssue
import org.sonar.api.batch.sensor.issue.NewIssueLocation; //导入依赖的package包/类
private void saveLineIssue(LineIssue issue) {
NewIssue newIssue = sensorContext.newIssue();
InputFile primaryFile = Preconditions.checkNotNull(fileSystem.inputFile(fileSystem.predicates().is(issue.file())));
NewIssueLocation primaryLocation = newIssue.newLocation()
.message(issue.message())
.on(primaryFile)
.at(primaryFile.selectLine(issue.line()));
newIssue
.forRule(ruleKey(issue.check()))
.at(primaryLocation);
if (issue.cost() != null) {
newIssue.gap(issue.cost());
}
newIssue.save();
}
示例3: saveIssue
import org.sonar.api.batch.sensor.issue.NewIssueLocation; //导入依赖的package包/类
private void saveIssue(final SensorContext context, final InputFile inputFile, String lineString, final String externalRuleKey, final String message) {
RuleKey ruleKey = RuleKey.of(FramaCRulesDefinition.getRepositoryKeyForLanguage(), externalRuleKey);
LOGGER.info("externalRuleKey: "+externalRuleKey);
LOGGER.info("Repo: "+FramaCRulesDefinition.getRepositoryKeyForLanguage());
LOGGER.info("RuleKey: "+ruleKey);
NewIssue newIssue = context.newIssue()
.forRule(ruleKey);
NewIssueLocation primaryLocation = newIssue.newLocation()
.on(inputFile)
.message(message);
int maxLine = inputFile.lines();
int iLine = getLineAsInt(lineString, maxLine);
if (iLine > 0) {
primaryLocation.at(inputFile.selectLine(iLine));
}
newIssue.at(primaryLocation);
newIssue.save();
}
示例4: consumeFor
import org.sonar.api.batch.sensor.issue.NewIssueLocation; //导入依赖的package包/类
@Override
void consumeFor(InputFile inputFile, FileIssues message) {
for (SonarAnalyzer.FileIssues.Issue issue : message.getIssueList()) {
NewIssue newIssue = context.newIssue();
NewIssueLocation location = newIssue
.newLocation()
.on(inputFile)
.message(issue.getMessage());
SonarAnalyzer.TextRange issueTextRange = issue.getLocation();
if (issueTextRange.getStartOffset() == issueTextRange.getEndOffset() &&
issueTextRange.getStartLine() == issueTextRange.getEndLine()) {
// file level issue
} else {
location = location.at(toTextRange(inputFile, issueTextRange));
}
newIssue.forRule(RuleKey.of(repositoryKey, issue.getId()))
.at(location)
.save();
}
}
示例5: saveIssue
import org.sonar.api.batch.sensor.issue.NewIssueLocation; //导入依赖的package包/类
void saveIssue(InputFile inputFile, int line, String externalRuleKey, String message) {
RuleKey rule = RuleKey.of(PerlCriticRulesDefinition.getRepositoryKey(), externalRuleKey);
if (activeRules.find(rule) == null) {
log.info("Ignoring unknown or deactivated issue of type {}", rule);
return;
}
log.debug("Saving an issue of type {} on file {}", rule, inputFile);
NewIssue issue = this.context.newIssue().forRule(rule);
NewIssueLocation location = issue.newLocation().message(message).on(inputFile);
if (line > 0) {
location.at(inputFile.selectLine(line));
}
issue.at(location);
issue.save();
}
示例6: createNewIssue
import org.sonar.api.batch.sensor.issue.NewIssueLocation; //导入依赖的package包/类
private void createNewIssue(IssueAttributes issueAttributes, LocationAttributes locationAttributes, InputFile inputFile) {
Preconditions.checkNotNull(issueAttributes);
Preconditions.checkNotNull(locationAttributes);
Preconditions.checkNotNull(inputFile);
final NewIssue issue = sensorContext.newIssue();
final NewIssueLocation issueLocation = issue.newLocation();
issueLocation.on(inputFile);
issueLocation.at(inputFile.selectLine(locationAttributes.getLine().get()));
issueLocation.message(locationAttributes.getMessage().get());
issue.forRule(RuleKey.of(ColdFusionPlugin.REPOSITORY_KEY, issueAttributes.getId().get()));
issue.at(issueLocation);
issue.save();
}
示例7: addSecondaryLocation
import org.sonar.api.batch.sensor.issue.NewIssueLocation; //导入依赖的package包/类
private void addSecondaryLocation(final NewIssue issue, final XMLReportFinding xanFinding,
final SensorContext sensorContext) {
final InputFile secondaryFile = mkInputFileOrNull(xanFinding.getSecondaryLocationOrNull(),
sensorContext);
if (secondaryFile != null) {
final NewIssueLocation secondaryLocation = issue.newLocation();
secondaryLocation.on(secondaryFile);
secondaryLocation.message(xanFinding.getSecondaryLocationMessage());
final int secondaryLine = normalizeLineNo(
xanFinding.getSecondaryLocationOrNull().getLineNoOrMinus1());
if (secondaryLine <= secondaryFile.lines()) {
final TextRange textRange = secondaryFile.selectLine(secondaryLine);
secondaryLocation.at(textRange);
}
issue.addLocation(secondaryLocation);
LOG.debug("Added secondary location for finding " + xanFinding.getFindingID());
}
}
示例8: saveIssues
import org.sonar.api.batch.sensor.issue.NewIssueLocation; //导入依赖的package包/类
private void saveIssues(InputFile inputFile, SourceFile squidFile) {
Collection<CheckMessage> messages = squidFile.getCheckMessages();
for (CheckMessage message : messages) {
RuleKey ruleKey = checks.ruleKey((SquidAstVisitor<Grammar>) message.getCheck());
NewIssue newIssue = context.newIssue();
NewIssueLocation primaryLocation = newIssue.newLocation()
.message(message.getText(Locale.ENGLISH))
.on(inputFile);
if (message.getLine() != null) {
primaryLocation.at(inputFile.selectLine(message.getLine()));
}
newIssue.forRule(ruleKey).at(primaryLocation).save();
}
}
示例9: processParseException
import org.sonar.api.batch.sensor.issue.NewIssueLocation; //导入依赖的package包/类
private static void processParseException(ParseException e, SensorContext context, CompatibleInputFile inputFile, Optional<RuleKey> parsingErrorKey) {
reportAnalysisError(e, context, inputFile);
LOG.warn("Unable to parse file {}", inputFile.absolutePath());
LOG.warn("Cause: {}", e.getMessage());
if (parsingErrorKey.isPresent()) {
// the ParsingErrorCheck rule is activated: we create a beautiful issue
NewIssue newIssue = context.newIssue();
NewIssueLocation primaryLocation = newIssue.newLocation()
.message("Parse error: " + e.getMessage())
.on(inputFile.wrapped());
newIssue
.forRule(parsingErrorKey.get())
.at(primaryLocation)
.save();
}
}
示例10: saveViolations
import org.sonar.api.batch.sensor.issue.NewIssueLocation; //导入依赖的package包/类
private void saveViolations(SensorContext context, InputFile inputFile, SourceFile squidFile) {
Collection<CheckMessage> messages = squidFile.getCheckMessages();
if (messages != null) {
for (CheckMessage message : messages) {
RuleKey ruleKey = checks.ruleKey((SquidCheck<LexerlessGrammar>) message.getCheck());
NewIssue newIssue = context.newIssue()
.forRule(ruleKey)
.gap(message.getCost());
Integer line = message.getLine();
NewIssueLocation location = newIssue.newLocation()
.on(inputFile)
.message(message.getText(Locale.ENGLISH));
if (line != null) {
location.at(inputFile.selectLine(line));
}
newIssue.at(location);
newIssue.save();
}
}
}
示例11: processRecognitionException
import org.sonar.api.batch.sensor.issue.NewIssueLocation; //导入依赖的package包/类
private void processRecognitionException(RecognitionException e, SensorContext sensorContext, InputFile inputFile) {
if (parsingErrorRuleKey != null) {
NewIssue newIssue = sensorContext.newIssue();
NewIssueLocation primaryLocation = newIssue.newLocation()
.message(e.getMessage())
.on(inputFile)
.at(inputFile.selectLine(e.getLine()));
newIssue
.forRule(parsingErrorRuleKey)
.at(primaryLocation)
.save();
}
}
示例12: processRecognitionException
import org.sonar.api.batch.sensor.issue.NewIssueLocation; //导入依赖的package包/类
private void processRecognitionException(RecognitionException e, SensorContext sensorContext, InputFile inputFile) {
if (parsingErrorRuleKey != null) {
NewIssue newIssue = sensorContext.newIssue();
NewIssueLocation primaryLocation = newIssue.newLocation()
.message(e.getMessage())
.on(inputFile)
.at(inputFile.selectLine(e.getLine()));
newIssue
.forRule(parsingErrorRuleKey)
.at(primaryLocation)
.save();
}
}
示例13: saveFileIssue
import org.sonar.api.batch.sensor.issue.NewIssueLocation; //导入依赖的package包/类
private void saveFileIssue(FileIssue issue) {
NewIssue newIssue = sensorContext.newIssue();
InputFile primaryFile = Preconditions.checkNotNull(fileSystem.inputFile(fileSystem.predicates().is(issue.file())));
NewIssueLocation primaryLocation = newIssue.newLocation()
.message(issue.message())
.on(primaryFile);
newIssue
.forRule(ruleKey(issue.check()))
.at(primaryLocation);
if (issue.cost() != null) {
newIssue.gap(issue.cost());
}
InputFile secondaryFile;
for (IssueLocation secondary : issue.secondaryLocations()) {
secondaryFile = fileSystem.inputFile(fileSystem.predicates().is(secondary.file()));
if (secondaryFile == null) {
secondaryFile = primaryFile;
}
newIssue.addLocation(newLocation(secondaryFile, newIssue, secondary));
}
newIssue.save();
}
示例14: fill
import org.sonar.api.batch.sensor.issue.NewIssueLocation; //导入依赖的package包/类
@Override
public void fill(final SensorContext context, final InputFile inputFile,
final TsqlIssue... issues) {
for (final TsqlIssue error : issues) {
InputFile file = inputFile;
try {
if (error.getLine() < 1) {
LOGGER.warn(
format("Can't add issue %s on file %s as line is 0", error.getType(), error.getFilePath()));
continue;
}
if (file == null){
final FileSystem fileSystem = context.fileSystem();
file = fileSystem.inputFile(fileSystem.predicates().and(error.getPredicate()));
if (file == null) {
LOGGER.debug(format("Cound not find file %s to add issue %s at line %d.", error.getFilePath(),
error.getType(), error.getLine()));
continue;
}
}
final RuleKey rule = RuleKey.of(error.getRepositoryKey(), error.getType());
final NewIssue issue = context.newIssue().forRule(rule);
final NewIssueLocation loc = issue.newLocation().on(file).at(file.selectLine(error.getLine()));
if (error.getDescription() != null) {
loc.message(error.getDescription());
}
issue.at(loc).save();
} catch (final Throwable e) {
LOGGER.warn(format("Can't add issue %s on file %s at line %d.", error.getType(), file.absolutePath(),
error.getLine()), e);
}
}
}
示例15: saveFileIssue
import org.sonar.api.batch.sensor.issue.NewIssueLocation; //导入依赖的package包/类
private void saveFileIssue(FileIssue issue) {
NewIssue newIssue = sensorContext.newIssue();
InputFile primaryFile = Preconditions.checkNotNull(fileSystem.inputFile(fileSystem.predicates().is(issue.file())));
NewIssueLocation primaryLocation = newIssue.newLocation()
.message(issue.message())
.on(primaryFile);
newIssue
.forRule(ruleKey(issue.check()))
.at(primaryLocation);
if (issue.cost() != null) {
newIssue.gap(issue.cost());
}
InputFile secondaryFile;
for (org.sonar.plugins.json.api.visitors.issue.IssueLocation secondary : issue.secondaryLocations()) {
secondaryFile = fileSystem.inputFile(fileSystem.predicates().is(secondary.file()));
if (secondaryFile == null) {
secondaryFile = primaryFile;
}
newIssue.addLocation(newLocation(secondaryFile, newIssue, secondary));
}
newIssue.save();
}