@Override public String componentKey() { return component.key(); }
@Before public void setUp() { mockedProject = mock(DefaultInputProject.class); projectAnalysisInfo = mock(ProjectAnalysisInfo.class); component = mock(InputComponent.class); when(component.key()).thenReturn("foo"); }
private DefaultIssueLocation rewriteLocation(DefaultIssueLocation location) { InputComponent component = location.inputComponent(); Optional<Path> dirOrModulePath = Optional.empty(); if (component instanceof DefaultInputDir) { DefaultInputDir dirComponent = (DefaultInputDir) component; dirOrModulePath = Optional.of(project.getBaseDir().relativize(dirComponent.path())); } else if (component instanceof DefaultInputModule && !Objects.equals(project.key(), component.key())) { DefaultInputModule moduleComponent = (DefaultInputModule) component; dirOrModulePath = Optional.of(project.getBaseDir().relativize(moduleComponent.getBaseDir())); } if (dirOrModulePath.isPresent()) { String path = PathUtils.sanitize(dirOrModulePath.get().toString()); DefaultIssueLocation fixedLocation = new DefaultIssueLocation(); fixedLocation.on(project); StringBuilder fullMessage = new StringBuilder(); if (!isNullOrEmpty(path)) { fullMessage.append("[").append(path).append("] "); } fullMessage.append(location.message()); fixedLocation.message(fullMessage.toString()); return fixedLocation; } else { return location; } } }
@Override public void store(Measure measure) { // Emulate duplicate measure check String componentKey = measure.inputComponent().key(); String metricKey = measure.metric().key(); if (measuresByComponentAndMetric.contains(componentKey, metricKey)) { throw new IllegalStateException("Can not add the same measure twice"); } measuresByComponentAndMetric.row(componentKey).put(metricKey, measure); }
public List<TrackedIssue> trackIssues(InputComponent component, Collection<ScannerReport.Issue> reportIssues, Date analysisDate) { List<TrackedIssue> trackedIssues = new LinkedList<>(); if (hasServerAnalysis) { // all the issues that are not closed in db before starting this module scan, including manual issues Collection<ServerIssueFromWs> serverIssues = loadServerIssues(component); if (shouldCopyServerIssues(component)) { // raw issues should be empty, we just need to deal with server issues (SONAR-6931) copyServerIssues(serverIssues, trackedIssues, component.key()); } else { SourceHashHolder sourceHashHolder = loadSourceHashes(component); Collection<TrackedIssue> rIssues = IssueTransformer.toTrackedIssue(component, reportIssues, sourceHashHolder); Input<ServerIssueFromWs> baseIssues = createBaseInput(serverIssues, sourceHashHolder); Input<TrackedIssue> rawIssues = createRawInput(rIssues, sourceHashHolder); Tracking<TrackedIssue, ServerIssueFromWs> track = tracker.trackNonClosed(rawIssues, baseIssues); addUnmatchedFromServer(track.getUnmatchedBases(), trackedIssues, component.key()); mergeMatched(track, trackedIssues, rIssues); addUnmatchedFromReport(track.getUnmatchedRaws(), trackedIssues, analysisDate); } } if (hasServerAnalysis && !component.isFile()) { Preconditions.checkState(component instanceof InputModule, "Object without parent is of type: " + component.getClass()); // issues that relate to deleted components addIssuesOnDeletedComponents(trackedIssues, component.key()); } return trackedIssues; }
public static TrackedIssue toTrackedIssue(InputComponent component, ScannerReport.Issue rawIssue, @Nullable SourceHashHolder hashes) { RuleKey ruleKey = RuleKey.of(rawIssue.getRuleRepository(), rawIssue.getRuleKey()); Preconditions.checkNotNull(component.key(), "Component key must be set"); Preconditions.checkNotNull(ruleKey, "Rule key must be set"); TrackedIssue issue = new TrackedIssue(hashes != null ? hashes.getHashedSource() : null); issue.setKey(Uuids.createFast()); issue.setComponentKey(component.key()); issue.setRuleKey(ruleKey); issue.setGap(rawIssue.getGap() != 0 ? rawIssue.getGap() : null); issue.setSeverity(rawIssue.getSeverity().name()); issue.setMessage(StringUtils.trimToNull(rawIssue.getMsg())); issue.setResolution(null); issue.setStatus(Issue.STATUS_OPEN); issue.setNew(true); if (rawIssue.hasTextRange()) { TextRange r = rawIssue.getTextRange(); issue.setStartLine(r.getStartLine()); issue.setStartLineOffset(r.getStartOffset()); issue.setEndLine(r.getEndLine()); issue.setEndLineOffset(r.getEndOffset()); } return issue; }
metric.key()); if (!component.isFile()) { throw new UnsupportedOperationException("Saving coverage measure is only allowed on files. Attempt to save '" + metric.key() + "' on '" + component.key() + "'"); if (measureCache.contains(component.key(), metric.key())) { throw new UnsupportedOperationException("Can not add the same measure twice on " + component + ": " + measure); measureCache.put(component.key(), metric.key(), measureToSave);
if (!component.key().equals(componentKey)) { DefaultInputComponent sameProjectComponent = (DefaultInputComponent) componentStore.getByKey(componentKey); blockBuilder.setOtherFileRef(sameProjectComponent.scannerId());
@Override public String componentKey() { return inputComponent.key(); }
@Override public String componentKey() { return component.key(); }
public BatchComponent get(InputComponent inputComponent) { return components.get(inputComponent.key()); }
@Override public void store(Measure measure) { // Emulate duplicate measure check String componentKey = measure.inputComponent().key(); String metricKey = measure.metric().key(); if (measuresByComponentAndMetric.contains(componentKey, metricKey)) { throw new IllegalStateException("Can not add the same measure twice"); } measuresByComponentAndMetric.row(componentKey).put(metricKey, measure); }
private DefaultIssueLocation rewriteLocation(DefaultIssueLocation location) { InputComponent component = location.inputComponent(); Optional<Path> dirOrModulePath = Optional.empty(); if (component instanceof DefaultInputDir) { DefaultInputDir dirComponent = (DefaultInputDir) component; dirOrModulePath = Optional.of(project.getBaseDir().relativize(dirComponent.path())); } else if (component instanceof DefaultInputModule && !Objects.equals(project.key(), component.key())) { DefaultInputModule moduleComponent = (DefaultInputModule) component; dirOrModulePath = Optional.of(project.getBaseDir().relativize(moduleComponent.getBaseDir())); } if (dirOrModulePath.isPresent()) { String path = PathUtils.sanitize(dirOrModulePath.get().toString()); DefaultIssueLocation fixedLocation = new DefaultIssueLocation(); fixedLocation.on(project); StringBuilder fullMessage = new StringBuilder(); if (!isNullOrEmpty(path)) { fullMessage.append("[").append(path).append("] "); } fullMessage.append(location.message()); fixedLocation.message(fullMessage.toString()); return fixedLocation; } else { return location; } } }
public List<TrackedIssue> trackIssues(InputComponent component, Collection<ScannerReport.Issue> reportIssues, Date analysisDate) { List<TrackedIssue> trackedIssues = new LinkedList<>(); if (hasServerAnalysis) { // all the issues that are not closed in db before starting this module scan, including manual issues Collection<ServerIssueFromWs> serverIssues = loadServerIssues(component); if (shouldCopyServerIssues(component)) { // raw issues should be empty, we just need to deal with server issues (SONAR-6931) copyServerIssues(serverIssues, trackedIssues, component.key()); } else { SourceHashHolder sourceHashHolder = loadSourceHashes(component); Collection<TrackedIssue> rIssues = IssueTransformer.toTrackedIssue(component, reportIssues, sourceHashHolder); Input<ServerIssueFromWs> baseIssues = createBaseInput(serverIssues, sourceHashHolder); Input<TrackedIssue> rawIssues = createRawInput(rIssues, sourceHashHolder); Tracking<TrackedIssue, ServerIssueFromWs> track = tracker.trackNonClosed(rawIssues, baseIssues); addUnmatchedFromServer(track.getUnmatchedBases(), trackedIssues, component.key()); mergeMatched(track, trackedIssues, rIssues); addUnmatchedFromReport(track.getUnmatchedRaws(), trackedIssues, analysisDate); } } if (hasServerAnalysis && !component.isFile()) { Preconditions.checkState(component instanceof InputModule, "Object without parent is of type: " + component.getClass()); // issues that relate to deleted components addIssuesOnDeletedComponents(trackedIssues, component.key()); } return trackedIssues; }
public static TrackedIssue toTrackedIssue(InputComponent component, ScannerReport.Issue rawIssue, @Nullable SourceHashHolder hashes) { RuleKey ruleKey = RuleKey.of(rawIssue.getRuleRepository(), rawIssue.getRuleKey()); Preconditions.checkNotNull(component.key(), "Component key must be set"); Preconditions.checkNotNull(ruleKey, "Rule key must be set"); TrackedIssue issue = new TrackedIssue(hashes != null ? hashes.getHashedSource() : null); issue.setKey(Uuids.createFast()); issue.setComponentKey(component.key()); issue.setRuleKey(ruleKey); issue.setGap(rawIssue.getGap() != 0 ? rawIssue.getGap() : null); issue.setSeverity(rawIssue.getSeverity().name()); issue.setMessage(StringUtils.trimToNull(rawIssue.getMsg())); issue.setResolution(null); issue.setStatus(Issue.STATUS_OPEN); issue.setNew(true); if (rawIssue.hasTextRange()) { TextRange r = rawIssue.getTextRange(); issue.setStartLine(r.getStartLine()); issue.setStartLineOffset(r.getStartOffset()); issue.setEndLine(r.getEndLine()); issue.setEndLineOffset(r.getEndOffset()); } return issue; }
metric.key()); if (!component.isFile()) { throw new UnsupportedOperationException("Saving coverage measure is only allowed on files. Attempt to save '" + metric.key() + "' on '" + component.key() + "'"); if (measureCache.contains(component.key(), metric.key())) { throw new UnsupportedOperationException("Can not add the same measure twice on " + component + ": " + measure); measureCache.put(component.key(), metric.key(), measureToSave);
if (!component.key().equals(componentKey)) { DefaultInputComponent sameProjectComponent = (DefaultInputComponent) componentStore.getByKey(componentKey); blockBuilder.setOtherFileRef(sameProjectComponent.scannerId());
BatchReport.Issue rawIssue = builder.build(); if (filters.accept(inputComponent.key(), rawIssue)) { write(component, rawIssue); return true;