Skip to content

Commit

Permalink
Fix JENKINS-18667 + fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Aug 1, 2013
1 parent 49fb679 commit 9baf7b5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 70 deletions.
Expand Up @@ -2,6 +2,8 @@

import antlr.ANTLRException;
import hudson.Extension;
import hudson.Util;
import hudson.console.AnnotatedLargeText;
import hudson.matrix.MatrixConfiguration;
import hudson.model.*;
import hudson.model.listeners.ItemListener;
Expand All @@ -10,6 +12,7 @@
import jenkins.model.Jenkins;
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.lib.xtrigger.AbstractTriggerByFullContext;
import org.jenkinsci.lib.xtrigger.XTriggerDescriptor;
Expand All @@ -21,6 +24,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -57,10 +61,55 @@ public File getLogFile() {

@Override
public Collection<? extends Action> getProjectActions() {
BuildResultTriggerAction action = new BuildResultTriggerAction((AbstractProject) job, getLogFile(), getDescriptor().getDisplayName());
BuildResultTriggerAction action = new InternalBuildResultTriggerAction(getDescriptor().getDisplayName());
return Collections.singleton(action);
}

public final class InternalBuildResultTriggerAction extends BuildResultTriggerAction {

private transient String actionTitle;

public InternalBuildResultTriggerAction(String actionTitle) {
this.actionTitle = actionTitle;
}

@SuppressWarnings("unused")
public AbstractProject<?, ?> getOwner() {
return (AbstractProject) job;
}

@Override
public String getIconFileName() {
return "clipboard.gif";
}

@Override
public String getDisplayName() {
return "BuildResultTrigger Log";
}

@Override
public String getUrlName() {
return "buildResultTriggerPollLog";
}

@SuppressWarnings("unused")
public String getLabel() {
return actionTitle;
}

@SuppressWarnings("unused")
public String getLog() throws IOException {
return Util.loadFile(getLogFile());
}

@SuppressWarnings("unused")
public void writeLogTo(XMLOutput out) throws IOException {
new AnnotatedLargeText<InternalBuildResultTriggerAction>(getLogFile(), Charset.defaultCharset(), true, this).writeHtmlTo(0, out.asWriter());
}
}


@Override
protected boolean requiresWorkspaceForPolling() {
return false;
Expand Down Expand Up @@ -114,15 +163,7 @@ protected BuildResultTriggerContext getContext(Node node, XTriggerLog log) throw
}

private boolean isValidBuildResultProject(AbstractProject item) {
if (item == null) {
return false;
}

if (item instanceof MatrixConfiguration) {
return false;
}

return true;
return item != null && !(item instanceof MatrixConfiguration);
}

@Override
Expand Down Expand Up @@ -166,19 +207,19 @@ private boolean checkIfModifiedJob(String jobName, CheckedResult[] expectedResul
}

Integer newLastBuildNumber = newContextResults.get(jobName);
if (newLastBuildNumber == null || newLastBuildNumber.intValue() == 0) {
if (newLastBuildNumber == null || newLastBuildNumber == 0) {
log.info(String.format("The job %s doesn't have any new builds.", jobName));
return false;
}


Integer oldLastBuildNumber = oldContextResults.get(jobName);
if (oldLastBuildNumber == null || oldLastBuildNumber.intValue() == 0) {
if (oldLastBuildNumber == null || oldLastBuildNumber == 0) {
return isMatchingExpectedResults(jobName, expectedResults, log, newContextResults.get(jobName));
}

//Process if there is a new build between now and previous polling
if (newLastBuildNumber.intValue() == 0 || newLastBuildNumber.intValue() != oldLastBuildNumber.intValue()) {
if (newLastBuildNumber.intValue() != oldLastBuildNumber.intValue()) {
return isMatchingExpectedResults(jobName, expectedResults, log, newContextResults.get(jobName));
}

Expand Down
@@ -1,66 +1,10 @@
package org.jenkinsci.plugins.buildresulttrigger;

import hudson.Util;
import hudson.console.AnnotatedLargeText;
import hudson.model.AbstractProject;
import hudson.model.Action;
import org.apache.commons.jelly.XMLOutput;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

/**
* @author Gregory Boissinot
*/
public class BuildResultTriggerAction implements Action {

private transient AbstractProject<?, ?> job;
private transient File logFile;
private transient String label;

public BuildResultTriggerAction(AbstractProject<?, ?> job, File logFile, String label) {
this.job = job;
this.logFile = logFile;
this.label = label;
}

@SuppressWarnings("unused")
public AbstractProject<?, ?> getOwner() {
return job;
}

@SuppressWarnings("unused")
public String getLabel() {
return label;
}

@SuppressWarnings("unused")
public String getLog() throws IOException {
return Util.loadFile(getLogFile());
}

public File getLogFile() {
return logFile;
}

@SuppressWarnings("unused")
public void writeLogTo(XMLOutput out) throws IOException {
new AnnotatedLargeText<BuildResultTriggerAction>(getLogFile(), Charset.defaultCharset(), true, this).writeHtmlTo(0, out.asWriter());
}

@SuppressWarnings("unused")
public String getIconFileName() {
return "clipboard.gif";
}

public String getDisplayName() {
return "BuildResultTrigger Log";
}

@SuppressWarnings("unused")
public String getUrlName() {
return "buildResultTriggerPollLog";
}
public abstract class BuildResultTriggerAction implements Action {

}

0 comments on commit 9baf7b5

Please sign in to comment.