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

Block scoped usage #235

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: Java CI

on: [push]
on:
- pull_request
- push
branches:
- master

jobs:
build:

runs-on: ubuntu-latest

steps:
Expand Down
47 changes: 11 additions & 36 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@
<matrix-project.version>1.13</matrix-project.version>
<junit-plugin.version>1.24</junit-plugin.version>
<git-plugin.version>3.9.1</git-plugin.version>
<workflow-api.version>2.34</workflow-api.version>
<workflow-cps.version>2.67</workflow-cps.version>
<workflow-step.version>2.19</workflow-step.version>
<workflow-job.version>2.32</workflow-job.version>
<structs.version>1.19</structs.version>
<antisamy-markup-formatter.version>1.5</antisamy-markup-formatter.version>
<dashboard-view.version>2.9.4</dashboard-view.version>
Expand Down Expand Up @@ -124,9 +120,11 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>2.1.16</version>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.138.x</artifactId>
<version>3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand All @@ -148,16 +146,6 @@
<artifactId>mailer</artifactId>
<version>1.20</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-scm-step</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
Expand All @@ -168,17 +156,16 @@
<artifactId>commons-lang3</artifactId>
<version>${commons.lang.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-credentials</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>2.6.3</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -289,32 +276,26 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<version>${script-security.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>${workflow-api.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>${workflow-cps.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${workflow-step.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>${workflow-job.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>${structs.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -326,12 +307,10 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>${credentials.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>apache-httpcomponents-client-4-api</artifactId>
<version>${httpcomponents-client.version}</version>
</dependency>

<!-- Optional Jenkins Plug-in Dependencies -->
Expand Down Expand Up @@ -519,7 +498,6 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>cloudbees-folder</artifactId>
<version>${folder-plugin.version}</version>
<scope>test</scope>
</dependency>

Expand All @@ -534,14 +512,12 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>2.15</version>
<scope>test</scope>
</dependency>
<!-- recorder -> step -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>2.7</version>
<scope>test</scope>
</dependency>
<!-- Docker Agents -->
Expand Down Expand Up @@ -575,7 +551,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>2.2.7</version>
<version>2.6.3</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand All @@ -584,7 +560,6 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>3.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import edu.hm.hafner.analysis.IssueParser;
import edu.hm.hafner.analysis.ParsingCanceledException;
import edu.hm.hafner.analysis.ParsingException;
import edu.hm.hafner.analysis.ReaderFactory;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.util.Ensure;
import edu.umd.cs.findbugs.annotations.Nullable;
Expand Down Expand Up @@ -117,9 +118,15 @@ public String getReportEncoding() {
@Override
public Report scan(final Run<?, ?> run, final FilePath workspace, final Charset sourceCodeEncoding,
final LogHandler logger) {
return scan(run, workspace, sourceCodeEncoding, logger, new ConsoleLogReaderFactory(run));
}

@Override
public Report scan(final Run<?, ?> run, final FilePath workspace, final Charset sourceCodeEncoding,
final LogHandler logger, final ReaderFactory readerFactory) {
String actualPattern = getActualPattern();
if (StringUtils.isBlank(actualPattern)) {
return scanInConsoleLog(workspace, run, logger);
return scanInConsoleLog(workspace, run, logger, readerFactory);
}
else {
if (StringUtils.isBlank(getPattern())) {
Expand Down Expand Up @@ -159,7 +166,8 @@ private Report scanInWorkspace(final FilePath workspace, final String expandedPa
}
}

private Report scanInConsoleLog(final FilePath workspace, final Run<?, ?> run, final LogHandler logger) {
private Report scanInConsoleLog(final FilePath workspace, final Run<?, ?> run, final LogHandler logger,
final ReaderFactory readerFactory) {
Ensure.that(getDescriptor().canScanConsoleLog()).isTrue(
"Static analysis tool %s cannot scan console log output, please define a file pattern",
getActualName());
Expand All @@ -170,7 +178,7 @@ private Report scanInConsoleLog(final FilePath workspace, final Run<?, ?> run, f
consoleReport.logInfo("Parsing console log (workspace: '%s')", workspace);
logger.log(consoleReport);

Report report = createParser().parse(new ConsoleLogReaderFactory(run));
Report report = createParser().parse(readerFactory);

if (getDescriptor().isConsoleLog()) {
report.stream().filter(issue -> !issue.hasFileName())
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/io/jenkins/plugins/analysis/core/model/Tool.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import edu.hm.hafner.analysis.ParsingCanceledException;
import edu.hm.hafner.analysis.ParsingException;
import edu.hm.hafner.analysis.ReaderFactory;
import edu.hm.hafner.analysis.Report;

import org.kohsuke.stapler.DataBoundSetter;
Expand Down Expand Up @@ -139,6 +140,31 @@ public ToolDescriptor getDescriptor() {
public abstract Report scan(Run<?, ?> run, FilePath workspace, Charset sourceCodeEncoding, LogHandler logger)
throws ParsingException, ParsingCanceledException;

/**
* Scans the results of a build for issues. This method is invoked on Jenkins master. I.e., if a tool wants to
* process some build results it is required to run a {@link MasterToSlaveCallable}.
*
* @param run
* the build
* @param workspace
* the workspace of the build
* @param sourceCodeEncoding
* the encoding to use to read source files
* @param logger
* the logger
*
* @return the created report
* @throws ParsingException
* Signals that during parsing a non recoverable error has been occurred
* @throws ParsingCanceledException
* Signals that the parsing has been aborted by the user
*/
public Report scan(final Run<?, ?> run, final FilePath workspace, final Charset sourceCodeEncoding, final LogHandler logger,
final ReaderFactory factory)
throws ParsingException, ParsingCanceledException {
return scan(run, workspace, sourceCodeEncoding, logger);
}

/** Descriptor for {@link Tool}. **/
public abstract static class ToolDescriptor extends Descriptor<Tool> {
private final String id;
Expand Down
Loading