Skip to content
Permalink
Browse files

JENKINS-30932, JENKINS-30933

  • Loading branch information...
aquarellian committed Oct 13, 2015
1 parent 8e588d2 commit 829d233b0b737a91fd5c305384e1410d3b5ed88c
@@ -131,6 +131,10 @@ public String getProjectPath() {
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException,
InterruptedException {
FilePath reportPath = build.getWorkspace().child(getPath());
if (!reportPath.exists()) {
logError(listener, "jenkins.plugin.error.sonar.report.not.exists", Level.SEVERE, reportPath);
return false;
}
LOGGER.log(Level.INFO, "Getting Sonar Report from: {0}", reportPath);

SonarReportBuilder builder = new SonarReportBuilder();
@@ -151,15 +155,18 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
String gerritNameEnvVar = getEnvVar(build, listener, GERRIT_NAME_ENV_VAR_NAME);
GerritTrigger trigger = GerritTrigger.getTrigger(build.getProject());
String gerritServerName = gerritNameEnvVar != null ? gerritNameEnvVar : trigger != null ? trigger.getServerName() : null;
if (checkAndLogIfNull(listener, gerritServerName, "jenkins.plugin.error.gerrit.server.empty", Level.SEVERE)) {
if (gerritServerName == null) {
logError(listener, "jenkins.plugin.error.gerrit.server.empty", Level.SEVERE);
return false;
}
IGerritHudsonTriggerConfig gerritConfig = GerritManagement.getConfig(gerritServerName);
if (checkAndLogIfNull(listener, gerritConfig, "jenkins.plugin.error.gerrit.config.empty", Level.SEVERE)) {
if (gerritConfig == null) {
logError(listener, "jenkins.plugin.error.gerrit.config.empty", Level.SEVERE);
return false;
}
GerritRestApiFactory gerritRestApiFactory = new GerritRestApiFactory();
if (checkAndLogIfNull(listener, gerritConfig.getGerritHttpUserName(), "jenkins.plugin.error.gerrit.user.empty", Level.WARNING)) {
if (gerritConfig.getGerritHttpUserName() == null) {
logError(listener, "jenkins.plugin.error.gerrit.user.empty", Level.SEVERE);
return false;
}
GerritAuthData.Basic authData = new GerritAuthData.Basic(gerritConfig.getGerritFrontEndUrl(),
@@ -207,13 +214,10 @@ private String getEnvVar(AbstractBuild build, BuildListener listener, String nam
return envVars.get(name);
}

private boolean checkAndLogIfNull(BuildListener listener, Object value, String message, Level l) {
if (value == null) {
listener.getLogger().println(message);
LOGGER.log(l, message);
return true;
}
return false;
private void logError(BuildListener listener, String message, Level l, Object... params) {
message = getLocalized(message, params);
listener.getLogger().println(message);
LOGGER.log(l, message);
}

private void logResultMap(Multimap<String, Issue> file2issues, String message) {
@@ -22,6 +22,11 @@ public static String getLocalized(String s){
return messages.getString(s);
}

public static String getLocalized(String s, Object... params){
String string = getLocalized(s);
return String.format(string, params);
}

public static String getLocalized(String s, Locale l){
ResourceBundle messages = ResourceBundle.getBundle(MESSAGES, l);
return messages.getString(s);
@@ -14,4 +14,5 @@ jenkins.plugin.default.review.title.issues=<total_count> Sonar violations have b
jenkins.plugin.error.gerrit.server.empty=Cannot obtain Gerrit server name. Please check your Gerrit Trigger settings
jenkins.plugin.error.gerrit.config.empty=Cannot obtain Gerrit configuration. Please check your Gerrit Trigger settings
jenkins.plugin.error.gerrit.user.empty=Gerrit authentication is not configured. Please check Gerrit Trigger settings
jenkins.plugin.error.sonar.report.not.exists=Sonar report '%s' does not exist. Please check plugin settings

0 comments on commit 829d233

Please sign in to comment.
You can’t perform that action at this time.