Skip to content

Commit

Permalink
Add an option to skip the time-consuming post-processing step.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Jan 8, 2024
1 parent a698285 commit 92949e5
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import io.jenkins.plugins.analysis.core.model.StaticAnalysisLabelProvider;
import io.jenkins.plugins.analysis.core.model.Tool;
import io.jenkins.plugins.analysis.core.steps.IssuesScanner.BlameMode;
import io.jenkins.plugins.analysis.core.steps.IssuesScanner.PostProcessingMode;
import io.jenkins.plugins.analysis.core.steps.WarningChecksPublisher.AnnotationScope;
import io.jenkins.plugins.analysis.core.util.HealthDescriptor;
import io.jenkins.plugins.analysis.core.util.ModelValidation;
Expand Down Expand Up @@ -127,6 +128,8 @@ public class IssuesRecorder extends Recorder {
private boolean skipPublishingChecks; // by default, checks will be published
private boolean publishAllIssues; // by default, only new issues will be published

private boolean skipPostProcessing; // @since 10.6.0: by default, post-processing will be enabled

@CheckForNull
private ChecksInfo checksInfo;

Expand Down Expand Up @@ -482,6 +485,20 @@ public void setSkipPublishingChecks(final boolean skipPublishingChecks) {
this.skipPublishingChecks = skipPublishingChecks;
}

/**
* Returns whether post-processing of the issues should be disabled.
*
* @return {@code true} if post-processing of the issues should be disabled.
*/
public boolean isSkipPostProcessing() {
return skipPostProcessing;
}

@DataBoundSetter
public void setSkipPostProcessing(final boolean skipPostProcessing) {
this.skipPostProcessing = skipPostProcessing;
}

/**
* Returns whether all issues should be published using the Checks API. If set to {@code false} only new issues will
* be published.
Expand Down Expand Up @@ -643,7 +660,7 @@ public int getUnhealthy() {
}

/**
* Sets the healthy threshold, i.e. the number of issues when health is reported as 0%.
* Sets the healthy threshold, i.e., the number of issues when health is reported as 0%.
*
* @param unhealthy
* the number of issues when health is reported as 0%
Expand Down Expand Up @@ -806,7 +823,8 @@ private AnnotatedReport scanWithTool(final Run<?, ?> run, final FilePath workspa
final Tool tool) throws IOException, InterruptedException {
IssuesScanner issuesScanner = new IssuesScanner(tool, getFilters(), getSourceCodeCharset(),
workspace, getSourceCodePaths(), run, new FilePath(run.getRootDir()), listener,
scm, isBlameDisabled ? BlameMode.DISABLED : BlameMode.ENABLED, quiet);
scm, isBlameDisabled ? BlameMode.DISABLED : BlameMode.ENABLED,
skipPostProcessing ? PostProcessingMode.DISABLED : PostProcessingMode.ENABLED, quiet);

return issuesScanner.scan();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,22 @@ class IssuesScanner {
private final TaskListener listener;
private final String scm;
private final BlameMode blameMode;
private final PostProcessingMode postProcessingMode;
private final boolean quiet;

enum BlameMode {
ENABLED, DISABLED
}

enum PostProcessingMode {
ENABLED, DISABLED
}

@SuppressWarnings("checkstyle:ParameterNumber")
IssuesScanner(final Tool tool, final List<RegexpFilter> filters, final Charset sourceCodeEncoding,
final FilePath workspace, final Set<String> sourceDirectories, final Run<?, ?> run,
final FilePath jenkinsRootDir, final TaskListener listener,
final String scm, final BlameMode blameMode, final boolean quiet) {
final String scm, final BlameMode blameMode, final PostProcessingMode postProcessingMode, final boolean quiet) {
this.filters = new ArrayList<>(filters);
this.sourceCodeEncoding = sourceCodeEncoding;
this.tool = tool;
Expand All @@ -95,6 +100,7 @@ enum BlameMode {
this.listener = listener;
this.scm = scm;
this.blameMode = blameMode;
this.postProcessingMode = postProcessingMode;
this.quiet = quiet;
}

Expand Down Expand Up @@ -123,7 +129,9 @@ private RepositoryStatistics getRepositoryStatistics(final Report report) {
}

private AnnotatedReport postProcessReport(final Report report) throws IOException, InterruptedException {
if (tool.getDescriptor().isPostProcessingEnabled() && report.isNotEmpty()) {
if (tool.getDescriptor().isPostProcessingEnabled()
&& report.isNotEmpty()
&& postProcessingMode == PostProcessingMode.ENABLED) {
report.logInfo("Post processing issues on '%s' with source code encoding '%s'",
getAgentName(), sourceCodeEncoding);
AnnotatedReport result = workspace.act(createPostProcessor(report));
Expand Down Expand Up @@ -170,7 +178,6 @@ private Blamer createBlamer(final Report report) {
report.logInfo("-> Filtering SCMs by key '%s'", scm);
}
Blamer blamer = BlamerFactory.findBlamer(scm, run, workspace, listener, log);
log.logSummary();
report.mergeLogMessages(log);

return blamer;
Expand Down Expand Up @@ -283,7 +290,6 @@ private Blames blame(final Report filtered, final FileLocations fileLocations) {
}
FilteredLog log = new FilteredLog("Errors while extracting author and commit information from Git:");
Blames blames = blamer.blame(fileLocations, log);
log.logSummary();
filtered.mergeLogMessages(log);
return blames;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.jenkins.plugins.analysis.core.filter.RegexpFilter;
import io.jenkins.plugins.analysis.core.model.Tool;
import io.jenkins.plugins.analysis.core.steps.IssuesScanner.BlameMode;
import io.jenkins.plugins.analysis.core.steps.IssuesScanner.PostProcessingMode;
import io.jenkins.plugins.prism.SourceCodeDirectory;

/**
Expand All @@ -41,6 +42,7 @@ public class ScanForIssuesStep extends Step {
private String sourceDirectory = StringUtils.EMPTY;
private Set<SourceCodeDirectory> sourceDirectories = new HashSet<>(); // @since 9.11.0
private boolean isBlameDisabled;
private boolean skipPostProcessing; // @since 10.6.0: by default, post-processing will be enabled
private boolean quiet;

private List<RegexpFilter> filters = new ArrayList<>();
Expand Down Expand Up @@ -153,6 +155,20 @@ public void setForensicsDisabled(final boolean forensicsDisabled) {
// do nothing
}

/**
* Returns whether post-processing of the issues should be disabled.
*
* @return {@code true} if post-processing of the issues should be disabled.
*/
public boolean isSkipPostProcessing() {
return skipPostProcessing;
}

@DataBoundSetter
public void setSkipPostProcessing(final boolean skipPostProcessing) {
this.skipPostProcessing = skipPostProcessing;
}

@CheckForNull
public String getSourceCodeEncoding() {
return sourceCodeEncoding;
Expand Down Expand Up @@ -228,6 +244,7 @@ static class Execution extends AnalysisExecution<AnnotatedReport> {
private final Tool tool;
private final String sourceCodeEncoding;
private final boolean isBlameDisabled;
private final boolean skipPostProcessing;
private final List<RegexpFilter> filters;
private final Set<String> sourceDirectories;
private final String scm;
Expand All @@ -250,6 +267,7 @@ static class Execution extends AnalysisExecution<AnnotatedReport> {
filters = step.getFilters();
sourceDirectories = step.getAllSourceDirectories();
scm = step.getScm();
skipPostProcessing = step.isSkipPostProcessing();
quiet = step.isQuiet();
}

Expand All @@ -261,7 +279,9 @@ protected AnnotatedReport run() throws IOException, InterruptedException, Illega
IssuesScanner issuesScanner = new IssuesScanner(tool, filters,
getCharset(sourceCodeEncoding), workspace, sourceDirectories,
getRun(), new FilePath(getRun().getRootDir()), listener,
scm, isBlameDisabled ? BlameMode.DISABLED : BlameMode.ENABLED, quiet);
scm, isBlameDisabled ? BlameMode.DISABLED : BlameMode.ENABLED,
skipPostProcessing ? PostProcessingMode.DISABLED : PostProcessingMode.ENABLED,
quiet);

return issuesScanner.scan();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
If this option is unchecked, then the plugin automatically resolves absolute paths, fingerprints,
package and module names from the source files in the workspace.
If this operation slows down your build, you can use this option to deactivate this feature.
</div>
5 changes: 5 additions & 0 deletions plugin/src/main/resources/issues/scan-parameters.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
</f:entry>
<s:scm/>

<f:entry field="skipPostProcessing">
<f:checkbox title="${%title.skipPostProcessing}" />
</f:entry>
<s:scm/>

<i:hr title="${%Reading Affected Files}"/>

<p:sourceConfig/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title.sourceDirectories=Source Directories
description.sourceDirectories=Additional paths to the source code if not in the root of the workspace \
(or outside the workspace).
title.blameDisabled=Disable retrieval of blame information (author and commit) from SCM
title.skipPostProcessing=Disable detection of missing package and module names
title.filter=Issue Filters
description.filter=Issues will be matched with all the specified filters. If no filter is \
defined, then all issues will be published. Filters with empty regular expression will be ignored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class DetailsTableModelTest extends AbstractDetailsModelTest {
@Test
@org.jvnet.hudson.test.Issue("JENKINS-64051")
@org.junitpioneer.jupiter.Issue("JENKINS-64051")
void shouldNotRemoveWhitespace() {
try (IssueBuilder builder = new IssueBuilder()) {
builder.setMessage("project: Defaults to NumberGroupSeparator on .NET Core except on Windows.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void shouldCollectSingleResultForSingleAxis() {
verify(recorder).publishResult(any(), any(), anyString(), any(), anyString(), any());
}

@Test @org.jvnet.hudson.test.Issue("JENKINS-59178")
@Test @org.junitpioneer.jupiter.Issue("JENKINS-59178")
void shouldCollectDifferentResultsForTwoAxes() {
IssuesRecorder recorder = mock(IssuesRecorder.class);
IssuesAggregator aggregator = createIssueAggregator(recorder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private String getWorkspacePath(final WorkflowJob project, final String fileName
/**
* Tests JENKINS-56484: Error while parsing clang errors with active timestamper plugin.
*/
@Test @org.jvnet.hudson.test.Issue("JENKINS-56484")
@Test @org.junitpioneer.jupiter.Issue("JENKINS-56484")
void shouldCorrectlyParseClangErrors() {
WorkflowJob project = createPipeline();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void shouldShowNoFilesOutsideWorkspace() {
* Verifies that a source code file will be copied from outside the workspace if configured correspondingly.
*/
@Test
@org.jvnet.hudson.test.Issue("JENKINS-55998")
@org.junitpioneer.jupiter.Issue("JENKINS-55998")
void shouldShowFileOutsideWorkspaceIfConfigured() {
FreeStyleProject job = createFreeStyleProject();
prepareGccLog(job);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MiscIssuesRecorderITest extends IntegrationTestWithJenkinsPerSuite {
/**
* Verifies that {@link FindBugs} handles the different severity mapping modes ({@link PriorityProperty}).
*/
@Test @org.jvnet.hudson.test.Issue("JENKINS-55514")
@Test @org.junitpioneer.jupiter.Issue("JENKINS-55514")
void shouldMapSeverityFilterForFindBugs() {
FreeStyleProject project = createFreeStyleProjectWithWorkspaceFilesWithSuffix("findbugs-severities.xml");

Expand Down Expand Up @@ -208,7 +208,6 @@ void shouldCreateSingleActionIfAggregationEnabled() {
first -> assertThat(first).endsWith("checkstyle-issues.txt"),
second -> assertThat(second).endsWith("pmd-warnings-issues.txt")
);

}

private List<AnalysisResult> runJobWithAggregation(final boolean isAggregationEnabled) {
Expand All @@ -223,7 +222,7 @@ private List<AnalysisResult> runJobWithAggregation(final boolean isAggregationEn

/**
* Runs the CheckStyle and PMD tools for two corresponding files which contain 10 issues in total. Since a filter
* afterwords removes all issues, the actual result contains no warnings. However, the two origins are still
* afterword removes all issues, the actual result contains no warnings. However, the two origins are still
* reported with a total of 0 warnings per origin.
*/
@Test
Expand Down Expand Up @@ -258,7 +257,7 @@ void shouldHaveOriginsIfBuildContainsWarnings() {
* Verifies that a report that contains errors (since the report pattern does not find some files),
* will fail the step if the property {@link IssuesRecorder#setFailOnError(boolean)} is enabled.
*/
@Test @org.jvnet.hudson.test.Issue("JENKINS-58056")
@Test @org.junitpioneer.jupiter.Issue("JENKINS-58056")
void shouldFailBuildWhenFailBuildOnErrorsIsSet() {
FreeStyleProject job = createFreeStyleProject();
IssuesRecorder recorder = enableEclipseWarnings(job);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import hudson.FilePath;
import hudson.model.FreeStyleProject;
import hudson.model.Run;

import io.jenkins.plugins.analysis.core.model.ResultAction;
import io.jenkins.plugins.analysis.core.testutil.IntegrationTestWithJenkinsPerSuite;
Expand Down Expand Up @@ -129,6 +130,36 @@ void shouldShowModulesForVariousModulesDetectedForOsgiMavenAndAntInTheHtmlOutput
new PropertyRow("Test-Bundle-Name", 1));
}

@Test
void shouldSkipPostProcessing() {
String[] workspaceFiles = {
BUILD_FILE_PATH + ANT_BUILD_FILE_LOCATION + "build.xml",
BUILD_FILE_PATH + ANT_BUILD_FILE_LOCATION + "m1/build.xml",
BUILD_FILE_PATH + MAVEN_BUILD_FILE_LOCATION + "pom.xml",
BUILD_FILE_PATH + MAVEN_BUILD_FILE_LOCATION + "m1/pom.xml",
BUILD_FILE_PATH + MAVEN_BUILD_FILE_LOCATION + "m2/pom.xml",
BUILD_FILE_PATH + OSGI_BUILD_FILE_LOCATION + "META-INF/MANIFEST.MF",
BUILD_FILE_PATH + OSGI_BUILD_FILE_LOCATION + "m1/META-INF/MANIFEST.MF",
BUILD_FILE_PATH + OSGI_BUILD_FILE_LOCATION + "m2/META-INF/MANIFEST.MF",
BUILD_FILE_PATH + OSGI_BUILD_FILE_LOCATION + "m3/META-INF/MANIFEST.MF",
BUILD_FILE_PATH + OSGI_BUILD_FILE_LOCATION + "plugin.properties"};

Check warning on line 145 in plugin/src/test/java/io/jenkins/plugins/analysis/warnings/steps/ModuleDetectorITest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>void shouldShowModulesForVariousModulesDetectedForOsgiMavenAndAntInTheHtmlOutput() { String[] workspaceFiles &#61; { BUILD_FILE_PATH &#43; ANT_BUILD_FILE_LOCATION &#43; &#34;build.xml&#34;, BUILD_FILE_PATH &#43; ANT_BUILD_FILE_LOCATION &#43; &#34;m1/build.xml&#34;, BUILD_FILE_PATH &#43; MAVEN_BUILD_FILE_LOCATION &#43; &#34;pom.xml&#34;, BUILD_FILE_PATH &#43; MAVEN_BUILD_FILE_LOCATION &#43; &#34;m1/pom.xml&#34;, BUILD_FILE_PATH &#43; MAVEN_BUILD_FILE_LOCATION &#43; &#34;m2/pom.xml&#34;, BUILD_FILE_PATH &#43; OSGI_BUILD_FILE_LOCATION &#43; &#34;META-INF/MANIFEST.MF&#34;, BUILD_FILE_PATH &#43; OSGI_BUILD_FILE_LOCATION &#43; &#34;m1/META-INF/MANIFEST.MF&#34;, BUILD_FILE_PATH &#43; OSGI_BUILD_FILE_LOCATION &#43; &#34;m2/META-INF/MANIFEST.MF&#34;, BUILD_FILE_PATH &#43; OSGI_BUILD_FILE_LOCATION &#43; &#34;m3/META-INF/MANIFEST.MF&#34;, BUILD_FILE_PATH &#43; OSGI_BUILD_FILE_LOCATION &#43; &#34;plugin.properties&#34;};</code></pre>

FreeStyleProject project = createFreeStyleProject();
copyWorkspaceFiles(project, workspaceFiles, file -> file.replaceFirst("detectors/buildfiles/\\w*/", ""));
var recorder = enableGenericWarnings(project, new Eclipse());
recorder.setSkipPostProcessing(true);

createEclipseWarningsReport(workspaceFiles.length - 1, true,
getJenkins().jenkins.getWorkspaceFor(project));

Run<?, ?> build = buildSuccessfully(project);
ResultAction result = getResultAction(build);
assertThat(result.getResult().getIssues().getModules()).containsExactly("-");

assertThat(getConsoleLog(build)).doesNotContain("Resolving module names from module definitions (build.xml, pom.xml, or Manifest.mf files)");
assertThat(getConsoleLog(build)).contains("Skipping post processing");
}

/**
* Verifies that the output is correct if there are only Maven modules in the expected HTML output.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PackageDetectorsITest extends IntegrationTestWithJenkinsPerSuite {
* in the expected HTML output.
*/
@Test
@org.jvnet.hudson.test.Issue("JENKINS-58538")
@org.junitpioneer.jupiter.Issue("JENKINS-58538")
void shouldShowFolderDistributionRatherThanPackageDistribution() {
FreeStyleProject project = createFreeStyleProject();

Expand Down Expand Up @@ -311,9 +311,6 @@ void shouldDetectVariousNamespacesForCSharpFiles() {
assertThat(logOutput).contains(returnExpectedNumberOfResolvedPackageNames(6));
}

/**
* Verifies that various packages (Java) are handled correctly.
*/
@Test
void shouldDetectVariousPackagesForJavaFiles() {
ResultAction action = buildProject(
Expand All @@ -330,16 +327,39 @@ void shouldDetectVariousPackagesForJavaFiles() {
assertThat(result.getIssues().getPackages()).containsExactly(
"edu.hm.hafner.analysis._123.int.naming.structure", "-");

Map<String, Long> totalByPacakgeName = collectPackageNames(result);
assertThat(totalByPacakgeName).hasSize(2);
assertThat(totalByPacakgeName.get("edu.hm.hafner.analysis._123.int.naming.structure")).isEqualTo(1L);
assertThat(totalByPacakgeName.get("-")).isEqualTo(5L);
Map<String, Long> totalByPackageName = collectPackageNames(result);
assertThat(totalByPackageName).hasSize(2);
assertThat(totalByPackageName.get("edu.hm.hafner.analysis._123.int.naming.structure")).isEqualTo(1L);
assertThat(totalByPackageName.get("-")).isEqualTo(5L);

String consoleLog = getConsoleLog(result);
assertThat(consoleLog).contains(DEFAULT_DEBUG_LOG_LINE);
assertThat(consoleLog).contains(returnExpectedNumberOfResolvedPackageNames(6));
}

@Test
void shouldSkipPackageDetection() {
FreeStyleProject project = createJobWithWorkspaceFiles(
PACKAGE_WITH_FILES_JAVA + "eclipseForJavaVariousClasses.txt",
PACKAGE_WITH_FILES_JAVA + "SampleClassWithPackage.java",
PACKAGE_WITH_FILES_JAVA + "SampleClassWithoutPackage.java",
PACKAGE_WITH_FILES_JAVA + "SampleClassWithUnconventionalPackageNaming.java",
PACKAGE_WITH_FILES_JAVA + "SampleClassWithBrokenPackageNaming.java");
var recorder = enableGenericWarnings(project, new Eclipse());
recorder.setSkipPostProcessing(true);

Run<?, ?> build = buildSuccessfully(project);
ResultAction action = getResultAction(build);

AnalysisResult result = action.getResult();
assertThat(result.getIssues()).hasSize(6);
assertThat(result.getIssues().getPackages()).containsExactly("-");

String consoleLog = getConsoleLog(result);
assertThat(consoleLog).doesNotContain(DEFAULT_DEBUG_LOG_LINE);
assertThat(consoleLog).contains("Skipping post processing");
}

private String returnExpectedNumberOfResolvedPackageNames(final int expectedNumberOfResolvedPackageNames) {
return "-> resolved package names of " + expectedNumberOfResolvedPackageNames + " affected files";
}
Expand Down
Loading

0 comments on commit 92949e5

Please sign in to comment.