-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from J-cztery/AddJobSupport
* upstream/pr/95: JENKINS-24207 - Add new selectors for Perforce and P4 plugins that allow to update JIRA issues based on jobs associated with changes. Other changes: 1. Refactor selectors. Break down methods in DefaultIssuesSelector so that it is easier to reuse. Side effect is that DefaultIssueSelector now will be fully recursive (once the other problems are fixed). 2. Fix resources (DefaultUpdaterIssueSelector/config.jelly->selectors/DefaultIssueSelector/config.jelly).
- Loading branch information
Showing
14 changed files
with
586 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/hudson/plugins/jira/selector/perforce/JobIssueSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package hudson.plugins.jira.selector.perforce; | ||
|
||
import java.util.Set; | ||
|
||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.plugins.jira.JiraSite; | ||
import hudson.plugins.jira.selector.DefaultIssueSelector; | ||
|
||
/** | ||
* Base class for job selectors. Perforce offers mechanism to associate JIRA | ||
* issues with change lists called jobs. The classes inheriting from this class | ||
* find issues by examining jobs associated with changes | ||
* | ||
* @author Jacek Tomaka | ||
* @since 2.3 | ||
*/ | ||
public abstract class JobIssueSelector extends DefaultIssueSelector { | ||
|
||
@Override | ||
/** | ||
* See {@link #addJobIdsFromChangeLog(Run, JiraSite, TaskListener, Set)} | ||
*/ | ||
protected void addIssuesFromChangeLog(Run<?, ?> build, JiraSite site, TaskListener listener, Set<String> issueIds) { | ||
addJobIdsFromChangeLog(build, site, listener, issueIds); | ||
} | ||
|
||
/** | ||
* Adds job ids from change log to issueIds. | ||
*/ | ||
protected abstract void addJobIdsFromChangeLog(Run<?, ?> build, JiraSite site, TaskListener listener, | ||
Set<String> issueIds); | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
src/main/java/hudson/plugins/jira/selector/perforce/P4JobIssueSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package hudson.plugins.jira.selector.perforce; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.logging.Logger; | ||
|
||
import org.jenkinsci.plugins.p4.changes.P4ChangeEntry; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import com.perforce.p4java.core.IFix; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Descriptor; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.plugins.jira.JiraSite; | ||
import hudson.plugins.jira.Messages; | ||
import hudson.plugins.jira.RunScmChangeExtractor; | ||
import hudson.plugins.jira.selector.AbstractIssueSelector; | ||
import hudson.scm.ChangeLogSet; | ||
import hudson.scm.ChangeLogSet.Entry; | ||
|
||
/** | ||
* Job selector for Perforce Software SCM plugin (P4) | ||
* | ||
* @author Jacek Tomaka | ||
* @since 2.3 | ||
*/ | ||
public class P4JobIssueSelector extends JobIssueSelector { | ||
private static final Logger LOGGER = Logger.getLogger(P4JobIssueSelector.class.getName()); | ||
|
||
@Extension(optional = true) | ||
public static final class DescriptorImpl extends Descriptor<AbstractIssueSelector> { | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return Messages.P4JobIssueSelector_DisplayName(); | ||
} | ||
} | ||
|
||
@DataBoundConstructor | ||
public P4JobIssueSelector() { | ||
} | ||
|
||
@Override | ||
protected void addJobIdsFromChangeLog(Run<?, ?> build, JiraSite site, TaskListener listener, Set<String> issueIds) { | ||
getLogger().finer("Searching for JIRA issues in perforce jobs in " + build); | ||
for (ChangeLogSet<? extends Entry> set : RunScmChangeExtractor.getChanges(build)) { | ||
for (Entry change : set) { | ||
getLogger().fine("Looking for JIRA IDs as Perforce Jobs in " + change.getMsg()); | ||
if (P4ChangeEntry.class.isAssignableFrom(change.getClass())) { | ||
P4ChangeEntry p4ChangeEntry = (P4ChangeEntry) change; | ||
|
||
List<IFix> jobs = p4ChangeEntry.getJobs(); | ||
if (jobs != null) { | ||
for (IFix job : jobs) { | ||
String jobId = job.getJobId(); | ||
if (issueIds.add(jobId)) { | ||
getLogger().finer("Added perforce job id " + jobId + " from build " + build); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected Logger getLogger() { | ||
return LOGGER; | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/hudson/plugins/jira/selector/perforce/PerforceJobIssueSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package hudson.plugins.jira.selector.perforce; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.logging.Logger; | ||
|
||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import com.tek42.perforce.model.Changelist; | ||
import com.tek42.perforce.model.Changelist.JobEntry; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Descriptor; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.plugins.jira.JiraSite; | ||
import hudson.plugins.jira.Messages; | ||
import hudson.plugins.jira.RunScmChangeExtractor; | ||
import hudson.plugins.jira.selector.AbstractIssueSelector; | ||
import hudson.plugins.perforce.PerforceChangeLogEntry; | ||
import hudson.scm.ChangeLogSet; | ||
import hudson.scm.ChangeLogSet.Entry; | ||
|
||
/** | ||
* Job selector for old Perforce SCM plugin | ||
* | ||
* @author Jacek Tomaka | ||
* @since 2.3 | ||
* | ||
*/ | ||
public class PerforceJobIssueSelector extends JobIssueSelector { | ||
private static final Logger LOGGER = Logger.getLogger(PerforceJobIssueSelector.class.getName()); | ||
|
||
@Extension(optional = true) | ||
public static final class DescriptorImpl extends Descriptor<AbstractIssueSelector> { | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return Messages.PerforceJobIssueSelector_DisplayName(); | ||
} | ||
} | ||
|
||
@DataBoundConstructor | ||
public PerforceJobIssueSelector() { | ||
} | ||
|
||
@Override | ||
protected void addJobIdsFromChangeLog(Run<?, ?> build, JiraSite site, TaskListener listener, Set<String> issueIds) { | ||
getLogger().finer("Searching for JIRA issues in perforce jobs in " + build); | ||
for (ChangeLogSet<? extends Entry> set : RunScmChangeExtractor.getChanges(build)) { | ||
for (Entry change : set) { | ||
getLogger().fine("Looking for JIRA IDs as Perforce Jobs in " + change.getMsg()); | ||
if (PerforceChangeLogEntry.class.isAssignableFrom(change.getClass())) { | ||
PerforceChangeLogEntry perforceChangeLogEntry = (PerforceChangeLogEntry) change; | ||
Changelist changeList = perforceChangeLogEntry.getChange(); | ||
if (changeList != null) { | ||
List<JobEntry> jobs = changeList.getJobs(); | ||
if (jobs != null) { | ||
for (JobEntry job : jobs) { | ||
String jobId = job.getJob(); | ||
if (issueIds.add(jobId)) { | ||
getLogger().finer("Added perforce job id " + jobId + " from build " + build); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected Logger getLogger() { | ||
return LOGGER; | ||
} | ||
|
||
} |
Oops, something went wrong.