Skip to content

Commit

Permalink
Merge pull request #193 from jenkinsci/JENKINS-23152
Browse files Browse the repository at this point in the history
Fix for JENKINS-23152
  • Loading branch information
rsandell committed Dec 22, 2014
2 parents 19bfb01 + bed6fa9 commit c3899ea
Show file tree
Hide file tree
Showing 20 changed files with 1,471 additions and 734 deletions.
3 changes: 1 addition & 2 deletions pom.xml
Expand Up @@ -3,8 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.509.3</version>
<!--<relativePath>../pom.xml</relativePath>-->
<version>1.565.3</version>
</parent>

<groupId>com.sonyericsson.hudson.plugins.gerrit</groupId>
Expand Down
Expand Up @@ -33,6 +33,8 @@
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.TriggerContextConverter;

import com.sonymobile.tools.gerrit.gerritevents.dto.attr.Provider;
import com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent;
import hudson.Plugin;
import hudson.model.AbstractProject;
import hudson.model.Api;
Expand Down Expand Up @@ -240,6 +242,28 @@ public boolean containsServer(String serverName) {
return contains;
}

/**
* Finds the server config for the event's provider.
*
* @param event the event
* @return the config or null if no server could be found.
* @see com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent#getProvider()
*/
public static IGerritHudsonTriggerConfig getServerConfig(GerritTriggeredEvent event) {
Provider provider = event.getProvider();
if (provider != null) {
GerritServer gerritServer = getInstance().getServer(provider.getName());
if (gerritServer != null) {
return gerritServer.getConfig();
} else {
logger.warn("Could not find server config for {} - no such server.", provider.getName());
}
} else {
logger.warn("The event {} has no provider specified. BUG!", event);
}
return null;
}

/**
* Gets the global config.
*
Expand Down
Expand Up @@ -29,21 +29,21 @@
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.TriggerContext;
import com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent;

import hudson.model.Result;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Result;
import jenkins.model.Jenkins;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.CheckForNull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.TreeMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.sonyericsson.hudson.plugins.gerrit.trigger.utils.Logic.shouldSkip;

/**
Expand Down Expand Up @@ -320,7 +320,7 @@ public synchronized boolean isBuilding(GerritTriggeredEvent event, AbstractProje
return false;
} else {
for (Entry entry : pb.getEntries()) {
if (entry.getProject().equals(project)) {
if (entry.isProject(project)) {
if (entry.getBuild() != null) {
return !entry.isBuildCompleted();
} else {
Expand Down Expand Up @@ -699,8 +699,8 @@ public synchronized boolean wereAllBuildsNotBuilt() {
*/
public static class Entry {

private AbstractProject project;
private AbstractBuild build;
private String project;
private String build;
private boolean buildCompleted;
private String unsuccessfulMessage;

Expand All @@ -711,8 +711,8 @@ public static class Entry {
* @param build the build.
*/
private Entry(AbstractProject project, AbstractBuild build) {
this.project = project;
this.build = build;
this.project = project.getFullName();
this.build = build.getId();
buildCompleted = false;
}

Expand All @@ -722,7 +722,7 @@ private Entry(AbstractProject project, AbstractBuild build) {
* @param project the project.
*/
private Entry(AbstractProject project) {
this.project = project;
this.project = project.getFullName();
buildCompleted = false;
}

Expand All @@ -731,17 +731,24 @@ private Entry(AbstractProject project) {
*
* @return the project.
*/
@CheckForNull
public AbstractProject getProject() {
return project;
return Jenkins.getInstance().getItemByFullName(project, AbstractProject.class);
}

/**
* The build of a project.
*
* @return the build.
*/
@CheckForNull
public AbstractBuild getBuild() {
return build;
AbstractProject p = getProject();
if (p != null) {
return p.getBuild(build);
} else {
return null;
}
}

/**
Expand All @@ -750,7 +757,11 @@ public AbstractBuild getBuild() {
* @param build the build.
*/
private void setBuild(AbstractBuild build) {
this.build = build;
if (build != null) {
this.build = build.getId();
} else {
this.build = null;
}
}

/**
Expand Down Expand Up @@ -803,6 +814,21 @@ public String toString() {
return s;
}

/**
* If the provided project is the same as this entry is referencing.
* It does so by checking the fullName for equality.
*
* @param other the other project to check
* @return true if so.
* @see #getProject()
*/
public boolean isProject(AbstractProject other) {
if (this.project != null && other != null) {
return this.project.equals(other.getFullName());
} else {
return this.project == null && other == null;
}
}
}
}
}

0 comments on commit c3899ea

Please sign in to comment.