Skip to content

Commit

Permalink
Implemented JENKINS-30386
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNielsen committed Sep 10, 2015
1 parent f116c87 commit fe97369
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Expand Up @@ -77,7 +77,9 @@ public CodeSonarPublisher(List<Condition> conditions, String hubAddress, String
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
String expandedHubAddress = build.getEnvironment(listener).expand(Util.fixNull(hubAddress));
String expandedProjectName = build.getEnvironment(listener).expand(Util.fixNull(projectName));


httpService.setListener(listener);

if (expandedHubAddress.isEmpty()) {
throw new AbortException("Hub address not provided");
}
Expand All @@ -91,7 +93,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
if (analysisUrl == null) {
analysisUrl = analysisService.getLatestAnalysisUrlForAProject(expandedHubAddress, expandedProjectName);
}

Analysis analysisActiveWarnings = analysisService.getAnalysisFromUrl(analysisUrl, UrlFilters.ACTIVE);

String metricsUrl = metricsService.getMetricsUrlFromAnAnalysisId(expandedHubAddress, analysisActiveWarnings.getAnalysisId());
Expand Down
@@ -1,7 +1,7 @@
package org.jenkinsci.plugins.codesonar.services;

import hudson.AbortException;
import java.io.IOException;
import hudson.model.BuildListener;
import java.io.Serializable;
import org.apache.http.client.fluent.Request;

Expand All @@ -10,15 +10,30 @@
* @author Andrius
*/
public class HttpService implements Serializable {
private transient BuildListener listener;

public String getContentFromUrlAsString(String url) throws AbortException {
log(String.format("Request sent to %s", url));

String output;
try {
output = Request.Get(url).execute().returnContent().asString();
} catch (Exception e) {
log(String.format("Error on url: %s", url));
log(String.format("Exception message is: %s", e.getMessage()));
throw new AbortException(e.getMessage());
}

return output;
}

public void setListener(BuildListener listener) {
this.listener = listener;
}

private void log(String content) {
if(listener != null) {
listener.getLogger().println("[CodeSonar] "+content);
}
}
}

0 comments on commit fe97369

Please sign in to comment.