Skip to content

Commit

Permalink
Update dependencies and require to java 11
Browse files Browse the repository at this point in the history
  • Loading branch information
reyamam authored and shrykull committed Jan 14, 2022
1 parent a89e48b commit 572ca92
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 51 deletions.
43 changes: 26 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.4</version>
<relativePath />
<version>4.32</version>
<relativePath/>
</parent>

<artifactId>sonar-gerrit</artifactId>
Expand All @@ -25,7 +26,9 @@
~ hpi-plugin.version: The HPI Maven Plugin version used by the plugin..
~ stapler-plugin.version: The Stapler Maven plugin version required by the plugin.
-->
<jersey.version>2.31</jersey.version>
<jersey.version>3.0.3</jersey.version>
<jenkins.version>2.277.1</jenkins.version>
<java.version>11</java.version>
</properties>

<name>Sonar Gerrit Plugin</name>
Expand Down Expand Up @@ -54,7 +57,7 @@
<developerConnection>scm:git:ssh://[email protected]/jenkinsci/${project.artifactId}-plugin.git
</developerConnection>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
<tag>sonar-gerrit-2.4.3</tag>
<tag>sonar-gerrit-3.0.2</tag>
</scm>

<repositories>
Expand Down Expand Up @@ -88,6 +91,7 @@
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<extensions>true</extensions>

<configuration>
<compatibleSinceVersion>1.0</compatibleSinceVersion>
<!-- Otherwise classes are loaded from Guava 11 by Jenkins WAR -->
Expand Down Expand Up @@ -146,17 +150,17 @@
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.22</version>
<version>2.23</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand All @@ -171,17 +175,17 @@
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.14</version>
<version>1.15</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>2.6.3</version>
<version>2.6.4</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -196,24 +200,24 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.20</version>
<version>308.v852b473a2b8c</version>
</dependency>
<dependency>
<groupId>com.sonyericsson.hudson.plugins.gerrit</groupId>
<artifactId>gerrit-trigger</artifactId>
<version>2.30.5</version>
<version>2.35.2</version>
</dependency>
<!-- to replace makros like ${GERRIT_CHANGE_NUMBER} -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>token-macro</artifactId>
<version>2.12</version>
<version>267.vcdaea6462991</version>
</dependency>
<!-- to reuse Sonar Installations with credentials from this plugin -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>sonar</artifactId>
<version>2.12</version>
<version>2.14</version>
</dependency>

<dependency>
Expand All @@ -223,12 +227,12 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
<version>31.0.1-jre</version>
</dependency>
<dependency>
<groupId>com.urswolfer.gerrit.client.rest</groupId>
<artifactId>gerrit-rest-java-client</artifactId>
<version>0.9.2</version>
<version>0.9.4</version>
</dependency>

<!-- JERSEY CLIENT -->
Expand All @@ -247,5 +251,10 @@
<artifactId>jersey-media-json-binding</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,16 @@
import hudson.tasks.Publisher;
import jenkins.tasks.SimpleBuildStep;

/**
* Project: Sonar-Gerrit Plugin
* Author: Tatiana Didik
*/
public class SonarToGerritPublisher extends Publisher implements SimpleBuildStep {

private static final Logger LOGGER = Logger.getLogger(SonarToGerritPublisher.class.getName());

public static final String GERRIT_CHANGE_NUMBER_ENV_VAR_NAME = "GERRIT_CHANGE_NUMBER";

public static final String GERRIT_NAME_ENV_VAR_NAME = "GERRIT_NAME";

public static final String GERRIT_PATCHSET_NUMBER_ENV_VAR_NAME = "GERRIT_PATCHSET_NUMBER";

// ------------------ configuration settings
/*
* The URL of SonarQube server to be used for comments
* */
@Nonnull
private InspectionConfig inspectionConfig = new InspectionConfig();

Expand All @@ -96,11 +91,11 @@ public SonarToGerritPublisher() {
// @DataBoundConstructor
@Deprecated //since 2.0. Left here for Jenkins version < 1.625.3
public SonarToGerritPublisher(String sonarURL, List<SubJobConfig> subJobConfigs,
String severity, boolean changedLinesOnly, boolean newIssuesOnly,
String noIssuesToPostText, String someIssuesToPostText, String issueComment,
boolean overrideCredentials, String httpUsername, String httpPassword,
boolean postScore, String category, String noIssuesScore, String issuesScore,
String noIssuesNotification, String issuesNotification) {
String severity, boolean changedLinesOnly, boolean newIssuesOnly,
String noIssuesToPostText, String someIssuesToPostText, String issueComment,
boolean overrideCredentials, String httpUsername, String httpPassword,
boolean postScore, String category, String noIssuesScore, String issuesScore,
String noIssuesNotification, String issuesNotification) {
setSonarURL(sonarURL);
setSubJobConfigs(subJobConfigs);

Expand All @@ -114,19 +109,23 @@ public SonarToGerritPublisher(String sonarURL, List<SubJobConfig> subJobConfigs,
setReviewConfig(reviewConfig);

if (postScore) {
ScoreConfig scoreConfig = new ScoreConfig(issueFilterConfig, category, Integer.parseInt(noIssuesScore), Integer.parseInt(issuesScore));
ScoreConfig scoreConfig = new ScoreConfig(issueFilterConfig, category, Integer.parseInt(noIssuesScore), Integer
.parseInt(issuesScore));
setScoreConfig(scoreConfig);
} else {
setScoreConfig(null);
}

NotificationConfig notificationConfig = new NotificationConfig(noIssuesNotification, issuesNotification, issuesNotification);
NotificationConfig notificationConfig = new NotificationConfig(noIssuesNotification, issuesNotification,
issuesNotification);
setNotificationConfig(notificationConfig);
}

@Override
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException {
TaskListenerLogger.logMessage(listener, LOGGER, Level.INFO, "jenkins.plugin.sonar.start", inspectionConfig.getAnalysisType());
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull Launcher launcher,
@Nonnull TaskListener listener) throws InterruptedException, IOException {
TaskListenerLogger
.logMessage(listener, LOGGER, Level.INFO, "jenkins.plugin.sonar.start", inspectionConfig.getAnalysisType());

//load inspection report
SonarConnector sonarConnector = new SonarConnector(run, listener, inspectionConfig);
Expand All @@ -153,15 +152,19 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull
//get issues to be commented
Multimap<String, IssueAdapter> file2issuesToComment = getFilteredFileToIssueMultimap(
reviewConfig.getIssueFilterConfig(), sonarConnector, fileToChangedLines);
TaskListenerLogger.logMessage(listener, LOGGER, Level.INFO, "jenkins.plugin.issues.to.comment", file2issuesToComment.entries().size());
TaskListenerLogger
.logMessage(listener, LOGGER, Level.INFO, "jenkins.plugin.issues.to.comment", file2issuesToComment.entries()
.size());

//get issues to be scored
Multimap<String, IssueAdapter> file2issuesToScore = null;
boolean postScore = scoreConfig != null;
if (postScore) {
file2issuesToScore = getFilteredFileToIssueMultimap(
scoreConfig.getIssueFilterConfig(), sonarConnector, fileToChangedLines);
TaskListenerLogger.logMessage(listener, LOGGER, Level.INFO, "jenkins.plugin.issues.to.score", file2issuesToScore.entries().size());
TaskListenerLogger
.logMessage(listener, LOGGER, Level.INFO, "jenkins.plugin.issues.to.score", file2issuesToScore.entries()
.size());
}

String serverUrl;
Expand All @@ -187,14 +190,15 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull
}

private Multimap<String, IssueAdapter> getFilteredFileToIssueMultimap(IssueFilterConfig filterConfig,
SonarConnector sonarConnector,
Map<String, Set<Integer>> fileToChangedLines) {
SonarConnector sonarConnector,
Map<String, Set<Integer>> fileToChangedLines) {
IssueFilter commentFilter = new IssueFilter(filterConfig, sonarConnector.getIssues(), fileToChangedLines);
Iterable<IssueAdapter> issuesToComment = commentFilter.filter();
return sonarConnector.getReportData(issuesToComment);
}

private Map<String, String> getEnvVars(Run<?, ?> run, TaskListener listener, List<String> varNames) throws IOException, InterruptedException {
private Map<String, String> getEnvVars(Run<?, ?> run, TaskListener listener, List<String> varNames) throws IOException,
InterruptedException {
Map<String, String> envVars = new HashMap<>();
for (String varName : varNames) {
envVars.put(varName, getEnvVar(run, listener, varName));
Expand All @@ -205,7 +209,8 @@ private Map<String, String> getEnvVars(Run<?, ?> run, TaskListener listener, Lis
private String getEnvVar(Run<?, ?> run, TaskListener listener, String name) throws IOException, InterruptedException {
EnvVars envVars = run.getEnvironment(listener);
String value = envVars.get(name);
// due to JENKINS-30910 old versions of workflow-job-plugin do not have code copying ParameterAction values to Environment Variables in pipeline jobs.
// due to JENKINS-30910 old versions of workflow-job-plugin do not have code copying ParameterAction values to
// Environment Variables in pipeline jobs.
if (value == null) {
ParametersAction action = run.getAction(ParametersAction.class);
if (action != null) {
Expand Down Expand Up @@ -234,47 +239,56 @@ public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
}


/**
* Descriptor for {@link SonarToGerritPublisher}. Used as a singleton.
* The class is marked as public so that it can be accessed from views.
* <p>
* See <tt>src/main/resources/hudson/plugins/hello_world/SonarToGerritBuilder/*.jelly</tt>
* for the actual HTML fragment for the configuration screen.
*/
@Symbol("sonarToGerrit")
@Extension // This indicates to Jenkins that this is an implementation of an extension point.
public static final class DescriptorImpl extends BuildStepDescriptor<Publisher> {

public static final NotifyHandling NOTIFICATION_RECIPIENT_NO_ISSUES = NotifyHandling.NONE;

public static final NotifyHandling NOTIFICATION_RECIPIENT_SOME_ISSUES = NotifyHandling.OWNER;

public static final NotifyHandling NOTIFICATION_RECIPIENT_NEGATIVE_SCORE = NotifyHandling.OWNER;

public static final String PROJECT_PATH = "";

public static final String SONAR_REPORT_PATH = "target/sonar/sonar-report.json";

public static final String SONAR_URL = "http://localhost:9000";

public static final String SONAR_PULLREQUEST_KEY = "${GERRIT_CHANGE_NUMBER}";

public static final String DEFAULT_INSPECTION_CONFIG_TYPE = InspectionConfig.DescriptorImpl.BASE_TYPE;

public static final boolean AUTO_MATCH_INSPECTION_AND_REVISION_PATHS = false;

public static final String NO_ISSUES_TEXT = Localization.getLocalized("jenkins.plugin.default.review.title.no.issues");

public static final String SOME_ISSUES_TEXT = Localization.getLocalized("jenkins.plugin.default.review.title.issues");

public static final String ISSUE_COMMENT_TEXT = Localization.getLocalized("jenkins.plugin.default.review.body");

public static final String CATEGORY = "Code-Review";

public static final Integer NO_ISSUES_SCORE = 1;

public static final Integer SOME_ISSUES_SCORE = -1;

public static final boolean OVERRIDE_CREDENTIALS = false;

public static final String SEVERITY = Severity.INFO.name();

public static final boolean NEW_ISSUES_ONLY = false;

public static final boolean CHANGED_LINES_ONLY = false;

public static final int DEFAULT_SCORE = 0;


/**
* In order to load the persisted global configuration, you have to
* call load() in the constructor.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.jenkinsci.plugins.sonargerrit.inspection.entity;

import javax.json.bind.annotation.JsonbDateFormat;

import java.util.Date;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.json.bind.annotation.JsonbDateFormat;

/**
* Project: Sonar-Gerrit Plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.common.base.MoreObjects;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger;
import org.jenkinsci.plugins.sonargerrit.config.AuthenticationConfig;
import org.jenkinsci.plugins.sonargerrit.review.ConnectionInfo;
import org.jenkinsci.plugins.sonargerrit.util.DataHelper;

import java.util.Arrays;
Expand All @@ -13,6 +12,8 @@

import static org.jenkinsci.plugins.sonargerrit.util.Localization.getLocalized;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Project: Sonar-Gerrit Plugin
* Author: Tatiana Didik
Expand Down Expand Up @@ -70,6 +71,7 @@ public String getPassword() {
return password;
}

@SuppressFBWarnings("NP_NULL_PARAM_DEREF")
private String retrieveServerName(Map<String, String> envVars, GerritTrigger trigger) {
String serverName = envVars.get(GERRIT_NAME_ENV_VAR_NAME);
String triggerServerName = trigger != null ? trigger.getServerName() : null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.jenkinsci.plugins.sonargerrit.sonar;

import javax.annotation.Nullable;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.MediaType;

import org.apache.commons.lang.StringUtils;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
Expand Down Expand Up @@ -82,7 +82,7 @@ public ComponentSearchResult fetchComponents(@Nullable String component) {
ComponentSearchResult componentSearchResult = null;
Integer total = null;

for (int currentPage = 1; total == null || (currentPage - 1) * PAGE_SIZE < total; currentPage++) {
for (int currentPage = 1; (total == null) || (((currentPage - 1) * PAGE_SIZE) < total); currentPage++) {
ComponentSearchResult pageResult = fetchComponents(component, currentPage);
if (componentSearchResult == null) {
componentSearchResult = pageResult;
Expand Down
Loading

0 comments on commit 572ca92

Please sign in to comment.