Skip to content

Commit

Permalink
SONARJNKNS-258 Fix dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju committed Jun 20, 2016
1 parent 030d9e5 commit ea30cb5
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 48 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@
</pluginRepositories>

<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-ws</artifactId>
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/hudson/plugins/sonar/AbstractMsBuildSQRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/sonar/MsBuildSQRunnerBegin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -106,7 +106,7 @@ public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskLi
}

private static Map<String, String> getSonarProps(SonarInstallation inst) {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();

map.put("sonar.host.url", inst.getServerUrl());

Expand Down
28 changes: 13 additions & 15 deletions src/main/java/hudson/plugins/sonar/MsBuildSQRunnerEnd.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,7 +106,7 @@ private static void addArgs(ArgumentListBuilder args, EnvVars env, SonarInstalla
}

private static Map<String, String> getSonarProps(SonarInstallation inst) {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();

if (!StringUtils.isBlank(inst.getServerAuthenticationToken())) {
map.put("sonar.login", inst.getServerAuthenticationToken());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,11 +87,11 @@ public MaskPasswordsOutputStream(OutputStream logger, Collection<String> 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
Expand Down
21 changes: 7 additions & 14 deletions src/main/java/hudson/plugins/sonar/utils/SonarUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -66,7 +63,7 @@ public static String extractSonarProjectURLFromLogs(Run<?, ?> build) throws IOEx
}

public static <T extends Action> List<T> getPersistentActions(Actionable actionable, Class<T> type) {
List<T> filtered = new LinkedList<T>();
List<T> filtered = new LinkedList<>();

// we use this method to avoid recursively calling transitive action factories
for (Action a : actionable.getActions()) {
Expand All @@ -79,10 +76,10 @@ public static <T extends Action> List<T> getPersistentActions(Actionable actiona
}
return filtered;
}

@CheckForNull
public static <T extends Action> T getPersistentAction(Actionable actionable, Class<T> 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;
Expand Down Expand Up @@ -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) {
Expand All @@ -126,8 +121,6 @@ private static String extractPatternFromLogs(String pattern, Run<?, ?> build) th
url = match.group(1);
}
}
} finally {
IOUtils.closeQuietly(br);
}
return url;
}
Expand Down

0 comments on commit ea30cb5

Please sign in to comment.