Skip to content

Commit

Permalink
Miscellaneous code cleanup (#147)
Browse files Browse the repository at this point in the history
* Fix generics
* Use non-deprecated methods
* Use static methods where possible
* Remove unnecessary unboxing
  • Loading branch information
basil authored Oct 19, 2021
1 parent 6796123 commit 6307427
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ static Map<String,List<FlowNode>> getThrottledPipelineRunsForCategory(@NonNull S
return throttledPipelines;
}

private static Item getItem(ItemGroup group, String name) {
private static Item getItem(ItemGroup<?> group, String name) {
if (group instanceof Jenkins) {
return ((Jenkins) group).getItemMap().get(name);
} else {
Expand Down Expand Up @@ -411,7 +411,7 @@ public boolean isApplicable(Class<? extends Job> jobType) {
return Job.class.isAssignableFrom(jobType) && Queue.Task.class.isAssignableFrom(jobType);
}

public boolean isMatrixProject(Job job) {
public boolean isMatrixProject(Job<?, ?> job) {
return job instanceof MatrixProject;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ private CauseOfBlockage canTakeImpl(Node node, Task task) {
}
if (tjp != null) {
if (tjp.getThrottleOption().equals("project")) {
if (tjp.getMaxConcurrentPerNode().intValue() > 0) {
int maxConcurrentPerNode = tjp.getMaxConcurrentPerNode().intValue();
if (tjp.getMaxConcurrentPerNode() > 0) {
int maxConcurrentPerNode = tjp.getMaxConcurrentPerNode();
int runCount = buildsOfProjectOnNode(node, task);

// This would mean that there are as many or more builds currently running than are allowed.
Expand Down Expand Up @@ -121,7 +121,7 @@ private CauseOfBlockage throttleCheckForCategoriesOnNode(Node node, Jenkins jenk
int runCount = 0;
// Max concurrent per node for category
int maxConcurrentPerNode = getMaxConcurrentPerNodeBasedOnMatchingLabels(
node, category, category.getMaxConcurrentPerNode().intValue());
node, category, category.getMaxConcurrentPerNode());
if (maxConcurrentPerNode > 0) {
for (Task catTask : categoryTasks) {
if (jenkins.getQueue().isPending(catTask)) {
Expand Down Expand Up @@ -234,8 +234,8 @@ private CauseOfBlockage canRunImpl(Task task, ThrottleJobProperty tjp, List<Stri
}
if (tjp != null) {
if (tjp.getThrottleOption().equals("project")) {
if (tjp.getMaxConcurrentTotal().intValue() > 0) {
int maxConcurrentTotal = tjp.getMaxConcurrentTotal().intValue();
if (tjp.getMaxConcurrentTotal() > 0) {
int maxConcurrentTotal = tjp.getMaxConcurrentTotal();
int totalRunCount = buildsOfProjectOnAllNodes(task);

if (totalRunCount >= maxConcurrentTotal) {
Expand Down Expand Up @@ -263,8 +263,8 @@ private CauseOfBlockage throttleCheckForCategoriesAllNodes(Jenkins jenkins, @Non

// Double check category itself isn't null
if (category != null) {
if (category.getMaxConcurrentTotal().intValue() > 0) {
int maxConcurrentTotal = category.getMaxConcurrentTotal().intValue();
if (category.getMaxConcurrentTotal() > 0) {
int maxConcurrentTotal = category.getMaxConcurrentTotal();
int totalRunCount = 0;

for (Task catTask : categoryTasks) {
Expand Down Expand Up @@ -668,7 +668,7 @@ private int getMaxConcurrentPerNodeBasedOnMatchingLabels(
for(LabelAtom aNodeLabel: nodeLabels) {
String nodeLabel = aNodeLabel.getDisplayName();
if(nodeLabel.equals(throttledNodeLabel)) {
maxConcurrentPerNodeLabeledIfMatch = nodeLabeledPair.getMaxConcurrentPerNodeLabeled().intValue();
maxConcurrentPerNodeLabeledIfMatch = nodeLabeledPair.getMaxConcurrentPerNodeLabeled();
LOGGER.log(Level.FINE, "node labels match; => maxConcurrentPerNode'' = {0}", maxConcurrentPerNodeLabeledIfMatch);
nodeLabelsMatch = true;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import hudson.util.CopyOnWriteMap;
import hudson.util.VersionNumber;

import jenkins.model.Jenkins;

import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
Expand Down Expand Up @@ -460,7 +462,7 @@ public void clearConfiguredCategories() throws Exception {
HtmlForm config = page.getFormByName("config");
List<HtmlButton> deleteButtons;
// TODO Delete the tables code once the baseline is past 2.264.
VersionNumber version = j.jenkins.getVersion();
VersionNumber version = Jenkins.getVersion();
if (version.isNewerThanOrEqualTo(new VersionNumber("2.264"))) {
deleteButtons =
config.getByXPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import jenkins.model.Jenkins;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -83,7 +84,7 @@ public class ThrottleQueueTaskDispatcherTest {
@Before
public void setUp() {
// TODO Delete the tables code once the baseline is past 2.264.
VersionNumber version = r.jenkins.getVersion();
VersionNumber version = Jenkins.getVersion();
if (version.isNewerThanOrEqualTo(new VersionNumber("2.264"))) {
parentXPath = parentXPathDivs;
} else {
Expand Down Expand Up @@ -198,12 +199,12 @@ private void assertBasedOnMaxLabelPairMatchingOrNot(
HtmlPage page = getLoggerPage(logger);
if(expectMatch)
{
assertTrue(expectedTracesMessage(match, true), page.asText().contains(matchTrace));
assertTrue(expectedTracesMessage(max, true), page.asText().contains(maxTrace+targetedPairNumber));
assertTrue(expectedTracesMessage(match, true), page.asNormalizedText().contains(matchTrace));
assertTrue(expectedTracesMessage(max, true), page.asNormalizedText().contains(maxTrace+targetedPairNumber));
}
else {
assertTrue(expectedTracesMessage(mismatch, true), page.asText().contains(mismatchTrace));
assertFalse(expectedTracesMessage(max, false), page.asText().contains(maxTrace));
assertTrue(expectedTracesMessage(mismatch, true), page.asNormalizedText().contains(mismatchTrace));
assertFalse(expectedTracesMessage(max, false), page.asNormalizedText().contains(maxTrace));
}
}

Expand Down

0 comments on commit 6307427

Please sign in to comment.