diff --git a/pom.xml b/pom.xml index 7c97ec5d..d9b049e0 100644 --- a/pom.xml +++ b/pom.xml @@ -124,6 +124,11 @@ + + commons-lang + commons-lang + 2.6 + org.sonarsource.sonarqube sonar-ws diff --git a/src/main/java/hudson/plugins/sonar/AbstractMsBuildSQRunner.java b/src/main/java/hudson/plugins/sonar/AbstractMsBuildSQRunner.java index a30fe9a5..e653ad7c 100644 --- a/src/main/java/hudson/plugins/sonar/AbstractMsBuildSQRunner.java +++ b/src/main/java/hudson/plugins/sonar/AbstractMsBuildSQRunner.java @@ -33,26 +33,23 @@ */ package hudson.plugins.sonar; -import hudson.plugins.sonar.utils.BuilderUtils; - +import hudson.AbortException; +import hudson.EnvVars; import hudson.Launcher; -import hudson.model.TaskListener; -import org.codehaus.plexus.util.StringUtils; import hudson.Util; -import hudson.model.Run; import hudson.model.AbstractBuild; import hudson.model.EnvironmentContributingAction; import hudson.model.InvisibleAction; +import hudson.model.Run; +import hudson.model.TaskListener; +import hudson.plugins.sonar.utils.BuilderUtils; import hudson.tasks.Builder; -import jenkins.tasks.SimpleBuildStep; -import hudson.AbortException; -import hudson.EnvVars; - -import javax.annotation.Nullable; - import java.io.IOException; import java.util.Collections; import java.util.Map; +import javax.annotation.Nullable; +import jenkins.tasks.SimpleBuildStep; +import org.apache.commons.lang.StringUtils; public abstract class AbstractMsBuildSQRunner extends Builder implements SimpleBuildStep { protected static final String EXE = "MSBuild.SonarQube.Runner.exe"; diff --git a/src/main/java/hudson/plugins/sonar/MsBuildSQRunnerBegin.java b/src/main/java/hudson/plugins/sonar/MsBuildSQRunnerBegin.java index 908f1002..419976c0 100644 --- a/src/main/java/hudson/plugins/sonar/MsBuildSQRunnerBegin.java +++ b/src/main/java/hudson/plugins/sonar/MsBuildSQRunnerBegin.java @@ -52,7 +52,7 @@ import java.util.Map; import javax.annotation.Nullable; import jenkins.model.Jenkins; -import org.codehaus.plexus.util.StringUtils; +import org.apache.commons.lang.StringUtils; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; @@ -106,7 +106,7 @@ public void perform(Run run, FilePath workspace, Launcher launcher, TaskLi } private static Map getSonarProps(SonarInstallation inst) { - Map map = new LinkedHashMap(); + Map map = new LinkedHashMap<>(); map.put("sonar.host.url", inst.getServerUrl()); diff --git a/src/main/java/hudson/plugins/sonar/MsBuildSQRunnerEnd.java b/src/main/java/hudson/plugins/sonar/MsBuildSQRunnerEnd.java index 96dbd8be..523d7103 100644 --- a/src/main/java/hudson/plugins/sonar/MsBuildSQRunnerEnd.java +++ b/src/main/java/hudson/plugins/sonar/MsBuildSQRunnerEnd.java @@ -33,29 +33,27 @@ */ package hudson.plugins.sonar; -import org.codehaus.plexus.util.StringUtils; -import hudson.plugins.sonar.utils.SonarUtils; -import hudson.model.Action; -import hudson.plugins.sonar.action.SonarMarkerAction; -import org.kohsuke.stapler.DataBoundConstructor; -import jenkins.model.Jenkins; import hudson.AbortException; import hudson.EnvVars; -import hudson.plugins.sonar.utils.BuilderUtils; -import hudson.util.ArgumentListBuilder; import hudson.Extension; -import hudson.model.AbstractProject; -import hudson.tasks.BuildStepDescriptor; import hudson.FilePath; import hudson.Launcher; -import hudson.model.TaskListener; +import hudson.model.AbstractProject; +import hudson.model.Action; import hudson.model.Run; - +import hudson.model.TaskListener; +import hudson.plugins.sonar.action.SonarMarkerAction; +import hudson.plugins.sonar.utils.BuilderUtils; +import hudson.plugins.sonar.utils.SonarUtils; +import hudson.tasks.BuildStepDescriptor; +import hudson.tasks.Builder; +import hudson.util.ArgumentListBuilder; import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; - -import hudson.tasks.Builder; +import jenkins.model.Jenkins; +import org.apache.commons.lang.StringUtils; +import org.kohsuke.stapler.DataBoundConstructor; public class MsBuildSQRunnerEnd extends AbstractMsBuildSQRunner { @DataBoundConstructor @@ -108,7 +106,7 @@ private static void addArgs(ArgumentListBuilder args, EnvVars env, SonarInstalla } private static Map getSonarProps(SonarInstallation inst) { - Map map = new LinkedHashMap(); + Map map = new LinkedHashMap<>(); if (!StringUtils.isBlank(inst.getServerAuthenticationToken())) { map.put("sonar.login", inst.getServerAuthenticationToken()); diff --git a/src/main/java/hudson/plugins/sonar/utils/MaskPasswordsOutputStream.java b/src/main/java/hudson/plugins/sonar/utils/MaskPasswordsOutputStream.java index 47fdc3f4..5ea9c243 100644 --- a/src/main/java/hudson/plugins/sonar/utils/MaskPasswordsOutputStream.java +++ b/src/main/java/hudson/plugins/sonar/utils/MaskPasswordsOutputStream.java @@ -34,15 +34,12 @@ package hudson.plugins.sonar.utils; import hudson.console.LineTransformationOutputStream; -import org.apache.commons.lang.StringUtils; - -import com.google.common.base.Charsets; - import java.io.IOException; import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.regex.Pattern; +import org.apache.commons.lang.StringUtils; /** * Class adapted from the mask-passwords plugin @@ -90,11 +87,11 @@ public MaskPasswordsOutputStream(OutputStream logger, Collection passwor @Override protected void eol(byte[] bytes, int len) throws IOException { - String line = new String(bytes, 0, len, Charsets.UTF_8); + String line = new String(bytes, 0, len, StandardCharsets.UTF_8); if (passwordsAsPattern != null && !line.contains(URL_IN_LOGS)) { line = passwordsAsPattern.matcher(line).replaceAll(REPLACEMENT); } - logger.write(line.getBytes(Charsets.UTF_8)); + logger.write(line.getBytes(StandardCharsets.UTF_8)); } @Override diff --git a/src/main/java/hudson/plugins/sonar/utils/SonarUtils.java b/src/main/java/hudson/plugins/sonar/utils/SonarUtils.java index 6c1f4899..85754bbe 100644 --- a/src/main/java/hudson/plugins/sonar/utils/SonarUtils.java +++ b/src/main/java/hudson/plugins/sonar/utils/SonarUtils.java @@ -18,15 +18,10 @@ */ package hudson.plugins.sonar.utils; -import hudson.plugins.sonar.action.SonarAnalysisAction; import hudson.model.Action; import hudson.model.Actionable; import hudson.model.Run; -import org.apache.commons.io.IOUtils; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - +import hudson.plugins.sonar.action.SonarAnalysisAction; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -36,6 +31,8 @@ import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; /** * @author Julien HENRY @@ -66,7 +63,7 @@ public static String extractSonarProjectURLFromLogs(Run build) throws IOEx } public static List getPersistentActions(Actionable actionable, Class type) { - List filtered = new LinkedList(); + List filtered = new LinkedList<>(); // we use this method to avoid recursively calling transitive action factories for (Action a : actionable.getActions()) { @@ -79,10 +76,10 @@ public static List getPersistentActions(Actionable actiona } return filtered; } - + @CheckForNull public static T getPersistentAction(Actionable actionable, Class type) { - // we use this method to avoid recursively calling transitive action factories + // we use this method to avoid recursively calling transitive action factories for (Action a : actionable.getActions()) { if (a == null) { continue; @@ -114,10 +111,8 @@ public static Properties extractReportTask(Run build) throws IOException { } private static String extractPatternFromLogs(String pattern, Run build) throws IOException { - BufferedReader br = null; String url = null; - try { - br = new BufferedReader(build.getLogReader()); + try (BufferedReader br = new BufferedReader(build.getLogReader())) { String strLine; Pattern p = Pattern.compile(pattern); while ((strLine = br.readLine()) != null) { @@ -126,8 +121,6 @@ private static String extractPatternFromLogs(String pattern, Run build) th url = match.group(1); } } - } finally { - IOUtils.closeQuietly(br); } return url; }