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 3 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) {
// no-arg constructor defaults context lines to 3
generator.run(new FullTextFingerprint(), report, getCharset());
}
else {
generator.run(new FullTextFingerprint(linesLookAhead), report, getCharset());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
<f:combobox/>
</f:entry>

<f:entry title="${%title.configureContextLines}" field="linesLookAhead"
help="${descriptor.getHelpFile('contextLines')}">
Copy link
Member

Choose a reason for hiding this comment

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

I think we should conform to the default naming scheme

Suggested change
help="${descriptor.getHelpFile('contextLines')}">
">

<f:number default="3" min="0"/>
</f:entry>

<st:include class="${descriptor.clazz}" page="local-config.jelly" optional="true"/>

<i:tool-defaults/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ description.patternOrConsole=<a rel="noopener noreferrer" href="{0}">Fileset ''i
If you leave this field blank, then the console log will be scanned for issues.
title.defaultPattern=Default Pattern
title.skipSymbolicLinks=Skip symbolic links when searching for files
title.configureContextLines=Configure the context lines
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div>
Copy link
Member

Choose a reason for hiding this comment

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

Can you move that to help-linesLookAhead.html, then we do not need to specify the name in the entry.

Configures the number of context lines used for issue fingerprinting in report analysis.
This value determines how many lines before and after an issue are included for better context.
It cannot be negative and the default value is 3.
This setting applies only to report-based analysis and is not available for console log scanning.
</div>
Loading