Skip to content
Permalink
Browse files

Better implementation of JENKINS-30386

  • Loading branch information...
MadsNielsen committed Sep 10, 2015
1 parent 8671c16 commit f8d7db8dc84c417b033489e4d976d3fd732456b4
@@ -78,8 +78,6 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
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");
}
@@ -3,37 +3,28 @@
import hudson.AbortException;
import hudson.model.BuildListener;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.http.client.fluent.Request;

/**
*
* @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));


private static final Logger logger = Logger.getLogger(HttpService.class.getName());

public String getContentFromUrlAsString(String url) throws AbortException {
logger.fine(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());
logger.log(Level.SEVERE, String.format("[CodeSonar] Error on url: %s", url), e);
throw new AbortException(String.format("[CodeSonar] Error on url: %s%n[CodeSonar] Message is: %s", url, 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);
}
}
}
@@ -104,6 +104,7 @@ public void testLogging() throws Exception {

// assert that we have a message in the console log
String log = FileUtils.readFileToString(build.getLogFile());
assertTrue(log.contains("[CodeSonar] Request sent to http://10.10.10.10/index.xml"));
assertTrue(log.contains("[CodeSonar] Error on url: http://10.10.10.10/index.xml"));
assertTrue(log.contains("[CodeSonar] Message is: "));
}
}

0 comments on commit f8d7db8

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