本文整理汇总了Java中org.sonar.api.utils.SonarException类的典型用法代码示例。如果您正苦于以下问题:Java SonarException类的具体用法?Java SonarException怎么用?Java SonarException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SonarException类属于org.sonar.api.utils包,在下文中一共展示了SonarException类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addRuleProperty
import org.sonar.api.utils.SonarException; //导入依赖的package包/类
private static void addRuleProperty(Rule rule, Field field) {
org.sonar.check.RuleProperty propertyAnnotation = field.getAnnotation(org.sonar.check.RuleProperty.class);
if (propertyAnnotation != null) {
String fieldKey = StringUtils.defaultIfEmpty(propertyAnnotation.key(), field.getName());
RuleParam param = rule.createParameter(fieldKey);
param.setDescription(propertyAnnotation.description());
param.setDefaultValue(propertyAnnotation.defaultValue());
if (!StringUtils.isBlank(propertyAnnotation.type())) {
try {
param.setType(PropertyType.valueOf(propertyAnnotation.type().trim()).name());
} catch (IllegalArgumentException e) {
throw new SonarException("Invalid property type [" + propertyAnnotation.type() + "]", e);
}
} else {
param.setType(guessType(field.getType()).name());
}
}
}
示例2: visitFile
import org.sonar.api.utils.SonarException; //导入依赖的package包/类
@Override
public void visitFile(@Nullable AstNode astNode) {
List<String> lines;
try {
lines = Files.readLines(getContext().getFile(), charset);
} catch (IOException e) {
throw new SonarException(e);
}
for (int i = 0; i < lines.size(); i++) {
String line = lines.get(i);
if (line.length() > maximumLineLength) {
addIssue(
i + 1,
this,
MessageFormat.format(
"The line contains {0,number,integer} characters which is greater than {1,number,integer} authorized.",
line.length(),
maximumLineLength));
}
}
}
示例3: sonarSeverityToJiraPriorityId
import org.sonar.api.utils.SonarException; //导入依赖的package包/类
protected String sonarSeverityToJiraPriorityId(RulePriority reviewSeverity, Settings settings) {
final String priorityId;
switch (reviewSeverity) {
case INFO:
priorityId = settings.getString(JiraConstants.JIRA_INFO_PRIORITY_ID);
break;
case MINOR:
priorityId = settings.getString(JiraConstants.JIRA_MINOR_PRIORITY_ID);
break;
case MAJOR:
priorityId = settings.getString(JiraConstants.JIRA_MAJOR_PRIORITY_ID);
break;
case CRITICAL:
priorityId = settings.getString(JiraConstants.JIRA_CRITICAL_PRIORITY_ID);
break;
case BLOCKER:
priorityId = settings.getString(JiraConstants.JIRA_BLOCKER_PRIORITY_ID);
break;
default:
throw new SonarException("Unable to convert review severity to JIRA priority: " + reviewSeverity);
}
return priorityId;
}
示例4: visitFile
import org.sonar.api.utils.SonarException; //导入依赖的package包/类
@Override
public void visitFile(AstNode astNode) {
List<String> lines;
try {
lines = Files.readLines(getContext().getFile(), charset);
} catch (IOException e) {
throw new SonarException(e);
}
for (String line : lines) {
if (line.contains("\t")) {
addIssueOnFile(this, "Replace all tab characters in this file by sequences of whitespaces.");
break;
}
}
}
示例5: visitFile
import org.sonar.api.utils.SonarException; //导入依赖的package包/类
@Override
public void visitFile(AstNode astNode) {
List<String> lines;
try {
lines = Files.readLines(getContext().getFile(), charset);
} catch (IOException e) {
throw new SonarException(e);
}
for (int i = 0; i < lines.size(); i++) {
String line = lines.get(i);
if (line.length() > 0 && Pattern.matches("[" + WHITESPACE + "]", line.subSequence(line.length() - 1, line.length()))) {
addIssue(i + 1, this, "Remove the useless trailing whitespaces at the end of this line.");
}
}
}
示例6: visitFile
import org.sonar.api.utils.SonarException; //导入依赖的package包/类
@Override
public void visitFile(AstNode astNode) {
RandomAccessFile randomAccessFile = null;
try {
randomAccessFile = new RandomAccessFile(getContext().getFile(), "r");
if (!endsWithNewline(randomAccessFile)) {
addIssueOnFile(this, "Add an empty new line at the end of this file.");
}
} catch (IOException e) {
throw new SonarException(e);
} finally {
Closeables.closeQuietly(randomAccessFile);
}
}
示例7: parseFiles
import org.sonar.api.utils.SonarException; //导入依赖的package包/类
private void parseFiles(File[] reports, UnitTestIndex index) {
SurefireStaxHandler staxParser = new SurefireStaxHandler(index);
StaxParser parser = new StaxParser(staxParser, false);
for (File report : reports) {
try {
parser.parse(report);
} catch (XMLStreamException e) {
throw new SonarException("Fail to parse the Surefire report: " + report, e);
}
}
}
示例8: analyse
import org.sonar.api.utils.SonarException; //导入依赖的package包/类
public final void analyse(SensorContext context) {
if (noBinaryDirectoryFound()) {
J3cLogger.LOGGER.info("No JaCoCo analysis of project coverage can be done since there is no directories with classes.");
return;
}
File jacocoExecutionData = pathResolver.relativeFile(fileSystem.baseDir(), configuration.getReportPath());
if(noCoverageReportFound(jacocoExecutionData)) {
J3cLogger.LOGGER.info("No JaCoCo analysis of project coverage found at: " + jacocoExecutionData.getPath());
return;
}
try {
ExecutionDataStore mergedResults = parseExecutionData(jacocoExecutionData);
CoverageBuilder coverageBuilder = analyze(mergedResults);
CoverageComplexityDataSet coverageComplexityDataSet = new CoverageComplexityDataSet();
for (IClassCoverage classCoverage : coverageBuilder.getClasses()) {
if (isExcluded(classCoverage) || isNotInScope(classCoverage, context)) {
continue;
}
for (IMethodCoverage methodCoverage : classCoverage.getMethods()) {
coverageComplexityDataSet.add(methodCoverage);
}
}
saveMeasures(context, coverageComplexityDataSet);
} catch (Exception e) {
J3cLogger.LOGGER.error(e.getMessage(), e);
throw new SonarException(e);
}
}
示例9: visitFile
import org.sonar.api.utils.SonarException; //导入依赖的package包/类
@Override
public void visitFile(AstNode astNode) {
List<String> lines;
try {
lines = Files.readLines(getContext().getFile(), charset);
} catch (IOException e) {
throw new SonarException(e);
}
for (int i = 0; i < lines.size(); i++) {
if (lines.get(i).contains("\t")) {
getContext().createLineViolation(this, "Replace all tab characters in this file by sequences of white-spaces.", i + 1);
break;
}
}
}
示例10: count
import org.sonar.api.utils.SonarException; //导入依赖的package包/类
public void count() {
logger.fine("Count comment in " + sourceCode.getResource().getLongName());
ArrayList<String> code = (ArrayList<String>) sourceCode.getCode();
if (code != null && code.size() > 0) {
try {
boolean commenting = false;
for (String line : code) {
String trimmed = StringUtils.trim(line);
if (StringUtils.isBlank(trimmed)) {
blankLines++;
} else if (trimmed.startsWith("(:") && trimmed.endsWith(":)")) {
commentLines++;
} else if (trimmed.startsWith("(:") && !trimmed.contains(":)") && !trimmed.endsWith(":)")) {
commenting = true;
commentLines++;
} else if (commenting && trimmed.contains(":)")) {
commenting = false;
commentLines++;
} else if (commenting) {
commentLines++;
} else {
if (trimmed.contains("declare function")) {
functions++;
}
}
linesOfCode++;
}
} catch (Exception e) {
throw new SonarException(e);
}
}
sourceCode.addMeasure(CoreMetrics.FUNCTIONS, (double) functions);
sourceCode.addMeasure(CoreMetrics.LINES, (double) linesOfCode);
sourceCode.addMeasure(CoreMetrics.COMMENT_LINES, (double) commentLines);
sourceCode.addMeasure(CoreMetrics.NCLOC, (double) linesOfCode - blankLines - commentLines);
}
示例11: getCode
import org.sonar.api.utils.SonarException; //导入依赖的package包/类
@Override
public List<String> getCode() {
if (inputFile != null && code.size() == 0) {
try {
code = FileUtils.readLines(inputFile, "UTF-8");
return code;
} catch (IOException e) {
throw new SonarException(e);
}
} else {
return code;
}
}