/** * Required rule name */ public NewRule setName(String s) { this.name = trimToNull(s); return this; }
/** * Sets author for this line. * The string will be trimmed, and null will be set if it is empty. */ public BlameLine author(@Nullable String author) { this.author = StringUtils.trimToNull(author); return this; }
/** * The optional description, in a restricted Markdown format, has no max length. It's exclusive with HTML description * (see {@link #setHtmlDescription(String)}) */ public NewRule setMarkdownDescription(@Nullable String s) { checkState(htmlDescription == null, "Rule '%s' already has an HTML description", this); this.markdownDescription = trimToNull(s); return this; }
@CheckForNull private String getBranch() { return trimToNull(properties.get(CoreProperties.PROJECT_BRANCH_PROPERTY)); } }
/** * The optional description, in HTML format, has no max length. It's exclusive with markdown description * (see {@link #setMarkdownDescription(String)}) */ public NewRule setHtmlDescription(@Nullable String s) { checkState(markdownDescription == null, "Rule '%s' already has a Markdown description", this); this.htmlDescription = trimToNull(s); return this; }
public Builder setDescription(@Nullable String description) { this.description = abbreviate(trimToNull(description), MAX_COMPONENT_DESCRIPTION_LENGTH); return this; }
private static String nameOfOthers(ScannerReport.Component reportComponent, String defaultName) { String name = trimToNull(reportComponent.getName()); return name == null ? defaultName : name; }
@Override public String generateKey(String projectKey, @Nullable String fileOrDirPath) { if (isLegacyBranch) { projectKey = ComponentKeys.createKey(projectKey, branchName); } if (isEmpty(fileOrDirPath)) { return projectKey; } return ComponentKeys.createEffectiveKey(projectKey, trimToNull(fileOrDirPath)); } }
private String createProjectVersion(ScannerReport.Component component) { String version = trimToNull(component.getVersion()); if (version != null) { return version; } if (baseAnalysis != null) { return firstNonNull(baseAnalysis.getVersion(), DEFAULT_PROJECT_VERSION); } return DEFAULT_PROJECT_VERSION; }
public Component buildProject(ScannerReport.Component project, String scmBasePath) { this.rootComponent = project; this.scmBasePath = trimToNull(scmBasePath); Node root = createProjectHierarchy(project); return buildComponent(root, "", ""); }
private String nameOfProject(ScannerReport.Component component) { String name = trimToNull(component.getName()); if (name != null) { return name; } return project.getName(); }
@Override public String generateKey(String projectKey, @Nullable String fileOrDirPath) { if (isEmpty(fileOrDirPath)) { return projectKey; } return ComponentKeys.createEffectiveKey(projectKey, trimToNull(fileOrDirPath)); } }
private static FileAttributes createFileAttributes(ScannerReport.Component component) { checkArgument(component.getType() == ScannerReport.Component.ComponentType.FILE); checkArgument(component.getLines() > 0, "File '%s' has no line", component.getProjectRelativePath()); return new FileAttributes( component.getIsTest(), trimToNull(component.getLanguage()), component.getLines()); }
public void load(ScannerReport.Metadata metadata) { String deprecatedBranch = trimToNull(metadata.getDeprecatedBranch()); String branchName = trimToNull(metadata.getBranchName()); if (deprecatedBranch != null && branchName != null) { throw MessageException.of("Properties sonar.branch and sonar.branch.name can't be set together"); } if (delegate == null && hasBranchProperties(metadata)) { throw MessageException.of("Current edition does not support branch feature"); } if (delegate != null && deprecatedBranch == null) { delegate.load(metadata); } else { metadataHolder.setBranch(new DefaultBranchImpl(deprecatedBranch)); } }
public NewAdHocRule(ScannerReport.AdHocRule ruleFromScannerReport) { Preconditions.checkArgument(isNotBlank(ruleFromScannerReport.getEngineId()), "'engine id' not expected to be null for an ad hoc rule"); Preconditions.checkArgument(isNotBlank(ruleFromScannerReport.getRuleId()), "'rule id' not expected to be null for an ad hoc rule"); Preconditions.checkArgument(isNotBlank(ruleFromScannerReport.getName()), "'name' not expected to be null for an ad hoc rule"); Preconditions.checkArgument(ruleFromScannerReport.getSeverity() != Constants.Severity.UNSET_SEVERITY , "'severity' not expected to be null for an ad hoc rule"); Preconditions.checkArgument(ruleFromScannerReport.getType() != ScannerReport.IssueType.UNSET, "'issue type' not expected to be null for an ad hoc rule"); this.key = RuleKey.of(RuleKey.EXTERNAL_RULE_REPO_PREFIX + ruleFromScannerReport.getEngineId(), ruleFromScannerReport.getRuleId()); this.engineId = ruleFromScannerReport.getEngineId(); this.ruleId = ruleFromScannerReport.getRuleId(); this.name = ruleFromScannerReport.getName(); this.description = trimToNull(ruleFromScannerReport.getDescription()); this.severity = ruleFromScannerReport.getSeverity().name(); this.ruleType = RuleType.valueOf(ruleFromScannerReport.getType().name()); this.hasDetails = true; }
private static Optional<Measure> toLongMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) { if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) { return toNoValueMeasure(builder, batchMeasure); } return of(builder.create(batchMeasure.getLongValue().getValue(), trimToNull(batchMeasure.getLongValue().getData()))); }
private static Optional<Measure> toIntegerMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) { if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) { return toNoValueMeasure(builder, batchMeasure); } return of(builder.create(batchMeasure.getIntValue().getValue(), trimToNull(batchMeasure.getIntValue().getData()))); }
private static Optional<Measure> toDoubleMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) { if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) { return toNoValueMeasure(builder, batchMeasure); } return of(builder.create(batchMeasure.getDoubleValue().getValue(), // Decimals are not truncated in scanner report, so an arbitrary decimal scale is applied when reading values from report org.sonar.api.measures.Metric.MAX_DECIMAL_SCALE, trimToNull(batchMeasure.getDoubleValue().getData()))); }
private static Optional<Measure> toBooleanMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) { if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) { return toNoValueMeasure(builder, batchMeasure); } return of(builder.create(batchMeasure.getBooleanValue().getValue(), trimToNull(batchMeasure.getBooleanValue().getData()))); }
private ComponentImpl buildFile(ScannerReport.Component component) { String key = keyGenerator.generateKey(rootComponent.getKey(), component.getProjectRelativePath()); String publicKey = publicKeyGenerator.generateKey(rootComponent.getKey(), component.getProjectRelativePath()); return ComponentImpl.builder(Component.Type.FILE) .setUuid(uuidSupplier.apply(key)) .setDbKey(key) .setKey(publicKey) .setName(component.getProjectRelativePath()) .setShortName(FilenameUtils.getName(component.getProjectRelativePath())) .setStatus(convertStatus(component.getStatus())) .setDescription(trimToNull(component.getDescription())) .setReportAttributes(createAttributesBuilder(component.getRef(), component.getProjectRelativePath(), scmBasePath).build()) .setFileAttributes(createFileAttributes(component)) .build(); }