Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to configure context lines for fingerprinting #1943

Open
wants to merge 4 commits into
base: 13.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
<changelist>-SNAPSHOT</changelist>
<module.name>${project.groupId}.warnings.ng</module.name>

<analysis-model-api.version>13.0.0-rc852.f04104a_881e9</analysis-model-api.version>
<analysis-model-tests.version>13.0.0-rc5991.66662b_93493c</analysis-model-tests.version>
<analysis-model-api.version>13.0.0-rc853.93e9b_716371e</analysis-model-api.version>
<analysis-model-tests.version>13.0.0-rc6003.203a_5b_4fdf93</analysis-model-tests.version>
<pull-request-monitoring.version>335.v525cd64ec76b_</pull-request-monitoring.version>

<eclipse-collections.version>9.2.0</eclipse-collections.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public abstract class ReportScanningTool extends Tool {
private String pattern = StringUtils.EMPTY;
private String reportEncoding = StringUtils.EMPTY;
private boolean skipSymbolicLinks = false;
private int linesLookAhead = 3;

/**
* Sets the Ant file-set pattern of files to work with. If the pattern is undefined, then the console log is
Expand Down Expand Up @@ -133,6 +134,21 @@ public String getReportEncoding() {
return reportEncoding;
}

/**
* Sets the context lines which is used in the fingerprinting process.
*
* @param linesLookAhead
* the actual number of lines.
*/
@DataBoundSetter
public void setLinesLookAhead(final int linesLookAhead) {
this.linesLookAhead = linesLookAhead;
}

public int getLinesLookAhead() {
return linesLookAhead;
}

@Override
public Report scan(final Run<?, ?> run, final FilePath workspace, final Charset sourceCodeEncoding,
final LogHandler logger) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import io.jenkins.plugins.analysis.core.filter.RegexpFilter;
import io.jenkins.plugins.analysis.core.model.ReportLocations;
import io.jenkins.plugins.analysis.core.model.ReportScanningTool;
import io.jenkins.plugins.analysis.core.model.Tool;
import io.jenkins.plugins.analysis.core.util.AffectedFilesResolver;
import io.jenkins.plugins.analysis.core.util.ConsoleLogHandler;
Expand Down Expand Up @@ -148,9 +149,13 @@ private AnnotatedReport postProcessReport(final Report report) throws IOExceptio
}

private ReportPostProcessor createPostProcessor(final Report report) {
int linesLookAhead = -1;
if (tool instanceof ReportScanningTool) {
linesLookAhead = ((ReportScanningTool) tool).getLinesLookAhead();
}
return new ReportPostProcessor(tool.getActualId(), report, sourceCodeEncoding.name(),
createBlamer(report), filters, getPermittedSourceDirectories(), sourceDirectories,
postProcessingMode);
postProcessingMode, linesLookAhead);
}

private Set<String> getPermittedSourceDirectories() {
Expand Down Expand Up @@ -261,11 +266,12 @@ private static class ReportPostProcessor extends MasterToSlaveFileCallable<Annot
private final Set<String> requestedSourceDirectories;
private final PostProcessingMode postProcessingMode;
private final List<RegexpFilter> filters;
private final int linesLookAhead;

@SuppressWarnings("checkstyle:ParameterNumber")
ReportPostProcessor(final String id, final Report report, final String sourceCodeEncoding,
final Blamer blamer, final List<RegexpFilter> filters, final Set<String> permittedSourceDirectories,
final Set<String> requestedSourceDirectories, final PostProcessingMode postProcessingMode) {
final Set<String> requestedSourceDirectories, final PostProcessingMode postProcessingMode, final int linesLookAhead) {
super();

this.id = id;
Expand All @@ -276,6 +282,7 @@ private static class ReportPostProcessor extends MasterToSlaveFileCallable<Annot
this.permittedSourceDirectories = permittedSourceDirectories;
this.requestedSourceDirectories = requestedSourceDirectories;
this.postProcessingMode = postProcessingMode;
this.linesLookAhead = linesLookAhead;
}

@Override
Expand Down Expand Up @@ -365,7 +372,13 @@ private void createFingerprints(final Report report) {
report.logInfo("Creating fingerprints for all affected code blocks to track issues over different builds");

FingerprintGenerator generator = new FingerprintGenerator();
generator.run(new FullTextFingerprint(), report, getCharset());
if (linesLookAhead < 0) {
//Empty constructor defaults context lines to 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//Empty constructor defaults context lines to 3
// no-arg constructor defaults context lines to 3

generator.run(new FullTextFingerprint(), report, getCharset());
}
else {
generator.run(new FullTextFingerprint(linesLookAhead), report, getCharset());
}
}
}

Expand Down
Loading