diff --git a/.gitignore b/.gitignore index 1146752..a141bc5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ work .project .settings *.iml - +.idea/ diff --git a/src/main/java/jenkins/plugins/extracolumns/BuildTriggersColumn.java b/src/main/java/jenkins/plugins/extracolumns/BuildTriggersColumn.java new file mode 100644 index 0000000..eb459b6 --- /dev/null +++ b/src/main/java/jenkins/plugins/extracolumns/BuildTriggersColumn.java @@ -0,0 +1,141 @@ +package jenkins.plugins.extracolumns; + +import hudson.Extension; +import hudson.Util; +import hudson.model.AbstractProject; +import hudson.model.Job; +import hudson.scm.NullSCM; +import hudson.scm.SCM; +import hudson.triggers.SCMTrigger; +import hudson.triggers.Trigger; +import hudson.triggers.TriggerDescriptor; +import hudson.views.ListViewColumn; +import hudson.views.ListViewColumnDescriptor; +import jenkins.model.ParameterizedJobMixIn; +import org.kohsuke.stapler.DataBoundConstructor; + +import java.util.List; +import java.util.Map; + +public class BuildTriggersColumn extends ListViewColumn { + + private int columnWidth; + private boolean forceWidth; + + @DataBoundConstructor + public BuildTriggersColumn(int columnWidth, boolean forceWidth) { + this.columnWidth = columnWidth; + this.forceWidth = forceWidth; + } + + public BuildTriggersColumn() { + this(80, false); + } + + public String getBuildTriggers(@SuppressWarnings("rawtypes") Job job) { + String upstreamTriggerName = jenkins.triggers.Messages.ReverseBuildTrigger_build_after_other_projects_are_built(); + + StringBuilder result = new StringBuilder(); + + List upstreamProjects = getUpstreamProjects(job); + if (upstreamProjects != null && !upstreamProjects.isEmpty()) { + result.append(escape(upstreamTriggerName)).append(": "); + append(result, upstreamProjects); + } + + Map> triggers = getTriggers(job); + if (triggers != null) { + boolean hasSourceCodeManagement = hasSourceCodeManagement(job); + + for (Map.Entry> trigger : triggers.entrySet()) { + if (upstreamTriggerName.equals(trigger.getKey().getDisplayName())) + continue; + + if (result.length() > 0) + result.append("
"); + + boolean isDisabled = !hasSourceCodeManagement && trigger.getValue() instanceof SCMTrigger; + + if (isDisabled) + result.append("[") + .append(escape(Messages.BuildTriggersColumn_Disabled())) + .append("] "); + + result.append(escape(trigger.getKey().getDisplayName())); + + String spec = trigger.getValue().getSpec(); + if (spec != null && spec.trim().length() > 0) + result.append(": ") + .append(escape(spec)); + + if (isDisabled) + result.append(""); + } + } + + return result.toString(); + } + + private List getUpstreamProjects(Job job) { + if (!(job instanceof AbstractProject)) + return null; + + AbstractProject proj = (AbstractProject) job; + + return proj.getUpstreamProjects(); + } + + private boolean hasSourceCodeManagement(Job job) { + if (!(job instanceof AbstractProject)) + return false; + + AbstractProject proj = (AbstractProject) job; + + SCM sourceCodeManagement = proj.getScm(); + return sourceCodeManagement != null && !(sourceCodeManagement instanceof NullSCM); + } + + private Map> getTriggers(Job aJob) { + if (!(aJob instanceof ParameterizedJobMixIn.ParameterizedJob)) + return null; + + ParameterizedJobMixIn.ParameterizedJob job = (ParameterizedJobMixIn.ParameterizedJob) aJob; + + return job.getTriggers(); + } + + private void append(StringBuilder result, List upstreamTriggers) { + for (int i = 0; i < upstreamTriggers.size(); i++) { + AbstractProject up = upstreamTriggers.get(i); + if (i > 0) + result.append(", "); + result.append(escape(up.getDisplayName())); + } + } + + private String escape(String txt) { + if (txt == null) + txt = ""; + + return Util.escape(txt.trim()).replace("\n", "
"); + } + + @Extension + public static class DescriptorImpl extends ListViewColumnDescriptor { + + @Override + public boolean shownByDefault() { + return false; + } + + @Override + public String getDisplayName() { + return Messages.BuildTriggersColumn_DisplayName(); + } + + @Override + public String getHelpFile() { + return "/plugin/extra-columns/help-buildTriggers-column.html"; + } + } +} diff --git a/src/main/resources/jenkins/plugins/extracolumns/BuildTriggersColumn/column.jelly b/src/main/resources/jenkins/plugins/extracolumns/BuildTriggersColumn/column.jelly new file mode 100644 index 0000000..3f0e883 --- /dev/null +++ b/src/main/resources/jenkins/plugins/extracolumns/BuildTriggersColumn/column.jelly @@ -0,0 +1,31 @@ + + + + + + + + + diff --git a/src/main/resources/jenkins/plugins/extracolumns/BuildTriggersColumn/columnHeader.jelly b/src/main/resources/jenkins/plugins/extracolumns/BuildTriggersColumn/columnHeader.jelly new file mode 100644 index 0000000..62a1707 --- /dev/null +++ b/src/main/resources/jenkins/plugins/extracolumns/BuildTriggersColumn/columnHeader.jelly @@ -0,0 +1,30 @@ + + + + + + ${%BuildTriggersColumn.Header} + + \ No newline at end of file diff --git a/src/main/resources/jenkins/plugins/extracolumns/BuildTriggersColumn/columnHeader.properties b/src/main/resources/jenkins/plugins/extracolumns/BuildTriggersColumn/columnHeader.properties new file mode 100644 index 0000000..e5b595d --- /dev/null +++ b/src/main/resources/jenkins/plugins/extracolumns/BuildTriggersColumn/columnHeader.properties @@ -0,0 +1,25 @@ +# +# The MIT License +# +# Copyright (c) 2012, Frederic Gurr +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +BuildTriggersColumn.Header=Build triggers diff --git a/src/main/resources/jenkins/plugins/extracolumns/BuildTriggersColumn/config.jelly b/src/main/resources/jenkins/plugins/extracolumns/BuildTriggersColumn/config.jelly new file mode 100644 index 0000000..129bb22 --- /dev/null +++ b/src/main/resources/jenkins/plugins/extracolumns/BuildTriggersColumn/config.jelly @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + +
${%This column shows the build triggers.}
+
+
\ No newline at end of file diff --git a/src/main/resources/jenkins/plugins/extracolumns/BuildTriggersColumn/config_de.properties b/src/main/resources/jenkins/plugins/extracolumns/BuildTriggersColumn/config_de.properties new file mode 100644 index 0000000..774f906 --- /dev/null +++ b/src/main/resources/jenkins/plugins/extracolumns/BuildTriggersColumn/config_de.properties @@ -0,0 +1,24 @@ +# The MIT License +# +# Copyright (c) 2012, Frederic Gurr +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +Force\ column\ width=Spaltenbreite festlegen +Column\ width=Spaltenbreite diff --git a/src/main/resources/jenkins/plugins/extracolumns/Messages.properties b/src/main/resources/jenkins/plugins/extracolumns/Messages.properties index bc88d6c..8d07072 100644 --- a/src/main/resources/jenkins/plugins/extracolumns/Messages.properties +++ b/src/main/resources/jenkins/plugins/extracolumns/Messages.properties @@ -46,3 +46,5 @@ SlaveOrLabelColumn.DisplayName=Slave Allocation UserNameColumn.DisplayName=User Name CronTriggerColumn.DisplayName=Periodic Build Trigger CronTriggerColumn.ToolTipFormat=Would have last run at {0}; would next run at {1}. +BuildTriggersColumn.DisplayName=Build Triggers +BuildTriggersColumn.Disabled=Disabled diff --git a/src/main/webapp/help-buildTriggers-column.html b/src/main/webapp/help-buildTriggers-column.html new file mode 100644 index 0000000..18f4c7f --- /dev/null +++ b/src/main/webapp/help-buildTriggers-column.html @@ -0,0 +1,29 @@ + + +
+ This column shows the build triggers.
+
+ To force a specific column width in pixel (px) check the "Force column width" checkbox and set the desired width.
+
\ No newline at end of file