Skip to content

Commit

Permalink
JENKINS-14592 Added some more logging, and ensure that output that do…
Browse files Browse the repository at this point in the history
…esnt include job name is parsed
  • Loading branch information
rossrowe committed Jul 27, 2012
1 parent 74fa15d commit db11b54
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 24 deletions.
9 changes: 5 additions & 4 deletions src/main/java/hudson/plugins/sauce_ondemand/BrowserAxis.java
Expand Up @@ -27,22 +27,23 @@
import hudson.Extension;
import hudson.matrix.Axis;
import hudson.matrix.AxisDescriptor;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* {@link Axis} that configures {@code SELENIUM_DRIVER}.
* @author Kohsuke Kawaguchi
*/
public class BrowserAxis extends Axis {

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

@DataBoundConstructor
public BrowserAxis(List<String> values) {
Expand All @@ -67,9 +68,9 @@ public List<com.saucelabs.ci.Browser> getBrowsers() {
try {
return BrowserFactory.getInstance().values();
} catch (IOException e) {
logger.error("Error retrieving browsers from Saucelabs", e);
logger.log(Level.WARNING, "Error retrieving browsers from Saucelabs", e);
} catch (JSONException e) {
logger.error("Error parsing JSON response", e);
logger.log(Level.WARNING, "Error parsing JSON response", e);
}
return Collections.emptyList();
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/hudson/plugins/sauce_ondemand/PluginImpl.java
Expand Up @@ -37,13 +37,14 @@
import hudson.util.FormValidation;
import hudson.util.Secret;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.bind.JavaScriptMethod;

import javax.servlet.ServletException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Persists the access credential to Sauce OnDemand.
Expand All @@ -53,7 +54,7 @@
@Extension
public class PluginImpl extends Plugin implements Describable<PluginImpl> {

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

private SauceLibraryManager libraryManager = new HudsonSauceLibraryManager();
/**
Expand Down Expand Up @@ -161,7 +162,7 @@ public String checkForUpdates() {
"})\">Update Sauce Connect<\\a>" :
"No update required, Sauce Connect is up to date";
} catch (Exception e) {
logger.error(e);
logger.log(Level.WARNING, "Error checking for later version", e);
}
return "Failed to connect to Sauce OnDemand";
}
Expand All @@ -176,7 +177,7 @@ public String applyUpdates() {
libraryManager.triggerReload();
return "Update of the Sauce Connect library was successful";
} catch (Exception e) {
logger.error(e);
logger.log(Level.WARNING, "Error Reloading plugin", e);
}
return "Failed to apply updates, please see application logs";
}
Expand Down
Expand Up @@ -121,9 +121,9 @@ public SauceOnDemandBuildWrapper(Credentials

@Override
public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
listener.getLogger().println("Starting Sauce OnDemand SSH tunnels");

if (isEnableSauceConnect()) {
listener.getLogger().println("Starting Sauce OnDemand SSH tunnels");
if (launchSauceConnectOnSlave) {
if (!(Computer.currentComputer() instanceof Hudson.MasterComputer)) {
File sauceConnectJar = copySauceConnectToSlave(build, listener);
Expand Down Expand Up @@ -216,8 +216,8 @@ public boolean tearDown(AbstractBuild build, BuildListener listener) throws IOEx
SauceConnectCloser tunnelCloser = new SauceConnectCloser(tunnels, listener);
tunnelCloser.call();
}
listener.getLogger().println("Sauce Connect closed");
}
listener.getLogger().println("Sauce Connect closed");
processBuildOutput(build);
return true;
}
Expand Down
Expand Up @@ -27,12 +27,13 @@
import hudson.tasks.junit.TestObject;
import hudson.tasks.junit.TestResultAction.Data;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -43,7 +44,7 @@
*/
public class SauceOnDemandReportFactory extends Data {

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

public static final SauceOnDemandReportFactory INSTANCE = new SauceOnDemandReportFactory();

Expand All @@ -60,28 +61,39 @@ public Object readResolve() {
public List<SauceOnDemandReport> getTestAction(TestObject testObject) {

if (testObject instanceof CaseResult) {
logger.log(Level.INFO, "Attempting to find Sauce SessionID for test object");
CaseResult cr = (CaseResult) testObject;
String jobName = cr.getFullName();
List<String[]> ids = findSessionIDs(jobName, cr.getStdout(), cr.getStderr());
List<String> lines = new ArrayList<String>();
try {
lines = IOUtils.readLines(testObject.getOwner().getLogReader());
} catch (IOException e) {
logger.log(Level.SEVERE, "Error reading log file", e);
}
String[] lineArray = lines.toArray(new String[lines.size()]);
if (ids.isEmpty()) {
//try parse the build output
try {
List<String> lines = IOUtils.readLines(testObject.getOwner().getLogReader());
String[] lineArray = lines.toArray(new String[lines.size()]);
ids = SauceOnDemandReportFactory.findSessionIDs(jobName, lineArray);
} catch (IOException e) {
logger.error("Error reading log file", e);
}
logger.log(Level.INFO, "Parsing build output");
ids = SauceOnDemandReportFactory.findSessionIDs(jobName, lineArray);
}
boolean matchingJobNames = true;
if (ids.isEmpty()) {
// fall back to old-style log parsing (when no job-name is present in output)
logger.log(Level.INFO, "Parsing stdout with no job name");
ids = findSessionIDs(null, cr.getStdout(), cr.getStderr());
if (ids.isEmpty()) {
ids = SauceOnDemandReportFactory.findSessionIDs(null, lineArray);
}
matchingJobNames = false;
}
if (!ids.isEmpty()) {
if (ids.isEmpty()) {
logger.log(Level.WARNING, "Unable to find Sauce SessionID for test object");
} else {
return Collections.singletonList(new SauceOnDemandReport(cr, ids, matchingJobNames));
}
} else {
logger.log(Level.INFO, "Test Object not a CaseResult, unable to parse output");
}
return Collections.emptyList();
}
Expand Down
Expand Up @@ -64,9 +64,9 @@ public SauceOnDemandReportFactory getTestData(AbstractBuild<?, ?> build, Launche
for (CaseResult cr : sr.getCases()) {
String jobName = cr.getFullName();
List<String[]> sessionIDs = SauceOnDemandReportFactory.findSessionIDs(jobName, cr.getStdout(), cr.getStderr());
List<String> lines = IOUtils.readLines(build.getLogReader());
String[] array = lines.toArray(new String[lines.size()]);
if (sessionIDs.isEmpty()) {
List<String> lines = IOUtils.readLines(build.getLogReader());
String[] array = lines.toArray(new String[lines.size()]);
sessionIDs = SauceOnDemandReportFactory.findSessionIDs(jobName, array);
}
for (String[] id : sessionIDs) {
Expand Down Expand Up @@ -95,6 +95,9 @@ public SauceOnDemandReportFactory getTestData(AbstractBuild<?, ?> build, Launche
if (sessionIDs.isEmpty()) {
// check for old-style logs
sessionIDs = SauceOnDemandReportFactory.findSessionIDs(null, cr.getStdout(), cr.getStderr());
if (sessionIDs.isEmpty()) {
sessionIDs = SauceOnDemandReportFactory.findSessionIDs(null, array);
}
if (!sessionIDs.isEmpty()) {
hasResult = true;
}
Expand Down
Expand Up @@ -52,7 +52,7 @@ public void testFullConfig() throws Exception {
setCredential();

FreeStyleProject p = createFreeStyleProject();
SauceOnDemandBuildWrapper before = new SauceOnDemandBuildWrapper(null, new SeleniumInformation("http://localhost:8080/"), "localhost", "4445", true, null, false);
SauceOnDemandBuildWrapper before = new SauceOnDemandBuildWrapper(null, new SeleniumInformation("http://localhost:8080/"), "localhost", "4445", false, null, false);
p.getBuildWrappersList().add(before);
invokeSeleniumFromBuild(p, new SauceBuilder());
}
Expand All @@ -64,7 +64,7 @@ public void testMinimalConfig() throws Exception {
setCredential();

FreeStyleProject p = createFreeStyleProject();
SauceOnDemandBuildWrapper before = new SauceOnDemandBuildWrapper(null, null, null, "0", true, null, false);
SauceOnDemandBuildWrapper before = new SauceOnDemandBuildWrapper(null, null, null, "0", false, null, false);
p.getBuildWrappersList().add(before);
invokeSeleniumFromBuild(p, new SauceBuilder());
}
Expand Down

0 comments on commit db11b54

Please sign in to comment.