diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView.java index 0b324db25..f1c1ac5c8 100644 --- a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView.java +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView.java @@ -102,6 +102,15 @@ public BuildMonitorInstallation getInstallation() { public boolean collectAnonymousUsageStatistics() { return descriptor.getPermissionToCollectAnonymousUsageStatistics(); } + @SuppressWarnings("unused") // used in .jelly + public double getOvertimeFactor() { + return currentConfig().getOvertimeFactor(); + } + + @SuppressWarnings("unused") // used in .jelly + public String getFilterRegex() { + return currentConfig().getFilterRegex(); + } @Override protected void submit(StaplerRequest req) throws ServletException, IOException, FormException { @@ -113,7 +122,12 @@ protected void submit(StaplerRequest req) throws ServletException, IOException, String requestedOrdering = req.getParameter("order"); title = req.getParameter("title"); - + String filterRegex = req.getParameter("filterRegex"); + float overtimeFactor = Float.parseFloat(req.getParameter("overtimeFactor"));//needs parsing into config as input is string. + currentConfig().setOvertimeFactor(overtimeFactor); + currentConfig().setStripCommonPrefix(json.optBoolean("stripPrefix",false)); + currentConfig().setStripCommonSuffix(json.optBoolean("stripSuffix",false)); + currentConfig().setFilterRegex(filterRegex); currentConfig().setDisplayCommitters(json.optBoolean("displayCommitters", true)); try { diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/Config.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/Config.java index 83ebd2e7b..3892d2705 100644 --- a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/Config.java +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/Config.java @@ -10,7 +10,38 @@ public class Config { - private boolean displayCommitters; + private boolean displayCommitters,shouldStripCommonPrefix,shouldStripCommonSuffix; + private String filterRegex; + private double overtimeFactor; + + public void setStripCommonPrefix(boolean strip){ + this.shouldStripCommonPrefix = strip; + } + + public void setStripCommonSuffix(boolean strip){ + this.shouldStripCommonSuffix = strip; + } + public Boolean ShouldStripCommonPrefix(){ + return getOrElse(shouldStripCommonPrefix,false); + } + public Boolean ShouldStripCommonSuffix(){ + return getOrElse(shouldStripCommonSuffix,false); + } + public void setOvertimeFactor(double overtimeFactor){ + this.overtimeFactor = overtimeFactor; + } + + public double getOvertimeFactor() { + return getOrElse(this.overtimeFactor, 1.0); + } + + public void setFilterRegex(String filterRegex) { + this.filterRegex = filterRegex; + } + + public String getFilterRegex() { + return getOrElse(this.filterRegex,""); + } public static Config defaultConfig() { return new Config(); diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/JobView.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/JobView.java index 9db4ed8a2..8716384a3 100644 --- a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/JobView.java +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/JobView.java @@ -159,4 +159,7 @@ private BuildViewModel buildViewOf(Run build) { return BuildView.of(build, relative, systemTime); } + public boolean hasQueuedItem() { + return job.getQueueItem() != null; + } } \ No newline at end of file diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/JobViewSerialiser.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/JobViewSerialiser.java index cdd44f47f..6010f4401 100644 --- a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/JobViewSerialiser.java +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/JobViewSerialiser.java @@ -20,6 +20,8 @@ public void serialize(JobView job, JsonGenerator jgen, SerializerProvider provid jgen.writeObjectField("hashCode", job.hashCode()); jgen.writeObjectField("progress", job.progress()); jgen.writeObjectField("estimatedDuration", job.estimatedDuration()); + /*jgen.writeObjectField("buildExceedsEstimatedDuration", job.buildExceedsEstimatedDuration());*/ + jgen.writeObjectField("hasQueuedItem", job.hasQueuedItem()); for (Feature feature : job.features()) { Object serialised = feature.asJson(); diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/JobViews.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/JobViews.java index f185ade83..8cea076ac 100644 --- a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/JobViews.java +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/JobViews.java @@ -2,7 +2,10 @@ import com.smartcodeltd.jenkinsci.plugins.buildmonitor.facade.StaticJenkinsAPIs; import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.*; +import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons.StripMostCommonPrefixConfig; +import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons.StripMostCommonSuffixConfig; import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.headline.HeadlineConfig; +import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.jobNameFilter.JobNameFilterConfig; import hudson.model.Job; import java.util.List; @@ -30,8 +33,12 @@ public JobView viewOf(Job job) { // todo: a more elegant way of assembling the features would be nice viewFeatures.add(new HasHeadline(new HeadlineConfig(config.shouldDisplayCommitters()))); + viewFeatures.add(new shouldStripMostCommonPrefix(new StripMostCommonPrefixConfig(config.ShouldStripCommonPrefix()))); + viewFeatures.add(new shouldStripMostCommonSuffix(new StripMostCommonSuffixConfig(config.ShouldStripCommonSuffix()))); viewFeatures.add(new KnowsLastCompletedBuildDetails()); viewFeatures.add(new KnowsCurrentBuildsDetails()); + viewFeatures.add(new BuildExceedsEstimatedDuration(config.getOvertimeFactor())); + viewFeatures.add(new HasNameFilter(new JobNameFilterConfig(config.getFilterRegex()))); if (jenkins.hasPlugin(Claim)) { viewFeatures.add(new CanBeClaimed()); diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/duration/Duration.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/duration/Duration.java index 53c4b8d90..582d22d1d 100644 --- a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/duration/Duration.java +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/duration/Duration.java @@ -14,7 +14,7 @@ public boolean greaterThan(Duration otherDuration) { return duration > otherDuration.toLong(); } - private long toLong() { + public long toLong() { return duration; } } \ No newline at end of file diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/BuildExceeds.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/BuildExceeds.java new file mode 100644 index 000000000..c1d4f3f2f --- /dev/null +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/BuildExceeds.java @@ -0,0 +1,23 @@ +package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features; + +import org.codehaus.jackson.annotate.JsonValue; + +/** + * @author Vincent & Robert + */ +public class BuildExceeds { + private final boolean value; + + public BuildExceeds(boolean value) { + this.value = value; + } + + @JsonValue + public boolean value() { + return value; + } + + public BuildExceeds asJson() { + return this; + } +} diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/BuildExceedsEstimatedDuration.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/BuildExceedsEstimatedDuration.java new file mode 100644 index 000000000..159487d9e --- /dev/null +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/BuildExceedsEstimatedDuration.java @@ -0,0 +1,39 @@ +package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features; + +import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.JobView; +import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.NullBuildView; +import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.duration.Duration; +import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.duration.DurationInMilliseconds; + +public class BuildExceedsEstimatedDuration implements Feature { + private JobView job; + private double config; + + public BuildExceedsEstimatedDuration(double config) { + this.config = config; + } + + @Override + public BuildExceedsEstimatedDuration of(JobView jobView) { + this.job = jobView; + return this; + } + + public boolean buildExceedsEstimatedDuration() { + double overTimeFactor = this.config; + + if (job.lastBuild() instanceof NullBuildView) { + return false; + } + + Duration tooLongDuration = new DurationInMilliseconds((long) ((double) job.lastBuild().estimatedDuration().toLong() * overTimeFactor)); + + return job.isRunning() && job.lastBuild().elapsedTime().greaterThan(tooLongDuration); + } + + @Override + public BuildExceeds asJson() { + return new BuildExceeds(buildExceedsEstimatedDuration()); + } + +} diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/HasNameFilter.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/HasNameFilter.java new file mode 100644 index 000000000..02e7afec1 --- /dev/null +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/HasNameFilter.java @@ -0,0 +1,29 @@ +package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features; + +import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.JobView; +import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.jobNameFilter.*; + +public class HasNameFilter implements Feature { + private JobView job; + private JobNameFilterConfig config; + + public HasNameFilter(JobNameFilterConfig config) { + this.config = config; + } + + @Override + public HasNameFilter of(JobView jobView) { + this.job = jobView; + + return this; + } + + @Override + public JobNameFiltered asJson() { + JobNameFilterer nameFilterer = new JobNameFilterer(job.name()); + + nameFilterer = nameFilterer.filterRegex(config.regex); + + return new JobNameFiltered(nameFilterer.getJobName()); + } +} \ No newline at end of file diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StripMostCommonPrefix.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StripMostCommonPrefix.java new file mode 100644 index 000000000..115224fb8 --- /dev/null +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StripMostCommonPrefix.java @@ -0,0 +1,17 @@ +package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons; + +/** + * Contains methods used to filter the job name with specified prefix, suffix and regex + */ +public class StripMostCommonPrefix { + private StripMostCommonPrefixConfig conf; + + public StripMostCommonPrefix(StripMostCommonPrefixConfig conf) { + this.conf = conf; + } + + public boolean getPrefix(){ + //Boolean.toString(conf.prefix) + return conf.prefix; + } +} \ No newline at end of file diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StripMostCommonPrefixConfig.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StripMostCommonPrefixConfig.java new file mode 100644 index 000000000..ada9407ae --- /dev/null +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StripMostCommonPrefixConfig.java @@ -0,0 +1,12 @@ +package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons; + +/** + * @author Vincent & Robert + */ +public class StripMostCommonPrefixConfig { + public final Boolean prefix; + + public StripMostCommonPrefixConfig(Boolean prefix) { + this.prefix = prefix; + } +} \ No newline at end of file diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StripMostCommonSuffix.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StripMostCommonSuffix.java new file mode 100644 index 000000000..b61214347 --- /dev/null +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StripMostCommonSuffix.java @@ -0,0 +1,17 @@ +package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons; + +/** + * Contains methods used to filter the job name with specified prefix, suffix and regex + */ +public class StripMostCommonSuffix { + private StripMostCommonSuffixConfig conf; + + public StripMostCommonSuffix(StripMostCommonSuffixConfig conf) { + this.conf = conf; + } + + + public boolean getSuffix(){ + return conf.suffix; + } +} \ No newline at end of file diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StripMostCommonSuffixConfig.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StripMostCommonSuffixConfig.java new file mode 100644 index 000000000..221e6a0e6 --- /dev/null +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StripMostCommonSuffixConfig.java @@ -0,0 +1,12 @@ +package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons; + +/** + * @author Vincent & Robert + */ +public class StripMostCommonSuffixConfig { + public final Boolean suffix; + + public StripMostCommonSuffixConfig(Boolean suffix) { + this.suffix = suffix; + } +} \ No newline at end of file diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StrippedMostCommonPrefix.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StrippedMostCommonPrefix.java new file mode 100644 index 000000000..15ceeeaef --- /dev/null +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StrippedMostCommonPrefix.java @@ -0,0 +1,23 @@ +package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons; + +import org.codehaus.jackson.annotate.JsonValue; + +/** + * @author Vincent & Robert + */ +public class StrippedMostCommonPrefix { + private final boolean value; + + public StrippedMostCommonPrefix(boolean value) { + this.value = value; + } + + @JsonValue + public boolean value() { + return value; + } + + public StrippedMostCommonPrefix asJson() { + return this; + } +} \ No newline at end of file diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StrippedMostCommonSuffix.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StrippedMostCommonSuffix.java new file mode 100644 index 000000000..0b65ec7d0 --- /dev/null +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/StripMostCommons/StrippedMostCommonSuffix.java @@ -0,0 +1,23 @@ +package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons; + +import org.codehaus.jackson.annotate.JsonValue; + +/** + * @author Vincent & Robert + */ +public class StrippedMostCommonSuffix { + private final boolean value; + + public StrippedMostCommonSuffix(boolean value) { + this.value = value; + } + + @JsonValue + public boolean value() { + return value; + } + + public StrippedMostCommonSuffix asJson() { + return this; + } +} \ No newline at end of file diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/jobNameFilter/JobNameFilterConfig.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/jobNameFilter/JobNameFilterConfig.java new file mode 100644 index 000000000..bfb2a8aa5 --- /dev/null +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/jobNameFilter/JobNameFilterConfig.java @@ -0,0 +1,12 @@ +package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.jobNameFilter; + +/** + * @author Vincent & Robert + */ +public class JobNameFilterConfig { + public final String regex; + + public JobNameFilterConfig( String regex) { + this.regex = regex; + } +} \ No newline at end of file diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/jobNameFilter/JobNameFiltered.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/jobNameFilter/JobNameFiltered.java new file mode 100644 index 000000000..1621b4886 --- /dev/null +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/jobNameFilter/JobNameFiltered.java @@ -0,0 +1,23 @@ +package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.jobNameFilter; + +import org.codehaus.jackson.annotate.JsonValue; + +/** + * @author Vincent & Robert + */ +public class JobNameFiltered { + private final String value; + + public JobNameFiltered(String value) { + this.value = value; + } + + @JsonValue + public String value() { + return value; + } + + public JobNameFiltered asJson() { + return this; + } +} \ No newline at end of file diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/jobNameFilter/JobNameFilterer.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/jobNameFilter/JobNameFilterer.java new file mode 100644 index 000000000..13ff5fe8f --- /dev/null +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/jobNameFilter/JobNameFilterer.java @@ -0,0 +1,33 @@ +package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.jobNameFilter; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Contains methods used to filter the job name with specified prefix, suffix and regex + */ +public class JobNameFilterer { + private String jobName; + + public JobNameFilterer(String jobName) { + this.jobName = jobName; + } + + public JobNameFilterer filterRegex(String regex) { + if (regex.length() <= 0) { + return this; + } + + String filteredName; + + Pattern p = Pattern.compile(regex); + Matcher m = p.matcher(jobName); + filteredName = m.replaceAll(""); + + return new JobNameFilterer(filteredName); + } + + public String getJobName() { + return jobName; + } +} \ No newline at end of file diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/shouldStripMostCommonPrefix.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/shouldStripMostCommonPrefix.java new file mode 100644 index 000000000..881703f69 --- /dev/null +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/shouldStripMostCommonPrefix.java @@ -0,0 +1,29 @@ +package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features; + +import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.JobView; +import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons.StripMostCommonPrefix; +import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons.StripMostCommonPrefixConfig; +import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons.StrippedMostCommonPrefix; + +public class shouldStripMostCommonPrefix implements Feature { + private JobView job; + private StripMostCommonPrefixConfig config; + + + public shouldStripMostCommonPrefix(StripMostCommonPrefixConfig stripMostCommonPrefixConfig) { + this.config = stripMostCommonPrefixConfig; + } + + @Override + public shouldStripMostCommonPrefix of(JobView jobView) { + this.job = jobView; + + return this; + } + + @Override + public StrippedMostCommonPrefix asJson() { + StripMostCommonPrefix coms = new StripMostCommonPrefix(config); + return new StrippedMostCommonPrefix(coms.getPrefix()); + } +} \ No newline at end of file diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/shouldStripMostCommonSuffix.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/shouldStripMostCommonSuffix.java new file mode 100644 index 000000000..3b4202313 --- /dev/null +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/features/shouldStripMostCommonSuffix.java @@ -0,0 +1,27 @@ +package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features; + +import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.JobView; +import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons.*; + +public class shouldStripMostCommonSuffix implements Feature { + private JobView job; + private StripMostCommonSuffixConfig config; + + + public shouldStripMostCommonSuffix(StripMostCommonSuffixConfig Strip) { + this.config = Strip; + } + + @Override + public shouldStripMostCommonSuffix of(JobView jobView) { + this.job = jobView; + + return this; + } + + @Override + public StrippedMostCommonSuffix asJson() { + StripMostCommonSuffix coms = new StripMostCommonSuffix(config); + return new StrippedMostCommonSuffix(coms.getSuffix()); + } +} \ No newline at end of file diff --git a/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/configure-entries.jelly b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/configure-entries.jelly index 59a277a47..f088570db 100644 --- a/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/configure-entries.jelly +++ b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/configure-entries.jelly @@ -48,6 +48,21 @@ + + + + + + + + + + + + + + + diff --git a/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/help-filterNamePrefix.html b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/help-filterNamePrefix.html new file mode 100644 index 000000000..216fa1dd7 --- /dev/null +++ b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/help-filterNamePrefix.html @@ -0,0 +1,3 @@ +
+ Removes Prefix from job name on build monitor. +
\ No newline at end of file diff --git a/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/help-filterNameRegex.html b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/help-filterNameRegex.html new file mode 100644 index 000000000..b1fe93f76 --- /dev/null +++ b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/help-filterNameRegex.html @@ -0,0 +1,3 @@ +
+ Removes matching regex from job name on build monitor. +
\ No newline at end of file diff --git a/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/help-filterNameSuffix.html b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/help-filterNameSuffix.html new file mode 100644 index 000000000..70b71c3b3 --- /dev/null +++ b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/help-filterNameSuffix.html @@ -0,0 +1,3 @@ +
+ Removes Suffix from job name on build monitor. +
\ No newline at end of file diff --git a/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/main-settings.jelly b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/main-settings.jelly index 15506990c..f8fe05705 100644 --- a/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/main-settings.jelly +++ b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/main-settings.jelly @@ -41,6 +41,24 @@ id="settings-show-badges" type="checkbox" /> +
  • + + +
  • +
  • + + +
  • {{project.name}} + href="{{project.url}}"> + {{project.name}} +

    • {{ project.headline }}
    • @@ -42,6 +44,12 @@ {{ badge.text }} +
    • job has build in queue
    • +
    • + + + Job is taking longer than expected too complete. +
    @@ -50,4 +58,4 @@
  • - \ No newline at end of file + diff --git a/build-monitor-plugin/src/main/webapp/scripts/controllers.js b/build-monitor-plugin/src/main/webapp/scripts/controllers.js index 0e0e8dfae..c1788995d 100644 --- a/build-monitor-plugin/src/main/webapp/scripts/controllers.js +++ b/build-monitor-plugin/src/main/webapp/scripts/controllers.js @@ -24,6 +24,8 @@ angular. return fetchJobViews().then(function (response) { $scope.jobs = response.data.data; + //required. + getFreqOfJobs($scope.jobs); $rootScope.$broadcast('jenkins:data-fetched', response.data.meta); @@ -37,6 +39,54 @@ angular. $scope.fontSize = fontSizeFor($scope.jobs, newColumnCount); }); + /* + TODO extract into widget. + */ + + function getFreqOfJobs(itemsOnScreen){ + var namesOnScreen = []; + for(var i = 0; i < itemsOnScreen.length;i++){ + namesOnScreen.push(itemsOnScreen[i].jobNameFiltered); + $scope.jobs[i].name = itemsOnScreen[i].jobNameFiltered; + } + var sharedStartString,sharedEndString; + + if($scope.jobs[0].strippedMostCommonPrefix){ + sharedStartString = sharedStart(namesOnScreen); + for(var i = 0; i < namesOnScreen.length; i++){ + $scope.jobs[i].name = namesOnScreen[i].substring(sharedStartString.length,namesOnScreen[i].length); + } + + } + if($scope.jobs[0].strippedMostCommonSuffix){ + sharedEndString = sharedEnd(namesOnScreen); + for(var i = 0; i < itemsOnScreen.length;i++){ + $scope.jobs[i].name = $scope.jobs[i].name.substring(0,$scope.jobs[i].name.length-sharedEndString.length); + } + } + } + //shameful copy and paste from SO + function reverse(s){ + return s.split("").reverse().join(""); + } + function sharedStart(array,bool){ + array = array.sort(), + a1= array[0], a2= array[array.length-1], L= a1.length, i= 0; + + while(i