diff --git a/core/src/main/java/hudson/model/BuildStatusIcon.java b/core/src/main/java/hudson/model/BuildStatusIcon.java new file mode 100644 index 0000000000000..6d47544b88a2e --- /dev/null +++ b/core/src/main/java/hudson/model/BuildStatusIcon.java @@ -0,0 +1,50 @@ +package hudson.model; + +import edu.umd.cs.findbugs.annotations.NonNull; +import hudson.Extension; +import org.kohsuke.stapler.DataBoundConstructor; + +/** + * Renders {@link BallColor} as icon for a Job. + * + * @since TODO + */ +public class BuildStatusIcon extends JobIcon { + + @DataBoundConstructor + public BuildStatusIcon() { /* NOP */ } + + @Override + public String getImageOf(String size) { + return getBuildStatus().getImageOf(size); + } + + @Override + public String getIconClassName() { + return "symbol-status-" + getBuildStatus().getIconName(); + } + + @Override + public String getDescription() { + return getBuildStatus().getDescription(); + } + + protected BallColor getBuildStatus() { + Job job = getOwner(); + if (job != null) { + return job.getIconColor(); + } + + return BallColor.NOTBUILT; + } + + @Extension + public static class DescriptorImpl extends JobIconDescriptor { + + @Override + @NonNull + public String getDisplayName() { + return Messages.BuildStatusIcon_DisplayName(); + } + } +} diff --git a/core/src/main/java/hudson/model/Job.java b/core/src/main/java/hudson/model/Job.java index 2ba53d7182a01..295e2dc487dd3 100644 --- a/core/src/main/java/hudson/model/Job.java +++ b/core/src/main/java/hudson/model/Job.java @@ -185,6 +185,8 @@ public abstract class Job, RunT extends Run parent, String name) saveNextBuildNumber(); } + if (icon == null) { + setIcon(new BuildStatusIcon()); + } + if (properties == null) // didn't exist < 1.72 properties = new CopyOnWriteList<>(); @@ -1256,6 +1262,32 @@ public BallColor getIconColor() { return BallColor.NOTBUILT; } + /** + * Gets the icon used for this job. + * + * @return the icon. + * + * @since TODO + */ + public JobIcon getIcon() { + return icon; + } + + /** + * Sets the icon used for this job. + * + * @param icon the icon. + * + * @since TODO + */ + public void setIcon(JobIcon icon) { + this.icon = icon; + + if (icon != null) { + icon.setOwner(this); + } + } + /** * Get the current health report for a job. * @@ -1399,6 +1431,14 @@ public synchronized void doConfigSubmit(StaplerRequest2 req, try (BulkChange bc = new BulkChange(this)) { setDisplayName(json.optString("displayNameOrNull")); + JSONObject jobIconConfig = json.optJSONObject("icon"); + if (jobIconConfig != null) { + JobIcon jobIcon = Descriptor.bindJSON(req, JobIcon.class, jobIconConfig); + setIcon(jobIcon); + } else { + setIcon(null); + } + logRotator = null; DescribableList, JobPropertyDescriptor> t = new DescribableList<>(NOOP, getAllProperties()); diff --git a/core/src/main/java/hudson/model/JobIcon.java b/core/src/main/java/hudson/model/JobIcon.java new file mode 100644 index 0000000000000..cae9162d5e765 --- /dev/null +++ b/core/src/main/java/hudson/model/JobIcon.java @@ -0,0 +1,47 @@ +package hudson.model; + +import edu.umd.cs.findbugs.annotations.Nullable; +import hudson.ExtensionPoint; +import jenkins.model.Jenkins; +import org.jenkins.ui.icon.IconSpec; + +/** + * Renders {@link StatusIcon} for a Job. + * + *

+ * Possible subtypes can range from dumb icons that always render the same thing to smarter icons + * that change its icon based on the state of the job. + * + * @since TODO + */ +public abstract class JobIcon extends AbstractStatusIcon implements Describable, ExtensionPoint, + IconSpec { + + private Job owner; + + /** + * Called by {@link Job} to set the owner that this icon is used for. + * @param job the job. + */ + protected void setOwner(@Nullable Job job) { + owner = job; + } + + /** + * Get the owner. + * @return the job. + */ + protected @Nullable Job getOwner() { + return owner; + } + + @Override + public String getIconClassName() { + return null; + } + + @Override + public JobIconDescriptor getDescriptor() { + return (JobIconDescriptor) Jenkins.get().getDescriptorOrDie(getClass()); + } +} diff --git a/core/src/main/java/hudson/model/JobIconDescriptor.java b/core/src/main/java/hudson/model/JobIconDescriptor.java new file mode 100644 index 0000000000000..b8348856e2a32 --- /dev/null +++ b/core/src/main/java/hudson/model/JobIconDescriptor.java @@ -0,0 +1,27 @@ +package hudson.model; + +import hudson.DescriptorExtensionList; +import jenkins.model.Jenkins; + +/** + * Job icon descriptor. + * + * @since TODO + */ +public abstract class JobIconDescriptor extends Descriptor { + + public static DescriptorExtensionList all() { + return Jenkins.get().getDescriptorList(JobIcon.class); + } + + /** + * Returns true if this {@link Job} type is applicable to the + * given job type. + * @param jobType the type of job. + * @return true to indicate applicable, in which case the icon will be + * displayed in the configuration screen of this job. + */ + public boolean isApplicable(Class> jobType) { + return true; + } +} diff --git a/core/src/main/java/hudson/model/TestIcon.java b/core/src/main/java/hudson/model/TestIcon.java new file mode 100644 index 0000000000000..22b168e9794f9 --- /dev/null +++ b/core/src/main/java/hudson/model/TestIcon.java @@ -0,0 +1,39 @@ +package hudson.model; + +import edu.umd.cs.findbugs.annotations.NonNull; +import hudson.Extension; +import org.kohsuke.stapler.DataBoundConstructor; + +/** + * Renders a test icon for a Job. + */ +public class TestIcon extends JobIcon { + + @DataBoundConstructor + public TestIcon() { /* NOP */ } + + @Override + public String getImageOf(String size) { + return null; + } + + @Override + public String getIconClassName() { + return "symbol-edit"; + } + + @Override + public String getDescription() { + return "Testing"; + } + + @Extension + public static class DescriptorImpl extends JobIconDescriptor { + + @Override + @NonNull + public String getDisplayName() { + return "Test Icon"; + } + } +} diff --git a/core/src/main/resources/hudson/model/Job/configure.jelly b/core/src/main/resources/hudson/model/Job/configure.jelly index d226a966558d2..fa15ab8e871cd 100644 --- a/core/src/main/resources/hudson/model/Job/configure.jelly +++ b/core/src/main/resources/hudson/model/Job/configure.jelly @@ -56,6 +56,7 @@ THE SOFTWARE. + diff --git a/core/src/main/resources/hudson/model/Job/index.jelly b/core/src/main/resources/hudson/model/Job/index.jelly index d9b214900c7bb..e46382993987f 100644 --- a/core/src/main/resources/hudson/model/Job/index.jelly +++ b/core/src/main/resources/hudson/model/Job/index.jelly @@ -31,11 +31,18 @@ THE SOFTWARE.

- - - - - + + + + + + + + + + + +

diff --git a/core/src/main/resources/hudson/model/Messages.properties b/core/src/main/resources/hudson/model/Messages.properties index d56c57ff5ee03..2dd51ba557b66 100644 --- a/core/src/main/resources/hudson/model/Messages.properties +++ b/core/src/main/resources/hudson/model/Messages.properties @@ -92,6 +92,9 @@ BallColor.Success=Success BallColor.Unstable=Unstable Build.post_build_steps_failed=Post-build steps failed + +BuildStatusIcon.DisplayName=Build Status Icon + CLI.clear-queue.shortDescription=Clears the build queue. CLI.online-node.shortDescription=Resume using a node for performing builds, to cancel out the earlier "offline-node" command. diff --git a/core/src/main/resources/hudson/model/Run/statusIcon.jelly b/core/src/main/resources/hudson/model/Run/statusIcon.jelly index 548d5176bcea6..b9b9f18c20eed 100644 --- a/core/src/main/resources/hudson/model/Run/statusIcon.jelly +++ b/core/src/main/resources/hudson/model/Run/statusIcon.jelly @@ -35,6 +35,6 @@ THE SOFTWARE. - + diff --git a/core/src/main/resources/hudson/views/StatusColumn/column.jelly b/core/src/main/resources/hudson/views/StatusColumn/column.jelly index 428a173fedf6b..63629678677cf 100644 --- a/core/src/main/resources/hudson/views/StatusColumn/column.jelly +++ b/core/src/main/resources/hudson/views/StatusColumn/column.jelly @@ -24,17 +24,9 @@ THE SOFTWARE. - - - -
- -
- -
- - - - -
+ +
+ +
+
diff --git a/core/src/main/resources/lib/hudson/jobLink.jelly b/core/src/main/resources/lib/hudson/jobLink.jelly index af40d22b37ae9..e09b2352bb417 100644 --- a/core/src/main/resources/lib/hudson/jobLink.jelly +++ b/core/src/main/resources/lib/hudson/jobLink.jelly @@ -31,7 +31,7 @@ THE SOFTWARE. - + diff --git a/core/src/main/resources/lib/hudson/projectView.jelly b/core/src/main/resources/lib/hudson/projectView.jelly index 75842abc1e9f6..3e68dd7aa1f98 100644 --- a/core/src/main/resources/lib/hudson/projectView.jelly +++ b/core/src/main/resources/lib/hudson/projectView.jelly @@ -97,15 +97,7 @@ THE SOFTWARE.