本文整理汇总了Java中org.sonar.api.issue.Issuable类的典型用法代码示例。如果您正苦于以下问题:Java Issuable类的具体用法?Java Issuable怎么用?Java Issuable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Issuable类属于org.sonar.api.issue包,在下文中一共展示了Issuable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addIssue
import org.sonar.api.issue.Issuable; //导入依赖的package包/类
private void addIssue(Project project, double coverage, double previousCoverage) {
Issuable issuable = perspectives.as(Issuable.class, (Resource) project);
if (issuable == null) {
LOGGER.warn("Could not get a perspective of Issuable to create an issue for {}, skipping",
project);
return;
}
Optional<RuleKey> ruleKey = CoverageRule.decreasingOverallLineCoverageRule(fileSystem);
if (ruleKey.isPresent()) {
LOGGER.debug("RuleKey: {}", ruleKey.get());
addIssue(issuable,
formatIssueMessage("the project", coverage, previousCoverage),
ruleKey.get());
} else {
LOGGER.warn("Could not determine the RuleKey for the project {}", project.getEffectiveKey());
}
}
示例2: 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());
}
}
}
示例3: addErrorTest
import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Test
public void addErrorTest() {
final Rule rule = setupRule("repo", "key");
final Issuable issuable = setupIssuable();
final IssueBuilder issueBuilder = mock(IssueBuilder.class);
final Issue issue = mock(Issue.class);
when(issuable.newIssueBuilder()).thenReturn(issueBuilder);
when(issueBuilder.ruleKey(RuleKey.of("repo", "key"))).thenReturn(issueBuilder);
when(issueBuilder.message(event.getMessage())).thenReturn(issueBuilder);
when(issueBuilder.line(event.getLine())).thenReturn(issueBuilder);
when(issueBuilder.build()).thenReturn(issue);
addErrorToListener();
verify(issuable).addIssue(issue);
verify(issueBuilder).ruleKey(RuleKey.of("repo", "key"));
verify(issueBuilder).message(event.getMessage());
verify(issueBuilder).line(event.getLine());
verify(rule).ruleKey();
}
示例4: saveIssues
import org.sonar.api.issue.Issuable; //导入依赖的package包/类
/**
* Saves issues form input file and source file.
*
* @param sonarFile input file.
* @param squidFile source file.
*/
private void saveIssues(InputFile sonarFile, SourceFile squidFile) {
Collection<CheckMessage> messages = squidFile.getCheckMessages();
messages.forEach(message -> {
RuleKey ruleKey = checks.ruleKey((SquidAstVisitor<Grammar>) message.getCheck());
Issuable issuable = resourcePerspectives.as(Issuable.class, sonarFile);
if (issuable != null) {
Issue issue = issuable.newIssueBuilder()
.ruleKey(ruleKey)
.line(message.getLine())
.message(message.getText(Locale.ENGLISH))
.build();
issuable.addIssue(issue);
}
});
}
示例5: createIssueSensorBackedByMocks
import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Before
public void createIssueSensorBackedByMocks() {
ResourcePerspectives resourcePerspectives = mock(ResourcePerspectives.class);
Checks<Object> checks = mock(Checks.class);
CheckFactory checkFactory = mock(CheckFactory.class);
when(checkFactory.create(Mockito.anyString())).thenReturn(checks);
List<Object> checksList = Arrays.asList(new Object[] {realIfOneStringExistsBothMustExistMultiFileCheck});
when(checks.all()).thenReturn(checksList);
when(checks.ruleKey(Mockito.isA(StringDisallowedIfMatchInAnotherFileCheck.class))).thenReturn(RuleKey.of("text", "StringDisallowedIfMatchInAnotherFileCheck"));
when(checks.ruleKey(Mockito.isA(MultiFileIfOneStringExistsThenBothMustExistCheck.class))).thenReturn(RuleKey.of("text", "MultiFileIfOneStringExistsThenBothMustExistCheck"));
// realStringDisallowedMultiFileCheck.setRuleKey(RuleKey.parse("text:StringDisallowedIfMatchInAnotherFileCheck")); // Not strictly necessary here. Normally set by the framework to the value in the Check class's annotation
when(checks.addAnnotatedChecks(Mockito.anyCollection())).thenReturn(checks);
mockIssuable = mock(Issuable.class);
when(resourcePerspectives.as(Mockito.eq(Issuable.class), Mockito.isA(InputFile.class))).thenReturn(mockIssuable);
IssueBuilder mockIssueBuilder = mock(IssueBuilder.class);
when(mockIssuable.newIssueBuilder()).thenReturn(mockIssueBuilder);
when(mockIssueBuilder.ruleKey(Mockito.isA(RuleKey.class))).thenReturn(mockIssueBuilder);
when(mockIssueBuilder.line(Mockito.anyInt())).thenReturn(mockIssueBuilder);
when(mockIssueBuilder.message(Mockito.anyString())).thenReturn(mockIssueBuilder);
when(mockIssueBuilder.build()).thenReturn(mock(Issue.class));
sensor = new TextIssueSensor(fs, resourcePerspectives, checkFactory, project);
}
开发者ID:gjd6640,项目名称:sonar-text-plugin,代码行数:26,代码来源:MultiFileIfOneExistsThenBothMustExistCheckTest.java
示例6: createIssueSensorBackedByMocks
import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Before
public void createIssueSensorBackedByMocks() {
ResourcePerspectives resourcePerspectives = mock(ResourcePerspectives.class);
Checks<Object> checks = mock(Checks.class);
CheckFactory checkFactory = mock(CheckFactory.class);
when(checkFactory.create(Mockito.anyString())).thenReturn(checks);
List<Object> checksList = Arrays.asList(new Object[] {realStringDisallowedMultiFileCheck});
when(checks.all()).thenReturn(checksList);
when(checks.ruleKey(Mockito.isA(StringDisallowedIfMatchInAnotherFileCheck.class))).thenReturn(RuleKey.of("text", "StringDisallowedIfMatchInAnotherFileCheck"));
// realStringDisallowedMultiFileCheck.setRuleKey(RuleKey.parse("text:StringDisallowedIfMatchInAnotherFileCheck")); // Not strictly necessary here. Normally set by the framework to the value in the Check class's annotation
when(checks.addAnnotatedChecks(Mockito.anyCollection())).thenReturn(checks);
mockIssuable = mock(Issuable.class);
when(resourcePerspectives.as(Mockito.eq(Issuable.class), Mockito.isA(InputFile.class))).thenReturn(mockIssuable);
IssueBuilder mockIssueBuilder = mock(IssueBuilder.class);
when(mockIssuable.newIssueBuilder()).thenReturn(mockIssueBuilder);
when(mockIssueBuilder.ruleKey(Mockito.isA(RuleKey.class))).thenReturn(mockIssueBuilder);
when(mockIssueBuilder.line(Mockito.anyInt())).thenReturn(mockIssueBuilder);
when(mockIssueBuilder.message(Mockito.anyString())).thenReturn(mockIssueBuilder);
when(mockIssueBuilder.build()).thenReturn(mock(Issue.class));
sensor = new TextIssueSensor(fs, resourcePerspectives, checkFactory, project);
}
开发者ID:gjd6640,项目名称:sonar-text-plugin,代码行数:25,代码来源:StringDisallowedIfMatchInAnotherFileCheckTest.java
示例7: createIssueSensorBackedByMocks
import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Before
public void createIssueSensorBackedByMocks() {
ResourcePerspectives resourcePerspectives = mock(ResourcePerspectives.class);
Checks<Object> checks = mock(Checks.class);
CheckFactory checkFactory = mock(CheckFactory.class);
when(checkFactory.create(Mockito.anyString())).thenReturn(checks);
textCheckMock = mock(AbstractTextCheck.class);
List<Object> checksList = Arrays.asList(new Object[] {textCheckMock});
when(checks.all()).thenReturn(checksList);
when(checks.addAnnotatedChecks(Mockito.anyCollection())).thenReturn(checks);
mockIssuable = mock(Issuable.class);
when(resourcePerspectives.as(Mockito.eq(Issuable.class), Mockito.isA(InputFile.class))).thenReturn(mockIssuable);
IssueBuilder mockIssueBuilder = mock(IssueBuilder.class);
when(mockIssuable.newIssueBuilder()).thenReturn(mockIssueBuilder);
when(mockIssueBuilder.ruleKey(Mockito.isA(RuleKey.class))).thenReturn(mockIssueBuilder);
when(mockIssueBuilder.line(Mockito.anyInt())).thenReturn(mockIssueBuilder);
when(mockIssueBuilder.message(Mockito.anyString())).thenReturn(mockIssueBuilder);
when(mockIssueBuilder.build()).thenReturn(mock(Issue.class));
sensor = new TextIssueSensor(fs, resourcePerspectives, checkFactory, project);
}
示例8: 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());
}
}
}
}
}
示例9: whenDecorateIsInvokedThenAllViolationsShouldBeProcessed
import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Test
public void whenDecorateIsInvokedThenAllViolationsShouldBeProcessed() {
int count = 10;
DecoratorContext context = mock(DecoratorContext.class);
Resource resource = mock(Resource.class);
configureProject("Java");
List<Issue> issues = new ArrayList<Issue>();
for (int i = 0; i < count; i++) {
issues.add(createIssue("", DebtProcessorFactory.MISSING_SWITCH_DEFAULT_CHECK_STYLE, ""));
}
Issuable issuable = mock(Issuable.class);
when(issuable.issues()).thenReturn(issues);
when(perspectivesMock.as(Issuable.class, resource)).thenReturn(issuable);
decorator.decorate(resource, context);
}
示例10: 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);
}
}
示例11: setUp
import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Before
public void setUp() {
project = new Project("foo:bar");
settings.setProperty("sonar.scanAllFiles", true);
when(rp.as(eq(Issuable.class), any(Resource.class))).thenReturn(issuable);
when(rp.as(eq(Issuable.class), any(InputFile.class))).thenReturn(issuable);
Issuable.IssueBuilder issueBuilder = mock(Issuable.IssueBuilder.class, Answers.RETURNS_SELF);
when(issuable.newIssueBuilder()).thenReturn(issueBuilder);
}
示例12: testAnalyse
import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Test
public void testAnalyse() {
String relativePath = "src/test/resources/sensor/Book.cls";
DefaultInputFile inputFile = new DefaultInputFile(relativePath).setLanguage(Apex.KEY);
inputFile.setAbsolutePath((new File(relativePath)).getAbsolutePath());
fileSystem.add(inputFile);
Issuable issuable = mock(Issuable.class);
Issuable.IssueBuilder issueBuilder = mock(Issuable.IssueBuilder.class);
when(perspectives.as(Mockito.eq(Issuable.class), Mockito.any(InputFile.class))).thenReturn(issuable);
when(issuable.newIssueBuilder()).thenReturn(issueBuilder);
when(issueBuilder.ruleKey(Mockito.any(RuleKey.class))).thenReturn(issueBuilder);
when(issueBuilder.line(Mockito.any(Integer.class))).thenReturn(issueBuilder);
when(issueBuilder.message(Mockito.any(String.class))).thenReturn(issueBuilder);
Project project = new Project("cls");
SensorContext context = mock(SensorContext.class);
squidSensor.analyse(project, context);
verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.FILES), eq(1.0));
verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.LINES), eq(7.0));
verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.NCLOC), eq(6.0));
verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.STATEMENTS), eq(2.0));
verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.FUNCTIONS), eq(1.0));
verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.CLASSES), eq(1.0));
verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.COMPLEXITY), eq(1.0));
}
示例13: 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());
}
}
}
}
}
示例14: 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());
}
}
}
示例15: decorate
import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Override
public void decorate(Resource resource, DecoratorContext context) {
Issuable issuable = perspectives.as(Issuable.class, resource);
if (issuable != null) {
for (Issue issue : issuable.issues()) {
DebtsFilter.getInstance().filter(issue);
}
}
if (allResourcesAreProcessed(resource)) {
saveMeasures(context);
}
}